Extending the X_NUCLEO_IDW01M1 to allow configuration of the board as an access point
Dependents: X_NUCLEO_IDW01M1_AP_Test
Fork of X_NUCLEO_IDW01M1 by
spwf/wifi_driver.c
- Committer:
- mridup
- Date:
- 2016-04-13
- Revision:
- 0:dc55f40eb04f
File content as of revision 0:dc55f40eb04f:
/** ****************************************************************************** * @file wifi_driver.c * @author Central LAB * @version V2.0.0 * @date 01-March-2016 * @brief Enable Wi-Fi functionality using AT cmd set ****************************************************************************** * @attention * * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include <stddef.h> #include "wifi_module.h" #include "ring_buffer.h" #include "device.h" #include "wait_api.h" #include "stdio.h" #include "string.h" #include "wifi_driver.h" void Wifi_ticker(void) { Wifi_SysTick_Isr(); } void Wifi_scheduler(void) { Wifi_TIM_Handler(); } void Rx_irq_handler(void) { uint8_t data_byte = (uint8_t)callSpwfSADevice_getChar(spwf_dev); status_flag.Uartx_Rx_Processing = WIFI_FALSE; Stop_Timer(); __disable_irq(); push_buffer(&big_buff, &data_byte); __enable_irq(); Start_Timer(); status_flag.Uartx_Rx_Processing = WIFI_TRUE; /*if(is_half_full(&big_buff)) { status_flag.resume_receive_data = WIFI_TRUE; if(callSpwfSADevice_read_rts(spwf_dev)) callSpwfSADevice_rts(spwf_dev, GPIO_PIN_SET); //callSpwfSADevice_attach(0); } else { if(status_flag.AT_Cmd_Processing == WIFI_FALSE) { status_flag.Uartx_Rx_Processing = WIFI_TRUE; } }*/ } /** * @brief wifi_reset * Reset WiFi module using PC12 gpio pin * @param None * @retval None */ void wifi_reset(void) { WiFi_Module_State = Process_Event; WiFi_WIND_State.WiFiHWStarted = WIFI_FALSE; wifi_connected = 0; //reset wifi_connected to get user callback memset((void*)&WiFi_WIND_State,0x00,sizeof(WiFi_WIND_State)); /*reset the WIND State?*/ /* === RESET PIN - PC12 ===*/ callSpwfSADevice_reset(spwf_dev, 0); wait_ms(100); callSpwfSADevice_reset(spwf_dev, 1); wait_ms(100); while(WiFi_WIND_State.WiFiHWStarted != WIFI_TRUE) { //nothing to do __NOP(); } } /** * @brief PowerUp_WiFi_Module * Power up Wi-Fi module,SET GPIO PA0 pin * @param None * @retval None */ void PowerUp_WiFi_Module(void) { /* === SET PIN - PC12 ===*/ callSpwfSADevice_reset(spwf_dev, 1); wait_ms(50); } /** * @brief Receive_Data * Receive data from UART port * @param uint8_t number of bytes to be received * @retval None */ void Receive_Data(void) { callSpwfSADevice_rts(spwf_dev, 0); } /** * @brief USART_Transmit_AT_Cmd * send AT cmd on UART port of wifi module. * @param size size of the AT command * @retval WiFi_Status_t : status of AT cmd */ WiFi_Status_t USART_Transmit_AT_Cmd(uint16_t size) { //Check for Hardware Started if(status_flag.WiFi_Enabled == WIFI_FALSE) return WiFi_NOT_READY; //Check for Deep-Sleep or Standby Mode, return error if true if (status_flag.Standby_Enabled == WIFI_TRUE || status_flag.Deep_Sleep_Enabled == WIFI_TRUE) return WiFi_IN_LOW_POWER_ERROR; status_flag.AT_Cmd_Processing = WIFI_TRUE;//Stop Any Rx between the TX call if (size == 0) { return WiFi_UNHANDLED_IND_ERROR; } #if defined(USART3_INT_MODE) if(HAL_UART_Transmit_IT(&UartWiFiHandle, (uint8_t *)WiFi_AT_Cmd_Buff, size)!= HAL_OK) { Error_Handler(); return WiFi_HAL_UART_ERROR; } while (UartReady != SET); UartReady = RESET; #elif defined(USART3_POLLING_MODE) callSpwfSADevice_write(spwf_dev, (const char *) WiFi_AT_Cmd_Buff, size); #else #error "Please select USART mode in your application (in wifi_module.h file)" #endif status_flag.AT_Cmd_Processing = WIFI_FALSE;//Re-enable Rx for UART if(status_flag.Uartx_Rx_Processing == WIFI_FALSE) Receive_Data();//Start receiving Rx from the UART again, if and only if it was stopped in the previous Uartx_Rx_Handler return WiFi_MODULE_SUCCESS; }