Skip to content

Commit

Permalink
applications: nrf5340_audio: Add a deinitialise function
Browse files Browse the repository at this point in the history
    The data FIFO module did not have a deinitialise function so
	added one, with a twister test.

Signed-off-by: Graham Wacey <[email protected]>
  • Loading branch information
gWacey committed Jul 8, 2024
1 parent 43e521e commit 2e8465c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/data_fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ int data_fifo_num_used_get(struct data_fifo *data_fifo, uint32_t *alloced_num,
*/
int data_fifo_empty(struct data_fifo *data_fifo);

/**
* @brief Deinitialise the data_fifo.
*
* @note The fifo is emptied first, so it is the users responsibility to release any data items it
* has queued. The internal slab and message buffer are not released.
*
* @param data_fifo Pointer to the data_fifo structure.
*
* @retval 0 if success, error otherwise.
*/
int data_fifo_deinit(struct data_fifo *data_fifo);

/**
* @brief Initialise the data_fifo.
*
Expand Down
16 changes: 16 additions & 0 deletions lib/data_fifo/data_fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ int data_fifo_empty(struct data_fifo *data_fifo)
return 0;
}

int data_fifo_deinit(struct data_fifo *data_fifo)
{
__ASSERT_NO_MSG(data_fifo != NULL);
__ASSERT_NO_MSG(data_fifo->initialized);
int ret;

ret = data_fifo_empty(data_fifo);
if (ret) {
return ret;
}

data_fifo->initialized = false;

return 0;
}

int data_fifo_init(struct data_fifo *data_fifo)
{
__ASSERT_NO_MSG(data_fifo != NULL);
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/data_fifo/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ static void internal_test_remaining_elements(struct data_fifo *data_fifo, uint32
num_locked, line);
}

ZTEST(suite_data_fifo, test_data_fifo_deinit_ok)
{
DATA_FIFO_DEFINE(data_fifo, 8, 128);

int ret;

ret = data_fifo_init(&data_fifo);
zassert_equal(ret, 0, "init did not return 0");
zassert_equal(data_fifo.initialized, true, "init did not set initialise flag");

ret = data_fifo_deinit(&data_fifo);
zassert_equal(ret, 0, "deinit did not return 0");
zassert_equal(data_fifo.initialized, false, "deinit did not reset initialise flag");
}

ZTEST(suite_data_fifo, test_data_fifo_init_ok)
{
DATA_FIFO_DEFINE(data_fifo, 8, 128);
Expand Down

0 comments on commit 2e8465c

Please sign in to comment.