Part Number: LAUNCHCC3220MODASF
Tool/software: TI C/C++ Compiler
Hello,
I chose the "httget" example as a template, which was then extended with the "Timerled". This works without problems. The next step is the example to extend with a UDP socket. This function is called after toggling the Led. Problem here is that in the middle of processing the command "sl_socket" the "HWI_excHandler is called and the whole process is stopped.
Can you help me with this problem?
C-Code
plattform.c
#include <ti/drivers/net/wifi/simplelink.h> #include <ti/drivers/net/wifi/slnetifwifi.h> #include <ti/display/Display.h> #include <ti/drivers/SPI.h> #include "Board.h" #include "pthread.h" #include "semaphore.h" #include <test.h> #include <str.h> #include <stdio.h> #include <stdlib.h> #include <ti/drivers/net/wifi/sl_socket.h> #include <ti/drivers/Power.h> #include <ti/drivers/power/PowerCC32XX.h> #define APPLICATION_NAME "HTTP GET" #define DEVICE_ERROR ("Device error, please refer \"DEVICE ERRORS CODES\" section in errors.h") #define WLAN_ERROR ("WLAN error, please refer \"WLAN ERRORS CODES\" section in errors.h") #define SL_STOP_TIMEOUT (200) #define SPAWN_TASK_PRIORITY (9) #define SPAWN_STACK_SIZE (4096) #define TASK_STACK_SIZE (2048) #define SLNET_IF_WIFI_PRIO (5) #define SLNET_IF_WIFI_NAME "CC32xx" /* AP SSID */ #define SSID_NAME "Fritzbox_Test" /* Security type could be SL_WLAN_SEC_TYPE_WPA_WPA2 */ #define SECURITY_TYPE SL_WLAN_SEC_TYPE_WPA_WPA2 /* Password of the secured AP */ #define SECURITY_KEY "mysimplewlan" pthread_t httpThread = (pthread_t)NULL; pthread_t spawn_thread = (pthread_t)NULL; int32_t mode; Display_Handle display; int Merker; typedef struct StartApCmd { /* Ap's SSID */ uint8_t *ssid; /* Determine if AP has hidden SSID */ uint8_t hidden; /* 802.11 WLAN channel [1-12] */ uint8_t channel; /* The AP's TX power */ uint8_t tx_pow; /* Limits the number of stations that the AP's has */ uint8_t sta_limit; /* Security parameters - Security Type and Password */ SlWlanSecParams_t secParams; }StartApCmd_t; typedef struct appControlBlock_t { /* Status Variables */ /* This bit-wise status variable shows the state of the NWP */ uint32_t Status; /* This field keeps the device's role (STA, P2P or AP) */ uint32_t Role; /* This flag lets the application to exit */ uint32_t Exit; /* Sets the number of Ping attempts to send */ uint32_t PingAttempts; /* Data & Network entry Union*/ /*gDataBuffer_t gDataBuffer; //P2P mode CB p2p_CB P2P_CB; //STA/AP mode CB connection_CB CON_CB; //Cmd Prompt buffer uint8_t CmdBuffer[CMD_BUFFER_LEN]; // WoWLAN semaphore sem_t WowlanSleepSem;*/ }appControlBlock; int Merker=13; int init_Merker =0; int32_t ret = 0; int32_t mode = 0; StartApCmd_t StartApParams; appControlBlock app_CB; typedef enum { /* This bit is set: Network Processor is powered up */ STATUS_BIT_NWP_INIT = 0, /* This bit is set: the device is connected to the AP or client is connected to device (AP) */ STATUS_BIT_CONNECTION, /* This bit is set: the device has leased IP to any connected client */ STATUS_BIT_IP_LEASED, /* This bit is set: the device has acquired an IP */ STATUS_BIT_IP_ACQUIRED, /* If this bit is set: the device (P2P mode) found any p2p-device in scan */ STATUS_BIT_P2P_DEV_FOUND, /* If this bit is set: the device (P2P mode) found any p2p-negotiation request */ STATUS_BIT_P2P_REQ_RECEIVED, /* If this bit is set: the device(P2P mode) connection to client(or reverse way) is failed */ STATUS_BIT_CONNECTION_FAILED, /* This bit is set: device is undergoing ping operation */ STATUS_BIT_PING_STARTED, /* This bit is set: Scan is running is background */ STATUS_BIT_SCAN_RUNNING, /* If this bit is set: the device has acquired an IPv6 address */ STATUS_BIT_IPV6_ACQUIRED, /* If this bit is set: the device has acquired an IPv6 address */ STATUS_BIT_IPV6_GLOBAL_ACQUIRED, /* If this bit is set: the device has acquired an IPv6 address */ STATUS_BIT_IPV6_LOCAL_ACQUIRED, /* If this bit is set: Authentication with ENT AP failed. */ STATUS_BIT_AUTHENTICATION_FAILED, STATUS_BIT_RESET_REQUIRED, STATUS_BIT_TX_STARED }e_StatusBits; #define CMD_BUFFER_LEN (256) int32_t ParseStartApCmd (void *arg, StartApCmd_t *StartApParams); extern void* httpTask(void* pvParameters); void FreeStartApCmd(StartApCmd_t *StartApParams); typedef union { SlSockAddrIn6_t in6; /* Socket info for Ipv6 */ SlSockAddrIn_t in4; /* Socket info for Ipv4 */ }sockAddr_t; _i16 Sd; _i16 Status; extern void udp (void); /////////////////////////////////////////////////////////////////////////// /* ======== printError ========*/ #ifdef _test_ void printError(char *errString, int code) { printf("Error! code = %d, Description = %s\n", code, errString); while(1) { ; } } #endif extern int Handshake_Merker=1; /*! \brief SimpleLinkNetAppEventHandler This handler gets called whenever a Netapp event is reported by the host driver / NWP. Here user can implement he's own logic for any of these events. This handler is used by 'network_terminal' application to show case the following scenarios: 1. Handling IPv4 / IPv6 IP address acquisition. 2. Handling IPv4 / IPv6 IP address Dropping. \param pNetAppEvent - pointer to Netapp event data. \return void \note For more information, please refer to: user.h in the porting folder of the host driver and the CC31xx/CC32xx NWP programmer's guide (SWRU455) section 5.7 */ void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent) { int32_t status = 0; pthread_attr_t pAttrs; struct sched_param priParam; if(pNetAppEvent == NULL) { return; } switch(pNetAppEvent->Id) { case SL_NETAPP_EVENT_IPV4_ACQUIRED: case SL_NETAPP_EVENT_IPV6_ACQUIRED: /* Initialize SlNetSock layer with CC3x20 interface */ SlNetIf_init(0); SlNetIf_add(SLNETIF_ID_1, SLNET_IF_WIFI_NAME, (const SlNetIf_Config_t *)&SlNetIfConfigWifi, SLNET_IF_WIFI_PRIO); SlNetSock_init(0); SlNetUtil_init(0); if(mode != ROLE_AP) { Display_printf(display, 0, 0,"[NETAPP EVENT] IP Acquired: IP=%d.%d.%d.%d , " "Gateway=%d.%d.%d.%d\n\r", SL_IPV4_BYTE(pNetAppEvent->Data.IpAcquiredV4.Ip,3), SL_IPV4_BYTE(pNetAppEvent->Data.IpAcquiredV4.Ip,2), SL_IPV4_BYTE(pNetAppEvent->Data.IpAcquiredV4.Ip,1), SL_IPV4_BYTE(pNetAppEvent->Data.IpAcquiredV4.Ip,0), SL_IPV4_BYTE(pNetAppEvent->Data.IpAcquiredV4.Gateway,3), SL_IPV4_BYTE(pNetAppEvent->Data.IpAcquiredV4.Gateway,2), SL_IPV4_BYTE(pNetAppEvent->Data.IpAcquiredV4.Gateway,1), SL_IPV4_BYTE(pNetAppEvent->Data.IpAcquiredV4.Gateway,0)); pthread_attr_init(&pAttrs); priParam.sched_priority = 1; status = pthread_attr_setschedparam(&pAttrs, &priParam); status |= pthread_attr_setstacksize(&pAttrs, TASK_STACK_SIZE); status = pthread_create(&httpThread, &pAttrs, httpTask, NULL); if(status) { #ifdef _test_ printError("Task create failed", status); #endif } } break; default: break; } } /*! \brief SimpleLinkFatalErrorEventHandler This handler gets called whenever a socket event is reported by the NWP / Host driver. After this routine is called, the user's application must restart the device in order to recover. \param slFatalErrorEvent - pointer to fatal error event. \return void \note For more information, please refer to: user.h in the porting folder of the host driver and the CC31xx/CC32xx NWP programmer's guide (SWRU455) section 17.9. */ void SimpleLinkFatalErrorEventHandler(SlDeviceFatal_t *slFatalErrorEvent) { /* Unused in this application */ } /*! \brief SimpleLinkNetAppRequestMemFreeEventHandler This handler gets called whenever the NWP is done handling with the buffer used in a NetApp request. This allows the use of dynamic memory with these requests. \param pNetAppRequest - Pointer to NetApp request structure. \param pNetAppResponse - Pointer to NetApp request Response. \note For more information, please refer to: user.h in the porting folder of the host driver and the CC31xx/CC32xx NWP programmer's guide (SWRU455) section 17.9. \return void */ void SimpleLinkNetAppRequestMemFreeEventHandler(uint8_t *buffer) { /* Unused in this application */ } /*! \brief SimpleLinkNetAppRequestEventHandler This handler gets called whenever a NetApp event is reported by the NWP / Host driver. User can write he's logic to handle the event here. \param pNetAppRequest - Pointer to NetApp request structure. \param pNetAppResponse - Pointer to NetApp request Response. \note For more information, please refer to: user.h in the porting folder of the host driver and the CC31xx/CC32xx NWP programmer's guide (SWRU455) section 17.9. \return void */ void SimpleLinkNetAppRequestEventHandler(SlNetAppRequest_t *pNetAppRequest, SlNetAppResponse_t *pNetAppResponse) { /* Unused in this application */ } /*! \brief SimpleLinkHttpServerEventHandler This handler gets called whenever a HTTP event is reported by the NWP internal HTTP server. \param pHttpEvent - pointer to http event data. \param pHttpEvent - pointer to http response. \return void \note For more information, please refer to: user.h in the porting folder of the host driver and the CC31xx/CC32xx NWP programmer's guide (SWRU455) chapter 9. */ void SimpleLinkHttpServerEventHandler( SlNetAppHttpServerEvent_t *pHttpEvent, SlNetAppHttpServerResponse_t * pHttpResponse) { /* Unused in this application */ } /*! \brief SimpleLinkWlanEventHandler This handler gets called whenever a WLAN event is reported by the host driver / NWP. Here user can implement he's own logic for any of these events. This handler is used by 'network_terminal' application to show case the following scenarios: 1. Handling connection / Disconnection. 2. Handling Addition of station / removal. 3. RX filter match handler. 4. P2P connection establishment. \param pWlanEvent - pointer to Wlan event data. \return void \note For more information, please refer to: user.h in the porting folder of the host driver and the CC31xx/CC32xx NWP programmer's guide (SWRU455) sections 4.3.4, 4.4.5 and 4.5.5. \sa cmdWlanConnectCallback, cmdEnableFilterCallback, cmdWlanDisconnectCallback, cmdP2PModecallback. */ void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) { /* Unused in this application */ } /*! \brief SimpleLinkGeneralEventHandler This handler gets called whenever a general error is reported by the NWP / Host driver. Since these errors are not fatal, application can handle them. \param pDevEvent - pointer to device error event. \return void \note For more information, please refer to: user.h in the porting folder of the host driver and the CC31xx/CC32xx NWP programmer's guide (SWRU455) section 17.9. */ void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent) { /* Unused in this application */ } /*! \brief SimpleLinkSockEventHandler This handler gets called whenever a socket event is reported by the NWP / Host driver. \param SlSockEvent_t - pointer to socket event data. \return void \note For more information, please refer to: user.h in the porting folder of the host driver and the CC31xx/CC32xx NWP programmer's guide (SWRU455) section 7.6. */ void SimpleLinkSockEventHandler(SlSockEvent_t *pSock) { /* Unused in this application */ } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Connect(void) { SlWlanSecParams_t secParams = {0}; int16_t ret = 0; secParams.Key = (signed char*)SECURITY_KEY; secParams.KeyLen = strlen(SECURITY_KEY); secParams.Type = SECURITY_TYPE; printf( "Connecting to : %s.\r\n",SSID_NAME); ret = sl_WlanConnect((signed char*)SSID_NAME, strlen( SSID_NAME), 0, &secParams, 0); if(ret) { printf("Connection failed, ret=%d", ret); } init_Merker=1; } /*! \brief Display application banner This routine shows application startup display on UART. \param appName - points to a string representing application name. */ static void DisplayBanner(char * AppName) { Display_printf(display, 0, 0, "\n\n\n\r"); Display_printf(display, 0, 0, "\t\t *************************" "************************\n\r"); Display_printf(display, 0, 0, "\t\t %s Application \n\r", AppName); Display_printf(display, 0, 0, "\t\t **************************" "***********************\n\r"); Display_printf(display, 0, 0, "\n\n\n\r"); } void mainThread(void *pvParameters) { int32_t status = 0; pthread_attr_t pAttrs_spawn; struct sched_param priParam; SPI_init(); Display_init(); display = Display_open(Display_Type_UART, NULL); if(display == NULL) { /* Failed to open display driver */ while(1) { ; } } /* Print Application name */ DisplayBanner(APPLICATION_NAME); /* Start the SimpleLink Host */ pthread_attr_init(&pAttrs_spawn); priParam.sched_priority = SPAWN_TASK_PRIORITY; status = pthread_attr_setschedparam(&pAttrs_spawn, &priParam); status |= pthread_attr_setstacksize(&pAttrs_spawn, SPAWN_STACK_SIZE); status = pthread_create(&spawn_thread, &pAttrs_spawn, sl_Task, NULL); if(status) { printf("Task create failed status=%d", status); } /* pthread_attr_init(&pAttrs_spawn); (`////////////////////////////7test priParam.sched_priority = SPAWN_TASK_PRIORITY; status = pthread_attr_setschedparam(&pAttrs_spawn, &priParam); status |= pthread_attr_setstacksize(&pAttrs_spawn, SPAWN_STACK_SIZE); status = pthread_create(&spawn_thread, &pAttrs_spawn, udp, NULL); if(status) { printf("Task2 create failed status=%d", status); }*/ /* Turn NWP on - initialize the device*/ mode = sl_Start(0, 0, 0); if (mode < 0) { Display_printf(display, 0, 0,"\n\r[line:%d, error code:%d] %s\n\r", __LINE__, mode, DEVICE_ERROR); } if(mode != ROLE_STA) { /* Set NWP role as STA */ mode = sl_WlanSetMode(ROLE_STA); if (mode < 0) { Display_printf(display, 0, 0,"\n\r[line:%d, error code:%d] %s\n\r", __LINE__, mode, WLAN_ERROR); } /* For changes to take affect, we restart the NWP */ status = sl_Stop(SL_STOP_TIMEOUT); if (status < 0) { Display_printf(display, 0, 0,"\n\r[line:%d, error code:%d] %s\n\r", __LINE__, status, DEVICE_ERROR); } mode = sl_Start(0, 0, 0); if (mode < 0) { Display_printf(display, 0, 0,"\n\r[line:%d, error code:%d] %s\n\r", __LINE__, mode, DEVICE_ERROR); } } if(mode != ROLE_STA) { printf("Failed to configure device to it's default state, mode=%d", mode); } Connect(); } void udp (void) { Power_setDependency(PowerCC32XX_PERIPH_TIMERA0); Power_setConstraint(PowerCC32XX_DISALLOW_LPDS); if(init_Merker==1 ) { SlSockAddrIn_t Addr; _i8 SendBuf[]= "HelloWorld!!!"; _i8 RecvBuf[1460]; _i16 AddrSize; SlSockAddr_t *sa; /* Contains the ip address and port of the connected peer. */ SlSockAddr_t *csa; sockAddr_t sAddr; sAddr.in4.sin_family = SL_AF_INET; sAddr.in4.sin_port = sl_Htons((uint16_t)3000); //Port 3000 sAddr.in4.sin_addr.s_addr = SL_INADDR_ANY; sa = (SlSockAddr_t*)&sAddr.in4; csa = (SlSockAddr_t*)&sAddr.in4; AddrSize = sizeof(SlSockAddrIn_t); /* Get UDP sock descriptor - This call opens the socket. */ Sd = sl_Socket(sa->sa_family, SL_SOCK_DGRAM, 0); if( 0 > Sd ) { // error printf("Socket Status: %d", Sd); } Addr.sin_family= SL_AF_INET; Addr.sin_port= sl_Htons(5001); Addr.sin_addr.s_addr= SL_INADDR_ANY; Status= sl_Bind(Sd,( SlSockAddr_t*)&Addr,sizeof(SlSockAddrIn_t)); if( Status) { // error printf("Blind Status: %d", Status); } Addr.sin_family= SL_AF_INET; Addr.sin_port= sl_Htons(5001); Addr.sin_addr.s_addr= sl_Htonl(SL_IPV4_VAL(255,255,255,0)); Status= sl_SendTo(Sd, SendBuf, strlen((const char *)SendBuf), 0, (SlSockAddr_t*)&Addr, sizeof(SlSockAddr_t)); if( strlen((const char *)SendBuf)!= Status) { // error printf("SendTo Status: %d", Status); } AddrSize= sizeof(SlSockAddrIn_t); Status= sl_RecvFrom(Sd, RecvBuf,1460,0, ( SlSockAddr_t*) &Addr, (SlSocklen_t*)&AddrSize); if( 0 > Status) { // error printf("RecvFrom Status: %d", Status); } Status= sl_Close(Sd); if( Status) { // error printf("Close Status: %d", Status); } } }
/* * ======== timerled.c ======== */ /* Standard includes */ #include <stdlib.h> #include <stdio.h> #include <ti/drivers/net/wifi/simplelink.h> #include <stddef.h> /* Driver Header files */ #include <ti/drivers/GPIO.h> #include <ti/drivers/Timer.h> /* Board Header file */ #include "Board.h" #include "test.h" extern int Merker_sem=0; /* Callback used for toggling the LED. */ void timerCallback(Timer_Handle myHandle); void senden(int); int Daten_gpio [3]= {0,1,2}; int Daten_gpio_Merker; int i; extern int Merker; extern void anzeige (void); sem_t *sem_udp; void udp (void); /* * ======== mainThread ======== */ void *mainThread1(void *arg0) { Timer_Handle timer0; Timer_Params params; sem_init(sem_udp,0,0); /* Call driver init functions */ GPIO_init(); Timer_init(); /* Configure the LED pin */ GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); /* Turn off user LED */ GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_OFF); /* Setting up the timer in continuous callback mode that calls the callback * function every 1,000,000 microseconds, or 1 second. */ Timer_Params_init(¶ms); params.period = 1000000; params.periodUnits = Timer_PERIOD_US; params.timerMode = Timer_CONTINUOUS_CALLBACK; params.timerCallback = timerCallback; timer0 = Timer_open(Board_TIMER0, ¶ms); if (timer0 == NULL) { // Failed to initialized timer while (1) {} } if (Timer_start(timer0) == Timer_STATUS_ERROR) { // Failed to start timer while (1) {} } return (NULL); } /* * This callback is called every 1,000,000 microseconds, or 1 second. Because * the LED is toggled each time this function is called, the LED will blink at * a rate of once every 2 seconds. * */ void timerCallback(Timer_Handle myHandle) { GPIO_toggle(Board_GPIO_LED0); udp(); }