Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
msg_queue.h File Reference
#include <ch.h>
#include <hal.h>
#include "modules/tlsf/tlsf_malloc.h"
+ Include dependency graph for msg_queue.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  MsgQueue
 

Typedefs

typedef struct MsgQueue MsgQueue
 

Enumerations

enum  MsgQueueStatus {
  MsgQueue_MAILBOX_FULL = -100 , MsgQueue_MAILBOX_FAIL , MsgQueue_MAILBOX_TIMEOUT , MsgQueue_MAILBOX_NOT_EMPTY ,
  MsgQueue_INVALID_PTR , MsgQueue_OK = 0
}
 
enum  MsgQueueUrgency { MsgQueue_REGULAR , MsgQueue_OUT_OF_BAND }
 

Functions

void msgqueue_init (MsgQueue *que, tlsf_memory_heap_t *heap, msg_t *mb_buf, const cnt_t mb_size)
 initialise MsgQueue More...
 
bool msgqueue_is_full (MsgQueue *que)
 test if queue is full More...
 
bool msgqueue_is_empty (MsgQueue *que)
 test if queue is empty More...
 
int32_t msgqueue_send (MsgQueue *que, void *msg, const uint16_t msgLen, const MsgQueueUrgency urgency)
 send a buffer previously allocated by msgqueue_malloc_before_send More...
 
int32_t msgqueue_send_timeout (MsgQueue *que, void *msg, const uint16_t msgLen, const MsgQueueUrgency urgency, const systime_t timout)
 send a buffer previously allocated by msgqueue_malloc_before_send More...
 
int32_t msgqueue_copy_send (MsgQueue *que, const void *msg, const uint16_t msgLen, const MsgQueueUrgency urgency)
 send a buffer NOT previously allocated More...
 
int32_t msgqueue_copy_send_timeout (MsgQueue *que, const void *msg, const uint16_t msgLen, const MsgQueueUrgency urgency, const systime_t timout)
 send a buffer NOT previously allocated More...
 
int32_t msgqueue_pop (MsgQueue *que, void **msgPtr)
 wait then receive message More...
 
int32_t msgqueue_pop_timeout (MsgQueue *que, void **msgPtr, const systime_t timout)
 receive message specifying timeout More...
 
const char * msgqueue_strerror (const MsgQueueStatus errno)
 debug api More...
 

Data Structure Documentation

◆ MsgQueue

struct MsgQueue

Definition at line 225 of file msg_queue.h.

+ Collaboration diagram for MsgQueue:
Data Fields
tlsf_memory_heap_t * heap
mailbox_t mb

Typedef Documentation

◆ MsgQueue

typedef struct MsgQueue MsgQueue

Definition at line 1 of file msg_queue.h.

Enumeration Type Documentation

◆ MsgQueueStatus

Enumerator
MsgQueue_MAILBOX_FULL 
MsgQueue_MAILBOX_FAIL 
MsgQueue_MAILBOX_TIMEOUT 
MsgQueue_MAILBOX_NOT_EMPTY 
MsgQueue_INVALID_PTR 
MsgQueue_OK 

Definition at line 38 of file msg_queue.h.

◆ MsgQueueUrgency

Enumerator
MsgQueue_REGULAR 
MsgQueue_OUT_OF_BAND 

Definition at line 47 of file msg_queue.h.

Function Documentation

◆ msgqueue_copy_send()

int32_t msgqueue_copy_send ( MsgQueue que,
const void *  msg,
const uint16_t  msgLen,
const MsgQueueUrgency  urgency 
)

send a buffer NOT previously allocated

buffer is copied before beeing sent, buffer is still valid after this function returns. Less effective that zero copy alternatives which has been to be preferably used Non blocking, if queue is full, report error and immediately return

Parameters
[in]quepointer to opaque MsgQueue object
[in]msgpointer to buffer
[in]msgLenlength of buffer (the same param that has been given to msgqueue_malloc_before_send)
[in]urgencyregular=queued at end of fifo or out_of_band queued at start of fifo
Returns
if > 0 : requested length if < 0 : error status (see errors at begining of this header file)

Definition at line 127 of file msg_queue.c.

References msg, and msgqueue_copy_send_timeout().

+ Here is the call graph for this function:

◆ msgqueue_copy_send_timeout()

int32_t msgqueue_copy_send_timeout ( MsgQueue que,
const void *  msg,
const uint16_t  msgLen,
const MsgQueueUrgency  urgency,
const systime_t  timout 
)

send a buffer NOT previously allocated

buffer is copied before beeing sent, buffer is still valid after this function returns. Less effective that zero copy alternatives which has been to be preferably used

Parameters
[in]quepointer to opaque MsgQueue object
[in]msgpointer to buffer
[in]msgLenlength of buffer (the same param that has been given to msgqueue_malloc_before_send)
[in]urgencyregular=queued at end of fifo or out_of_band queued at start of fifo
[in]timout: time to wait for MailBox avaibility (can be TIME_INFINITE or TIME_IMMEDIATE)
Returns
if > 0 : requested length if < 0 : error status (see errors at begining of this header file)

Definition at line 114 of file msg_queue.c.

References msg, MSGQ_HEAP, MsgQueue_MAILBOX_FULL, msgqueue_send_timeout(), and tlsf_malloc_r().

Referenced by msgqueue_copy_send().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ msgqueue_init()

void msgqueue_init ( MsgQueue que,
tlsf_memory_heap_t heap,
msg_t *  mb_buf,
const cnt_t  mb_size 
)

initialise MsgQueue

init sdQueue objet, tie memory pool buffer, tie mailbox buffer initialize mailbox

Parameters
[out]queopaque object to be initialized
[in]heapreference to the tlsf heap object (needed if module should free memory)
[in]mb_buffinternal buffer used by MailBox (see Chibios Doc)
[in]mb_sizesize of previous buffer (length of MailBox queue)

Definition at line 42 of file msg_queue.c.

References MsgQueue::heap, and MsgQueue::mb.

Referenced by sdLogInit().

+ Here is the caller graph for this function:

◆ msgqueue_is_empty()

bool msgqueue_is_empty ( MsgQueue que)

test if queue is empty

Parameters
[in]quepointer to opaque MsgQueue object
Returns
true if empty, false otherwise

Definition at line 59 of file msg_queue.c.

References MsgQueue::mb.

◆ msgqueue_is_full()

bool msgqueue_is_full ( MsgQueue que)

test if queue is full

Parameters
[in]quepointer to opaque MsgQueue object
Returns
true if full, false otherwise

Definition at line 50 of file msg_queue.c.

References MsgQueue::mb.

◆ msgqueue_pop()

int32_t msgqueue_pop ( MsgQueue que,
void **  msgPtr 
)

wait then receive message

this is zero copy api, blocking call usage : struct MyStruct *msg msgqueue_pop (&que, void (void **) &msg); use msg->myField etc etc tlsf_free(MSGQ_HEAP, msg);

Parameters
[in]quepointer to opaque MsgQueue object
[out]msgPtrpointer to pointer to buffer
Returns
if > 0 : length of received msg if < 0 : error status (see errors at begining of this header file)

Definition at line 134 of file msg_queue.c.

References msgqueue_pop_timeout().

+ Here is the call graph for this function:

◆ msgqueue_pop_timeout()

int32_t msgqueue_pop_timeout ( MsgQueue que,
void **  msgPtr,
const systime_t  timout 
)

receive message specifying timeout

this is zero copy api, blocking call usage : struct MyStruct *msg msgqueue_pop (&que, void (void **) &msg); use msg->myField etc etc msgqueue_free_after_pop (&que, msg);

Parameters
[in]quepointer to opaque MsgQueue object
[out]msgPtrpointer to pointer to buffer
[in]timout: time to wait for MailBox avaibility (can be TIME_INFINITE or TIME_IMMEDIATE)
Returns
if > 0 : length of received msg if < 0 : error status (see errors at begining of this header file)

Definition at line 139 of file msg_queue.c.

References MsgQueue::mb, MsgPtrLen::msg_ptr_len, MSGQ_HEAP, MsgQueue_MAILBOX_TIMEOUT, status, and tlsf_get_heap_addr().

Referenced by msgqueue_pop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ msgqueue_send()

int32_t msgqueue_send ( MsgQueue que,
void *  msg,
const uint16_t  msgLen,
const MsgQueueUrgency  urgency 
)

send a buffer previously allocated by msgqueue_malloc_before_send

deallocation is done by the caching thread which actually write data to sd card from the sender point of view, ptr should be considered invalid after beeing sent. Even if msgqueue_send fail, deallocation is done Non blocking, if queue is full, report error and immediately return usage : msg = tlsf_malloc(MSGQ_HEAP, msg, msgLen); msgqueue_send (que, msg, msgLen, urgency);

Parameters
[in]quepointer to opaque MsgQueue object
[in]msgpointer to buffer given by msgqueue_malloc_before_send
[in]msgLenlength of buffer (the same param that has been given to msgqueue_malloc_before_send)
[in]urgencyregular=queued at end of fifo or out_of_band queued at start of fifo
Returns
if > 0 : requested length if < 0 : error status (see errors at begining of this header file)

Definition at line 69 of file msg_queue.c.

References msg, and msgqueue_send_timeout().

+ Here is the call graph for this function:

◆ msgqueue_send_timeout()

int32_t msgqueue_send_timeout ( MsgQueue que,
void *  msg,
const uint16_t  msgLen,
const MsgQueueUrgency  urgency,
const systime_t  timout 
)

send a buffer previously allocated by msgqueue_malloc_before_send

deallocation is done by the caching thread which actually write data to sd card from the sender point of view, ptr should be considered invalid after beeing sent. Even if msgqueue_send fail, deallocation is done usage : msg = tlsf_malloc(MSGQ_HEAP, msg, msgLen); msgqueue_send (que, msg, msgLen, urgency);

Parameters
[in]quepointer to opaque MsgQueue object
[in]msgpointer to buffer given by msgqueue_malloc_before_send
[in]msgLenlength of buffer (the same param that has been given to msgqueue_malloc_before_send)
[in]urgencyregular=queued at end of fifo or out_of_band queued at start of fifo
[in]timout: time to wait for MailBox avaibility (can be TIME_INFINITE or TIME_IMMEDIATE)
Returns
if > 0 : requested length if < 0 : error status (see errors at begining of this header file)

Definition at line 76 of file msg_queue.c.

References MsgQueue::heap, simple_quad_sim::m, MsgQueue::mb, msg, MsgPtrLen::msg_ptr_len, MSGQ_HEAP, MsgQueue_INVALID_PTR, MsgQueue_MAILBOX_FULL, MsgQueue_REGULAR, tlsf_free_r(), and tlsf_get_heap_addr().

Referenced by msgqueue_copy_send_timeout(), and msgqueue_send().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ msgqueue_strerror()

const char* msgqueue_strerror ( const MsgQueueStatus  errno)

debug api

give ascii string corresponding to the given errno

Parameters
[in]errno: staus
Returns
pointer to error string

Definition at line 168 of file msg_queue.c.

References _strerror, and MsgQueue_MAILBOX_FULL.