source: uKadecot/trunk/ssp/extension/dataqueue.c@ 101

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

TOPPERS/uKadecotのソースコードを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/plain
File size: 6.0 KB
Line 
1/*
2 * TOPPERS/SSP Kernel
3 * Smallest Set Profile Kernel
4 *
5 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
6 * Toyohashi Univ. of Technology, JAPAN
7 * Copyright (C) 2005-2010 by Embedded and Real-Time Systems Laboratory
8 * Graduate School of Information Science, Nagoya Univ., JAPAN
9 * Copyright (C) 2011 by Meika Sugimoto
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‰ü•ÏE
13 * Ä”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‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[ƒX
16 * ƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
17 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg—p
18 * ‚Å‚«‚éŒ`‚ōĔ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—p
24 * ‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±‚ƁD
25 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
26ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
27ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ì
28 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
29 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É•ñ
30 * ‚·‚邱‚ƁD
31 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹ŠQ
32 * ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD‚Ü‚½C
33 * –{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝—R‚ÉŠî‚Ã
34 * ‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
35 *
36 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨‚æ
37 * ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I‚ɑ΂·
38 * ‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p
39 * ‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»‚̐ӔC‚ð•‰
40 * ‚í‚È‚¢D
41 *
42 */
43
44/*
45 * ƒf[ƒ^ƒLƒ…
46[‹@”\
47 */
48
49#include "kernel_impl.h"
50#include "check.h"
51#include "dataqueue.h"
52
53/*
54 * ƒgƒŒ[ƒXƒƒOƒ}ƒNƒ‚̃fƒtƒHƒ‹ƒg’è‹`
55 */
56#ifndef LOG_PSND_DTQ_ENTER
57#define LOG_PSND_DTQ_ENTER(dtqid, data)
58#endif /* LOG_PSND_DTQ_ENTER */
59
60#ifndef LOG_PSND_DTQ_LEAVE
61#define LOG_PSND_DTQ_LEAVE(ercd)
62#endif /* LOG_PSND_DTQ_LEAVE */
63
64#ifndef LOG_IPSND_DTQ_ENTER
65#define LOG_IPSND_DTQ_ENTER(dtqid, data)
66#endif /* LOG_IPSND_DTQ_ENTER */
67
68#ifndef LOG_IPSND_DTQ_LEAVE
69#define LOG_IPSND_DTQ_LEAVE(ercd)
70#endif /* LOG_IPSND_DTQ_LEAVE */
71
72#ifndef LOG_PRCV_DTQ_ENTER
73#define LOG_PRCV_DTQ_ENTER(dtqid, p_data)
74#endif /* LOG_PRCV_DTQ_ENTER */
75
76#ifndef LOG_PRCV_DTQ_LEAVE
77#define LOG_PRCV_DTQ_LEAVE(ercd, data)
78#endif /* LOG_PRCV_DTQ_LEAVE */
79
80/*
81 * ƒf[ƒ^ƒLƒ…
82[‚ւ̃f[ƒ^‘—M
83 */
84void
85enqueue_data(intptr_t* const data , uint8_t* const tail , const uint8_t size , const intptr_t sdata);
86
87/*
88 * ƒf[ƒ^ƒLƒ…
89[‚©‚ç‚̃f[ƒ^ŽóM
90 */
91void
92dequeue_data(intptr_t* const data , uint8_t* const head , const uint8_t size , intptr_t* rdata);
93
94
95/*
96 * ƒf[ƒ^ƒLƒ…
97[‚̐”
98 */
99#define tnum_dtq ((uint_t)(tmax_dtqid - TMIN_DTQID + 1))
100
101/*
102 * ƒf[ƒ^ƒLƒ…
103[ID‚©‚çƒf[ƒ^ƒLƒ…
104[ŠÇ—ƒuƒƒbƒN‚ðŽæ‚èo‚·‚½‚߂̃}ƒNƒ
105 */
106#define INDEX_DTQ(dtqid) ((uint_t)((dtqid) - TMIN_DTQID))
107
108/*
109 * ƒf[ƒ^ƒLƒ…
110[‹@”\‚̏‰Šú‰»
111 */
112#ifdef TOPPERS_dtqini
113
114void
115initialize_dataqueue(void)
116{
117 uint_t i;
118
119 for (i = 0U ; i < tnum_dtq ; i++) {
120 dtqcb_count[i] = 0U;
121 dtqcb_head[i] = 0U;
122 dtqcb_tail[i] = 0U;
123 }
124}
125
126#endif /* TOPPERS_dtqini */
127
128
129/*
130 * ƒf[ƒ^ƒLƒ…
131[‚ª–ž”t‚©‚̃`ƒFƒbƒN
132 */
133
134Inline bool_t
135data_full(uint8_t count , uint8_t size)
136{
137 return (count >= size)? true : false;
138}
139
140/*
141 * ƒf[ƒ^ƒLƒ…
142[‚ª‹ó‚©‚̃`ƒFƒbƒN
143 */
144
145Inline bool_t
146data_empty(uint8_t count)
147{
148 return (count == 0)? true : false;
149}
150
151
152/*
153 * ƒf[ƒ^ƒLƒ…
154[‚ւ̃f[ƒ^‘—M
155 */
156
157
158#ifdef TOPPERS_dtqenq
159
160void
161enqueue_data(intptr_t* const data , uint8_t* const tail , const uint8_t size , const intptr_t sdata)
162{
163 data[*tail] = sdata;
164 (*tail)++;
165 if (*tail >= size) {
166 *tail = 0U;
167 }
168}
169
170#endif /* TOPPERS_dtqenq */
171
172/*
173 * ‘—M‘Ò‚¿ƒLƒ…
174[‚̐擪ƒ^ƒXƒN‚©‚ç‚̃f[ƒ^ŽóM
175 */
176#ifdef TOPPERS_dtqdeq
177
178void
179dequeue_data(intptr_t* const data , uint8_t* const head , const uint8_t size , intptr_t* rdata)
180{
181 *rdata = data[*head];
182 (*head)++;
183 if (*head >= size) {
184 *head = 0U;
185 }
186
187}
188
189#endif /* TOPPERS_dtqdeq */
190
191/*
192 * ƒf[ƒ^ƒLƒ…
193[‚Ö‚Ì‘—Miƒ|[ƒŠƒ“ƒOj
194 */
195#ifdef TOPPERS_psnd_dtq
196
197ER
198psnd_dtq(ID dtqid, intptr_t data)
199{
200 ER ercd;
201 int_t index;
202
203 LOG_PSND_DTQ_ENTER(dtqid, data);
204 CHECK_TSKCTX_UNL();
205 CHECK_DTQID(dtqid);
206
207 t_lock_cpu();
208 index = INDEX_DTQ(dtqid);
209
210 if (!data_full(dtqcb_count[index] , dtqinib_size[index]))
211 {
212 enqueue_data(dtqinib_data[index] , &(dtqcb_tail[index]) ,
213 dtqinib_size[index] , data);
214 dtqcb_count[index]++;
215 ercd = E_OK;
216 }
217 else {
218 ercd = E_TMOUT;
219 }
220 t_unlock_cpu();
221
222 error_exit:
223 LOG_PSND_DTQ_LEAVE(ercd);
224 return(ercd);
225}
226
227#endif /* TOPPERS_psnd_dtq */
228
229/*
230 * ƒf[ƒ^ƒLƒ…
231[‚Ö‚Ì‘—Miƒ|[ƒŠƒ“ƒOC”ñƒ^ƒXƒNƒRƒ“ƒeƒLƒXƒg—pj
232 */
233#ifdef TOPPERS_ipsnd_dtq
234
235ER
236ipsnd_dtq(ID dtqid, intptr_t data)
237{
238 ER ercd;
239 int_t index;
240
241 LOG_IPSND_DTQ_ENTER(dtqid, data);
242 CHECK_INTCTX_UNL();
243 CHECK_DTQID(dtqid);
244
245 i_lock_cpu();
246 index = INDEX_DTQ(dtqid);
247
248 if (!data_full(dtqcb_count[index] , dtqinib_size[index]))
249 {
250 enqueue_data(dtqinib_data[index] , &(dtqcb_tail[index]) ,
251 dtqinib_size[index] , data);
252 dtqcb_count[index]++;
253 ercd = E_OK;
254 }
255 else {
256 ercd = E_TMOUT;
257 }
258 i_unlock_cpu();
259
260 error_exit:
261 LOG_IPSND_DTQ_LEAVE(ercd);
262 return(ercd);
263}
264
265#endif /* TOPPERS_ipsnd_dtq */
266
267/*
268 * ƒf[ƒ^ƒLƒ…
269[‚©‚ç‚ÌŽóMiƒ|[ƒŠƒ“ƒOj
270 */
271#ifdef TOPPERS_prcv_dtq
272
273ER
274prcv_dtq(ID dtqid, intptr_t *p_data)
275{
276 ER ercd;
277 int_t index;
278
279 LOG_PRCV_DTQ_ENTER(dtqid, p_data);
280 CHECK_TSKCTX_UNL();
281 CHECK_DTQID(dtqid);
282
283 t_lock_cpu();
284 index = INDEX_DTQ(dtqid);
285
286 if (!data_empty(dtqcb_count[index]))
287 {
288 dequeue_data(dtqinib_data[index] , &(dtqcb_head[index]) ,
289 dtqinib_size[index] , p_data);
290 dtqcb_count[index]--;
291 ercd = E_OK;
292 }
293 else {
294 ercd = E_TMOUT;
295 }
296 t_unlock_cpu();
297
298 error_exit:
299 LOG_PRCV_DTQ_LEAVE(ercd, *p_data);
300 return(ercd);
301}
302
303#endif /* TOPPERS_prcv_dtq */
Note: See TracBrowser for help on using the repository browser.