Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Different task priorities are possible in FreeRTOS. Therefore, the netX peripheral driver needs to operate as a subordinate component. That's why it is strongly recommended using the FreeRTOS mutex implementation for the netX peripheral driver instead of the original mutex implementation. Another benefit of using the FreeRTOS mutex is, that it supports concepts such as priority inheritance.

Since FreeRTOS supports dynamic and static memory management, there are basically two options: a dynamic mutex or a static mutex. Currently, only the dynamic mutex is supported (therefore we need a heap structure).

Dynamic Mutex Implementation

For the dynamic peripheral driver implementation, the following definitions need to be made in the netx_drv_user_conf.h:

Code Block
languagecpp
titlenetx_drv_user_conf.h
/*!
 * \brief Define that has to be set if an RTOS is used.
 */
#define RTOS_USED

/*!
 * \brief RTOS_USED relevant define that ignores the compiler error that is
 * generated to let the engineer know, that those functions has to be implemented
 * by him.
 */
#define RTOS_ERROR_IGNORE

/*!
 * \brief RTOS_USED relevant type used for the element to be locked
 */
#define DRV_LOCK_T  SemaphoreHandle_t

/*!
 * \brief RTOS_USED relevant initializer type of the type to be locked as rvalue is in default the mutex initializer type.
 */
#define DRV_LOCK_INITIALIZER_TYPE SemaphoreHandle_t

/*!
 * \brief RTOS_USED relevant initializer value of the type to be locked as rvalue is in default the mutex initializer value.
 */
#define DRV_LOCK_INITIALIZER_VALUE NULL

/*!
 * \brief RTOS_USED relevant initializer of the type to be locked as rvalue.
 */
#define DRV_LOCK_INITIALIZER  xSemaphoreCreateMutex()

/*!
 * \brief RTOS_USED relevant function executing the lock.
 * Shall return DRV_LOCKED in case the mutex is not free or
 * might be implemented with priority inheritance or similiar functionality.
 */
#define DRV_LOCK(__HANDLE__)  if(xSemaphoreTake((__HANDLE__)->tLock,0)!=pdTRUE ){return DRV_LOCKED;}

/*!
 * \brief RTOS_USED relevant function releasing the lock.
 */
#define DRV_UNLOCK(__HANDLE__)  xSemaphoreGive((__HANDLE__)->tLock)

Static

...

Mutex Implementation

A static Mutex implementation is currently not supported.