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