48
48
static async_context_freertos_t async_context_instance ;
49
49
50
50
// Create an async context
51
- static async_context_t * example_async_context (void ) {
51
+ static async_context_t * create_async_context (void ) {
52
52
async_context_freertos_config_t config = async_context_freertos_default_config ();
53
53
config .task_priority = WORKER_TASK_PRIORITY ; // defaults to ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_PRIORITY
54
54
config .task_stack_size = WORKER_TASK_STACK_SIZE ; // defaults to ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_STACK_SIZE
55
+ #if configSUPPORT_STATIC_ALLOCATION
56
+ static StackType_t async_context_freertos_task_stack [WORKER_TASK_STACK_SIZE ];
57
+ config .task_stack = async_context_freertos_task_stack ;
58
+ #endif
55
59
if (!async_context_freertos_init (& async_context_instance , & config ))
56
60
return NULL ;
57
61
return & async_context_instance .core ;
58
62
}
59
63
60
64
#if USE_LED
61
65
// Turn led on or off
62
- static void pico_set_led (bool led_on ) {
66
+ static void set_led (bool led_on ) {
63
67
#if defined PICO_DEFAULT_LED_PIN
64
68
gpio_put (PICO_DEFAULT_LED_PIN , led_on );
65
69
#elif defined(CYW43_WL_GPIO_LED_PIN )
@@ -68,20 +72,20 @@ static void pico_set_led(bool led_on) {
68
72
}
69
73
70
74
// Initialise led
71
- static void pico_init_led (void ) {
75
+ static void init_led (void ) {
72
76
#if defined PICO_DEFAULT_LED_PIN
73
77
gpio_init (PICO_DEFAULT_LED_PIN );
74
78
gpio_set_dir (PICO_DEFAULT_LED_PIN , GPIO_OUT );
75
79
#elif defined(CYW43_WL_GPIO_LED_PIN )
76
80
hard_assert (cyw43_arch_init () == PICO_OK );
77
- pico_set_led (false); // make sure cyw43 is started
81
+ set_led (false); // make sure cyw43 is started
78
82
#endif
79
83
}
80
84
81
85
void blink_task (__unused void * params ) {
82
86
bool on = false;
83
87
printf ("blink_task starts\n" );
84
- pico_init_led ();
88
+ init_led ();
85
89
while (true) {
86
90
#if configNUMBER_OF_CORES > 1
87
91
static int last_core_id = -1 ;
@@ -90,7 +94,7 @@ void blink_task(__unused void *params) {
90
94
printf ("blink task is on core %d\n" , last_core_id );
91
95
}
92
96
#endif
93
- pico_set_led (on );
97
+ set_led (on );
94
98
on = !on ;
95
99
96
100
#if LED_BUSY_WAIT
@@ -122,13 +126,20 @@ static void do_work(async_context_t *context, async_at_time_worker_t *worker) {
122
126
async_at_time_worker_t worker_timeout = { .do_work = do_work };
123
127
124
128
void main_task (__unused void * params ) {
125
- async_context_t * context = example_async_context ();
129
+ async_context_t * context = create_async_context ();
126
130
// start the worker running
127
131
async_context_add_at_time_worker_in_ms (context , & worker_timeout , 0 );
128
132
#if USE_LED
129
133
// start the led blinking
134
+ #if configSUPPORT_STATIC_ALLOCATION
135
+ static StackType_t blink_stack [BLINK_TASK_STACK_SIZE ];
136
+ static StaticTask_t blink_buf ;
137
+ xTaskCreateStatic (blink_task , "BlinkThread" , BLINK_TASK_STACK_SIZE , NULL , BLINK_TASK_PRIORITY , blink_stack , & blink_buf );
138
+ #else
139
+ static_assert (configSUPPORT_DYNAMIC_ALLOCATION , "" );
130
140
xTaskCreate (blink_task , "BlinkThread" , BLINK_TASK_STACK_SIZE , NULL , BLINK_TASK_PRIORITY , NULL );
131
- #endif
141
+ #endif // configSUPPORT_STATIC_ALLOCATION
142
+ #endif // USE_LED
132
143
int count = 0 ;
133
144
while (true) {
134
145
#if configNUMBER_OF_CORES > 1
@@ -146,11 +157,19 @@ void main_task(__unused void *params) {
146
157
147
158
void vLaunch ( void ) {
148
159
TaskHandle_t task ;
160
+ #if configSUPPORT_STATIC_ALLOCATION
161
+ static StackType_t main_stack [MAIN_TASK_STACK_SIZE ];
162
+ static StaticTask_t main_buf ;
163
+ task = xTaskCreateStatic (main_task , "MainThread" , MAIN_TASK_STACK_SIZE , NULL , MAIN_TASK_PRIORITY , main_stack , & main_buf );
164
+ #else
165
+ static_assert (configSUPPORT_DYNAMIC_ALLOCATION , "" );
149
166
xTaskCreate (main_task , "MainThread" , MAIN_TASK_STACK_SIZE , NULL , MAIN_TASK_PRIORITY , & task );
150
-
167
+ #endif // configSUPPORT_STATIC_ALLOCATION
151
168
#if configUSE_CORE_AFFINITY && configNUMBER_OF_CORES > 1
152
169
// we must bind the main task to one core (well at least while the init is called)
153
170
vTaskCoreAffinitySet (task , 1 );
171
+ #else
172
+ (void )task ;
154
173
#endif
155
174
156
175
/* Start the tasks and timer running. */
0 commit comments