queue.h
1 /*
2  * Copyright (C) 2019 Gunar Schorcht
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  *
8  * FreeRTOS to RIOT-OS adaption module for source code compatibility
9  */
10 
11 #ifndef FREERTOS_QUEUE_H
12 #define FREERTOS_QUEUE_H
13 
14 #ifndef DOXYGEN
15 
16 #include "freertos/FreeRTOS.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #define xQueueHandle QueueHandle_t
23 
24 typedef void* QueueHandle_t;
25 
26 QueueHandle_t xQueueGenericCreate (const UBaseType_t uxQueueLength,
27  const UBaseType_t uxItemSize,
28  const uint8_t ucQueueType);
29 
30 QueueHandle_t xQueueCreateCountingSemaphore (const UBaseType_t uxMaxCount,
31  const UBaseType_t uxInitialCount);
32 
33 void vQueueDelete (QueueHandle_t xQueue);
34 
35 BaseType_t xQueueGenericReset (QueueHandle_t xQueue, BaseType_t xNewQueue);
36 
37 BaseType_t xQueueGenericReceive (QueueHandle_t xQueue,
38  void * const pvBuffer,
39  TickType_t xTicksToWait,
40  const BaseType_t xJustPeeking);
41 
42 BaseType_t xQueueGenericSend (QueueHandle_t xQueue,
43  const void * const pvItemToQueue,
44  TickType_t xTicksToWait,
45  const BaseType_t xCopyPosition);
46 
47 BaseType_t xQueueReceiveFromISR (QueueHandle_t xQueue, void * const pvBuffer,
48  BaseType_t * const pxHigherPriorityTaskWoken);
49 
50 BaseType_t xQueueGenericSendFromISR (QueueHandle_t xQueue,
51  const void * const pvItemToQueue,
52  BaseType_t * const pxHigherPriorityTaskWoken,
53  const BaseType_t xCopyPosition );
54 
55 BaseType_t xQueueGiveFromISR (QueueHandle_t xQueue,
56  BaseType_t * const pxHigherPriorityTaskWoken);
57 
58 UBaseType_t uxQueueMessagesWaiting( QueueHandle_t xQueue );
59 
60 /*
61  * PLEASE NOTE: Following definitions were copied directly from the FreeRTOS
62  * distribution and are under the following copyright:
63  *
64  * FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.
65  * All rights reserved
66  *
67  * FreeRTOS is free software; you can redistribute it and/or modify it under
68  * the terms of the GNU General Public License (version 2) as published by the
69  * Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
70  *
71  * Full license text is available on the following
72  * link: http://www.freertos.org/a00114.html
73  */
74 
75 #define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
76 #define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
77 #define queueOVERWRITE ( ( BaseType_t ) 2 )
78 
79 #define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U )
80 #define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )
81 #define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U )
82 #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
83 #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
84 #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
85 
86 #define errQUEUE_EMPTY ( ( BaseType_t ) 0 )
87 #define errQUEUE_FULL ( ( BaseType_t ) 0 )
88 #define errQUEUE_BLOCKED ( -4 )
89 #define errQUEUE_YIELD ( -5 )
90 
91 #define xQueueCreate( uxQueueLength, uxItemSize ) \
92  xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) )
93 
94 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) \
95  xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), \
96  pdFALSE )
97 
98 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) \
99  xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), \
100  queueSEND_TO_BACK )
101 
102 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) \
103  xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), \
104  queueSEND_TO_BACK )
105 
106 #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
107  xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), \
108  ( pxHigherPriorityTaskWoken ), \
109  queueSEND_TO_BACK )
110 
111 #define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE )
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif /* DOXYGEN */
118 #endif /* FREERTOS_QUEUE_H */