[101] | 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{\tgEF
|
---|
| 12 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»EüÏE
|
---|
| 13 | * ÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
| 14 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
| 15 | * \¦C±Ìpð¨æѺL̳ÛØKèªC»ÌÜÜÌ`Å\[X
|
---|
| 16 | * R[hÉÜÜêÄ¢é±ÆD
|
---|
| 17 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉgp
|
---|
| 18 | * Å«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
| 19 | gipÒ}
|
---|
| 20 | * j
|
---|
| 21 | AÈÇjÉCãLÌì \¦C±Ìpð¨æѺL̳Û
|
---|
| 22 | * ØKèðfÚ·é±ÆD
|
---|
| 23 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉgp
|
---|
| 24 | * Å«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±ÆD
|
---|
| 25 | * (a) Äzzɺ¤hL
|
---|
| 26 | gipÒ}j
|
---|
| 27 | AÈÇjÉCãLÌì
|
---|
| 28 | * \¦C±Ìpð¨æѺL̳ÛØKèðfÚ·é±ÆD
|
---|
| 29 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉñ
|
---|
| 30 | * ·é±ÆD
|
---|
| 31 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹Q
|
---|
| 32 | * ©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆDܽC
|
---|
| 33 | * {\tgEFAÌ[UܽÍGh[U©çÌ¢©ÈéRÉîÃ
|
---|
| 34 | * ¿©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
| 35 | *
|
---|
| 36 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨æ
|
---|
| 37 | * ÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚIÉη
|
---|
| 38 | * éK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEFAÌ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[XO}NÌftHgè`
|
---|
| 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 | */
|
---|
| 84 | void
|
---|
| 85 | enqueue_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 | */
|
---|
| 91 | void
|
---|
| 92 | dequeue_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 | [ÇubNðæè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 |
|
---|
| 114 | void
|
---|
| 115 | initialize_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©Ì`FbN
|
---|
| 132 | */
|
---|
| 133 |
|
---|
| 134 | Inline bool_t
|
---|
| 135 | data_full(uint8_t count , uint8_t size)
|
---|
| 136 | {
|
---|
| 137 | return (count >= size)? true : false;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | /*
|
---|
| 141 | * f[^L
|
---|
| 142 | [ªó©Ì`FbN
|
---|
| 143 | */
|
---|
| 144 |
|
---|
| 145 | Inline bool_t
|
---|
| 146 | data_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 |
|
---|
| 160 | void
|
---|
| 161 | enqueue_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 | [Ìæª^XN©çÌf[^óM
|
---|
| 175 | */
|
---|
| 176 | #ifdef TOPPERS_dtqdeq
|
---|
| 177 |
|
---|
| 178 | void
|
---|
| 179 | dequeue_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 | [ÖÌMi|[Oj
|
---|
| 194 | */
|
---|
| 195 | #ifdef TOPPERS_psnd_dtq
|
---|
| 196 |
|
---|
| 197 | ER
|
---|
| 198 | psnd_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 | [ÖÌMi|[OCñ^XNReLXgpj
|
---|
| 232 | */
|
---|
| 233 | #ifdef TOPPERS_ipsnd_dtq
|
---|
| 234 |
|
---|
| 235 | ER
|
---|
| 236 | ipsnd_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 | [©çÌóMi|[Oj
|
---|
| 270 | */
|
---|
| 271 | #ifdef TOPPERS_prcv_dtq
|
---|
| 272 |
|
---|
| 273 | ER
|
---|
| 274 | prcv_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 */
|
---|