Eric Ebert
/
CoOS
CoOS Demonstrator adapted to mbed Hardware.
queue.c@0:57690853989a, 2010-12-03 (annotated)
- Committer:
- ericebert
- Date:
- Fri Dec 03 19:45:30 2010 +0000
- Revision:
- 0:57690853989a
Some basic LED-Flashing works in the CoOS-RTOS using Tasks
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ericebert | 0:57690853989a | 1 | /** |
ericebert | 0:57690853989a | 2 | ******************************************************************************* |
ericebert | 0:57690853989a | 3 | * @file queue.c |
ericebert | 0:57690853989a | 4 | * @version V1.1.3 |
ericebert | 0:57690853989a | 5 | * @date 2010.04.26 |
ericebert | 0:57690853989a | 6 | * @brief Queue management implementation code of CooCox CoOS kernel. |
ericebert | 0:57690853989a | 7 | ******************************************************************************* |
ericebert | 0:57690853989a | 8 | * @copy |
ericebert | 0:57690853989a | 9 | * |
ericebert | 0:57690853989a | 10 | * INTERNAL FILE,DON'T PUBLIC. |
ericebert | 0:57690853989a | 11 | * |
ericebert | 0:57690853989a | 12 | * <h2><center>© COPYRIGHT 2009 CooCox </center></h2> |
ericebert | 0:57690853989a | 13 | ******************************************************************************* |
ericebert | 0:57690853989a | 14 | */ |
ericebert | 0:57690853989a | 15 | |
ericebert | 0:57690853989a | 16 | /*---------------------------- Include ---------------------------------------*/ |
ericebert | 0:57690853989a | 17 | #include <coocox.h> |
ericebert | 0:57690853989a | 18 | |
ericebert | 0:57690853989a | 19 | |
ericebert | 0:57690853989a | 20 | #if CFG_QUEUE_EN > 0 |
ericebert | 0:57690853989a | 21 | /*---------------------------- Variable Define -------------------------------*/ |
ericebert | 0:57690853989a | 22 | QCB QueueTbl[CFG_MAX_QUEUE] = {{0}}; /*!< Queue control block table */ |
ericebert | 0:57690853989a | 23 | U32 QueueIDVessel = 0; /*!< Queue list mask */ |
ericebert | 0:57690853989a | 24 | |
ericebert | 0:57690853989a | 25 | |
ericebert | 0:57690853989a | 26 | |
ericebert | 0:57690853989a | 27 | /** |
ericebert | 0:57690853989a | 28 | ******************************************************************************* |
ericebert | 0:57690853989a | 29 | * @brief Create a queue |
ericebert | 0:57690853989a | 30 | * @param[in] qStart Pointer to mail pointer buffer. |
ericebert | 0:57690853989a | 31 | * @param[in] size The length of queue. |
ericebert | 0:57690853989a | 32 | * @param[in] sortType Mail queue waiting list sort type. |
ericebert | 0:57690853989a | 33 | * @param[out] None |
ericebert | 0:57690853989a | 34 | * @retval E_CREATE_FAIL Create queue fail. |
ericebert | 0:57690853989a | 35 | * @retval others Create queue successful. |
ericebert | 0:57690853989a | 36 | * |
ericebert | 0:57690853989a | 37 | * @par Description |
ericebert | 0:57690853989a | 38 | * @details This function is called to create a queue. |
ericebert | 0:57690853989a | 39 | * @note |
ericebert | 0:57690853989a | 40 | ******************************************************************************* |
ericebert | 0:57690853989a | 41 | */ |
ericebert | 0:57690853989a | 42 | OS_EventID CoCreateQueue(void **qStart, U16 size ,U8 sortType) |
ericebert | 0:57690853989a | 43 | { |
ericebert | 0:57690853989a | 44 | U8 i; |
ericebert | 0:57690853989a | 45 | P_ECB pecb; |
ericebert | 0:57690853989a | 46 | |
ericebert | 0:57690853989a | 47 | #if CFG_PAR_CHECKOUT_EN >0 |
ericebert | 0:57690853989a | 48 | if((qStart == 0) || (size == 0)) |
ericebert | 0:57690853989a | 49 | { |
ericebert | 0:57690853989a | 50 | return E_CREATE_FAIL; |
ericebert | 0:57690853989a | 51 | } |
ericebert | 0:57690853989a | 52 | #endif |
ericebert | 0:57690853989a | 53 | |
ericebert | 0:57690853989a | 54 | OsSchedLock(); |
ericebert | 0:57690853989a | 55 | for(i = 0; i < CFG_MAX_QUEUE; i++) |
ericebert | 0:57690853989a | 56 | { |
ericebert | 0:57690853989a | 57 | /* Assign a free QUEUE control block */ |
ericebert | 0:57690853989a | 58 | if((QueueIDVessel & (1 << i)) == 0) |
ericebert | 0:57690853989a | 59 | { |
ericebert | 0:57690853989a | 60 | QueueIDVessel |= (1<<i); |
ericebert | 0:57690853989a | 61 | OsSchedUnlock(); |
ericebert | 0:57690853989a | 62 | |
ericebert | 0:57690853989a | 63 | QueueTbl[i].qStart = qStart; /* Initialize the queue */ |
ericebert | 0:57690853989a | 64 | QueueTbl[i].id = i; |
ericebert | 0:57690853989a | 65 | QueueTbl[i].head = 0; |
ericebert | 0:57690853989a | 66 | QueueTbl[i].tail = 0; |
ericebert | 0:57690853989a | 67 | QueueTbl[i].qMaxSize = size; |
ericebert | 0:57690853989a | 68 | QueueTbl[i].qSize = 0; |
ericebert | 0:57690853989a | 69 | |
ericebert | 0:57690853989a | 70 | /* Get a event control block and initial the event content */ |
ericebert | 0:57690853989a | 71 | pecb = CreatEvent(EVENT_TYPE_QUEUE,sortType,&QueueTbl[i]); |
ericebert | 0:57690853989a | 72 | |
ericebert | 0:57690853989a | 73 | if(pecb == 0 ) /* If there is no free EVENT control block*/ |
ericebert | 0:57690853989a | 74 | { |
ericebert | 0:57690853989a | 75 | return E_CREATE_FAIL; |
ericebert | 0:57690853989a | 76 | } |
ericebert | 0:57690853989a | 77 | return (pecb->id); |
ericebert | 0:57690853989a | 78 | } |
ericebert | 0:57690853989a | 79 | } |
ericebert | 0:57690853989a | 80 | |
ericebert | 0:57690853989a | 81 | OsSchedUnlock(); |
ericebert | 0:57690853989a | 82 | return E_CREATE_FAIL; /* There is no free QUEUE control block */ |
ericebert | 0:57690853989a | 83 | } |
ericebert | 0:57690853989a | 84 | |
ericebert | 0:57690853989a | 85 | |
ericebert | 0:57690853989a | 86 | /** |
ericebert | 0:57690853989a | 87 | ******************************************************************************* |
ericebert | 0:57690853989a | 88 | * @brief Delete a queue |
ericebert | 0:57690853989a | 89 | * @param[in] id Event ID. |
ericebert | 0:57690853989a | 90 | * @param[in] opt Delete option. |
ericebert | 0:57690853989a | 91 | * @param[out] None |
ericebert | 0:57690853989a | 92 | * @retval E_INVALID_ID Invalid event ID. |
ericebert | 0:57690853989a | 93 | * @retval E_INVALID_PARAMETER Invalid parameter. |
ericebert | 0:57690853989a | 94 | * @retval E_TASK_WAITTING Tasks waitting for the event,delete fail. |
ericebert | 0:57690853989a | 95 | * @retval E_OK Event deleted successful. |
ericebert | 0:57690853989a | 96 | * |
ericebert | 0:57690853989a | 97 | * @par Description |
ericebert | 0:57690853989a | 98 | * @details This function is called to delete a queue. |
ericebert | 0:57690853989a | 99 | * @note |
ericebert | 0:57690853989a | 100 | ******************************************************************************* |
ericebert | 0:57690853989a | 101 | */ |
ericebert | 0:57690853989a | 102 | StatusType CoDelQueue(OS_EventID id,U8 opt) |
ericebert | 0:57690853989a | 103 | { |
ericebert | 0:57690853989a | 104 | P_ECB pecb; |
ericebert | 0:57690853989a | 105 | P_QCB pqcb; |
ericebert | 0:57690853989a | 106 | StatusType err; |
ericebert | 0:57690853989a | 107 | #if CFG_PAR_CHECKOUT_EN >0 |
ericebert | 0:57690853989a | 108 | if(id >= CFG_MAX_EVENT) |
ericebert | 0:57690853989a | 109 | { |
ericebert | 0:57690853989a | 110 | return E_INVALID_ID; /* Invalid id,return error */ |
ericebert | 0:57690853989a | 111 | } |
ericebert | 0:57690853989a | 112 | #endif |
ericebert | 0:57690853989a | 113 | |
ericebert | 0:57690853989a | 114 | pecb = &EventTbl[id]; |
ericebert | 0:57690853989a | 115 | #if CFG_PAR_CHECKOUT_EN >0 |
ericebert | 0:57690853989a | 116 | if( pecb->eventType != EVENT_TYPE_QUEUE) |
ericebert | 0:57690853989a | 117 | { |
ericebert | 0:57690853989a | 118 | return E_INVALID_ID; /* The event is not queue,return error*/ |
ericebert | 0:57690853989a | 119 | } |
ericebert | 0:57690853989a | 120 | #endif |
ericebert | 0:57690853989a | 121 | pqcb = (P_QCB)pecb->eventPtr; /* Point at queue control block */ |
ericebert | 0:57690853989a | 122 | err = DeleteEvent(pecb,opt); /* Delete the event control block */ |
ericebert | 0:57690853989a | 123 | if(err == E_OK) /* If the event block have been deleted */ |
ericebert | 0:57690853989a | 124 | { |
ericebert | 0:57690853989a | 125 | QueueIDVessel &= ~((U32)(1<<(pqcb->id))); /* Update free queue list */ |
ericebert | 0:57690853989a | 126 | pqcb->qStart = 0; |
ericebert | 0:57690853989a | 127 | pqcb->id = 0; |
ericebert | 0:57690853989a | 128 | pqcb->head = 0; |
ericebert | 0:57690853989a | 129 | pqcb->tail = 0; |
ericebert | 0:57690853989a | 130 | pqcb->qMaxSize = 0; |
ericebert | 0:57690853989a | 131 | pqcb->qSize = 0; |
ericebert | 0:57690853989a | 132 | } |
ericebert | 0:57690853989a | 133 | return err; |
ericebert | 0:57690853989a | 134 | } |
ericebert | 0:57690853989a | 135 | |
ericebert | 0:57690853989a | 136 | |
ericebert | 0:57690853989a | 137 | |
ericebert | 0:57690853989a | 138 | /** |
ericebert | 0:57690853989a | 139 | ******************************************************************************* |
ericebert | 0:57690853989a | 140 | * @brief Accept a mail from queue |
ericebert | 0:57690853989a | 141 | * @param[in] id Event ID. |
ericebert | 0:57690853989a | 142 | * @param[out] perr A pointer to error code. |
ericebert | 0:57690853989a | 143 | * @retval 0 |
ericebert | 0:57690853989a | 144 | * @retval A pointer to mail accepted. |
ericebert | 0:57690853989a | 145 | * |
ericebert | 0:57690853989a | 146 | * @par Description |
ericebert | 0:57690853989a | 147 | * @details This function is called to accept a mail from queue. |
ericebert | 0:57690853989a | 148 | * @note |
ericebert | 0:57690853989a | 149 | ******************************************************************************* |
ericebert | 0:57690853989a | 150 | */ |
ericebert | 0:57690853989a | 151 | void* CoAcceptQueueMail(OS_EventID id,StatusType* perr) |
ericebert | 0:57690853989a | 152 | { |
ericebert | 0:57690853989a | 153 | P_ECB pecb; |
ericebert | 0:57690853989a | 154 | P_QCB pqcb; |
ericebert | 0:57690853989a | 155 | void* pmail; |
ericebert | 0:57690853989a | 156 | #if CFG_PAR_CHECKOUT_EN >0 |
ericebert | 0:57690853989a | 157 | if(id >= CFG_MAX_EVENT) |
ericebert | 0:57690853989a | 158 | { |
ericebert | 0:57690853989a | 159 | *perr = E_INVALID_ID; /* Invalid id,return error */ |
ericebert | 0:57690853989a | 160 | return 0; |
ericebert | 0:57690853989a | 161 | } |
ericebert | 0:57690853989a | 162 | #endif |
ericebert | 0:57690853989a | 163 | |
ericebert | 0:57690853989a | 164 | pecb = &EventTbl[id]; |
ericebert | 0:57690853989a | 165 | #if CFG_PAR_CHECKOUT_EN >0 |
ericebert | 0:57690853989a | 166 | if(pecb->eventType != EVENT_TYPE_QUEUE)/* Invalid event control block type*/ |
ericebert | 0:57690853989a | 167 | { |
ericebert | 0:57690853989a | 168 | *perr = E_INVALID_ID; |
ericebert | 0:57690853989a | 169 | return 0; |
ericebert | 0:57690853989a | 170 | } |
ericebert | 0:57690853989a | 171 | #endif |
ericebert | 0:57690853989a | 172 | pqcb = (P_QCB)pecb->eventPtr; /* Point at queue control block */ |
ericebert | 0:57690853989a | 173 | OsSchedLock(); |
ericebert | 0:57690853989a | 174 | if(pqcb->qSize != 0) /* If there are any messages in the queue */ |
ericebert | 0:57690853989a | 175 | { |
ericebert | 0:57690853989a | 176 | /* Extract oldest message from the queue */ |
ericebert | 0:57690853989a | 177 | pmail = *(pqcb->qStart + pqcb->head); |
ericebert | 0:57690853989a | 178 | pqcb->head++; /* Update the queue head */ |
ericebert | 0:57690853989a | 179 | pqcb->qSize--; /* Update the number of messages in the queue */ |
ericebert | 0:57690853989a | 180 | if(pqcb->head == pqcb->qMaxSize) |
ericebert | 0:57690853989a | 181 | { |
ericebert | 0:57690853989a | 182 | pqcb->head = 0; |
ericebert | 0:57690853989a | 183 | } |
ericebert | 0:57690853989a | 184 | OsSchedUnlock(); |
ericebert | 0:57690853989a | 185 | *perr = E_OK; |
ericebert | 0:57690853989a | 186 | return pmail; /* Return message received */ |
ericebert | 0:57690853989a | 187 | } |
ericebert | 0:57690853989a | 188 | else /* If there is no message in the queue*/ |
ericebert | 0:57690853989a | 189 | { |
ericebert | 0:57690853989a | 190 | OsSchedUnlock(); |
ericebert | 0:57690853989a | 191 | *perr = E_QUEUE_EMPTY; |
ericebert | 0:57690853989a | 192 | return 0; /* Return 0 */ |
ericebert | 0:57690853989a | 193 | } |
ericebert | 0:57690853989a | 194 | } |
ericebert | 0:57690853989a | 195 | |
ericebert | 0:57690853989a | 196 | |
ericebert | 0:57690853989a | 197 | |
ericebert | 0:57690853989a | 198 | /** |
ericebert | 0:57690853989a | 199 | ******************************************************************************* |
ericebert | 0:57690853989a | 200 | * @brief Pend for a mail |
ericebert | 0:57690853989a | 201 | * @param[in] id Event ID. |
ericebert | 0:57690853989a | 202 | * @param[in] timeout The longest time for writting mail. |
ericebert | 0:57690853989a | 203 | * @param[out] perr A pointer to error code. |
ericebert | 0:57690853989a | 204 | * @retval 0 |
ericebert | 0:57690853989a | 205 | * @retval A pointer to mail accept. |
ericebert | 0:57690853989a | 206 | * |
ericebert | 0:57690853989a | 207 | * @par Description |
ericebert | 0:57690853989a | 208 | * @details This function is called to wait for a mail. |
ericebert | 0:57690853989a | 209 | * @note |
ericebert | 0:57690853989a | 210 | ******************************************************************************* |
ericebert | 0:57690853989a | 211 | */ |
ericebert | 0:57690853989a | 212 | void* CoPendQueueMail(OS_EventID id,U32 timeout,StatusType* perr) |
ericebert | 0:57690853989a | 213 | { |
ericebert | 0:57690853989a | 214 | P_ECB pecb; |
ericebert | 0:57690853989a | 215 | P_QCB pqcb; |
ericebert | 0:57690853989a | 216 | P_OSTCB curTCB; |
ericebert | 0:57690853989a | 217 | void* pmail; |
ericebert | 0:57690853989a | 218 | if(OSIntNesting > 0) /* If the caller is ISR */ |
ericebert | 0:57690853989a | 219 | { |
ericebert | 0:57690853989a | 220 | *perr = E_CALL; |
ericebert | 0:57690853989a | 221 | return 0; |
ericebert | 0:57690853989a | 222 | } |
ericebert | 0:57690853989a | 223 | #if CFG_PAR_CHECKOUT_EN >0 |
ericebert | 0:57690853989a | 224 | if(id >= CFG_MAX_EVENT) |
ericebert | 0:57690853989a | 225 | { |
ericebert | 0:57690853989a | 226 | *perr = E_INVALID_ID; /* Invalid event id,return error */ |
ericebert | 0:57690853989a | 227 | return 0; |
ericebert | 0:57690853989a | 228 | } |
ericebert | 0:57690853989a | 229 | #endif |
ericebert | 0:57690853989a | 230 | |
ericebert | 0:57690853989a | 231 | pecb = &EventTbl[id]; |
ericebert | 0:57690853989a | 232 | #if CFG_PAR_CHECKOUT_EN >0 |
ericebert | 0:57690853989a | 233 | if(pecb->eventType != EVENT_TYPE_QUEUE) /* The event type is not queue */ |
ericebert | 0:57690853989a | 234 | { |
ericebert | 0:57690853989a | 235 | *perr = E_INVALID_ID; |
ericebert | 0:57690853989a | 236 | return 0; |
ericebert | 0:57690853989a | 237 | } |
ericebert | 0:57690853989a | 238 | #endif |
ericebert | 0:57690853989a | 239 | if(OSSchedLock != 0) /* Judge schedule is locked or not? */ |
ericebert | 0:57690853989a | 240 | { |
ericebert | 0:57690853989a | 241 | *perr = E_OS_IN_LOCK; /* Schedule is locked,return error */ |
ericebert | 0:57690853989a | 242 | return 0; |
ericebert | 0:57690853989a | 243 | } |
ericebert | 0:57690853989a | 244 | pqcb = (P_QCB)pecb->eventPtr; /* Point at queue control block */ |
ericebert | 0:57690853989a | 245 | |
ericebert | 0:57690853989a | 246 | if(pqcb->qSize != 0) /* If there are any messages in the queue */ |
ericebert | 0:57690853989a | 247 | { |
ericebert | 0:57690853989a | 248 | /* Extract oldest message from the queue */ |
ericebert | 0:57690853989a | 249 | pmail = *(pqcb->qStart + pqcb->head); |
ericebert | 0:57690853989a | 250 | pqcb->head++; /* Update the queue head */ |
ericebert | 0:57690853989a | 251 | pqcb->qSize--; /* Update the number of messages in the queue */ |
ericebert | 0:57690853989a | 252 | if(pqcb->head == pqcb->qMaxSize)/* Check queue head */ |
ericebert | 0:57690853989a | 253 | { |
ericebert | 0:57690853989a | 254 | pqcb->head = 0; |
ericebert | 0:57690853989a | 255 | } |
ericebert | 0:57690853989a | 256 | *perr = E_OK; |
ericebert | 0:57690853989a | 257 | return pmail; /* Return message received */ |
ericebert | 0:57690853989a | 258 | } |
ericebert | 0:57690853989a | 259 | else /* If there is no message in the queue*/ |
ericebert | 0:57690853989a | 260 | { |
ericebert | 0:57690853989a | 261 | curTCB = TCBRunning; |
ericebert | 0:57690853989a | 262 | if(timeout == 0) /* If time-out is not configured */ |
ericebert | 0:57690853989a | 263 | { |
ericebert | 0:57690853989a | 264 | /* Block current task until the event occur */ |
ericebert | 0:57690853989a | 265 | EventTaskToWait(pecb,curTCB); |
ericebert | 0:57690853989a | 266 | |
ericebert | 0:57690853989a | 267 | /* Have recived message or the queue have been deleted */ |
ericebert | 0:57690853989a | 268 | pmail = curTCB->pmail; |
ericebert | 0:57690853989a | 269 | curTCB->pmail = 0; |
ericebert | 0:57690853989a | 270 | *perr = E_OK; |
ericebert | 0:57690853989a | 271 | return pmail; /* Return message received or 0 */ |
ericebert | 0:57690853989a | 272 | } |
ericebert | 0:57690853989a | 273 | else /* If time-out is configured */ |
ericebert | 0:57690853989a | 274 | { |
ericebert | 0:57690853989a | 275 | OsSchedLock(); |
ericebert | 0:57690853989a | 276 | |
ericebert | 0:57690853989a | 277 | /* Block current task until event or timeout occurs */ |
ericebert | 0:57690853989a | 278 | EventTaskToWait(pecb,curTCB); |
ericebert | 0:57690853989a | 279 | InsertDelayList(curTCB,timeout); |
ericebert | 0:57690853989a | 280 | OsSchedUnlock(); |
ericebert | 0:57690853989a | 281 | if(curTCB->pmail == 0) /* If time-out occurred */ |
ericebert | 0:57690853989a | 282 | { |
ericebert | 0:57690853989a | 283 | *perr = E_TIMEOUT; |
ericebert | 0:57690853989a | 284 | return 0; |
ericebert | 0:57690853989a | 285 | } |
ericebert | 0:57690853989a | 286 | else /* If event occured */ |
ericebert | 0:57690853989a | 287 | { |
ericebert | 0:57690853989a | 288 | pmail = curTCB->pmail; |
ericebert | 0:57690853989a | 289 | curTCB->pmail = 0; |
ericebert | 0:57690853989a | 290 | *perr = E_OK; |
ericebert | 0:57690853989a | 291 | return pmail; /* Return message received or 0 */ |
ericebert | 0:57690853989a | 292 | } |
ericebert | 0:57690853989a | 293 | } |
ericebert | 0:57690853989a | 294 | } |
ericebert | 0:57690853989a | 295 | } |
ericebert | 0:57690853989a | 296 | |
ericebert | 0:57690853989a | 297 | |
ericebert | 0:57690853989a | 298 | |
ericebert | 0:57690853989a | 299 | /** |
ericebert | 0:57690853989a | 300 | ******************************************************************************* |
ericebert | 0:57690853989a | 301 | * @brief Post a mail to queue |
ericebert | 0:57690853989a | 302 | * @param[in] id Event ID. |
ericebert | 0:57690853989a | 303 | * @param[in] pmail Pointer to mail that want to send. |
ericebert | 0:57690853989a | 304 | * @param[out] None |
ericebert | 0:57690853989a | 305 | * @retval E_OK |
ericebert | 0:57690853989a | 306 | * @retval E_INVALID_ID |
ericebert | 0:57690853989a | 307 | * @retval E_QUEUE_FULL |
ericebert | 0:57690853989a | 308 | * |
ericebert | 0:57690853989a | 309 | * @par Description |
ericebert | 0:57690853989a | 310 | * @details This function is called to post a mail to queue. |
ericebert | 0:57690853989a | 311 | * @note |
ericebert | 0:57690853989a | 312 | ******************************************************************************* |
ericebert | 0:57690853989a | 313 | */ |
ericebert | 0:57690853989a | 314 | StatusType CoPostQueueMail(OS_EventID id,void* pmail) |
ericebert | 0:57690853989a | 315 | { |
ericebert | 0:57690853989a | 316 | P_ECB pecb; |
ericebert | 0:57690853989a | 317 | P_QCB pqcb; |
ericebert | 0:57690853989a | 318 | #if CFG_PAR_CHECKOUT_EN >0 |
ericebert | 0:57690853989a | 319 | if(id >= CFG_MAX_EVENT) |
ericebert | 0:57690853989a | 320 | { |
ericebert | 0:57690853989a | 321 | return E_INVALID_ID; |
ericebert | 0:57690853989a | 322 | } |
ericebert | 0:57690853989a | 323 | #endif |
ericebert | 0:57690853989a | 324 | |
ericebert | 0:57690853989a | 325 | pecb = &EventTbl[id]; |
ericebert | 0:57690853989a | 326 | #if CFG_PAR_CHECKOUT_EN >0 |
ericebert | 0:57690853989a | 327 | if(pecb->eventType != EVENT_TYPE_QUEUE) |
ericebert | 0:57690853989a | 328 | { |
ericebert | 0:57690853989a | 329 | return E_INVALID_ID; /* The event type isn't queue,return */ |
ericebert | 0:57690853989a | 330 | } |
ericebert | 0:57690853989a | 331 | #endif |
ericebert | 0:57690853989a | 332 | pqcb = (P_QCB)pecb->eventPtr; |
ericebert | 0:57690853989a | 333 | if(pqcb->qSize == pqcb->qMaxSize) /* If queue is full */ |
ericebert | 0:57690853989a | 334 | { |
ericebert | 0:57690853989a | 335 | return E_QUEUE_FULL; |
ericebert | 0:57690853989a | 336 | } |
ericebert | 0:57690853989a | 337 | else /* If queue is not full */ |
ericebert | 0:57690853989a | 338 | { |
ericebert | 0:57690853989a | 339 | OsSchedLock(); |
ericebert | 0:57690853989a | 340 | *(pqcb->qStart + pqcb->tail) = pmail; /* Insert message into queue */ |
ericebert | 0:57690853989a | 341 | pqcb->tail++; /* Update queue tail */ |
ericebert | 0:57690853989a | 342 | pqcb->qSize++; /* Update the number of messages in the queue */ |
ericebert | 0:57690853989a | 343 | if(pqcb->tail == pqcb->qMaxSize) /* Check queue tail */ |
ericebert | 0:57690853989a | 344 | { |
ericebert | 0:57690853989a | 345 | pqcb->tail = 0; |
ericebert | 0:57690853989a | 346 | } |
ericebert | 0:57690853989a | 347 | EventTaskToRdy(pecb); /* Check the event waiting list */ |
ericebert | 0:57690853989a | 348 | OsSchedUnlock(); |
ericebert | 0:57690853989a | 349 | return E_OK; |
ericebert | 0:57690853989a | 350 | } |
ericebert | 0:57690853989a | 351 | } |
ericebert | 0:57690853989a | 352 | |
ericebert | 0:57690853989a | 353 | |
ericebert | 0:57690853989a | 354 | /** |
ericebert | 0:57690853989a | 355 | ******************************************************************************* |
ericebert | 0:57690853989a | 356 | * @brief Post a mail to queue in ISR |
ericebert | 0:57690853989a | 357 | * @param[in] id Event ID. |
ericebert | 0:57690853989a | 358 | * @param[in] pmail Pointer to mail that want to send. |
ericebert | 0:57690853989a | 359 | * @param[out] None |
ericebert | 0:57690853989a | 360 | * @retval E_OK |
ericebert | 0:57690853989a | 361 | * @retval E_INVALID_ID |
ericebert | 0:57690853989a | 362 | * @retval E_QUEUE_FULL |
ericebert | 0:57690853989a | 363 | * |
ericebert | 0:57690853989a | 364 | * @par Description |
ericebert | 0:57690853989a | 365 | * @details This function is called in ISR to post a mail to queue. |
ericebert | 0:57690853989a | 366 | * @note |
ericebert | 0:57690853989a | 367 | ******************************************************************************* |
ericebert | 0:57690853989a | 368 | */ |
ericebert | 0:57690853989a | 369 | #if CFG_MAX_SERVICE_REQUEST > 0 |
ericebert | 0:57690853989a | 370 | StatusType isr_PostQueueMail(OS_EventID id,void* pmail) |
ericebert | 0:57690853989a | 371 | { |
ericebert | 0:57690853989a | 372 | if(OSSchedLock > 0) /* If scheduler is locked,(the caller is ISR) */ |
ericebert | 0:57690853989a | 373 | { |
ericebert | 0:57690853989a | 374 | /* Insert the request into service request queue */ |
ericebert | 0:57690853989a | 375 | if(InsertInSRQ(QUEUE_REQ,id,pmail) == FALSE) |
ericebert | 0:57690853989a | 376 | { |
ericebert | 0:57690853989a | 377 | return E_SEV_REQ_FULL; /* If service request queue is full */ |
ericebert | 0:57690853989a | 378 | } |
ericebert | 0:57690853989a | 379 | else /* If the request have been inserted into service request queue */ |
ericebert | 0:57690853989a | 380 | { |
ericebert | 0:57690853989a | 381 | return E_OK; |
ericebert | 0:57690853989a | 382 | } |
ericebert | 0:57690853989a | 383 | } |
ericebert | 0:57690853989a | 384 | else /* The scheduler is unlocked */ |
ericebert | 0:57690853989a | 385 | { |
ericebert | 0:57690853989a | 386 | return(CoPostQueueMail(id,pmail)); /* Send the message to the queue*/ |
ericebert | 0:57690853989a | 387 | } |
ericebert | 0:57690853989a | 388 | } |
ericebert | 0:57690853989a | 389 | #endif |
ericebert | 0:57690853989a | 390 | |
ericebert | 0:57690853989a | 391 | #endif |