Other Parts Discussed in Thread: CC3220SF
Hello,
I open new thread because this is different issue from original one.
Attached program transmits 24KB TCP traffic every 0.16s.
This program runs normally with SDK 2.10, but with SDK 2.20 stops abnormally after sending some packets.
At that time, the return value from sl_Send is -2005(=SL_API_ABORTED).
Why?
Sample program usage:
1) Import serial_wifi_CC3220SF_LAUNCHXL_tirtos_ccs from SDK.
2) Replace serial_wifi.c in the project with attached file.
3) Set SSID, security key, ip address in the source code.
4) Build, load, and run.
I'm using SocketTest v3.0.0 as the receiver side software.
It's downloaded from sourceforge.
sourceforge.net/.../
Regards,
Nobuhiro
#include <stddef.h> #include <ti/drivers/Timer.h> #include <ti/drivers/SPI.h> #include <ti/drivers/net/wifi/slnetifwifi.h> #include <ti/sysbios/BIOS.h> #include <ti/sysbios/knl/Task.h> #include <ti/sysbios/knl/Semaphore.h> #include <ti/devices/cc32xx/inc/hw_types.h> #include <ti/devices/cc32xx/inc/hw_memmap.h> #include <ti/devices/cc32xx/inc/hw_ints.h> #include <ti/devices/cc32xx/inc/hw_timer.h> #include <ti/devices/cc32xx/driverlib/timer.h> #include <ti/devices/cc32xx/driverlib/prcm.h> #include <ti/devices/cc32xx/driverlib/rom_map.h> #include <ti/devices/cc32xx/driverlib/interrupt.h> #include "pthread.h" #include "Board.h" #define INTR_PERIOD_COUNTS_VALUE 16000 // 200us #define AP_SSID "SSID" // Access Point #define PAYLOAD_SIZE (24*1024) // 24KB #define SEND_PERIOD_INT 800 // WLAN send interval 160ms Timer_Params timerParams; Timer_Handle timerHandle = 0; pthread_t gSpawnThread = (pthread_t)NULL; pthread_attr_t pAttrs_spawn; struct sched_param priParam; Task_Params taskParams; Task_Struct taskStruct; Char taskStack[4096]; Semaphore_Params semParams; Semaphore_Struct semStruct; Semaphore_Handle semHandle; int32_t sock; SlNetCfgIpV4Args_t ipV4; SlSockAddrIn_t sAddr; SlWlanSecParams_t secParams; unsigned long send_count = 0; unsigned char payload[PAYLOAD_SIZE] = {}; unsigned long interruptCount = 0; int status = 0; // Callback Functions from SimpleLink Wifi Driver - must be defined void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) {} void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent) {} void SimpleLinkHttpServerEventHandler(SlNetAppHttpServerEvent_t *pHttpEvent, SlNetAppHttpServerResponse_t *pHttpResponse) {} void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent) {} void SimpleLinkSockEventHandler(SlSockEvent_t *pSock) {} void SimpleLinkFatalErrorEventHandler(SlDeviceFatal_t *slFatalErrorEvent){} void SimpleLinkNetAppRequestEventHandler(SlNetAppRequest_t *pNetAppRequest, SlNetAppResponse_t *pNetAppResponse) {} void SimpleLinkNetAppRequestMemFreeEventHandler(uint8_t *buffer) {} // WLAN send void sendTask(UArg arg0, UArg arg1) { int i; unsigned char dummy_data; for (;;) { Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); send_count++; dummy_data = 0x30 + (send_count % 8); for (i = 0; i < PAYLOAD_SIZE; i++) { if ((i % 64) == 0) { payload[i] = '\n'; } else { payload[i] = dummy_data; } } status = sl_Send(sock, payload, sizeof(payload), 0); if (status < 0) { while(1); } } } void timerCallback(void) { MAP_TimerIntClear(TIMERA2_BASE, 0x2FFF); interruptCount++; if (interruptCount % SEND_PERIOD_INT == 0) { Semaphore_post(semHandle); } } void *mainThread(void *arg0) { SPI_init(); Semaphore_Params_init(&semParams); semParams.mode = Semaphore_Mode_BINARY; Semaphore_construct(&semStruct, 0, &semParams); semHandle = Semaphore_handle(&semStruct); // Create sl_Task pthread_attr_init(&pAttrs_spawn); priParam.sched_priority = 9; pthread_attr_setschedparam(&pAttrs_spawn, &priParam); pthread_attr_setstacksize(&pAttrs_spawn, 4096); pthread_create(&gSpawnThread, &pAttrs_spawn, sl_Task, NULL); // Create send task Task_Params_init(&taskParams); taskParams.stackSize = 4096; taskParams.stack = &taskStack; taskParams.priority = 10; Task_construct(&taskStruct, (Task_FuncPtr)sendTask, &taskParams, NULL); // Establish connection to AP sl_Stop(10000); if (sl_Start(0, 0, 0) != ROLE_STA) { sl_WlanSetMode(ROLE_STA); sl_Stop(10000); sl_Start(0, 0, 0); } ipV4.Ip = (_u32)SL_IPV4_VAL(192, 168, 0, 6); // my(sender) ip ipV4.IpMask = (_u32)SL_IPV4_VAL(255, 255, 255, 0); ipV4.IpGateway = (_u32)SL_IPV4_VAL(192, 168, 0, 1); // dummy ipV4.IpDnsServer=(_u32)SL_IPV4_VAL(192, 168, 0, 1); // dummy sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE, SL_NETCFG_ADDR_STATIC, sizeof(SlNetCfgIpV4Args_t), (uint8_t *)&ipV4); secParams.Key = "security key"; secParams.KeyLen = strlen(secParams.Key); secParams.Type = SL_WLAN_SEC_TYPE_WPA_WPA2; sl_WlanConnect(AP_SSID, strlen(AP_SSID), 0, &secParams, 0); Task_sleep(5000); // wait 5s // Create socket sAddr.sin_family = SL_AF_INET; sAddr.sin_port = sl_Htons(5001); sAddr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(192, 168, 0, 108)); // receiver's ip sock = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, 0); sl_Connect(sock, (const SlSockAddr_t *)&sAddr, sizeof(SlSockAddrIn_t)); // Create timer /* Initialize hardware timer */ MAP_PRCMPeripheralClkEnable(PRCM_TIMERA2, PRCM_RUN_MODE_CLK); MAP_IntDisable(INT_TIMERA2A); MAP_IntDisable(INT_TIMERA2B); MAP_TimerIntDisable(TIMERA2_BASE, TIMER_CAPB_EVENT | TIMER_CAPB_MATCH | TIMER_TIMB_TIMEOUT | TIMER_CAPA_EVENT | TIMER_CAPA_MATCH | TIMER_TIMA_TIMEOUT); MAP_TimerDisable(TIMERA2_BASE, TIMER_BOTH); MAP_TimerIntClear(TIMERA2_BASE, TIMER_CAPB_EVENT | TIMER_CAPB_MATCH | TIMER_TIMB_TIMEOUT | TIMER_CAPA_EVENT | TIMER_CAPA_MATCH | TIMER_TIMA_TIMEOUT); /* set timer interrupt to 0, highest app priority */ MAP_IntPrioritySet(INT_TIMERA2A, 0<<5); MAP_IntPrioritySet(INT_TIMERA2B, 0<<5); /* Configure timer as periodic count-down with period of INTR_PERIOD_COUNTS_VALUE ticks */ MAP_TimerConfigure(TIMERA2_BASE, TIMER_CFG_PERIODIC); MAP_TimerLoadSet(TIMERA2_BASE, TIMER_A, INTR_PERIOD_COUNTS_VALUE); MAP_TimerIntRegister(TIMERA2_BASE, TIMER_A, timerCallback); /* Start the timer */ MAP_IntEnable(INT_TIMERA2A); MAP_TimerIntEnable(TIMERA2_BASE, TIMER_TIMA_TIMEOUT); MAP_TimerEnable(TIMERA2_BASE, TIMER_A); return (NULL); }