📄 os_q.lst
字号:
187 * applications where the queue is used for mutual exclusion because the resource(s)
188 * will no longer be guarded by the queue.
189 * 5) If the storage for the message queue was allocated dynamically (i.e. //using a malloc()
190 * type call) then your application MUST release the memory storage by call the counterpart
191 * call of the dynamic allocation scheme used. If the queue storage was created statically
192 * then, the storage can be reused.
193 *********************************************************************************************************
194 */
195
196 #if OS_Q_DEL_EN > 0
197 OS_EVENT *OSQDel (OS_EVENT *pevent, INT8U opt, INT8U *err) reentrant //using 0
198 {
199 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
200 1 OS_CPU_SR cpu_sr;
201 1 #endif
202 1 BOOLEAN tasks_waiting;
203 1 OS_Q *pq;
204 1
205 1
206 1 if (OSIntNesting > 0) { /* See if called from ISR ... */
207 2 *err = OS_ERR_DEL_ISR; /* ... can't DELETE from an ISR */
208 2 return ((OS_EVENT *)0);
209 2 }
210 1 #if OS_ARG_CHK_EN > 0
211 1 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
212 2 *err = OS_ERR_PEVENT_NULL;
213 2 return (pevent);
214 2 }
215 1 #endif
216 1 if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
217 2 *err = OS_ERR_EVENT_TYPE;
218 2 return (pevent);
219 2 }
220 1 OS_ENTER_CRITICAL();
221 1 if (pevent->OSEventGrp != 0x00) { /* See if any tasks waiting on queue */
222 2 tasks_waiting = TRUE; /* Yes */
223 2 } else {
224 2 tasks_waiting = FALSE; /* No */
225 2 }
226 1 switch (opt) {
227 2 case OS_DEL_NO_PEND: /* Delete queue only if no task waiting */
228 2 if (tasks_waiting == FALSE) {
229 3 #if OS_EVENT_NAME_SIZE > 0
230 3 (void)strcpy(pevent->OSEventName, "?"); /* Unknown name */
231 3 #endif
232 3 pq = (OS_Q *)pevent->OSEventPtr; /* Return OS_Q to free list */
233 3 pq->OSQPtr = OSQFreeList;
234 3 OSQFreeList = pq;
235 3 pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
236 3 pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block to free list */
237 3 pevent->OSEventCnt = 0;
238 3 OSEventFreeList = pevent; /* Get next free event control block */
239 3 OS_EXIT_CRITICAL();
240 3 *err = OS_NO_ERR;
C51 COMPILER V7.06 OS_Q 07/18/2003 11:06:02 PAGE 5
241 3 return ((OS_EVENT *)0); /* Queue has been deleted */
242 3 } else {
243 3 OS_EXIT_CRITICAL();
244 3 *err = OS_ERR_TASK_WAITING;
245 3 return (pevent);
246 3 }
247 2
248 2 case OS_DEL_ALWAYS: /* Always delete the queue */
249 2 while (pevent->OSEventGrp != 0x00) { /* Ready ALL tasks waiting for queue */
250 3 OS_EventTaskRdy(pevent, (void *)0, OS_STAT_Q);
251 3 }
252 2 #if OS_EVENT_NAME_SIZE > 0
253 2 (void)strcpy(pevent->OSEventName, "?"); /* Unknown name */
254 2 #endif
255 2 pq = (OS_Q *)pevent->OSEventPtr; /* Return OS_Q to free list */
256 2 pq->OSQPtr = OSQFreeList;
257 2 OSQFreeList = pq;
258 2 pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
259 2 pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block to free list */
260 2 pevent->OSEventCnt = 0;
261 2 OSEventFreeList = pevent; /* Get next free event control block */
262 2 OS_EXIT_CRITICAL();
263 2 if (tasks_waiting == TRUE) { /* Reschedule only if task(s) were waiting */
264 3 OS_Sched(); /* Find highest priority task ready to run */
265 3 }
266 2 *err = OS_NO_ERR;
267 2 return ((OS_EVENT *)0); /* Queue has been deleted */
268 2
269 2 default:
270 2 OS_EXIT_CRITICAL();
271 2 *err = OS_ERR_INVALID_OPT;
272 2 return (pevent);
273 2 }
274 1 }
275 #endif
276
277 /*$PAGE*/
278 /*
279 *********************************************************************************************************
280 * FLUSH QUEUE
281 *
282 * Description : This function is used to flush the contents of the message queue.
283 *
284 * Arguments : none
285 *
286 * Returns : OS_NO_ERR upon success
287 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue
288 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
289 *
290 * WARNING : You should use this function with great care because, when to flush the queue, you LOOSE
291 * the references to what the queue entries are pointing to and thus, you could cause
292 * 'memory leaks'. In other words, the data you are pointing to that's being referenced
293 * by the queue entries should, most likely, need to be de-allocated (i.e. freed).
294 *********************************************************************************************************
295 */
296
297 #if OS_Q_FLUSH_EN > 0
298 INT8U OSQFlush (OS_EVENT *pevent) reentrant //using 0
299 {
300 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
301 1 OS_CPU_SR cpu_sr;
302 1 #endif
C51 COMPILER V7.06 OS_Q 07/18/2003 11:06:02 PAGE 6
303 1 OS_Q *pq;
304 1
305 1
306 1 #if OS_ARG_CHK_EN > 0
307 1 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
308 2 return (OS_ERR_PEVENT_NULL);
309 2 }
310 1 if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
311 2 return (OS_ERR_EVENT_TYPE);
312 2 }
313 1 #endif
314 1 OS_ENTER_CRITICAL();
315 1 pq = (OS_Q *)pevent->OSEventPtr; /* Point to queue storage structure */
316 1 pq->OSQIn = pq->OSQStart;
317 1 pq->OSQOut = pq->OSQStart;
318 1 pq->OSQEntries = 0;
319 1 OS_EXIT_CRITICAL();
320 1 return (OS_NO_ERR);
321 1 }
322 #endif
323
324 /*$PAGE*/
325 /*
326 *********************************************************************************************************
327 * PEND ON A QUEUE FOR A MESSAGE
328 *
329 * Description: This function waits for a message to be sent to a queue
330 *
331 * Arguments : pevent is a pointer to the event control block associated with the desired queue
332 *
333 * timeout is an optional timeout period (in clock ticks). If non-zero, your task will
334 * wait for a message to arrive at the queue up to the amount of time
335 * specified by this argument. If you specify 0, however, your task will wait
336 * forever at the specified queue or, until a message arrives.
337 *
338 * err is a pointer to where an error message will be deposited. Possible error
339 * messages are:
340 *
341 * OS_NO_ERR The call was successful and your task received a
342 * message.
343 * OS_TIMEOUT A message was not received within the specified timeout
344 * OS_ERR_EVENT_TYPE You didn't pass a pointer to a queue
345 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
346 * OS_ERR_PEND_ISR If you called this function from an ISR and the result
347 * would lead to a suspension.
348 *
349 * Returns : != (void *)0 is a pointer to the message received
350 * == (void *)0 if you received a NULL pointer message or,
351 * if no message was received or,
352 * if 'pevent' is a NULL pointer or,
353 * if you didn't pass a pointer to a queue.
354 *
355 * Note(s) : As of V2.60, this function allows you to receive NULL pointer messages.
356 *********************************************************************************************************
357 */
358
359 void *OSQPend (OS_EVENT *pevent, INT16U timeout, INT8U *err) reentrant //using 0
360 {
361 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
362 1 OS_CPU_SR cpu_sr;
363 1 #endif
364 1 void *msg;
C51 COMPILER V7.06 OS_Q 07/18/2003 11:06:02 PAGE 7
365 1 OS_Q *pq;
366 1
367 1
368 1 if (OSIntNesting > 0) { /* See if called from ISR ... */
369 2 *err = OS_ERR_PEND_ISR; /* ... can't PEND from an ISR */
370 2 return ((void *)0);
371 2 }
372 1 #if OS_ARG_CHK_EN > 0
373 1 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
374 2 *err = OS_ERR_PEVENT_NULL;
375 2 return ((void *)0);
376 2 }
377 1 if (pevent->OSEventType != OS_EVENT_TYPE_Q) {/* Validate event block type */
378 2 *err = OS_ERR_EVENT_TYPE;
379 2 return ((void *)0);
380 2 }
381 1 #endif
382 1 OS_ENTER_CRITICAL();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -