µGFX  2.9
version 2.9
gos_cmsis.h
Go to the documentation of this file.
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.io/license.html
6  */
7 
8 /**
9  * @file src/gos/gos_cmsis.h
10  * @brief GOS - Operating System Support header file for CMSIS RTOS.
11  */
12 
13 #ifndef _GOS_CMSIS_H
14 #define _GOS_CMSIS_H
15 
16 #if GFX_USE_OS_CMSIS
17 
18 #include "cmsis_os.h"
19 
20 #ifndef GFX_OS_HEAP_SIZE
21  #define GFX_OS_HEAP_SIZE 10240
22 #endif
23 
24 /*===========================================================================*/
25 /* Type definitions */
26 /*===========================================================================*/
27 
28 #define gDelayNone 0
29 #define gDelayForever osWaitForever
30 typedef gU32 gDelay;
31 typedef gU32 gTicks;
32 typedef gU16 gSemcount;
33 typedef void gThreadreturn;
34 typedef osPriority gThreadpriority;
35 
36 #define gSemMaxCount osFeature_Semaphore
37 #define gThreadpriorityLow osPriorityLow
38 #define gThreadpriorityNormal osPriorityNormal
39 #define gThreadpriorityHigh osPriorityHigh
40 
41 typedef struct gSem {
42  gU32 semaphore[2];
43  osSemaphoreId id;
44  gSemcount available;
45 } gSem;
46 
47 typedef struct gMutex {
48  gU32 mutex[4];
49  osMutexId id;
50 } gMutex;
51 
52 typedef osThreadId gThread;
53 
54 #define GFX_THREAD_STACK(name, sz) gU8 name[1]; // Some compilers don't allow zero sized arrays. Let's waste one byte
55 #define GFX_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void* param)
56 #define gfxThreadReturn(retval) return
57 
58 /*===========================================================================*/
59 /* Function declarations. */
60 /*===========================================================================*/
61 
62 #define gfxExit() os_error(0)
63 #define gfxHalt(msg) os_error(1)
64 #define gfxSystemTicks() osKernelSysTick()
65 #define gfxMillisecondsToTicks(ms) osKernelSysTickMicroSec(1000*ms)
66 #define gfxSystemLock() osKernelInitialize()
67 #define gfxSystemUnlock() osKernelStart()
68 #define gfxSleepMilliseconds(ms) osDelay(ms)
69 
70 void gfxMutexInit(gMutex* pmutex);
71 #define gfxMutexDestroy(pmutex) osMutexDelete((pmutex)->id)
72 #define gfxMutexEnter(pmutex) osMutexWait((pmutex)->id, gDelayForever)
73 #define gfxMutexExit(pmutex) osMutexRelease((pmutex)->id)
74 
75 void gfxSemInit(gSem* psem, gSemcount val, gSemcount limit);
76 void gfxSemDestroy(gSem* psem);
77 gBool gfxSemWait(gSem* psem, gDelay ms);
78 gBool gfxSemWaitI(gSem* psem);
79 void gfxSemSignal(gSem* psem);
80 void gfxSemSignalI(gSem* psem);
81 
82 gThread gfxThreadCreate(void* stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void* param);
83 #define gfxYield() osThreadYield()
84 #define gfxThreadMe() osThreadGetId()
85 #define gfxThreadClose(thread) {}
86 
87 /*===========================================================================*/
88 /* Use the generic heap handling */
89 /*===========================================================================*/
90 
91 #define GOS_NEED_X_HEAP GFXON
92 #include "gos_x_heap.h"
93 
94 #endif /* GFX_USE_OS_CMSIS */
95 #endif /* _GOS_CMSIS_H */
void gfxSemSignal(gSem *psem)
Signal a semaphore.
void * gThread
A thread handle.
Definition: gos.h:116
#define GFX_THREAD_FUNCTION(fnName, param)
Declare a thread function.
Definition: gos.h:73
gBool gfxSemWait(gSem *psem, gDelay ms)
Wait on a semaphore.
void gfxMutexInit(gMutex *pmutex)
Initialise a mutex to protect a region of code from other threads.
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn), p), void *param)
Start a new thread.
gBool gfxSemWaitI(gSem *psem)
Test if a wait on a semaphore can be satisfied immediately.
void gfxSemDestroy(gSem *psem)
Destroy a Counted Semaphore.
void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit)
Initialise a Counted Semaphore.
void gfxSemSignalI(gSem *psem)
Signal a semaphore.
A mutex.
Definition: gos.h:110
A semaphore.
Definition: gos.h:104