📄 ucos.lst
字号:
(0097) *
(0098) * Returns : The length of the string or 0 if the 'pevent' is a NULL pointer.
(0099) *********************************************************************************************************
(0100) */
(0101)
(0102) #if OS_EVENT_EN && (OS_EVENT_NAME_SIZE > 1)
(0103) INT8U OSEventNameGet (OS_EVENT *pevent, char *pname, INT8U *err)
(0104) {
(0105) INT8U len;
(0106) #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
(0107) OS_CPU_SR cpu_sr;
(0108)
(0109)
(0110)
(0111) cpu_sr = 0; /* Prevent compiler warning */
(0112) #endif
(0113) OS_ENTER_CRITICAL();
(0114) #if OS_ARG_CHK_EN > 0
(0115) if (pevent == (OS_EVENT *)0) { /* Is 'pevent' a NULL pointer? */
(0116) OS_EXIT_CRITICAL(); /* Yes */
(0117) *err = OS_ERR_PEVENT_NULL;
(0118) return (0);
(0119) }
(0120) if (pname == (char *)0) { /* Is 'pname' a NULL pointer? */
(0121) OS_EXIT_CRITICAL(); /* Yes */
(0122) *err = OS_ERR_PNAME_NULL;
(0123) return (0);
(0124) }
(0125) #endif
(0126) switch (pevent->OSEventType) {
(0127) case OS_EVENT_TYPE_SEM:
(0128) case OS_EVENT_TYPE_MUTEX:
(0129) case OS_EVENT_TYPE_MBOX:
(0130) case OS_EVENT_TYPE_Q:
(0131) break;
(0132)
(0133) default:
(0134) OS_EXIT_CRITICAL();
(0135) *err = OS_ERR_EVENT_TYPE;
(0136) return (0);
(0137) }
(0138) len = OS_StrCopy(pname, pevent->OSEventName); /* Copy name from OS_EVENT */
(0139) OS_EXIT_CRITICAL();
(0140) *err = OS_NO_ERR;
(0141) return (len);
(0142) }
(0143) #endif
(0144)
(0145) /*$PAGE*/
(0146) /*
(0147) *********************************************************************************************************
(0148) * ASSIGN A NAME TO A SEMAPHORE, MUTEX, MAILBOX or QUEUE
(0149) *
(0150) * Description: This function assigns a name to a semaphore, mutex, mailbox or queue.
(0151) *
(0152) * Arguments : pevent is a pointer to the event group. 'pevent' can point either to a semaphore,
(0153) * a mutex, a mailbox or a queue. Where this function is concerned, it doesn't
(0154) * matter the actual type.
(0155) *
(0156) * pname is a pointer to an ASCII string that will be used as the name of the semaphore,
(0157) * mutex, mailbox or queue. The string must be able to hold at least
(0158) * OS_EVENT_NAME_SIZE characters.
(0159) *
(0160) * err is a pointer to an error code that can contain one of the following values:
(0161) *
(0162) * OS_NO_ERR if the requested task is resumed
(0163) * OS_ERR_EVENT_TYPE if 'pevent' is not pointing to the proper event
(0164) * control block type.
(0165) * OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
(0166) * OS_ERR_PEVENT_NULL if you passed a NULL pointer for 'pevent'
(0167) *
(0168) * Returns : None
(0169) *********************************************************************************************************
(0170) */
(0171)
(0172) #if OS_EVENT_EN && (OS_EVENT_NAME_SIZE > 1)
(0173) void OSEventNameSet (OS_EVENT *pevent, char *pname, INT8U *err)
(0174) {
(0175) INT8U len;
(0176) #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
(0177) OS_CPU_SR cpu_sr;
(0178)
(0179)
(0180)
(0181) cpu_sr = 0; /* Prevent compiler warning */
(0182) #endif
(0183) OS_ENTER_CRITICAL();
(0184) #if OS_ARG_CHK_EN > 0
(0185) if (pevent == (OS_EVENT *)0) { /* Is 'pevent' a NULL pointer? */
(0186) OS_EXIT_CRITICAL(); /* Yes */
(0187) *err = OS_ERR_PEVENT_NULL;
(0188) return;
(0189) }
(0190) if (pname == (char *)0) { /* Is 'pname' a NULL pointer? */
(0191) OS_EXIT_CRITICAL(); /* Yes */
(0192) *err = OS_ERR_PNAME_NULL;
(0193) return;
(0194) }
(0195) #endif
(0196) switch (pevent->OSEventType) {
(0197) case OS_EVENT_TYPE_SEM:
(0198) case OS_EVENT_TYPE_MUTEX:
(0199) case OS_EVENT_TYPE_MBOX:
(0200) case OS_EVENT_TYPE_Q:
(0201) break;
(0202)
(0203) default:
(0204) OS_EXIT_CRITICAL();
(0205) *err = OS_ERR_EVENT_TYPE;
(0206) return;
(0207) }
(0208) len = OS_StrLen(pname); /* Can we fit the string in the storage area? */
(0209) if (len > (OS_EVENT_NAME_SIZE - 1)) { /* No */
(0210) OS_EXIT_CRITICAL();
(0211) *err = OS_ERR_EVENT_NAME_TOO_LONG;
(0212) return;
(0213) }
(0214) (void)OS_StrCopy(pevent->OSEventName, pname); /* Yes, copy name to the event control block */
(0215) OS_EXIT_CRITICAL();
(0216) *err = OS_NO_ERR;
(0217) }
(0218) #endif
(0219)
(0220) /*$PAGE*/
(0221) /*
(0222) *********************************************************************************************************
(0223) * INITIALIZATION
(0224) *
(0225) * Description: This function is used to initialize the internals of uC/OS-II and MUST be called prior to
(0226) * creating any uC/OS-II object and, prior to calling OSStart().
(0227) *
(0228) * Arguments : none
(0229) *
(0230) * Returns : none
(0231) *********************************************************************************************************
(0232) */
(0233)
(0234) void OSInit (void)
(0235) {
(0236) #if OS_VERSION >= 204
(0237) OSInitHookBegin(); /* Call port specific initialization code */
01DF 1C53 ADC R5,R3
01E0 9240040A STS OSPrioHighRdy,R4
(0238) #endif
(0239)
(0240) OS_InitMisc(); /* Initialize miscellaneous variables */
01E2 9020040B LDS R2,OSPrioCur
(0241)
(0242) OS_InitRdyList(); /* Initialize the Ready List */
(0243)
(0244) OS_InitTCBList(); /* Initialize the free list of OS_TCBs */
01E4 1442 CP R4,R2
(0245)
(0246) OS_InitEventList(); /* Initialize the free list of OS_EVENTs */
(0247)
(0248) #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
(0249) OS_FlagInit(); /* Initialize the event flag structures */
(0250) #endif
(0251)
(0252) #if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)
(0253) OS_MemInit(); /* Initialize the memory manager */
(0254) #endif
(0255)
(0256) #if (OS_Q_EN > 0) && (OS_MAX_QS > 0)
(0257) OS_QInit(); /* Initialize the message queue structures */
(0258) #endif
(0259)
(0260) OS_InitTaskIdle(); /* Create the Idle Task */
01E5 F409 BNE 0x01E7
(0261) #if OS_TASK_STAT_EN > 0
(0262) OS_InitTaskStat(); /* Create the Statistic Task */
(0263) #endif
(0264)
(0265) #if OS_VERSION >= 204
(0266) OSInitHookEnd(); /* Call port specific init. code */
01E6 C03B RJMP 0x0222
01E7 2C24 MOV R2,R4
(0267) #endif
(0268)
(0269) #if OS_VERSION >= 270 && OS_DEBUG_EN > 0
(0270) OSDebugInit();
01E8 E082 LDI R24,2
01E9 9D82 MUL R24,R2
01EA 01F0 MOVW R30,R0
(0271) #endif
(0272) }
(0273) /*$PAGE*/
(0274) /*
(0275) *********************************************************************************************************
(0276) * ENTER ISR
(0277) *
(0278) * Description: This function is used to notify uC/OS-II that you are about to service an interrupt
(0279) * service routine (ISR). This allows uC/OS-II to keep track of interrupt nesting and thus
(0280) * only perform rescheduling at the last nested ISR.
(0281) *
(0282) * Arguments : none
(0283) *
(0284) * Returns : none
(0285) *
(0286) * Notes : 1) This function should be called ith interrupts already disabled
(0287) * 2) Your ISR can directly increment OSIntNesting without calling this function because
(0288) * OSIntNesting has been declared 'global'.
(0289) * 3) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
(0290) * 4) You MUST invoke OSIntEnter() and OSIntExit() in pair. In other words, for every call
(0291) * to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
(0292) * end of the ISR.
(0293) * 5) You are allowed to nest interrupts up to 255 levels deep.
(0294) * 6) I removed the OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL() around the increment because
(0295) * OSIntEnter() is always called with interrupts disabled.
(0296) *********************************************************************************************************
(0297) */
(0298)
(0299) void OSIntEnter (void)
(0300) {
(0301) if (OSRunning == TRUE) {
01EB E687 LDI R24,0x67
01EC E093 LDI R25,3
01ED 0FE8 ADD R30,R24
01EE 1FF9 ADC R31,R25
(0302) if (OSIntNesting < 255u) {
01EF 8020 LDD R2,Z+0
01F0 8031 LDD R3,Z+1
01F1 9230037C STS OSTCBHighRdy+1,R3
(0303) OSIntNesting++; /* Increment ISR nesting level */
01F3 9220037B STS OSTCBHighRdy,R2
01F5 01C1 MOVW R24,R2
(0304) }
(0305) }
01F6 960F ADIW R24,0xF
01F7 E041 LDI R20,1
01F8 E050 LDI R21,0
(0306) }
(0307) /*$PAGE*/
(0308) /*
(0309) *********************************************************************************************************
(0310) * EXIT ISR
(0311) *
(0312) * Description: This function is used to notify uC/OS-II that you have completed serviving an ISR. When
(0313) * the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
(0314) * a new, high-priority task, is ready to run.
(0315) *
(0316) * Arguments : none
(0317) *
(0318) * Returns : none
(0319) *
(0320) * Notes : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair. In other words, for every call
(0321) * to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
(0322) * end of the ISR.
(0323) * 2) Rescheduling is prevented when the scheduler is locked (see OS_SchedLock())
(0324) *********************************************************************************************************
(0325) */
(0326)
(0327) void OSIntExit (void)
(0328) {
(0329) INT8U y;
(0330) #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
(0331) OS_CPU_SR cpu_sr;
(0332)
(0333)
(0334)
(0335) cpu_sr = 0; /* Prevent compiler warning */
01F9 E060 LDI R22,0
(0336) #endif
(0337) if (OSRunning == TRUE) {
01FA E070 LDI R23,0
01FB 01FC MOVW R30,R24
01FC 8040 LDD R4,Z+0
01FD 8051 LDD R5,Z+1
01FE 8062 LDD R6,Z+2
(0338) OS_ENTER_CRITICAL();
01FF 8073 LDD R7,Z+3
0200 0E44 ADD R4,R20
0201 1E55 ADC R5,R21
(0339) if (OSIntNesting > 0) { /* Prevent OSIntNesting from wrapping */
0202 1E66 ADC R6,R22
0203 1E77 ADC R7,R23
0204 8240 STD Z+0,R4
0205 8251 STD Z+1,R5
0206 8262 STD Z+2,R6
(0340) OSIntNesting--;
0207 8273 STD Z+3,R7
0208 E041 LDI R20,1
0209 E050 LDI R21,0
020A E060 LDI R22,0
(0341) }
(0342) if (OSIntNesting == 0) { /* Reschedule only if all ISRs complete ... */
020B E070 LDI R23,0
020C 90400410 LDS R4,OSCtxSwCtr+2
020E 90500411 LDS R5,OSCtxSwCtr+3
(0343) if (OSLockNesting == 0) { /* ... and not locked. */
0210 9020040E LDS R2,OSCtxSwCtr
0212 9030040F LDS R3,OSCtxSwCtr+1
0214 0E24 ADD R2,R20
(0344) y = OSUnMapTbl[OSRdyGrp];
0215 1E35 ADC R3,R21
0216 1E46 ADC R4,R22
0217 1E57 ADC R5,R23
0218 9230040F STS OSCtxSwCtr+1,R3
021A 9220040E STS OSCtxSwCtr,R2
021C 92500411 STS OSCtxSwCtr+3,R5
(0345) OSPrioHighRdy = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
021E 92400410 STS OSCtxSwCtr+2,R4
0220 940E0770 CALL _OSIntCtxSw
0222 2D0A MOV R16,R10
0223 940E06D7 CALL _OS_CPU_SR_Restore
0225 940E09C5 CALL pop_gset4
0227 9508 RET
_OSSchedLock:
cpu_sr --> R20
0228 940E09D3 CALL push_gset1
022A 2744 CLR R20
022B 91800406 LDS R24,OSRunning
022D 3081 CPI R24,1
022E F469 BNE 0x023C
022F 940E06D4 CALL _OS_CPU_SR_Save
0231 2F40 MOV R20,R16
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -