Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinKastberg committed Feb 1, 2024
1 parent 68cbf53 commit 466877c
Showing 1 changed file with 41 additions and 12 deletions.
53 changes: 41 additions & 12 deletions source/iar/retarget_os_rtos2.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "cmsis_os2.h"
#include "cmsis_compiler.h"

#if defined(_DLIB_THREAD_SUPPORT) && _DLIB_THREAD_SUPPORT > 0
//#if defined(_DLIB_THREAD_SUPPORT) && _DLIB_THREAD_SUPPORT > 0

/* Check if the kernel has been initialized */
static uint32_t os_kernel_is_initialized (void) {
Expand Down Expand Up @@ -53,41 +53,70 @@ struct rt_mutex_s {
osMutexId_t id;
};

#pragma language=save
#pragma language=extended
/* Initialize mutex */
__USED void __iar_system_Mtxinit(__iar_Rmtx *)
__USED void __iar_system_Mtxinit(struct rt_mutex_s *mutex)
{
int result = 0;

if (os_kernel_is_initialized()) {
mutex->id = osMutexNew(NULL);
}
}

/* Acquire mutex */
__USED void __iar_system_Mtxlock(struct rt_mutex_s *mutex)
{
if (os_kernel_is_running() && is_thread_mode()) {
(void)osMutexAcquire(mutex->id, osWaitForever);
}
}

/* Release mutex */
__USED void __iar_system_Mtxunlock(struct rt_mutex_s *mutex) // Unlock a system lock
{
if (os_kernel_is_running() && is_thread_mode()) {
(void)osMutexRelease(mutex->id);
}
}

/* Free mutex */
__USED void __iar_system_Mtxdst(struct rt_mutex_s *mutex) // Destroy a system lock
{
(void)osMutexDelete(mutex->id);
}

//#endif //defined(_DLIB_THREAD_SUPPORT) && _DLIB_THREAD_SUPPORT > 0

if (mutex->id != NULL) {
result = 1;
}
/* Initialize mutex */
__USED void __iar_file_Mtxinit(struct rt_mutex_s *mutex)
{
if (os_kernel_is_initialized()) {
mutex->id = osMutexNew(NULL);
}
return result;
}

/* Acquire mutex */
__USED void __iar_system_Mtxlock(__iar_Rmtx *);
__USED void __iar_file_Mtxlock(struct rt_mutex_s *mutex)
{
if (os_kernel_is_running() && is_thread_mode()) {
(void)osMutexAcquire(mutex->id, osWaitForever);
}
}

/* Release mutex */
__USED void __iar_system_Mtxunlock(__iar_Rmtx *); // Unlock a system lock
__USED void __iar_file_Mtxunlock(struct rt_mutex_s *mutex) // Unlock a system lock
{
if (os_kernel_is_running() && is_thread_mode()) {
(void)osMutexRelease(mutex->id);
}
}

/* Free mutex */
__USED void __iar_system_Mtxdst(__iar_Rmtx *); // Destroy a system lock
__USED void __iar_file_Mtxdst(struct rt_mutex_s *mutex) // Destroy a system lock
{
(void)osMutexDelete(mutex->id);
}

#endif //defined(_DLIB_THREAD_SUPPORT) && _DLIB_THREAD_SUPPORT > 0
//#endif //defined(_DLIB_THREAD_SUPPORT) && _DLIB_THREAD_SUPPORT > 0

#pragma language=restore

0 comments on commit 466877c

Please sign in to comment.