1
6
7
8
9
10
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
45
46
47
50
51
54
55
58
59
63
64
65
66
67
68
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
98
109
110
111
112
113
114
115
116
117
118
119
120
124
125
126
127
128
129
/* ... */
#ifndef _PICO_ASYNC_CONTEXT_FREERTOS_H
#define _PICO_ASYNC_CONTEXT_FREERTOS_H
/* ... */
#include "pico/async_context.h"
#include "FreeRTOS.h"
#include "semphr.h"
#include "timers.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_PRIORITY
#define ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_PRIORITY ( tskIDLE_PRIORITY + 4)
#endif
#ifndef ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_STACK_SIZE
#define ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#endif
typedef struct async_context_freertos async_context_freertos_t;
#if !defined(configNUMBER_OF_CORES) && defined(configNUM_CORES)
#if !portSUPPORT_SMP
#error configNUMBER_OF_CORES is the new name for configNUM_CORES
#else
#error configNUMBER_OF_CORES is the new name for configNUM_CORES, however it looks like you may need to define both as you are using an old SMP branch of FreeRTOS/* ... */
#endif/* ... */
#endif
/* ... */
typedef struct async_context_freertos_config {
/* ... */
UBaseType_t task_priority;
/* ... */
configSTACK_DEPTH_TYPE task_stack_size;
/* ... */
#if configUSE_CORE_AFFINITY && configNUMBER_OF_CORES > 1
UBaseType_t task_core_id;
#endif
...} async_context_freertos_config_t;
struct async_context_freertos {
async_context_t core;
SemaphoreHandle_t lock_mutex;
SemaphoreHandle_t work_needed_sem;
TimerHandle_t timer_handle;
TaskHandle_t task_handle;
uint8_t nesting;
volatile bool task_should_exit;
...};
/* ... */
bool async_context_freertos_init(async_context_freertos_t *self, async_context_freertos_config_t *config);
/* ... */
static inline async_context_freertos_config_t async_context_freertos_default_config(void) {
async_context_freertos_config_t config = {
.task_priority = ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_PRIORITY,
.task_stack_size = ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_STACK_SIZE,
#if configUSE_CORE_AFFINITY && configNUMBER_OF_CORES > 1
.task_core_id = (UBaseType_t)-1,
#endif
...};
return config;
}{ ... }
/* ... */
static inline bool async_context_freertos_init_with_defaults(async_context_freertos_t *self) {
async_context_freertos_config_t config = async_context_freertos_default_config();
return async_context_freertos_init(self, &config);
}{ ... }
#ifdef __cplusplus
}extern "C" { ... }
#endif
/* ... */
#endif