Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

applications: nrf5340_audio: Audio Module Template #12

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions include/audio_modules/audio_module_template.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright(c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#ifndef _AUDIO_MODULE_TEMPLATE_H_
#define _AUDIO_MODULE_TEMPLATE_H_

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "audio_defines.h"
#include "audio_module.h"

#define AUDIO_MODULE_TEMPLATE_LAST_BYTES (10)

/**
* @brief Private pointer to the module's parameters.
*
*/
extern struct audio_module_description *audio_module_template_description;

/**
* @brief The module configuration structure.
*
*/
struct audio_module_template_configuration {
/* The rate. */
uint32_t sample_rate_hz;

/* the depth. */
uint32_t bit_depth;

/* A string .*/
char *some_text;
};

/**
* @brief Private module context.
*
*/
struct audio_module_template_context {
/* Array of data to illustrate the data process function. */
uint8_t audio_module_template_data[AUDIO_MODULE_TEMPLATE_LAST_BYTES];

/* The template configuration. */
struct audio_module_template_configuration config;
};

#endif /* _AUDIO_MODULE_TEMPLATE_H_ */
1 change: 1 addition & 0 deletions subsys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ add_subdirectory_ifdef(CONFIG_NRF_DM dm)
add_subdirectory_ifdef(CONFIG_EMDS emds)
add_subdirectory_ifdef(CONFIG_NET_CORE_MONITOR net_core_monitor)
add_subdirectory_ifdef(CONFIG_AUDIO_MODULE audio_module)
add_subdirectory_ifdef(CONFIG_AUDIO_MODULE_TEMPLATE audio_modules/audio_module_template)
add_subdirectory_ifdef(CONFIG_UART_ASYNC_ADAPTER uart_async_adapter)
add_subdirectory_ifdef(CONFIG_SDFW_SERVICES_ENABLED sdfw_services)
add_subdirectory(suit)
Expand Down
1 change: 1 addition & 0 deletions subsys/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ rsource "dm/Kconfig"
rsource "nrf_security/Kconfig"
rsource "net_core_monitor/Kconfig"
rsource "audio_module/Kconfig"
rsource "audio_modules/audio_module_template/Kconfig"
rsource "uart_async_adapter/Kconfig"
rsource "trusted_storage/Kconfig"
rsource "logging/Kconfig"
Expand Down
10 changes: 10 additions & 0 deletions subsys/audio_modules/audio_module_template/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/audio_module_template.c)

target_include_directories(app PRIVATE ${ZEPHYR_NRF_MODULE_DIR}/include/audio_module
${ZEPHYR_NRF_MODULE_DIR}/include/audio_modules)
27 changes: 27 additions & 0 deletions subsys/audio_modules/audio_module_template/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
menu "Audio Modules"

config AUDIO_MODULE_TEMPLATE
bool "Audio module template"
help
Enable the audio module template, the
starting point for a new audio module

if AUDIO_MODULE_TEMPLATE

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

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

endmenu # Log levels

endif # AUDIO_MODULE_TEMPLATE

endmenu # Audio Modules
200 changes: 200 additions & 0 deletions subsys/audio_modules/audio_module_template/audio_module_template.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/*
* Copyright(c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#include "audio_module_template.h"

#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <zephyr/kernel.h>
#include <zephyr/shell/shell.h>
#include <errno.h>
#include "audio_defines.h"
#include "audio_module.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(audio_module_template, CONFIG_AUDIO_MODULE_TEMPLATE_LOG_LEVEL);

static int audio_module_template_open(struct audio_module_handle_private *handle,
struct audio_module_configuration const *const configuration)

{
struct audio_module_handle *hdl = (struct audio_module_handle *)handle;
struct audio_module_template_context *ctx =
(struct audio_module_template_context *)hdl->context;
struct audio_module_template_configuration *config =
(struct audio_module_template_configuration *)configuration;

/* Perform any other functions required to open the module. */

/* For example: Clear the module's context.
* Save the initial configuration to the module context.
*/
memset(ctx, 0, sizeof(struct audio_module_template_context));
memcpy(&ctx->config, config, sizeof(struct audio_module_template_configuration));

LOG_DBG("Open %s module", hdl->name);

return 0;
}

static int audio_module_template_close(struct audio_module_handle_private *handle)
{
struct audio_module_handle *hdl = (struct audio_module_handle *)handle;
struct audio_module_template_context *ctx =
(struct audio_module_template_context *)hdl->context;

/* Perform any other functions required to close the module. */

/* For example: Clear the context data */
memset(ctx, 0, sizeof(struct audio_module_template_context));

LOG_DBG("Close %s module", hdl->name);

return 0;
}

static int audio_module_template_configuration_set(
struct audio_module_handle_private *handle,
struct audio_module_configuration const *const configuration)
{
struct audio_module_template_configuration *config =
(struct audio_module_template_configuration *)configuration;
struct audio_module_handle *hdl = (struct audio_module_handle *)handle;
struct audio_module_template_context *ctx =
(struct audio_module_template_context *)hdl->context;

/* Perform any other functions to configure the module. */

/* For example: Copy the configuration into the context. */
memcpy(&ctx->config, config, sizeof(struct audio_module_template_configuration));

LOG_DBG("Set the configuration for %s module: rate = %d depth = %d string = %s",
hdl->name, ctx->config.sample_rate_hz, ctx->config.bit_depth,
ctx->config.some_text);

return 0;
}

static int
audio_module_template_configuration_get(struct audio_module_handle_private const *const handle,
struct audio_module_configuration *configuration)
{
struct audio_module_template_configuration *config =
(struct audio_module_template_configuration *)configuration;
struct audio_module_handle *hdl = (struct audio_module_handle *)handle;
struct audio_module_template_context *ctx =
(struct audio_module_template_context *)hdl->context;

/* Perform any other functions to extract the configuration of the module. */

/* For example: Copy the configuration from the context into the output configuration. */
memcpy(config, &ctx->config, sizeof(struct audio_module_template_configuration));

LOG_DBG("Get the configuration for %s module: rate = %d depth = %d string = %s",
hdl->name, config->sample_rate_hz, config->bit_depth, config->some_text);

return 0;
}

static int audio_module_template_start(struct audio_module_handle_private *handle)
{
struct audio_module_handle *hdl = (struct audio_module_handle *)handle;

/* Perform any other functions to start the module. */

LOG_DBG("Start the %s module", hdl->name);

return 0;
}

static int audio_module_template_stop(struct audio_module_handle_private *handle)
{
struct audio_module_handle *hdl = (struct audio_module_handle *)handle;

/* Perform any other functions to stop the module. */

LOG_DBG("Stop the %s module", hdl->name);

return 0;
}

static int audio_module_template_data_process(struct audio_module_handle_private *handle,
struct audio_data const *const audio_data_in,
struct audio_data *audio_data_out)
{
struct audio_module_handle *hdl = (struct audio_module_handle *)handle;

/* Perform any other functions to process the data within the module. */

/* For example: Copy the input to the output. */
{
size_t size = audio_data_in->data_size < audio_data_out->data_size
? audio_data_in->data_size
: audio_data_out->data_size;

memcpy(&audio_data_out->meta, &audio_data_in->meta, sizeof(struct audio_metadata));
memcpy((uint8_t *)audio_data_out->data, (uint8_t *)audio_data_in->data, size);
audio_data_out->data_size = size;
}

LOG_DBG("Process the input audio data into the output audio data item for %s module",
hdl->name);

return 0;
}

/**
* @brief Table of the dummy module functions.
*/
const struct audio_module_functions audio_module_template_functions = {
/**
* @brief Function to an open the dummy module.
*/
.open = audio_module_template_open,

/**
* @brief Function to close the dummy module.
*/
.close = audio_module_template_close,

/**
* @brief Function to set the configuration of the dummy module.
*/
.configuration_set = audio_module_template_configuration_set,

/**
* @brief Function to get the configuration of the dummy module.
*/
.configuration_get = audio_module_template_configuration_get,

/**
* @brief Start a module processing data.
*/
.start = audio_module_template_start,

/**
* @brief Pause a module processing data.
*/
.stop = audio_module_template_stop,

/**
* @brief The core data processing function in the dummy module.
*/
.data_process = audio_module_template_data_process,
};

/**
* @brief The set-up description for the LC3 decoder.
*/
struct audio_module_description audio_module_template_dept = {
.name = "Audio Module Temp",
.type = AUDIO_MODULE_TYPE_IN_OUT,
.functions = &audio_module_template_functions};

/**
* @brief A private pointer to the LC3 decoder set-up parameters.
*/
struct audio_module_description *audio_module_template_description = &audio_module_template_dept;
1 change: 1 addition & 0 deletions tests/subsys/audio_module/src/audio_module_test_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ int test_data_process_function(struct audio_module_handle_private *handle,
audio_data_tx->data_size = audio_data_rx->data_size;
} else {
printk("The input and output data pointers are NULL");
return -1;
}

return 0;
Expand Down
17 changes: 17 additions & 0 deletions tests/subsys/audio_modules/audio_module_template/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright (c) 20234 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project("Audio module Template")

target_sources(app PRIVATE
src/main.c
src/template_test.c
)

target_include_directories(app PRIVATE ${ZEPHYR_NRF_MODULE_DIR}/subsys/audio_modules/audio_module_template)
17 changes: 17 additions & 0 deletions tests/subsys/audio_modules/audio_module_template/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

CONFIG_ZTEST=y
CONFIG_ZTEST_STACK_SIZE=8196
CONFIG_IRQ_OFFLOAD=y
CONFIG_DATA_FIFO=y
CONFIG_AUDIO_MODULE=y
CONFIG_AUDIO_MODULE_TEMPLATE=y

# The large stack size can be optimized
CONFIG_MAIN_STACK_SIZE=16000

CONFIG_STACK_SENTINEL=y
11 changes: 11 additions & 0 deletions tests/subsys/audio_modules/audio_module_template/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/fff.h>
#include <zephyr/ztest.h>
#include <errno.h>

ZTEST_SUITE(suite_audio_module_template, NULL, NULL, NULL, NULL, NULL);
Loading
Loading