📄 os_core.s43
字号:
OSSchedLock:
; 196. /*$PAGE*/
; 197. /*
; 198. *********************************************************************************************************
; 199. * PREVENT SCHEDULING
; 200. *
; 201. * Description: This function is used to prevent rescheduling to take place. This allows your application
; 202. * to prevent context switches until you are ready to permit context switching.
; 203. *
; 204. * Arguments : none
; 205. *
; 206. * Returns : none
; 207. *
; 208. * Notes : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every
; 209. * call to OSSchedLock() you MUST have a call to OSSchedUnlock().
; 210. *********************************************************************************************************
; 211. */
; 212.
; 213. #if OS_SCHED_LOCK_EN > 0
; 214. void OSSchedLock (void)
; 215. {
; 216. #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; 217. OS_CPU_SR cpu_sr;
; 218. #endif
; 219.
; 220.
; 221. if (OSRunning == TRUE) { /* Make sure multitasking is running */
CMP.B #1,&OSRunning
JNE (?0077)
; 222. OS_ENTER_CRITICAL();
DINT
; 223. if (OSLockNesting < 255) { /* Prevent OSLockNesting from wrapping back to 0 */
CMP.B #255,&OSLockNesting
JC (?0079)
; 224. OSLockNesting++; /* Increment lock nesting level */
ADD.B #1,&OSLockNesting
?0079:
; 225. }
; 226. OS_EXIT_CRITICAL();
EINT
?0077:
; 227. }
; 228. }
RET
OSSchedUnlock:
; 229. #endif
; 230.
; 231. /*$PAGE*/
; 232. /*
; 233. *********************************************************************************************************
; 234. * ENABLE SCHEDULING
; 235. *
; 236. * Description: This function is used to re-allow rescheduling.
; 237. *
; 238. * Arguments : none
; 239. *
; 240. * Returns : none
; 241. *
; 242. * Notes : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every
; 243. * call to OSSchedLock() you MUST have a call to OSSchedUnlock().
; 244. *********************************************************************************************************
; 245. */
; 246.
; 247. #if OS_SCHED_LOCK_EN > 0
; 248. void OSSchedUnlock (void)
; 249. {
; 250. #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; 251. OS_CPU_SR cpu_sr;
; 252. #endif
; 253.
; 254.
; 255. if (OSRunning == TRUE) { /* Make sure multitasking is running */
CMP.B #1,&OSRunning
JNE (?0089)
; 256. OS_ENTER_CRITICAL();
DINT
; 257. if (OSLockNesting > 0) { /* Do not decrement if already 0 */
CMP.B #0,&OSLockNesting
JEQ (?0083)
; 258. OSLockNesting--; /* Decrement lock nesting level */
ADD.B #-1,&OSLockNesting
; 259. if ((OSLockNesting == 0) && (OSIntNesting == 0)) { /* See if sched. enabled and not an ISR */
CMP.B #0,&OSLockNesting
JNE (?0085)
CMP.B #0,&OSIntNesting
JNE (?0085)
; 260. OS_EXIT_CRITICAL();
EINT
; 261. OS_Sched(); /* See if a HPT is ready */
CALL #OS_Sched
; 262. } else {
RET
?0085:
; 263. OS_EXIT_CRITICAL();
EINT
; 264. }
; 265. } else {
RET
?0083:
; 266. OS_EXIT_CRITICAL();
EINT
?0089:
; 267. }
; 268. }
; 269. }
RET
OSStart:
; 270. #endif
; 271.
; 272. /*$PAGE*/
; 273. /*
; 274. *********************************************************************************************************
; 275. * START MULTITASKING
; 276. *
; 277. * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
; 278. * task that you have created. Before you can call OSStart(), you MUST have called OSInit()
; 279. * and you MUST have created at least one task.
; 280. *
; 281. * Arguments : none
; 282. *
; 283. * Returns : none
; 284. *
; 285. * Note : OSStartHighRdy() MUST:
; 286. * a) Call OSTaskSwHook() then,
; 287. * b) Set OSRunning to TRUE.
; 288. * c) Load the context of the task pointed to by OSTCBHighRdy.
; 289. * d_ Execute the task.
; 290. *********************************************************************************************************
; 291. */
; 292.
; 293. void OSStart (void)
; 294. {
; 295. INT8U y;
; 296. INT8U x;
; 297.
; 298.
; 299. if (OSRunning == FALSE) {
CMP.B #0,&OSRunning
JNE (?0091)
; 300. y = OSUnMapTbl[OSRdyGrp]; /* Find highest priority's task priority number */
MOV.B &OSRdyGrp,R12
MOV.B OSUnMapTbl(R12),R13
; 301. x = OSUnMapTbl[OSRdyTbl[y]];
MOV.B R13,R12
MOV.B OSRdyTbl(R12),R14
MOV.B OSUnMapTbl(R14),R12
; 302. OSPrioHighRdy = (INT8U)((y << 3) + x);
ADD.B R13,R13
ADD.B R13,R13
ADD.B R13,R13
ADD.B R12,R13
MOV.B R13,&OSPrioHighRdy
; 303. OSPrioCur = OSPrioHighRdy;
MOV.B &OSPrioHighRdy,&OSPrioCur
; 304. OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run */
MOV.B &OSPrioHighRdy,R12
ADD R12,R12
MOV OSTCBPrioTbl(R12),&OSTCBHighRdy
; 305. OSTCBCur = OSTCBHighRdy;
MOV &OSTCBHighRdy,&OSTCBCur
; 306. OSStartHighRdy(); /* Execute target specific code to start task */
CALL #OSStartHighRdy
?0091:
; 307. }
; 308. }
RET
OSStatInit:
; 309. /*$PAGE*/
; 310. /*
; 311. *********************************************************************************************************
; 312. * STATISTICS INITIALIZATION
; 313. *
; 314. * Description: This function is called by your application to establish CPU usage by first determining
; 315. * how high a 32-bit counter would count to in 1 second if no other tasks were to execute
; 316. * during that time. CPU usage is then determined by a low priority task which keeps track
; 317. * of this 32-bit counter every second but this time, with other tasks running. CPU usage is
; 318. * determined by:
; 319. *
; 320. * OSIdleCtr
; 321. * CPU Usage (%) = 100 * (1 - ------------)
; 322. * OSIdleCtrMax
; 323. *
; 324. * Arguments : none
; 325. *
; 326. * Returns : none
; 327. *********************************************************************************************************
; 328. */
; 329.
; 330. #if OS_TASK_STAT_EN > 0
; 331. void OSStatInit (void)
; 332. {
; 333. #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; 334. OS_CPU_SR cpu_sr;
; 335. #endif
; 336.
; 337.
; 338. OSTimeDly(2); /* Synchronize with clock tick */
MOV #2,R12
CALL #OSTimeDly
; 339. OS_ENTER_CRITICAL();
DINT
; 340. OSIdleCtr = 0L; /* Clear idle counter */
MOV #0,&OSIdleCtr
MOV #0,&(OSIdleCtr+2)
; 341. OS_EXIT_CRITICAL();
EINT
; 342. OSTimeDly(OS_TICKS_PER_SEC); /* Determine MAX. idle counter value for 1 second */
MOV #200,R12
CALL #OSTimeDly
; 343. OS_ENTER_CRITICAL();
DINT
; 344. OSIdleCtrMax = OSIdleCtr; /* Store maximum idle counter count in 1 second */
MOV &OSIdleCtr,&OSIdleCtrMax
MOV &(OSIdleCtr+2),&(OSIdleCtrMax+2)
; 345. OSStatRdy = TRUE;
MOV.B #1,&OSStatRdy
; 346. OS_EXIT_CRITICAL();
EINT
; 347. }
RET
OSTimeTick:
; 348. #endif
; 349. /*$PAGE*/
; 350. /*
; 351. *********************************************************************************************************
; 352. * PROCESS SYSTEM TICK
; 353. *
; 354. * Description: This function is used to signal to uC/OS-II the occurrence of a 'system tick' (also known
; 355. * as a 'clock tick'). This function should be called by the ticker ISR but, can also be
; 356. * called by a high priority task.
; 357. *
; 358. * Arguments : none
; 359. *
; 360. * Returns : none
; 361. *********************************************************************************************************
; 362. */
; 363.
; 364. void OSTimeTick (void)
; 365. {
; 366. #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; 367. OS_CPU_SR cpu_sr;
; 368. #endif
; 369. OS_TCB *ptcb;
; 370.
; 371.
; 372. OSTimeTickHook(); /* Call user definable hook */
CALL #OSTimeTickHook
; 373. #if OS_TIME_GET_SET_EN > 0
; 374. OS_ENTER_CRITICAL(); /* Update the 32-bit tick counter */
DINT
; 375. OSTime++;
ADD #1,&OSTime
ADDC #0,&(OSTime+2)
; 376. OS_EXIT_CRITICAL();
EINT
; 377. #endif
; 378. if (OSRunning == TRUE) {
CMP.B #1,&OSRunning
JNE (?0094)
; 379. ptcb = OSTCBList; /* Point at first TCB in TCB list */
MOV &OSTCBList,R13
?0095:
; 380. while (ptcb->OSTCBPrio != OS_IDLE_PRIO) { /* Go through all TCBs in TCB list */
CMP.B #12,29(R13)
JEQ (?0094)
; 381. OS_ENTER_CRITICAL();
DINT
; 382. if (ptcb->OSTCBDly != 0) { /* Delayed or waiting for event with TO */
CMP #0,26(R13)
JEQ (?0103)
; 383. if (--ptcb->OSTCBDly == 0) { /* Decrement nbr of ticks to end of delay */
ADD #-1,26(R13)
CMP #0,26(R13)
JNE (?0103)
; 384. if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY) { /* Is task suspended? */
BIT.B #8,28(R13)
JNE (?0102)
; 385. OSRdyGrp |= ptcb->OSTCBBitY; /* No, Make task R-to-R (timed out)*/
BIS.B 33(R13),&OSRdyGrp
; 386. OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
MOV.B 31(R13),R12
BIS.B 32(R13),OSRdyTbl(R12)
; 387. } else { /* Yes, Leave 1 tick to prevent ... */
JMP (?0103)
?0102:
; 388. ptcb->OSTCBDly = 1; /* ... loosing the task when the ... */
MOV #1,26(R13)
?0103:
; 389. } /* ... suspension is removed. */
; 390. }
; 391. }
; 392. ptcb = ptcb->OSTCBNext; /* Point at next TCB in TCB list */
MOV 14(R13),R13
; 393. OS_EXIT_CRITICAL();
EINT
; 394. }
; 395. }
JMP (?0095)
?0094:
; 396. }
RET
OSVersion:
; 397. /*$PAGE*/
; 398. /*
; 399. *********************************************************************************************************
; 400. * GET VERSION
; 401. *
; 402. * Description: This function is used to return the version number of uC/OS-II. The returned value
; 403. * corresponds to uC/OS-II's version number multiplied by 100. In other words, version 2.00
; 404. * would be returned as 200.
; 405. *
; 406. * Arguments : none
; 407. *
; 408. * Returns : the version number of uC/OS-II multiplied by 100.
; 409. *********************************************************************************************************
; 410. */
; 411.
; 412. INT16U OSVersion (void)
; 413. {
; 414. return (OS_VERSION);
MOV #252,R12
; 415. }
RET
OS_Dummy:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -