SmartSnippets DA1459x SDK
sdk
middleware
osal
osal_freertos.h
Go to the documentation of this file.
1
41
#ifndef OSAL_FREERTOS_H_
42
#define OSAL_FREERTOS_H_
43
44
#if defined(OS_FREERTOS)
45
46
#include <FreeRTOS.h>
47
#include <event_groups.h>
48
#include <semphr.h>
49
#include <task.h>
50
#include <queue.h>
51
#include <timers.h>
52
#include <
interrupts.h
>
53
#include <atomic.h>
54
55
/*
56
* OSAL CONFIGURATION FORWARD MACROS
57
*****************************************************************************************
58
*/
59
60
/* Enable use of low power tickless mode */
61
#define _OS_USE_TICKLESS_IDLE ( configUSE_TICKLESS_IDLE > 0 )
62
/* Total size of heap memory available for the OS */
63
#define _OS_TOTAL_HEAP_SIZE ( configTOTAL_HEAP_SIZE )
64
/* Word size used for the items stored to the stack */
65
#define _OS_STACK_WORD_SIZE ( sizeof(StackType_t) )
66
/* Minimal stack size (in bytes) defined for an OS task */
67
#define _OS_MINIMAL_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * _OS_STACK_WORD_SIZE )
68
/* Priority of timer daemon OS task */
69
#define _OS_DAEMON_TASK_PRIORITY ( configTIMER_TASK_PRIORITY )
70
71
/*
72
* OSAL DATA TYPE AND ENUMERATION FORWARD MACROS
73
*****************************************************************************************
74
*/
75
76
/* OS task priority values */
77
#define _OS_TASK_PRIORITY_LOWEST ( tskIDLE_PRIORITY )
78
#define _OS_TASK_PRIORITY_NORMAL ( tskIDLE_PRIORITY + 1 )
79
#define _OS_TASK_PRIORITY_HIGHEST ( configMAX_PRIORITIES - 1 )
80
81
/* Data types and enumerations for OS tasks and functions that operate on them */
82
#define _OS_TASK TaskHandle_t
83
#define _OS_TASK_STATUS TaskStatus_t
84
#define _OS_TASK_CREATE_SUCCESS pdPASS
85
#define _OS_TASK_NOTIFY_SUCCESS pdPASS
86
#define _OS_TASK_NOTIFY_FAIL pdFALSE
87
#define _OS_TASK_NOTIFY_NO_WAIT 0
88
#define _OS_TASK_NOTIFY_FOREVER portMAX_DELAY
89
#define _OS_TASK_NOTIFY_NONE 0
90
#define _OS_TASK_NOTIFY_ALL_BITS 0xFFFFFFFF
91
92
/* Data types and enumerations for OS mutexes and functions that operate on them */
93
#define _OS_MUTEX SemaphoreHandle_t
94
#define _OS_MUTEX_CREATE_SUCCESS 1
95
#define _OS_MUTEX_CREATE_FAIL 0
96
#define _OS_MUTEX_TAKEN pdTRUE
97
#define _OS_MUTEX_NOT_TAKEN pdFALSE
98
#define _OS_MUTEX_NO_WAIT 0
99
#define _OS_MUTEX_FOREVER portMAX_DELAY
100
101
/* Data types and enumerations for OS events and functions that operate on them */
102
#define _OS_EVENT SemaphoreHandle_t
103
#define _OS_EVENT_CREATE_SUCCESS 1
104
#define _OS_EVENT_CREATE_FAIL 0
105
#define _OS_EVENT_SIGNALED pdTRUE
106
#define _OS_EVENT_NOT_SIGNALED pdFALSE
107
#define _OS_EVENT_NO_WAIT 0
108
#define _OS_EVENT_FOREVER portMAX_DELAY
109
110
/* Data types and enumerations for OS event groups and functions that operate on them */
111
#define _OS_EVENT_GROUP EventGroupHandle_t
112
#define _OS_EVENT_GROUP_OK pdTRUE
113
#define _OS_EVENT_GROUP_FAIL pdFALSE
114
#define _OS_EVENT_GROUP_NO_WAIT 0
115
#define _OS_EVENT_GROUP_FOREVER portMAX_DELAY
116
117
/* Data types and enumerations for OS queues and functions that operate on them */
118
#define _OS_QUEUE QueueHandle_t
119
#define _OS_QUEUE_OK pdTRUE
120
#define _OS_QUEUE_FULL errQUEUE_FULL
121
#define _OS_QUEUE_EMPTY errQUEUE_EMPTY
122
#define _OS_QUEUE_NO_WAIT 0
123
#define _OS_QUEUE_FOREVER portMAX_DELAY
124
125
/* Data types and enumerations for OS timers and functions that operate on them */
126
#define _OS_TIMER TimerHandle_t
127
#define _OS_TIMER_SUCCESS pdPASS
128
#define _OS_TIMER_FAIL pdFAIL
129
#define _OS_TIMER_RELOAD pdTRUE
130
#define _OS_TIMER_ONCE pdFALSE
131
#define _OS_TIMER_NO_WAIT 0
132
#define _OS_TIMER_FOREVER portMAX_DELAY
133
134
/* Base data types matching underlying architecture */
135
#define _OS_BASE_TYPE BaseType_t
136
#define _OS_UBASE_TYPE UBaseType_t
137
138
/* Enumeration values indicating successful or not OS operation */
139
#define _OS_OK pdPASS
140
#define _OS_FAIL pdFAIL
141
142
/* Boolean enumeration values */
143
#define _OS_TRUE pdTRUE
144
#define _OS_FALSE pdFALSE
145
146
/* Maximum OS delay (in OS ticks) */
147
#define _OS_MAX_DELAY portMAX_DELAY
148
149
/* OS tick time (i.e. time expressed in OS ticks) data type */
150
#define _OS_TICK_TIME TickType_t
151
152
/* OS tick period (in cycles of source clock used for the OS timer) */
153
#define _OS_TICK_PERIOD TICK_PERIOD
154
155
/* OS tick period (in msec) */
156
#define _OS_TICK_PERIOD_MS portTICK_PERIOD_MS
157
158
/* Frequency (in Hz) of the source clock used for the OS timer */
159
#define _OS_TICK_CLOCK_HZ configSYSTICK_CLOCK_HZ
160
161
/* Data type of OS task function (i.e. OS_TASK_FUNCTION) argument */
162
#define _OS_TASK_ARG_TYPE void *
163
164
/* Data types and enumerations for OS Atomic operations */
165
#define _OS_ATOMIC_COMPARE_AND_SWAP_SUCCESS ATOMIC_COMPARE_AND_SWAP_SUCCESS
166
#define _OS_ATOMIC_COMPARE_AND_SWAP_FAILURE ATOMIC_COMPARE_AND_SWAP_FAILURE
167
168
/* Data type about the output of _OS_GET_HEAP_STATISTICS() */
169
#define _OS_HEAP_STATISTICS_TYPE HeapStats_t
170
171
/*
172
* OSAL ENUMERATIONS
173
*****************************************************************************************
174
*/
175
176
/* OS task notification action */
177
#define _OS_NOTIFY_NO_ACTION eNoAction
178
#define _OS_NOTIFY_SET_BITS eSetBits
179
#define _OS_NOTIFY_INCREMENT eIncrement
180
#define _OS_NOTIFY_VAL_WITH_OVERWRITE eSetValueWithOverwrite
181
#define _OS_NOTIFY_VAL_WITHOUT_OVERWRITE eSetValueWithoutOverwrite
182
183
/* OS task state */
184
#define _OS_TASK_RUNNING eRunning
185
#define _OS_TASK_READY eReady
186
#define _OS_TASK_BLOCKED eBlocked
187
#define _OS_TASK_SUSPENDED eSuspended
188
#define _OS_TASK_DELETED eDeleted
189
190
/* OS scheduler state */
191
#define _OS_SCHEDULER_RUNNING taskSCHEDULER_RUNNING
192
#define _OS_SCHEDULER_NOT_STARTED taskSCHEDULER_NOT_STARTED
193
#define _OS_SCHEDULER_SUSPENDED taskSCHEDULER_SUSPENDED
194
195
/*
196
* OSAL MACRO FUNCTION DEFINITIONS
197
*****************************************************************************************
198
*/
199
200
/* Declare an OS task function */
201
#define _OS_TASK_FUNCTION(func, arg) void func(OS_TASK_ARG_TYPE arg)
202
203
/* Run the OS task scheduler */
204
#define _OS_TASK_SCHEDULER_RUN() vTaskStartScheduler()
205
206
/* Convert a time in milliseconds to a time in OS ticks */
207
#define _OS_TIME_TO_TICKS(time_in_ms) pdMS_TO_TICKS(time_in_ms)
208
209
/* Return current OS task handle */
210
#if (INCLUDE_xTaskGetCurrentTaskHandle == 1) || (configUSE_MUTEXES == 1)
211
#define _OS_GET_CURRENT_TASK() xTaskGetCurrentTaskHandle()
212
#else
213
#define _OS_GET_CURRENT_TASK()
214
#endif
/* INCLUDE_xTaskGetCurrentTaskHandle || configUSE_MUTEXES */
215
216
/* Create OS task */
217
#define _OS_TASK_CREATE(name, task_func, arg, stack_size, priority, task) \
218
xTaskCreate((task_func), (name), (((stack_size) - 1) / _OS_STACK_WORD_SIZE + 1), \
219
(arg), (priority), &(task))
220
221
/* Delete OS task */
222
#define _OS_TASK_DELETE(task) vTaskDelete(task)
223
224
/* Get the priority of an OS task */
225
#define _OS_TASK_PRIORITY_GET(task) \
226
({ \
227
UBaseType_t ret; \
228
_OS_ASSERT(!in_interrupt()); \
229
ret = uxTaskPriorityGet(task); \
230
ret; \
231
})
232
233
/* Get the priority of an OS task from ISR */
234
#define _OS_TASK_PRIORITY_GET_FROM_ISR(task) uxTaskPriorityGetFromISR(task)
235
236
/* Set the priority of an OS task */
237
#define _OS_TASK_PRIORITY_SET(task, prio) vTaskPrioritySet((task), (prio))
238
239
/* The running OS task yields control to the scheduler */
240
#define _OS_TASK_YIELD() \
241
do { \
242
_OS_ASSERT(!in_interrupt()); \
243
portYIELD(); \
244
} while (0)
245
246
/* The running OS task yields control to the scheduler from ISR */
247
#define _OS_TASK_YIELD_FROM_ISR() portYIELD_FROM_ISR(pdTRUE)
248
249
/* Send notification to OS task, updating its notification value */
250
#define _OS_TASK_NOTIFY(task, value, action) \
251
({ \
252
BaseType_t ret; \
253
_OS_ASSERT(!in_interrupt()); \
254
ret = xTaskNotify((task), (value), (action)); \
255
ret; \
256
})
257
258
/* Send notification to OS task, updating one notification index value */
259
#define _OS_TASK_NOTIFY_INDEXED(task, index, value, action) \
260
({ \
261
BaseType_t ret; \
262
_OS_ASSERT(!in_interrupt()); \
263
xTaskNotifyIndexed((task), (index), (value), (action)); \
264
ret; \
265
})
266
267
/* Send notification to OS task, updating its notification value and returning previous value */
268
#define _OS_TASK_NOTIFY_AND_QUERY(task, value, action, prev_value) \
269
({ \
270
BaseType_t ret; \
271
_OS_ASSERT(!in_interrupt()); \
272
xTaskNotifyAndQuery((task), (value), (action), (prev_value)); \
273
ret; \
274
})
275
276
/* Send notification to OS task, updating one notification index value and returning previous value */
277
#define _OS_TASK_NOTIFY_AND_QUERY_INDEXED(task, index, value, action, prev_value) \
278
({ \
279
BaseType_t ret; \
280
_OS_ASSERT(!in_interrupt()); \
281
xTaskNotifyAndQueryIndexed((task), (index), (value), (action), (prev_value)); \
282
ret; \
283
})
284
285
/* Send notification to OS task from ISR, updating its notification value */
286
#define _OS_TASK_NOTIFY_FROM_ISR(task, value, action) \
287
({ \
288
BaseType_t need_switch = pdFALSE, ret; \
289
ret = xTaskNotifyFromISR((task), (value), (action), &need_switch); \
290
portEND_SWITCHING_ISR(need_switch); \
291
ret; \
292
})
293
294
/* Send notification to OS task from ISR, updating one notification index value */
295
#define _OS_TASK_NOTIFY_INDEXED_FROM_ISR(task, index, value, action) \
296
({ \
297
BaseType_t need_switch = pdFALSE, ret; \
298
ret = xTaskNotifyIndexedFromISR((task), (index), (value), (action), &need_switch) \
299
portEND_SWITCHING_ISR(need_switch); \
300
ret; \
301
})
302
303
/* Send notification to OS task from ISR, updating its notification value and returning
304
* previous value */
305
#define _OS_TASK_NOTIFY_AND_QUERY_FROM_ISR(task, value, action, prev_value) \
306
({ \
307
BaseType_t need_switch = pdFALSE, ret; \
308
ret = xTaskNotifyAndQueryFromISR((task), (value), (action), (prev_value), \
309
&need_switch); \
310
portEND_SWITCHING_ISR(need_switch); \
311
ret; \
312
})
313
314
/* Send notification to OS task from ISR, updating one notification index value and returning
315
* previous value */
316
#define _OS_TASK_NOTIFY_AND_QUERY_INDEXED_FROM_ISR(task, index, value, action, prev_value) \
317
({ \
318
BaseType_t need_switch = pdFALSE, ret; \
319
ret = xTaskNotifyAndQueryIndexedFromISR((task), (index), (value), (action), \
320
(prev_value), &need_switch); \
321
portEND_SWITCHING_ISR(need_switch); \
322
ret; \
323
})
324
325
/* Send a notification event to OS task, incrementing its notification value */
326
#define _OS_TASK_NOTIFY_GIVE(task) \
327
({ \
328
BaseType_t ret; \
329
_OS_ASSERT(!in_interrupt()); \
330
ret = xTaskNotifyGive(task); \
331
ret; \
332
})
333
334
/* Send a notification event to OS task, incrementing a notification index value */
335
#define _OS_TASK_NOTIFY_GIVE_INDEXED(task, index) \
336
({ \
337
BaseType_t ret; \
338
_OS_ASSERT(!in_interrupt()); \
339
ret = xTaskNotifyGiveIndexed((task), (index)); \
340
ret; \
341
})
342
343
/* Send a notification event to OS task from ISR, incrementing its notification value */
344
#define _OS_TASK_NOTIFY_GIVE_FROM_ISR(task) \
345
({ \
346
BaseType_t need_switch = pdFALSE; \
347
vTaskNotifyGiveFromISR((task), &need_switch); \
348
portEND_SWITCHING_ISR(need_switch); \
349
})
350
351
/* Send a notification event to OS task from ISR, incrementing a notification index value */
352
#define _OS_TASK_NOTIFY_GIVE_INDEXED_FROM_ISR(task, index) \
353
({ \
354
BaseType_t need_switch = pdFALSE; \
355
vTaskNotifyGiveIndexedFromISR((task), (index), &need_switch) \
356
portEND_SWITCHING_ISR(need_switch); \
357
})
358
359
/* Wait for the calling OS task to receive a notification event, clearing to zero or
360
* decrementing task notification value on exit */
361
#define _OS_TASK_NOTIFY_TAKE(clear_on_exit, time_to_wait) \
362
ulTaskNotifyTake((clear_on_exit), (time_to_wait))
363
364
/* Wait for the calling OS task to receive a notification event, clearing to zero or
365
* decrementing task notification index value on exit */
366
#define _OS_TASK_NOTIFY_TAKE_INDEXED(index, clear_on_exit, time_to_wait) \
367
ulTaskNotifyTakeIndexed((index), (clear_on_exit), (time_to_wait))
368
369
/* Clear the notification state of an aS task */
370
#define _OS_TASK_NOTIFY_STATE_CLEAR(task) xTaskNotifyStateClear(task)
371
372
/* Clear a notification index state of an OS task */
373
#define _OS_TASK_NOTIFY_STATE_CLEAR_INDEXED(task, index) \
374
xTaskNotifyStateClearIndexed((task), (index))
375
376
/* Clear specific bits in the notification value of an OS task */
377
#define _OS_TASK_NOTIFY_VALUE_CLEAR(task, bits_to_clear) \
378
ulTaskNotifyValueClear((task), (bits_to_clear))
379
380
/* Clear specific bits in one notification index value of an OS task */
381
#define _OS_TASK_NOTIFY_VALUE_CLEAR_INDEXED(task, index,bits_to_clear) \
382
ulTaskNotifyValueClearIndexed((task), (index), (bits_to_clear))
383
384
/* Wait for the calling OS task to receive a notification, updating task notification value
385
* on exit */
386
#define _OS_TASK_NOTIFY_WAIT(entry_bits, exit_bits, value, ticks_to_wait) \
387
xTaskNotifyWait((entry_bits), (exit_bits), (value), (ticks_to_wait))
388
389
/* Wait for the calling OS task to receive a notification index, updating notification value
390
* on exit */
391
#define _OS_TASK_NOTIFY_WAIT_INDEXED(index, entry_bits, exit_bits, value, ticks_to_wait) \
392
xTaskNotifyWaitIndexed((index), (entry_bits), (exit_bits), (value), (ticks_to_wait))
393
394
/* Resume OS task */
395
#define _OS_TASK_RESUME(task) \
396
do { \
397
_OS_ASSERT(!in_interrupt()); \
398
vTaskResume(task); \
399
} while (0)
400
401
/* Resume OS task from ISR */
402
#define _OS_TASK_RESUME_FROM_ISR(task) xTaskResumeFromISR(task)
403
404
/* Suspend OS task */
405
#define _OS_TASK_SUSPEND(task) \
406
do { \
407
_OS_ASSERT(!in_interrupt()); \
408
vTaskSuspend(task); \
409
} while (0)
410
411
/* Resume the Scheduler */
412
#define _OS_TASK_RESUME_ALL() xTaskResumeAll();
413
414
/* Suspend the Scheduler */
415
#define _OS_TASK_SUSPEND_ALL() vTaskSuspendAll();
416
417
/* Create OS mutex */
418
#define _OS_MUTEX_CREATE(mutex) \
419
({ \
420
(mutex) = xSemaphoreCreateRecursiveMutex(); \
421
(mutex) != NULL ? OS_MUTEX_CREATE_SUCCESS : OS_MUTEX_CREATE_FAIL; \
422
})
423
424
/* Delete OS mutex */
425
#define _OS_MUTEX_DELETE(mutex) vSemaphoreDelete(mutex)
426
427
/* Release OS mutex */
428
#define _OS_MUTEX_PUT(mutex) xSemaphoreGiveRecursive(mutex)
429
430
/* Acquire OS mutex */
431
#define _OS_MUTEX_GET(mutex, timeout) xSemaphoreTakeRecursive((mutex), (timeout))
432
433
/* Get OS task owner of OS mutex */
434
#define _OS_MUTEX_GET_OWNER(mutex) \
435
({ \
436
TaskHandle_t ret; \
437
_OS_ASSERT(!in_interrupt()); \
438
ret = xQueueGetMutexHolder(mutex); \
439
ret; \
440
})
441
442
/* Get OS task owner of OS mutex from ISR */
443
#define _OS_MUTEX_GET_OWNER_FROM_ISR(mutex) xQueueGetMutexHolderFromISR(mutex)
444
445
/* Get OS mutex current count value */
446
#define _OS_MUTEX_GET_COUNT(mutex) \
447
({ \
448
UBaseType_t ret; \
449
_OS_ASSERT(!in_interrupt()); \
450
ret = uxSemaphoreGetCount(mutex); \
451
ret; \
452
})
453
454
/* Get OS mutex current count value from ISR */
455
#define _OS_MUTEX_GET_COUNT_FROM_ISR(mutex) uxQueueMessagesWaitingFromISR(mutex)
456
457
/* Create OS event */
458
#define _OS_EVENT_CREATE(event) do { (event) = xSemaphoreCreateBinary(); } while (0)
459
460
/* Delete OS event */
461
#define _OS_EVENT_DELETE(event) vSemaphoreDelete(event)
462
463
/* Set OS event in signaled state */
464
#define _OS_EVENT_SIGNAL(event) \
465
({ \
466
BaseType_t ret; \
467
_OS_ASSERT(!in_interrupt()); \
468
ret = xSemaphoreGive(event); \
469
ret; \
470
})
471
472
/* Set OS event in signaled state from ISR */
473
#define _OS_EVENT_SIGNAL_FROM_ISR(event) \
474
({ \
475
BaseType_t need_switch = pdFALSE, ret; \
476
ret = xSemaphoreGiveFromISR((event), &need_switch); \
477
portEND_SWITCHING_ISR(need_switch); \
478
ret; \
479
})
480
481
/* Set OS event in signaled state from ISR without requesting running OS task to yield */
482
#define _OS_EVENT_SIGNAL_FROM_ISR_NO_YIELD(event, need_yield) \
483
xSemaphoreGiveFromISR((event), (need_yield))
484
485
/* Wait for OS event to be signaled */
486
#define _OS_EVENT_WAIT(event, timeout) xSemaphoreTake((event), (timeout))
487
488
/* Check if OS event is signaled and clear it */
489
#define _OS_EVENT_CHECK(event) \
490
({ \
491
BaseType_t ret; \
492
_OS_ASSERT(!in_interrupt()); \
493
ret = xSemaphoreTake((event), OS_EVENT_NO_WAIT); \
494
ret; \
495
})
496
497
/* Check from ISR if OS event is signaled and clear it */
498
#define _OS_EVENT_CHECK_FROM_ISR(event) \
499
({ \
500
BaseType_t need_switch = pdFALSE, ret; \
501
ret = xSemaphoreTakeFromISR((event), &need_switch); \
502
portEND_SWITCHING_ISR(need_switch); \
503
ret; \
504
})
505
506
/* Check from ISR if OS event is signaled and clear it, without requesting running
507
* OS task to yield */
508
#define _OS_EVENT_CHECK_FROM_ISR_NO_YIELD(event, need_yield) \
509
xSemaphoreTakeFromISR((event), (need_yield))
510
511
/* Get OS event status */
512
#define _OS_EVENT_GET_STATUS(event) \
513
({ \
514
_OS_ASSERT(!in_interrupt()); \
515
((uxSemaphoreGetCount(event) > 0) ? OS_EVENT_SIGNALED : OS_EVENT_NOT_SIGNALED); \
516
})
517
518
/* Get OS event status from ISR */
519
#define _OS_EVENT_GET_STATUS_FROM_ISR(event) \
520
((xQueueIsQueueEmptyFromISR(event) != pdFALSE) ? OS_EVENT_NOT_SIGNALED : OS_EVENT_SIGNALED)
521
522
/* Create OS event group */
523
#define _OS_EVENT_GROUP_CREATE() xEventGroupCreate()
524
525
/* Wait for OS event group bits to become set */
526
#define _OS_EVENT_GROUP_WAIT_BITS(event_group, bits_to_wait, clear_on_exit, wait_for_all, timeout) \
527
({ \
528
EventBits_t ret; \
529
_OS_ASSERT(!in_interrupt()); \
530
ret = xEventGroupWaitBits((event_group), (bits_to_wait), (clear_on_exit), (wait_for_all), (timeout)); \
531
ret; \
532
})
533
534
/* Set OS event group bits */
535
#define _OS_EVENT_GROUP_SET_BITS(event_group, bits_to_set) \
536
({ \
537
EventBits_t ret; \
538
_OS_ASSERT(!in_interrupt()); \
539
ret = xEventGroupSetBits((event_group), (bits_to_set)); \
540
ret; \
541
})
542
543
/* Set OS event group bits from ISR */
544
#define _OS_EVENT_GROUP_SET_BITS_FROM_ISR(event_group, bits_to_set) \
545
({ \
546
BaseType_t need_switch = pdFALSE, ret; \
547
ret = xEventGroupSetBitsFromISR((event_group), (bits_to_set), &need_switch); \
548
portEND_SWITCHING_ISR(need_switch); \
549
ret; \
550
})
551
552
/* Set OS event group bits from ISR without requesting running OS task to yield */
553
#define _OS_EVENT_GROUP_SET_BITS_FROM_ISR_NO_YIELD(event_group, bits_to_set, need_yield) \
554
xEventGroupSetBitsFromISR((event_group), (bits_to_set), (need_yield))
555
556
/* Clear OS event group bits */
557
#define _OS_EVENT_GROUP_CLEAR_BITS(event_group, bits_to_clear) \
558
({ \
559
EventBits_t ret; \
560
_OS_ASSERT(!in_interrupt()); \
561
ret = xEventGroupClearBits((event_group), (bits_to_clear)); \
562
ret; \
563
})
564
565
/* Clear OS event group bits from an interrupt */
566
#define _OS_EVENT_GROUP_CLEAR_BITS_FROM_ISR(event_group, bits_to_clear) \
567
xEventGroupClearBitsFromISR((event_group), (bits_to_clear))
568
569
/* Get OS event group bits */
570
#define _OS_EVENT_GROUP_GET_BITS(event_group) \
571
({ \
572
EventBits_t ret; \
573
_OS_ASSERT(!in_interrupt()); \
574
ret = xEventGroupGetBits(event_group); \
575
ret; \
576
})
577
578
/* Get OS event group bits from an interrupt */
579
#define _OS_EVENT_GROUP_GET_BITS_FROM_ISR(event_group) xEventGroupGetBitsFromISR(event_group)
580
581
/* Synchronize OS event group bits */
582
#define _OS_EVENT_GROUP_SYNC(event_group, bits_to_set, bits_to_wait, timeout) \
583
({ \
584
EventBits_t ret; \
585
_OS_ASSERT(!in_interrupt()); \
586
ret = xEventGroupSync((event_group), (bits_to_set), (bits_to_wait), (timeout)); \
587
ret; \
588
})
589
590
/* Delete OS event group */
591
#define _OS_EVENT_GROUP_DELETE(event_group) vEventGroupDelete(event_group)
592
593
/* Create OS queue */
594
#define _OS_QUEUE_CREATE(queue, item_size, max_items) \
595
do { (queue) = xQueueCreate((max_items), (item_size)); } while (0)
596
597
/* Deletes OS queue */
598
#define _OS_QUEUE_DELETE(queue) vQueueDelete(queue)
599
600
/* Put element in OS queue */
601
#define _OS_QUEUE_PUT(queue, item, timeout) \
602
({ \
603
BaseType_t ret; \
604
_OS_ASSERT(!in_interrupt()); \
605
ret = xQueueSendToBack((queue), (item), (timeout)); \
606
ret; \
607
})
608
609
/* Put element in OS queue */
610
#define _OS_QUEUE_PUT_FROM_ISR(queue, item) \
611
({ \
612
BaseType_t need_switch = pdFALSE, ret; \
613
ret = xQueueSendToBackFromISR((queue), (item), &need_switch); \
614
portEND_SWITCHING_ISR(need_switch); \
615
ret; \
616
})
617
618
/* Replace element in OS queue of one element */
619
#define _OS_QUEUE_REPLACE(queue, item) \
620
({ \
621
BaseType_t ret; \
622
_OS_ASSERT(!in_interrupt()); \
623
ret = xQueueOverwrite((queue), (item)); \
624
ret; \
625
})
626
627
/* Replace element in OS queue of one element from ISR */
628
#define _OS_QUEUE_REPLACE_FROM_ISR(queue, item) \
629
({ \
630
BaseType_t need_switch = pdFALSE, ret; \
631
ret = xQueueOverwriteFromISR((queue), (item), &need_switch); \
632
portEND_SWITCHING_ISR(need_switch); \
633
ret; \
634
})
635
636
/* Replace element in OS queue of one element from ISR without requesting running OS task to yield */
637
#define _OS_QUEUE_REPLACE_FROM_ISR_NO_YIELD(queue, item, need_yield) \
638
xQueueOverwriteFromISR((queue), (item), (need_yield))
639
640
/* Get element from OS queue */
641
#define _OS_QUEUE_GET(queue, item, timeout) \
642
({ \
643
BaseType_t ret; \
644
_OS_ASSERT(!in_interrupt()); \
645
ret = xQueueReceive((queue), (item), (timeout)); \
646
ret; \
647
})
648
649
/* Get element from OS queue from ISR */
650
#define _OS_QUEUE_GET_FROM_ISR(queue, item) \
651
({ \
652
BaseType_t need_switch = pdFALSE, ret; \
653
ret = xQueueReceiveFromISR((queue), (item), &need_switch); \
654
portEND_SWITCHING_ISR(need_switch); \
655
ret; \
656
})
657
658
/* Get element from OS queue from ISR without requesting running OS task to yield */
659
#define _OS_QUEUE_GET_FROM_ISR_NO_YIELD(queue, item, need_yield) \
660
xQueueReceiveFromISR((queue), (item), (need_yield))
661
662
/* Peek element from OS queue */
663
#define _OS_QUEUE_PEEK(queue, item, timeout) \
664
({ \
665
BaseType_t ret; \
666
_OS_ASSERT(!in_interrupt()); \
667
ret = xQueuePeek((queue), (item), (timeout)); \
668
ret; \
669
})
670
671
/* Peek element from OS queue from ISR */
672
#define _OS_QUEUE_PEEK_FROM_ISR(queue, item) xQueuePeekFromISR((queue), (item))
673
674
/* Get the number of messages stored in OS queue */
675
#define _OS_QUEUE_MESSAGES_WAITING(queue) \
676
({ \
677
UBaseType_t ret; \
678
_OS_ASSERT(!in_interrupt()); \
679
ret = uxQueueMessagesWaiting(queue); \
680
ret; \
681
})
682
683
/* Get the number of messages stored in OS queue from ISR */
684
#define _OS_QUEUE_MESSAGES_WAITING_FROM_ISR(queue) uxQueueMessagesWaitingFromISR(queue)
685
686
/* Get the number of free spaces in OS queue */
687
#define _OS_QUEUE_SPACES_AVAILABLE(queue) uxQueueSpacesAvailable(queue)
688
689
/* Create OS timer */
690
#define _OS_TIMER_CREATE(name, period, reload, timer_id, callback) \
691
xTimerCreate((name), (period), (((reload) == OS_TIMER_ONCE) ? pdFALSE : pdTRUE), \
692
((void *) (timer_id)), (callback))
693
694
/* Get OS timer ID */
695
#define _OS_TIMER_GET_TIMER_ID(timer) pvTimerGetTimerID(timer)
696
697
/* Check if OS timer is active */
698
#define _OS_TIMER_IS_ACTIVE(timer) xTimerIsTimerActive(timer)
699
700
/* Start OS timer */
701
#define _OS_TIMER_START(timer, timeout) \
702
({ \
703
BaseType_t ret; \
704
_OS_ASSERT(!in_interrupt()); \
705
ret = xTimerStart((timer), (timeout)); \
706
ret; \
707
})
708
709
/* Stop OS timer */
710
#define _OS_TIMER_STOP(timer, timeout) \
711
({ \
712
BaseType_t ret; \
713
_OS_ASSERT(!in_interrupt()); \
714
ret = xTimerStop((timer), (timeout)); \
715
ret; \
716
})
717
718
/* Change OS timer's period */
719
#define _OS_TIMER_CHANGE_PERIOD(timer, period, timeout) \
720
({ \
721
BaseType_t ret; \
722
_OS_ASSERT(!in_interrupt()); \
723
ret = xTimerChangePeriod((timer), (period), (timeout)); \
724
ret; \
725
})
726
727
/* Delete OS timer */
728
#define _OS_TIMER_DELETE(timer, timeout) xTimerDelete((timer), (timeout))
729
730
/* Reset OS timer */
731
#define _OS_TIMER_RESET(timer, timeout) \
732
({ \
733
BaseType_t ret; \
734
_OS_ASSERT(!in_interrupt()); \
735
ret = xTimerReset((timer), (timeout)); \
736
ret; \
737
})
738
739
/* Start OS timer from ISR */
740
#define _OS_TIMER_START_FROM_ISR(timer) \
741
({ \
742
BaseType_t need_switch = pdFALSE, ret; \
743
ret = xTimerStartFromISR((timer), &need_switch); \
744
portEND_SWITCHING_ISR(need_switch); \
745
ret; \
746
})
747
748
/* Stop OS timer from ISR */
749
#define _OS_TIMER_STOP_FROM_ISR(timer) \
750
({ \
751
BaseType_t need_switch = pdFALSE, ret; \
752
ret = xTimerStopFromISR((timer), &need_switch); \
753
portEND_SWITCHING_ISR(need_switch); \
754
ret; \
755
})
756
757
/* Change OS timer period from ISR */
758
#define _OS_TIMER_CHANGE_PERIOD_FROM_ISR(timer, period) \
759
({ \
760
BaseType_t need_switch = pdFALSE, ret; \
761
ret = xTimerChangePeriodFromISR((timer), (period), &need_switch); \
762
portEND_SWITCHING_ISR(need_switch); \
763
ret; \
764
})
765
766
/* Reset OS timer from ISR */
767
#define _OS_TIMER_RESET_FROM_ISR(timer) \
768
({ \
769
BaseType_t need_switch = pdFALSE, ret; \
770
ret = xTimerResetFromISR((timer), &need_switch); \
771
portEND_SWITCHING_ISR(need_switch); \
772
ret; \
773
})
774
775
/* Set OS timer auto-reload mode */
776
#define _OS_TIMER_SET_RELOAD_MODE(timer, auto_reload) vTimerSetReloadMode((timer), (auto_reload))
777
778
/* Get OS timer auto-reload mode */
779
#define _OS_TIMER_GET_RELOAD_MODE(timer) uxTimerGetReloadMode(timer)
780
781
/* Delay execution of OS task for specified time */
782
#define _OS_DELAY(ticks) vTaskDelay(ticks)
783
784
/* Delay execution of OS task until specified time */
785
#define _OS_DELAY_UNTIL(ticks) \
786
{ \
787
TickType_t prev_wake_time = xTaskGetTickCount(); \
788
vTaskDelayUntil(&prev_wake_time, ticks - prev_wake_time); \
789
}
790
791
/* Get current OS tick count */
792
#define _OS_GET_TICK_COUNT() \
793
({ \
794
TickType_t ret; \
795
_OS_ASSERT(!in_interrupt()); \
796
ret = xTaskGetTickCount(); \
797
ret; \
798
})
799
800
/* Get current OS tick count from ISR */
801
#define _OS_GET_TICK_COUNT_FROM_ISR() xTaskGetTickCountFromISR()
802
803
/* Convert from OS ticks to ms */
804
#define _OS_TICKS_2_MS(ticks) portCONVERT_TICKS_2_MS(ticks)
805
806
/* Convert from ms to OS ticks */
807
#define _OS_MS_2_TICKS(ms) pdMS_TO_TICKS(ms)
808
809
/* Delay execution of OS task for specified time */
810
#define _OS_DELAY_MS(ms) _OS_DELAY(_OS_MS_2_TICKS(ms))
811
812
/* Enter critical section from non-ISR context */
813
#define _OS_ENTER_CRITICAL_SECTION() \
814
do { \
815
_OS_ASSERT(!in_interrupt()); \
816
portENTER_CRITICAL(); \
817
} while (0)
818
819
/* Enter critical section from ISR context */
820
#define _OS_ENTER_CRITICAL_SECTION_FROM_ISR(critical_section_status) \
821
do { \
822
critical_section_status = portSET_INTERRUPT_MASK_FROM_ISR(); \
823
} while (0)
824
825
/* Leave critical section from non-ISR context */
826
#define _OS_LEAVE_CRITICAL_SECTION() \
827
do { \
828
_OS_ASSERT(!in_interrupt()); \
829
portEXIT_CRITICAL(); \
830
} while (0)
831
832
/* Leave critical section from ISR context */
833
#define _OS_LEAVE_CRITICAL_SECTION_FROM_ISR(critical_section_status) \
834
do { \
835
portCLEAR_INTERRUPT_MASK_FROM_ISR(critical_section_status); \
836
} while (0)
837
838
839
/* Name for OS memory allocation function */
840
#define _OS_MALLOC_FUNC pvPortMalloc
841
842
/* Name for non-retain memory allocation function */
843
#define _OS_MALLOC_NORET_FUNC pvPortMalloc
844
845
/* Allocate memory from OS provided heap */
846
#define _OS_MALLOC(size) _OS_MALLOC_FUNC(size)
847
848
/* Allocate memory from non-retain heap */
849
#define _OS_MALLOC_NORET(size) _OS_MALLOC_NORET_FUNC(size)
850
851
/* Name for OS free memory function */
852
#define _OS_FREE_FUNC vPortFree
853
854
/* Name for non-retain memory free function */
855
#define _OS_FREE_NORET_FUNC vPortFree
856
857
/* Free memory allocated by OS_MALLOC() */
858
#define _OS_FREE(addr) _OS_FREE_FUNC(addr)
859
860
/* Free memory allocated by OS_MALLOC_NORET() */
861
#define _OS_FREE_NORET(addr) _OS_FREE_NORET_FUNC(addr)
862
863
/* OS assertion */
864
#if (configASSERT_DEFINED == 1)
865
#define _OS_ASSERT(cond) configASSERT(cond)
866
#endif
/* configASSERT_DEFINED */
867
868
/* OS precondition */
869
#define _OS_PRECONDITION(cond) configPRECONDITION(cond)
870
871
/* OS memory barrier */
872
#ifdef portMEMORY_BARRIER
873
#define _OS_MEMORY_BARRIER() portMEMORY_BARRIER()
874
#endif
875
876
/*OS software barrier */
877
#ifdef portSOFTWARE_BARRIER
878
#define _OS_SOFTWARE_BARRIER() portSOFTWARE_BARRIER()
879
#endif
880
881
/* Get OS task status */
882
#if (configUSE_TRACE_FACILITY == 1)
883
#define _OS_GET_TASKS_STATUS(task_status, status_size) \
884
uxTaskGetSystemState((task_status), (status_size), NULL)
885
#else
886
#define _OS_GET_TASKS_STATUS(task_status, status_size)
887
#endif
/* configUSE_TRACE_FACILITY */
888
889
/* Get the high water mark of the stack associated with an OS task */
890
#if (INCLUDE_uxTaskGetStackHighWaterMark == 1)
891
#define _OS_GET_TASK_STACK_WATERMARK(task) uxTaskGetStackHighWaterMark(task)
892
#else
893
#define _OS_GET_TASK_STACK_WATERMARK(task)
894
#endif
/* INCLUDE_uxTaskGetStackHighWaterMark */
895
896
/* Get the high water mark of heap */
897
#define _OS_GET_HEAP_WATERMARK() xPortGetMinimumEverFreeHeapSize()
898
899
/* Get current free heap size */
900
#define _OS_GET_FREE_HEAP_SIZE() xPortGetFreeHeapSize()
901
902
/* Get current number of OS tasks */
903
#define _OS_GET_TASKS_NUMBER() uxTaskGetNumberOfTasks()
904
905
/* Get OS task name */
906
#define _OS_GET_TASK_NAME(task) pcTaskGetTaskName(task)
907
908
/* Get OS task state */
909
#if (INCLUDE_eTaskGetState == 1)
910
#define _OS_GET_TASK_STATE(task) eTaskGetState(task)
911
#else
912
#define _OS_GET_TASK_STATE(task)
913
#endif
/* INCLUDE_eTaskGetState */
914
915
/* Get OS task priority */
916
#if (INCLUDE_uxTaskPriorityGet == 1)
917
#define _OS_GET_TASK_PRIORITY(task) uxTaskPriorityGet(task)
918
#else
919
#define _OS_GET_TASK_PRIORITY(task)
920
#endif
/* INCLUDE_uxTaskPriorityGet */
921
922
/* Get OS task scheduler state */
923
#if ((INCLUDE_xTaskGetSchedulerState == 1) || (configUSE_TIMERS == 1))
924
#define _OS_GET_TASK_SCHEDULER_STATE() xTaskGetSchedulerState()
925
#endif
/* INCLUDE_xTaskGetSchedulerState || configUSE_TIMERS */
926
927
/* Get OS task handle associated with the Idle OS task */
928
#if (INCLUDE_xTaskGetIdleTaskHandle == 1)
929
#define _OS_GET_IDLE_TASK_HANDLE() xTaskGetIdleTaskHandle()
930
#else
931
#define _OS_GET_IDLE_TASK_HANDLE()
932
#endif
/* INCLUDE_xTaskGetIdleTaskHandle */
933
934
/* Get OS task handle by name */
935
#if (INCLUDE_xTaskGetHandle == 1)
936
#define _OS_GET_TASK_HANDLE(task_name) xTaskGetHandle(task_name)
937
#else
938
#define _OS_GET_TASK_HANDLE(task_name)
939
#endif
/* INCLUDE_xTaskGetHandle */
940
941
/* Conditionally change contents of value_location with exchange_value */
942
#define _OS_ATOMIC_COMPARE_AND_SWAP_U32(value_location, exchange_value, swap_condition) \
943
Atomic_CompareAndSwap_u32((value_location), (exchange_value), (swap_condition))
944
945
/* Set the address pointed to by destination_pointer to the value of *exchange_pointer */
946
#define _OS_ATOMIC_SWAP_POINTERS_P32(destination_pointer, exchange_pointer) \
947
Atomic_SwapPointers_p32((destination_pointer), (exchange_pointer))
948
949
/* Conditionally set the address pointed to by destination_pointer to the value of *exchange_pointer */
950
#define _OS_ATOMIC_COMPARE_AND_SWAP_POINTERS_P32(destination_pointer, exchange_pointer, swap_condition) \
951
Atomic_CompareAndSwapPointers_p32((destination_pointer), (exchange_pointer), (swap_condition))
952
953
/* Add add_value to value located at value_location */
954
#define _OS_ATOMIC_ADD_U32(value_location, add_value) \
955
Atomic_Add_u32((value_location), (add_value))
956
957
/* Subtract subtract_value from value located at value_location */
958
#define _OS_ATOMIC_SUBTRACT_U32(value_location, subtract_value) \
959
Atomic_Subtract_u32((value_location), (subtract_value))
960
961
/* Increment value located at value_location by 1*/
962
#define _OS_ATOMIC_INCREMENT_U32(value_location) \
963
Atomic_Increment_u32(value_location)
964
965
/* Decrement value located at value_location by 1*/
966
#define _OS_ATOMIC_DECREMENT_U32(value_location) \
967
Atomic_Decrement_u32(value_location)
968
969
/* Perform OR calculation on value at value_location with or_mask */
970
#define _OS_ATOMIC_OR_U32(value_location, or_mask) \
971
Atomic_OR_u32((value_location), (or_mask))
972
973
/* Perform AND calculation on value at value_location with and_mask */
974
#define _OS_ATOMIC_AND_U32(value_location, and_mask) \
975
Atomic_AND_u32((value_location), (and_mask))
976
977
/* Perform NAND calculation on value at value_location with nand_mask */
978
#define _OS_ATOMIC_NAND_U32(value_location, nand_mask) \
979
Atomic_NAND_u32((value_location), (nand_mask))
980
981
/* Perform XOR calculation on value at value_location with xor_mask */
982
#define _OS_ATOMIC_XOR_U32(value_location, xor_mask) \
983
Atomic_XOR_u32((value_location), (xor_mask))
984
985
/* Get information about the current heap state */
986
#define _OS_GET_HEAP_STATISTICS(results_pointer) vPortGetHeapStats(results_pointer)
987
988
/* ****************************************************** */
989
/* The following macro functions are called by the system */
990
/* ****************************************************** */
991
992
/* Perform processing prior to system stopping (e.g. entering hibernation) */
993
#define _OS_SYS_PRE_STOP_PROCESSING() configPRE_STOP_PROCESSING()
994
995
/* Perform processing prior to system entering sleep */
996
#define _OS_SYS_PRE_SLEEP_PROCESSING(sleep_period) configPRE_SLEEP_PROCESSING(sleep_period)
997
998
/* Perform processing after system waking-up */
999
#define _OS_SYS_POST_SLEEP_PROCESSING() configPOST_SLEEP_PROCESSING()
1000
1001
/* Perform processing prior to system entering idle state */
1002
#define _OS_SYS_PRE_IDLE_PROCESSING(sleep_period) configPRE_IDLE_ENTRY(sleep_period)
1003
1004
/* Perform processing after system exiting idle state */
1005
#define _OS_SYS_POST_IDLE_PROCESSING(sleep_period) configPOST_IDLE_ENTRY(sleep_period)
1006
1007
/* Hook function to handle memory allocation failures */
1008
#if (configUSE_MALLOC_FAILED_HOOK == 1)
1009
#define _OS_APP_MALLOC_FAILED(...) void vApplicationMallocFailedHook(__VA_ARGS__)
1010
#endif
/* configUSE_MALLOC_FAILED_HOOK */
1011
1012
/* Hook function to be called on each iteration of the idle OS task */
1013
#if (configUSE_IDLE_HOOK == 1)
1014
#define _OS_APP_IDLE(...) void vApplicationIdleHook(__VA_ARGS__)
1015
#endif
/* configUSE_IDLE_HOOK */
1016
1017
/* Hook function to be called upon stack overflow */
1018
#if (configCHECK_FOR_STACK_OVERFLOW > 0)
1019
#define _OS_APP_STACK_OVERFLOW(...) void vApplicationStackOverflowHook(__VA_ARGS__)
1020
#endif
/* configCHECK_FOR_STACK_OVERFLOW */
1021
1022
/* Hook function to be called on every OS tick */
1023
#if (configUSE_TICK_HOOK == 1)
1024
#define _OS_APP_TICK(...) void vApplicationTickHook(__VA_ARGS__)
1025
#endif
/* configUSE_TICK_HOOK */
1026
1027
/* Hook function to be called at the point the daemon OS task starts executing */
1028
#if (configUSE_DAEMON_TASK_STARTUP_HOOK == 1)
1029
#define _OS_APP_DAEMON_TASK(...) void vApplicationDaemonTaskStartupHook(__VA_ARGS__)
1030
#endif
/* configUSE_DAEMON_TASK_STARTUP_HOOK */
1031
1032
/* *************************************************************** */
1033
/* The following macro functions are used internally by the system */
1034
/* *************************************************************** */
1035
1036
/* Advance OS tick count */
1037
#define _OS_TICK_ADVANCE() xPortTickAdvance()
1038
1039
/* Update OS tick count by adding a given number of OS ticks */
1040
#define _OS_TICK_INCREMENT(ticks) \
1041
{ \
1042
xTaskIncrementTick(); \
1043
vTaskStepTick(ticks); \
1044
}
1045
1046
#endif
/* OS_FREERTOS */
1047
1048
#endif
/* OSAL_FREERTOS_H_ */
1049
interrupts.h
Interrupt priority configuration.
Generated on Tue Oct 24 2023 10:38:23 for SmartSnippets DA1459x SDK by
1.8.16