Prusa MINI Firmware overview
Collaboration diagram for Mailboxes:

Functions

err_t sys_mbox_new (sys_mbox_t *mbox, int size)
 
void sys_mbox_post (sys_mbox_t *mbox, void *msg)
 
err_t sys_mbox_trypost (sys_mbox_t *mbox, void *msg)
 
u32_t sys_arch_mbox_fetch (sys_mbox_t *mbox, void **msg, u32_t timeout)
 
u32_t sys_arch_mbox_tryfetch (sys_mbox_t *mbox, void **msg)
 
void sys_mbox_free (sys_mbox_t *mbox)
 
int sys_mbox_valid (sys_mbox_t *mbox)
 
void sys_mbox_set_invalid (sys_mbox_t *mbox)
 

Detailed Description

Function Documentation

◆ sys_mbox_new()

err_t sys_mbox_new ( sys_mbox_t mbox,
int  size 
)

Create a new mbox of specified size

Parameters
mboxpointer to the mbox to create
size(minimum) number of messages in this mbox
Returns
ERR_OK if successful, another err_t otherwise
51 {
52  osMessageQDef(QUEUE, size, void *);
53 
54  *mbox = osMessageCreate(osMessageQ(QUEUE), NULL);
55 
56 #if SYS_STATS
57  ++lwip_stats.sys.mbox.used;
58  if (lwip_stats.sys.mbox.max < lwip_stats.sys.mbox.used) {
59  lwip_stats.sys.mbox.max = lwip_stats.sys.mbox.used;
60  }
61 #endif /* SYS_STATS */
62  if (*mbox == NULL)
63  return ERR_MEM;
64 
65  return ERR_OK;
66 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sys_mbox_post()

void sys_mbox_post ( sys_mbox_t mbox,
void msg 
)

Post a message to an mbox - may not fail -> blocks if full, only used from tasks not from ISR

Parameters
mboxmbox to posts the message
msgmessage to post (ATTENTION: can be NULL)
97 {
98  while(osMessagePut(*mbox, (uint32_t)data, osWaitForever) != osOK);
99 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sys_mbox_trypost()

err_t sys_mbox_trypost ( sys_mbox_t mbox,
void msg 
)

Try to post a message to an mbox - may fail if full or ISR

Parameters
mboxmbox to posts the message
msgmessage to post (ATTENTION: can be NULL)
105 {
106 err_t result;
107 
108  if ( osMessagePut(*mbox, (uint32_t)msg, 0) == osOK)
109  {
110  result = ERR_OK;
111  }
112  else {
113  // could not post, queue must be full
114  result = ERR_MEM;
115 
116 #if SYS_STATS
117  lwip_stats.sys.mbox.err++;
118 #endif /* SYS_STATS */
119 
120  }
121 
122  return result;
123 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sys_arch_mbox_fetch()

u32_t sys_arch_mbox_fetch ( sys_mbox_t mbox,
void **  msg,
u32_t  timeout 
)

Wait for a new message to arrive in the mbox

Parameters
mboxmbox to get a message from
msgpointer where the message is stored
timeoutmaximum time (in milliseconds) to wait for a message (0 = wait forever)
Returns
time (in milliseconds) waited for a message, may be 0 if not waited or SYS_ARCH_TIMEOUT on timeout The returned time has to be accurate to prevent timer jitter!
142 {
143  osEvent event;
144  uint32_t starttime = osKernelSysTick();;
145 
146  if(timeout != 0)
147  {
148  event = osMessageGet (*mbox, timeout);
149 
150  if(event.status == osEventMessage)
151  {
152  *msg = (void *)event.value.v;
153  return (osKernelSysTick() - starttime);
154  }
155  else
156  {
157  return SYS_ARCH_TIMEOUT;
158  }
159  }
160  else
161  {
162  event = osMessageGet (*mbox, osWaitForever);
163  *msg = (void *)event.value.v;
164  return (osKernelSysTick() - starttime);
165  }
166 }
Here is the call graph for this function:

◆ sys_arch_mbox_tryfetch()

u32_t sys_arch_mbox_tryfetch ( sys_mbox_t mbox,
void **  msg 
)

Wait for a new message to arrive in the mbox

Parameters
mboxmbox to get a message from
msgpointer where the message is stored
Returns
0 (milliseconds) if a message has been received or SYS_MBOX_EMPTY if the mailbox is empty
174 {
175  osEvent event;
176 
177  event = osMessageGet (*mbox, 0);
178 
179  if(event.status == osEventMessage)
180  {
181  *msg = (void *)event.value.v;
182  return ERR_OK;
183  }
184  else
185  {
186  return SYS_MBOX_EMPTY;
187  }
188 }
Here is the call graph for this function:

◆ sys_mbox_free()

void sys_mbox_free ( sys_mbox_t mbox)

Delete an mbox

Parameters
mboxmbox to delete
75 {
76  if( osMessageWaiting(*mbox) )
77  {
78  /* Line for breakpoint. Should never break here! */
79  portNOP();
80 #if SYS_STATS
81  lwip_stats.sys.mbox.err++;
82 #endif /* SYS_STATS */
83 
84  // TODO notify the user of failure.
85  }
86 
88 
89 #if SYS_STATS
90  --lwip_stats.sys.mbox.used;
91 #endif /* SYS_STATS */
92 }
Here is the call graph for this function:

◆ sys_mbox_valid()

int sys_mbox_valid ( sys_mbox_t mbox)

Check if an mbox is valid/allocated: return 1 for valid, 0 for invalid

191 {
192  if (*mbox == SYS_MBOX_NULL)
193  return 0;
194  else
195  return 1;
196 }

◆ sys_mbox_set_invalid()

void sys_mbox_set_invalid ( sys_mbox_t mbox)

Set an mbox invalid so that sys_mbox_valid returns 0

199 {
200  *mbox = SYS_MBOX_NULL;
201 }
osKernelSysTick
uint32_t osKernelSysTick(void)
Get the value of the Kernel SysTick timer.
Definition: cmsis_os.c:227
mbox
static sys_mbox_t mbox
Definition: tcpip.c:61
data
uint8_t data[8]
Definition: masstorage.h:49
NULL
#define NULL
Definition: usbd_def.h:53
osEvent::status
osStatus status
status code: event or error information
Definition: cmsis_os.h:396
osMessageGet
osEvent osMessageGet(osMessageQId queue_id, uint32_t millisec)
Get a Message or Wait for a Message from a Queue.
Definition: cmsis_os.c:1145
ERR_MEM
Definition: err.h:65
osEvent
Definition: cmsis_os.h:395
osMessageWaiting
uint32_t osMessageWaiting(osMessageQId queue_id)
Get the number of messaged stored in a queue.
Definition: cmsis_os.c:1642
portNOP
#define portNOP()
Definition: portmacro.h:203
osOK
function completed; no error or event occurred.
Definition: cmsis_os.h:235
osMessagePut
osStatus osMessagePut(osMessageQId queue_id, uint32_t info, uint32_t millisec)
Put a Message to a Queue.
Definition: cmsis_os.c:1113
osEventMessage
function completed; message event occurred.
Definition: cmsis_os.h:237
osWaitForever
#define osWaitForever
wait forever timeout value
Definition: cmsis_os.h:230
osMessageDelete
osStatus osMessageDelete(osMessageQId queue_id)
Delete a Message Queue.
Definition: cmsis_os.c:1668
ERR_OK
Definition: err.h:63
err_t
s8_t err_t
Definition: err.h:57
SYS_MBOX_EMPTY
#define SYS_MBOX_EMPTY
Definition: sys.h:92
osMessageCreate
osMessageQId osMessageCreate(const osMessageQDef_t *queue_def, osThreadId thread_id)
Create and Initialize a Message Queue.
Definition: cmsis_os.c:1086
osMessageQ
#define osMessageQ(name)
Access a Message Queue Definition.
Definition: cmsis_os.h:829
osEvent::value
union osEvent::@54 value
event value
SYS_MBOX_NULL
#define SYS_MBOX_NULL
Definition: sys_arch.h:37
osEvent::v
uint32_t v
message as 32-bit value
Definition: cmsis_os.h:398
SYS_ARCH_TIMEOUT
#define SYS_ARCH_TIMEOUT
Definition: sys.h:87
size
static png_bytep size_t size
Definition: pngwrite.c:2170
osMessageQDef
#define osMessageQDef(name, queue_sz, type)
Create a Message Queue Definition.
Definition: cmsis_os.h:818