an old afLib which supports both SPI and UART

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers af_queue.h Source File

af_queue.h

00001 /*
00002  * q.h
00003  *
00004  *  Created on: Apr 27, 2015
00005  *      Author: chrisatkiban
00006  */
00007 
00008 #ifndef AF_QUEUE_H
00009 #define AF_QUEUE_H
00010 
00011 #include <stdint.h>
00012 #include "mbed.h"
00013 
00014 #ifdef  __cplusplus
00015 extern "C" {
00016 #endif
00017 
00018 #define ALIGN_SIZE( sizeToAlign, PowerOfTwo ) \
00019         (((sizeToAlign) + (PowerOfTwo) - 1) & ~((PowerOfTwo) - 1))
00020 
00021 #define AF_QUEUE_DECLARE(q, elem_size, max_elem) queue_t volatile (q); uint8_t volatile (q##_mem)[(max_elem) * (ALIGN_SIZE(sizeof(af_queue_elem_desc_t), 4) + ALIGN_SIZE((elem_size), 4))]
00022 #define AF_QUEUE_INIT(q, elem_size, max_elem) af_queue_init((queue_t *)&(q), elem_size, max_elem, (uint8_t *)(q##_mem))
00023 #define AF_QUEUE_GET(p_q) af_queue_get((queue_t *)(p_q))
00024 #define AF_QUEUE_GET_FROM_INTERRUPT(p_q) af_queue_get_from_interrupt((queue_t *)(p_q))
00025 #define AF_QUEUE_ELEM_ALLOC(p_q) af_queue_elem_alloc((queue_t *)(p_q))
00026 #define AF_QUEUE_ELEM_ALLOC_FROM_INTERRUPT(p_q) af_queue_elem_alloc_from_interrupt((queue_t *)(p_q))
00027 #define AF_QUEUE_ELEM_FREE(p_q, p_data) af_queue_elem_free((queue_t *)(p_q), p_data)
00028 #define AF_QUEUE_ELEM_FREE_FROM_INTERRUPT(p_q, p_data) af_queue_elem_free_from_interrupt((queue_t *)(p_q), p_data)
00029 #define AF_QUEUE_PEEK(p_q) af_queue_peek((queue_t *)(p_q))
00030 #define AF_QUEUE_PEEK_FROM_INTERRUPT(p_q) af_queue_peek_from_interrupt((queue_t *)(p_q))
00031 #define AF_QUEUE_PEEK_TAIL(p_q) af_queue_peek_tail((queue_t *)(p_q))
00032 #define AF_QUEUE_PEEK_TAIL_FROM_INTERRUPT(p_q) af_queue_peek_tail_from_interrupt((queue_t *)(p_q))
00033 #define AF_QUEUE_PUT(p_q, p_data) af_queue_put((queue_t *)(p_q), p_data)
00034 #define AF_QUEUE_PUT_FROM_INTERRUPT(p_q, p_data) af_queue_put_from_interrupt((queue_t *)(p_q), p_data)
00035 
00036 typedef struct af_queue_elem_desc_s
00037 {
00038     struct af_queue_elem_desc_s *p_next_alloc;
00039     struct af_queue_elem_desc_s *p_next_free;
00040     uint8_t data[0];
00041 } af_queue_elem_desc_t;
00042 
00043 typedef struct queue_s
00044 {
00045     af_queue_elem_desc_t *p_head;
00046     af_queue_elem_desc_t *p_tail;
00047     af_queue_elem_desc_t *p_free_head;
00048 } queue_t;
00049 
00050 void af_queue_init_system(uint8_t (*p_preemption_disable)(void), void (*p_preemption_enable)(uint8_t is_nested), Stream *theLog);
00051 void af_queue_init(queue_t *p_q, int elem_size, int max_elem, uint8_t *p_mem);
00052 void *af_queue_peek(queue_t *p_q);
00053 void *af_queue_peek_from_interrupt(queue_t *p_q);
00054 void *af_queue_peek_tail(queue_t *p_q);
00055 void *af_queue_peek_tail_from_interrupt(queue_t *p_q);
00056 void *af_queue_get(queue_t *p_q);
00057 void *af_queue_get_from_interrupt(queue_t *p_q);
00058 void *af_queue_elem_alloc(queue_t *p_q);
00059 void *af_queue_elem_alloc_from_interrupt(queue_t *p_q);
00060 void af_queue_elem_free(queue_t *p_q, void *p_data);
00061 void af_queue_elem_free_from_interrupt(queue_t *p_q, void *p_data);
00062 void af_queue_put(queue_t *p_q, void *p_data);
00063 void af_queue_put_from_interrupt(queue_t *p_q, void *p_data);
00064 void af_queue_dump(queue_t *p_q);
00065 
00066 #ifdef __cplusplus
00067 } /* end of extern "C" */
00068 #endif
00069 
00070 #endif /* AF_QUEUE_H */