Prusa MINI Firmware overview
Collaboration diagram for Mutexes:

Functions

err_t sys_mutex_new (sys_mutex_t *mutex)
 
void sys_mutex_lock (sys_mutex_t *mutex)
 
void sys_mutex_unlock (sys_mutex_t *mutex)
 
void sys_mutex_free (sys_mutex_t *mutex)
 
int sys_mutex_valid (sys_mutex_t *mutex)
 
void sys_mutex_set_invalid (sys_mutex_t *mutex)
 

Detailed Description

Mutexes are recommended to correctly handle priority inversion, especially if you use LWIP_CORE_LOCKING .

Function Documentation

◆ sys_mutex_new()

err_t sys_mutex_new ( sys_mutex_t mutex)

Create a new mutex. Note that mutexes are expected to not be taken recursively by the lwIP code, so both implementation types (recursive or non-recursive) should work.

Parameters
mutexpointer to the mutex to create
Returns
ERR_OK if successful, another err_t otherwise
319  {
320 
321  osMutexDef(MUTEX);
322 
323  *mutex = osMutexCreate(osMutex(MUTEX));
324 
325 
326  //*mutex = xSemaphoreCreateMutex();
327  if(*mutex == NULL)
328  {
329 #if SYS_STATS
330  ++lwip_stats.sys.mutex.err;
331 #endif /* SYS_STATS */
332  return ERR_MEM;
333  }
334 
335 #if SYS_STATS
336  ++lwip_stats.sys.mutex.used;
337  if (lwip_stats.sys.mutex.max < lwip_stats.sys.mutex.used) {
338  lwip_stats.sys.mutex.max = lwip_stats.sys.mutex.used;
339  }
340 #endif /* SYS_STATS */
341  return ERR_OK;
342 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sys_mutex_lock()

void sys_mutex_lock ( sys_mutex_t mutex)

Lock a mutex

Parameters
mutexthe mutex to lock
356 {
357  osMutexWait (*mutex, osWaitForever);
358 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sys_mutex_unlock()

void sys_mutex_unlock ( sys_mutex_t mutex)

Unlock a mutex

Parameters
mutexthe mutex to unlock
363 {
364  osMutexRelease(*mutex);
365 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sys_mutex_free()

void sys_mutex_free ( sys_mutex_t mutex)

Delete a semaphore

Parameters
mutexthe mutex to delete
346 {
347 #if SYS_STATS
348  --lwip_stats.sys.mutex.used;
349 #endif /* SYS_STATS */
350 
351  osMutexDelete(*mutex);
352 }
Here is the call graph for this function:

◆ sys_mutex_valid()

int sys_mutex_valid ( sys_mutex_t mutex)

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

◆ sys_mutex_set_invalid()

void sys_mutex_set_invalid ( sys_mutex_t mutex)

Set a mutex invalid so that sys_mutex_valid returns 0

osMutexDef
osMutexDef(lwip_sys_mutex)
osMutexRelease
osStatus osMutexRelease(osMutexId mutex_id)
Release a Mutex that was obtained by osMutexWait.
Definition: cmsis_os.c:709
NULL
#define NULL
Definition: usbd_def.h:53
ERR_MEM
Definition: err.h:65
osMutexCreate
osMutexId osMutexCreate(const osMutexDef_t *mutex_def)
Create and Initialize a Mutex object.
Definition: cmsis_os.c:640
osWaitForever
#define osWaitForever
wait forever timeout value
Definition: cmsis_os.h:230
ERR_OK
Definition: err.h:63
osMutex
#define osMutex(name)
Definition: cmsis_os.h:650
osMutexWait
osStatus osMutexWait(osMutexId mutex_id, uint32_t millisec)
Wait until a Mutex becomes available.
Definition: cmsis_os.c:669
osMutexDelete
osStatus osMutexDelete(osMutexId mutex_id)
Delete a Mutex.
Definition: cmsis_os.c:733