source: UsbWattMeter/trunk/asp_dcre/kernel/dataqueue.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: 18.4 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: dataqueue.c 164 2016-03-07 11:33:50Z coas-nagasima $
45 */
46
47/*
48 * ƒf[ƒ^ƒLƒ…
49[‹@”\
50 */
51
52#include "kernel_impl.h"
53#include "check.h"
54#include "task.h"
55#include "wait.h"
56#include "dataqueue.h"
57
58/*
59 * ƒgƒŒ[ƒXƒƒOƒ}ƒNƒ‚̃fƒtƒHƒ‹ƒg’è‹`
60 */
61#ifndef LOG_ACRE_DTQ_ENTER
62#define LOG_ACRE_DTQ_ENTER(pk_cdtq)
63#endif /* LOG_ACRE_DTQ_ENTER */
64
65#ifndef LOG_ACRE_DTQ_LEAVE
66#define LOG_ACRE_DTQ_LEAVE(ercd)
67#endif /* LOG_ACRE_DTQ_LEAVE */
68
69#ifndef LOG_DEL_DTQ_ENTER
70#define LOG_DEL_DTQ_ENTER(dtqid)
71#endif /* LOG_DEL_DTQ_ENTER */
72
73#ifndef LOG_DEL_DTQ_LEAVE
74#define LOG_DEL_DTQ_LEAVE(ercd)
75#endif /* LOG_DEL_DTQ_LEAVE */
76
77#ifndef LOG_SND_DTQ_ENTER
78#define LOG_SND_DTQ_ENTER(dtqid, data)
79#endif /* LOG_SND_DTQ_ENTER */
80
81#ifndef LOG_SND_DTQ_LEAVE
82#define LOG_SND_DTQ_LEAVE(ercd)
83#endif /* LOG_SND_DTQ_LEAVE */
84
85#ifndef LOG_PSND_DTQ_ENTER
86#define LOG_PSND_DTQ_ENTER(dtqid, data)
87#endif /* LOG_PSND_DTQ_ENTER */
88
89#ifndef LOG_PSND_DTQ_LEAVE
90#define LOG_PSND_DTQ_LEAVE(ercd)
91#endif /* LOG_PSND_DTQ_LEAVE */
92
93#ifndef LOG_IPSND_DTQ_ENTER
94#define LOG_IPSND_DTQ_ENTER(dtqid, data)
95#endif /* LOG_IPSND_DTQ_ENTER */
96
97#ifndef LOG_IPSND_DTQ_LEAVE
98#define LOG_IPSND_DTQ_LEAVE(ercd)
99#endif /* LOG_IPSND_DTQ_LEAVE */
100
101#ifndef LOG_TSND_DTQ_ENTER
102#define LOG_TSND_DTQ_ENTER(dtqid, data, tmout)
103#endif /* LOG_TSND_DTQ_ENTER */
104
105#ifndef LOG_TSND_DTQ_LEAVE
106#define LOG_TSND_DTQ_LEAVE(ercd)
107#endif /* LOG_TSND_DTQ_LEAVE */
108
109#ifndef LOG_FSND_DTQ_ENTER
110#define LOG_FSND_DTQ_ENTER(dtqid, data)
111#endif /* LOG_FSND_DTQ_ENTER */
112
113#ifndef LOG_FSND_DTQ_LEAVE
114#define LOG_FSND_DTQ_LEAVE(ercd)
115#endif /* LOG_FSND_DTQ_LEAVE */
116
117#ifndef LOG_IFSND_DTQ_ENTER
118#define LOG_IFSND_DTQ_ENTER(dtqid, data)
119#endif /* LOG_IFSND_DTQ_ENTER */
120
121#ifndef LOG_IFSND_DTQ_LEAVE
122#define LOG_IFSND_DTQ_LEAVE(ercd)
123#endif /* LOG_IFSND_DTQ_LEAVE */
124
125#ifndef LOG_RCV_DTQ_ENTER
126#define LOG_RCV_DTQ_ENTER(dtqid, p_data)
127#endif /* LOG_RCV_DTQ_ENTER */
128
129#ifndef LOG_RCV_DTQ_LEAVE
130#define LOG_RCV_DTQ_LEAVE(ercd, data)
131#endif /* LOG_RCV_DTQ_LEAVE */
132
133#ifndef LOG_PRCV_DTQ_ENTER
134#define LOG_PRCV_DTQ_ENTER(dtqid, p_data)
135#endif /* LOG_PRCV_DTQ_ENTER */
136
137#ifndef LOG_PRCV_DTQ_LEAVE
138#define LOG_PRCV_DTQ_LEAVE(ercd, data)
139#endif /* LOG_PRCV_DTQ_LEAVE */
140
141#ifndef LOG_TRCV_DTQ_ENTER
142#define LOG_TRCV_DTQ_ENTER(dtqid, p_data, tmout)
143#endif /* LOG_TRCV_DTQ_ENTER */
144
145#ifndef LOG_TRCV_DTQ_LEAVE
146#define LOG_TRCV_DTQ_LEAVE(ercd, data)
147#endif /* LOG_TRCV_DTQ_LEAVE */
148
149#ifndef LOG_INI_DTQ_ENTER
150#define LOG_INI_DTQ_ENTER(dtqid)
151#endif /* LOG_INI_DTQ_ENTER */
152
153#ifndef LOG_INI_DTQ_LEAVE
154#define LOG_INI_DTQ_LEAVE(ercd)
155#endif /* LOG_INI_DTQ_LEAVE */
156
157#ifndef LOG_REF_DTQ_ENTER
158#define LOG_REF_DTQ_ENTER(dtqid, pk_rdtq)
159#endif /* LOG_REF_DTQ_ENTER */
160
161#ifndef LOG_REF_DTQ_LEAVE
162#define LOG_REF_DTQ_LEAVE(ercd, pk_rdtq)
163#endif /* LOG_REF_DTQ_LEAVE */
164
165/*
166 * ƒf[ƒ^ƒLƒ…
167[‚̐”
168 */
169#define tnum_dtq ((uint_t)(tmax_dtqid - TMIN_DTQID + 1))
170#define tnum_sdtq ((uint_t)(tmax_sdtqid - TMIN_DTQID + 1))
171
172/*
173 * ƒf[ƒ^ƒLƒ…
174[ID‚©‚çƒf[ƒ^ƒLƒ…
175[ŠÇ—ƒuƒƒbƒN‚ðŽæ‚èo‚·‚½‚߂̃}ƒNƒ
176 */
177#define INDEX_DTQ(dtqid) ((uint_t)((dtqid) - TMIN_DTQID))
178#define get_dtqcb(dtqid) (&(dtqcb_table[INDEX_DTQ(dtqid)]))
179
180#ifdef TOPPERS_dtqini
181
182/*
183 * Žg—p‚µ‚Ä‚¢‚È‚¢ƒf[ƒ^ƒLƒ…
184[ŠÇ—ƒuƒƒbƒN‚̃ŠƒXƒg
185 */
186QUEUE free_dtqcb;
187
188/*
189 * ƒf[ƒ^ƒLƒ…
190[‹@”\‚̏‰Šú‰»
191 */
192void
193initialize_dataqueue(void)
194{
195 uint_t i, j;
196 DTQCB *p_dtqcb;
197 DTQINIB *p_dtqinib;
198
199 for (i = 0; i < tnum_sdtq; i++) {
200 p_dtqcb = &(dtqcb_table[i]);
201 queue_initialize(&(p_dtqcb->swait_queue));
202 p_dtqcb->p_dtqinib = &(dtqinib_table[i]);
203 queue_initialize(&(p_dtqcb->rwait_queue));
204 p_dtqcb->count = 0U;
205 p_dtqcb->head = 0U;
206 p_dtqcb->tail = 0U;
207 }
208 queue_initialize(&free_dtqcb);
209 for (j = 0; i < tnum_dtq; i++, j++) {
210 p_dtqcb = &(dtqcb_table[i]);
211 p_dtqinib = &(adtqinib_table[j]);
212 p_dtqinib->dtqatr = TA_NOEXS;
213 p_dtqcb->p_dtqinib = ((const DTQINIB *) p_dtqinib);
214 queue_insert_prev(&free_dtqcb, &(p_dtqcb->swait_queue));
215 }
216}
217
218#endif /* TOPPERS_dtqini */
219
220/*
221 * ƒf[ƒ^ƒLƒ…
222[ŠÇ——̈æ‚ւ̃f[ƒ^‚ÌŠi”[
223 */
224#ifdef TOPPERS_dtqenq
225
226void
227enqueue_data(DTQCB *p_dtqcb, intptr_t data)
228{
229 (p_dtqcb->p_dtqinib->p_dtqmb + p_dtqcb->tail)->data = data;
230 p_dtqcb->count++;
231 p_dtqcb->tail++;
232 if (p_dtqcb->tail >= p_dtqcb->p_dtqinib->dtqcnt) {
233 p_dtqcb->tail = 0U;
234 }
235}
236
237#endif /* TOPPERS_dtqenq */
238
239/*
240 * ƒf[ƒ^ƒLƒ…
241[ŠÇ——̈æ‚ւ̃f[ƒ^‚Ì‹­§Ši”[
242 */
243#ifdef TOPPERS_dtqfenq
244
245void
246force_enqueue_data(DTQCB *p_dtqcb, intptr_t data)
247{
248 (p_dtqcb->p_dtqinib->p_dtqmb + p_dtqcb->tail)->data = data;
249 p_dtqcb->tail++;
250 if (p_dtqcb->tail >= p_dtqcb->p_dtqinib->dtqcnt) {
251 p_dtqcb->tail = 0U;
252 }
253 if (p_dtqcb->count < p_dtqcb->p_dtqinib->dtqcnt) {
254 p_dtqcb->count++;
255 }
256 else {
257 p_dtqcb->head = p_dtqcb->tail;
258 }
259}
260
261#endif /* TOPPERS_dtqfenq */
262
263/*
264 * ƒf[ƒ^ƒLƒ…
265[ŠÇ——̈悩‚ç‚̃f[ƒ^‚ÌŽæo‚µ
266 */
267#ifdef TOPPERS_dtqdeq
268
269void
270dequeue_data(DTQCB *p_dtqcb, intptr_t *p_data)
271{
272 *p_data = (p_dtqcb->p_dtqinib->p_dtqmb + p_dtqcb->head)->data;
273 p_dtqcb->count--;
274 p_dtqcb->head++;
275 if (p_dtqcb->head >= p_dtqcb->p_dtqinib->dtqcnt) {
276 p_dtqcb->head = 0U;
277 }
278}
279
280#endif /* TOPPERS_dtqdeq */
281
282/*
283 * ƒf[ƒ^ƒLƒ…
284[‚ւ̃f[ƒ^‘—M
285 */
286#ifdef TOPPERS_dtqsnd
287
288bool_t
289send_data(DTQCB *p_dtqcb, intptr_t data, bool_t *p_dspreq)
290{
291 TCB *p_tcb;
292
293 if (!queue_empty(&(p_dtqcb->rwait_queue))) {
294 p_tcb = (TCB *) queue_delete_next(&(p_dtqcb->rwait_queue));
295 ((WINFO_DTQ *)(p_tcb->p_winfo))->data = data;
296 *p_dspreq = wait_complete(p_tcb);
297 return(true);
298 }
299 else if (p_dtqcb->count < p_dtqcb->p_dtqinib->dtqcnt) {
300 enqueue_data(p_dtqcb, data);
301 *p_dspreq = false;
302 return(true);
303 }
304 else {
305 return(false);
306 }
307}
308
309#endif /* TOPPERS_dtqsnd */
310
311/*
312 * ƒf[ƒ^ƒLƒ…
313[‚ւ̃f[ƒ^‹­§‘—M
314 */
315#ifdef TOPPERS_dtqfsnd
316
317bool_t
318force_send_data(DTQCB *p_dtqcb, intptr_t data)
319{
320 TCB *p_tcb;
321
322 if (!queue_empty(&(p_dtqcb->rwait_queue))) {
323 p_tcb = (TCB *) queue_delete_next(&(p_dtqcb->rwait_queue));
324 ((WINFO_DTQ *)(p_tcb->p_winfo))->data = data;
325 return(wait_complete(p_tcb));
326 }
327 else {
328 force_enqueue_data(p_dtqcb, data);
329 return(false);
330 }
331}
332
333#endif /* TOPPERS_dtqfsnd */
334
335/*
336 * ƒf[ƒ^ƒLƒ…
337[‚©‚ç‚̃f[ƒ^ŽóM
338 */
339#ifdef TOPPERS_dtqrcv
340
341bool_t
342receive_data(DTQCB *p_dtqcb, intptr_t *p_data, bool_t *p_dspreq)
343{
344 TCB *p_tcb;
345 intptr_t data;
346
347 if (p_dtqcb->count > 0U) {
348 dequeue_data(p_dtqcb, p_data);
349 if (!queue_empty(&(p_dtqcb->swait_queue))) {
350 p_tcb = (TCB *) queue_delete_next(&(p_dtqcb->swait_queue));
351 data = ((WINFO_DTQ *)(p_tcb->p_winfo))->data;
352 enqueue_data(p_dtqcb, data);
353 *p_dspreq = wait_complete(p_tcb);
354 }
355 else {
356 *p_dspreq = false;
357 }
358 return(true);
359 }
360 else if (!queue_empty(&(p_dtqcb->swait_queue))) {
361 p_tcb = (TCB *) queue_delete_next(&(p_dtqcb->swait_queue));
362 *p_data = ((WINFO_DTQ *)(p_tcb->p_winfo))->data;
363 *p_dspreq = wait_complete(p_tcb);
364 return(true);
365 }
366 else {
367 return(false);
368 }
369}
370
371#endif /* TOPPERS_dtqrcv */
372
373/*
374 * ƒf[ƒ^ƒLƒ…
375[‚̐¶¬
376 */
377#ifdef TOPPERS_acre_dtq
378
379ER_UINT
380acre_dtq(const T_CDTQ *pk_cdtq)
381{
382 DTQCB *p_dtqcb;
383 DTQINIB *p_dtqinib;
384 ATR dtqatr;
385 DTQMB *p_dtqmb;
386 ER ercd;
387
388 LOG_ACRE_DTQ_ENTER(pk_cdtq);
389 CHECK_TSKCTX_UNL();
390 CHECK_RSATR(pk_cdtq->dtqatr, TA_TPRI);
391 if (pk_cdtq->dtqmb != NULL) {
392 CHECK_ALIGN_MB(pk_cdtq->dtqmb);
393 }
394 dtqatr = pk_cdtq->dtqatr;
395 p_dtqmb = pk_cdtq->dtqmb;
396
397 t_lock_cpu();
398 if (tnum_dtq == 0 || queue_empty(&free_dtqcb)) {
399 ercd = E_NOID;
400 }
401 else {
402 if (pk_cdtq->dtqcnt != 0 && p_dtqmb == NULL) {
403 p_dtqmb = kernel_malloc(sizeof(DTQMB) * pk_cdtq->dtqcnt);
404 dtqatr |= TA_MBALLOC;
405 }
406 if (pk_cdtq->dtqcnt != 0 && p_dtqmb == NULL) {
407 ercd = E_NOMEM;
408 }
409 else {
410 p_dtqcb = ((DTQCB *) queue_delete_next(&free_dtqcb));
411 p_dtqinib = (DTQINIB *)(p_dtqcb->p_dtqinib);
412 p_dtqinib->dtqatr = dtqatr;
413 p_dtqinib->dtqcnt = pk_cdtq->dtqcnt;
414 p_dtqinib->p_dtqmb = p_dtqmb;
415
416 queue_initialize(&(p_dtqcb->swait_queue));
417 queue_initialize(&(p_dtqcb->rwait_queue));
418 p_dtqcb->count = 0U;
419 p_dtqcb->head = 0U;
420 p_dtqcb->tail = 0U;
421 ercd = DTQID(p_dtqcb);
422 }
423 }
424 t_unlock_cpu();
425
426 error_exit:
427 LOG_ACRE_DTQ_LEAVE(ercd);
428 return(ercd);
429}
430
431#endif /* TOPPERS_acre_dtq */
432
433/*
434 * ƒf[ƒ^ƒLƒ…
435[‚̍폜
436 */
437#ifdef TOPPERS_del_dtq
438
439ER
440del_dtq(ID dtqid)
441{
442 DTQCB *p_dtqcb;
443 DTQINIB *p_dtqinib;
444 bool_t dspreq;
445 ER ercd;
446
447 LOG_DEL_DTQ_ENTER(dtqid);
448 CHECK_TSKCTX_UNL();
449 CHECK_DTQID(dtqid);
450 p_dtqcb = get_dtqcb(dtqid);
451
452 t_lock_cpu();
453 if (p_dtqcb->p_dtqinib->dtqatr == TA_NOEXS) {
454 ercd = E_NOEXS;
455 }
456 else if (DTQID(p_dtqcb) > tmax_sdtqid) {
457 dspreq = init_wait_queue(&(p_dtqcb->swait_queue));
458 if (init_wait_queue(&(p_dtqcb->rwait_queue))) {
459 dspreq = true;
460 }
461 p_dtqinib = (DTQINIB *)(p_dtqcb->p_dtqinib);
462 if ((p_dtqinib->dtqatr & TA_MBALLOC) != 0U) {
463 kernel_free(p_dtqinib->p_dtqmb);
464 }
465 p_dtqinib->dtqatr = TA_NOEXS;
466 queue_insert_prev(&free_dtqcb, &(p_dtqcb->swait_queue));
467 if (dspreq) {
468 dispatch();
469 }
470 ercd = E_OK;
471 }
472 else {
473 ercd = E_OBJ;
474 }
475 t_unlock_cpu();
476
477 error_exit:
478 LOG_DEL_DTQ_LEAVE(ercd);
479 return(ercd);
480}
481
482#endif /* TOPPERS_del_dtq */
483
484/*
485 * ƒf[ƒ^ƒLƒ…
486[‚Ö‚Ì‘—M
487 */
488#ifdef TOPPERS_snd_dtq
489
490ER
491snd_dtq(ID dtqid, intptr_t data)
492{
493 DTQCB *p_dtqcb;
494 WINFO_DTQ winfo_dtq;
495 bool_t dspreq;
496 ER ercd;
497
498 LOG_SND_DTQ_ENTER(dtqid, data);
499 CHECK_DISPATCH();
500 CHECK_DTQID(dtqid);
501 p_dtqcb = get_dtqcb(dtqid);
502
503 t_lock_cpu();
504 if (p_dtqcb->p_dtqinib->dtqatr == TA_NOEXS) {
505 ercd = E_NOEXS;
506 }
507 else if (send_data(p_dtqcb, data, &dspreq)) {
508 if (dspreq) {
509 dispatch();
510 }
511 ercd = E_OK;
512 }
513 else {
514 winfo_dtq.data = data;
515 p_runtsk->tstat = (TS_WAITING | TS_WAIT_SDTQ);
516 wobj_make_wait((WOBJCB *) p_dtqcb, (WINFO_WOBJ *) &winfo_dtq);
517 dispatch();
518 ercd = winfo_dtq.winfo.wercd;
519 }
520 t_unlock_cpu();
521
522 error_exit:
523 LOG_SND_DTQ_LEAVE(ercd);
524 return(ercd);
525}
526
527#endif /* TOPPERS_snd_dtq */
528
529/*
530 * ƒf[ƒ^ƒLƒ…
531[‚Ö‚Ì‘—Miƒ|[ƒŠƒ“ƒOj
532 */
533#ifdef TOPPERS_psnd_dtq
534
535ER
536psnd_dtq(ID dtqid, intptr_t data)
537{
538 DTQCB *p_dtqcb;
539 bool_t dspreq;
540 ER ercd;
541
542 LOG_PSND_DTQ_ENTER(dtqid, data);
543 CHECK_TSKCTX_UNL();
544 CHECK_DTQID(dtqid);
545 p_dtqcb = get_dtqcb(dtqid);
546
547 t_lock_cpu();
548 if (p_dtqcb->p_dtqinib->dtqatr == TA_NOEXS) {
549 ercd = E_NOEXS;
550 }
551 else if (send_data(p_dtqcb, data, &dspreq)) {
552 if (dspreq) {
553 dispatch();
554 }
555 ercd = E_OK;
556 }
557 else {
558 ercd = E_TMOUT;
559 }
560 t_unlock_cpu();
561
562 error_exit:
563 LOG_PSND_DTQ_LEAVE(ercd);
564 return(ercd);
565}
566
567#endif /* TOPPERS_psnd_dtq */
568
569/*
570 * ƒf[ƒ^ƒLƒ…
571[‚Ö‚Ì‘—Miƒ|[ƒŠƒ“ƒOC”ñƒ^ƒXƒNƒRƒ“ƒeƒLƒXƒg—pj
572 */
573#ifdef TOPPERS_ipsnd_dtq
574
575ER
576ipsnd_dtq(ID dtqid, intptr_t data)
577{
578 DTQCB *p_dtqcb;
579 bool_t dspreq;
580 ER ercd;
581
582 LOG_IPSND_DTQ_ENTER(dtqid, data);
583 CHECK_INTCTX_UNL();
584 CHECK_DTQID(dtqid);
585 p_dtqcb = get_dtqcb(dtqid);
586
587 i_lock_cpu();
588 if (p_dtqcb->p_dtqinib->dtqatr == TA_NOEXS) {
589 ercd = E_NOEXS;
590 }
591 else if (send_data(p_dtqcb, data, &dspreq)) {
592 if (dspreq) {
593 reqflg = true;
594 }
595 ercd = E_OK;
596 }
597 else {
598 ercd = E_TMOUT;
599 }
600 i_unlock_cpu();
601
602 error_exit:
603 LOG_IPSND_DTQ_LEAVE(ercd);
604 return(ercd);
605}
606
607#endif /* TOPPERS_ipsnd_dtq */
608
609/*
610 * ƒf[ƒ^ƒLƒ…
611[‚Ö‚Ì‘—Miƒ^ƒCƒ€ƒAƒEƒg‚ ‚èj
612 */
613#ifdef TOPPERS_tsnd_dtq
614
615ER
616tsnd_dtq(ID dtqid, intptr_t data, TMO tmout)
617{
618 DTQCB *p_dtqcb;
619 WINFO_DTQ winfo_dtq;
620 TMEVTB tmevtb;
621 bool_t dspreq;
622 ER ercd;
623
624 LOG_TSND_DTQ_ENTER(dtqid, data, tmout);
625 CHECK_DISPATCH();
626 CHECK_DTQID(dtqid);
627 CHECK_TMOUT(tmout);
628 p_dtqcb = get_dtqcb(dtqid);
629
630 t_lock_cpu();
631 if (p_dtqcb->p_dtqinib->dtqatr == TA_NOEXS) {
632 ercd = E_NOEXS;
633 }
634 else if (send_data(p_dtqcb, data, &dspreq)) {
635 if (dspreq) {
636 dispatch();
637 }
638 ercd = E_OK;
639 }
640 else if (tmout == TMO_POL) {
641 ercd = E_TMOUT;
642 }
643 else {
644 winfo_dtq.data = data;
645 p_runtsk->tstat = (TS_WAITING | TS_WAIT_SDTQ);
646 wobj_make_wait_tmout((WOBJCB *) p_dtqcb, (WINFO_WOBJ *) &winfo_dtq,
647 &tmevtb, tmout);
648 dispatch();
649 ercd = winfo_dtq.winfo.wercd;
650 }
651 t_unlock_cpu();
652
653 error_exit:
654 LOG_TSND_DTQ_LEAVE(ercd);
655 return(ercd);
656}
657
658#endif /* TOPPERS_tsnd_dtq */
659
660/*
661 * ƒf[ƒ^ƒLƒ…
662[‚Ö‚Ì‹­§‘—M
663 */
664#ifdef TOPPERS_fsnd_dtq
665
666ER
667fsnd_dtq(ID dtqid, intptr_t data)
668{
669 DTQCB *p_dtqcb;
670 ER ercd;
671
672 LOG_FSND_DTQ_ENTER(dtqid, data);
673 CHECK_TSKCTX_UNL();
674 CHECK_DTQID(dtqid);
675 p_dtqcb = get_dtqcb(dtqid);
676
677 t_lock_cpu();
678 if (p_dtqcb->p_dtqinib->dtqatr == TA_NOEXS) {
679 ercd = E_NOEXS;
680 }
681 else if (!(p_dtqcb->p_dtqinib->dtqcnt > 0U)) {
682 ercd = E_ILUSE;
683 }
684 else if (force_send_data(p_dtqcb, data)) {
685 dispatch();
686 }
687 ercd = E_OK;
688 t_unlock_cpu();
689
690 error_exit:
691 LOG_FSND_DTQ_LEAVE(ercd);
692 return(ercd);
693}
694
695#endif /* TOPPERS_fsnd_dtq */
696
697/*
698 * ƒf[ƒ^ƒLƒ…
699[‚Ö‚Ì‹­§‘—Mi”ñƒ^ƒXƒNƒRƒ“ƒeƒLƒXƒg—pj
700 */
701#ifdef TOPPERS_ifsnd_dtq
702
703ER
704ifsnd_dtq(ID dtqid, intptr_t data)
705{
706 DTQCB *p_dtqcb;
707 ER ercd;
708
709 LOG_IFSND_DTQ_ENTER(dtqid, data);
710 CHECK_INTCTX_UNL();
711 CHECK_DTQID(dtqid);
712 p_dtqcb = get_dtqcb(dtqid);
713
714 i_lock_cpu();
715 if (p_dtqcb->p_dtqinib->dtqatr == TA_NOEXS) {
716 ercd = E_NOEXS;
717 }
718 else if (!(p_dtqcb->p_dtqinib->dtqcnt > 0U)) {
719 ercd = E_ILUSE;
720 }
721 else if (force_send_data(p_dtqcb, data)) {
722 reqflg = true;
723 }
724 ercd = E_OK;
725 i_unlock_cpu();
726
727 error_exit:
728 LOG_IFSND_DTQ_LEAVE(ercd);
729 return(ercd);
730}
731
732#endif /* TOPPERS_ifsnd_dtq */
733
734/*
735 * ƒf[ƒ^ƒLƒ…
736[‚©‚ç‚ÌŽóM
737 */
738#ifdef TOPPERS_rcv_dtq
739
740ER
741rcv_dtq(ID dtqid, intptr_t *p_data)
742{
743 DTQCB *p_dtqcb;
744 WINFO_DTQ winfo_dtq;
745 bool_t dspreq;
746 ER ercd;
747
748 LOG_RCV_DTQ_ENTER(dtqid, p_data);
749 CHECK_DISPATCH();
750 CHECK_DTQID(dtqid);
751 p_dtqcb = get_dtqcb(dtqid);
752
753 t_lock_cpu();
754 if (p_dtqcb->p_dtqinib->dtqatr == TA_NOEXS) {
755 ercd = E_NOEXS;
756 }
757 else if (receive_data(p_dtqcb, p_data, &dspreq)) {
758 if (dspreq) {
759 dispatch();
760 }
761 ercd = E_OK;
762 }
763 else {
764 p_runtsk->tstat = (TS_WAITING | TS_WAIT_RDTQ);
765 make_wait(&(winfo_dtq.winfo));
766 queue_insert_prev(&(p_dtqcb->rwait_queue), &(p_runtsk->task_queue));
767 winfo_dtq.p_dtqcb = p_dtqcb;
768 LOG_TSKSTAT(p_runtsk);
769 dispatch();
770 ercd = winfo_dtq.winfo.wercd;
771 if (ercd == E_OK) {
772 *p_data = winfo_dtq.data;
773 }
774 }
775 t_unlock_cpu();
776
777 error_exit:
778 LOG_RCV_DTQ_LEAVE(ercd, *p_data);
779 return(ercd);
780}
781
782#endif /* TOPPERS_rcv_dtq */
783
784/*
785 * ƒf[ƒ^ƒLƒ…
786[‚©‚ç‚ÌŽóMiƒ|[ƒŠƒ“ƒOj
787 */
788#ifdef TOPPERS_prcv_dtq
789
790ER
791prcv_dtq(ID dtqid, intptr_t *p_data)
792{
793 DTQCB *p_dtqcb;
794 bool_t dspreq;
795 ER ercd;
796
797 LOG_PRCV_DTQ_ENTER(dtqid, p_data);
798 CHECK_TSKCTX_UNL();
799 CHECK_DTQID(dtqid);
800 p_dtqcb = get_dtqcb(dtqid);
801
802 t_lock_cpu();
803 if (p_dtqcb->p_dtqinib->dtqatr == TA_NOEXS) {
804 ercd = E_NOEXS;
805 }
806 else if (receive_data(p_dtqcb, p_data, &dspreq)) {
807 if (dspreq) {
808 dispatch();
809 }
810 ercd = E_OK;
811 }
812 else {
813 ercd = E_TMOUT;
814 }
815 t_unlock_cpu();
816
817 error_exit:
818 LOG_PRCV_DTQ_LEAVE(ercd, *p_data);
819 return(ercd);
820}
821
822#endif /* TOPPERS_prcv_dtq */
823
824/*
825 * ƒf[ƒ^ƒLƒ…
826[‚©‚ç‚ÌŽóMiƒ^ƒCƒ€ƒAƒEƒg‚ ‚èj
827 */
828#ifdef TOPPERS_trcv_dtq
829
830ER
831trcv_dtq(ID dtqid, intptr_t *p_data, TMO tmout)
832{
833 DTQCB *p_dtqcb;
834 WINFO_DTQ winfo_dtq;
835 TMEVTB tmevtb;
836 bool_t dspreq;
837 ER ercd;
838
839 LOG_TRCV_DTQ_ENTER(dtqid, p_data, tmout);
840 CHECK_DISPATCH();
841 CHECK_DTQID(dtqid);
842 CHECK_TMOUT(tmout);
843 p_dtqcb = get_dtqcb(dtqid);
844
845 t_lock_cpu();
846 if (p_dtqcb->p_dtqinib->dtqatr == TA_NOEXS) {
847 ercd = E_NOEXS;
848 }
849 else if (receive_data(p_dtqcb, p_data, &dspreq)) {
850 if (dspreq) {
851 dispatch();
852 }
853 ercd = E_OK;
854 }
855 else if (tmout == TMO_POL) {
856 ercd = E_TMOUT;
857 }
858 else {
859 p_runtsk->tstat = (TS_WAITING | TS_WAIT_RDTQ);
860 make_wait_tmout(&(winfo_dtq.winfo), &tmevtb, tmout);
861 queue_insert_prev(&(p_dtqcb->rwait_queue), &(p_runtsk->task_queue));
862 winfo_dtq.p_dtqcb = p_dtqcb;
863 LOG_TSKSTAT(p_runtsk);
864 dispatch();
865 ercd = winfo_dtq.winfo.wercd;
866 if (ercd == E_OK) {
867 *p_data = winfo_dtq.data;
868 }
869 }
870 t_unlock_cpu();
871
872 error_exit:
873 LOG_TRCV_DTQ_LEAVE(ercd, *p_data);
874 return(ercd);
875}
876
877#endif /* TOPPERS_trcv_dtq */
878
879/*
880 * ƒf[ƒ^ƒLƒ…
881[‚̍ú‰»
882 */
883#ifdef TOPPERS_ini_dtq
884
885ER
886ini_dtq(ID dtqid)
887{
888 DTQCB *p_dtqcb;
889 bool_t dspreq;
890 ER ercd;
891
892 LOG_INI_DTQ_ENTER(dtqid);
893 CHECK_TSKCTX_UNL();
894 CHECK_DTQID(dtqid);
895 p_dtqcb = get_dtqcb(dtqid);
896
897 t_lock_cpu();
898 if (p_dtqcb->p_dtqinib->dtqatr == TA_NOEXS) {
899 ercd = E_NOEXS;
900 }
901 else {
902 dspreq = init_wait_queue(&(p_dtqcb->swait_queue));
903 if (init_wait_queue(&(p_dtqcb->rwait_queue))) {
904 dspreq = true;
905 }
906 p_dtqcb->count = 0U;
907 p_dtqcb->head = 0U;
908 p_dtqcb->tail = 0U;
909 if (dspreq) {
910 dispatch();
911 }
912 ercd = E_OK;
913 }
914 t_unlock_cpu();
915
916 error_exit:
917 LOG_INI_DTQ_LEAVE(ercd);
918 return(ercd);
919}
920
921#endif /* TOPPERS_ini_dtq */
922
923/*
924 * ƒf[ƒ^ƒLƒ…
925[‚̏ó‘ÔŽQÆ
926 */
927#ifdef TOPPERS_ref_dtq
928
929ER
930ref_dtq(ID dtqid, T_RDTQ *pk_rdtq)
931{
932 DTQCB *p_dtqcb;
933 ER ercd;
934
935 LOG_REF_DTQ_ENTER(dtqid, pk_rdtq);
936 CHECK_TSKCTX_UNL();
937 CHECK_DTQID(dtqid);
938 p_dtqcb = get_dtqcb(dtqid);
939
940 t_lock_cpu();
941 if (p_dtqcb->p_dtqinib->dtqatr == TA_NOEXS) {
942 ercd = E_NOEXS;
943 }
944 else {
945 pk_rdtq->stskid = wait_tskid(&(p_dtqcb->swait_queue));
946 pk_rdtq->rtskid = wait_tskid(&(p_dtqcb->rwait_queue));
947 pk_rdtq->sdtqcnt = p_dtqcb->count;
948 ercd = E_OK;
949 }
950 t_unlock_cpu();
951
952 error_exit:
953 LOG_REF_DTQ_LEAVE(ercd, pk_rdtq);
954 return(ercd);
955}
956
957#endif /* TOPPERS_ref_dtq */
Note: See TracBrowser for help on using the repository browser.