GUI_X_uCOS.c
1 /*
2 *********************************************************************************************************
3 * uC/GUI
4 * Universal graphic software for embedded applications
5 *
6 * (c) Copyright 2002, Micrium Inc., Weston, FL
7 * (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
8 *
9 * 礐/GUI is protected by international copyright laws. Knowledge of the
10 * source code may not be used to write a similar product. This file may
11 * only be used in accordance with a license and should not be redistributed
12 * in any way. We appreciate your understanding and fairness.
13 *
14 ---Author-Explanation
15 *
16 * 1.00.00 020519 JJL First release of uC/GUI to uC/OS-II interface
17 *
18 *
19 * Known problems or limitations with current version
20 *
21 * None.
22 *
23 *
24 * Open issues
25 *
26 * None
27 *********************************************************************************************************
28 */
29
30 #include "os.h"
31 #include "os_Cfg_app.h"
32 #include "GUI_Private.H"
33 #include "stdio.H"
34
35
36 /*
37 *********************************************************************************************************
38 * GLOBAL VARIABLES
39 *********************************************************************************************************
40 */
41
42 static int KeyPressed;
43 static char KeyIsInited;
44
45 static OS_SEM dispSem;
46 static OS_SEM eventSem;
47 static OS_SEM keySem;
48
49 /*
50 *********************************************************************************************************
51 * TIMING FUNCTIONS
52 *
53 * Notes: Some timing dependent routines of uC/GUI require a GetTime and delay funtion.
54 * Default time unit (tick), normally is 1 ms.
55 *********************************************************************************************************
56 */
57
58 int GUI_X_GetTime(void)
59 {
60 OS_ERR err;
61
62 return ((int)OSTimeGet( (OS_ERR *)&err));
63 }
64
65 void GUI_X_Delay(int period)
66 {
67 OS_TICK ticks;
68 OS_ERR err;
69
70 ticks = period * OS_CFG_TICK_RATE_HZ / 1000;
71 OSTimeDly( (OS_TICK )ticks,
72 (OS_OPT )OS_OPT_TIME_DLY,
73 (OS_ERR *)&err);
74 }
75
76
77 /*
78 *********************************************************************************************************
79 * GUI_X_ExecIdle()
80 *********************************************************************************************************
81 */
82 /*WM空闲时调用*/
83 void GUI_X_ExecIdle(void)
84 {
85 OS_ERR err;
86
87 OSTimeDly( (OS_TICK )50,
88 (OS_OPT )OS_OPT_TIME_DLY,
89 (OS_ERR *)&err);
90 }
91
92
93 /*
94 *********************************************************************************************************
95 * MULTITASKING INTERFACE FUNCTIONS
96 *
97 * Note(1): 1) The following routines are required only if uC/GUI is used in a true multi task environment,
98 * which means you have more than one thread using the uC/GUI API. In this case the #define
99 * GUI_OS 1 needs to be in GUIConf.h
100 *********************************************************************************************************
101 */
102
103 void GUI_X_InitOS (void)
104 {
105 OS_ERR err;
106
107 OSSemCreate( (OS_SEM *)&dispSem, //建立一个互斥型信号量
108 (CPU_CHAR *)"dispSem",
109 (OS_SEM_CTR )1,
110 (OS_ERR *)&err );
111
112 OSSemCreate( (OS_SEM *)&eventSem,
113 (CPU_CHAR *)"eventSem",
114 (OS_SEM_CTR )1,
115 (OS_ERR *)&err );
116 }
117
118
119 void GUI_X_Lock(void)
120 {
121 OS_ERR err;
122 CPU_TS ts;
123
124 OSSemPend( (OS_SEM *)&dispSem,
125 (OS_TICK )0,
126 (OS_OPT )OS_OPT_PEND_BLOCKING,
127 (CPU_TS *)&ts,
128 (OS_ERR *)&err);
129 }
130
131
132 void GUI_X_Unlock(void)
133 {
134 OS_ERR err;
135
136 OSSemPost( (OS_SEM *)&dispSem,
137 (OS_OPT )OS_OPT_POST_1,
138 (OS_ERR *)&err);
139 }
140
141
142 U32 GUI_X_GetTaskId(void)
143 {
144 return ((U32)(OSTCBCurPtr->Prio));
145 }
146
147 /*
148 *********************************************************************************************************
149 * GUI_X_WaitEvent()
150 * GUI_X_SignalEvent()
151 *********************************************************************************************************
152 */
153
154
155 void GUI_X_WaitEvent(void)
156 {
157 OS_ERR err;
158 CPU_TS ts;
159
160 OSSemPend( (OS_SEM *)&eventSem,
161 (OS_TICK )0,
162 (OS_OPT )OS_OPT_PEND_BLOCKING,
163 (CPU_TS *)&ts,
164 (OS_ERR *)&err);
165 }
166
167
168 void GUI_X_SignalEvent(void)
169 {
170 OS_ERR err;
171
172 OSSemPost( (OS_SEM *)&eventSem,
173 (OS_OPT )OS_OPT_POST_1,
174 (OS_ERR *)&err);
175 }
176
177 /*
178 *********************************************************************************************************
179 * KEYBOARD INTERFACE FUNCTIONS
180 *
181 * Purpose: The keyboard routines are required only by some widgets.
182 * If widgets are not used, they may be eliminated.
183 *
184 * Note(s): If uC/OS-II is used, characters typed into the log window will be placed in the keyboard buffer.
185 * This is a neat feature which allows you to operate your target system without having to use or
186 * even to have a keyboard connected to it. (useful for demos !)
187 *********************************************************************************************************
188 */
189
190 static void CheckInit(void)
191 {
192 if(KeyIsInited==DEF_FALSE)
193 {
194 KeyIsInited = DEF_TRUE;
195 GUI_X_Init();
196 }
197 }
198
199
200 /*被GUI_Init()调用,用来初始化一些GUI运行之前需要用的硬件,如键盘或者鼠标之类的.如果不需要的话,可以为空*/
201 void GUI_X_Init(void)
202 {
203 OS_ERR err;
204
205 OSSemCreate( (OS_SEM *)&keySem,
206 (CPU_CHAR *)"keySem",
207 (OS_SEM_CTR )0,
208 (OS_ERR *)&err );
209 }
210
211
212 int GUI_X_GetKey(void)
213 {
214 int r;
215 r = KeyPressed;
216 CheckInit();
217 KeyPressed = 0;
218 return (r);
219 }
220
221
222 int GUI_X_WaitKey(void)
223 {
224 int r;
225 OS_ERR err;
226 CPU_TS ts;
227
228 CheckInit();
229 if(KeyPressed==0)
230 {
231 OSSemPend( (OS_SEM *)&keySem, //等待信号量
232 (OS_TICK )0,
233 (OS_OPT )OS_OPT_PEND_BLOCKING,
234 (CPU_TS *)&ts,
235 (OS_ERR *)&err);
236 }
237 r= KeyPressed;
238 KeyPressed = 0;
239 return (r);
240 }
241
242
243 void GUI_X_StoreKey(int k)
244 {
245 OS_ERR err;
246
247 KeyPressed = k;
248 OSSemPost( (OS_SEM *)&keySem, //释放信号量
249 (OS_OPT )OS_OPT_POST_1,
250 (OS_ERR *)&err);
251 }
252
253 void GUI_X_Log(const char *s)
254 {
255 GUI_USE_PARA(s);
256 }
257
258 void GUI_X_Warn(const char *s)
259 {
260 GUI_USE_PARA(s);
261 }
262
263 void GUI_X_ErrorOut(const char *s)
264 {
265 GUI_USE_PARA(s);
266 } |