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
25 extern "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 
37 
45  UBaseType_t task_priority;
49  configSTACK_DEPTH_TYPE task_stack_size;
54 #if configUSE_CORE_AFFINITY && configNUM_CORES > 1
55  UBaseType_t task_core_id;
56 #endif
58 
60  async_context_t core;
61  SemaphoreHandle_t lock_mutex;
62  SemaphoreHandle_t work_needed_sem;
63  TimerHandle_t timer_handle;
64  TaskHandle_t task_handle;
65  uint8_t nesting;
66  volatile bool task_should_exit;
67 };
68 
81 
91  .task_priority = ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_PRIORITY,
92  .task_stack_size = ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_STACK_SIZE,
93 #if configUSE_CORE_AFFINITY
94  .task_core_id = (UBaseType_t)-1, // none
95 #endif
96  };
97  return config;
98 
99 }
100 
113  return async_context_freertos_init(self, &config);
114 }
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 
120 #endif
async_context_freertos
Definition: async_context_freertos.h:59
async_context_freertos_default_config
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:89
async_context_freertos_config
Configuration object for async_context_freertos instances.
Definition: async_context_freertos.h:41
async_context_freertos_config::task_stack_size
configSTACK_DEPTH_TYPE task_stack_size
Definition: async_context_freertos.h:49
async_context_freertos_config::task_priority
UBaseType_t task_priority
Definition: async_context_freertos.h:45
async_context_freertos_init_with_defaults
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:111
async_context_freertos_init
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:107
async_context
Base structure type of all async_contexts. For details about its use, see pico_async_context.
Definition: async_context.h:175
async_context.h