an old afLib which supports both SPI and UART

Committer:
Rhyme
Date:
Mon Apr 23 06:15:05 2018 +0000
Revision:
1:112741fe45d1
Parent:
0:6f371c791202
afLib1.3 first mbed version with working UART

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:6f371c791202 1 /*
Rhyme 0:6f371c791202 2 * q.h
Rhyme 0:6f371c791202 3 *
Rhyme 0:6f371c791202 4 * Created on: Apr 27, 2015
Rhyme 0:6f371c791202 5 * Author: chrisatkiban
Rhyme 0:6f371c791202 6 */
Rhyme 0:6f371c791202 7
Rhyme 0:6f371c791202 8 #ifndef AF_QUEUE_H
Rhyme 0:6f371c791202 9 #define AF_QUEUE_H
Rhyme 0:6f371c791202 10
Rhyme 0:6f371c791202 11 #include <stdint.h>
Rhyme 0:6f371c791202 12 #include "mbed.h"
Rhyme 0:6f371c791202 13
Rhyme 0:6f371c791202 14 #ifdef __cplusplus
Rhyme 0:6f371c791202 15 extern "C" {
Rhyme 0:6f371c791202 16 #endif
Rhyme 0:6f371c791202 17
Rhyme 0:6f371c791202 18 #define ALIGN_SIZE( sizeToAlign, PowerOfTwo ) \
Rhyme 0:6f371c791202 19 (((sizeToAlign) + (PowerOfTwo) - 1) & ~((PowerOfTwo) - 1))
Rhyme 0:6f371c791202 20
Rhyme 0:6f371c791202 21 #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))]
Rhyme 0:6f371c791202 22 #define AF_QUEUE_INIT(q, elem_size, max_elem) af_queue_init((queue_t *)&(q), elem_size, max_elem, (uint8_t *)(q##_mem))
Rhyme 0:6f371c791202 23 #define AF_QUEUE_GET(p_q) af_queue_get((queue_t *)(p_q))
Rhyme 0:6f371c791202 24 #define AF_QUEUE_GET_FROM_INTERRUPT(p_q) af_queue_get_from_interrupt((queue_t *)(p_q))
Rhyme 0:6f371c791202 25 #define AF_QUEUE_ELEM_ALLOC(p_q) af_queue_elem_alloc((queue_t *)(p_q))
Rhyme 0:6f371c791202 26 #define AF_QUEUE_ELEM_ALLOC_FROM_INTERRUPT(p_q) af_queue_elem_alloc_from_interrupt((queue_t *)(p_q))
Rhyme 0:6f371c791202 27 #define AF_QUEUE_ELEM_FREE(p_q, p_data) af_queue_elem_free((queue_t *)(p_q), p_data)
Rhyme 0:6f371c791202 28 #define AF_QUEUE_ELEM_FREE_FROM_INTERRUPT(p_q, p_data) af_queue_elem_free_from_interrupt((queue_t *)(p_q), p_data)
Rhyme 0:6f371c791202 29 #define AF_QUEUE_PEEK(p_q) af_queue_peek((queue_t *)(p_q))
Rhyme 0:6f371c791202 30 #define AF_QUEUE_PEEK_FROM_INTERRUPT(p_q) af_queue_peek_from_interrupt((queue_t *)(p_q))
Rhyme 0:6f371c791202 31 #define AF_QUEUE_PEEK_TAIL(p_q) af_queue_peek_tail((queue_t *)(p_q))
Rhyme 0:6f371c791202 32 #define AF_QUEUE_PEEK_TAIL_FROM_INTERRUPT(p_q) af_queue_peek_tail_from_interrupt((queue_t *)(p_q))
Rhyme 0:6f371c791202 33 #define AF_QUEUE_PUT(p_q, p_data) af_queue_put((queue_t *)(p_q), p_data)
Rhyme 0:6f371c791202 34 #define AF_QUEUE_PUT_FROM_INTERRUPT(p_q, p_data) af_queue_put_from_interrupt((queue_t *)(p_q), p_data)
Rhyme 0:6f371c791202 35
Rhyme 0:6f371c791202 36 typedef struct af_queue_elem_desc_s
Rhyme 0:6f371c791202 37 {
Rhyme 0:6f371c791202 38 struct af_queue_elem_desc_s *p_next_alloc;
Rhyme 0:6f371c791202 39 struct af_queue_elem_desc_s *p_next_free;
Rhyme 0:6f371c791202 40 uint8_t data[0];
Rhyme 0:6f371c791202 41 } af_queue_elem_desc_t;
Rhyme 0:6f371c791202 42
Rhyme 0:6f371c791202 43 typedef struct queue_s
Rhyme 0:6f371c791202 44 {
Rhyme 0:6f371c791202 45 af_queue_elem_desc_t *p_head;
Rhyme 0:6f371c791202 46 af_queue_elem_desc_t *p_tail;
Rhyme 0:6f371c791202 47 af_queue_elem_desc_t *p_free_head;
Rhyme 0:6f371c791202 48 } queue_t;
Rhyme 0:6f371c791202 49
Rhyme 0:6f371c791202 50 void af_queue_init_system(uint8_t (*p_preemption_disable)(void), void (*p_preemption_enable)(uint8_t is_nested), Stream *theLog);
Rhyme 0:6f371c791202 51 void af_queue_init(queue_t *p_q, int elem_size, int max_elem, uint8_t *p_mem);
Rhyme 0:6f371c791202 52 void *af_queue_peek(queue_t *p_q);
Rhyme 0:6f371c791202 53 void *af_queue_peek_from_interrupt(queue_t *p_q);
Rhyme 0:6f371c791202 54 void *af_queue_peek_tail(queue_t *p_q);
Rhyme 0:6f371c791202 55 void *af_queue_peek_tail_from_interrupt(queue_t *p_q);
Rhyme 0:6f371c791202 56 void *af_queue_get(queue_t *p_q);
Rhyme 0:6f371c791202 57 void *af_queue_get_from_interrupt(queue_t *p_q);
Rhyme 0:6f371c791202 58 void *af_queue_elem_alloc(queue_t *p_q);
Rhyme 0:6f371c791202 59 void *af_queue_elem_alloc_from_interrupt(queue_t *p_q);
Rhyme 0:6f371c791202 60 void af_queue_elem_free(queue_t *p_q, void *p_data);
Rhyme 0:6f371c791202 61 void af_queue_elem_free_from_interrupt(queue_t *p_q, void *p_data);
Rhyme 0:6f371c791202 62 void af_queue_put(queue_t *p_q, void *p_data);
Rhyme 0:6f371c791202 63 void af_queue_put_from_interrupt(queue_t *p_q, void *p_data);
Rhyme 0:6f371c791202 64 void af_queue_dump(queue_t *p_q);
Rhyme 0:6f371c791202 65
Rhyme 0:6f371c791202 66 #ifdef __cplusplus
Rhyme 0:6f371c791202 67 } /* end of extern "C" */
Rhyme 0:6f371c791202 68 #endif
Rhyme 0:6f371c791202 69
Rhyme 0:6f371c791202 70 #endif /* AF_QUEUE_H */