初始版本
This commit is contained in:
580
components/libraries/queue/nrf_queue.c
Normal file
580
components/libraries/queue/nrf_queue.c
Normal file
@@ -0,0 +1,580 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_QUEUE)
|
||||
#include "nrf_queue.h"
|
||||
#include "app_util_platform.h"
|
||||
|
||||
#if NRF_QUEUE_CONFIG_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL NRF_QUEUE_CONFIG_LOG_LEVEL
|
||||
#define NRF_LOG_INIT_FILTER_LEVEL NRF_QUEUE_CONFIG_LOG_INIT_FILTER_LEVEL
|
||||
#define NRF_LOG_INFO_COLOR NRF_QUEUE_CONFIG_INFO_COLOR
|
||||
#define NRF_LOG_DEBUG_COLOR NRF_QUEUE_CONFIG_DEBUG_COLOR
|
||||
#else
|
||||
#define NRF_LOG_LEVEL 0
|
||||
#endif // NRF_QUEUE_CONFIG_LOG_ENABLED
|
||||
#include "nrf_log.h"
|
||||
|
||||
NRF_SECTION_DEF(nrf_queue, nrf_queue_t);
|
||||
|
||||
#if NRF_QUEUE_CLI_CMDS && NRF_CLI_ENABLED
|
||||
#include "nrf_cli.h"
|
||||
|
||||
static void nrf_queue_status(nrf_cli_t const * p_cli, size_t argc, char **argv)
|
||||
{
|
||||
UNUSED_PARAMETER(argv);
|
||||
|
||||
if (nrf_cli_help_requested(p_cli))
|
||||
{
|
||||
nrf_cli_help_print(p_cli, NULL, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
nrf_cli_fprintf(p_cli, NRF_CLI_ERROR, "Bad argument count");
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t num_of_instances = NRF_SECTION_ITEM_COUNT(nrf_queue, nrf_queue_t);
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < num_of_instances; i++)
|
||||
{
|
||||
const nrf_queue_t * p_instance = NRF_SECTION_ITEM_GET(nrf_queue, nrf_queue_t, i);
|
||||
|
||||
uint32_t element_size = p_instance->element_size;
|
||||
uint32_t size = p_instance->size;
|
||||
uint32_t max_util = nrf_queue_max_utilization_get(p_instance);
|
||||
uint32_t util = nrf_queue_utilization_get(p_instance);
|
||||
const char * p_name = p_instance->p_name;
|
||||
nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL,
|
||||
"%s\r\n\t- Element size:\t%d\r\n"
|
||||
"\t- Usage:\t%u%% (%u out of %u elements)\r\n"
|
||||
"\t- Maximum:\t%u%% (%u out of %u elements)\r\n"
|
||||
"\t- Mode:\t\t%s\r\n\r\n",
|
||||
p_name, element_size,
|
||||
100ul * util/size, util,size,
|
||||
100ul * max_util/size, max_util,size,
|
||||
(p_instance->mode == NRF_QUEUE_MODE_OVERFLOW) ? "Overflow" : "No overflow");
|
||||
|
||||
}
|
||||
}
|
||||
// Register "queue" command and its subcommands in CLI.
|
||||
NRF_CLI_CREATE_STATIC_SUBCMD_SET(nrf_queue_commands)
|
||||
{
|
||||
NRF_CLI_CMD(status, NULL, "Print status of queue instances.", nrf_queue_status),
|
||||
NRF_CLI_SUBCMD_SET_END
|
||||
};
|
||||
|
||||
NRF_CLI_CMD_REGISTER(queue, &nrf_queue_commands, "Commands for BALLOC management", nrf_queue_status);
|
||||
#endif //NRF_QUEUE_CLI_CMDS
|
||||
|
||||
__STATIC_INLINE size_t circullar_buffer_size_get(nrf_queue_t const * p_queue)
|
||||
{
|
||||
static const uint8_t full_queue_indicator = 1;
|
||||
|
||||
/* When a queue is implemented as a cyclic buffer, it is not possible to
|
||||
* distinguish a full queue from an empty queue. In order to solve this
|
||||
* problem, the cyclic buffer has been implemented one element larger than
|
||||
* the queue size.
|
||||
*/
|
||||
return p_queue->size + full_queue_indicator;
|
||||
}
|
||||
|
||||
/**@brief Get next element index.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the queue instance.
|
||||
* @param[in] idx Current index.
|
||||
*
|
||||
* @return Next element index.
|
||||
*/
|
||||
__STATIC_INLINE size_t nrf_queue_next_idx(nrf_queue_t const * p_queue, size_t idx)
|
||||
{
|
||||
ASSERT(p_queue != NULL);
|
||||
return (idx < p_queue->size) ? (idx + 1) : 0;
|
||||
}
|
||||
|
||||
/**@brief Get current queue utilization. This function assumes that this process will not be interrupted.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the queue instance.
|
||||
*
|
||||
* @return Current queue utilization.
|
||||
*/
|
||||
__STATIC_INLINE size_t queue_utilization_get(nrf_queue_t const * p_queue)
|
||||
{
|
||||
size_t front = p_queue->p_cb->front;
|
||||
size_t back = p_queue->p_cb->back;
|
||||
|
||||
return (back >= front) ? (back - front) :
|
||||
(circullar_buffer_size_get(p_queue) - front + back);
|
||||
}
|
||||
|
||||
bool nrf_queue_is_full(nrf_queue_t const * p_queue)
|
||||
{
|
||||
ASSERT(p_queue != NULL);
|
||||
size_t front = p_queue->p_cb->front;
|
||||
size_t back = p_queue->p_cb->back;
|
||||
|
||||
return (nrf_queue_next_idx(p_queue, back) == front);
|
||||
}
|
||||
|
||||
ret_code_t nrf_queue_push(nrf_queue_t const * p_queue, void const * p_element)
|
||||
{
|
||||
ret_code_t status = NRF_SUCCESS;
|
||||
|
||||
ASSERT(p_queue != NULL);
|
||||
ASSERT(p_element != NULL);
|
||||
|
||||
CRITICAL_REGION_ENTER();
|
||||
bool is_full = nrf_queue_is_full(p_queue);
|
||||
|
||||
if (!is_full || (p_queue->mode == NRF_QUEUE_MODE_OVERFLOW))
|
||||
{
|
||||
// Get write position.
|
||||
size_t write_pos = p_queue->p_cb->back;
|
||||
p_queue->p_cb->back = nrf_queue_next_idx(p_queue, p_queue->p_cb->back);
|
||||
if (is_full)
|
||||
{
|
||||
// Overwrite the oldest element.
|
||||
NRF_LOG_INST_WARNING(p_queue->p_log, "Queue full. Overwriting oldest element.");
|
||||
p_queue->p_cb->front = nrf_queue_next_idx(p_queue, p_queue->p_cb->front);
|
||||
}
|
||||
|
||||
// Write a new element.
|
||||
switch (p_queue->element_size)
|
||||
{
|
||||
case sizeof(uint8_t):
|
||||
((uint8_t *)p_queue->p_buffer)[write_pos] = *((uint8_t *)p_element);
|
||||
break;
|
||||
|
||||
case sizeof(uint16_t):
|
||||
((uint16_t *)p_queue->p_buffer)[write_pos] = *((uint16_t *)p_element);
|
||||
break;
|
||||
|
||||
case sizeof(uint32_t):
|
||||
((uint32_t *)p_queue->p_buffer)[write_pos] = *((uint32_t *)p_element);
|
||||
break;
|
||||
|
||||
case sizeof(uint64_t):
|
||||
((uint64_t *)p_queue->p_buffer)[write_pos] = *((uint64_t *)p_element);
|
||||
break;
|
||||
|
||||
default:
|
||||
memcpy((void *)((size_t)p_queue->p_buffer + write_pos * p_queue->element_size),
|
||||
p_element,
|
||||
p_queue->element_size);
|
||||
break;
|
||||
}
|
||||
|
||||
// Update utilization.
|
||||
size_t utilization = queue_utilization_get(p_queue);
|
||||
if (p_queue->p_cb->max_utilization < utilization)
|
||||
{
|
||||
p_queue->p_cb->max_utilization = utilization;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = NRF_ERROR_NO_MEM;
|
||||
}
|
||||
|
||||
CRITICAL_REGION_EXIT();
|
||||
|
||||
NRF_LOG_INST_DEBUG(p_queue->p_log, "pushed element 0x%08X, status:%d", p_element, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
ret_code_t nrf_queue_generic_pop(nrf_queue_t const * p_queue,
|
||||
void * p_element,
|
||||
bool just_peek)
|
||||
{
|
||||
ret_code_t status = NRF_SUCCESS;
|
||||
|
||||
ASSERT(p_queue != NULL);
|
||||
ASSERT(p_element != NULL);
|
||||
|
||||
CRITICAL_REGION_ENTER();
|
||||
|
||||
if (!nrf_queue_is_empty(p_queue))
|
||||
{
|
||||
// Get read position.
|
||||
size_t read_pos = p_queue->p_cb->front;
|
||||
|
||||
// Update next read position.
|
||||
if (!just_peek)
|
||||
{
|
||||
p_queue->p_cb->front = nrf_queue_next_idx(p_queue, p_queue->p_cb->front);
|
||||
}
|
||||
|
||||
// Read element.
|
||||
switch (p_queue->element_size)
|
||||
{
|
||||
case sizeof(uint8_t):
|
||||
*((uint8_t *)p_element) = ((uint8_t *)p_queue->p_buffer)[read_pos];
|
||||
break;
|
||||
|
||||
case sizeof(uint16_t):
|
||||
*((uint16_t *)p_element) = ((uint16_t *)p_queue->p_buffer)[read_pos];
|
||||
break;
|
||||
|
||||
case sizeof(uint32_t):
|
||||
*((uint32_t *)p_element) = ((uint32_t *)p_queue->p_buffer)[read_pos];
|
||||
break;
|
||||
|
||||
case sizeof(uint64_t):
|
||||
*((uint64_t *)p_element) = ((uint64_t *)p_queue->p_buffer)[read_pos];
|
||||
break;
|
||||
|
||||
default:
|
||||
memcpy(p_element,
|
||||
(void const *)((size_t)p_queue->p_buffer + read_pos * p_queue->element_size),
|
||||
p_queue->element_size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = NRF_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
CRITICAL_REGION_EXIT();
|
||||
NRF_LOG_INST_DEBUG(p_queue->p_log, "%s element 0x%08X, status:%d",
|
||||
just_peek ? "peeked" : "popped", p_element, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Purpose of this function is to provide number of continous bytes in the queue's
|
||||
* array before circullar buffer needs to wrapp.
|
||||
*/
|
||||
static size_t continous_items_get(nrf_queue_t const * p_queue, bool write)
|
||||
{
|
||||
size_t front = p_queue->p_cb->front;
|
||||
size_t back = p_queue->p_cb->back;
|
||||
|
||||
/* Number of continous items for queue write operation */
|
||||
if (write)
|
||||
{
|
||||
return (back >= front) ? circullar_buffer_size_get(p_queue) - back : front - back;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (back >= front) ? back - front : circullar_buffer_size_get(p_queue) - front;
|
||||
}
|
||||
}
|
||||
|
||||
/**@brief Write elements to the queue. This function assumes that there is enough room in the queue
|
||||
* to write the requested number of elements and that this process will not be interrupted.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the nrf_queue_t instance.
|
||||
* @param[in] p_data Pointer to the buffer with elements to write.
|
||||
* @param[in] element_count Number of elements to write.
|
||||
*/
|
||||
static void queue_write(nrf_queue_t const * p_queue, void const * p_data, uint32_t element_count)
|
||||
{
|
||||
size_t prev_available = nrf_queue_available_get(p_queue);
|
||||
size_t continuous = continous_items_get(p_queue, true);
|
||||
void * p_write_ptr = (void *)((size_t)p_queue->p_buffer
|
||||
+ p_queue->p_cb->back * p_queue->element_size);
|
||||
|
||||
if (element_count <= continuous)
|
||||
{
|
||||
memcpy(p_write_ptr,
|
||||
p_data,
|
||||
element_count * p_queue->element_size);
|
||||
|
||||
p_queue->p_cb->back = ((p_queue->p_cb->back + element_count) <= p_queue->size)
|
||||
? (p_queue->p_cb->back + element_count)
|
||||
: 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t first_write_length = continuous * p_queue->element_size;
|
||||
memcpy(p_write_ptr,
|
||||
p_data,
|
||||
first_write_length);
|
||||
|
||||
size_t elements_left = element_count - continuous;
|
||||
memcpy(p_queue->p_buffer,
|
||||
(void const *)((size_t)p_data + first_write_length),
|
||||
elements_left * p_queue->element_size);
|
||||
|
||||
p_queue->p_cb->back = elements_left;
|
||||
if (prev_available < element_count)
|
||||
{
|
||||
// Overwrite the oldest elements.
|
||||
p_queue->p_cb->front = nrf_queue_next_idx(p_queue, p_queue->p_cb->back);
|
||||
}
|
||||
}
|
||||
|
||||
// Update utilization.
|
||||
size_t utilization = queue_utilization_get(p_queue);
|
||||
if (p_queue->p_cb->max_utilization < utilization)
|
||||
{
|
||||
p_queue->p_cb->max_utilization = utilization;
|
||||
}
|
||||
}
|
||||
|
||||
ret_code_t nrf_queue_write(nrf_queue_t const * p_queue,
|
||||
void const * p_data,
|
||||
size_t element_count)
|
||||
{
|
||||
ret_code_t status = NRF_SUCCESS;
|
||||
|
||||
ASSERT(p_queue != NULL);
|
||||
ASSERT(p_data != NULL);
|
||||
ASSERT(element_count <= p_queue->size);
|
||||
|
||||
if (element_count == 0)
|
||||
{
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
CRITICAL_REGION_ENTER();
|
||||
|
||||
if ((nrf_queue_available_get(p_queue) >= element_count)
|
||||
|| (p_queue->mode == NRF_QUEUE_MODE_OVERFLOW))
|
||||
{
|
||||
queue_write(p_queue, p_data, element_count);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = NRF_ERROR_NO_MEM;
|
||||
}
|
||||
|
||||
CRITICAL_REGION_EXIT();
|
||||
|
||||
NRF_LOG_INST_DEBUG(p_queue->p_log, "Write %d elements (start address: 0x%08X), status:%d",
|
||||
element_count, p_data, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
size_t nrf_queue_in(nrf_queue_t const * p_queue,
|
||||
void const * p_data,
|
||||
size_t element_count)
|
||||
{
|
||||
ASSERT(p_queue != NULL);
|
||||
ASSERT(p_data != NULL);
|
||||
|
||||
size_t req_element_count = element_count;
|
||||
|
||||
if (element_count == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CRITICAL_REGION_ENTER();
|
||||
|
||||
if (p_queue->mode == NRF_QUEUE_MODE_OVERFLOW)
|
||||
{
|
||||
element_count = MIN(element_count, p_queue->size);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t available = nrf_queue_available_get(p_queue);
|
||||
element_count = MIN(element_count, available);
|
||||
}
|
||||
|
||||
queue_write(p_queue, p_data, element_count);
|
||||
|
||||
CRITICAL_REGION_EXIT();
|
||||
|
||||
NRF_LOG_INST_DEBUG(p_queue->p_log, "Put in %d elements (start address: 0x%08X), requested :%d",
|
||||
element_count, p_data, req_element_count);
|
||||
|
||||
return element_count;
|
||||
}
|
||||
|
||||
/**@brief Read elements from the queue. This function assumes that there are enough elements
|
||||
* in the queue to read and that this process will not be interrupted.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the nrf_queue_t instance.
|
||||
* @param[out] p_data Pointer to the buffer where elements will be copied.
|
||||
* @param[in] element_count Number of elements to read.
|
||||
*/
|
||||
static void queue_read(nrf_queue_t const * p_queue, void * p_data, uint32_t element_count)
|
||||
{
|
||||
size_t front = p_queue->p_cb->front;
|
||||
size_t continuous = continous_items_get(p_queue, false);
|
||||
void const * p_read_ptr = (void const *)((size_t)p_queue->p_buffer
|
||||
+ front * p_queue->element_size);
|
||||
|
||||
if (element_count <= continuous)
|
||||
{
|
||||
memcpy(p_data,
|
||||
p_read_ptr,
|
||||
element_count * p_queue->element_size);
|
||||
|
||||
p_queue->p_cb->front = ((front + element_count) <= p_queue->size)
|
||||
? (front + element_count)
|
||||
: 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t first_read_length = continuous * p_queue->element_size;
|
||||
memcpy(p_data,
|
||||
p_read_ptr,
|
||||
first_read_length);
|
||||
|
||||
size_t elements_left = element_count - continuous;
|
||||
memcpy((void *)((size_t)p_data + first_read_length),
|
||||
p_queue->p_buffer,
|
||||
elements_left * p_queue->element_size);
|
||||
|
||||
p_queue->p_cb->front = elements_left;
|
||||
}
|
||||
}
|
||||
|
||||
ret_code_t nrf_queue_read(nrf_queue_t const * p_queue,
|
||||
void * p_data,
|
||||
size_t element_count)
|
||||
{
|
||||
ret_code_t status = NRF_SUCCESS;
|
||||
|
||||
ASSERT(p_queue != NULL);
|
||||
ASSERT(p_data != NULL);
|
||||
|
||||
if (element_count == 0)
|
||||
{
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
CRITICAL_REGION_ENTER();
|
||||
|
||||
if (element_count <= queue_utilization_get(p_queue))
|
||||
{
|
||||
queue_read(p_queue, p_data, element_count);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = NRF_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
CRITICAL_REGION_EXIT();
|
||||
|
||||
NRF_LOG_INST_DEBUG(p_queue->p_log, "Read %d elements (start address: 0x%08X), status :%d",
|
||||
element_count, p_data, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
size_t nrf_queue_out(nrf_queue_t const * p_queue,
|
||||
void * p_data,
|
||||
size_t element_count)
|
||||
{
|
||||
ASSERT(p_queue != NULL);
|
||||
ASSERT(p_data != NULL);
|
||||
|
||||
size_t req_element_count = element_count;
|
||||
|
||||
if (element_count == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CRITICAL_REGION_ENTER();
|
||||
|
||||
size_t utilization = queue_utilization_get(p_queue);
|
||||
element_count = MIN(element_count, utilization);
|
||||
|
||||
queue_read(p_queue, p_data, element_count);
|
||||
|
||||
CRITICAL_REGION_EXIT();
|
||||
|
||||
NRF_LOG_INST_DEBUG(p_queue->p_log, "Out %d elements (start address: 0x%08X), requested :%d",
|
||||
element_count, p_data, req_element_count);
|
||||
return element_count;
|
||||
}
|
||||
|
||||
void nrf_queue_reset(nrf_queue_t const * p_queue)
|
||||
{
|
||||
ASSERT(p_queue != NULL);
|
||||
|
||||
CRITICAL_REGION_ENTER();
|
||||
|
||||
memset(p_queue->p_cb, 0, sizeof(nrf_queue_cb_t));
|
||||
|
||||
CRITICAL_REGION_EXIT();
|
||||
|
||||
NRF_LOG_INST_DEBUG(p_queue->p_log, "Reset");
|
||||
}
|
||||
|
||||
size_t nrf_queue_utilization_get(nrf_queue_t const * p_queue)
|
||||
{
|
||||
size_t utilization;
|
||||
ASSERT(p_queue != NULL);
|
||||
|
||||
CRITICAL_REGION_ENTER();
|
||||
|
||||
utilization = queue_utilization_get(p_queue);
|
||||
|
||||
CRITICAL_REGION_EXIT();
|
||||
|
||||
return utilization;
|
||||
}
|
||||
|
||||
bool nrf_queue_is_empty(nrf_queue_t const * p_queue)
|
||||
{
|
||||
ASSERT(p_queue != NULL);
|
||||
size_t front = p_queue->p_cb->front;
|
||||
size_t back = p_queue->p_cb->back;
|
||||
return (front == back);
|
||||
}
|
||||
|
||||
size_t nrf_queue_available_get(nrf_queue_t const * p_queue)
|
||||
{
|
||||
ASSERT(p_queue != NULL);
|
||||
return p_queue->size - nrf_queue_utilization_get(p_queue);
|
||||
}
|
||||
|
||||
size_t nrf_queue_max_utilization_get(nrf_queue_t const * p_queue)
|
||||
{
|
||||
ASSERT(p_queue != NULL);
|
||||
return p_queue->p_cb->max_utilization;
|
||||
}
|
||||
|
||||
void nrf_queue_max_utilization_reset(nrf_queue_t const * p_queue)
|
||||
{
|
||||
ASSERT(p_queue != NULL);
|
||||
p_queue->p_cb->max_utilization = 0;
|
||||
}
|
||||
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_QUEUE)
|
||||
471
components/libraries/queue/nrf_queue.h
Normal file
471
components/libraries/queue/nrf_queue.h
Normal file
@@ -0,0 +1,471 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @defgroup nrf_queue Queue module
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
* @brief Functions that handle the queue instances.
|
||||
*/
|
||||
|
||||
#ifndef NRF_QUEUE_H__
|
||||
#define NRF_QUEUE_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "nrf_assert.h"
|
||||
#include "sdk_errors.h"
|
||||
#include "app_util.h"
|
||||
#include "app_util_platform.h"
|
||||
#include "nrf_log_instance.h"
|
||||
#include "nrf_section.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Name of the module used for logger messaging.
|
||||
*/
|
||||
#define NRF_QUEUE_LOG_NAME queue
|
||||
|
||||
/**@brief Queue control block. */
|
||||
typedef struct
|
||||
{
|
||||
volatile size_t front; //!< Queue front index.
|
||||
volatile size_t back; //!< Queue back index.
|
||||
size_t max_utilization; //!< Maximum utilization of the queue.
|
||||
} nrf_queue_cb_t;
|
||||
|
||||
/**@brief Supported queue modes. */
|
||||
typedef enum
|
||||
{
|
||||
NRF_QUEUE_MODE_OVERFLOW, //!< If the queue is full, new element will overwrite the oldest.
|
||||
NRF_QUEUE_MODE_NO_OVERFLOW, //!< If the queue is full, new element will not be accepted.
|
||||
} nrf_queue_mode_t;
|
||||
|
||||
/**@brief Instance of the queue. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_queue_cb_t * p_cb; //!< Pointer to the instance control block.
|
||||
void * p_buffer; //!< Pointer to the memory that is used as storage.
|
||||
size_t size; //!< Size of the queue.
|
||||
size_t element_size; //!< Size of one element.
|
||||
nrf_queue_mode_t mode; //!< Mode of the queue.
|
||||
#if NRF_QUEUE_CLI_CMDS
|
||||
const char * p_name; //!< Pointer to string with queue name.
|
||||
#endif
|
||||
NRF_LOG_INSTANCE_PTR_DECLARE(p_log) //!< Pointer to instance of the logger object (Conditionally compiled).
|
||||
} nrf_queue_t;
|
||||
|
||||
#if NRF_QUEUE_CLI_CMDS
|
||||
#define __NRF_QUEUE_ASSIGN_POOL_NAME(_name) .p_name = STRINGIFY(_name),
|
||||
#else
|
||||
#define __NRF_QUEUE_ASSIGN_POOL_NAME(_name)
|
||||
#endif
|
||||
/**@brief Create a queue instance.
|
||||
*
|
||||
* @note This macro reserves memory for the given queue instance.
|
||||
*
|
||||
* @param[in] _type Type which is stored.
|
||||
* @param[in] _name Name of the queue.
|
||||
* @param[in] _size Size of the queue.
|
||||
* @param[in] _mode Mode of the queue.
|
||||
*/
|
||||
#define NRF_QUEUE_DEF(_type, _name, _size, _mode) \
|
||||
static _type CONCAT_2(_name, _nrf_queue_buffer[(_size) + 1]); \
|
||||
static nrf_queue_cb_t CONCAT_2(_name, _nrf_queue_cb); \
|
||||
NRF_LOG_INSTANCE_REGISTER(NRF_QUEUE_LOG_NAME, _name, \
|
||||
NRF_QUEUE_CONFIG_INFO_COLOR, \
|
||||
NRF_QUEUE_CONFIG_DEBUG_COLOR, \
|
||||
NRF_QUEUE_CONFIG_LOG_INIT_FILTER_LEVEL, \
|
||||
NRF_QUEUE_CONFIG_LOG_ENABLED ? \
|
||||
NRF_QUEUE_CONFIG_LOG_LEVEL : NRF_LOG_SEVERITY_NONE); \
|
||||
NRF_SECTION_ITEM_REGISTER(nrf_queue, const nrf_queue_t _name) = \
|
||||
{ \
|
||||
.p_cb = &CONCAT_2(_name, _nrf_queue_cb), \
|
||||
.p_buffer = CONCAT_2(_name,_nrf_queue_buffer), \
|
||||
.size = (_size), \
|
||||
.element_size = sizeof(_type), \
|
||||
.mode = _mode, \
|
||||
__NRF_QUEUE_ASSIGN_POOL_NAME(_name) \
|
||||
NRF_LOG_INSTANCE_PTR_INIT(p_log, NRF_QUEUE_LOG_NAME, _name) \
|
||||
}
|
||||
|
||||
#if !(defined(__LINT__))
|
||||
/**@brief Create multiple queue instances.
|
||||
*
|
||||
* @note This macro reserves memory for array of queue instances.
|
||||
*
|
||||
* @param[in] _type Type which is stored.
|
||||
* @param[in] _name Name of the array with queue instances.
|
||||
* @param[in] _size Size of single queue instance.
|
||||
* @param[in] _mode Mode of single queue instance.
|
||||
* @param[in] _num Number of queue instances within array.
|
||||
*/
|
||||
#define NRF_QUEUE_ARRAY_DEF(_type, _name, _size, _mode, _num) \
|
||||
MACRO_REPEAT_FOR(_num, NRF_QUEUE_ARRAY_INSTANCE_ELEMS_DEC, _type, _name, _size, _mode) \
|
||||
static const nrf_queue_t _name[] = \
|
||||
{ \
|
||||
MACRO_REPEAT_FOR(_num, NRF_QUEUE_ARRAY_INSTANCE_INIT, _type, _name, _size, _mode) \
|
||||
}; \
|
||||
STATIC_ASSERT(ARRAY_SIZE(_name) == _num)
|
||||
#else
|
||||
#define NRF_QUEUE_ARRAY_DEF(_type, _name, _size, _mode, _num) \
|
||||
static const nrf_queue_t _name[_num];
|
||||
#endif // !(defined(__LINT__))
|
||||
|
||||
/**@brief Helping macro used to declare elements for nrf_queue_t instance.
|
||||
* Used in @ref NRF_QUEUE_ARRAY_DEF.
|
||||
*/
|
||||
#define NRF_QUEUE_ARRAY_INSTANCE_ELEMS_DEC(_num, _type, _name, _size, _mode) \
|
||||
static _type CONCAT_3(_name, _num, _nrf_queue_buffer[(_size) + 1]); \
|
||||
static nrf_queue_cb_t CONCAT_3(_name, _num, _nrf_queue_cb);
|
||||
|
||||
/**@brief Helping macro used to initialize nrf_queue_t instance in an array fashion.
|
||||
* Used in @ref NRF_QUEUE_ARRAY_DEF.
|
||||
*/
|
||||
#define NRF_QUEUE_ARRAY_INSTANCE_INIT(_num, _type, _name, _size, _mode) \
|
||||
{ \
|
||||
.p_cb = &CONCAT_3(_name, _num, _nrf_queue_cb), \
|
||||
.p_buffer = CONCAT_3(_name, _num, _nrf_queue_buffer), \
|
||||
.size = (_size), \
|
||||
.element_size = sizeof(_type), \
|
||||
.mode = _mode, \
|
||||
},
|
||||
|
||||
/**@brief Declare a queue interface.
|
||||
*
|
||||
* @param[in] _type Type which is stored.
|
||||
* @param[in] _name Name of the queue.
|
||||
*/
|
||||
#define NRF_QUEUE_INTERFACE_DEC(_type, _name) \
|
||||
ret_code_t _name##_push(_type const * p_element); \
|
||||
ret_code_t _name##_pop(_type * p_element); \
|
||||
ret_code_t _name##_peek(_type * p_element); \
|
||||
ret_code_t _name##_write(_type const * p_data, \
|
||||
size_t element_count); \
|
||||
ret_code_t _name##_read(_type * p_data, \
|
||||
size_t element_count); \
|
||||
size_t _name##_out(_type * p_data, \
|
||||
size_t element_count); \
|
||||
size_t _name##_in(_type const * p_data, \
|
||||
size_t element_count); \
|
||||
bool _name##_is_full(void); \
|
||||
bool _name##_is_empty(void); \
|
||||
size_t _name##_utilization_get(void); \
|
||||
size_t _name##_available_get(void); \
|
||||
size_t _name##_max_utilization_get(void); \
|
||||
void _name##_reset(void)
|
||||
|
||||
/**@brief Define a queue interface.
|
||||
*
|
||||
* @param[in] _type Type which is stored.
|
||||
* @param[in] _name Name of the queue.
|
||||
* @param[in] _p_queue Queue instance.
|
||||
*/
|
||||
#define NRF_QUEUE_INTERFACE_DEF(_type, _name, _p_queue) \
|
||||
ret_code_t _name##_push(_type const * p_element) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_queue) != NULL); \
|
||||
ASSERT((_p_queue)->element_size == sizeof(_type)); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
return nrf_queue_push((_p_queue), p_element); \
|
||||
} \
|
||||
ret_code_t _name##_pop(_type * p_element) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_queue) != NULL); \
|
||||
ASSERT((_p_queue)->element_size == sizeof(_type)); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
return nrf_queue_pop((_p_queue), p_element); \
|
||||
} \
|
||||
ret_code_t _name##_peek(_type * p_element) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_queue) != NULL); \
|
||||
ASSERT((_p_queue)->element_size == sizeof(_type)); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
return nrf_queue_peek((_p_queue), p_element); \
|
||||
} \
|
||||
ret_code_t _name##_write(_type const * p_data, \
|
||||
size_t element_count) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_queue) != NULL); \
|
||||
ASSERT((_p_queue)->element_size == sizeof(_type)); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
return nrf_queue_write((_p_queue), p_data, element_count); \
|
||||
} \
|
||||
ret_code_t _name##_read(_type * p_data, \
|
||||
size_t element_count) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_queue) != NULL); \
|
||||
ASSERT((_p_queue)->element_size == sizeof(_type)); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
return nrf_queue_read((_p_queue), p_data, element_count); \
|
||||
} \
|
||||
size_t _name##_in(_type const * p_data, \
|
||||
size_t element_count) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_queue) != NULL); \
|
||||
ASSERT((_p_queue)->element_size == sizeof(_type)); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
return nrf_queue_in((_p_queue), p_data, element_count); \
|
||||
} \
|
||||
size_t _name##_out(_type * p_data, \
|
||||
size_t element_count) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_queue) != NULL); \
|
||||
ASSERT((_p_queue)->element_size == sizeof(_type)); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
return nrf_queue_out((_p_queue), p_data, element_count); \
|
||||
} \
|
||||
bool _name##_is_full(void) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_queue) != NULL); \
|
||||
return nrf_queue_is_full(_p_queue); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
} \
|
||||
bool _name##_is_empty(void) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_queue) != NULL); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
return nrf_queue_is_empty(_p_queue); \
|
||||
} \
|
||||
size_t _name##_utilization_get(void) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_queue) != NULL); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
return nrf_queue_utilization_get(_p_queue); \
|
||||
} \
|
||||
size_t _name##_available_get(void) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_queue) != NULL); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
return nrf_queue_available_get(_p_queue); \
|
||||
} \
|
||||
size_t _name##_max_utilization_get(void) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_queue) != NULL); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
return nrf_queue_max_utilization_get(_p_queue); \
|
||||
} \
|
||||
void _name##_reset(void) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_queue) != NULL); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
nrf_queue_reset(_p_queue); \
|
||||
}
|
||||
|
||||
/**@brief Function for pushing an element to the end of queue.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the nrf_queue_t instance.
|
||||
* @param[in] p_element Pointer to the element that will be stored in the queue.
|
||||
*
|
||||
* @return NRF_SUCCESS If an element has been successfully added.
|
||||
* @return NRF_ERROR_NO_MEM If the queue is full (only in @ref NRF_QUEUE_MODE_NO_OVERFLOW).
|
||||
*/
|
||||
ret_code_t nrf_queue_push(nrf_queue_t const * p_queue, void const * p_element);
|
||||
|
||||
/**@brief Generic pop implementation.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the nrf_queue_t instance.
|
||||
* @param[out] p_element Pointer where the element will be copied.
|
||||
* @param[out] just_peek If true, the returned element will not be removed from queue.
|
||||
*
|
||||
* @return NRF_SUCCESS If an element was returned.
|
||||
* @return NRF_ERROR_NOT_FOUND If there are no more elements in the queue.
|
||||
*/
|
||||
ret_code_t nrf_queue_generic_pop(nrf_queue_t const * p_queue,
|
||||
void * p_element,
|
||||
bool just_peek);
|
||||
|
||||
/**@brief Pop element from the front of the queue.
|
||||
*
|
||||
* @param[in] _p_queue Pointer to the nrf_queue_t instance.
|
||||
* @param[out] _p_element Pointer where the element will be copied.
|
||||
*
|
||||
* @return NRF_SUCCESS If an element was returned.
|
||||
* @return NRF_ERROR_NOT_FOUND If there are no more elements in the queue.
|
||||
*/
|
||||
#define nrf_queue_pop(_p_queue, _p_element) nrf_queue_generic_pop((_p_queue), (_p_element), false)
|
||||
|
||||
/**@brief Peek element from the front of the queue.
|
||||
*
|
||||
* @param[in] _p_queue Pointer to the nrf_queue_t instance.
|
||||
* @param[out] _p_element Pointer where the element will be copied.
|
||||
*
|
||||
* @return NRF_SUCCESS If an element was returned.
|
||||
* @return NRF_ERROR_NOT_FOUND If there are no more elements in the queue.
|
||||
*/
|
||||
#define nrf_queue_peek(_p_queue, _p_element) nrf_queue_generic_pop((_p_queue), (_p_element), true)
|
||||
|
||||
/**@brief Function for writing elements to the queue.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the nrf_queue_t instance.
|
||||
* @param[in] p_data Pointer to the buffer with elements to write.
|
||||
* @param[in] element_count Number of elements to write.
|
||||
*
|
||||
* @return NRF_SUCCESS If an element was written.
|
||||
* @return NRF_ERROR_NO_MEM There is not enough space in the queue. No element was written.
|
||||
*/
|
||||
ret_code_t nrf_queue_write(nrf_queue_t const * p_queue,
|
||||
void const * p_data,
|
||||
size_t element_count);
|
||||
|
||||
/**@brief Function for writing a portion of elements to the queue.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the nrf_queue_t instance.
|
||||
* @param[in] p_data Pointer to the buffer with elements to write.
|
||||
* @param[in] element_count Number of elements to write.
|
||||
*
|
||||
* @return The number of added elements.
|
||||
*/
|
||||
size_t nrf_queue_in(nrf_queue_t const * p_queue,
|
||||
void const * p_data,
|
||||
size_t element_count);
|
||||
|
||||
/**@brief Function for reading elements from the queue.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the nrf_queue_t instance.
|
||||
* @param[out] p_data Pointer to the buffer where elements will be copied.
|
||||
* @param[in] element_count Number of elements to read.
|
||||
*
|
||||
* @return NRF_SUCCESS If an element was returned.
|
||||
* @return NRF_ERROR_NOT_FOUND There is not enough elements in the queue.
|
||||
*/
|
||||
ret_code_t nrf_queue_read(nrf_queue_t const * p_queue,
|
||||
void * p_data,
|
||||
size_t element_count);
|
||||
|
||||
/**@brief Function for reading a portion of elements from the queue.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the nrf_queue_t instance.
|
||||
* @param[out] p_data Pointer to the buffer where elements will be copied.
|
||||
* @param[in] element_count Number of elements to read.
|
||||
*
|
||||
* @return The number of read elements.
|
||||
*/
|
||||
size_t nrf_queue_out(nrf_queue_t const * p_queue,
|
||||
void * p_data,
|
||||
size_t element_count);
|
||||
|
||||
/**@brief Function for checking if the queue is full.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the queue instance.
|
||||
*
|
||||
* @return True if the queue is full.
|
||||
*/
|
||||
bool nrf_queue_is_full(nrf_queue_t const * p_queue);
|
||||
|
||||
/**@brief Function for checking if the queue is empty.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the queue instance.
|
||||
*
|
||||
* @return True if the queue is empty.
|
||||
*/
|
||||
bool nrf_queue_is_empty(nrf_queue_t const * p_queue);
|
||||
|
||||
/**@brief Function for getting the current queue utilization.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the queue instance.
|
||||
*
|
||||
* @return Current queue utilization.
|
||||
*/
|
||||
size_t nrf_queue_utilization_get(nrf_queue_t const * p_queue);
|
||||
|
||||
/**@brief Function for getting the size of available space.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the queue instance.
|
||||
*
|
||||
* @return Size of available space.
|
||||
*/
|
||||
size_t nrf_queue_available_get(nrf_queue_t const * p_queue);
|
||||
|
||||
/**@brief Function for getting the maximal queue utilization.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the queue instance.
|
||||
*
|
||||
* @return Maximal queue utilization.
|
||||
*/
|
||||
size_t nrf_queue_max_utilization_get(nrf_queue_t const * p_queue);
|
||||
|
||||
/**@brief Function for resetting the maximal queue utilization.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the queue instance.
|
||||
*
|
||||
*/
|
||||
void nrf_queue_max_utilization_reset(nrf_queue_t const * p_queue);
|
||||
|
||||
/**@brief Function for resetting the queue state.
|
||||
*
|
||||
* @param[in] p_queue Pointer to the queue instance.
|
||||
*/
|
||||
void nrf_queue_reset(nrf_queue_t const * p_queue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_QUEUE_H__
|
||||
/** @} */
|
||||
Reference in New Issue
Block a user