Skip to content

Commit

Permalink
applications: nrf5340_audio: Audio module improvements
Browse files Browse the repository at this point in the history
    Corrections from use, additional testing and fake function updates.

Signed-off-by: Graham Wacey <graham.wacey@nordicsemi.no>
  • Loading branch information
gWacey committed Aug 28, 2024
1 parent 3d33b76 commit efc2529
Show file tree
Hide file tree
Showing 16 changed files with 394 additions and 222 deletions.
2 changes: 1 addition & 1 deletion include/audio_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct audio_metadata {
* bits_per_sample = 24
* carrier_size = 32
*/
uint8_t carried_bits_pr_sample;
uint8_t carried_bits_per_sample;

/* A 32 bit mask indicating which channel(s)/locations are active within
* the data. A bit set indicates the location is active and
Expand Down
25 changes: 25 additions & 0 deletions include/audio_module/audio_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ extern "C" {

#include "audio_defines.h"

/**
* @brief Helper macro to configure the modules parameters.
*/
#define AUDIO_MODULE_PARAMETERS(p, dest, stk, stk_size, pri, fifo_rx, fifo_tx, slab, slab_size) \
(p).description = (dest); \
(p).thread.stack = (stk); \
(p).thread.stack_size = (stk_size); \
(p).thread.priority = (pri); \
(p).thread.msg_rx = (fifo_rx); \
(p).thread.msg_tx = (fifo_tx); \
(p).thread.data_slab = (slab); \
(p).thread.data_size = (slab_size);

/**
* @brief Number of valid location bits.
*/
Expand Down Expand Up @@ -409,6 +422,10 @@ int audio_module_stop(struct audio_module_handle *handle);
/**
* @brief Send an audio data item to an audio module, all data is consumed by the module.
*
* @note: The data pointer and its associated size that are passed via the audio data
* pointer, can be NULL and/or 0. It is the responsibility of the low level module functions
* to handle this correctly.
*
* @param handle [in/out] The handle for the receiving module instance.
* @param audio_data [in] Pointer to the audio data to send to the module.
* @param response_cb [in] Pointer to a callback to run when the buffer is
Expand All @@ -423,6 +440,10 @@ int audio_module_data_tx(struct audio_module_handle *handle,
/**
* @brief Retrieve an audio data item from an audio module.
*
* @note: The data pointer and its associated size that are passed via the audio data
* pointer, can be NULL and/or 0. It is the responsibility of the low level module functions
* to handle this correctly.
*
* @param handle [in/out] The handle to the module instance.
* @param audio_data [out] Pointer to the audio data from the module.
* @param timeout [in] Non-negative waiting period to wait for operation to complete
Expand All @@ -441,6 +462,10 @@ int audio_module_data_rx(struct audio_module_handle *handle, struct audio_data *
* returned via the module or final module's output FIFO. All the input data is consumed
* within the call and thus the input data buffer maybe released once the function returns.
*
* @note: The data I/O pointers and their associated sizes that are passed via the audio data
* pointers, can be NULL and/or 0. It is the responsibility of the low level module functions
* to handle this correctly.
*
* @param handle_tx [in/out] The handle to the module to send the input audio data to.
* @param handle_rx [in/out] The handle to the module to receive audio data from.
* @param audio_data_tx [in] Pointer to the audio data to send.
Expand Down
20 changes: 15 additions & 5 deletions include/data_fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ struct data_fifo {
};

#define DATA_FIFO_DEFINE(name, elements_max_in, block_size_max_in) \
char __aligned(WB_UP(1)) \
_msgq_buffer_##name[(elements_max_in) * sizeof(struct data_fifo_msgq)] = {0}; \
char __aligned(WB_UP(1)) \
_slab_buffer_##name[(elements_max_in) * (block_size_max_in)] = {0}; \
char __aligned(WB_UP( \
1)) _msgq_buffer_##name[(elements_max_in) * sizeof(struct data_fifo_msgq)] = {0}; \
char __aligned(WB_UP(1)) _slab_buffer_##name[(elements_max_in) * (block_size_max_in)] = { \
0}; \
struct data_fifo name = {.msgq_buffer = _msgq_buffer_##name, \
.slab_buffer = _slab_buffer_##name, \
.block_size_max = block_size_max_in, \
Expand Down Expand Up @@ -163,7 +163,7 @@ int data_fifo_empty(struct data_fifo *data_fifo);
int data_fifo_uninit(struct data_fifo *data_fifo);

/**
* @brief Initialise the data_fifo.
* @brief Initialize the data_fifo.
*
* @param data_fifo Pointer to the data_fifo structure.
*
Expand All @@ -172,6 +172,16 @@ int data_fifo_uninit(struct data_fifo *data_fifo);
*/
int data_fifo_init(struct data_fifo *data_fifo);

/**
* @brief Test if the data_fifo state.
*
* @param data_fifo Pointer to the data_fifo structure.
*
* @retval false Uninitialized.
* @retval true Initialized.
*/
bool data_fifo_state(struct data_fifo *data_fifo);

/**
* @}
*/
Expand Down
10 changes: 10 additions & 0 deletions lib/data_fifo/data_fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,13 @@ int data_fifo_init(struct data_fifo *data_fifo)

return ret;
}

int data_fifo_state(struct data_fifo *data_fifo)
{
__ASSERT_NO_MSG(data_fifo != NULL);
__ASSERT_NO_MSG(data_fifo->elements_max != 0);
__ASSERT_NO_MSG(data_fifo->block_size_max != 0);
__ASSERT_NO_MSG((data_fifo->block_size_max % WB_UP(1)) == 0);

return data_fifo->initialized;
}
2 changes: 1 addition & 1 deletion subsys/audio_module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/audio_module.c)
zephyr_sources_ifdef(CONFIG_AUDIO_MODULE audio_module.c)
9 changes: 6 additions & 3 deletions subsys/audio_module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "Audio Module"
menu "Audio Modules"

config AUDIO_MODULE
tristate "Enable the audio module"
Expand All @@ -20,8 +19,12 @@ config AUDIO_MODULE_NAME_SIZE
int "Maximum size for module naming in characters"
default 20

#----------------------------------------------------------------------------#
menu "Log levels"

module = AUDIO_MODULE
module-str = audio_module
source "subsys/logging/Kconfig.template.log_config"

endmenu # Audio Module
endmenu # Log levels
endmenu # Audio Modules
Loading

0 comments on commit efc2529

Please sign in to comment.