Prusa MINI Firmware overview
Collaboration diagram for Semaphores:

Functions

err_t sys_sem_new (sys_sem_t *sem, u8_t count)
 
void sys_sem_signal (sys_sem_t *sem)
 
u32_t sys_arch_sem_wait (sys_sem_t *sem, u32_t timeout)
 
void sys_sem_free (sys_sem_t *sem)
 
int sys_sem_valid (sys_sem_t *sem)
 
void sys_sem_set_invalid (sys_sem_t *sem)
 

Detailed Description

Function Documentation

◆ sys_sem_new()

err_t sys_sem_new ( sys_sem_t sem,
u8_t  count 
)

Create a new semaphore

Parameters
sempointer to the semaphore to create
countinitial count of the semaphore
Returns
ERR_OK if successful, another err_t otherwise
207 {
208  osSemaphoreDef(SEM);
209 
210  *sem = osSemaphoreCreate (osSemaphore(SEM), 1);
211 
212  if(*sem == NULL)
213  {
214 #if SYS_STATS
215  ++lwip_stats.sys.sem.err;
216 #endif /* SYS_STATS */
217  return ERR_MEM;
218  }
219 
220  if(count == 0) // Means it can't be taken
221  {
222  osSemaphoreWait(*sem,0);
223  }
224 
225 #if SYS_STATS
226  ++lwip_stats.sys.sem.used;
227  if (lwip_stats.sys.sem.max < lwip_stats.sys.sem.used) {
228  lwip_stats.sys.sem.max = lwip_stats.sys.sem.used;
229  }
230 #endif /* SYS_STATS */
231 
232  return ERR_OK;
233 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sys_sem_signal()

void sys_sem_signal ( sys_sem_t sem)

Signals a semaphore

Parameters
semthe semaphore to signal
276 {
277  osSemaphoreRelease(*sem);
278 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sys_arch_sem_wait()

u32_t sys_arch_sem_wait ( sys_sem_t sem,
u32_t  timeout 
)

Wait for a semaphore for the specified timeout

Parameters
semthe semaphore to wait for
timeouttimeout in milliseconds to wait (0 = wait forever)
Returns
time (in milliseconds) waited for the semaphore or SYS_ARCH_TIMEOUT on timeout
252 {
253  uint32_t starttime = osKernelSysTick();
254 
255  if(timeout != 0)
256  {
257  if(osSemaphoreWait (*sem, timeout) == osOK)
258  {
259  return (osKernelSysTick() - starttime);
260  }
261  else
262  {
263  return SYS_ARCH_TIMEOUT;
264  }
265  }
266  else
267  {
268  while(osSemaphoreWait (*sem, osWaitForever) != osOK);
269  return (osKernelSysTick() - starttime);
270  }
271 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sys_sem_free()

void sys_sem_free ( sys_sem_t sem)

Delete a semaphore

Parameters
semsemaphore to delete
283 {
284 #if SYS_STATS
285  --lwip_stats.sys.sem.used;
286 #endif /* SYS_STATS */
287 
288  osSemaphoreDelete(*sem);
289 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sys_sem_valid()

int sys_sem_valid ( sys_sem_t sem)

Check if a semaphore is valid/allocated: return 1 for valid, 0 for invalid

292 {
293  if (*sem == SYS_SEM_NULL)
294  return 0;
295  else
296  return 1;
297 }
Here is the caller graph for this function:

◆ sys_sem_set_invalid()

void sys_sem_set_invalid ( sys_sem_t sem)

Set a semaphore invalid so that sys_sem_valid returns 0

301 {
302  *sem = SYS_SEM_NULL;
303 }
osKernelSysTick
uint32_t osKernelSysTick(void)
Get the value of the Kernel SysTick timer.
Definition: cmsis_os.c:227
osSemaphore
#define osSemaphore(name)
Definition: cmsis_os.h:709
osSemaphoreWait
int32_t osSemaphoreWait(osSemaphoreId semaphore_id, uint32_t millisec)
Wait until a Semaphore token becomes available.
Definition: cmsis_os.c:822
NULL
#define NULL
Definition: usbd_def.h:53
osSemaphoreDelete
osStatus osSemaphoreDelete(osSemaphoreId semaphore_id)
Delete a Semaphore.
Definition: cmsis_os.c:889
ERR_MEM
Definition: err.h:65
osSemaphoreCreate
osSemaphoreId osSemaphoreCreate(const osSemaphoreDef_t *semaphore_def, int32_t count)
Create and Initialize a Semaphore object used for managing resources.
Definition: cmsis_os.c:755
osSemaphoreDef
#define osSemaphoreDef(name)
Definition: cmsis_os.h:700
osOK
function completed; no error or event occurred.
Definition: cmsis_os.h:235
osWaitForever
#define osWaitForever
wait forever timeout value
Definition: cmsis_os.h:230
ERR_OK
Definition: err.h:63
SYS_SEM_NULL
#define SYS_SEM_NULL
Definition: sys_arch.h:38
SYS_ARCH_TIMEOUT
#define SYS_ARCH_TIMEOUT
Definition: sys.h:87
osSemaphoreRelease
osStatus osSemaphoreRelease(osSemaphoreId semaphore_id)
Release a Semaphore token.
Definition: cmsis_os.c:862