⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_q.s43

📁 IAR project for MSP430 and uC/OS. All configured to start filling with tasks.
💻 S43
📖 第 1 页 / 共 4 页
字号:
	MOV	#0,R12	
; 194.	    }
	JMP	(?0098)	
?0081:
; 195.	    if (pevent->OSEventType != OS_EVENT_TYPE_Q) {          /* Validate event block type                */
	MOV.B	#2,R12	
	CMP.B	@R11,R12	
	JEQ	(?0083)	
; 196.	        *err = OS_ERR_EVENT_TYPE;
	MOV.B	#1,0(R8)	
; 197.	        return (pevent);
	MOV	R11,R12	
; 198.	    }
	JMP	(?0098)	
?0083:
; 199.	#endif
; 200.	    OS_ENTER_CRITICAL();
	DINT		
; 201.	    if (pevent->OSEventGrp != 0x00) {                      /* See if any tasks waiting on queue        */
	CMP.B	#0,1(R11)	
	JEQ	(?0085)	
; 202.	        tasks_waiting = TRUE;                              /* Yes                                      */
	MOV.B	#1,R10	
; 203.	    } else {
	JMP	(?0086)	
?0085:
; 204.	        tasks_waiting = FALSE;                             /* No                                       */
	MOV.B	#0,R10	
?0086:
; 205.	    }
; 206.	    switch (opt) {
	SUB.B	#0,R14	
	JEQ	(?0088)	
	SUB.B	#1,R14	
	JEQ	(?0091)	
	JMP	(?0097)	
?0088:
; 207.	        case OS_DEL_NO_PEND:                               /* Delete queue only if no task waiting     */
; 208.	             if (tasks_waiting == FALSE) {
	CMP.B	#0,R10	
	JNE	(?0090)	
; 209.	                 pq                  = (OS_Q *)pevent->OSEventPtr;  /* Return OS_Q to free list        */
	MOV	4(R11),R12	
; 210.	                 pq->OSQPtr          = OSQFreeList;
	MOV	&OSQFreeList,0(R12)	
; 211.	                 OSQFreeList         = pq;
	MOV	R12,&OSQFreeList	
; 212.	                 pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
	MOV.B	#0,0(R11)	
; 213.	                 pevent->OSEventPtr  = OSEventFreeList;    /* Return Event Control Block to free list  */
	MOV	&OSEventFreeList,4(R11)	
; 214.	                 OSEventFreeList     = pevent;             /* Get next free event control block        */
	MOV	R11,&OSEventFreeList	
; 215.	                 OS_EXIT_CRITICAL();
	EINT		
; 216.	                 *err = OS_NO_ERR;
	MOV.B	#0,0(R8)	
; 217.	                 return ((OS_EVENT *)0);                   /* Queue has been deleted                   */
	MOV	#0,R12	
; 218.	             } else {
	JMP	(?0098)	
?0090:
; 219.	                 OS_EXIT_CRITICAL();
	EINT		
; 220.	                 *err = OS_ERR_TASK_WAITING;
	MOV.B	#8,0(R8)	
; 221.	                 return (pevent);
	MOV	R11,R12	
; 222.	             }
	JMP	(?0098)	
?0091:
; 223.	
; 224.	        case OS_DEL_ALWAYS:                                /* Always delete the queue                  */
; 225.	             while (pevent->OSEventGrp != 0x00) {          /* Ready ALL tasks waiting for queue        */
	CMP.B	#0,1(R11)	
	JEQ	(?0092)	
; 226.	                 OS_EventTaskRdy(pevent, (void *)0, OS_STAT_Q);
	PUSH.B	#4	
	MOV	#0,R14	
	MOV	R11,R12	
	CALL	#OS_EventTaskRdy	
	ADD	#2,SP	
	JMP	(?0091)	
?0092:
; 227.	             }
; 228.	             pq                  = (OS_Q *)pevent->OSEventPtr;      /* Return OS_Q to free list        */
	MOV	4(R11),R12	
; 229.	             pq->OSQPtr          = OSQFreeList;
	MOV	&OSQFreeList,0(R12)	
; 230.	             OSQFreeList         = pq;
	MOV	R12,&OSQFreeList	
; 231.	             pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
	MOV.B	#0,0(R11)	
; 232.	             pevent->OSEventPtr  = OSEventFreeList;        /* Return Event Control Block to free list  */
	MOV	&OSEventFreeList,4(R11)	
; 233.	             OSEventFreeList     = pevent;                 /* Get next free event control block        */
	MOV	R11,&OSEventFreeList	
; 234.	             OS_EXIT_CRITICAL();
	EINT		
; 235.	             if (tasks_waiting == TRUE) {                  /* Reschedule only if task(s) were waiting  */
	CMP.B	#1,R10	
	JNE	(?0096)	
; 236.	                 OS_Sched();                               /* Find highest priority task ready to run  */
	CALL	#OS_Sched	
?0096:
; 237.	             }
; 238.	             *err = OS_NO_ERR;
	MOV.B	#0,0(R8)	
; 239.	             return ((OS_EVENT *)0);                       /* Queue has been deleted                   */
	MOV	#0,R12	
; 240.	
; 241.	        default:
	JMP	(?0098)	
?0097:
; 242.	             OS_EXIT_CRITICAL();
	EINT		
; 243.	             *err = OS_ERR_INVALID_OPT;
	MOV.B	#7,0(R8)	
; 244.	             return (pevent);
	MOV	R11,R12	
; 245.	    }
?0098:
	POP	R8	
	POP	R11	
	POP	R10	
	RET		
?0087:
; 246.	}
OSQFlush:
; 247.	#endif
; 248.	
; 249.	/*$PAGE*/
; 250.	/*
; 251.	*********************************************************************************************************
; 252.	*                                           FLUSH QUEUE
; 253.	*
; 254.	* Description : This function is used to flush the contents of the message queue.
; 255.	*
; 256.	* Arguments   : none
; 257.	*
; 258.	* Returns     : OS_NO_ERR           upon success
; 259.	*               OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a queue
; 260.	*               OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer
; 261.	*********************************************************************************************************
; 262.	*/
; 263.	
; 264.	#if OS_Q_FLUSH_EN > 0
; 265.	INT8U  OSQFlush (OS_EVENT *pevent)
; 266.	{
; 267.	#if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
; 268.	    OS_CPU_SR  cpu_sr;
; 269.	#endif
; 270.	    OS_Q      *pq;
; 271.	
; 272.	
; 273.	#if OS_ARG_CHK_EN > 0
; 274.	    if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
	CMP	#0,R12	
	JNE	(?0100)	
; 275.	        return (OS_ERR_PEVENT_NULL);
	MOV.B	#4,R12	
; 276.	    }
	RET		
?0100:
; 277.	    if (pevent->OSEventType != OS_EVENT_TYPE_Q) {     /* Validate event block type                     */
	MOV.B	#2,R13	
	CMP.B	@R12,R13	
	JEQ	(?0102)	
; 278.	        return (OS_ERR_EVENT_TYPE);
	MOV.B	#1,R12	
; 279.	    }
	RET		
?0102:
; 280.	#endif
; 281.	    OS_ENTER_CRITICAL();
	DINT		
; 282.	    pq             = (OS_Q *)pevent->OSEventPtr;      /* Point to queue storage structure              */
	MOV	4(R12),R13	
; 283.	    pq->OSQIn      = pq->OSQStart;
	MOV	2(R13),6(R13)	
; 284.	    pq->OSQOut     = pq->OSQStart;
	MOV	2(R13),8(R13)	
; 285.	    pq->OSQEntries = 0;
	MOV	#0,12(R13)	
; 286.	    OS_EXIT_CRITICAL();
	EINT		
; 287.	    return (OS_NO_ERR);
	MOV.B	#0,R12	
; 288.	}
	RET		
OSQPend:
; 289.	#endif
; 290.	
; 291.	/*$PAGE*/
; 292.	/*
; 293.	*********************************************************************************************************
; 294.	*                                     PEND ON A QUEUE FOR A MESSAGE
; 295.	*
; 296.	* Description: This function waits for a message to be sent to a queue
; 297.	*
; 298.	* Arguments  : pevent        is a pointer to the event control block associated with the desired queue
; 299.	*
; 300.	*              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
; 301.	*                            wait for a message to arrive at the queue up to the amount of time
; 302.	*                            specified by this argument.  If you specify 0, however, your task will wait
; 303.	*                            forever at the specified queue or, until a message arrives.
; 304.	*
; 305.	*              err           is a pointer to where an error message will be deposited.  Possible error
; 306.	*                            messages are:
; 307.	*
; 308.	*                            OS_NO_ERR           The call was successful and your task received a
; 309.	*                                                message.
; 310.	*                            OS_TIMEOUT          A message was not received within the specified timeout
; 311.	*                            OS_ERR_EVENT_TYPE   You didn't pass a pointer to a queue
; 312.	*                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer
; 313.	*                            OS_ERR_PEND_ISR     If you called this function from an ISR and the result
; 314.	*                                                would lead to a suspension.
; 315.	*
; 316.	* Returns    : != (void *)0  is a pointer to the message received
; 317.	*              == (void *)0  if no message was received or,
; 318.	*                            if 'pevent' is a NULL pointer or,
; 319.	*                            if you didn't pass a pointer to a queue.
; 320.	*********************************************************************************************************
; 321.	*/
; 322.	
; 323.	void  *OSQPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)
; 324.	{
	PUSH	R10	
	PUSH	R11	
	MOV	R12,R10	
	MOV	6(SP),R11	
; 325.	#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
; 326.	    OS_CPU_SR  cpu_sr;
; 327.	#endif
; 328.	    void      *msg;
; 329.	    OS_Q      *pq;
; 330.	
; 331.	
; 332.	    if (OSIntNesting > 0) {                      /* See if called from ISR ...                         */
	CMP.B	#0,&OSIntNesting	
	JEQ	(?0105)	
; 333.	        *err = OS_ERR_PEND_ISR;                  /* ... can't PEND from an ISR                         */
	MOV.B	#2,0(R11)	
; 334.	        return ((void *)0);
	MOV	#0,R12	
; 335.	    }
	JMP	(?0116)	
?0105:
; 336.	#if OS_ARG_CHK_EN > 0
; 337.	    if (pevent == (OS_EVENT *)0) {               /* Validate 'pevent'                                  */
	CMP	#0,R10	
	JNE	(?0107)	
; 338.	        *err = OS_ERR_PEVENT_NULL;
	MOV.B	#4,0(R11)	
; 339.	        return ((void *)0);
	MOV	#0,R12	
; 340.	    }
	JMP	(?0116)	
?0107:
; 341.	    if (pevent->OSEventType != OS_EVENT_TYPE_Q) {/* Validate event block type                          */
	MOV.B	#2,R12	
	CMP.B	@R10,R12	
	JEQ	(?0109)	
; 342.	        *err = OS_ERR_EVENT_TYPE;
	MOV.B	#1,0(R11)	
; 343.	        return ((void *)0);
	MOV	#0,R12	
; 344.	    }
	JMP	(?0116)	
?0109:
; 345.	#endif
; 346.	    OS_ENTER_CRITICAL();
	DINT		
; 347.	    pq = (OS_Q *)pevent->OSEventPtr;             /* Point at queue control block                       */
	MOV	4(R10),R13	
; 348.	    if (pq->OSQEntries > 0) {                    /* See if any messages in the queue                   */
	CMP	#0,12(R13)	
	JEQ	(?0111)	
; 349.	        msg = *pq->OSQOut++;                     /* Yes, extract oldest message from the queue         */
	MOV	8(R13),R14	
	ADD	#2,8(R13)	
	MOV	@R14,R12	
; 350.	        pq->OSQEntries--;                        /* Update the number of entries in the queue          */
	ADD	#-1,12(R13)	
; 351.	        if (pq->OSQOut == pq->OSQEnd) {          /* Wrap OUT pointer if we are at the end of the queue */
	CMP	8(R13),4(R13)	
	JNE	(?0113)	
; 352.	            pq->OSQOut = pq->OSQStart;
	MOV	2(R13),8(R13)	
?0113:
; 353.	        }
; 354.	        OS_EXIT_CRITICAL();
	EINT		
; 355.	        *err = OS_NO_ERR;
	MOV.B	#0,0(R11)	
; 356.	        return (msg);                            /* Return message received                            */
; 357.	    }
	JMP	(?0116)	
?0111:
; 358.	    OSTCBCur->OSTCBStat |= OS_STAT_Q;            /* Task will have to pend for a message to be posted  */
	MOV	&OSTCBCur,R12	
	BIS.B	#4,28(R12)	
; 359.	    OSTCBCur->OSTCBDly   = timeout;              /* Load timeout into TCB                              */
	MOV	&OSTCBCur,R12	
	MOV	R14,26(R12)	
; 360.	    OS_EventTaskWait(pevent);                    /* Suspend task until event or timeout occurs         */
	MOV	R10,R12	
	CALL	#OS_EventTaskWait	
; 361.	    OS_EXIT_CRITICAL();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -