async_context_threadsafe_background.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_THREADSAFE_BACKGROUND_H
8 #define _PICO_ASYNC_CONTEXT_THREADSAFE_BACKGROUND_H
9 
20 #include "pico/async_context.h"
21 #include "pico/sem.h"
22 #include "pico/mutex.h"
23 #include "hardware/irq.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #ifndef ASYNC_CONTEXT_THREADSAFE_BACKGROUND_MULTI_CORE
30 #define ASYNC_CONTEXT_THREADSAFE_BACKGROUND_MULTI_CORE LIB_PICO_MULTICORE
31 #endif
32 
34 
55 
57  async_context_t core;
58  alarm_pool_t *alarm_pool; // this must be on the same core as core_num
59  absolute_time_t last_set_alarm_time;
60  recursive_mutex_t lock_mutex;
61  semaphore_t work_needed_sem;
62  volatile alarm_id_t alarm_id;
63 #if ASYNC_CONTEXT_THREADSAFE_BACKGROUND_MULTI_CORE
64  volatile alarm_id_t force_alarm_id;
65  bool alarm_pool_owned;
66 #endif
67  uint8_t low_priority_irq_num;
68  volatile bool alarm_pending;
69 };
70 
83 
92 
105  return async_context_threadsafe_background_init(self, &config);
106 }
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif
int32_t alarm_id_t
The identifier for an alarm.
Definition: time.h:359
static bool async_context_threadsafe_background_init_with_defaults(async_context_threadsafe_background_t *self)
Initialize an async_context_threadsafe_background instance with default values.
Definition: async_context_threadsafe_background.h:103
bool async_context_threadsafe_background_init(async_context_threadsafe_background_t *self, async_context_threadsafe_background_config_t *config)
Initialize an async_context_threadsafe_background instance using the specified configuration.
Definition: async_context_threadsafe_background.c:195
async_context_threadsafe_background_config_t async_context_threadsafe_background_default_config(void)
Return a copy of the default configuration object used by async_context_threadsafe_background_init_wi...
Definition: async_context_threadsafe_background.c:28
recursive mutex instance
Definition: mutex.h:47
Definition: types.h:33
Definition: time.c:25
Configuration object for async_context_threadsafe_background instances.
Definition: async_context_threadsafe_background.h:38
alarm_pool_t * custom_alarm_pool
Definition: async_context_threadsafe_background.h:53
uint8_t low_priority_irq_handler_priority
Definition: async_context_threadsafe_background.h:42
Definition: async_context_threadsafe_background.h:56
Base structure type of all async_contexts. For details about its use, see pico_async_context.
Definition: async_context.h:179