@web-font-path: "roboto-debian.css";
Loading...
Searching...
No Matches
async_context_freertos.h
1/*
2 * Copyright (c) 2022 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _PICO_ASYNC_CONTEXT_FREERTOS_H
8#define _PICO_ASYNC_CONTEXT_FREERTOS_H
9
17#include "pico/async_context.h"
18
19// FreeRTOS includes
20#include "FreeRTOS.h"
21#include "semphr.h"
22#include "timers.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#ifndef ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_PRIORITY
29#define ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_PRIORITY ( tskIDLE_PRIORITY + 4)
30#endif
31
32#ifndef ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_STACK_SIZE
33#define ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
34#endif
35
36typedef struct async_context_freertos async_context_freertos_t;
37
38#if !defined(configNUMBER_OF_CORES) && defined(configNUM_CORES)
39#if !portSUPPORT_SMP
40#error configNUMBER_OF_CORES is the new name for configNUM_CORES
41#else
42// portSUPPORT_SMP was defined in old smp branch
43#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
44#endif
45#endif
46
54 UBaseType_t task_priority;
58 configSTACK_DEPTH_TYPE task_stack_size;
62#if configSUPPORT_STATIC_ALLOCATION
63 StackType_t *task_stack;
64#endif
69#if configUSE_CORE_AFFINITY && configNUMBER_OF_CORES > 1
70 UBaseType_t task_core_id;
71#endif
72} async_context_freertos_config_t;
73
75 async_context_t core;
76 SemaphoreHandle_t lock_mutex;
77 SemaphoreHandle_t work_needed_sem;
78 SemaphoreHandle_t task_complete_sem;
79 TimerHandle_t timer_handle;
80 TaskHandle_t task_handle;
81#if configSUPPORT_STATIC_ALLOCATION
82 StaticSemaphore_t lock_mutex_buf;
83 StaticSemaphore_t work_needed_sem_buf;
84 StaticSemaphore_t task_complete_sem_buf;
85 StaticTimer_t timer_buf;
86 StaticTask_t task_buf;
87#endif
88 uint8_t nesting;
89 volatile bool task_should_exit;
90};
91
103bool async_context_freertos_init(async_context_freertos_t *self, async_context_freertos_config_t *config);
104
112 static inline async_context_freertos_config_t async_context_freertos_default_config(void) {
113 async_context_freertos_config_t config = {
114 .task_priority = ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_PRIORITY,
115 .task_stack_size = ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_STACK_SIZE,
116#if configUSE_CORE_AFFINITY && configNUMBER_OF_CORES > 1
117 .task_core_id = (UBaseType_t)-1, // none
118#endif
119 };
120 return config;
121
122}
123
134 static inline bool async_context_freertos_init_with_defaults(async_context_freertos_t *self) {
135 async_context_freertos_config_t config = async_context_freertos_default_config();
136 return async_context_freertos_init(self, &config);
137}
138
139#ifdef __cplusplus
140}
141#endif
142
143#endif
bool async_context_freertos_init(async_context_freertos_t *self, async_context_freertos_config_t *config)
Initialize an async_context_freertos instance using the specified configuration.
Definition async_context_freertos.c:108
static bool async_context_freertos_init_with_defaults(async_context_freertos_t *self)
Initialize an async_context_freertos instance with default values.
Definition async_context_freertos.h:134
static async_context_freertos_config_t async_context_freertos_default_config(void)
Return a copy of the default configuration object used by async_context_freertos_init_with_defaults()...
Definition async_context_freertos.h:112
Configuration object for async_context_freertos instances.
Definition async_context_freertos.h:50
UBaseType_t task_priority
Task priority for the async_context task.
Definition async_context_freertos.h:54
configSTACK_DEPTH_TYPE task_stack_size
Stack size for the async_context task.
Definition async_context_freertos.h:58
Definition async_context_freertos.h:74