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/utils/ring_buffer.c@22:a1276b7d3b2d, 2016-07-07 (annotated)
- Committer:
- scsims
- Date:
- Thu Jul 07 13:54:06 2016 +0000
- Revision:
- 22:a1276b7d3b2d
- Parent:
- 1:bd9db471d47d
Added wifi_connected_to_ap extern to indicate when BSSS beacons have been lost/picked up. Also added some debugging to get a better idea as to what's going to and from the SPWF01SA.11 over the UART
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mridup | 0:dc55f40eb04f | 1 | /** |
mridup | 0:dc55f40eb04f | 2 | ****************************************************************************** |
mridup | 0:dc55f40eb04f | 3 | * @file ring_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 Circular 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>© 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 "ring_buffer.h" |
mridup | 0:dc55f40eb04f | 41 | #include "wifi_module.h" |
mridup | 0:dc55f40eb04f | 42 | |
mridup | 0:dc55f40eb04f | 43 | /** @addtogroup MIDDLEWARES |
mridup | 0:dc55f40eb04f | 44 | * @{ |
mridup | 0:dc55f40eb04f | 45 | */ |
mridup | 0:dc55f40eb04f | 46 | |
mridup | 0:dc55f40eb04f | 47 | |
mridup | 0:dc55f40eb04f | 48 | /** @defgroup NUCLEO_WIFI_UTILS |
mridup | 0:dc55f40eb04f | 49 | * @brief Wi-Fi buffer utility |
mridup | 0:dc55f40eb04f | 50 | * @{ |
mridup | 0:dc55f40eb04f | 51 | */ |
mridup | 0:dc55f40eb04f | 52 | |
mridup | 0:dc55f40eb04f | 53 | |
mridup | 0:dc55f40eb04f | 54 | /** @defgroup NUCLEO_WIFI_UTILS_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_UTILS_Private_Variables |
mridup | 0:dc55f40eb04f | 63 | * @{ |
mridup | 0:dc55f40eb04f | 64 | */ |
mridup | 0:dc55f40eb04f | 65 | |
mridup | 0:dc55f40eb04f | 66 | extern uint8_t ring_buffer[RINGBUF_SIZE]; |
mridup | 0:dc55f40eb04f | 67 | extern uint8_t pop_buffer[MAX_BUFFER_GLOBAL]; |
mridup | 0:dc55f40eb04f | 68 | extern uint8_t prefetch_buffer[20]; |
mridup | 0:dc55f40eb04f | 69 | //extern wifi_bool enable_receive_data_chunk; |
mridup | 0:dc55f40eb04f | 70 | extern volatile Wifi_Status_Var status_flag; |
mridup | 0:dc55f40eb04f | 71 | extern uint32_t pop_buffer_size; |
mridup | 0:dc55f40eb04f | 72 | |
mridup | 0:dc55f40eb04f | 73 | #define ELEMENT_SIZE 1 |
mridup | 0:dc55f40eb04f | 74 | |
mridup | 0:dc55f40eb04f | 75 | |
mridup | 0:dc55f40eb04f | 76 | /** |
mridup | 0:dc55f40eb04f | 77 | * @} |
mridup | 0:dc55f40eb04f | 78 | */ |
mridup | 0:dc55f40eb04f | 79 | |
mridup | 0:dc55f40eb04f | 80 | /** @defgroup NUCLEO_WIFI_UTILS_Private_Functions |
mridup | 0:dc55f40eb04f | 81 | * @{ |
mridup | 0:dc55f40eb04f | 82 | */ |
mridup | 0:dc55f40eb04f | 83 | |
mridup | 0:dc55f40eb04f | 84 | /** |
mridup | 0:dc55f40eb04f | 85 | * @brief init |
mridup | 0:dc55f40eb04f | 86 | * Initialize a circular buffer of type buffer_td |
mridup | 0:dc55f40eb04f | 87 | * @param None |
mridup | 0:dc55f40eb04f | 88 | * @retval None |
mridup | 0:dc55f40eb04f | 89 | */ |
mridup | 0:dc55f40eb04f | 90 | void init(buffer_td *buffer, int size) |
mridup | 0:dc55f40eb04f | 91 | { |
mridup | 0:dc55f40eb04f | 92 | buffer->size = size; |
mridup | 0:dc55f40eb04f | 93 | buffer->start = 0; |
mridup | 0:dc55f40eb04f | 94 | buffer->count = 0; |
mridup | 0:dc55f40eb04f | 95 | buffer->end = 0; |
mridup | 0:dc55f40eb04f | 96 | buffer->element = ring_buffer; |
mridup | 0:dc55f40eb04f | 97 | } |
mridup | 0:dc55f40eb04f | 98 | |
mridup | 0:dc55f40eb04f | 99 | /** |
mridup | 0:dc55f40eb04f | 100 | * @brief flush_buffer_queue |
mridup | 0:dc55f40eb04f | 101 | * flushes the buffer |
mridup | 0:dc55f40eb04f | 102 | * @param None |
mridup | 0:dc55f40eb04f | 103 | * @retval None |
mridup | 0:dc55f40eb04f | 104 | */ |
mridup | 0:dc55f40eb04f | 105 | void flush_buffer_queue(buffer_td *buffer) |
mridup | 0:dc55f40eb04f | 106 | { |
mridup | 0:dc55f40eb04f | 107 | buffer->start = buffer->end;//the tail goes up to the head and buffer becomes empty |
mridup | 0:dc55f40eb04f | 108 | buffer->count = 0; |
mridup | 0:dc55f40eb04f | 109 | } |
mridup | 0:dc55f40eb04f | 110 | |
mridup | 0:dc55f40eb04f | 111 | /** |
mridup | 0:dc55f40eb04f | 112 | * @brief is_half_full |
mridup | 0:dc55f40eb04f | 113 | * checks if the buffer is half full (empty) |
mridup | 0:dc55f40eb04f | 114 | * @param None |
mridup | 0:dc55f40eb04f | 115 | * @retval None |
mridup | 0:dc55f40eb04f | 116 | */ |
mridup | 0:dc55f40eb04f | 117 | int is_half_full(buffer_td *buffer) |
mridup | 0:dc55f40eb04f | 118 | { |
mridup | 0:dc55f40eb04f | 119 | int bufsize = buffer->size; |
mridup | 0:dc55f40eb04f | 120 | if (buffer->count >= bufsize - 100) |
mridup | 0:dc55f40eb04f | 121 | { |
mridup | 0:dc55f40eb04f | 122 | //printf("half full!"); |
mridup | 0:dc55f40eb04f | 123 | return 1; |
mridup | 0:dc55f40eb04f | 124 | } |
mridup | 0:dc55f40eb04f | 125 | else |
mridup | 0:dc55f40eb04f | 126 | { |
mridup | 0:dc55f40eb04f | 127 | return 0; |
mridup | 0:dc55f40eb04f | 128 | } |
mridup | 0:dc55f40eb04f | 129 | } |
mridup | 0:dc55f40eb04f | 130 | |
mridup | 0:dc55f40eb04f | 131 | /** |
mridup | 0:dc55f40eb04f | 132 | * @brief is_half_empty |
mridup | 0:dc55f40eb04f | 133 | * checks if the buffer is less than half |
mridup | 0:dc55f40eb04f | 134 | * @param None |
mridup | 0:dc55f40eb04f | 135 | * @retval None |
mridup | 0:dc55f40eb04f | 136 | */ |
mridup | 0:dc55f40eb04f | 137 | int is_half_empty(buffer_td *buffer) |
mridup | 0:dc55f40eb04f | 138 | { |
mridup | 0:dc55f40eb04f | 139 | //int bufsize = buffer->size; |
mridup | 0:dc55f40eb04f | 140 | if (buffer->count <= 100) |
mridup | 0:dc55f40eb04f | 141 | { |
mridup | 0:dc55f40eb04f | 142 | return 1; |
mridup | 0:dc55f40eb04f | 143 | } |
mridup | 0:dc55f40eb04f | 144 | else |
mridup | 0:dc55f40eb04f | 145 | { |
mridup | 0:dc55f40eb04f | 146 | return 0; |
mridup | 0:dc55f40eb04f | 147 | } |
mridup | 0:dc55f40eb04f | 148 | } |
mridup | 0:dc55f40eb04f | 149 | |
mridup | 0:dc55f40eb04f | 150 | /** |
mridup | 0:dc55f40eb04f | 151 | * @brief full |
mridup | 0:dc55f40eb04f | 152 | * indicates if the given buffer is full or not |
mridup | 0:dc55f40eb04f | 153 | * @param None |
mridup | 0:dc55f40eb04f | 154 | * @retval None |
mridup | 0:dc55f40eb04f | 155 | */ |
mridup | 0:dc55f40eb04f | 156 | int full(buffer_td *buffer) |
mridup | 0:dc55f40eb04f | 157 | { |
mridup | 0:dc55f40eb04f | 158 | int bufsize = buffer->size; |
mridup | 0:dc55f40eb04f | 159 | if (buffer->count == bufsize) |
mridup | 0:dc55f40eb04f | 160 | { |
mridup | 0:dc55f40eb04f | 161 | return 1; |
mridup | 0:dc55f40eb04f | 162 | } |
mridup | 0:dc55f40eb04f | 163 | else |
mridup | 0:dc55f40eb04f | 164 | { |
mridup | 0:dc55f40eb04f | 165 | return 0; |
mridup | 0:dc55f40eb04f | 166 | } |
mridup | 0:dc55f40eb04f | 167 | } |
mridup | 0:dc55f40eb04f | 168 | |
mridup | 0:dc55f40eb04f | 169 | /** |
mridup | 0:dc55f40eb04f | 170 | * @brief empty |
mridup | 0:dc55f40eb04f | 171 | * indicates if the given buffer is empty or not |
mridup | 0:dc55f40eb04f | 172 | * @param None |
mridup | 0:dc55f40eb04f | 173 | * @retval None |
mridup | 0:dc55f40eb04f | 174 | */ |
mridup | 0:dc55f40eb04f | 175 | int empty(buffer_td *buffer) { |
mridup | 0:dc55f40eb04f | 176 | if (buffer->count == 0) { |
mridup | 0:dc55f40eb04f | 177 | return 1; |
mridup | 0:dc55f40eb04f | 178 | } else { |
mridup | 0:dc55f40eb04f | 179 | return 0; |
mridup | 0:dc55f40eb04f | 180 | } |
mridup | 0:dc55f40eb04f | 181 | } |
mridup | 0:dc55f40eb04f | 182 | |
mridup | 0:dc55f40eb04f | 183 | /** |
mridup | 0:dc55f40eb04f | 184 | * @brief prefetch_buffer_queue |
mridup | 0:dc55f40eb04f | 185 | * prefetches the pipeline upto xx bytes |
mridup | 0:dc55f40eb04f | 186 | * @param None |
mridup | 0:dc55f40eb04f | 187 | * @retval None |
mridup | 0:dc55f40eb04f | 188 | */ |
mridup | 0:dc55f40eb04f | 189 | uint8_t * prefetch_buffer_queue(buffer_td *buffer) |
mridup | 0:dc55f40eb04f | 190 | { |
mridup | 0:dc55f40eb04f | 191 | //int i = 0; |
mridup | 0:dc55f40eb04f | 192 | uint8_t * element; |
mridup | 0:dc55f40eb04f | 193 | int bufsize; |
mridup | 0:dc55f40eb04f | 194 | |
mridup | 0:dc55f40eb04f | 195 | memset(prefetch_buffer,0x00,20); |
mridup | 0:dc55f40eb04f | 196 | element = &prefetch_buffer[0]; |
mridup | 0:dc55f40eb04f | 197 | element[4] = '\0'; |
mridup | 0:dc55f40eb04f | 198 | |
mridup | 0:dc55f40eb04f | 199 | if(!empty(buffer)) |
mridup | 0:dc55f40eb04f | 200 | { |
mridup | 0:dc55f40eb04f | 201 | bufsize = (buffer->count); |
mridup | 0:dc55f40eb04f | 202 | if(buffer->count <= 20) |
mridup | 0:dc55f40eb04f | 203 | memcpy(element, &buffer->element[buffer->start], bufsize); |
mridup | 0:dc55f40eb04f | 204 | else |
mridup | 0:dc55f40eb04f | 205 | memcpy(element, &buffer->element[buffer->start], 20); |
mridup | 0:dc55f40eb04f | 206 | return element; |
mridup | 0:dc55f40eb04f | 207 | } |
mridup | 0:dc55f40eb04f | 208 | else return NULL; |
mridup | 0:dc55f40eb04f | 209 | } |
mridup | 0:dc55f40eb04f | 210 | |
mridup | 0:dc55f40eb04f | 211 | /* |
mridup | 0:dc55f40eb04f | 212 | * @brief push_buffer |
mridup | 0:dc55f40eb04f | 213 | * pushes a new item onto the circular buffer (queues it) |
mridup | 0:dc55f40eb04f | 214 | * @param None |
mridup | 0:dc55f40eb04f | 215 | * @retval None |
mridup | 0:dc55f40eb04f | 216 | */ |
mridup | 0:dc55f40eb04f | 217 | void push_buffer(buffer_td *buffer, uint8_t *data) |
mridup | 0:dc55f40eb04f | 218 | { |
mridup | 0:dc55f40eb04f | 219 | int bufsize; |
mridup | 0:dc55f40eb04f | 220 | |
mridup | 0:dc55f40eb04f | 221 | if (full(buffer)) |
mridup | 0:dc55f40eb04f | 222 | { |
mridup | 0:dc55f40eb04f | 223 | //Buffer overflow and no more space |
mridup | 0:dc55f40eb04f | 224 | //MPD: No Action taken here; in case of buffer overflow, do we need to overwrite last buffer? |
mridup | 0:dc55f40eb04f | 225 | //printf("\r\nRing Buffer Full!!\r\n"); |
mridup | 0:dc55f40eb04f | 226 | //printf(data); |
mridup | 0:dc55f40eb04f | 227 | return; |
mridup | 0:dc55f40eb04f | 228 | } |
mridup | 0:dc55f40eb04f | 229 | else |
mridup | 0:dc55f40eb04f | 230 | { |
mridup | 0:dc55f40eb04f | 231 | buffer->count++; |
mridup | 0:dc55f40eb04f | 232 | memcpy(&buffer->element[buffer->end], data, ELEMENT_SIZE); |
mridup | 0:dc55f40eb04f | 233 | buffer->end = buffer->end + ELEMENT_SIZE; |
mridup | 0:dc55f40eb04f | 234 | |
mridup | 0:dc55f40eb04f | 235 | //wrap around if max size is reached |
mridup | 0:dc55f40eb04f | 236 | bufsize = (buffer->size); |
mridup | 0:dc55f40eb04f | 237 | if (buffer->end >= bufsize) |
mridup | 0:dc55f40eb04f | 238 | { |
mridup | 0:dc55f40eb04f | 239 | buffer->end = 0; |
mridup | 0:dc55f40eb04f | 240 | } |
mridup | 0:dc55f40eb04f | 241 | } |
mridup | 0:dc55f40eb04f | 242 | } |
mridup | 0:dc55f40eb04f | 243 | |
mridup | 0:dc55f40eb04f | 244 | /** |
mridup | 0:dc55f40eb04f | 245 | * @brief pop_buffer_queue |
mridup | 0:dc55f40eb04f | 246 | * dequeues the circular buffer |
mridup | 0:dc55f40eb04f | 247 | * @param None |
mridup | 0:dc55f40eb04f | 248 | * @retval None |
mridup | 0:dc55f40eb04f | 249 | */ |
mridup | 0:dc55f40eb04f | 250 | uint8_t * pop_buffer_queue(buffer_td *buffer) |
mridup | 0:dc55f40eb04f | 251 | { |
mridup | 0:dc55f40eb04f | 252 | uint8_t * element; |
mridup | 0:dc55f40eb04f | 253 | int bufsize; |
mridup | 0:dc55f40eb04f | 254 | |
mridup | 0:dc55f40eb04f | 255 | element = &pop_buffer[0]; |
mridup | 0:dc55f40eb04f | 256 | if (empty(buffer)) |
mridup | 0:dc55f40eb04f | 257 | { |
mridup | 0:dc55f40eb04f | 258 | //printf("\r\nRing Buffer Empty!!\r\n"); |
mridup | 0:dc55f40eb04f | 259 | return NULL; |
mridup | 0:dc55f40eb04f | 260 | } |
mridup | 0:dc55f40eb04f | 261 | else |
mridup | 0:dc55f40eb04f | 262 | { |
mridup | 0:dc55f40eb04f | 263 | memset(pop_buffer, 0x00 , MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 264 | if(status_flag.enable_receive_data_chunk) |
mridup | 0:dc55f40eb04f | 265 | { |
mridup | 0:dc55f40eb04f | 266 | int buf_end = buffer->end; |
mridup | 0:dc55f40eb04f | 267 | // int buf_start = buffer->start; |
mridup | 0:dc55f40eb04f | 268 | if(buffer->count < 512) |
mridup | 0:dc55f40eb04f | 269 | { |
mridup | 0:dc55f40eb04f | 270 | pop_buffer_size = buffer->count; |
mridup | 0:dc55f40eb04f | 271 | if(buf_end >= buffer->start) |
mridup | 0:dc55f40eb04f | 272 | { |
mridup | 0:dc55f40eb04f | 273 | memcpy(element, &buffer->element[buffer->start], pop_buffer_size); |
mridup | 0:dc55f40eb04f | 274 | } |
mridup | 0:dc55f40eb04f | 275 | else |
mridup | 0:dc55f40eb04f | 276 | { |
mridup | 0:dc55f40eb04f | 277 | int buf_start = buffer->start; |
mridup | 0:dc55f40eb04f | 278 | memcpy(element, &buffer->element[buffer->start], RINGBUF_SIZE - buf_start); |
mridup | 0:dc55f40eb04f | 279 | memcpy(element+(RINGBUF_SIZE-buffer->start), &buffer->element[0], buf_end); |
mridup | 0:dc55f40eb04f | 280 | } |
mridup | 0:dc55f40eb04f | 281 | buffer->start = buffer->end; |
mridup | 0:dc55f40eb04f | 282 | buffer->count = 0; |
mridup | 0:dc55f40eb04f | 283 | } |
mridup | 0:dc55f40eb04f | 284 | else |
mridup | 0:dc55f40eb04f | 285 | { |
mridup | 0:dc55f40eb04f | 286 | if(buf_end >= buffer->start) |
mridup | 0:dc55f40eb04f | 287 | { |
mridup | 0:dc55f40eb04f | 288 | memcpy(element, &buffer->element[buffer->start], 511); |
mridup | 0:dc55f40eb04f | 289 | buffer->start = buffer->start + 511; |
mridup | 0:dc55f40eb04f | 290 | buffer->count = buf_end - buffer->start; |
mridup | 0:dc55f40eb04f | 291 | } |
mridup | 0:dc55f40eb04f | 292 | else |
mridup | 0:dc55f40eb04f | 293 | { |
mridup | 0:dc55f40eb04f | 294 | if(buffer->start + 511 < RINGBUF_SIZE) |
mridup | 0:dc55f40eb04f | 295 | { |
mridup | 0:dc55f40eb04f | 296 | memcpy(element, &buffer->element[buffer->start], 511); |
mridup | 0:dc55f40eb04f | 297 | buffer->start = buffer->start + 511; |
mridup | 0:dc55f40eb04f | 298 | buffer->count = (RINGBUF_SIZE - buffer->start)+ buf_end; |
mridup | 0:dc55f40eb04f | 299 | } |
mridup | 0:dc55f40eb04f | 300 | else |
mridup | 0:dc55f40eb04f | 301 | { |
mridup | 0:dc55f40eb04f | 302 | int buf_start = buffer->start; |
mridup | 0:dc55f40eb04f | 303 | memcpy(element, &buffer->element[buffer->start], RINGBUF_SIZE-buf_start); |
mridup | 0:dc55f40eb04f | 304 | memcpy(element+(RINGBUF_SIZE-buffer->start), &buffer->element[0], buf_start-513); //(buffer->start + 511) - 1024; |
mridup | 0:dc55f40eb04f | 305 | buffer->start = (buffer->start-513); |
mridup | 0:dc55f40eb04f | 306 | buffer->count = buf_end - buffer->start; |
mridup | 0:dc55f40eb04f | 307 | } |
mridup | 0:dc55f40eb04f | 308 | } |
mridup | 0:dc55f40eb04f | 309 | pop_buffer_size = 511; |
mridup | 0:dc55f40eb04f | 310 | } |
mridup | 0:dc55f40eb04f | 311 | } |
mridup | 0:dc55f40eb04f | 312 | else |
mridup | 0:dc55f40eb04f | 313 | { |
mridup | 0:dc55f40eb04f | 314 | /* First in First Out*/ |
mridup | 0:dc55f40eb04f | 315 | memcpy(element, &buffer->element[buffer->start], ELEMENT_SIZE); |
mridup | 0:dc55f40eb04f | 316 | buffer->start = buffer->start + ELEMENT_SIZE; |
mridup | 0:dc55f40eb04f | 317 | buffer->count--; |
mridup | 0:dc55f40eb04f | 318 | pop_buffer_size = 1; |
mridup | 0:dc55f40eb04f | 319 | bufsize = (buffer->size); |
mridup | 0:dc55f40eb04f | 320 | if (buffer->start >= bufsize) |
mridup | 0:dc55f40eb04f | 321 | { |
mridup | 0:dc55f40eb04f | 322 | buffer->start = 0; |
mridup | 0:dc55f40eb04f | 323 | } |
mridup | 0:dc55f40eb04f | 324 | } |
mridup | 0:dc55f40eb04f | 325 | return element; |
mridup | 0:dc55f40eb04f | 326 | } |
mridup | 0:dc55f40eb04f | 327 | } |
mridup | 0:dc55f40eb04f | 328 | |
mridup | 0:dc55f40eb04f | 329 | /** |
mridup | 0:dc55f40eb04f | 330 | * @brief rewinds_buffer_queue |
mridup | 0:dc55f40eb04f | 331 | * rewinds the circular buffer |
mridup | 0:dc55f40eb04f | 332 | * @param None |
mridup | 0:dc55f40eb04f | 333 | * @retval None |
mridup | 0:dc55f40eb04f | 334 | */ |
mridup | 0:dc55f40eb04f | 335 | void rewind_buffer_queue(buffer_td *buffer , int count) |
mridup | 0:dc55f40eb04f | 336 | { |
mridup | 0:dc55f40eb04f | 337 | int buf_end = buffer->end; |
mridup | 0:dc55f40eb04f | 338 | if(buffer->start - count >= 0) |
mridup | 0:dc55f40eb04f | 339 | { |
mridup | 0:dc55f40eb04f | 340 | buffer->start = buffer->start - count; |
mridup | 0:dc55f40eb04f | 341 | if(buf_end > buffer->start) { |
mridup | 0:dc55f40eb04f | 342 | buffer->count = buf_end - buffer->start; |
mridup | 0:dc55f40eb04f | 343 | } |
mridup | 0:dc55f40eb04f | 344 | else { |
mridup | 0:dc55f40eb04f | 345 | buffer->count = (RINGBUF_SIZE-buffer->start)+buf_end; |
mridup | 0:dc55f40eb04f | 346 | } |
mridup | 0:dc55f40eb04f | 347 | } |
mridup | 0:dc55f40eb04f | 348 | else |
mridup | 0:dc55f40eb04f | 349 | { |
mridup | 0:dc55f40eb04f | 350 | buffer->start = RINGBUF_SIZE - (count - buffer->start); |
mridup | 0:dc55f40eb04f | 351 | buffer->count = (RINGBUF_SIZE - buffer->start)+ buf_end; |
mridup | 0:dc55f40eb04f | 352 | } |
mridup | 0:dc55f40eb04f | 353 | } |
mridup | 0:dc55f40eb04f | 354 | |
mridup | 0:dc55f40eb04f | 355 | /** |
mridup | 0:dc55f40eb04f | 356 | * @} |
mridup | 0:dc55f40eb04f | 357 | */ |
mridup | 0:dc55f40eb04f | 358 | |
mridup | 0:dc55f40eb04f | 359 | /** |
mridup | 0:dc55f40eb04f | 360 | * @} |
mridup | 0:dc55f40eb04f | 361 | */ |
mridup | 0:dc55f40eb04f | 362 | |
mridup | 0:dc55f40eb04f | 363 | |
mridup | 0:dc55f40eb04f | 364 | /** |
mridup | 0:dc55f40eb04f | 365 | * @} |
mridup | 0:dc55f40eb04f | 366 | */ |
mridup | 0:dc55f40eb04f | 367 | |
mridup | 0:dc55f40eb04f | 368 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ |