Browse Source

Add support for ChibiOS V5 - Thanks Vrollei

inmarket 1 year ago
parent
commit
e2fb6820d0
4 changed files with 38 additions and 30 deletions
  1. 1 0
      changelog.txt
  2. 21 23
      src/gos/gos_chibios.c
  3. 11 6
      src/gos/gos_chibios.h
  4. 5 1
      tools/gmake_scripts/os_chibios.mk

+ 1 - 0
changelog.txt

@@ -25,6 +25,7 @@ FIX:		Fixed UC1610 driver private area initialisation
25 25
 FIX:		Fixed ST7735 driver and added kapacuk changes
26 26
 FEATURE:	Added keyboard support to radio buttons (by Steffan)
27 27
 FEATURE:	Added internal use only GFX_COMPILESTAGE (used to control compilation)
28
+FEATURE:	Added support for ChibiOS Kernel V5
28 29
 
29 30
 
30 31
 *** Release 2.8 ***

+ 21 - 23
src/gos/gos_chibios.c

@@ -11,38 +11,36 @@
11 11
 
12 12
 #include <string.h>
13 13
 
14
-#if CH_KERNEL_MAJOR == 2
14
+#if CH_KERNEL_MAJOR < 2 || CH_KERNEL_MAJOR > 5
15
+	#error "GOS: Unsupported version of ChibiOS"
16
+#endif
15 17
 
18
+#if CH_KERNEL_MAJOR <= 2
16 19
 	#if !CH_USE_MUTEXES
17 20
 		#error "GOS: CH_USE_MUTEXES must be defined in chconf.h"
18 21
 	#endif
19 22
 	#if !CH_USE_SEMAPHORES
20 23
 		#error "GOS: CH_USE_SEMAPHORES must be defined in chconf.h"
21 24
 	#endif
22
-	
23
-#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4)
24
-
25
+#else
25 26
 	#if !CH_CFG_USE_MUTEXES
26 27
 		#error "GOS: CH_CFG_USE_MUTEXES must be defined in chconf.h"
27 28
 	#endif
28 29
 	#if !CH_CFG_USE_SEMAPHORES
29 30
 		#error "GOS: CH_CFG_USE_SEMAPHORES must be defined in chconf.h"
30 31
 	#endif
31
-
32
-#else
33
-	#error "GOS: Unsupported version of ChibiOS"
34 32
 #endif
35 33
 
36 34
 void _gosInit(void)
37 35
 {
38 36
 	#if !GFX_OS_NO_INIT
39 37
 		/* Don't Initialize if the user already has */
40
-		#if CH_KERNEL_MAJOR == 2
38
+		#if CH_KERNEL_MAJOR <= 2
41 39
 			if (!chThdSelf()) {
42 40
 				halInit();
43 41
 				chSysInit();
44 42
 			}
45
-		#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4)
43
+		#else
46 44
 			if (!chThdGetSelfX()) {
47 45
 				halInit();
48 46
 				chSysInit();
@@ -108,9 +106,9 @@ void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit)
108 106
 
109 107
 	psem->limit = limit;
110 108
 	
111
-	#if CH_KERNEL_MAJOR == 2
109
+	#if CH_KERNEL_MAJOR <= 2
112 110
 		chSemInit(&psem->sem, val);
113
-	#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4)
111
+	#else
114 112
 		chSemObjectInit(&psem->sem, val);
115 113
 	#endif
116 114
 }
@@ -122,27 +120,27 @@ void gfxSemDestroy(gfxSem *psem)
122 120
 
123 121
 gBool gfxSemWait(gfxSem *psem, delaytime_t ms)
124 122
 {
125
-	#if CH_KERNEL_MAJOR == 2
123
+	#if CH_KERNEL_MAJOR <= 2
126 124
 		switch(ms) {
127 125
 		case TIME_IMMEDIATE:	return chSemWaitTimeout(&psem->sem, TIME_IMMEDIATE) != RDY_TIMEOUT;
128 126
 		case TIME_INFINITE:		chSemWait(&psem->sem);	return gTrue;
129
-		default:				return chSemWaitTimeout(&psem->sem, MS2ST(ms)) != RDY_TIMEOUT;
127
+		default:				return chSemWaitTimeout(&psem->sem, gfxMillisecondsToTicks(ms)) != RDY_TIMEOUT;
130 128
 		}
131
-	#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4)
129
+	#else
132 130
 		switch(ms) {
133 131
 		case TIME_IMMEDIATE:	return chSemWaitTimeout(&psem->sem, TIME_IMMEDIATE) != MSG_TIMEOUT;
134 132
 		case TIME_INFINITE:		chSemWait(&psem->sem);	return gTrue;
135
-		default:				return chSemWaitTimeout(&psem->sem, MS2ST(ms)) != MSG_TIMEOUT;
133
+		default:				return chSemWaitTimeout(&psem->sem, gfxMillisecondsToTicks(ms)) != MSG_TIMEOUT;
136 134
 		}
137 135
 	#endif
138 136
 }
139 137
 
140 138
 gBool gfxSemWaitI(gfxSem *psem)
141 139
 {
142
-	#if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3)
140
+	#if CH_KERNEL_MAJOR <= 3
143 141
 		if (psem->sem.s_cnt <= 0)
144 142
 			return gFalse;
145
-	#elif (CH_KERNEL_MAJOR == 4)
143
+	#else
146 144
 		if (psem->sem.cnt <= 0)
147 145
 			return gFalse;
148 146
 	#endif
@@ -154,10 +152,10 @@ void gfxSemSignal(gfxSem *psem)
154 152
 {
155 153
 	chSysLock();
156 154
 
157
-	#if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3)
155
+	#if CH_KERNEL_MAJOR <= 3
158 156
 		if (psem->sem.s_cnt < psem->limit)
159 157
 			chSemSignalI(&psem->sem);
160
-	#elif (CH_KERNEL_MAJOR == 4)
158
+	#else
161 159
 		if (psem->sem.cnt < psem->limit)
162 160
 			chSemSignalI(&psem->sem);
163 161
 	#endif
@@ -168,10 +166,10 @@ void gfxSemSignal(gfxSem *psem)
168 166
 
169 167
 void gfxSemSignalI(gfxSem *psem)
170 168
 {
171
-	#if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3)
169
+	#if CH_KERNEL_MAJOR <= 3
172 170
 		if (psem->sem.s_cnt < psem->limit)
173 171
 			chSemSignalI(&psem->sem);
174
-	#elif (CH_KERNEL_MAJOR == 4)
172
+	#else
175 173
 		if (psem->sem.cnt < psem->limit)
176 174
 			chSemSignalI(&psem->sem);
177 175
 	#endif
@@ -181,9 +179,9 @@ gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_
181 179
 {
182 180
 	if (!stackarea) {
183 181
 		if (!stacksz) stacksz = 256;
184
-		#if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3)
182
+		#if CH_KERNEL_MAJOR <= 3
185 183
 			return chThdCreateFromHeap(0, stacksz, prio, (tfunc_t)fn, param);
186
-		#elif CH_KERNEL_MAJOR == 4
184
+		#else
187 185
 			return chThdCreateFromHeap(0, stacksz, "ugfx", prio, (tfunc_t)fn, param);
188 186
 		#endif
189 187
 	}

+ 11 - 6
src/gos/gos_chibios.h

@@ -45,7 +45,7 @@ typedef tprio_t		threadpriority_t;
45 45
 #define DECLARE_THREAD_FUNCTION(fnName, param)	threadreturn_t fnName(void *param)
46 46
 #define THREAD_RETURN(retval)					return retval
47 47
 
48
-#if CH_KERNEL_MAJOR == 2
48
+#if CH_KERNEL_MAJOR <= 2
49 49
 	typedef struct {
50 50
 		Semaphore	sem;
51 51
 		semcount_t	limit;
@@ -53,7 +53,7 @@ typedef tprio_t		threadpriority_t;
53 53
 
54 54
 	typedef Mutex		gfxMutex;
55 55
 	typedef Thread*		gfxThreadHandle;
56
-#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4)
56
+#else
57 57
 	#undef DECLARE_THREAD_STACK
58 58
 	#define DECLARE_THREAD_STACK(a, b)  THD_WORKING_AREA(a, b)
59 59
 
@@ -72,24 +72,29 @@ typedef tprio_t		threadpriority_t;
72 72
 /*===========================================================================*/
73 73
 
74 74
 // First the kernel version specific ones
75
-#if CH_KERNEL_MAJOR == 2
75
+#if CH_KERNEL_MAJOR <= 2
76 76
 	#define gfxSystemTicks()			chTimeNow()
77 77
 	#define gfxMutexInit(pmutex)		chMtxInit(pmutex)
78 78
 	#define gfxMutexExit(pmutex)		chMtxUnlock()
79 79
 	#define gfxExit()					chSysHalt()
80 80
 	#define gfxHalt(msg)				{ chDbgPanic(msg); chSysHalt(); }
81
-#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4)
81
+#else
82 82
 	#define gfxSystemTicks()			chVTGetSystemTimeX()
83 83
 	#define gfxMutexInit(pmutex)		chMtxObjectInit(pmutex)
84 84
 	#define gfxMutexExit(pmutex)		chMtxUnlock(pmutex)
85 85
 	#define gfxExit()					osalSysHalt("gfx_exit")
86
-#define gfxHalt(msg)					{ chSysHalt(msg); }
86
+	#define gfxHalt(msg)				{ chSysHalt(msg); }
87
+#endif
88
+
89
+#if CH_KERNEL_MAJOR <= 4
90
+	#define gfxMillisecondsToTicks(ms)	MS2ST(ms)
91
+#else
92
+	#define gfxMillisecondsToTicks(ms)	TIME_MS2I(ms)
87 93
 #endif
88 94
 
89 95
 #define gfxAlloc(sz)				chHeapAlloc(0, sz)
90 96
 #define gfxFree(ptr)				chHeapFree(ptr)
91 97
 #define gfxYield()					chThdYield()
92
-#define gfxMillisecondsToTicks(ms)	MS2ST(ms)
93 98
 #define gfxSystemLock()				chSysLock()
94 99
 #define gfxSystemUnlock()			chSysUnlock()
95 100
 #define gfxMutexDestroy(pmutex)		(void)pmutex

+ 5 - 1
tools/gmake_scripts/os_chibios.mk

@@ -9,7 +9,7 @@
9 9
 
10 10
 # Requirements:
11 11
 #
12
-# CHIBIOS_VERSION               Which version of ChibiOS is this (2, 3, 16, git) - default is 16
12
+# CHIBIOS_VERSION               Which version of ChibiOS is this (2, 3, 4, 5, 16, git) - default is 16
13 13
 #								Note the 'git' option is one we try to keep up to date with the ChibiOS master
14 14
 #									If you find the 'git' option requires update please let us know.
15 15
 #
@@ -19,6 +19,10 @@ ifeq ($(CHIBIOS_VERSION),2)
19 19
   include $(GFXLIB)/tools/gmake_scripts/os_chibios_2.mk
20 20
 else ifeq ($(CHIBIOS_VERSION),3)
21 21
   include $(GFXLIB)/tools/gmake_scripts/os_chibios_3.mk
22
+else ifeq ($(CHIBIOS_VERSION),4)
23
+  include $(GFXLIB)/tools/gmake_scripts/os_chibios_3.mk
24
+else ifeq ($(CHIBIOS_VERSION),5)
25
+  include $(GFXLIB)/tools/gmake_scripts/os_chibios_3.mk
22 26
 else ifeq ($(CHIBIOS_VERSION),16)
23 27
   include $(GFXLIB)/tools/gmake_scripts/os_chibios_3.mk
24 28
 else ifeq ($(CHIBIOS_VERSION),git)