semphr.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_SEMPHR_H
12 #define FREERTOS_SEMPHR_H
13 
14 #ifndef DOXYGEN
15 
16 #include "freertos/FreeRTOS.h"
17 
18 #include <stdlib.h>
19 #include "mutex.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 typedef void* SemaphoreHandle_t;
26 
27 SemaphoreHandle_t xSemaphoreCreateMutex(void);
28 SemaphoreHandle_t xSemaphoreCreateRecursiveMutex(void);
29 
30 void vSemaphoreDelete (SemaphoreHandle_t xSemaphore);
31 
32 BaseType_t xSemaphoreGive (SemaphoreHandle_t xSemaphore);
33 BaseType_t xSemaphoreTake (SemaphoreHandle_t xSemaphore,
34  TickType_t xTicksToWait);
35 BaseType_t xSemaphoreGiveRecursive (SemaphoreHandle_t xSemaphore);
36 BaseType_t xSemaphoreTakeRecursive (SemaphoreHandle_t xSemaphore,
37  TickType_t xTicksToWait);
38 
39 #define vPortCPUInitializeMutex(m) mutex_init(m)
40 
41 void vPortCPUAcquireMutex (portMUX_TYPE *mux);
42 void vPortCPUReleaseMutex (portMUX_TYPE *mux);
43 
44 /*
45  * PLEASE NOTE: Following definitions were copied directly from the FreeRTOS
46  * distribution and are under the following copyright:
47  *
48  * FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.
49  * All rights reserved
50  *
51  * FreeRTOS is free software; you can redistribute it and/or modify it under
52  * the terms of the GNU General Public License (version 2) as published by the
53  * Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
54  *
55  * Full license text is available on the following
56  * link: http://www.freertos.org/a00114.html
57  */
58 
59 #define semSEMAPHORE_QUEUE_ITEM_LENGTH ( ( uint8_t ) 0U )
60 
61 #define xSemaphoreCreateBinary() \
62  xQueueGenericCreate( ( UBaseType_t ) 1, \
63  semSEMAPHORE_QUEUE_ITEM_LENGTH, \
64  queueQUEUE_TYPE_BINARY_SEMAPHORE )
65 #define xSemaphoreCreateCounting( uxMaxCount, uxInitialCount ) \
66  xQueueCreateCountingSemaphore( ( uxMaxCount ), ( uxInitialCount ) )
67 
68 #define xSemaphoreTakeFromISR( xSemaphore, pxHigherPriorityTaskWoken ) \
69  xQueueReceiveFromISR( ( QueueHandle_t ) ( xSemaphore ), \
70  NULL, ( pxHigherPriorityTaskWoken ) )
71 
72 #define xSemaphoreGiveFromISR( xSemaphore, pxHigherPriorityTaskWoken ) \
73  xQueueGiveFromISR( ( QueueHandle_t ) ( xSemaphore ), \
74  ( pxHigherPriorityTaskWoken ) )
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif /* DOXYGEN */
81 #endif /* FREERTOS_SEMPHR_H */
mutex.h
Mutex for thread synchronization.