📄 os_mbox.s43
字号:
MOV.B #0,0(R11)
; 173. pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block to free list */
MOV &OSEventFreeList,4(R11)
; 174. OSEventFreeList = pevent; /* Get next free event control block */
MOV R11,&OSEventFreeList
; 175. OS_EXIT_CRITICAL();
EINT
; 176. *err = OS_NO_ERR;
MOV.B #0,0(R8)
; 177. return ((OS_EVENT *)0); /* Mailbox has been deleted */
MOV #0,R12
; 178. } else {
JMP (?0088)
?0080:
; 179. OS_EXIT_CRITICAL();
EINT
; 180. *err = OS_ERR_TASK_WAITING;
MOV.B #8,0(R8)
; 181. return (pevent);
MOV R11,R12
; 182. }
JMP (?0088)
?0081:
; 183.
; 184. case OS_DEL_ALWAYS: /* Always delete the mailbox */
; 185. while (pevent->OSEventGrp != 0x00) { /* Ready ALL tasks waiting for mailbox */
CMP.B #0,1(R11)
JEQ (?0082)
; 186. OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MBOX);
PUSH.B #2
MOV #0,R14
MOV R11,R12
CALL #OS_EventTaskRdy
ADD #2,SP
JMP (?0081)
?0082:
; 187. }
; 188. pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
MOV.B #0,0(R11)
; 189. pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block to free list */
MOV &OSEventFreeList,4(R11)
; 190. OSEventFreeList = pevent; /* Get next free event control block */
MOV R11,&OSEventFreeList
; 191. OS_EXIT_CRITICAL();
EINT
; 192. if (tasks_waiting == TRUE) { /* Reschedule only if task(s) were waiting */
CMP.B #1,R10
JNE (?0086)
; 193. OS_Sched(); /* Find highest priority task ready to run */
CALL #OS_Sched
?0086:
; 194. }
; 195. *err = OS_NO_ERR;
MOV.B #0,0(R8)
; 196. return ((OS_EVENT *)0); /* Mailbox has been deleted */
MOV #0,R12
; 197.
; 198. default:
JMP (?0088)
?0087:
; 199. OS_EXIT_CRITICAL();
EINT
; 200. *err = OS_ERR_INVALID_OPT;
MOV.B #7,0(R8)
; 201. return (pevent);
MOV R11,R12
; 202. }
?0088:
POP R8
POP R11
POP R10
RET
?0077:
; 203. }
OSMboxPend:
; 204. #endif
; 205.
; 206. /*$PAGE*/
; 207. /*
; 208. *********************************************************************************************************
; 209. * PEND ON MAILBOX FOR A MESSAGE
; 210. *
; 211. * Description: This function waits for a message to be sent to a mailbox
; 212. *
; 213. * Arguments : pevent is a pointer to the event control block associated with the desired mailbox
; 214. *
; 215. * timeout is an optional timeout period (in clock ticks). If non-zero, your task will
; 216. * wait for a message to arrive at the mailbox up to the amount of time
; 217. * specified by this argument. If you specify 0, however, your task will wait
; 218. * forever at the specified mailbox or, until a message arrives.
; 219. *
; 220. * err is a pointer to where an error message will be deposited. Possible error
; 221. * messages are:
; 222. *
; 223. * OS_NO_ERR The call was successful and your task received a
; 224. * message.
; 225. * OS_TIMEOUT A message was not received within the specified timeout
; 226. * OS_ERR_EVENT_TYPE Invalid event type
; 227. * OS_ERR_PEND_ISR If you called this function from an ISR and the result
; 228. * would lead to a suspension.
; 229. * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
; 230. *
; 231. * Returns : != (void *)0 is a pointer to the message received
; 232. * == (void *)0 if no message was received or,
; 233. * if 'pevent' is a NULL pointer or,
; 234. * if you didn't pass the proper pointer to the event control block.
; 235. *********************************************************************************************************
; 236. */
; 237.
; 238. void *OSMboxPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)
; 239. {
PUSH R10
PUSH R11
MOV R12,R10
MOV 6(SP),R11
; 240. #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; 241. OS_CPU_SR cpu_sr;
; 242. #endif
; 243. void *msg;
; 244.
; 245.
; 246. if (OSIntNesting > 0) { /* See if called from ISR ... */
CMP.B #0,&OSIntNesting
JEQ (?0090)
; 247. *err = OS_ERR_PEND_ISR; /* ... can't PEND from an ISR */
MOV.B #2,0(R11)
; 248. return ((void *)0);
MOV #0,R12
; 249. }
JMP (?0099)
?0090:
; 250. #if OS_ARG_CHK_EN > 0
; 251. if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
CMP #0,R10
JNE (?0092)
; 252. *err = OS_ERR_PEVENT_NULL;
MOV.B #4,0(R11)
; 253. return ((void *)0);
MOV #0,R12
; 254. }
JMP (?0099)
?0092:
; 255. if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* Validate event block type */
MOV.B #1,R12
CMP.B @R10,R12
JEQ (?0094)
; 256. *err = OS_ERR_EVENT_TYPE;
MOV.B #1,0(R11)
; 257. return ((void *)0);
MOV #0,R12
; 258. }
JMP (?0099)
?0094:
; 259. #endif
; 260. OS_ENTER_CRITICAL();
DINT
; 261. msg = pevent->OSEventPtr;
MOV 4(R10),R12
; 262. if (msg != (void *)0) { /* See if there is already a message */
CMP #0,R12
JEQ (?0096)
; 263. pevent->OSEventPtr = (void *)0; /* Clear the mailbox */
MOV #0,4(R10)
; 264. OS_EXIT_CRITICAL();
EINT
; 265. *err = OS_NO_ERR;
MOV.B #0,0(R11)
; 266. return (msg); /* Return the message received (or NULL) */
; 267. }
JMP (?0099)
?0096:
; 268. OSTCBCur->OSTCBStat |= OS_STAT_MBOX; /* Message not available, task will pend */
MOV &OSTCBCur,R12
BIS.B #2,28(R12)
; 269. OSTCBCur->OSTCBDly = timeout; /* Load timeout in TCB */
MOV &OSTCBCur,R12
MOV R14,26(R12)
; 270. OS_EventTaskWait(pevent); /* Suspend task until event or timeout occurs */
MOV R10,R12
CALL #OS_EventTaskWait
; 271. OS_EXIT_CRITICAL();
EINT
; 272. OS_Sched(); /* Find next highest priority task ready to run */
CALL #OS_Sched
; 273. OS_ENTER_CRITICAL();
DINT
; 274. msg = OSTCBCur->OSTCBMsg;
MOV &OSTCBCur,R13
MOV 20(R13),R12
; 275. if (msg != (void *)0) { /* See if we were given the message */
CMP #0,R12
JEQ (?0098)
; 276. OSTCBCur->OSTCBMsg = (void *)0; /* Yes, clear message received */
MOV &OSTCBCur,R13
MOV #0,20(R13)
; 277. OSTCBCur->OSTCBStat = OS_STAT_RDY;
MOV &OSTCBCur,R13
MOV.B #0,28(R13)
; 278. OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; /* No longer waiting for event */
MOV &OSTCBCur,R13
MOV #0,18(R13)
; 279. OS_EXIT_CRITICAL();
EINT
; 280. *err = OS_NO_ERR;
MOV.B #0,0(R11)
; 281. return (msg); /* Return the message received */
; 282. }
JMP (?0099)
?0098:
; 283. OS_EventTO(pevent); /* Timed out, Make task ready */
MOV R10,R12
CALL #OS_EventTO
; 284. OS_EXIT_CRITICAL();
EINT
; 285. *err = OS_TIMEOUT; /* Indicate that a timeout occured */
MOV.B #10,0(R11)
; 286. return ((void *)0); /* Return a NULL message */
MOV #0,R12
; 287. }
?0099:
POP R11
POP R10
RET
OSMboxPost:
; 288. /*$PAGE*/
; 289. /*
; 290. *********************************************************************************************************
; 291. * POST MESSAGE TO A MAILBOX
; 292. *
; 293. * Description: This function sends a message to a mailbox
; 294. *
; 295. * Arguments : pevent is a pointer to the event control block associated with the desired mailbox
; 296. *
; 297. * msg is a pointer to the message to send. You MUST NOT send a NULL pointer.
; 298. *
; 299. * Returns : OS_NO_ERR The call was successful and the message was sent
; 300. * OS_MBOX_FULL If the mailbox already contains a message. You can can only send one
; 301. * message at a time and thus, the message MUST be consumed before you
; 302. * are allowed to send another one.
; 303. * OS_ERR_EVENT_TYPE If you are attempting to post to a non mailbox.
; 304. * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
; 305. * OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
; 306. *********************************************************************************************************
; 307. */
; 308.
; 309. #if OS_MBOX_POST_EN > 0
; 310. INT8U OSMboxPost (OS_EVENT *pevent, void *msg)
; 311. {
; 312. #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; 313. OS_CPU_SR cpu_sr;
; 314. #endif
; 315.
; 316.
; 317. #if OS_ARG_CHK_EN > 0
; 318. if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
CMP #0,R12
JNE (?0101)
; 319. return (OS_ERR_PEVENT_NULL);
MOV.B #4,R12
; 320. }
RET
?0101:
; 321. if (msg == (void *)0) { /* Make sure we are not posting a NULL pointer */
CMP #0,R14
JNE (?0103)
; 322. return (OS_ERR_POST_NULL_PTR);
MOV.B #3,R12
; 323. }
RET
?0103:
; 324. if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* Validate event block type */
MOV.B #1,R13
CMP.B @R12,R13
JEQ (?0105)
; 325. return (OS_ERR_EVENT_TYPE);
MOV.B #1,R12
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -