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 ST

Committer:
mridup
Date:
Thu Apr 14 06:14:14 2016 +0000
Revision:
1:bd9db471d47d
Parent:
spwf/utils/event_buffer.c@0:dc55f40eb04f
increasing reset delay to 200ms due to problem with L4 reset

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mridup 0:dc55f40eb04f 1 /**
mridup 0:dc55f40eb04f 2 ******************************************************************************
mridup 0:dc55f40eb04f 3 * @file event_buffer.c
mridup 0:dc55f40eb04f 4 * @author Central LAB
mridup 0:dc55f40eb04f 5 * @version V2.0.0
mridup 0:dc55f40eb04f 6 * @date 10-February-2016
mridup 0:dc55f40eb04f 7 * @brief Implements the Event Buffer management of the Wi-Fi module
mridup 0:dc55f40eb04f 8 ******************************************************************************
mridup 0:dc55f40eb04f 9 * @attention
mridup 0:dc55f40eb04f 10 *
mridup 0:dc55f40eb04f 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mridup 0:dc55f40eb04f 12 *
mridup 0:dc55f40eb04f 13 * Redistribution and use in source and binary forms, with or without modification,
mridup 0:dc55f40eb04f 14 * are permitted provided that the following conditions are met:
mridup 0:dc55f40eb04f 15 * 1. Redistributions of source code must retain the above copyright notice,
mridup 0:dc55f40eb04f 16 * this list of conditions and the following disclaimer.
mridup 0:dc55f40eb04f 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
mridup 0:dc55f40eb04f 18 * this list of conditions and the following disclaimer in the documentation
mridup 0:dc55f40eb04f 19 * and/or other materials provided with the distribution.
mridup 0:dc55f40eb04f 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mridup 0:dc55f40eb04f 21 * may be used to endorse or promote products derived from this software
mridup 0:dc55f40eb04f 22 * without specific prior written permission.
mridup 0:dc55f40eb04f 23 *
mridup 0:dc55f40eb04f 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mridup 0:dc55f40eb04f 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mridup 0:dc55f40eb04f 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mridup 0:dc55f40eb04f 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mridup 0:dc55f40eb04f 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mridup 0:dc55f40eb04f 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mridup 0:dc55f40eb04f 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mridup 0:dc55f40eb04f 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mridup 0:dc55f40eb04f 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mridup 0:dc55f40eb04f 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mridup 0:dc55f40eb04f 34 *
mridup 0:dc55f40eb04f 35 ******************************************************************************
mridup 0:dc55f40eb04f 36 */
mridup 0:dc55f40eb04f 37
mridup 0:dc55f40eb04f 38 #include <stdio.h>
mridup 0:dc55f40eb04f 39 #include <stdlib.h>
mridup 0:dc55f40eb04f 40 #include "event_buffer.h"
mridup 0:dc55f40eb04f 41 #include "wifi_module.h"
mridup 0:dc55f40eb04f 42
mridup 0:dc55f40eb04f 43 /** @addtogroup BSP
mridup 0:dc55f40eb04f 44 * @{
mridup 0:dc55f40eb04f 45 */
mridup 0:dc55f40eb04f 46
mridup 0:dc55f40eb04f 47
mridup 0:dc55f40eb04f 48 /** @defgroup NUCLEO_WIFI_BUFFER_MGMT
mridup 0:dc55f40eb04f 49 * @brief Wi-Fi_driver modules
mridup 0:dc55f40eb04f 50 * @{
mridup 0:dc55f40eb04f 51 */
mridup 0:dc55f40eb04f 52
mridup 0:dc55f40eb04f 53
mridup 0:dc55f40eb04f 54 /** @defgroup NUCLEO_WIFI_BUFFER_MGMT_Private_Defines
mridup 0:dc55f40eb04f 55 * @{
mridup 0:dc55f40eb04f 56 */
mridup 0:dc55f40eb04f 57
mridup 0:dc55f40eb04f 58 /**
mridup 0:dc55f40eb04f 59 * @}
mridup 0:dc55f40eb04f 60 */
mridup 0:dc55f40eb04f 61
mridup 0:dc55f40eb04f 62 /** @defgroup NUCLEO_WIFI_BUFFER_MGMT_Private_Variables
mridup 0:dc55f40eb04f 63 * @{
mridup 0:dc55f40eb04f 64 */
mridup 0:dc55f40eb04f 65 extern event_s_TypeDef event_buffer[1024];
mridup 0:dc55f40eb04f 66 #define ELEMENT_SIZE sizeof(event_s_TypeDef) //1
mridup 0:dc55f40eb04f 67
mridup 0:dc55f40eb04f 68 //extern UART_HandleTypeDef UartMsgHandle;
mridup 0:dc55f40eb04f 69 //extern char print_msg_buff[512];
mridup 0:dc55f40eb04f 70 extern event_s_TypeDef element;
mridup 0:dc55f40eb04f 71
mridup 0:dc55f40eb04f 72 /*
mridup 0:dc55f40eb04f 73 #ifdef USART_PRINT_MSG
mridup 0:dc55f40eb04f 74 #define printf(arg) sprintf((char*)print_msg_buff,arg); \
mridup 0:dc55f40eb04f 75 HAL_UART_Transmit(&UartMsgHandle, (uint8_t*)print_msg_buff, strlen(print_msg_buff), 1000);
mridup 0:dc55f40eb04f 76 #endif
mridup 0:dc55f40eb04f 77 */
mridup 0:dc55f40eb04f 78
mridup 0:dc55f40eb04f 79 /**
mridup 0:dc55f40eb04f 80 * @}
mridup 0:dc55f40eb04f 81 */
mridup 0:dc55f40eb04f 82
mridup 0:dc55f40eb04f 83 /** @defgroup NUCLEO_WIFI_BUFFER_MGMT_Private_Functions
mridup 0:dc55f40eb04f 84 * @{
mridup 0:dc55f40eb04f 85 */
mridup 0:dc55f40eb04f 86
mridup 0:dc55f40eb04f 87 /**
mridup 0:dc55f40eb04f 88 * @brief init
mridup 0:dc55f40eb04f 89 * Initialize a circular buffer of type buffer_t
mridup 0:dc55f40eb04f 90 * @param None
mridup 0:dc55f40eb04f 91 * @retval None
mridup 0:dc55f40eb04f 92 */
mridup 0:dc55f40eb04f 93 void event_init(buffer_e *buffer, int size) {
mridup 0:dc55f40eb04f 94 uint32_t element_size;
mridup 0:dc55f40eb04f 95 element_size = sizeof(event_s_TypeDef);
mridup 0:dc55f40eb04f 96 buffer->size = element_size*size;
mridup 0:dc55f40eb04f 97 buffer->start = 0;
mridup 0:dc55f40eb04f 98 buffer->count = 0;
mridup 0:dc55f40eb04f 99 buffer->end = 0;
mridup 0:dc55f40eb04f 100 buffer->element = event_buffer;
mridup 0:dc55f40eb04f 101 }
mridup 0:dc55f40eb04f 102
mridup 0:dc55f40eb04f 103 /**
mridup 0:dc55f40eb04f 104 * @brief full
mridup 0:dc55f40eb04f 105 * indicates if the given buffer is full or not
mridup 0:dc55f40eb04f 106 * @param None
mridup 0:dc55f40eb04f 107 * @retval None
mridup 0:dc55f40eb04f 108 */
mridup 0:dc55f40eb04f 109 int event_full(buffer_e *buffer)
mridup 0:dc55f40eb04f 110 {
mridup 0:dc55f40eb04f 111 int bufsize = buffer->size;
mridup 0:dc55f40eb04f 112 if (buffer->count == (bufsize/ELEMENT_SIZE))
mridup 0:dc55f40eb04f 113 {
mridup 0:dc55f40eb04f 114 return 1;
mridup 0:dc55f40eb04f 115 }
mridup 0:dc55f40eb04f 116 else
mridup 0:dc55f40eb04f 117 {
mridup 0:dc55f40eb04f 118 return 0;
mridup 0:dc55f40eb04f 119 }
mridup 0:dc55f40eb04f 120 }
mridup 0:dc55f40eb04f 121
mridup 0:dc55f40eb04f 122 /**
mridup 0:dc55f40eb04f 123 * @brief empty
mridup 0:dc55f40eb04f 124 * indicates if the given buffer is empty or not
mridup 0:dc55f40eb04f 125 * @param None
mridup 0:dc55f40eb04f 126 * @retval None
mridup 0:dc55f40eb04f 127 */
mridup 0:dc55f40eb04f 128 int event_empty(buffer_e *buffer) {
mridup 0:dc55f40eb04f 129 if (buffer->count == 0) {
mridup 0:dc55f40eb04f 130 return 1;
mridup 0:dc55f40eb04f 131 } else {
mridup 0:dc55f40eb04f 132 return 0;
mridup 0:dc55f40eb04f 133 }
mridup 0:dc55f40eb04f 134 }
mridup 0:dc55f40eb04f 135
mridup 0:dc55f40eb04f 136 /**
mridup 0:dc55f40eb04f 137 * @brief push_buffer
mridup 0:dc55f40eb04f 138 * pushes the data structure onto the circular buffer (queues it)
mridup 0:dc55f40eb04f 139 * @param None
mridup 0:dc55f40eb04f 140 * @retval None
mridup 0:dc55f40eb04f 141 */
mridup 0:dc55f40eb04f 142 void push_eventbuffer(buffer_e *buffer, event_s_TypeDef data)
mridup 0:dc55f40eb04f 143 {
mridup 0:dc55f40eb04f 144 int bufsize;
mridup 0:dc55f40eb04f 145 uint32_t index;
mridup 0:dc55f40eb04f 146
mridup 0:dc55f40eb04f 147 if (event_full(buffer))
mridup 0:dc55f40eb04f 148 {
mridup 0:dc55f40eb04f 149 //Buffer overflow and no more space
mridup 0:dc55f40eb04f 150 //MPD: No Action taken here; in case of buffer overflow, do we need to overwrite last buffer?
mridup 0:dc55f40eb04f 151 //printf("\r\nRing Buffer Full!!\r\n");
mridup 0:dc55f40eb04f 152 //printf(data);
mridup 0:dc55f40eb04f 153 return;
mridup 0:dc55f40eb04f 154 } else
mridup 0:dc55f40eb04f 155 {
mridup 0:dc55f40eb04f 156 index=buffer->end/ELEMENT_SIZE;
mridup 0:dc55f40eb04f 157 buffer->element[index].data_length = data.data_length;
mridup 0:dc55f40eb04f 158 buffer->element[index].wind64_pending_packet_no = data.wind64_pending_packet_no;
mridup 0:dc55f40eb04f 159 buffer->element[index].enc = data.enc;
mridup 0:dc55f40eb04f 160 buffer->element[index].ok_eval = data.ok_eval;
mridup 0:dc55f40eb04f 161 buffer->element[index].socket_id = data.socket_id;
mridup 0:dc55f40eb04f 162 buffer->element[index].wind = data.wind;
mridup 0:dc55f40eb04f 163 buffer->element[index].event = data.event;
mridup 0:dc55f40eb04f 164 buffer->element[index].event_pop = data.event_pop;
mridup 0:dc55f40eb04f 165 buffer->count++;
mridup 0:dc55f40eb04f 166 buffer->end = buffer->end + ELEMENT_SIZE;
mridup 0:dc55f40eb04f 167
mridup 0:dc55f40eb04f 168 //wrap around if max size is reached
mridup 0:dc55f40eb04f 169 bufsize = (buffer->size);
mridup 0:dc55f40eb04f 170 if (buffer->end >= bufsize)
mridup 0:dc55f40eb04f 171 {
mridup 0:dc55f40eb04f 172 buffer->end = 0;
mridup 0:dc55f40eb04f 173 }
mridup 0:dc55f40eb04f 174 }
mridup 0:dc55f40eb04f 175 }
mridup 0:dc55f40eb04f 176
mridup 0:dc55f40eb04f 177 /**
mridup 0:dc55f40eb04f 178 * @brief pop_buffer_queue
mridup 0:dc55f40eb04f 179 * dequeues the circular buffer
mridup 0:dc55f40eb04f 180 * @param None
mridup 0:dc55f40eb04f 181 * @retval None
mridup 0:dc55f40eb04f 182 */
mridup 0:dc55f40eb04f 183 event_s_TypeDef * pop_eventbuffer_queue(buffer_e *buffer)
mridup 0:dc55f40eb04f 184 {
mridup 0:dc55f40eb04f 185 int bufsize;
mridup 0:dc55f40eb04f 186 uint32_t index;
mridup 0:dc55f40eb04f 187
mridup 0:dc55f40eb04f 188 if (event_empty(buffer))
mridup 0:dc55f40eb04f 189 {
mridup 0:dc55f40eb04f 190 //printf("\r\Event Buffer Empty!!\r\n");
mridup 0:dc55f40eb04f 191 return NULL;
mridup 0:dc55f40eb04f 192 }
mridup 0:dc55f40eb04f 193 else
mridup 0:dc55f40eb04f 194 {
mridup 0:dc55f40eb04f 195 /* First in First Out*/
mridup 0:dc55f40eb04f 196 index=buffer->start/ELEMENT_SIZE;
mridup 0:dc55f40eb04f 197 element.data_length = buffer->element[index].data_length;
mridup 0:dc55f40eb04f 198 element.enc = buffer->element[index].enc;
mridup 0:dc55f40eb04f 199 element.ok_eval = buffer->element[index].ok_eval;
mridup 0:dc55f40eb04f 200 element.socket_id = buffer->element[index].socket_id;
mridup 0:dc55f40eb04f 201 element.wind64_pending_packet_no = buffer->element[index].wind64_pending_packet_no;
mridup 0:dc55f40eb04f 202 element.wind = buffer->element[index].wind;
mridup 0:dc55f40eb04f 203 element.event = buffer->element[index].event;
mridup 0:dc55f40eb04f 204 element.event_pop = buffer->element[index].event_pop;
mridup 0:dc55f40eb04f 205 buffer->start = buffer->start + ELEMENT_SIZE;
mridup 0:dc55f40eb04f 206 buffer->count--;
mridup 0:dc55f40eb04f 207
mridup 0:dc55f40eb04f 208 bufsize = (buffer->size);
mridup 0:dc55f40eb04f 209 if (buffer->start >= bufsize)
mridup 0:dc55f40eb04f 210 {
mridup 0:dc55f40eb04f 211 buffer->start = 0;
mridup 0:dc55f40eb04f 212 }
mridup 0:dc55f40eb04f 213 return &element;
mridup 0:dc55f40eb04f 214 }
mridup 0:dc55f40eb04f 215 }
mridup 0:dc55f40eb04f 216
mridup 0:dc55f40eb04f 217 void reset_event(event_s_TypeDef *r_event)
mridup 0:dc55f40eb04f 218 {
mridup 0:dc55f40eb04f 219 r_event->data_length = 0;
mridup 0:dc55f40eb04f 220 r_event->enc = WIFI_FALSE;
mridup 0:dc55f40eb04f 221 r_event->event = WIFI_NO_EVENT;
mridup 0:dc55f40eb04f 222 r_event->ok_eval = WIFI_FALSE;
mridup 0:dc55f40eb04f 223 r_event->socket_id = 9; //Socket ID 0-7
mridup 0:dc55f40eb04f 224 r_event->wind64_pending_packet_no = 9; //Max pending packets = 4
mridup 0:dc55f40eb04f 225 r_event->wind = 99; //any default value
mridup 0:dc55f40eb04f 226 r_event->event_pop = WIFI_TRUE;
mridup 0:dc55f40eb04f 227 }
mridup 0:dc55f40eb04f 228
mridup 0:dc55f40eb04f 229 /**
mridup 0:dc55f40eb04f 230 * @}
mridup 0:dc55f40eb04f 231 */
mridup 0:dc55f40eb04f 232
mridup 0:dc55f40eb04f 233 /**
mridup 0:dc55f40eb04f 234 * @}
mridup 0:dc55f40eb04f 235 */
mridup 0:dc55f40eb04f 236
mridup 0:dc55f40eb04f 237
mridup 0:dc55f40eb04f 238 /**
mridup 0:dc55f40eb04f 239 * @}
mridup 0:dc55f40eb04f 240 */
mridup 0:dc55f40eb04f 241
mridup 0:dc55f40eb04f 242 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/