Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

define queue in a structure

I have searched this website,there is only 1 post,but that is not my scenario.

I think this is a normal use case:

There is a struct:

struct ble_tgoi_c_s
{
    uint16_t                  conn_handle;   /**< Connection handle as provided by the SoftDevice. */
    tgoi_db_t                 peer_tgoi_db;   /**< Handles related to LBS on the peer. */
    ble_tgoi_c_evt_handler_t  evt_handler;   /**< Application event handler to be called when there is an event related to the LED Button service. */
    ble_srv_error_handler_t   error_handler; /**< Function to be called in case of an error. */
    uint8_t                   uuid_type;     /**< UUID type. */
    nrf_ble_gq_t            * p_gatt_queue;  /**< Pointer to the BLE GATT Queue instance. */
	nrf_queue_t*              queue;
};

I want to allocate a queue for each struct.(I have to connect up to 20 BLE peripherals in a single nRF52840 module,it is better to allocate queue for each one for some BLE peripherals maybe lose connection temperarily,that will block the whole tranfer process  with only one buffer)

Do we have a right way to call NRF_QUEUE_DEF?

If no,this port code is right?

#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)                  \
        }

-> normal funtion

#include <stdlib.h>	
				
typedef struct{ 
	uint8_t data[BUFFER_DOWN_QUEUE_UNIT_SIZE];
} buffer_down_structure_t;		

nrf_queue_t* nrf_queue_mydef(uint16_t size){
    buffer_down_structure_t* queue_nrf_queue_buffer;//[(size) + 1];
    queue_nrf_queue_buffer = (buffer_down_structure_t*)malloc(((size) + 1)*sizeof(buffer_down_structure_t));
    if(queue_nrf_queue_buffer == NULL)
    	return NULL;
    	
    nrf_queue_cb_t* queue_nrf_queue_cb;
    queue_nrf_queue_cb = (nrf_queue_cb_t*)malloc(sizeof(nrf_queue_cb_t));
    if(queue_nrf_queue_cb == NULL)
        return NULL;
    
    nrf_queue_t* q = (nrf_queue_t*)malloc(sizeof( nrf_queue_t));
	if(q == NULL)
		return NULL;
  	q->p_cb           = queue_nrf_queue_cb;
    q->p_buffer       = queue_nrf_queue_buffer;
    q->size           = size;
    q->element_size   = sizeof(buffer_down_structure_t);
    q->mode           = BUFFER_DOWN_QUEUE_MODE;
    
	return q;
}	

Parents Reply Children
Related