Published 03 Dec 2010, by
Eric Ebert
CoOS,
rtos
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <coocox.h>
00018
00019
00020 #if CFG_QUEUE_EN > 0
00021
00022 QCB QueueTbl[CFG_MAX_QUEUE] = {{0}};
00023 U32 QueueIDVessel = 0;
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 OS_EventID CoCreateQueue(void **qStart, U16 size ,U8 sortType)
00043 {
00044 U8 i;
00045 P_ECB pecb;
00046
00047 #if CFG_PAR_CHECKOUT_EN >0
00048 if((qStart == 0) || (size == 0))
00049 {
00050 return E_CREATE_FAIL;
00051 }
00052 #endif
00053
00054 OsSchedLock ();
00055 for(i = 0; i < CFG_MAX_QUEUE; i++)
00056 {
00057
00058 if((QueueIDVessel & (1 << i)) == 0)
00059 {
00060 QueueIDVessel |= (1<<i);
00061 OsSchedUnlock();
00062
00063 QueueTbl[i].qStart = qStart;
00064 QueueTbl[i].id = i;
00065 QueueTbl[i].head = 0;
00066 QueueTbl[i].tail = 0;
00067 QueueTbl[i].qMaxSize = size;
00068 QueueTbl[i].qSize = 0;
00069
00070
00071 pecb = CreatEvent (EVENT_TYPE_QUEUE ,sortType,&QueueTbl[i]);
00072
00073 if(pecb == 0 )
00074 {
00075 return E_CREATE_FAIL;
00076 }
00077 return (pecb->id );
00078 }
00079 }
00080
00081 OsSchedUnlock();
00082 return E_CREATE_FAIL;
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 StatusType CoDelQueue(OS_EventID id,U8 opt)
00103 {
00104 P_ECB pecb;
00105 P_QCB pqcb;
00106 StatusType err;
00107 #if CFG_PAR_CHECKOUT_EN >0
00108 if(id >= CFG_MAX_EVENT )
00109 {
00110 return E_INVALID_ID;
00111 }
00112 #endif
00113
00114 pecb = &EventTbl [id];
00115 #if CFG_PAR_CHECKOUT_EN >0
00116 if( pecb->eventType != EVENT_TYPE_QUEUE )
00117 {
00118 return E_INVALID_ID;
00119 }
00120 #endif
00121 pqcb = (P_QCB)pecb->eventPtr ;
00122 err = DeleteEvent (pecb,opt);
00123 if(err == E_OK)
00124 {
00125 QueueIDVessel &= ~((U32)(1<<(pqcb->id )));
00126 pqcb->qStart = 0;
00127 pqcb->id = 0;
00128 pqcb->head = 0;
00129 pqcb->tail = 0;
00130 pqcb->qMaxSize = 0;
00131 pqcb->qSize = 0;
00132 }
00133 return err;
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 void* CoAcceptQueueMail(OS_EventID id,StatusType* perr)
00152 {
00153 P_ECB pecb;
00154 P_QCB pqcb;
00155 void* pmail;
00156 #if CFG_PAR_CHECKOUT_EN >0
00157 if(id >= CFG_MAX_EVENT )
00158 {
00159 *perr = E_INVALID_ID;
00160 return 0;
00161 }
00162 #endif
00163
00164 pecb = &EventTbl [id];
00165 #if CFG_PAR_CHECKOUT_EN >0
00166 if(pecb->eventType != EVENT_TYPE_QUEUE )
00167 {
00168 *perr = E_INVALID_ID;
00169 return 0;
00170 }
00171 #endif
00172 pqcb = (P_QCB)pecb->eventPtr ;
00173 OsSchedLock ();
00174 if(pqcb->qSize != 0)
00175 {
00176
00177 pmail = *(pqcb->qStart + pqcb->head );
00178 pqcb->head ++;
00179 pqcb->qSize --;
00180 if(pqcb->head == pqcb->qMaxSize )
00181 {
00182 pqcb->head = 0;
00183 }
00184 OsSchedUnlock();
00185 *perr = E_OK;
00186 return pmail;
00187 }
00188 else
00189 {
00190 OsSchedUnlock();
00191 *perr = E_QUEUE_EMPTY;
00192 return 0;
00193 }
00194 }
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 void* CoPendQueueMail(OS_EventID id,U32 timeout,StatusType* perr)
00213 {
00214 P_ECB pecb;
00215 P_QCB pqcb;
00216 P_OSTCB curTCB;
00217 void* pmail;
00218 if(OSIntNesting > 0)
00219 {
00220 *perr = E_CALL;
00221 return 0;
00222 }
00223 #if CFG_PAR_CHECKOUT_EN >0
00224 if(id >= CFG_MAX_EVENT )
00225 {
00226 *perr = E_INVALID_ID;
00227 return 0;
00228 }
00229 #endif
00230
00231 pecb = &EventTbl [id];
00232 #if CFG_PAR_CHECKOUT_EN >0
00233 if(pecb->eventType != EVENT_TYPE_QUEUE )
00234 {
00235 *perr = E_INVALID_ID;
00236 return 0;
00237 }
00238 #endif
00239 if(OSSchedLock != 0)
00240 {
00241 *perr = E_OS_IN_LOCK;
00242 return 0;
00243 }
00244 pqcb = (P_QCB)pecb->eventPtr ;
00245
00246 if(pqcb->qSize != 0)
00247 {
00248
00249 pmail = *(pqcb->qStart + pqcb->head );
00250 pqcb->head ++;
00251 pqcb->qSize --;
00252 if(pqcb->head == pqcb->qMaxSize )
00253 {
00254 pqcb->head = 0;
00255 }
00256 *perr = E_OK;
00257 return pmail;
00258 }
00259 else
00260 {
00261 curTCB = TCBRunning ;
00262 if(timeout == 0)
00263 {
00264
00265 EventTaskToWait(pecb,curTCB);
00266
00267
00268 pmail = curTCB->pmail;
00269 curTCB->pmail = 0;
00270 *perr = E_OK;
00271 return pmail;
00272 }
00273 else
00274 {
00275 OsSchedLock ();
00276
00277
00278 EventTaskToWait(pecb,curTCB);
00279 InsertDelayList(curTCB,timeout);
00280 OsSchedUnlock();
00281 if(curTCB->pmail == 0)
00282 {
00283 *perr = E_TIMEOUT;
00284 return 0;
00285 }
00286 else
00287 {
00288 pmail = curTCB->pmail;
00289 curTCB->pmail = 0;
00290 *perr = E_OK;
00291 return pmail;
00292 }
00293 }
00294 }
00295 }
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 StatusType CoPostQueueMail(OS_EventID id,void* pmail)
00315 {
00316 P_ECB pecb;
00317 P_QCB pqcb;
00318 #if CFG_PAR_CHECKOUT_EN >0
00319 if(id >= CFG_MAX_EVENT )
00320 {
00321 return E_INVALID_ID;
00322 }
00323 #endif
00324
00325 pecb = &EventTbl [id];
00326 #if CFG_PAR_CHECKOUT_EN >0
00327 if(pecb->eventType != EVENT_TYPE_QUEUE )
00328 {
00329 return E_INVALID_ID;
00330 }
00331 #endif
00332 pqcb = (P_QCB)pecb->eventPtr ;
00333 if(pqcb->qSize == pqcb->qMaxSize )
00334 {
00335 return E_QUEUE_FULL;
00336 }
00337 else
00338 {
00339 OsSchedLock ();
00340 *(pqcb->qStart + pqcb->tail ) = pmail;
00341 pqcb->tail ++;
00342 pqcb->qSize ++;
00343 if(pqcb->tail == pqcb->qMaxSize )
00344 {
00345 pqcb->tail = 0;
00346 }
00347 EventTaskToRdy (pecb);
00348 OsSchedUnlock();
00349 return E_OK;
00350 }
00351 }
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 #if CFG_MAX_SERVICE_REQUEST > 0
00370 StatusType isr_PostQueueMail(OS_EventID id,void* pmail)
00371 {
00372 if(OSSchedLock > 0)
00373 {
00374
00375 if(InsertInSRQ(QUEUE_REQ,id,pmail) == FALSE)
00376 {
00377 return E_SEV_REQ_FULL;
00378 }
00379 else
00380 {
00381 return E_OK;
00382 }
00383 }
00384 else
00385 {
00386 return(CoPostQueueMail(id,pmail));
00387 }
00388 }
00389 #endif
00390
00391 #endif