source: UsbWattMeter/trunk/asp_dcre/kernel/pridataq.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: 17.9 KB
RevLine 
[164]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: pridataq.c 164 2016-03-07 11:33:50Z coas-nagasima $
45 */
46
47/*
48 * —Dæ“xƒf[ƒ^ƒLƒ…
49[‹@”\
50 */
51
52#include "kernel_impl.h"
53#include "check.h"
54#include "task.h"
55#include "wait.h"
56#include "pridataq.h"
57
58/*
59 * ƒgƒŒ[ƒXƒƒOƒ}ƒNƒ‚̃fƒtƒHƒ‹ƒg’è‹`
60 */
61#ifndef LOG_ACRE_PDQ_ENTER
62#define LOG_ACRE_PDQ_ENTER(pk_cpdq)
63#endif /* LOG_ACRE_PDQ_ENTER */
64
65#ifndef LOG_ACRE_PDQ_LEAVE
66#define LOG_ACRE_PDQ_LEAVE(ercd)
67#endif /* LOG_ACRE_PDQ_LEAVE */
68
69#ifndef LOG_DEL_PDQ_ENTER
70#define LOG_DEL_PDQ_ENTER(pdqid)
71#endif /* LOG_DEL_PDQ_ENTER */
72
73#ifndef LOG_DEL_PDQ_LEAVE
74#define LOG_DEL_PDQ_LEAVE(ercd)
75#endif /* LOG_DEL_PDQ_LEAVE */
76
77#ifndef LOG_SND_PDQ_ENTER
78#define LOG_SND_PDQ_ENTER(pdqid, data, datapri)
79#endif /* LOG_SND_PDQ_ENTER */
80
81#ifndef LOG_SND_PDQ_LEAVE
82#define LOG_SND_PDQ_LEAVE(ercd)
83#endif /* LOG_SND_PDQ_LEAVE */
84
85#ifndef LOG_PSND_PDQ_ENTER
86#define LOG_PSND_PDQ_ENTER(pdqid, data, datapri)
87#endif /* LOG_PSND_PDQ_ENTER */
88
89#ifndef LOG_PSND_PDQ_LEAVE
90#define LOG_PSND_PDQ_LEAVE(ercd)
91#endif /* LOG_PSND_PDQ_LEAVE */
92
93#ifndef LOG_IPSND_PDQ_ENTER
94#define LOG_IPSND_PDQ_ENTER(pdqid, data, datapri)
95#endif /* LOG_IPSND_PDQ_ENTER */
96
97#ifndef LOG_IPSND_PDQ_LEAVE
98#define LOG_IPSND_PDQ_LEAVE(ercd)
99#endif /* LOG_IPSND_PDQ_LEAVE */
100
101#ifndef LOG_TSND_PDQ_ENTER
102#define LOG_TSND_PDQ_ENTER(pdqid, data, datapri, tmout)
103#endif /* LOG_TSND_PDQ_ENTER */
104
105#ifndef LOG_TSND_PDQ_LEAVE
106#define LOG_TSND_PDQ_LEAVE(ercd)
107#endif /* LOG_TSND_PDQ_LEAVE */
108
109#ifndef LOG_RCV_PDQ_ENTER
110#define LOG_RCV_PDQ_ENTER(pdqid, p_data, p_datapri)
111#endif /* LOG_RCV_PDQ_ENTER */
112
113#ifndef LOG_RCV_PDQ_LEAVE
114#define LOG_RCV_PDQ_LEAVE(ercd, data, datapri)
115#endif /* LOG_RCV_PDQ_LEAVE */
116
117#ifndef LOG_PRCV_PDQ_ENTER
118#define LOG_PRCV_PDQ_ENTER(pdqid, p_data, p_datapri)
119#endif /* LOG_PRCV_PDQ_ENTER */
120
121#ifndef LOG_PRCV_PDQ_LEAVE
122#define LOG_PRCV_PDQ_LEAVE(ercd, data, datapri)
123#endif /* LOG_PRCV_PDQ_LEAVE */
124
125#ifndef LOG_TRCV_PDQ_ENTER
126#define LOG_TRCV_PDQ_ENTER(pdqid, p_data, p_datapri, tmout)
127#endif /* LOG_TRCV_PDQ_ENTER */
128
129#ifndef LOG_TRCV_PDQ_LEAVE
130#define LOG_TRCV_PDQ_LEAVE(ercd, data, datapri)
131#endif /* LOG_TRCV_PDQ_LEAVE */
132
133#ifndef LOG_INI_PDQ_ENTER
134#define LOG_INI_PDQ_ENTER(pdqid)
135#endif /* LOG_INI_PDQ_ENTER */
136
137#ifndef LOG_INI_PDQ_LEAVE
138#define LOG_INI_PDQ_LEAVE(ercd)
139#endif /* LOG_INI_PDQ_LEAVE */
140
141#ifndef LOG_REF_PDQ_ENTER
142#define LOG_REF_PDQ_ENTER(pdqid, pk_rpdq)
143#endif /* LOG_REF_PDQ_ENTER */
144
145#ifndef LOG_REF_PDQ_LEAVE
146#define LOG_REF_PDQ_LEAVE(ercd, pk_rpdq)
147#endif /* LOG_REF_PDQ_LEAVE */
148
149/*
150 * —Dæ“xƒf[ƒ^ƒLƒ…
151[‚̐”
152 */
153#define tnum_pdq ((uint_t)(tmax_pdqid - TMIN_PDQID + 1))
154#define tnum_spdq ((uint_t)(tmax_spdqid - TMIN_PDQID + 1))
155
156/*
157 * —Dæ“xƒf[ƒ^ƒLƒ…
158[ID‚©‚ç—Dæ“xƒf[ƒ^ƒLƒ…
159[ŠÇ—ƒuƒƒbƒN‚ðŽæ‚èo‚·‚½
160 * ‚߂̃}ƒNƒ
161 */
162#define INDEX_PDQ(pdqid) ((uint_t)((pdqid) - TMIN_PDQID))
163#define get_pdqcb(pdqid) (&(pdqcb_table[INDEX_PDQ(pdqid)]))
164
165#ifdef TOPPERS_pdqini
166
167/*
168 * Žg—p‚µ‚Ä‚¢‚È‚¢—Dæ“xƒf[ƒ^ƒLƒ…
169[ŠÇ—ƒuƒƒbƒN‚̃ŠƒXƒg
170 */
171QUEUE free_pdqcb;
172
173/*
174 * —Dæ“xƒf[ƒ^ƒLƒ…
175[‹@”\‚̏‰Šú‰»
176 */
177void
178initialize_pridataq(void)
179{
180 uint_t i, j;
181 PDQCB *p_pdqcb;
182 PDQINIB *p_pdqinib;
183
184 for (i = 0; i < tnum_spdq; i++) {
185 p_pdqcb = &(pdqcb_table[i]);
186 queue_initialize(&(p_pdqcb->swait_queue));
187 p_pdqcb->p_pdqinib = &(pdqinib_table[i]);
188 queue_initialize(&(p_pdqcb->rwait_queue));
189 p_pdqcb->count = 0U;
190 p_pdqcb->p_head = NULL;
191 p_pdqcb->unused = 0U;
192 p_pdqcb->p_freelist = NULL;
193 }
194 queue_initialize(&free_pdqcb);
195 for (j = 0; i < tnum_pdq; i++, j++) {
196 p_pdqcb = &(pdqcb_table[i]);
197 p_pdqinib = &(apdqinib_table[j]);
198 p_pdqinib->pdqatr = TA_NOEXS;
199 p_pdqcb->p_pdqinib = ((const PDQINIB *) p_pdqinib);
200 queue_insert_prev(&free_pdqcb, &(p_pdqcb->swait_queue));
201 }
202}
203
204#endif /* TOPPERS_pdqini */
205
206/*
207 * —Dæ“xƒf[ƒ^ƒLƒ…
208[ŠÇ——̈æ‚ւ̃f[ƒ^‚ÌŠi”[
209 */
210#ifdef TOPPERS_pdqenq
211
212void
213enqueue_pridata(PDQCB *p_pdqcb, intptr_t data, PRI datapri)
214{
215 PDQMB *p_pdqmb;
216 PDQMB **pp_prev_next, *p_next;
217
218 if (p_pdqcb->p_freelist != NULL) {
219 p_pdqmb = p_pdqcb->p_freelist;
220 p_pdqcb->p_freelist = p_pdqmb->p_next;
221 }
222 else {
223 p_pdqmb = p_pdqcb->p_pdqinib->p_pdqmb + p_pdqcb->unused;
224 p_pdqcb->unused++;
225 }
226
227 p_pdqmb->data = data;
228 p_pdqmb->datapri = datapri;
229
230 pp_prev_next = &(p_pdqcb->p_head);
231 while ((p_next = *pp_prev_next) != NULL) {
232 if (p_next->datapri > datapri) {
233 break;
234 }
235 pp_prev_next = &(p_next->p_next);
236 }
237 p_pdqmb->p_next = p_next;
238 *pp_prev_next = p_pdqmb;
239 p_pdqcb->count++;
240}
241
242#endif /* TOPPERS_pdqenq */
243
244/*
245 * —Dæ“xƒf[ƒ^ƒLƒ…
246[ŠÇ——̈悩‚ç‚̃f[ƒ^‚ÌŽæo‚µ
247 */
248#ifdef TOPPERS_pdqdeq
249
250void
251dequeue_pridata(PDQCB *p_pdqcb, intptr_t *p_data, PRI *p_datapri)
252{
253 PDQMB *p_pdqmb;
254
255 p_pdqmb = p_pdqcb->p_head;
256 p_pdqcb->p_head = p_pdqmb->p_next;
257 p_pdqcb->count--;
258
259 *p_data = p_pdqmb->data;
260 *p_datapri = p_pdqmb->datapri;
261
262 p_pdqmb->p_next = p_pdqcb->p_freelist;
263 p_pdqcb->p_freelist = p_pdqmb;
264}
265
266#endif /* TOPPERS_pdqdeq */
267
268/*
269 * —Dæ“xƒf[ƒ^ƒLƒ…
270[‚ւ̃f[ƒ^‘—M
271 */
272#ifdef TOPPERS_pdqsnd
273
274bool_t
275send_pridata(PDQCB *p_pdqcb, intptr_t data, PRI datapri, bool_t *p_dspreq)
276{
277 TCB *p_tcb;
278
279 if (!queue_empty(&(p_pdqcb->rwait_queue))) {
280 p_tcb = (TCB *) queue_delete_next(&(p_pdqcb->rwait_queue));
281 ((WINFO_PDQ *)(p_tcb->p_winfo))->data = data;
282 ((WINFO_PDQ *)(p_tcb->p_winfo))->datapri = datapri;
283 *p_dspreq = wait_complete(p_tcb);
284 return(true);
285 }
286 else if (p_pdqcb->count < p_pdqcb->p_pdqinib->pdqcnt) {
287 enqueue_pridata(p_pdqcb, data, datapri);
288 *p_dspreq = false;
289 return(true);
290 }
291 else {
292 return(false);
293 }
294}
295
296#endif /* TOPPERS_pdqsnd */
297
298/*
299 * —Dæ“xƒf[ƒ^ƒLƒ…
300[‚©‚ç‚̃f[ƒ^ŽóM
301 */
302#ifdef TOPPERS_pdqrcv
303
304bool_t
305receive_pridata(PDQCB *p_pdqcb, intptr_t *p_data,
306 PRI *p_datapri, bool_t *p_dspreq)
307{
308 TCB *p_tcb;
309 intptr_t data;
310 PRI datapri;
311
312 if (p_pdqcb->count > 0U) {
313 dequeue_pridata(p_pdqcb, p_data, p_datapri);
314 if (!queue_empty(&(p_pdqcb->swait_queue))) {
315 p_tcb = (TCB *) queue_delete_next(&(p_pdqcb->swait_queue));
316 data = ((WINFO_PDQ *)(p_tcb->p_winfo))->data;
317 datapri = ((WINFO_PDQ *)(p_tcb->p_winfo))->datapri;
318 enqueue_pridata(p_pdqcb, data, datapri);
319 *p_dspreq = wait_complete(p_tcb);
320 }
321 else {
322 *p_dspreq = false;
323 }
324 return(true);
325 }
326 else if (!queue_empty(&(p_pdqcb->swait_queue))) {
327 p_tcb = (TCB *) queue_delete_next(&(p_pdqcb->swait_queue));
328 *p_data = ((WINFO_PDQ *)(p_tcb->p_winfo))->data;
329 *p_datapri = ((WINFO_PDQ *)(p_tcb->p_winfo))->datapri;
330 *p_dspreq = wait_complete(p_tcb);
331 return(true);
332 }
333 else {
334 return(false);
335 }
336}
337
338#endif /* TOPPERS_pdqrcv */
339
340/*
341 * —Dæ“xƒf[ƒ^ƒLƒ…
342[‚̐¶¬
343 */
344#ifdef TOPPERS_acre_pdq
345
346ER_UINT
347acre_pdq(const T_CPDQ *pk_cpdq)
348{
349 PDQCB *p_pdqcb;
350 PDQINIB *p_pdqinib;
351 ATR pdqatr;
352 PDQMB *p_pdqmb;
353 ER ercd;
354
355 LOG_ACRE_PDQ_ENTER(pk_cpdq);
356 CHECK_TSKCTX_UNL();
357 CHECK_RSATR(pk_cpdq->pdqatr, TA_TPRI);
358 CHECK_DPRI(pk_cpdq->maxdpri);
359 if (pk_cpdq->pdqmb != NULL) {
360 CHECK_ALIGN_MB(pk_cpdq->pdqmb);
361 }
362 pdqatr = pk_cpdq->pdqatr;
363 p_pdqmb = pk_cpdq->pdqmb;
364
365 t_lock_cpu();
366 if (tnum_pdq == 0 || queue_empty(&free_pdqcb)) {
367 ercd = E_NOID;
368 }
369 else {
370 if (pk_cpdq->pdqcnt != 0 && p_pdqmb == NULL) {
371 p_pdqmb = kernel_malloc(sizeof(PDQMB) * pk_cpdq->pdqcnt);
372 pdqatr |= TA_MBALLOC;
373 }
374 if (pk_cpdq->pdqcnt != 0 && p_pdqmb == NULL) {
375 ercd = E_NOMEM;
376 }
377 else {
378 p_pdqcb = ((PDQCB *) queue_delete_next(&free_pdqcb));
379 p_pdqinib = (PDQINIB *)(p_pdqcb->p_pdqinib);
380 p_pdqinib->pdqatr = pdqatr;
381 p_pdqinib->pdqcnt = pk_cpdq->pdqcnt;
382 p_pdqinib->maxdpri = pk_cpdq->maxdpri;
383 p_pdqinib->p_pdqmb = p_pdqmb;
384
385 queue_initialize(&(p_pdqcb->swait_queue));
386 queue_initialize(&(p_pdqcb->rwait_queue));
387 p_pdqcb->count = 0U;
388 p_pdqcb->p_head = NULL;
389 p_pdqcb->unused = 0U;
390 p_pdqcb->p_freelist = NULL;
391 ercd = PDQID(p_pdqcb);
392 }
393 }
394 t_unlock_cpu();
395
396 error_exit:
397 LOG_ACRE_PDQ_LEAVE(ercd);
398 return(ercd);
399}
400
401#endif /* TOPPERS_acre_pdq */
402
403/*
404 * —Dæ“xƒf[ƒ^ƒLƒ…
405[‚̍폜
406 */
407#ifdef TOPPERS_del_pdq
408
409ER
410del_pdq(ID pdqid)
411{
412 PDQCB *p_pdqcb;
413 PDQINIB *p_pdqinib;
414 bool_t dspreq;
415 ER ercd;
416
417 LOG_DEL_PDQ_ENTER(pdqid);
418 CHECK_TSKCTX_UNL();
419 CHECK_PDQID(pdqid);
420 p_pdqcb = get_pdqcb(pdqid);
421
422 t_lock_cpu();
423 if (p_pdqcb->p_pdqinib->pdqatr == TA_NOEXS) {
424 ercd = E_NOEXS;
425 }
426 else if (PDQID(p_pdqcb) > tmax_spdqid) {
427 dspreq = init_wait_queue(&(p_pdqcb->swait_queue));
428 if (init_wait_queue(&(p_pdqcb->rwait_queue))) {
429 dspreq = true;
430 }
431 p_pdqinib = (PDQINIB *)(p_pdqcb->p_pdqinib);
432 if ((p_pdqinib->pdqatr & TA_MBALLOC) != 0U) {
433 kernel_free(p_pdqinib->p_pdqmb);
434 }
435 p_pdqinib->pdqatr = TA_NOEXS;
436 queue_insert_prev(&free_pdqcb, &(p_pdqcb->swait_queue));
437 if (dspreq) {
438 dispatch();
439 }
440 ercd = E_OK;
441 }
442 else {
443 ercd = E_OBJ;
444 }
445 t_unlock_cpu();
446
447 error_exit:
448 LOG_DEL_PDQ_LEAVE(ercd);
449 return(ercd);
450}
451
452#endif /* TOPPERS_del_pdq */
453
454/*
455 * —Dæ“xƒf[ƒ^ƒLƒ…
456[‚Ö‚Ì‘—M
457 */
458#ifdef TOPPERS_snd_pdq
459
460ER
461snd_pdq(ID pdqid, intptr_t data, PRI datapri)
462{
463 PDQCB *p_pdqcb;
464 WINFO_PDQ winfo_pdq;
465 bool_t dspreq;
466 ER ercd;
467
468 LOG_SND_PDQ_ENTER(pdqid, data, datapri);
469 CHECK_DISPATCH();
470 CHECK_PDQID(pdqid);
471 p_pdqcb = get_pdqcb(pdqid);
472 CHECK_PAR(TMIN_DPRI <= datapri);
473
474 t_lock_cpu();
475 if (p_pdqcb->p_pdqinib->pdqatr == TA_NOEXS) {
476 ercd = E_NOEXS;
477 }
478 else if (!(datapri <= p_pdqcb->p_pdqinib->maxdpri)) {
479 ercd = E_PAR;
480 }
481 else if (send_pridata(p_pdqcb, data, datapri, &dspreq)) {
482 if (dspreq) {
483 dispatch();
484 }
485 ercd = E_OK;
486 }
487 else {
488 winfo_pdq.data = data;
489 winfo_pdq.datapri = datapri;
490 p_runtsk->tstat = (TS_WAITING | TS_WAIT_SPDQ);
491 wobj_make_wait((WOBJCB *) p_pdqcb, (WINFO_WOBJ *) &winfo_pdq);
492 dispatch();
493 ercd = winfo_pdq.winfo.wercd;
494 }
495 t_unlock_cpu();
496
497 error_exit:
498 LOG_SND_PDQ_LEAVE(ercd);
499 return(ercd);
500}
501
502#endif /* TOPPERS_snd_pdq */
503
504/*
505 * —Dæ“xƒf[ƒ^ƒLƒ…
506[‚Ö‚Ì‘—Miƒ|[ƒŠƒ“ƒOj
507 */
508#ifdef TOPPERS_psnd_pdq
509
510ER
511psnd_pdq(ID pdqid, intptr_t data, PRI datapri)
512{
513 PDQCB *p_pdqcb;
514 bool_t dspreq;
515 ER ercd;
516
517 LOG_PSND_PDQ_ENTER(pdqid, data, datapri);
518 CHECK_TSKCTX_UNL();
519 CHECK_PDQID(pdqid);
520 p_pdqcb = get_pdqcb(pdqid);
521 CHECK_PAR(TMIN_DPRI <= datapri);
522
523 t_lock_cpu();
524 if (p_pdqcb->p_pdqinib->pdqatr == TA_NOEXS) {
525 ercd = E_NOEXS;
526 }
527 else if (!(datapri <= p_pdqcb->p_pdqinib->maxdpri)) {
528 ercd = E_PAR;
529 }
530 else if (send_pridata(p_pdqcb, data, datapri, &dspreq)) {
531 if (dspreq) {
532 dispatch();
533 }
534 ercd = E_OK;
535 }
536 else {
537 ercd = E_TMOUT;
538 }
539 t_unlock_cpu();
540
541 error_exit:
542 LOG_PSND_PDQ_LEAVE(ercd);
543 return(ercd);
544}
545
546#endif /* TOPPERS_psnd_pdq */
547
548/*
549 * —Dæ“xƒf[ƒ^ƒLƒ…
550[‚Ö‚Ì‘—Miƒ|[ƒŠƒ“ƒOC”ñƒ^ƒXƒNƒRƒ“ƒeƒLƒXƒg—pj
551 */
552#ifdef TOPPERS_ipsnd_pdq
553
554ER
555ipsnd_pdq(ID pdqid, intptr_t data, PRI datapri)
556{
557 PDQCB *p_pdqcb;
558 bool_t dspreq;
559 ER ercd;
560
561 LOG_IPSND_PDQ_ENTER(pdqid, data, datapri);
562 CHECK_INTCTX_UNL();
563 CHECK_PDQID(pdqid);
564 p_pdqcb = get_pdqcb(pdqid);
565 CHECK_PAR(TMIN_DPRI <= datapri);
566
567 i_lock_cpu();
568 if (p_pdqcb->p_pdqinib->pdqatr == TA_NOEXS) {
569 ercd = E_NOEXS;
570 }
571 else if (!(datapri <= p_pdqcb->p_pdqinib->maxdpri)) {
572 ercd = E_PAR;
573 }
574 else if (send_pridata(p_pdqcb, data, datapri, &dspreq)) {
575 if (dspreq) {
576 reqflg = true;
577 }
578 ercd = E_OK;
579 }
580 else {
581 ercd = E_TMOUT;
582 }
583 i_unlock_cpu();
584
585 error_exit:
586 LOG_IPSND_PDQ_LEAVE(ercd);
587 return(ercd);
588}
589
590#endif /* TOPPERS_ipsnd_pdq */
591
592/*
593 * —Dæ“xƒf[ƒ^ƒLƒ…
594[‚Ö‚Ì‘—Miƒ^ƒCƒ€ƒAƒEƒg‚ ‚èj
595 */
596#ifdef TOPPERS_tsnd_pdq
597
598ER
599tsnd_pdq(ID pdqid, intptr_t data, PRI datapri, TMO tmout)
600{
601 PDQCB *p_pdqcb;
602 WINFO_PDQ winfo_pdq;
603 TMEVTB tmevtb;
604 bool_t dspreq;
605 ER ercd;
606
607 LOG_TSND_PDQ_ENTER(pdqid, data, datapri, tmout);
608 CHECK_DISPATCH();
609 CHECK_PDQID(pdqid);
610 CHECK_TMOUT(tmout);
611 p_pdqcb = get_pdqcb(pdqid);
612 CHECK_PAR(TMIN_DPRI <= datapri);
613
614 t_lock_cpu();
615 if (p_pdqcb->p_pdqinib->pdqatr == TA_NOEXS) {
616 ercd = E_NOEXS;
617 }
618 else if (!(datapri <= p_pdqcb->p_pdqinib->maxdpri)) {
619 ercd = E_PAR;
620 }
621 else if (send_pridata(p_pdqcb, data, datapri, &dspreq)) {
622 if (dspreq) {
623 dispatch();
624 }
625 ercd = E_OK;
626 }
627 else if (tmout == TMO_POL) {
628 ercd = E_TMOUT;
629 }
630 else {
631 winfo_pdq.data = data;
632 winfo_pdq.datapri = datapri;
633 p_runtsk->tstat = (TS_WAITING | TS_WAIT_SPDQ);
634 wobj_make_wait_tmout((WOBJCB *) p_pdqcb, (WINFO_WOBJ *) &winfo_pdq,
635 &tmevtb, tmout);
636 dispatch();
637 ercd = winfo_pdq.winfo.wercd;
638 }
639 t_unlock_cpu();
640
641 error_exit:
642 LOG_TSND_PDQ_LEAVE(ercd);
643 return(ercd);
644}
645
646#endif /* TOPPERS_tsnd_pdq */
647
648/*
649 * —Dæ“xƒf[ƒ^ƒLƒ…
650[‚©‚ç‚ÌŽóM
651 */
652#ifdef TOPPERS_rcv_pdq
653
654ER
655rcv_pdq(ID pdqid, intptr_t *p_data, PRI *p_datapri)
656{
657 PDQCB *p_pdqcb;
658 WINFO_PDQ winfo_pdq;
659 bool_t dspreq;
660 ER ercd;
661
662 LOG_RCV_PDQ_ENTER(pdqid, p_data, p_datapri);
663 CHECK_DISPATCH();
664 CHECK_PDQID(pdqid);
665 p_pdqcb = get_pdqcb(pdqid);
666
667 t_lock_cpu();
668 if (p_pdqcb->p_pdqinib->pdqatr == TA_NOEXS) {
669 ercd = E_NOEXS;
670 }
671 else if (receive_pridata(p_pdqcb, p_data, p_datapri, &dspreq)) {
672 if (dspreq) {
673 dispatch();
674 }
675 ercd = E_OK;
676 }
677 else {
678 p_runtsk->tstat = (TS_WAITING | TS_WAIT_RPDQ);
679 make_wait(&(winfo_pdq.winfo));
680 queue_insert_prev(&(p_pdqcb->rwait_queue), &(p_runtsk->task_queue));
681 winfo_pdq.p_pdqcb = p_pdqcb;
682 LOG_TSKSTAT(p_runtsk);
683 dispatch();
684 ercd = winfo_pdq.winfo.wercd;
685 if (ercd == E_OK) {
686 *p_data = winfo_pdq.data;
687 *p_datapri = winfo_pdq.datapri;
688 }
689 }
690 t_unlock_cpu();
691
692 error_exit:
693 LOG_RCV_PDQ_LEAVE(ercd, *p_data, *p_datapri);
694 return(ercd);
695}
696
697#endif /* TOPPERS_rcv_pdq */
698
699/*
700 * —Dæ“xƒf[ƒ^ƒLƒ…
701[‚©‚ç‚ÌŽóMiƒ|[ƒŠƒ“ƒOj
702 */
703#ifdef TOPPERS_prcv_pdq
704
705ER
706prcv_pdq(ID pdqid, intptr_t *p_data, PRI *p_datapri)
707{
708 PDQCB *p_pdqcb;
709 bool_t dspreq;
710 ER ercd;
711
712 LOG_PRCV_PDQ_ENTER(pdqid, p_data, p_datapri);
713 CHECK_TSKCTX_UNL();
714 CHECK_PDQID(pdqid);
715 p_pdqcb = get_pdqcb(pdqid);
716
717 t_lock_cpu();
718 if (p_pdqcb->p_pdqinib->pdqatr == TA_NOEXS) {
719 ercd = E_NOEXS;
720 }
721 else if (receive_pridata(p_pdqcb, p_data, p_datapri, &dspreq)) {
722 if (dspreq) {
723 dispatch();
724 }
725 ercd = E_OK;
726 }
727 else {
728 ercd = E_TMOUT;
729 }
730 t_unlock_cpu();
731
732 error_exit:
733 LOG_PRCV_PDQ_LEAVE(ercd, *p_data, *p_datapri);
734 return(ercd);
735}
736
737#endif /* TOPPERS_prcv_pdq */
738
739/*
740 * —Dæ“xƒf[ƒ^ƒLƒ…
741[‚©‚ç‚ÌŽóMiƒ^ƒCƒ€ƒAƒEƒg‚ ‚èj
742 */
743#ifdef TOPPERS_trcv_pdq
744
745ER
746trcv_pdq(ID pdqid, intptr_t *p_data, PRI *p_datapri, TMO tmout)
747{
748 PDQCB *p_pdqcb;
749 WINFO_PDQ winfo_pdq;
750 TMEVTB tmevtb;
751 bool_t dspreq;
752 ER ercd;
753
754 LOG_TRCV_PDQ_ENTER(pdqid, p_data, p_datapri, tmout);
755 CHECK_DISPATCH();
756 CHECK_PDQID(pdqid);
757 CHECK_TMOUT(tmout);
758 p_pdqcb = get_pdqcb(pdqid);
759
760 t_lock_cpu();
761 if (p_pdqcb->p_pdqinib->pdqatr == TA_NOEXS) {
762 ercd = E_NOEXS;
763 }
764 else if (receive_pridata(p_pdqcb, p_data, p_datapri, &dspreq)) {
765 if (dspreq) {
766 dispatch();
767 }
768 ercd = E_OK;
769 }
770 else if (tmout == TMO_POL) {
771 ercd = E_TMOUT;
772 }
773 else {
774 p_runtsk->tstat = (TS_WAITING | TS_WAIT_RPDQ);
775 make_wait_tmout(&(winfo_pdq.winfo), &tmevtb, tmout);
776 queue_insert_prev(&(p_pdqcb->rwait_queue), &(p_runtsk->task_queue));
777 winfo_pdq.p_pdqcb = p_pdqcb;
778 LOG_TSKSTAT(p_runtsk);
779 dispatch();
780 ercd = winfo_pdq.winfo.wercd;
781 if (ercd == E_OK) {
782 *p_data = winfo_pdq.data;
783 *p_datapri = winfo_pdq.datapri;
784 }
785 }
786 t_unlock_cpu();
787
788 error_exit:
789 LOG_TRCV_PDQ_LEAVE(ercd, *p_data, *p_datapri);
790 return(ercd);
791}
792
793#endif /* TOPPERS_trcv_pdq */
794
795/*
796 * —Dæ“xƒf[ƒ^ƒLƒ…
797[‚̍ú‰»
798 */
799#ifdef TOPPERS_ini_pdq
800
801ER
802ini_pdq(ID pdqid)
803{
804 PDQCB *p_pdqcb;
805 bool_t dspreq;
806 ER ercd;
807
808 LOG_INI_PDQ_ENTER(pdqid);
809 CHECK_TSKCTX_UNL();
810 CHECK_PDQID(pdqid);
811 p_pdqcb = get_pdqcb(pdqid);
812
813 t_lock_cpu();
814 if (p_pdqcb->p_pdqinib->pdqatr == TA_NOEXS) {
815 ercd = E_NOEXS;
816 }
817 else {
818 dspreq = init_wait_queue(&(p_pdqcb->swait_queue));
819 if (init_wait_queue(&(p_pdqcb->rwait_queue))) {
820 dspreq = true;
821 }
822 p_pdqcb->count = 0U;
823 p_pdqcb->p_head = NULL;
824 p_pdqcb->unused = 0U;
825 p_pdqcb->p_freelist = NULL;
826 if (dspreq) {
827 dispatch();
828 }
829 ercd = E_OK;
830 }
831 t_unlock_cpu();
832
833 error_exit:
834 LOG_INI_PDQ_LEAVE(ercd);
835 return(ercd);
836}
837
838#endif /* TOPPERS_ini_pdq */
839
840/*
841 * —Dæ“xƒf[ƒ^ƒLƒ…
842[‚̏ó‘ÔŽQÆ
843 */
844#ifdef TOPPERS_ref_pdq
845
846ER
847ref_pdq(ID pdqid, T_RPDQ *pk_rpdq)
848{
849 PDQCB *p_pdqcb;
850 ER ercd;
851
852 LOG_REF_PDQ_ENTER(pdqid, pk_rpdq);
853 CHECK_TSKCTX_UNL();
854 CHECK_PDQID(pdqid);
855 p_pdqcb = get_pdqcb(pdqid);
856
857 t_lock_cpu();
858 if (p_pdqcb->p_pdqinib->pdqatr == TA_NOEXS) {
859 ercd = E_NOEXS;
860 }
861 else {
862 pk_rpdq->stskid = wait_tskid(&(p_pdqcb->swait_queue));
863 pk_rpdq->rtskid = wait_tskid(&(p_pdqcb->rwait_queue));
864 pk_rpdq->spdqcnt = p_pdqcb->count;
865 ercd = E_OK;
866 }
867 t_unlock_cpu();
868
869 error_exit:
870 LOG_REF_PDQ_LEAVE(ercd, pk_rpdq);
871 return(ercd);
872}
873
874#endif /* TOPPERS_ref_pdq */
Note: See TracBrowser for help on using the repository browser.