//**************************************************************************** // //! \brief OOB Application Main Task - Initializes SimpleLink Driver and //! Handles HTTP Requests //! \param[in] pvParameters is the data passed to the Task //! //! \return None // //**************************************************************************** static void OOBTask(void *pvParameters) { //Read Device Mode Configuration ReadDeviceConfiguration(); //Connect to Network ConnectToNetwork(); //Handle Async Events while(1) { //LED Actions if(g_ucLEDStatus == LED_ON) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); osi_Sleep(500); } if(g_ucLEDStatus == LED_OFF) { GPIO_IF_LedOff(MCU_RED_LED_GPIO); osi_Sleep(500); } if(g_ucLEDStatus==LED_BLINK) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); osi_Sleep(500); GPIO_IF_LedOff(MCU_RED_LED_GPIO); osi_Sleep(500); } } }
//***************************************************************************** // //! Configures the pins as GPIOs and peroidically toggles the lines //! //! \param None //! //! This function //! 1. Configures 3 lines connected to LEDs as GPIO //! 2. Sets up the GPIO pins as output //! 3. Periodically toggles each LED one by one by toggling the GPIO line //! //! \return None // //***************************************************************************** void LEDBlinkyRoutine() { // // Toggle the lines initially to turn off the LEDs. // The values driven are as required by the LEDs on the LP. // GPIO_IF_LedOff(MCU_ALL_LED_IND); while(1) { // // Alternately toggle hi-low each of the GPIOs // to switch the corresponding LED on/off. // MAP_UtilsDelay(8000000); GPIO_IF_LedOn(MCU_RED_LED_GPIO); MAP_UtilsDelay(8000000); GPIO_IF_LedOff(MCU_RED_LED_GPIO); MAP_UtilsDelay(8000000); GPIO_IF_LedOn(MCU_ORANGE_LED_GPIO); MAP_UtilsDelay(8000000); GPIO_IF_LedOff(MCU_ORANGE_LED_GPIO); MAP_UtilsDelay(8000000); GPIO_IF_LedOn(MCU_GREEN_LED_GPIO); MAP_UtilsDelay(8000000); GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); } }
//***************************************************************************** // //! main function demonstrates the use of the timers to generate //! periodic interrupts. //! //! \param None //! //! \return none // //***************************************************************************** int main(void) { // // Initialize board configurations BoardInit(); // // Pinmuxing for LEDs // PinMuxConfig(); // // configure the LED RED and GREEN // GPIO_IF_LedConfigure(LED1|LED3); GPIO_IF_LedOff(MCU_RED_LED_GPIO); GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); // // Base address for first timer // g_ulBase = TIMERA0_BASE; // // Base address for second timer // g_ulRefBase = TIMERA1_BASE; // // Configuring the timers // Timer_IF_Init(PRCM_TIMERA0, g_ulBase, TIMER_CFG_PERIODIC, TIMER_A, 0); Timer_IF_Init(PRCM_TIMERA1, g_ulRefBase, TIMER_CFG_PERIODIC, TIMER_A, 0); // // Setup the interrupts for the timer timeouts. // Timer_IF_IntSetup(g_ulBase, TIMER_A, TimerBaseIntHandler); Timer_IF_IntSetup(g_ulRefBase, TIMER_A, TimerRefIntHandler); // // Turn on the timers feeding values in mSec // Timer_IF_Start(g_ulBase, TIMER_A, 500); Timer_IF_Start(g_ulRefBase, TIMER_A, 1000); // // Loop forever while the timers run. // while(FOREVER) { } }
//***************************************************************************** // //! MicroPhone Control Routine //! //! \param pValue - pointer to a memory structure that is passed //! to the interrupt handler. //! //! \return None // //***************************************************************************** void MicroPhoneControl(void* pValue) { int iCount=0; unsigned long ulPin5Val = 1; //Check whether GPIO Level is Stable As No Debouncing Circuit in LP for(iCount=0;iCount<3;iCount++) { osi_Sleep(200); ulPin5Val = MAP_GPIOPinRead(GPIOA1_BASE,GPIO_PIN_5); if(ulPin5Val) { //False Alarm return; } } if (g_ucMicStartFlag == 0) { for(iCount = 0; iCount<3; iCount++) { //Blink LED 3 times to Indicate ON GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); osi_Sleep(50); GPIO_IF_LedOn(MCU_GREEN_LED_GPIO); osi_Sleep(50); } g_ucMicStartFlag = 1; } else { //Blink LED 3 times to Indicate OFF for(iCount = 0; iCount<3; iCount++) { GPIO_IF_LedOn(MCU_GREEN_LED_GPIO); osi_Sleep(50); GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); osi_Sleep(50); } g_ucMicStartFlag = 0; } //Enable GPIO Interrupt MAP_GPIOIntClear(GPIOA1_BASE,GPIO_PIN_5); MAP_IntPendClear(INT_GPIOA1); MAP_IntEnable(INT_GPIOA1); MAP_GPIOIntEnable(GPIOA1_BASE,GPIO_PIN_5); }
//**************************************************************************** // //! \brief Connecting to a WLAN Accesspoint //! //! This function connects to the required AP (SSID_NAME) with Security //! parameters specified in te form of macros at the top of this file //! //! \param None //! //! \return 0 on success else error code //! //! \warning If the WLAN connection fails or we don't aquire an IP //! address, It will be stuck in this function forever. // //**************************************************************************** long WlanConnect() { long lRetVal = -1; SlSecParams_t secParams; secParams.Key = SECURITY_KEY; secParams.KeyLen = strlen(SECURITY_KEY); secParams.Type = SECURITY_TYPE; lRetVal = sl_WlanConnect(SSID_NAME,strlen(SSID_NAME),0,&secParams,0); ASSERT_ON_ERROR(lRetVal); while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) { // Toggle LEDs to Indicate Connection Progress GPIO_IF_LedOff(MCU_IP_ALLOC_IND); MAP_UtilsDelay(800000); GPIO_IF_LedOn(MCU_IP_ALLOC_IND); MAP_UtilsDelay(800000); } // // Red LED on to indicate AP connection // GPIO_IF_LedOn(MCU_IP_ALLOC_IND); return SUCCESS; }
//***************************************************************************** // //! Periodic Timer Interrupt Handler //! //! \param None //! //! \return None // //***************************************************************************** void TimerPeriodicIntHandler(void) { unsigned long ulInts; // // Clear all pending interrupts from the timer we are // currently using. // ulInts = MAP_TimerIntStatus(TIMERA0_BASE, true); MAP_TimerIntClear(TIMERA0_BASE, ulInts); // // Increment our interrupt counter. // g_usTimerInts++; if(!(g_usTimerInts & 0x1)) { // // Off Led // GPIO_IF_LedOff(MCU_RED_LED_GPIO); } else { // // On Led // GPIO_IF_LedOn(MCU_RED_LED_GPIO); } }
//***************************************************************************** // //! \brief Starts Smart Configuration //! //! \param none //! //! \return void //! \note //! \warning //***************************************************************************** void SmartConfigTask(void* pValue) { long lRetVal = -1; DispatcherUartSendPacket((char*)pucUARTSmartConfigString, sizeof(pucUARTSmartConfigString)); //Turn off the Network Status LED GPIO_IF_LedOff(MCU_IP_ALLOC_IND); LedTimerConfigNStart(); //Reset the Network Status before Entering Smart Config Network_IF_UnsetMCUMachineState(STATUS_BIT_CONNECTION); Network_IF_UnsetMCUMachineState(STATUS_BIT_IP_AQUIRED); lRetVal = SmartConfigConnect(); if(lRetVal < 0) { ERR_PRINT(lRetVal); LOOP_FOREVER(); } // // Wait until IP is acquired // while (!(IS_CONNECTED(Network_IF_CurrentMCUState())) || !(IS_IP_ACQUIRED(Network_IF_CurrentMCUState()))); LedTimerDeinitStop(); // Red LED on GPIO_IF_LedOn(MCU_IP_ALLOC_IND); //Enable GPIO Interrupt Button_IF_EnableInterrupt(SW2); }
//***************************************************************************** // //! The interrupt handler for the watchdog timer //! //! \param None //! //! \return None // //***************************************************************************** void WatchdogIntHandler(void) { // // If we have been told to stop feeding the watchdog, return immediately // without clearing the interrupt. This will cause the system to reset // next time the watchdog interrupt fires. // if(!g_bFeedWatchdog) { return; } // // After 10 interrupts, switch On LED6 to indicate system reset // and don't clear watchdog interrupt which causes system reset // if(g_ulWatchdogCycles >= 10) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); MAP_UtilsDelay(800000); return; } // // Clear the watchdog interrupt. // MAP_WatchdogIntClear(WDT_BASE); GPIO_IF_LedOn(MCU_RED_LED_GPIO); MAP_UtilsDelay(800000); GPIO_IF_LedOff(MCU_RED_LED_GPIO); // // Increment our interrupt counter. // g_ulWatchdogCycles++; }
//**************************************************************************** // //! \brief Connecting to a WLAN Accesspoint //! //! This function connects to the required AP (SSID_NAME) with Security //! parameters specified in te form of macros at the top of this file //! //! \param None //! //! \return 0 on success else error code //! //! \warning If the WLAN connection fails or we don't aquire an IP //! address, It will be stuck in this function forever. // //**************************************************************************** static long WlanConnect() { SlSecParams_t secParams = {0}; long lRetVal = 0; secParams.Key = SECURITY_KEY; secParams.KeyLen = strlen(SECURITY_KEY); secParams.Type = SECURITY_TYPE; lRetVal = sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0); ASSERT_ON_ERROR(lRetVal); // Wait for WLAN Event while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) { // Toggle LEDs to Indicate Connection Progress _SlNonOsMainLoopTask(); GPIO_IF_LedOff(MCU_IP_ALLOC_IND); MAP_UtilsDelay(800000); _SlNonOsMainLoopTask(); GPIO_IF_LedOn(MCU_IP_ALLOC_IND); MAP_UtilsDelay(800000); } return SUCCESS; }
int fm_player(void) { char song_url[128] = {0}; // It's very tricky douban encoding track name into sequence number, so the url is pretty formated int index = 0; Report("Douban FM is ready\r\n"); while(1) { //fm_get_channel(); if(index >= 10) index = 0; else index++; memset(song_url, 0, sizeof(song_url)); fm_get_song(song_url, "1", index); if (strlen(song_url)) { Report("Going to play : %s\r\n", song_url); GPIO_IF_LedOn(MCU_ORANGE_LED_GPIO); fm_play_song(song_url); GPIO_IF_LedOff(MCU_ORANGE_LED_GPIO); } else { // wait for next try Report("Cannot fitch a song to play, waiting for next try\r\n"); osi_Sleep(1000); } } }
static void process_command(struct mg_connection *nc, unsigned char *data, size_t len) { // TODO(lsm): use proper JSON parser int cmd, val; if (sscanf((char *) data, "{\"t\":%d,\"v\":%d}", &cmd, &val) != 2) { LOG(LL_ERROR, ("Invalid request: %.*s", (int) len, data)); return; } if (cmd == 1) { switch (val) { case '0': { GPIO_IF_LedOff(MCU_RED_LED_GPIO); break; } case '1': { GPIO_IF_LedOn(MCU_RED_LED_GPIO); break; } case '2': { GPIO_IF_LedToggle(MCU_RED_LED_GPIO); break; } default: { LOG(LL_ERROR, ("Invalid value: %.*s", (int) len, data)); return; } } } else { LOG(LL_ERROR, ("Unknown command: %.*s", (int) len, data)); return; } }
//**************************************************************************** // //! Toggles the state of GPIOs(LEDs) //! //! \param LedNum is the enumeration for the GPIO to be toggled //! //! \return none // //**************************************************************************** void ToggleLedState(ledEnum LedNum) { unsigned char ledstate = 0; switch(LedNum) { case LED1: ledstate = GPIO_IF_LedStatus(MCU_RED_LED_GPIO); if(!ledstate) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); } else { GPIO_IF_LedOff(MCU_RED_LED_GPIO); } break; case LED2: ledstate = GPIO_IF_LedStatus(MCU_ORANGE_LED_GPIO); if(!ledstate) { GPIO_IF_LedOn(MCU_ORANGE_LED_GPIO); } else { GPIO_IF_LedOff(MCU_ORANGE_LED_GPIO); } break; case LED3: ledstate = GPIO_IF_LedStatus(MCU_GREEN_LED_GPIO); if(!ledstate) { GPIO_IF_LedOn(MCU_GREEN_LED_GPIO); } else { GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); } break; default: break; } }
int main(void) { long lRetVal = -1; // // initialize board configurations // BoardInit(); // // Pinmux GPIO for LEDs // PinMuxConfig(); #ifndef NOTERM // // Configuring UART // InitTerm(); #endif // // Configure LEDs // GPIO_IF_LedConfigure(LED1|LED2|LED3); GPIO_IF_LedOff(MCU_ALL_LED_IND); // // Simplelinkspawntask // lRetVal = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY); if(lRetVal < 0) { ERR_PRINT(lRetVal); LOOP_FOREVER(); } lRetVal = osi_TaskCreate(XmppClient, (const signed char*)"XmppClient",\ OSI_STACK_SIZE, NULL, 1, NULL ); if(lRetVal < 0) { ERR_PRINT(lRetVal); LOOP_FOREVER(); } osi_start(); while(1) { } }
void initBoard() { #ifndef USE_TIRTOS #if defined(ccs) || defined(gcc) MAP_IntVTableBaseSet((unsigned long) &g_pfnVectors[0]); #endif #if defined(ewarm) MAP_IntVTableBaseSet((unsigned long)&__vector_table); #endif #endif MAP_IntMasterEnable(); MAP_IntEnable(FAULT_SYSTICK); PRCMCC3200MCUInit(); PinMuxConfig(); GPIO_IF_LedConfigure(LED1); GPIO_IF_LedOff(MCU_RED_LED_GPIO); InitTerm(); ClearTerm(); UART_PRINT("Blink - Parse for IoT sample application\r\n"); UART_PRINT("----------------------------------------\r\n"); UART_PRINT("\r\n"); UART_PRINT("[Blink] Board init\r\n"); // start the spawn task short status = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY); if (status < 0) { UART_PRINT("[Blink] Spawn task failed\r\n"); ERR_PRINT(status); LOOP_FOREVER(); } // initialize the I2C bus status = I2C_IF_Open(I2C_MASTER_MODE_FST); if (status < 0) { UART_PRINT("[Blink] I2C opening error\r\n"); ERR_PRINT(status); LOOP_FOREVER(); } UART_PRINT("[Blink] Device : TI SimpleLink CC3200\r\n"); #ifdef USE_TIRTOS UART_PRINT("[Blink] Operating system : TI-RTOS\r\n"); #endif #ifdef USE_FREERTOS UART_PRINT("[Blink] Operating system : FreeRTOS\r\n"); #endif #ifndef SL_PLATFORM_MULTI_THREADED UART_PRINT("[Blink] Operating system : None\r\n"); #endif }
void InfiniteLoopTask(void *pvParameters) { // GPIO Configuration GPIO_IF_LedConfigure(LED1|LED3); GPIO_IF_LedOff(MCU_RED_LED_GPIO); TimerConfigNStart(); while(1); }
//***************************************************************************** // //! Toggle the Led state //! //! \param ledNum is the LED Number //! //! \return none //! //! \brief Toggles a board LED // //***************************************************************************** void GPIO_IF_LedToggle(unsigned char ucLedNum) { unsigned char ucLEDStatus = GPIO_IF_LedStatus(ucLedNum); if(ucLEDStatus == 1) { GPIO_IF_LedOff(ucLedNum); } else { GPIO_IF_LedOn(ucLedNum); } }
//**************************************************************************** // //! \brief OOB Application Main Task - Initializes SimpleLink Driver and //! Handles HTTP Requests //! \param[in] pvParameters is the data passed to the Task //! //! \return None // //**************************************************************************** static void OOBTask(void *pvParameters) { long lRetVal = -1; //Read Device Mode Configuration ReadDeviceConfiguration(); //Connect to Network lRetVal = ConnectToNetwork(); if(lRetVal < 0) { ERR_PRINT(lRetVal); LOOP_FOREVER(); } //Handle Async Events while(1) { //LED Actions if(g_ucLEDStatus == LED_ON) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); osi_Sleep(500); } if(g_ucLEDStatus == LED_OFF) { GPIO_IF_LedOff(MCU_RED_LED_GPIO); osi_Sleep(500); } if(g_ucLEDStatus==LED_BLINK) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); osi_Sleep(500); GPIO_IF_LedOff(MCU_RED_LED_GPIO); osi_Sleep(500); } } }
// main task to loop void MainLoop(void *pvParameters) { ButtonInit(); for(;;) { if (val&1) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); } else { GPIO_IF_LedOff(MCU_RED_LED_GPIO); } if (val &(1<<1)) { GPIO_IF_LedOn(MCU_ORANGE_LED_GPIO); } else { GPIO_IF_LedOff(MCU_ORANGE_LED_GPIO); } if (val & (1<<2)) { GPIO_IF_LedOn(MCU_GREEN_LED_GPIO); } else { GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); } } }
//***************************************************************************** // MAIN FUNCTION //***************************************************************************** void main() { // // Board Initialization // BoardInit(); // // configure the GPIO pins for LEDs,UART // PinMuxConfig(); // // Configure the UART // #ifndef NOTERM InitTerm(); #endif //NOTERM // // Display Application Banner // DisplayBanner(APPLICATION_NAME); // // Configure all 3 LEDs // GPIO_IF_LedConfigure(LED1 | LED2 | LED3); // switch off all LEDs GPIO_IF_LedOff(MCU_ALL_LED_IND); FileTest(); /*// // Start the SimpleLink Host // VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY); // // Start the WlanStationMode task // osi_TaskCreate( WlanStationMode, (const signed char*)"Wlan Station Task", OSI_STACK_SIZE, NULL, 1, NULL ); // // Start the task scheduler // osi_start();*/ }
//***************************************************************************** // //! main function demonstrates the use of the watchdog timer to perform system //! reset. //! //! \param None //! //! \return None // //***************************************************************************** void main(void) { tBoolean bRetcode; // // Initialize the board // BoardInit(); // // Pinmuxing for LEDs // PinMuxConfig(); // // configure RED LED // GPIO_IF_LedConfigure(LED1); GPIO_IF_LedOff(MCU_RED_LED_GPIO); // // Enable the peripherals used by this example. // MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK); // // Set up the watchdog interrupt handler. // WDT_IF_Init(WatchdogIntHandler, MILLISECONDS_TO_TICKS(WD_PERIOD_MS)); // // Start the timer. Once the timer is started, it cannot be disable. // MAP_WatchdogEnable(WDT_BASE); bRetcode = MAP_WatchdogRunning(WDT_BASE); if(!bRetcode) { WDT_IF_DeInit(); } // // Loop forever while the LED winks as watchdog interrupts are handled. // while(FOREVER) { } }
/* EFFECTS: Timer Interrupt handler, which toggles the RED led */ void TimerPeriodicIntHandler(void) { unsigned long ulInts; // Clear all pending interrupts from the timer we are currently using. ulInts = MAP_TimerIntStatus(TIMERA0_BASE, true); MAP_TimerIntClear(TIMERA0_BASE, ulInts); // Increment our interrupt counter. if(g_usTimerInts) { GPIO_IF_LedOff(MCU_RED_LED_GPIO); g_usTimerInts = 0; } else { GPIO_IF_LedOn(MCU_RED_LED_GPIO); g_usTimerInts = 1; } }
//**************************************************************************** // //! Main function //! //! \param none //! //! This function //! 1. Invokes the LEDBlinkyTask //! //! \return None. // //**************************************************************************** int main() { // // Initialize Board configurations // BoardInit(); // // Power on the corresponding GPIO port B for 9,10,11. // Set up the GPIO lines to mode 0 (GPIO) // PinMuxConfig(); #ifndef NOTERM // // Configuring UART // InitTerm(); #endif DisplayBanner("Lab 0"); Message("\t\t****************************************************\n\r"); Message("\t\t\t CC3200 UART Echo Usage \n\r"); Message("\t\t To get to state 3, the user must press and hold SW2 \n\r"); Message("\t\t then press SW3 without releasing SW2 \n\r"); Message("\t\t and then release SW2 while continuing to press SW3\n\r"); Message("\n\n\n\r"); GPIO_IF_LedConfigure(LED1|LED2|LED3); GPIO_IF_LedOff(MCU_ALL_LED_IND); // // Start the LEDBlinkyRoutine // LEDBlinkyRoutine(); return 0; }
void launchpad_init(void){ long lRetVal = -1; PinConfigSet(PIN_58, PIN_STRENGTH_2MA | PIN_STRENGTH_4MA, PIN_TYPE_STD_PD); GPIO_IF_LedConfigure(LED1|LED2|LED3); GPIO_IF_LedOff(MCU_ALL_LED_IND); MAP_UtilsDelay(8000000); GPIO_IF_LedOn(MCU_GREEN_LED_GPIO); Report ("Initialize I2C..."); // // I2C Init // lRetVal = I2C_IF_Open(I2C_MASTER_MODE_FST); if(lRetVal < 0) { Report ("Fail!\r\n"); while(1); } Report ("Success\r\n"); }
//**************************************************************************** // //! Main function //! //! \param none //! //! This function //! 1. Invokes the LEDBlinkyTask //! //! \return None. // //**************************************************************************** int main() { // // Initialize Board configurations // BoardInit(); // // Power on the corresponding GPIO port B for 9,10,11. // Set up the GPIO lines to mode 0 (GPIO) // PinMuxConfig(); GPIO_IF_LedConfigure(LED1|LED2|LED3); GPIO_IF_LedOff(MCU_ALL_LED_IND); // // Start the LEDBlinkyRoutine // LEDBlinkyRoutine(); return 0; }
//***************************************************************************** // //! main function demonstrates the use of the watchdog timer to perform system //! reset. //! //! \param None //! //! \return None // //***************************************************************************** void main(void) { tBoolean bRetcode; // // Initialize the board // BoardInit(); // // Pinmuxing for LEDs // PinMuxConfig(); // // configure RED LED // GPIO_IF_LedConfigure(LED1); GPIO_IF_LedOff(MCU_RED_LED_GPIO); // // Set up the watchdog interrupt handler. // WDT_IF_Init(WatchdogIntHandler, MILLISECONDS_TO_TICKS(WD_PERIOD_MS)); bRetcode = MAP_WatchdogRunning(WDT_BASE); if(!bRetcode) { WDT_IF_DeInit(); } // // Loop forever while the LED winks as watchdog interrupts are handled. // while(FOREVER) { } }
//***************************************************************************** // //! This function demonstrates how certificate can be used with SSL. //! The procedure includes the following steps: //! 1) connect to an open AP //! 2) get the server name via a DNS request //! 3) define all socket options and point to the CA certificate //! 4) connect to the server via TCP //! //! \param None //! //! \return 0 on success else error code //! \return LED1 is turned solid in case of success //! LED2 is turned solid in case of failure //! //***************************************************************************** static long ssl() { SlSockAddrIn_t Addr; int iAddrSize; unsigned char ucMethod = SL_SO_SEC_METHOD_SSLV3; unsigned int uiIP,uiCipher = SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA; long lRetVal = -1; int iSockID; GPIO_IF_LedConfigure(LED1|LED3); GPIO_IF_LedOff(MCU_RED_LED_GPIO); GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); lRetVal = InitializeAppVariables(); ASSERT_ON_ERROR(lRetVal); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its default state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if(lRetVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == lRetVal) UART_PRINT("Failed to configure the device in its default state \n\r"); return lRetVal; } UART_PRINT("Device is configured in default state \n\r"); CLR_STATUS_BIT_ALL(g_ulStatus); /// // Assumption is that the device is configured in station mode already // and it is in its default state // lRetVal = sl_Start(0, 0, 0); if (lRetVal < 0 || ROLE_STA != lRetVal) { UART_PRINT("Failed to start the device \n\r"); return lRetVal; } UART_PRINT("Device started as STATION \n\r"); // //Connecting to WLAN AP // lRetVal = WlanConnect(); if(lRetVal < 0) { UART_PRINT("Failed to establish connection w/ an AP \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } UART_PRINT("Connection established w/ AP and IP is aquired \n\r"); //Set time of the device for certificate verification. lRetVal = set_time(); if(lRetVal < 0) { UART_PRINT("Unable to set time in the device"); return lRetVal; } lRetVal = sl_NetAppDnsGetHostByName(g_Host, strlen((const char *)g_Host), (unsigned long*)&uiIP, SL_AF_INET); if(lRetVal < 0) { UART_PRINT("Device couldn't retrive the host name \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } Addr.sin_family = SL_AF_INET; Addr.sin_port = sl_Htons(GOOGLE_DST_PORT); Addr.sin_addr.s_addr = sl_Htonl(uiIP); iAddrSize = sizeof(SlSockAddrIn_t); // // opens a secure socket // iSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET); if( iSockID < 0 ) { UART_PRINT("Device unable to create secure socket \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } // // configure the socket as SSLV3.0 // lRetVal = sl_SetSockOpt(iSockID, SL_SOL_SOCKET, SL_SO_SECMETHOD, &ucMethod,\ sizeof(ucMethod)); if(lRetVal < 0) { UART_PRINT("Device couldn't set socket options \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } // //configure the socket as RSA with RC4 128 SHA // lRetVal = sl_SetSockOpt(iSockID, SL_SOL_SOCKET, SL_SO_SECURE_MASK, &uiCipher,\ sizeof(uiCipher)); if(lRetVal < 0) { UART_PRINT("Device couldn't set socket options \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } // //configure the socket with GOOGLE CA certificate - for server verification // lRetVal = sl_SetSockOpt(iSockID, SL_SOL_SOCKET, \ SL_SO_SECURE_FILES_CA_FILE_NAME, \ SL_SSL_CA_CERT_FILE_NAME, \ strlen(SL_SSL_CA_CERT_FILE_NAME)); if(lRetVal < 0) { UART_PRINT("Device couldn't set socket options \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } lRetVal = sl_SetSockOpt(iSockID, SL_SOL_SOCKET, \ SO_SECURE_DOMAIN_NAME_VERIFICATION, \ g_Host, strlen((const char *)g_Host)); if( lRetVal < 0 ) { UART_PRINT("Device couldn't set socket options \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } /* connect to the peer device - Google server */ lRetVal = sl_Connect(iSockID, ( SlSockAddr_t *)&Addr, iAddrSize); if(lRetVal < 0) { UART_PRINT("Device couldn't connect to Google server \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } GPIO_IF_LedOff(MCU_RED_LED_GPIO); GPIO_IF_LedOn(MCU_GREEN_LED_GPIO); return SUCCESS; }
//***************************************************************************** // //! \brief the aim of this example code is to demonstrate File-system //! capabilities of the device. //! For simplicity, the serial flash is used as the device under test. //! //! \param None //! //! \return none //! //! \note Green LED is turned solid in case of success //! Red LED is turned solid in case of failure // //***************************************************************************** void main() { long lRetVal; unsigned char policyVal; long lFileHandle; unsigned long ulToken; // // Initialize Board configurations // BoardInit(); // // Configure the pinmux settings for the peripherals exercised // PinMuxConfig(); // // Configure LEDs // GPIO_IF_LedConfigure(LED1|LED3); GPIO_IF_LedOff(MCU_RED_LED_GPIO); GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); // // Initializing the CC3200 networking layers // lRetVal = sl_Start(NULL, NULL, NULL); if(lRetVal < 0) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); LOOP_FOREVER(); } // // reset all network policies // lRetVal = sl_WlanPolicySet( SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(0,0,0,0,0), &policyVal, 1 /*PolicyValLen*/); if(lRetVal < 0) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); LOOP_FOREVER(); } if(WriteFileToDevice(&ulToken, &lFileHandle) < 0) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); LOOP_FOREVER(); } if(ReadFileFromDevice(ulToken, lFileHandle) < 0) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); LOOP_FOREVER(); } // // turn ON the green LED indicating success // GPIO_IF_LedOn(MCU_GREEN_LED_GPIO); lRetVal = sl_Stop(SL_STOP_TIMEOUT); LOOP_FOREVER(); }
long ConnectToNetwork() { long lRetVal = -1; unsigned int uiConnectTimeoutCnt =0; //Start Simplelink Device lRetVal = sl_Start(NULL,NULL,NULL); ASSERT_ON_ERROR(lRetVal); if(lRetVal != ROLE_STA) { if (ROLE_AP == lRetVal) { // If the device is in AP mode, we need to wait for this event // before doing anything while(!IS_IP_ACQUIRED(g_ulStatus)) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } } // // Configure to STA Mode // lRetVal = ConfigureMode(ROLE_STA); if(lRetVal !=ROLE_STA) { UART_PRINT("Unable to set STA mode...\n\r"); lRetVal = sl_Stop(SL_STOP_TIMEOUT); CLR_STATUS_BIT_ALL(g_ulStatus); return DEVICE_NOT_IN_STATION_MODE; } } //waiting for the device to Auto Connect while(uiConnectTimeoutCnt<AUTO_CONNECTION_TIMEOUT_COUNT && ((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))) { //Turn Green LED On GPIO_IF_LedOn(MCU_GREEN_LED_GPIO); osi_Sleep(50); //Turn Green LED Off GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); osi_Sleep(50); uiConnectTimeoutCnt++; } //Couldn't connect Using Auto Profile if(uiConnectTimeoutCnt==AUTO_CONNECTION_TIMEOUT_COUNT) { CLR_STATUS_BIT_ALL(g_ulStatus); //Turn Green LED On GPIO_IF_LedOn(MCU_GREEN_LED_GPIO); //Connect Using Smart Config lRetVal = SmartConfigConnect(); ASSERT_ON_ERROR(lRetVal); //Waiting for the device to Auto Connect while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) { MAP_UtilsDelay(500); } //Turn Green LED Off GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); } return SUCCESS; }
int main(void) { long lRetVal = -1; // // Initialize Board configurations // BoardInit(); // // Configure the pinmux settings for the peripherals exercised // PinMuxConfig(); #ifndef NOTERM InitTerm(); #endif // configure RED LED GPIO_IF_LedConfigure(LED1); GPIO_IF_LedOff(MCU_RED_LED_GPIO); InitializeAppVariables(); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its default state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if(lRetVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == lRetVal) UART_PRINT("Failed to configure the device in its " "default state \n\r"); LOOP_FOREVER(); } UART_PRINT("Device is configured in default state \n\r"); CLR_STATUS_BIT_ALL(g_ulStatus); //Start simplelink lRetVal = sl_Start(0,0,0); if (lRetVal < 0 || ROLE_STA != lRetVal) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(); } UART_PRINT("Device started as STATION \n\r"); /* Connect to our AP using SmartConfig method */ lRetVal = SmartConfigConnect(); if(lRetVal < 0) { ERR_PRINT(lRetVal); } LOOP_FOREVER(); }
//***************************************************************************** // //! \brief Generates Random Message and Sends Email to the preconfigured //! Recipient Email Id //! //! \param pValue - pointer to Input Data //! //! \return void //! \note //! \warning //***************************************************************************** void PushButtonMailSend(void* pValue) { int iIndex; long lRetVal = -1; // reset Orange LED GPIO_IF_LedOff(MCU_SENDING_DATA_IND); if(!IS_CONNECTED(Network_IF_CurrentMCUState())) { LedTimerConfigNStart(); lRetVal = Network_IF_ConnectAP(SSID_NAME,SecurityParams); if(lRetVal < 0) { UART_PRINT("Error: %d Connecting to an AP.\n\r",lRetVal); return; } } // // Disable the LED blinking Timer as Device is connected to AP // LedTimerDeinitStop(); // // Switch ON RED LED to indicate that Device acquired an IP // GPIO_IF_LedOn(MCU_IP_ALLOC_IND); MAP_UtilsDelay(10000); GenerateRandomMessage(); g_cConnectStatus = sl_NetAppEmailConnect(); // If return -1, throw connect error if(g_cConnectStatus == -1) { DispatcherUartSendPacket((char*)pucUARTErrorSocketCreateString, \ sizeof(pucUARTErrorSocketCreateString)); } // If return -2, throw socket option error if(g_cConnectStatus == -2) { DispatcherUartSendPacket((char*)pucUARTErrorSocketOptionString, \ sizeof(pucUARTErrorSocketOptionString)); } if(g_cConnectStatus == 0) { SlNetAppServerError_t sEmailErrorInfo; long lRetCode = SL_EMAIL_ERROR_FAILED; if((lRetCode = sl_NetAppEmailSend(pcEmailto,pcEmailsubject,\ pcEmailmessage, \ &sEmailErrorInfo)) == SL_EMAIL_ERROR_NONE) { // Blink LED7 to indicate email has been sent for(iIndex=0 ;iIndex<5 ;iIndex++) { MAP_UtilsDelay(6000000); GPIO_IF_LedOff(MCU_SENDING_DATA_IND); MAP_UtilsDelay(6000000); GPIO_IF_LedOn(MCU_SENDING_DATA_IND); } DispatcherUartSendPacket((char*)putUARTFinishString, \ sizeof(putUARTFinishString)); } else { lRetVal = EmailHandleERROR(lRetCode,(char*)sEmailErrorInfo.Value); } UART_PRINT("Cmd#"); } //Enable GPIO Interrupt Button_IF_EnableInterrupt(SW3); return; }