nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
audio_module.h
Go to the documentation of this file.
1/*
2 * Copyright(c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef _AUDIO_MODULE_H_
8#define _AUDIO_MODULE_H_
9
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#include <zephyr/kernel.h>
22#include <data_fifo.h>
23
24#include "audio_defines.h"
25
29#define AUDIO_MODULE_PARAMETERS(p, dest, stk, stk_size, pri, fifo_rx, fifo_tx, slab, slab_size) \
30 (p).description = (dest); \
31 (p).thread.stack = (stk); \
32 (p).thread.stack_size = (stk_size); \
33 (p).thread.priority = (pri); \
34 (p).thread.msg_rx = (fifo_rx); \
35 (p).thread.msg_tx = (fifo_tx); \
36 (p).thread.data_slab = (slab); \
37 (p).thread.data_size = (slab_size);
38
42#define AUDIO_MODULE_LOCATIONS_NUM (32)
43
48 /* The module type is undefined. */
50
51 /* This is an input processing module.
52 *
53 * @note An input module obtains data internally within the
54 * module (e.g. I2S in) and hence has no RX FIFO.
55 */
57
58 /* This is an output processing module.
59 *
60 * @note An output module takes audio data from an input or an in/out module.
61 * It then outputs data internally within the module (e.g. I2S out) and hence has no
62 * TX FIFO.
63 */
65
66 /* This is a processing module.
67 *
68 * @note A processing module takes input from and outputs to another
69 * module, thus having RX and TX FIFOs.
70 */
72};
73
78 /* Module state undefined. */
80
81 /* Module is in the configured state. */
83
84 /* Module is in the running state. */
86
87 /* Module is in the stopped state. */
89};
90
94struct audio_module_handle_private;
95
99struct audio_module_context;
100
104struct audio_module_configuration;
105
113typedef void (*audio_module_response_cb)(struct audio_module_handle_private *handle,
114 struct audio_data const *const audio_data);
115
130 int (*open)(struct audio_module_handle_private *handle,
131 struct audio_module_configuration const *const configuration);
132
142 int (*close)(struct audio_module_handle_private *handle);
143
155 int (*configuration_set)(struct audio_module_handle_private *handle,
156 struct audio_module_configuration const *const configuration);
157
168 int (*configuration_get)(struct audio_module_handle_private const *const handle,
169 struct audio_module_configuration *configuration);
170
180 int (*start)(struct audio_module_handle_private *handle);
181
191 int (*stop)(struct audio_module_handle_private *handle);
192
207 int (*data_process)(struct audio_module_handle_private *handle,
208 struct audio_data const *const audio_data_rx,
209 struct audio_data *audio_data_tx);
210};
211
216 /* The module base name. */
217 char *name;
218
219 /* The module type. */
221
222 /* A pointer to the functions in the module. */
224};
225
230 /* Thread stack. */
231 k_thread_stack_t *stack;
232
233 /* Thread stack size. */
235
236 /* Thread priority. */
238
239 /* A pointer to a module's audio data receiver FIFO, can be NULL. */
241
242 /* A pointer to a module's audio data transmitter FIFO, can be NULL. */
244
245 /* A pointer to the audio data buffer slab, can be NULL. */
246 struct k_mem_slab *data_slab;
247
248 /* Size of each memory data buffer in bytes that will be
249 * taken from the audio data buffer slab. The size can be 0.
250 */
251 size_t data_size;
252};
253
258 /* The module's description. */
260
261 /* The module's thread setting. */
263};
264
269 /* A NULL terminated string giving a unique name of this module's instance. */
270 char name[CONFIG_AUDIO_MODULE_NAME_SIZE + 1];
271
272 /* The module's description. */
274
275 /* Current state of the module. */
277
278 /* Thread ID. */
279 k_tid_t thread_id;
280
281 /* Thread data. */
282 struct k_thread thread_data;
283
284 /* Flag to indicate if the module should put its output audio data onto its TX FIFO. */
286
287 /* List node (pointer to next audio module). */
288 sys_snode_t node;
289
290 /* A single linked-list of the destination handles the module is connected to. */
291 sys_slist_t handle_dest_list;
292
293 /* Number of destination modules. */
294 uint8_t dest_count;
295
296 /* Semaphore to count messages between modules and on a module's TX FIFO. */
297 struct k_sem sem;
298
299 /* Mutex to make the above destinations list thread safe. */
300 struct k_mutex dest_mutex;
301
302 /* Module's thread configuration. */
304
305 /* Private context for the module. */
306 struct audio_module_context *context;
307};
308
313 /* Audio data to input. */
315
316 /* Sending module's handle. */
318
319 /* Callback for when the audio data has been consumed. */
321};
322
335int audio_module_open(struct audio_module_parameters const *const parameters,
336 struct audio_module_configuration const *const configuration,
337 char const *const name, struct audio_module_context *context,
338 struct audio_module_handle *handle);
339
348
358 struct audio_module_configuration const *const configuration);
359
369 struct audio_module_configuration *configuration);
370
386 struct audio_module_handle *handle_to, bool connect_external);
387
401 struct audio_module_handle *handle_disconnect,
402 bool disconnect_external);
403
412
421
437 struct audio_data const *const audio_data,
438 audio_module_response_cb response_cb);
439
456 k_timeout_t timeout);
457
480 struct audio_module_handle *handle_rx,
481 struct audio_data const *const audio_data_tx,
482 struct audio_data *audio_data_rx, k_timeout_t timeout);
483
494int audio_module_names_get(struct audio_module_handle const *const handle, char **base_name,
495 char *instance_name);
496
505int audio_module_state_get(struct audio_module_handle const *const handle,
507
517int audio_module_number_channels_calculate(uint32_t locations, int8_t *number_channels);
518
519#ifdef __cplusplus
520}
521#endif
522
527#endif /*_AUDIO_MODULE_H_ */
Globally accessible audio related defines.
Data first-in first-out library header.
int audio_module_configuration_get(struct audio_module_handle const *const handle, struct audio_module_configuration *configuration)
Get the configuration of an audio module.
int audio_module_connect(struct audio_module_handle *handle_from, struct audio_module_handle *handle_to, bool connect_external)
Connect two audio modules together or connect to the module's TX FIFO.
int audio_module_state_get(struct audio_module_handle const *const handle, enum audio_module_state *state)
Helper to get the state of a given audio module handle.
int audio_module_number_channels_calculate(uint32_t locations, int8_t *number_channels)
Helper to calculate the number of channels from the channel map for the given audio data.
int audio_module_data_tx(struct audio_module_handle *handle, struct audio_data const *const audio_data, audio_module_response_cb response_cb)
Send an audio data item to an audio module, all data is consumed by the module.
int audio_module_names_get(struct audio_module_handle const *const handle, char **base_name, char *instance_name)
Helper to get the base and instance names for a given audio module handle.
int audio_module_close(struct audio_module_handle *handle)
Close an opened audio module.
int audio_module_disconnect(struct audio_module_handle *handle, struct audio_module_handle *handle_disconnect, bool disconnect_external)
Disconnect audio modules from each other or disconnect the module's TX FIFO. The function should be c...
int audio_module_data_tx_rx(struct audio_module_handle *handle_tx, struct audio_module_handle *handle_rx, struct audio_data const *const audio_data_tx, struct audio_data *audio_data_rx, k_timeout_t timeout)
Send an audio data to an audio module and retrieve an audio data from an audio module.
int audio_module_stop(struct audio_module_handle *handle)
Stop processing audio data in the audio module given by handle.
int audio_module_reconfigure(struct audio_module_handle *handle, struct audio_module_configuration const *const configuration)
Reconfigure an opened audio module.
int audio_module_start(struct audio_module_handle *handle)
Start processing audio data in the audio module given by handle.
int audio_module_open(struct audio_module_parameters const *const parameters, struct audio_module_configuration const *const configuration, char const *const name, struct audio_module_context *context, struct audio_module_handle *handle)
Open an audio module.
audio_module_type
Module type.
Definition: audio_module.h:47
@ AUDIO_MODULE_TYPE_IN_OUT
Definition: audio_module.h:71
@ AUDIO_MODULE_TYPE_INPUT
Definition: audio_module.h:56
@ AUDIO_MODULE_TYPE_UNDEFINED
Definition: audio_module.h:49
@ AUDIO_MODULE_TYPE_OUTPUT
Definition: audio_module.h:64
void(* audio_module_response_cb)(struct audio_module_handle_private *handle, struct audio_data const *const audio_data)
Callback function for a response to a data_send as supplied by the module user.
Definition: audio_module.h:113
int audio_module_data_rx(struct audio_module_handle *handle, struct audio_data *audio_data, k_timeout_t timeout)
Retrieve an audio data item from an audio module.
audio_module_state
Module state.
Definition: audio_module.h:77
@ AUDIO_MODULE_STATE_STOPPED
Definition: audio_module.h:88
@ AUDIO_MODULE_STATE_CONFIGURED
Definition: audio_module.h:82
@ AUDIO_MODULE_STATE_RUNNING
Definition: audio_module.h:85
@ AUDIO_MODULE_STATE_UNDEFINED
Definition: audio_module.h:79
A unit of audio.
Definition: audio_defines.h:90
enum audio_module_type type
Definition: audio_module.h:220
const struct audio_module_functions * functions
Definition: audio_module.h:223
char * name
Definition: audio_module.h:217
A module's minimum description.
Definition: audio_module.h:215
int(* configuration_get)(struct audio_module_handle_private const *const handle, struct audio_module_configuration *configuration)
Get the configuration of an audio module.
Definition: audio_module.h:168
int(* stop)(struct audio_module_handle_private *handle)
Stop an audio module.
Definition: audio_module.h:191
int(* start)(struct audio_module_handle_private *handle)
Start an audio module.
Definition: audio_module.h:180
int(* close)(struct audio_module_handle_private *handle)
Close an open audio module.
Definition: audio_module.h:142
int(* data_process)(struct audio_module_handle_private *handle, struct audio_data const *const audio_data_rx, struct audio_data *audio_data_tx)
The core data processing for an audio module. Can be either an input, output or input/output module t...
Definition: audio_module.h:207
int(* open)(struct audio_module_handle_private *handle, struct audio_module_configuration const *const configuration)
Open an audio module with the specified initial configuration.
Definition: audio_module.h:130
int(* configuration_set)(struct audio_module_handle_private *handle, struct audio_module_configuration const *const configuration)
Reconfigure an audio module after it has been opened with its initial configuration.
Definition: audio_module.h:155
Private pointer to a module's functions.
Definition: audio_module.h:119
struct k_mutex dest_mutex
Definition: audio_module.h:300
bool use_tx_queue
Definition: audio_module.h:285
struct k_thread thread_data
Definition: audio_module.h:282
enum audio_module_state state
Definition: audio_module.h:276
sys_snode_t node
Definition: audio_module.h:288
struct audio_module_context * context
Definition: audio_module.h:306
const struct audio_module_description * description
Definition: audio_module.h:273
struct k_sem sem
Definition: audio_module.h:297
k_tid_t thread_id
Definition: audio_module.h:279
struct audio_module_thread_configuration thread
Definition: audio_module.h:303
uint8_t dest_count
Definition: audio_module.h:294
char name[CONFIG_AUDIO_MODULE_NAME_SIZE+1]
Definition: audio_module.h:270
sys_slist_t handle_dest_list
Definition: audio_module.h:291
Private module handle.
Definition: audio_module.h:268
audio_module_response_cb response_cb
Definition: audio_module.h:320
struct audio_module_handle * tx_handle
Definition: audio_module.h:317
Private structure describing a data_in message into the module thread.
Definition: audio_module.h:312
struct audio_module_description * description
Definition: audio_module.h:259
struct audio_module_thread_configuration thread
Definition: audio_module.h:262
Module's generic set-up structure.
Definition: audio_module.h:257
size_t data_size
Definition: audio_module.h:251
struct data_fifo * msg_rx
Definition: audio_module.h:240
struct data_fifo * msg_tx
Definition: audio_module.h:243
k_thread_stack_t * stack
Definition: audio_module.h:231
int priority
Definition: audio_module.h:237
struct k_mem_slab * data_slab
Definition: audio_module.h:246
size_t stack_size
Definition: audio_module.h:234
Module's thread configuration structure.
Definition: audio_module.h:229
Definition: data_fifo.h:34
enum state_type state