LocalParseStatus initWifiModule(void) { sint8 ret = 0; tstrWifiInitParam param; /* Initialize the BSP. */ nm_bsp_init(); /* Initialize WIFI parameters structure. */ memset((uint8_t *)¶m, 0, sizeof(tstrWifiInitParam)); param.pfAppWifiCb = fluffy_wifi_noti_cb; /* Initialize WINC1500 WIFI driver with data and status callbacks. */ ret = m2m_wifi_init(¶m); if (M2M_SUCCESS != ret) { printf("initWifiModule / m2m_wifi_init call error!(%d)\r\n", ret); return LOCAL_PARSE_ERROR_UNKNOWN; } /* Initialize Socket module */ fluffy_trans_init_socket(); #ifdef ENABLE_MDNS /* Initialize the Timer. */ configure_timer(); #endif return LOCAL_PARSE_SUCCESS; }
/** * \brief Main application function. * * Initializing the board and connect to wireless router. * And event handling the Wi-Fi and SW timer. */ int main(void) { tstrWifiInitParam param; int8_t ret; /* Initialize the board. */ system_init(); /* Initialize the UART console. */ configure_console(); /* Initialize the Timer. */ configure_timer(); /* Initialize the HTTP client service. */ configure_http_client(); /* Initialize the BSP. */ nm_bsp_init(); /* Output example information */ printf(STRING_HEADER); /* Initialize Wi-Fi driver with data and Wi-Fi status callbacks. */ param.pfAppWifiCb = wifi_callback; /* Set Wi-Fi event callback. */ ret = m2m_wifi_init(¶m); if (M2M_SUCCESS != ret) { printf("main: m2m_wifi_init call error!(%d)\r\n", ret); while (1) { /* Loop forever. */ } } /* Initialize Socket module */ socketInit(); registerSocketCallback(socket_event_handler, socket_resolve_handler); /* Connect to router. */ ret = m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL); if (M2M_SUCCESS != ret) { printf("main: failed to connect access point!\r\n"); while (1) { } } while (1) { /* Handle pending events from network controller. */ m2m_wifi_handle_events(NULL); /* Checks the timer timeout. */ sw_timer_task(&swt_module_inst); } }
void test_timer() { //clock is 50mz, 2*10^-8 * 1000000*255 is about 5 seconds set_maxcount_timer0(1000000); set_maxcount_timer1(100000); unsigned int conf = 0xE1FFF0FF; //timer 1: enable interrupt, continuous mode, //timer 0: enable interrupt, continuous mode, watch dog configure_timer(conf); int i; int j; for(i=0;i<1000000000;i++) {j++;} conf = 0x00000000; //only disable timer configure_timer(conf); }
// system initialization void init() { // set up PIT for jiffies count configure_timer(); // Spurious interrupt handler // overrides default 'black hole' handler, // necessary when something generates an interrupt storm AT91C_BASE_AIC->AIC_SPU = (unsigned int) spuriousInterruptHandler; // set up LED IO pins AT91C_BASE_PMC->PMC_PCER = (1 << PIN_LED_ID); PIN_LED_PIO->PIO_PER = PIN_LED_MASK; PIN_LED_PIO->PIO_PPUDR = PIN_LED_MASK; PIN_LED_PIO->PIO_OER = PIN_LED_OESET; PIN_LED_PIO->PIO_ODR = PIN_LED_OECLR; PIN_LED_PIO->PIO_CODR = PIN_LED_MASK; // set up USART usart.set_tx_buffer(usart_txbuf, USART_TX_BUF_SIZE); usart.set_rx_buffer(usart_rxbuf, USART_RX_BUF_SIZE); usart.begin(115200); }
/** * \brief Main application function. * * Application entry point. * * \return program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; init_state(); /* Initialize the board. */ sysclk_init(); board_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); printf("This example may not work as it requires internet connectivity.\r\n"); /* Initialize the Timer. */ configure_timer(); /* Initialize the HTTP client service. */ configure_http_client(); /* Initialize the BSP. */ nm_bsp_init(); /* Initialize SD/MMC storage. */ init_storage(); /* Initialize Wi-Fi parameters structure. */ memset((uint8_t *)¶m, 0, sizeof(tstrWifiInitParam)); /* Initialize Wi-Fi driver with data and status callbacks. */ param.pfAppWifiCb = wifi_cb; ret = m2m_wifi_init(¶m); if (M2M_SUCCESS != ret) { printf("main: m2m_wifi_init call error!(%d)\r\n", ret); while (1) { } } /* Initialize socket module. */ socketInit(); /* Register socket callback function. */ registerSocketCallback(socket_cb, resolve_cb); /* Connect to router. */ printf("main: Waiting for Wi-Fi connection. AP:%s\r\n", (char *)MAIN_WLAN_SSID); m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL); while (!(is_state_set(COMPLETED) || is_state_set(CANCELED))) { /* Handle pending events from network controller. */ m2m_wifi_handle_events(NULL); /* Checks the timer timeout. */ sw_timer_task(&swt_module_inst); } printf("main: Exit program. Please unplug the card.\r\n"); while (1) { } /* Loop forever. */ return 0; }
/** * \brief Main application function. * * Application entry point. * * \return program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; char topic[strlen(MAIN_CHAT_TOPIC) + MAIN_CHAT_USER_NAME_SIZE + 1]; /* Initialize the board. */ system_init(); /* Initialize the UART console. */ configure_console(); /* Output example information */ printf(STRING_HEADER); /* Initialize the Timer. */ configure_timer(); /* Initialize the MQTT service. */ configure_mqtt(); /* Initialize the BSP. */ nm_bsp_init(); /* Setup user name first */ printf("Enter the user name (Max %d characters)\r\n", MAIN_CHAT_USER_NAME_SIZE); scanf("%64s", mqtt_user); printf("User : %s\r\n", mqtt_user); sprintf(topic, "%s%s", MAIN_CHAT_TOPIC, mqtt_user); /* Initialize Wi-Fi parameters structure. */ memset((uint8_t *)¶m, 0, sizeof(tstrWifiInitParam)); /* Initialize Wi-Fi driver with data and status callbacks. */ param.pfAppWifiCb = wifi_callback; /* Set Wi-Fi event callback. */ ret = m2m_wifi_init(¶m); if (M2M_SUCCESS != ret) { printf("main: m2m_wifi_init call error!(%d)\r\n", ret); while (1) { /* Loop forever. */ } } /* Initialize socket interface. */ socketInit(); registerSocketCallback(socket_event_handler, socket_resolve_handler); /* Connect to router. */ m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL); while (1) { /* Handle pending events from network controller. */ m2m_wifi_handle_events(NULL); /* Try to read user input from USART. */ usart_read_job(&cdc_uart_module, &uart_ch_buffer); /* Checks the timer timeout. */ sw_timer_task(&swt_module_inst); /* Checks the USART buffer. */ check_usart_buffer(topic); } }