source: UsbWattMeter/trunk/asp_dcre/kernel/eventflag.c@ 164

Last change on this file since 164 was 164, checked in by coas-nagasima, 6 years ago

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 13.8 KB
Line 
1/*
2 * TOPPERS/ASP Kernel
3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Advanced Standard Profile Kernel
5 *
6 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
8 * Copyright (C) 2005-2014 by Embedded and Real-Time Systems Laboratory
9 * Graduate School of Information Science, Nagoya Univ., JAPAN
10 *
11 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
12 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
13 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
14 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
15 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
16 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
17 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
18 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
19ƒƒ“ƒgi—˜—p
20 * ŽÒƒ}ƒjƒ…
21ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
22 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
23 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
24 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
25 * ‚ƁD
26 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
27ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
28ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
29 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
30 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
31 * •ñ‚·‚邱‚ƁD
32 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
33 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
34 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
35 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
36 * –Ɛӂ·‚邱‚ƁD
37 *
38 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
39 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
40 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
41 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
42 * ‚̐ӔC‚𕉂í‚È‚¢D
43 *
44 * @(#) $Id: eventflag.c 164 2016-03-07 11:33:50Z coas-nagasima $
45 */
46
47/*
48 * ƒCƒxƒ“ƒgƒtƒ‰ƒO‹@”\
49 */
50
51#include "kernel_impl.h"
52#include "check.h"
53#include "task.h"
54#include "wait.h"
55#include "eventflag.h"
56
57/*
58 * ƒgƒŒ[ƒXƒƒOƒ}ƒNƒ‚̃fƒtƒHƒ‹ƒg’è‹`
59 */
60#ifndef LOG_ACRE_FLG_ENTER
61#define LOG_ACRE_FLG_ENTER(pk_cflg)
62#endif /* LOG_ACRE_FLG_ENTER */
63
64#ifndef LOG_ACRE_FLG_LEAVE
65#define LOG_ACRE_FLG_LEAVE(ercd)
66#endif /* LOG_ACRE_FLG_LEAVE */
67
68#ifndef LOG_DEL_FLG_ENTER
69#define LOG_DEL_FLG_ENTER(flgid)
70#endif /* LOG_DEL_FLG_ENTER */
71
72#ifndef LOG_DEL_FLG_LEAVE
73#define LOG_DEL_FLG_LEAVE(ercd)
74#endif /* LOG_DEL_FLG_LEAVE */
75
76#ifndef LOG_SET_FLG_ENTER
77#define LOG_SET_FLG_ENTER(flgid, setptn)
78#endif /* LOG_SET_FLG_ENTER */
79
80#ifndef LOG_SET_FLG_LEAVE
81#define LOG_SET_FLG_LEAVE(ercd)
82#endif /* LOG_SET_FLG_LEAVE */
83
84#ifndef LOG_ISET_FLG_ENTER
85#define LOG_ISET_FLG_ENTER(flgid, setptn)
86#endif /* LOG_ISET_FLG_ENTER */
87
88#ifndef LOG_ISET_FLG_LEAVE
89#define LOG_ISET_FLG_LEAVE(ercd)
90#endif /* LOG_ISET_FLG_LEAVE */
91
92#ifndef LOG_CLR_FLG_ENTER
93#define LOG_CLR_FLG_ENTER(flgid, clrptn)
94#endif /* LOG_CLR_FLG_ENTER */
95
96#ifndef LOG_CLR_FLG_LEAVE
97#define LOG_CLR_FLG_LEAVE(ercd)
98#endif /* LOG_CLR_FLG_LEAVE */
99
100#ifndef LOG_WAI_FLG_ENTER
101#define LOG_WAI_FLG_ENTER(flgid, waiptn, wfmode, p_flgptn)
102#endif /* LOG_WAI_FLG_ENTER */
103
104#ifndef LOG_WAI_FLG_LEAVE
105#define LOG_WAI_FLG_LEAVE(ercd, flgptn)
106#endif /* LOG_WAI_FLG_LEAVE */
107
108#ifndef LOG_POL_FLG_ENTER
109#define LOG_POL_FLG_ENTER(flgid, waiptn, wfmode, p_flgptn)
110#endif /* LOG_POL_FLG_ENTER */
111
112#ifndef LOG_POL_FLG_LEAVE
113#define LOG_POL_FLG_LEAVE(ercd, flgptn)
114#endif /* LOG_POL_FLG_LEAVE */
115
116#ifndef LOG_TWAI_FLG_ENTER
117#define LOG_TWAI_FLG_ENTER(flgid, waiptn, wfmode, p_flgptn, tmout)
118#endif /* LOG_TWAI_FLG_ENTER */
119
120#ifndef LOG_TWAI_FLG_LEAVE
121#define LOG_TWAI_FLG_LEAVE(ercd, flgptn)
122#endif /* LOG_TWAI_FLG_LEAVE */
123
124#ifndef LOG_INI_FLG_ENTER
125#define LOG_INI_FLG_ENTER(flgid)
126#endif /* LOG_INI_FLG_ENTER */
127
128#ifndef LOG_INI_FLG_LEAVE
129#define LOG_INI_FLG_LEAVE(ercd)
130#endif /* LOG_INI_FLG_LEAVE */
131
132#ifndef LOG_REF_FLG_ENTER
133#define LOG_REF_FLG_ENTER(flgid, pk_rflg)
134#endif /* LOG_REF_FLG_ENTER */
135
136#ifndef LOG_REF_FLG_LEAVE
137#define LOG_REF_FLG_LEAVE(ercd, pk_rflg)
138#endif /* LOG_REF_FLG_LEAVE */
139
140/*
141 * ƒCƒxƒ“ƒgƒtƒ‰ƒO‚̐”
142 */
143#define tnum_flg ((uint_t)(tmax_flgid - TMIN_FLGID + 1))
144#define tnum_sflg ((uint_t)(tmax_sflgid - TMIN_FLGID + 1))
145
146/*
147 * ƒCƒxƒ“ƒgƒtƒ‰ƒOID‚©‚çƒCƒxƒ“ƒgƒtƒ‰ƒOŠÇ—ƒuƒƒbƒN‚ðŽæ‚èo‚·‚½‚߂̃}ƒNƒ
148 */
149#define INDEX_FLG(flgid) ((uint_t)((flgid) - TMIN_FLGID))
150#define get_flgcb(flgid) (&(flgcb_table[INDEX_FLG(flgid)]))
151
152#ifdef TOPPERS_flgini
153
154/*
155 * Žg—p‚µ‚Ä‚¢‚È‚¢ƒCƒxƒ“ƒgƒtƒ‰ƒOŠÇ—ƒuƒƒbƒN‚̃ŠƒXƒg
156 */
157QUEUE free_flgcb;
158
159/*
160 * ƒCƒxƒ“ƒgƒtƒ‰ƒO‹@”\‚̏‰Šú‰»
161 */
162void
163initialize_eventflag(void)
164{
165 uint_t i, j;
166 FLGCB *p_flgcb;
167 FLGINIB *p_flginib;
168
169 for (i = 0; i < tnum_sflg; i++) {
170 p_flgcb = &(flgcb_table[i]);
171 queue_initialize(&(p_flgcb->wait_queue));
172 p_flgcb->p_flginib = &(flginib_table[i]);
173 p_flgcb->flgptn = p_flgcb->p_flginib->iflgptn;
174 }
175 queue_initialize(&free_flgcb);
176 for (j = 0; i < tnum_flg; i++, j++) {
177 p_flgcb = &(flgcb_table[i]);
178 p_flginib = &(aflginib_table[j]);
179 p_flginib->flgatr = TA_NOEXS;
180 p_flgcb->p_flginib = ((const FLGINIB *) p_flginib);
181 queue_insert_prev(&free_flgcb, &(p_flgcb->wait_queue));
182 }
183}
184
185#endif /* TOPPERS_flgini */
186
187/*
188 * ƒCƒxƒ“ƒgƒtƒ‰ƒO‘Ò‚¿‰ðœðŒ‚̃`ƒFƒbƒN
189 */
190#ifdef TOPPERS_flgcnd
191
192bool_t
193check_flg_cond(FLGCB *p_flgcb, FLGPTN waiptn, MODE wfmode, FLGPTN *p_flgptn)
194{
195 if ((wfmode & TWF_ORW) != 0U ? (p_flgcb->flgptn & waiptn) != 0U
196 : (p_flgcb->flgptn & waiptn) == waiptn) {
197 *p_flgptn = p_flgcb->flgptn;
198 if ((p_flgcb->p_flginib->flgatr & TA_CLR) != 0U) {
199 p_flgcb->flgptn = 0U;
200 }
201 return(true);
202 }
203 return(false);
204}
205
206#endif /* TOPPERS_flgcnd */
207
208/*
209 * ƒCƒxƒ“ƒgƒtƒ‰ƒO‚̐¶¬
210 */
211#ifdef TOPPERS_acre_flg
212
213ER_UINT
214acre_flg(const T_CFLG *pk_cflg)
215{
216 FLGCB *p_flgcb;
217 FLGINIB *p_flginib;
218 ER ercd;
219
220 LOG_ACRE_FLG_ENTER(pk_cflg);
221 CHECK_TSKCTX_UNL();
222 CHECK_RSATR(pk_cflg->flgatr, TA_TPRI|TA_WMUL|TA_CLR);
223
224 t_lock_cpu();
225 if (tnum_flg == 0 || queue_empty(&free_flgcb)) {
226 ercd = E_NOID;
227 }
228 else {
229 p_flgcb = ((FLGCB *) queue_delete_next(&free_flgcb));
230 p_flginib = (FLGINIB *)(p_flgcb->p_flginib);
231 p_flginib->flgatr = pk_cflg->flgatr;
232 p_flginib->iflgptn = pk_cflg->iflgptn;
233
234 queue_initialize(&(p_flgcb->wait_queue));
235 p_flgcb->flgptn = p_flgcb->p_flginib->iflgptn;
236 ercd = FLGID(p_flgcb);
237 }
238 t_unlock_cpu();
239
240 error_exit:
241 LOG_ACRE_FLG_LEAVE(ercd);
242 return(ercd);
243}
244
245#endif /* TOPPERS_acre_flg */
246
247/*
248 * ƒCƒxƒ“ƒgƒtƒ‰ƒO‚̍폜
249 */
250#ifdef TOPPERS_del_flg
251
252ER
253del_flg(ID flgid)
254{
255 FLGCB *p_flgcb;
256 FLGINIB *p_flginib;
257 bool_t dspreq;
258 ER ercd;
259
260 LOG_DEL_FLG_ENTER(flgid);
261 CHECK_TSKCTX_UNL();
262 CHECK_FLGID(flgid);
263 p_flgcb = get_flgcb(flgid);
264
265 t_lock_cpu();
266 if (p_flgcb->p_flginib->flgatr == TA_NOEXS) {
267 ercd = E_NOEXS;
268 }
269 else if (FLGID(p_flgcb) > tmax_sflgid) {
270 dspreq = init_wait_queue(&(p_flgcb->wait_queue));
271 p_flginib = (FLGINIB *)(p_flgcb->p_flginib);
272 p_flginib->flgatr = TA_NOEXS;
273 queue_insert_prev(&free_flgcb, &(p_flgcb->wait_queue));
274 if (dspreq) {
275 dispatch();
276 }
277 ercd = E_OK;
278 }
279 else {
280 ercd = E_OBJ;
281 }
282 t_unlock_cpu();
283
284 error_exit:
285 LOG_DEL_FLG_LEAVE(ercd);
286 return(ercd);
287}
288
289#endif /* TOPPERS_del_flg */
290
291/*
292 * ƒCƒxƒ“ƒgƒtƒ‰ƒO‚̃Zƒbƒg
293 */
294#ifdef TOPPERS_set_flg
295
296ER
297set_flg(ID flgid, FLGPTN setptn)
298{
299 FLGCB *p_flgcb;
300 QUEUE *p_queue;
301 TCB *p_tcb;
302 WINFO_FLG *p_winfo_flg;
303 bool_t dspreq = false;
304 ER ercd;
305
306 LOG_SET_FLG_ENTER(flgid, setptn);
307 CHECK_TSKCTX_UNL();
308 CHECK_FLGID(flgid);
309 p_flgcb = get_flgcb(flgid);
310
311 t_lock_cpu();
312 if (p_flgcb->p_flginib->flgatr == TA_NOEXS) {
313 ercd = E_NOEXS;
314 }
315 else {
316 p_flgcb->flgptn |= setptn;
317 p_queue = p_flgcb->wait_queue.p_next;
318 while (p_queue != &(p_flgcb->wait_queue)) {
319 p_tcb = (TCB *) p_queue;
320 p_queue = p_queue->p_next;
321 p_winfo_flg = (WINFO_FLG *)(p_tcb->p_winfo);
322 if (check_flg_cond(p_flgcb, p_winfo_flg->waiptn,
323 p_winfo_flg->wfmode, &(p_winfo_flg->flgptn))) {
324 queue_delete(&(p_tcb->task_queue));
325 if (wait_complete(p_tcb)) {
326 dspreq = true;
327 }
328 if ((p_flgcb->p_flginib->flgatr & TA_CLR) != 0U) {
329 break;
330 }
331 }
332 }
333 if (dspreq) {
334 dispatch();
335 }
336 ercd = E_OK;
337 }
338 t_unlock_cpu();
339
340 error_exit:
341 LOG_SET_FLG_LEAVE(ercd);
342 return(ercd);
343}
344
345#endif /* TOPPERS_set_flg */
346
347/*
348 * ƒCƒxƒ“ƒgƒtƒ‰ƒO‚̃Zƒbƒgi”ñƒ^ƒXƒNƒRƒ“ƒeƒLƒXƒg—pj
349 */
350#ifdef TOPPERS_iset_flg
351
352ER
353iset_flg(ID flgid, FLGPTN setptn)
354{
355 FLGCB *p_flgcb;
356 QUEUE *p_queue;
357 TCB *p_tcb;
358 WINFO_FLG *p_winfo_flg;
359 ER ercd;
360
361 LOG_ISET_FLG_ENTER(flgid, setptn);
362 CHECK_INTCTX_UNL();
363 CHECK_FLGID(flgid);
364 p_flgcb = get_flgcb(flgid);
365
366 i_lock_cpu();
367 if (p_flgcb->p_flginib->flgatr == TA_NOEXS) {
368 ercd = E_NOEXS;
369 }
370 else {
371 p_flgcb->flgptn |= setptn;
372 p_queue = p_flgcb->wait_queue.p_next;
373 while (p_queue != &(p_flgcb->wait_queue)) {
374 p_tcb = (TCB *) p_queue;
375 p_queue = p_queue->p_next;
376 p_winfo_flg = (WINFO_FLG *)(p_tcb->p_winfo);
377 if (check_flg_cond(p_flgcb, p_winfo_flg->waiptn,
378 p_winfo_flg->wfmode, &(p_winfo_flg->flgptn))) {
379 queue_delete(&(p_tcb->task_queue));
380 if (wait_complete(p_tcb)) {
381 reqflg = true;
382 }
383 if ((p_flgcb->p_flginib->flgatr & TA_CLR) != 0U) {
384 break;
385 }
386 }
387 }
388 ercd = E_OK;
389 }
390 i_unlock_cpu();
391
392 error_exit:
393 LOG_ISET_FLG_LEAVE(ercd);
394 return(ercd);
395}
396
397#endif /* TOPPERS_iset_flg */
398
399/*
400 * ƒCƒxƒ“ƒgƒtƒ‰ƒO‚̃NƒŠƒA
401 */
402#ifdef TOPPERS_clr_flg
403
404ER
405clr_flg(ID flgid, FLGPTN clrptn)
406{
407 FLGCB *p_flgcb;
408 ER ercd;
409
410 LOG_CLR_FLG_ENTER(flgid, clrptn);
411 CHECK_TSKCTX_UNL();
412 CHECK_FLGID(flgid);
413 p_flgcb = get_flgcb(flgid);
414
415 t_lock_cpu();
416 if (p_flgcb->p_flginib->flgatr == TA_NOEXS) {
417 ercd = E_NOEXS;
418 }
419 else {
420 p_flgcb->flgptn &= clrptn;
421 ercd = E_OK;
422 }
423 t_unlock_cpu();
424
425 error_exit:
426 LOG_CLR_FLG_LEAVE(ercd);
427 return(ercd);
428}
429
430#endif /* TOPPERS_clr_flg */
431
432/*
433 * ƒCƒxƒ“ƒgƒtƒ‰ƒO‘Ò‚¿
434 */
435#ifdef TOPPERS_wai_flg
436
437ER
438wai_flg(ID flgid, FLGPTN waiptn, MODE wfmode, FLGPTN *p_flgptn)
439{
440 FLGCB *p_flgcb;
441 WINFO_FLG winfo_flg;
442 ER ercd;
443
444 LOG_WAI_FLG_ENTER(flgid, waiptn, wfmode, p_flgptn);
445 CHECK_DISPATCH();
446 CHECK_FLGID(flgid);
447 CHECK_PAR(waiptn != 0U);
448 CHECK_PAR(wfmode == TWF_ORW || wfmode == TWF_ANDW);
449 p_flgcb = get_flgcb(flgid);
450
451 t_lock_cpu();
452 if (p_flgcb->p_flginib->flgatr == TA_NOEXS) {
453 ercd = E_NOEXS;
454 }
455 else if ((p_flgcb->p_flginib->flgatr & TA_WMUL) == 0U
456 && !queue_empty(&(p_flgcb->wait_queue))) {
457 ercd = E_ILUSE;
458 }
459 else if (check_flg_cond(p_flgcb, waiptn, wfmode, p_flgptn)) {
460 ercd = E_OK;
461 }
462 else {
463 winfo_flg.waiptn = waiptn;
464 winfo_flg.wfmode = wfmode;
465 p_runtsk->tstat = (TS_WAITING | TS_WAIT_FLG);
466 wobj_make_wait((WOBJCB *) p_flgcb, (WINFO_WOBJ *) &winfo_flg);
467 dispatch();
468 ercd = winfo_flg.winfo.wercd;
469 if (ercd == E_OK) {
470 *p_flgptn = winfo_flg.flgptn;
471 }
472 }
473 t_unlock_cpu();
474
475 error_exit:
476 LOG_WAI_FLG_LEAVE(ercd, *p_flgptn);
477 return(ercd);
478}
479
480#endif /* TOPPERS_wai_flg */
481
482/*
483 * ƒCƒxƒ“ƒgƒtƒ‰ƒO‘Ò‚¿iƒ|[ƒŠƒ“ƒOj
484 */
485#ifdef TOPPERS_pol_flg
486
487ER
488pol_flg(ID flgid, FLGPTN waiptn, MODE wfmode, FLGPTN *p_flgptn)
489{
490 FLGCB *p_flgcb;
491 ER ercd;
492
493 LOG_POL_FLG_ENTER(flgid, waiptn, wfmode, p_flgptn);
494 CHECK_TSKCTX_UNL();
495 CHECK_FLGID(flgid);
496 CHECK_PAR(waiptn != 0U);
497 CHECK_PAR(wfmode == TWF_ORW || wfmode == TWF_ANDW);
498 p_flgcb = get_flgcb(flgid);
499
500 t_lock_cpu();
501 if (p_flgcb->p_flginib->flgatr == TA_NOEXS) {
502 ercd = E_NOEXS;
503 }
504 else if ((p_flgcb->p_flginib->flgatr & TA_WMUL) == 0U
505 && !queue_empty(&(p_flgcb->wait_queue))) {
506 ercd = E_ILUSE;
507 }
508 else if (check_flg_cond(p_flgcb, waiptn, wfmode, p_flgptn)) {
509 ercd = E_OK;
510 }
511 else {
512 ercd = E_TMOUT;
513 }
514 t_unlock_cpu();
515
516 error_exit:
517 LOG_POL_FLG_LEAVE(ercd, *p_flgptn);
518 return(ercd);
519}
520
521#endif /* TOPPERS_pol_flg */
522
523/*
524 * ƒCƒxƒ“ƒgƒtƒ‰ƒO‘Ò‚¿iƒ^ƒCƒ€ƒAƒEƒg‚ ‚èj
525 */
526#ifdef TOPPERS_twai_flg
527
528ER
529twai_flg(ID flgid, FLGPTN waiptn, MODE wfmode, FLGPTN *p_flgptn, TMO tmout)
530{
531 FLGCB *p_flgcb;
532 WINFO_FLG winfo_flg;
533 TMEVTB tmevtb;
534 ER ercd;
535
536 LOG_TWAI_FLG_ENTER(flgid, waiptn, wfmode, p_flgptn, tmout);
537 CHECK_DISPATCH();
538 CHECK_FLGID(flgid);
539 CHECK_PAR(waiptn != 0U);
540 CHECK_PAR(wfmode == TWF_ORW || wfmode == TWF_ANDW);
541 CHECK_TMOUT(tmout);
542 p_flgcb = get_flgcb(flgid);
543
544 t_lock_cpu();
545 if (p_flgcb->p_flginib->flgatr == TA_NOEXS) {
546 ercd = E_NOEXS;
547 }
548 else if ((p_flgcb->p_flginib->flgatr & TA_WMUL) == 0U
549 && !queue_empty(&(p_flgcb->wait_queue))) {
550 ercd = E_ILUSE;
551 }
552 else if (check_flg_cond(p_flgcb, waiptn, wfmode, p_flgptn)) {
553 ercd = E_OK;
554 }
555 else if (tmout == TMO_POL) {
556 ercd = E_TMOUT;
557 }
558 else {
559 winfo_flg.waiptn = waiptn;
560 winfo_flg.wfmode = wfmode;
561 p_runtsk->tstat = (TS_WAITING | TS_WAIT_FLG);
562 wobj_make_wait_tmout((WOBJCB *) p_flgcb, (WINFO_WOBJ *) &winfo_flg,
563 &tmevtb, tmout);
564 dispatch();
565 ercd = winfo_flg.winfo.wercd;
566 if (ercd == E_OK) {
567 *p_flgptn = winfo_flg.flgptn;
568 }
569 }
570 t_unlock_cpu();
571
572 error_exit:
573 LOG_TWAI_FLG_LEAVE(ercd, *p_flgptn);
574 return(ercd);
575}
576
577#endif /* TOPPERS_twai_flg */
578
579/*
580 * ƒCƒxƒ“ƒgƒtƒ‰ƒO‚̍ú‰»
581 */
582#ifdef TOPPERS_ini_flg
583
584ER
585ini_flg(ID flgid)
586{
587 FLGCB *p_flgcb;
588 bool_t dspreq;
589 ER ercd;
590
591 LOG_INI_FLG_ENTER(flgid);
592 CHECK_TSKCTX_UNL();
593 CHECK_FLGID(flgid);
594 p_flgcb = get_flgcb(flgid);
595
596 t_lock_cpu();
597 if (p_flgcb->p_flginib->flgatr == TA_NOEXS) {
598 ercd = E_NOEXS;
599 }
600 else {
601 dspreq = init_wait_queue(&(p_flgcb->wait_queue));
602 p_flgcb->flgptn = p_flgcb->p_flginib->iflgptn;
603 if (dspreq) {
604 dispatch();
605 }
606 ercd = E_OK;
607 }
608 t_unlock_cpu();
609
610 error_exit:
611 LOG_INI_FLG_LEAVE(ercd);
612 return(ercd);
613}
614
615#endif /* TOPPERS_ini_flg */
616
617/*
618 * ƒCƒxƒ“ƒgƒtƒ‰ƒO‚̏ó‘ÔŽQÆ
619 */
620#ifdef TOPPERS_ref_flg
621
622ER
623ref_flg(ID flgid, T_RFLG *pk_rflg)
624{
625 FLGCB *p_flgcb;
626 ER ercd;
627
628 LOG_REF_FLG_ENTER(flgid, pk_rflg);
629 CHECK_TSKCTX_UNL();
630 CHECK_FLGID(flgid);
631 p_flgcb = get_flgcb(flgid);
632
633 t_lock_cpu();
634 if (p_flgcb->p_flginib->flgatr == TA_NOEXS) {
635 ercd = E_NOEXS;
636 }
637 else {
638 pk_rflg->wtskid = wait_tskid(&(p_flgcb->wait_queue));
639 pk_rflg->flgptn = p_flgcb->flgptn;
640 ercd = E_OK;
641 }
642 t_unlock_cpu();
643
644 error_exit:
645 LOG_REF_FLG_LEAVE(ercd, pk_rflg);
646 return(ercd);
647}
648
649#endif /* TOPPERS_ref_flg */
Note: See TracBrowser for help on using the repository browser.