📄 os_q.s43
字号:
NAME os_q(16)
RSEG CODE(1)
EXTERN OSEventFreeList
EXTERN OSIntNesting
PUBLIC OSQAccept
PUBLIC OSQCreate
PUBLIC OSQDel
PUBLIC OSQFlush
EXTERN OSQFreeList
PUBLIC OSQPend
PUBLIC OSQPost
PUBLIC OSQPostFront
PUBLIC OSQPostOpt
PUBLIC OSQQuery
EXTERN OSQTbl
EXTERN OSTCBCur
EXTERN OS_EventTO
EXTERN OS_EventTaskRdy
EXTERN OS_EventTaskWait
EXTERN OS_EventWaitListInit
PUBLIC OS_QInit
EXTERN OS_Sched
EXTERN ?CL430_1_26_L08
RSEG CODE
OSQAccept:
; 1. /*
; 2. *********************************************************************************************************
; 3. * uC/OS-II
; 4. * The Real-Time Kernel
; 5. * MESSAGE QUEUE MANAGEMENT
; 6. *
; 7. * (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
; 8. * All Rights Reserved
; 9. *
; 10. * File : OS_Q.C
; 11. * By : Jean J. Labrosse
; 12. *********************************************************************************************************
; 13. */
; 14.
; 15. #ifndef OS_MASTER_FILE
; 16. #include "includes.h"
; 17. #endif
; 18.
; 19. #if (OS_Q_EN > 0) && (OS_MAX_QS > 0)
; 20. /*
; 21. *********************************************************************************************************
; 22. * ACCEPT MESSAGE FROM QUEUE
; 23. *
; 24. * Description: This function checks the queue to see if a message is available. Unlike OSQPend(),
; 25. * OSQAccept() does not suspend the calling task if a message is not available.
; 26. *
; 27. * Arguments : pevent is a pointer to the event control block
; 28. *
; 29. * Returns : != (void *)0 is the message in the queue if one is available. The message is removed
; 30. * from the so the next time OSQAccept() is called, the queue will contain
; 31. * one less entry.
; 32. * == (void *)0 if the queue is empty or,
; 33. * if 'pevent' is a NULL pointer or,
; 34. * if you passed an invalid event type
; 35. *********************************************************************************************************
; 36. */
; 37.
; 38. #if OS_Q_ACCEPT_EN > 0
; 39. void *OSQAccept (OS_EVENT *pevent)
; 40. {
; 41. #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; 42. OS_CPU_SR cpu_sr;
; 43. #endif
; 44. void *msg;
; 45. OS_Q *pq;
; 46.
; 47.
; 48. #if OS_ARG_CHK_EN > 0
; 49. if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
CMP #0,R12
JNE (?0059)
; 50. return ((void *)0);
; 51. }
RET
?0059:
; 52. if (pevent->OSEventType != OS_EVENT_TYPE_Q) {/* Validate event block type */
MOV.B #2,R13
CMP.B @R12,R13
JEQ (?0061)
; 53. return ((void *)0);
MOV #0,R12
; 54. }
RET
?0061:
; 55. #endif
; 56. OS_ENTER_CRITICAL();
DINT
; 57. pq = (OS_Q *)pevent->OSEventPtr; /* Point at queue control block */
MOV 4(R12),R13
; 58. if (pq->OSQEntries > 0) { /* See if any messages in the queue */
CMP #0,12(R13)
JEQ (?0063)
; 59. msg = *pq->OSQOut++; /* Yes, extract oldest message from the queue */
MOV 8(R13),R14
ADD #2,8(R13)
MOV @R14,R12
; 60. pq->OSQEntries--; /* Update the number of entries in the queue */
ADD #-1,12(R13)
; 61. if (pq->OSQOut == pq->OSQEnd) { /* Wrap OUT pointer if we are at the end of the queue */
CMP 8(R13),4(R13)
JNE (?0066)
; 62. pq->OSQOut = pq->OSQStart;
MOV 2(R13),8(R13)
; 63. }
; 64. } else {
JMP (?0066)
?0063:
; 65. msg = (void *)0; /* Queue is empty */
MOV #0,R12
?0066:
; 66. }
; 67. OS_EXIT_CRITICAL();
EINT
; 68. return (msg); /* Return message received (or NULL) */
; 69. }
RET
OSQCreate:
; 70. #endif
; 71. /*$PAGE*/
; 72. /*
; 73. *********************************************************************************************************
; 74. * CREATE A MESSAGE QUEUE
; 75. *
; 76. * Description: This function creates a message queue if free event control blocks are available.
; 77. *
; 78. * Arguments : start is a pointer to the base address of the message queue storage area. The
; 79. * storage area MUST be declared as an array of pointers to 'void' as follows
; 80. *
; 81. * void *MessageStorage[size]
; 82. *
; 83. * size is the number of elements in the storage area
; 84. *
; 85. * Returns : != (OS_EVENT *)0 is a pointer to the event control clock (OS_EVENT) associated with the
; 86. * created queue
; 87. * == (OS_EVENT *)0 if no event control blocks were available or an error was detected
; 88. *********************************************************************************************************
; 89. */
; 90.
; 91. OS_EVENT *OSQCreate (void **start, INT16U size)
; 92. {
PUSH R10
; 93. #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; 94. OS_CPU_SR cpu_sr;
; 95. #endif
; 96. OS_EVENT *pevent;
; 97. OS_Q *pq;
; 98.
; 99.
; 100. if (OSIntNesting > 0) { /* See if called from ISR ... */
CMP.B #0,&OSIntNesting
JEQ (?0069)
; 101. return ((OS_EVENT *)0); /* ... can't CREATE from an ISR */
MOV #0,R12
; 102. }
JMP (?0077)
?0069:
; 103. OS_ENTER_CRITICAL();
DINT
; 104. pevent = OSEventFreeList; /* Get next free event control block */
MOV &OSEventFreeList,R10
; 105. if (OSEventFreeList != (OS_EVENT *)0) { /* See if pool of free ECB pool was empty */
CMP #0,&OSEventFreeList
JEQ (?0071)
; 106. OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
MOV &OSEventFreeList,R13
MOV 4(R13),&OSEventFreeList
?0071:
; 107. }
; 108. OS_EXIT_CRITICAL();
EINT
; 109. if (pevent != (OS_EVENT *)0) { /* See if we have an event control block */
CMP #0,R10
JEQ (?0076)
; 110. OS_ENTER_CRITICAL();
DINT
; 111. pq = OSQFreeList; /* Get a free queue control block */
MOV &OSQFreeList,R13
; 112. if (pq != (OS_Q *)0) { /* Were we able to get a queue control block ? */
CMP #0,R13
JEQ (?0075)
; 113. OSQFreeList = OSQFreeList->OSQPtr; /* Yes, Adjust free list pointer to next free*/
MOV &OSQFreeList,R15
MOV @R15,&OSQFreeList
; 114. OS_EXIT_CRITICAL();
EINT
; 115. pq->OSQStart = start; /* Initialize the queue */
MOV R12,2(R13)
; 116. pq->OSQEnd = &start[size];
MOV R14,R15
ADD R15,R15
ADD R12,R15
MOV R15,4(R13)
; 117. pq->OSQIn = start;
MOV R12,6(R13)
; 118. pq->OSQOut = start;
MOV R12,8(R13)
; 119. pq->OSQSize = size;
MOV R14,10(R13)
; 120. pq->OSQEntries = 0;
MOV #0,12(R13)
; 121. pevent->OSEventType = OS_EVENT_TYPE_Q;
MOV.B #2,0(R10)
; 122. pevent->OSEventCnt = 0;
MOV #0,2(R10)
; 123. pevent->OSEventPtr = pq;
MOV R13,4(R10)
; 124. OS_EventWaitListInit(pevent); /* Initalize the wait list */
MOV R10,R12
CALL #OS_EventWaitListInit
; 125. } else {
JMP (?0076)
?0075:
; 126. pevent->OSEventPtr = (void *)OSEventFreeList; /* No, Return event control block on error */
MOV &OSEventFreeList,4(R10)
; 127. OSEventFreeList = pevent;
MOV R10,&OSEventFreeList
; 128. OS_EXIT_CRITICAL();
EINT
; 129. pevent = (OS_EVENT *)0;
MOV #0,R10
?0076:
; 130. }
; 131. }
; 132. return (pevent);
MOV R10,R12
; 133. }
?0077:
POP R10
RET
OSQDel:
; 134. /*$PAGE*/
; 135. /*
; 136. *********************************************************************************************************
; 137. * DELETE A MESSAGE QUEUE
; 138. *
; 139. * Description: This function deletes a message queue and readies all tasks pending on the queue.
; 140. *
; 141. * Arguments : pevent is a pointer to the event control block associated with the desired
; 142. * queue.
; 143. *
; 144. * opt determines delete options as follows:
; 145. * opt == OS_DEL_NO_PEND Delete the queue ONLY if no task pending
; 146. * opt == OS_DEL_ALWAYS Deletes the queue even if tasks are waiting.
; 147. * In this case, all the tasks pending will be readied.
; 148. *
; 149. * err is a pointer to an error code that can contain one of the following values:
; 150. * OS_NO_ERR The call was successful and the queue was deleted
; 151. * OS_ERR_DEL_ISR If you tried to delete the queue from an ISR
; 152. * OS_ERR_INVALID_OPT An invalid option was specified
; 153. * OS_ERR_TASK_WAITING One or more tasks were waiting on the queue
; 154. * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue
; 155. * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
; 156. *
; 157. * Returns : pevent upon error
; 158. * (OS_EVENT *)0 if the queue was successfully deleted.
; 159. *
; 160. * Note(s) : 1) This function must be used with care. Tasks that would normally expect the presence of
; 161. * the queue MUST check the return code of OSQPend().
; 162. * 2) OSQAccept() callers will not know that the intended queue has been deleted unless
; 163. * they check 'pevent' to see that it's a NULL pointer.
; 164. * 3) This call can potentially disable interrupts for a long time. The interrupt disable
; 165. * time is directly proportional to the number of tasks waiting on the queue.
; 166. * 4) Because ALL tasks pending on the queue will be readied, you MUST be careful in
; 167. * applications where the queue is used for mutual exclusion because the resource(s)
; 168. * will no longer be guarded by the queue.
; 169. * 5) If the storage for the message queue was allocated dynamically (i.e. using a malloc()
; 170. * type call) then your application MUST release the memory storage by call the counterpart
; 171. * call of the dynamic allocation scheme used. If the queue storage was created statically
; 172. * then, the storage can be reused.
; 173. *********************************************************************************************************
; 174. */
; 175.
; 176. #if OS_Q_DEL_EN > 0
; 177. OS_EVENT *OSQDel (OS_EVENT *pevent, INT8U opt, INT8U *err)
; 178. {
PUSH R10
PUSH R11
PUSH R8
MOV R12,R11
MOV 8(SP),R8
; 179. #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; 180. OS_CPU_SR cpu_sr;
; 181. #endif
; 182. BOOLEAN tasks_waiting;
; 183. OS_Q *pq;
; 184.
; 185.
; 186. if (OSIntNesting > 0) { /* See if called from ISR ... */
CMP.B #0,&OSIntNesting
JEQ (?0079)
; 187. *err = OS_ERR_DEL_ISR; /* ... can't DELETE from an ISR */
MOV.B #140,0(R8)
; 188. return ((OS_EVENT *)0);
MOV #0,R12
; 189. }
JMP (?0098)
?0079:
; 190. #if OS_ARG_CHK_EN > 0
; 191. if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
CMP #0,R11
JNE (?0081)
; 192. *err = OS_ERR_PEVENT_NULL;
MOV.B #4,0(R8)
; 193. return (pevent);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -