mirror of
https://github.com/OneOfEleven/uv-k5-firmware-custom.git
synced 2025-06-20 15:08:37 +03:00
Initial commit
This commit is contained in:
55
external/CMSIS_5/CMSIS/RTOS/RTX/UserCodeTemplates/Mutex.c
vendored
Normal file
55
external/CMSIS_5/CMSIS/RTOS/RTX/UserCodeTemplates/Mutex.c
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
|
||||
#include "cmsis_os.h" // CMSIS RTOS header file
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Mutex creation & usage
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void Thread_Mutex (void const *argument); // thread function
|
||||
osThreadId tid_Thread_Mutex; // thread id
|
||||
osThreadDef (Thread_Mutex, osPriorityNormal, 1, 0); // thread object
|
||||
|
||||
osMutexId mid_Thread_Mutex; // mutex id
|
||||
osMutexDef (SampleMutex); // mutex name definition
|
||||
|
||||
|
||||
int Init_Mutex (void) {
|
||||
|
||||
mid_Thread_Mutex = osMutexCreate (osMutex (SampleMutex));
|
||||
if (!tid_Thread_Mutex) {
|
||||
; // Mutex object not created, handle failure
|
||||
}
|
||||
|
||||
tid_Thread_Mutex = osThreadCreate (osThread(Thread_Mutex), NULL);
|
||||
if (!tid_Thread_Mutex) return(-1);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
void Thread_Mutex (void const *argument) {
|
||||
osStatus status;
|
||||
|
||||
while (1) {
|
||||
; // Insert thread code here...
|
||||
|
||||
status = osMutexWait (mid_Thread_Mutex, NULL);
|
||||
switch (status) {
|
||||
case osOK:
|
||||
; // Use protected code here...
|
||||
osMutexRelease (mid_Thread_Mutex);
|
||||
break;
|
||||
case osErrorTimeoutResource:
|
||||
break;
|
||||
case osErrorResource:
|
||||
break;
|
||||
case osErrorParameter:
|
||||
break;
|
||||
case osErrorISR:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
osThreadYield (); // suspend thread
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user