TEST

Dependencies:   max32630fthr Adafruit_FeatherOLED USBDevice

Committer:
wwwarunraj
Date:
Sun Apr 19 11:19:57 2020 +0000
Revision:
4:291477e8690d
Parent:
3:2fe2ff1ca0dc
19/04

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gmehmet 1:f60eafbf009a 1 /*******************************************************************************
Emre.Eken@IST-LT-36262.maxim-ic.internal 3:2fe2ff1ca0dc 2 * Copyright (C) Maxim Integrated Products, Inc., All rights Reserved.
Emre.Eken@IST-LT-36262.maxim-ic.internal 3:2fe2ff1ca0dc 3 *
Emre.Eken@IST-LT-36262.maxim-ic.internal 3:2fe2ff1ca0dc 4 * This software is protected by copyright laws of the United States and
Emre.Eken@IST-LT-36262.maxim-ic.internal 3:2fe2ff1ca0dc 5 * of foreign countries. This material may also be protected by patent laws
Emre.Eken@IST-LT-36262.maxim-ic.internal 3:2fe2ff1ca0dc 6 * and technology transfer regulations of the United States and of foreign
Emre.Eken@IST-LT-36262.maxim-ic.internal 3:2fe2ff1ca0dc 7 * countries. This software is furnished under a license agreement and/or a
Emre.Eken@IST-LT-36262.maxim-ic.internal 3:2fe2ff1ca0dc 8 * nondisclosure agreement and may only be used or reproduced in accordance
Emre.Eken@IST-LT-36262.maxim-ic.internal 3:2fe2ff1ca0dc 9 * with the terms of those agreements. Dissemination of this information to
Emre.Eken@IST-LT-36262.maxim-ic.internal 3:2fe2ff1ca0dc 10 * any party or parties not specified in the license agreement and/or
Emre.Eken@IST-LT-36262.maxim-ic.internal 3:2fe2ff1ca0dc 11 * nondisclosure agreement is expressly prohibited.
gmehmet 1:f60eafbf009a 12 *
gmehmet 1:f60eafbf009a 13 * The above copyright notice and this permission notice shall be included
gmehmet 1:f60eafbf009a 14 * in all copies or substantial portions of the Software.
gmehmet 1:f60eafbf009a 15 *
gmehmet 1:f60eafbf009a 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
gmehmet 1:f60eafbf009a 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
gmehmet 1:f60eafbf009a 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
gmehmet 1:f60eafbf009a 19 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
gmehmet 1:f60eafbf009a 20 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
gmehmet 1:f60eafbf009a 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
gmehmet 1:f60eafbf009a 22 * OTHER DEALINGS IN THE SOFTWARE.
gmehmet 1:f60eafbf009a 23 *
gmehmet 1:f60eafbf009a 24 * Except as contained in this notice, the name of Maxim Integrated
gmehmet 1:f60eafbf009a 25 * Products, Inc. shall not be used except as stated in the Maxim Integrated
gmehmet 1:f60eafbf009a 26 * Products, Inc. Branding Policy.
gmehmet 1:f60eafbf009a 27 *
gmehmet 1:f60eafbf009a 28 * The mere transfer of this software does not imply any licenses
gmehmet 1:f60eafbf009a 29 * of trade secrets, proprietary technology, copyrights, patents,
gmehmet 1:f60eafbf009a 30 * trademarks, maskwork rights, or any other form of intellectual
gmehmet 1:f60eafbf009a 31 * property whatsoever. Maxim Integrated Products, Inc. retains all
gmehmet 1:f60eafbf009a 32 * ownership rights.
gmehmet 1:f60eafbf009a 33 *******************************************************************************
gmehmet 1:f60eafbf009a 34 */
gmehmet 1:f60eafbf009a 35
gmehmet 1:f60eafbf009a 36 #ifndef _QUEUE_H_
gmehmet 1:f60eafbf009a 37 #define _QUEUE_H_
gmehmet 1:f60eafbf009a 38 #include <stdio.h>
gmehmet 1:f60eafbf009a 39 #include <string.h>
gmehmet 1:f60eafbf009a 40 #include <stdint.h>
gmehmet 1:f60eafbf009a 41 #include <stdlib.h>
gmehmet 1:f60eafbf009a 42 #include <stdbool.h>
gmehmet 1:f60eafbf009a 43 #include <errno.h>
gmehmet 1:f60eafbf009a 44
gmehmet 1:f60eafbf009a 45 #ifndef UNIT_TEST
gmehmet 1:f60eafbf009a 46 #include "platform.h"
gmehmet 1:f60eafbf009a 47 #else
gmehmet 1:f60eafbf009a 48 #ifndef enter_critical_section
gmehmet 1:f60eafbf009a 49 #define enter_critical_section()
gmehmet 1:f60eafbf009a 50 #endif
gmehmet 1:f60eafbf009a 51
gmehmet 1:f60eafbf009a 52 #ifndef exit_critical_section
gmehmet 1:f60eafbf009a 53 #define exit_critical_section()
gmehmet 1:f60eafbf009a 54 #endif
gmehmet 1:f60eafbf009a 55
gmehmet 1:f60eafbf009a 56 #ifndef pr_info
gmehmet 1:f60eafbf009a 57 #define pr_info(...) printf(__VA_ARGS__)
gmehmet 1:f60eafbf009a 58 #endif
gmehmet 1:f60eafbf009a 59 #endif
gmehmet 1:f60eafbf009a 60
gmehmet 1:f60eafbf009a 61 #define QUEUE_USAGE_STATS
gmehmet 1:f60eafbf009a 62
gmehmet 1:f60eafbf009a 63 struct queue_t {
gmehmet 1:f60eafbf009a 64 char *wr; // write pointer
gmehmet 1:f60eafbf009a 65 char *rd; // read pointer
gmehmet 1:f60eafbf009a 66 char *base; // buffer base pointer
gmehmet 1:f60eafbf009a 67 int num_item; // number of data item
gmehmet 1:f60eafbf009a 68 int ovf_item; // Number of overflowed data
gmehmet 1:f60eafbf009a 69 int buffer_size; // buffer size in bytes
gmehmet 1:f60eafbf009a 70 int max_buffer_size; // buffer size in bytes
gmehmet 1:f60eafbf009a 71 int item_size; // data size
gmehmet 1:f60eafbf009a 72 char *name;
gmehmet 1:f60eafbf009a 73 #ifdef QUEUE_USAGE_STATS
gmehmet 1:f60eafbf009a 74 int pop_cnt;
gmehmet 1:f60eafbf009a 75 int push_cnt;
gmehmet 1:f60eafbf009a 76 int stats_period_cnt;
gmehmet 1:f60eafbf009a 77 #endif
gmehmet 1:f60eafbf009a 78 };
gmehmet 1:f60eafbf009a 79
gmehmet 1:f60eafbf009a 80 #ifdef __cplusplus
gmehmet 1:f60eafbf009a 81 extern "C" {
gmehmet 1:f60eafbf009a 82 #endif
gmehmet 1:f60eafbf009a 83
gmehmet 1:f60eafbf009a 84 /**
gmehmet 1:f60eafbf009a 85 * @brief Queue initialization.
gmehmet 1:f60eafbf009a 86 * @param[in] *q Points to the queue handle
gmehmet 1:f60eafbf009a 87 * @param[in] *buf Points to external queue buffer
gmehmet 1:f60eafbf009a 88 * @param[in] item_size Data size
gmehmet 1:f60eafbf009a 89 * @param[in] buffer_size Total buffer size in bytes
gmehmet 1:f60eafbf009a 90 * @param[out] *pDst points to output matrix structure
gmehmet 1:f60eafbf009a 91 * @return The function returns 0: success
gmehmet 1:f60eafbf009a 92 * -EINVAL (-22): Invalid Pointer, data or parameters
gmehmet 1:f60eafbf009a 93 * -2: Queue buffer is full, no more space
gmehmet 1:f60eafbf009a 94 **/
gmehmet 1:f60eafbf009a 95 int queue_init(struct queue_t *q, void *buf, int item_size, int buffer_size);
gmehmet 1:f60eafbf009a 96
gmehmet 1:f60eafbf009a 97
gmehmet 1:f60eafbf009a 98
gmehmet 1:f60eafbf009a 99 /**
gmehmet 1:f60eafbf009a 100 * @brief Queue initialization by name.
gmehmet 1:f60eafbf009a 101 * @param[in] *q Points to the queue handle
gmehmet 1:f60eafbf009a 102 * @param[in] *buf Points to external queue buffer
gmehmet 1:f60eafbf009a 103 * @param[in] item_size Data size
gmehmet 1:f60eafbf009a 104 * @param[in] buffer_size Total buffer size in bytes
gmehmet 1:f60eafbf009a 105 * @param[out] *pDst points to output matrix structure
gmehmet 1:f60eafbf009a 106 * @param[in] Set queue name for debugging
gmehmet 1:f60eafbf009a 107 * @return The function returns 0: success
gmehmet 1:f60eafbf009a 108 * -EINVAL (-22): Invalid Pointer, data or parameters
gmehmet 1:f60eafbf009a 109 * -2: Queue buffer is full, no more space
gmehmet 1:f60eafbf009a 110 **/
gmehmet 1:f60eafbf009a 111 int queue_init_by_name(struct queue_t *q, void *buf, int item_size, int buffer_size, const char *name);
gmehmet 1:f60eafbf009a 112
gmehmet 1:f60eafbf009a 113
gmehmet 1:f60eafbf009a 114
gmehmet 1:f60eafbf009a 115 /**
gmehmet 1:f60eafbf009a 116 * @brief Reset queue
gmehmet 1:f60eafbf009a 117 * @param[in] *q Points to the queue handle
gmehmet 1:f60eafbf009a 118 * @param[in] *data Points to any type of data to put FIFO
gmehmet 1:f60eafbf009a 119 * @param[out] *pDst Points to output matrix structure
gmehmet 1:f60eafbf009a 120 * @return The function returns 0: success
gmehmet 1:f60eafbf009a 121 * -EINVAL (-22): Invalid Pointer
gmehmet 1:f60eafbf009a 122 *
gmehmet 1:f60eafbf009a 123 **/
gmehmet 1:f60eafbf009a 124 int queue_reset(struct queue_t *q);
gmehmet 1:f60eafbf009a 125
gmehmet 1:f60eafbf009a 126
gmehmet 1:f60eafbf009a 127
gmehmet 1:f60eafbf009a 128 /**
gmehmet 1:f60eafbf009a 129 * @brief Update item size and reset queue. Usign of this command requires exta cauion.
gmehmet 1:f60eafbf009a 130 * @param[in] *q Points to the queue handle
gmehmet 1:f60eafbf009a 131 * @return The function returns 0: success
gmehmet 1:f60eafbf009a 132 * -EINVAL (-22): Invalid Pointer
gmehmet 1:f60eafbf009a 133 *
gmehmet 1:f60eafbf009a 134 **/
gmehmet 1:f60eafbf009a 135 int queue_update_items_size(struct queue_t *q, int item_size);
gmehmet 1:f60eafbf009a 136
gmehmet 1:f60eafbf009a 137
gmehmet 1:f60eafbf009a 138
gmehmet 1:f60eafbf009a 139 /**
gmehmet 1:f60eafbf009a 140 * @brief Data enqueue.
gmehmet 1:f60eafbf009a 141 * @param[in] *q points to the queue handle
gmehmet 1:f60eafbf009a 142 * @param[in] *data points to any type of data to put FIFO
gmehmet 1:f60eafbf009a 143 * @return The function returns 0: success
gmehmet 1:f60eafbf009a 144 * -EINVAL (-22): Invalid Pointer
gmehmet 1:f60eafbf009a 145 * -2: Queue buffer is full, no more space
gmehmet 1:f60eafbf009a 146 **/
gmehmet 1:f60eafbf009a 147 int enqueue(struct queue_t *q, void *data);
gmehmet 1:f60eafbf009a 148
gmehmet 1:f60eafbf009a 149
gmehmet 1:f60eafbf009a 150
gmehmet 1:f60eafbf009a 151 /**
gmehmet 1:f60eafbf009a 152 * @brief Data dequeue.
gmehmet 1:f60eafbf009a 153 * @param[in] *q points to the queue handle
gmehmet 1:f60eafbf009a 154 * @param[in] *data points to any type of data to put FIFO
gmehmet 1:f60eafbf009a 155 * @param[out] *data pop data from Queue
gmehmet 1:f60eafbf009a 156 * @return The function returns 0: success
gmehmet 1:f60eafbf009a 157 * -EINVAL (-22): Invalid Pointer or data
gmehmet 1:f60eafbf009a 158 * -2: Queue buffer is empty
gmehmet 1:f60eafbf009a 159 **/
gmehmet 1:f60eafbf009a 160 int dequeue(struct queue_t *q, void *data);
gmehmet 1:f60eafbf009a 161
gmehmet 1:f60eafbf009a 162
gmehmet 1:f60eafbf009a 163
gmehmet 1:f60eafbf009a 164 /**
gmehmet 1:f60eafbf009a 165 * @brief Queue Destroy
gmehmet 1:f60eafbf009a 166 * @param[in] *q points to the queue handle
gmehmet 1:f60eafbf009a 167 **/
gmehmet 1:f60eafbf009a 168 void queue_destroy(struct queue_t *q);
gmehmet 1:f60eafbf009a 169
gmehmet 1:f60eafbf009a 170
gmehmet 1:f60eafbf009a 171
gmehmet 1:f60eafbf009a 172 /**
gmehmet 1:f60eafbf009a 173 * @brief Number of elements in Queue
gmehmet 1:f60eafbf009a 174 * @param[in] *q points to the queue handle
gmehmet 1:f60eafbf009a 175 * @return number of elements
gmehmet 1:f60eafbf009a 176 **/
gmehmet 1:f60eafbf009a 177 int queue_len(struct queue_t *q);
gmehmet 1:f60eafbf009a 178
gmehmet 1:f60eafbf009a 179
gmehmet 1:f60eafbf009a 180
gmehmet 1:f60eafbf009a 181 /**
gmehmet 1:f60eafbf009a 182 * @brief Copies an item from the front of queue to data, but does not remove it from queue
gmehmet 1:f60eafbf009a 183 * @param[in] *q points to the queue handle
gmehmet 1:f60eafbf009a 184 * @param[out] Copy of item from front of the queue
gmehmet 1:f60eafbf009a 185 * @return if value is greater than 0, return value is number of elements.
gmehmet 1:f60eafbf009a 186 If value is less than 0, returns -EINVAL (-22)
gmehmet 1:f60eafbf009a 187 **/
gmehmet 1:f60eafbf009a 188 int queue_front(struct queue_t *q, void *data);
gmehmet 1:f60eafbf009a 189
gmehmet 1:f60eafbf009a 190
gmehmet 1:f60eafbf009a 191
gmehmet 1:f60eafbf009a 192 /**
gmehmet 1:f60eafbf009a 193 * @brief Copies n items from the front of the queue, but does not remove them
gmehmet 1:f60eafbf009a 194 * @param[in] *q - points to the queue handle
gmehmet 1:f60eafbf009a 195 * @param[out] *data - The buffer to hold copied data
gmehmet 1:f60eafbf009a 196 * @param[in] n - the number of items to remove
gmehmet 1:f60eafbf009a 197 * @param[in] buf_sz - input *data buffer size
gmehmet 1:f60eafbf009a 198 * @return 0: success
gmehmet 1:f60eafbf009a 199 * -EINVAL (-22): Invalid pointer
gmehmet 1:f60eafbf009a 200 * -2: Queue contains less than n items
gmehmet 1:f60eafbf009a 201 */
gmehmet 1:f60eafbf009a 202 int queue_front_n(struct queue_t *q, void *data, int n, int buf_sz);
gmehmet 1:f60eafbf009a 203
gmehmet 1:f60eafbf009a 204
gmehmet 1:f60eafbf009a 205
gmehmet 1:f60eafbf009a 206 /**
gmehmet 1:f60eafbf009a 207 * @brief Removes an item from front of queue
gmehmet 1:f60eafbf009a 208 * @param[in] *q points to the queue handle
gmehmet 1:f60eafbf009a 209 * @return status, success or fail
gmehmet 1:f60eafbf009a 210 **/
gmehmet 1:f60eafbf009a 211 int queue_pop(struct queue_t *q);
gmehmet 1:f60eafbf009a 212
gmehmet 1:f60eafbf009a 213 /**
gmehmet 1:f60eafbf009a 214 * @brief Removes n items from the front of the queue
gmehmet 1:f60eafbf009a 215 * @param[in] *q - points to the queue handle
gmehmet 1:f60eafbf009a 216 * @param[in] n - the number of items to remove
gmehmet 1:f60eafbf009a 217 * @return 0: success
gmehmet 1:f60eafbf009a 218 * -EINVAL (-22): Invalid pointer
gmehmet 1:f60eafbf009a 219 * -2: Queue contains less than n items
gmehmet 1:f60eafbf009a 220 */
gmehmet 1:f60eafbf009a 221 int queue_pop_n(struct queue_t *q, int n);
gmehmet 1:f60eafbf009a 222
gmehmet 1:f60eafbf009a 223
gmehmet 1:f60eafbf009a 224
gmehmet 1:f60eafbf009a 225 /**
gmehmet 1:f60eafbf009a 226 * @brief Checks if queue is fill
gmehmet 1:f60eafbf009a 227 * @param[in] *q points to the queue handle
gmehmet 1:f60eafbf009a 228 * @return true (full), false (not full)
gmehmet 1:f60eafbf009a 229 *
gmehmet 1:f60eafbf009a 230 **/
gmehmet 1:f60eafbf009a 231 bool queue_is_full(struct queue_t *q);
gmehmet 1:f60eafbf009a 232
gmehmet 1:f60eafbf009a 233
gmehmet 1:f60eafbf009a 234
gmehmet 1:f60eafbf009a 235 /**
gmehmet 1:f60eafbf009a 236 * @brief returns fifo usage info
gmehmet 1:f60eafbf009a 237 * @param[in] *q points to the queue handle
gmehmet 1:f60eafbf009a 238 * @param[out] *total returns total FIFO size in number of elements
gmehmet 1:f60eafbf009a 239 * @param[out] *nm_item returns number of elements in FIFO
gmehmet 1:f60eafbf009a 240 * @return status, success or fail
gmehmet 1:f60eafbf009a 241 * -EINVAL (-22): Invalid Pointer, data or parameters
gmehmet 1:f60eafbf009a 242 **/
gmehmet 1:f60eafbf009a 243 int queue_usage(struct queue_t *q, int *total, int *nm_item);
gmehmet 1:f60eafbf009a 244
gmehmet 1:f60eafbf009a 245
gmehmet 1:f60eafbf009a 246
gmehmet 1:f60eafbf009a 247 /**
gmehmet 1:f60eafbf009a 248 * @brief Pops out delimiter terminated string
gmehmet 1:f60eafbf009a 249 * @param[in] *q points to the queue handle
gmehmet 1:f60eafbf009a 250 * @param[out] *buf output char array to write
gmehmet 1:f60eafbf009a 251 * @param[in] buffer_size Maximum buffer size to write the output char array
gmehmet 1:f60eafbf009a 252 * @return status, string length if positive or fail if negative
gmehmet 1:f60eafbf009a 253 * -EINVAL (-22): Invalid Pointer, data or parameters
gmehmet 1:f60eafbf009a 254 **/
gmehmet 1:f60eafbf009a 255 int dequeue_string(struct queue_t *q, char *buf, int buffer_size);
gmehmet 1:f60eafbf009a 256
gmehmet 1:f60eafbf009a 257
gmehmet 1:f60eafbf009a 258
gmehmet 1:f60eafbf009a 259 /**
gmehmet 1:f60eafbf009a 260 * @brief Pushes null terminated string (char array)
gmehmet 1:f60eafbf009a 261 * @param[in] *q points to the queue handle
gmehmet 1:f60eafbf009a 262 * @param[in] *data string(char array) to add it to the circullar buffer
gmehmet 1:f60eafbf009a 263 * @param[in] sz 'data' length
gmehmet 1:f60eafbf009a 264 * @return status, success or fail
gmehmet 1:f60eafbf009a 265 * -EINVAL (-22): Invalid Pointer, data or parameters
gmehmet 1:f60eafbf009a 266 **/
gmehmet 1:f60eafbf009a 267 int enqueue_string(struct queue_t *q, char *data, int sz);
gmehmet 1:f60eafbf009a 268
gmehmet 1:f60eafbf009a 269
gmehmet 1:f60eafbf009a 270 /**
gmehmet 1:f60eafbf009a 271 * @brief Counts length of string in queue
gmehmet 1:f60eafbf009a 272 * @param[in] *q points to the queue handle
gmehmet 1:f60eafbf009a 273 * @return status, success or fail
gmehmet 1:f60eafbf009a 274 * -EINVAL (-22): Invalid Pointer, data or parameters
gmehmet 1:f60eafbf009a 275 * if ret >= 0, string length
gmehmet 1:f60eafbf009a 276 **/
gmehmet 1:f60eafbf009a 277 int queue_str_len(struct queue_t *q);
gmehmet 1:f60eafbf009a 278
gmehmet 1:f60eafbf009a 279
gmehmet 1:f60eafbf009a 280
gmehmet 1:f60eafbf009a 281 void queue_n_test(void);
gmehmet 1:f60eafbf009a 282
gmehmet 1:f60eafbf009a 283 int enqueue_test(struct queue_t *q, void *data);
gmehmet 1:f60eafbf009a 284 int dequeue_test(struct queue_t *q, void *data);
gmehmet 1:f60eafbf009a 285
gmehmet 1:f60eafbf009a 286 #ifdef __cplusplus
gmehmet 1:f60eafbf009a 287 }
gmehmet 1:f60eafbf009a 288 #endif
gmehmet 1:f60eafbf009a 289 #endif //_QUEUE_H_