1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#![no_std]
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
#![forbid(unsafe_op_in_unsafe_fn)]
use core::ffi::c_void;
extern "C" {
pub fn xTaskGetTickCountFromISR() -> TickType_t;
pub fn xTaskGetTickCount() -> TickType_t;
pub fn xTaskGetCurrentTaskHandle() -> TaskHandle_t;
pub fn vTaskResume(xTaskToResume: TaskHandle_t);
pub fn vTaskSuspend(xTaskToSuspend: TaskHandle_t);
pub fn vTaskDelayUntil(pxPreviousWakeTime: *mut TickType_t, xTimeIncrement: TickType_t);
pub fn xTaskDelayUntil(
pxPreviousWakeTime: *mut TickType_t,
xTimeIncrement: TickType_t,
) -> BaseType_t;
pub fn vTaskDelay(xTicksToDelay: TickType_t);
pub fn pvTaskGetThreadLocalStoragePointer(
xTaskToQuery: TaskHandle_t,
xIndex: BaseType_t,
) -> *mut c_void;
pub fn vTaskSetThreadLocalStoragePointer(
xTaskToSet: TaskHandle_t,
xIndex: BaseType_t,
pvValue: *mut c_void,
);
pub fn xQueueGenericReceive(
xQueue: QueueHandle_t,
pvBuffer: *const c_void,
xTicksToWait: TickType_t,
xJustPeek: BaseType_t,
) -> BaseType_t;
pub fn xQueueGenericSend(
xQueue: QueueHandle_t,
pvItemToQueue: *const c_void,
xTicksToWait: TickType_t,
xCopyPosition: BaseType_t,
) -> BaseType_t;
pub fn xQueueCreateMutex(ucQueueType: u8) -> QueueHandle_t;
pub fn vQueueDelete(xQueue: QueueHandle_t);
}
pub type BaseType_t = i32;
pub type UBaseType_t = u32;
pub type TickType_t = u32;
pub type TaskHandle_t = *mut c_void;
pub type QueueHandle_t = *mut c_void;
pub type SemaphoreHandle_t = *mut c_void;
pub const pdFALSE: BaseType_t = 0;
pub const pdTRUE: BaseType_t = 1;
pub const queueSEND_TO_BACK: BaseType_t = 0;
pub const queueSEND_TO_FRONT: BaseType_t = 1;
pub const queueOVERWRITE: BaseType_t = 2;
pub const semGIVE_BLOCK_TIME: TickType_t = 0;
pub const queueQUEUE_TYPE_BASE: u8 = 0;
pub const queueQUEUE_TYPE_SET: u8 = 0;
pub const queueQUEUE_TYPE_MUTEX: u8 = 1;
pub const queueQUEUE_TYPE_COUNTING_SEMAPHORE: u8 = 2;
pub const queueQUEUE_TYPE_BINARY_SEMAPHORE: u8 = 3;
pub const queueQUEUE_TYPE_RECURSIVE_MUTEX: u8 = 4;
pub const portMAX_DELAY: TickType_t = TickType_t::MAX;
pub unsafe fn xSemaphoreTake(xSemaphore: SemaphoreHandle_t, xBlockTime: TickType_t) -> BaseType_t {
unsafe { xQueueGenericReceive(xSemaphore, core::ptr::null(), xBlockTime, pdFALSE) }
}
pub unsafe fn xSemaphoreGive(xSemaphore: SemaphoreHandle_t) -> BaseType_t {
unsafe {
xQueueGenericSend(
xSemaphore,
core::ptr::null(),
semGIVE_BLOCK_TIME,
queueSEND_TO_BACK,
)
}
}
pub unsafe fn xSemaphoreCreateMutex() -> SemaphoreHandle_t {
unsafe { xQueueCreateMutex(queueQUEUE_TYPE_MUTEX) }
}
pub unsafe fn vSemaphoreDelete(xSemaphore: SemaphoreHandle_t) {
unsafe { vQueueDelete(xSemaphore) }
}