Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Disassembly Listing for messingWithRTOS
- Generated From:
- --- D:/Documents/MPLABXProjects/messingWithRTOS.X/dist/default/production/messingWithRTOS.X.production.as
- 1: opt subtitle "HI-TECH Software Omniscient Code Generator (Lite mode) build 12136"
- 2:
- 3: opt pagewidth 120
- 4:
- 5: opt lm
- 6:
- 7: processor 16F616
- 8: clrc macro
- 9: bcf 3,0
- 10: endm
- 11: clrz macro
- 12: bcf 3,2
- 13: endm
- 14: setc macro
- 15: bsf 3,0
- 16: endm
- 17: setz macro
- 18: bsf 3,2
- 19: endm
- 20: skipc macro
- 21: btfss 3,0
- 22: endm
- 23: skipz macro
- 24: btfss 3,2
- 25: endm
- 26: skipnc macro
- 27: btfsc 3,0
- 28: endm
- 29: skipnz macro
- 30: btfsc 3,2
- 31: endm
- 32: indf equ 0
- 33: indf0 equ 0
- 34: pc equ 2
- 35: pcl equ 2
- 36: status equ 3
- 37: fsr equ 4
- 38: fsr0 equ 4
- 39: c equ 1
- 40: z equ 0
- 41: pclath equ 10
- 42: # 8 "arrray_asm.c"
- 43: psect config,class=CONFIG,delta=2 ;#
- 44: # 8 "arrray_asm.c"
- 45: dw 0xFFFC & 0xFFF7 & 0xFFEF & 0xFFDF & 0xFFFF & 0xFF7F & 0xFFFF ;#
- 46: FNCALL _main,_fTask1
- 47: FNCALL _main,_fTask2
- 48: FNROOT _main
- 49: global _tasks
- 50: global _currentTask
- 51: global _PORTA
- 52: _PORTA set 0x5
- 53: global _PORTC
- 54: _PORTC set 0x7
- 55: global _ANSEL
- 56: _ANSEL set 0x91
- 57: global _TRISA
- 58: _TRISA set 0x85
- 59: global _TRISC
- 60: _TRISC set 0x87
- 61: psect text36,local,class=CODE,delta=2,merge=1
- 62: global __ptext36
- 63: __ptext36:
- 64: file "dist/default/production\messingWithRTOS.X.production.as"
- 65: line #
- 66: psect cinit,class=CODE,delta=2
- 67: global start_initialization
- 68: start_initialization:
- 69:
- 70: psect bssCOMMON,class=COMMON,space=1
- 71: global __pbssCOMMON
- 72: __pbssCOMMON:
- 73: _tasks:
- 74: ds 4
- 75:
- 76: _currentTask:
- 77: ds 1
- 78:
- 79: ; Clear objects allocated to COMMON
- 80: psect cinit,class=CODE,delta=2,merge=1
- 81: clrf ((__pbssCOMMON)+0)&07Fh
- 07A4 01F0 CLRF tasks
- 82: clrf ((__pbssCOMMON)+1)&07Fh
- 07A5 01F1 CLRF 0x71
- 83: clrf ((__pbssCOMMON)+2)&07Fh
- 07A6 01F2 CLRF 0x72
- 84: clrf ((__pbssCOMMON)+3)&07Fh
- 07A7 01F3 CLRF 0x73
- 85: clrf ((__pbssCOMMON)+4)&07Fh
- 07A8 01F4 CLRF currentTask
- 86: psect cinit,class=CODE,delta=2,merge=1
- 87: global end_of_initialization
- 88:
- 89: ;End of C runtime variable initialization code
- 90:
- 91: end_of_initialization:
- 92: clrf status
- 07A9 0183 CLRF STATUS
- 93: ljmp _main ;jump to C main() function
- 07AA 2FE3 GOTO 0x7E3
- 94: psect cstackCOMMON,class=COMMON,space=1
- 95: global __pcstackCOMMON
- 96: __pcstackCOMMON:
- 97: global ?_fTask1
- 98: ?_fTask1: ; 0 bytes @ 0x0
- 99: global ??_fTask1
- 100: ??_fTask1: ; 0 bytes @ 0x0
- 101: global ?_fTask2
- 102: ?_fTask2: ; 0 bytes @ 0x0
- 103: global ??_fTask2
- 104: ??_fTask2: ; 0 bytes @ 0x0
- 105: global ?_main
- 106: ?_main: ; 0 bytes @ 0x0
- 107: global ??_main
- 108: ??_main: ; 0 bytes @ 0x0
- 109: ds 1
- 110: ;!
- 111: ;!Data Sizes:
- 112: ;! Strings 0
- 113: ;! Constant 0
- 114: ;! Data 0
- 115: ;! BSS 5
- 116: ;! Persistent 0
- 117: ;! Stack 0
- 118: ;!
- 119: ;!Auto Spaces:
- 120: ;! Space Size Autos Used
- 121: ;! COMMON 14 1 6
- 122: ;! BANK0 80 0 0
- 123: ;! BANK1 32 0 0
- 124:
- 125: ;!
- 126: ;!Pointer List with Targets:
- 127: ;!
- 128: ;! None.
- 129:
- 130:
- 131: ;!
- 132: ;!Critical Paths under _main in COMMON
- 133: ;!
- 134: ;! None.
- 135: ;!
- 136: ;!Critical Paths under _main in BANK0
- 137: ;!
- 138: ;! None.
- 139: ;!
- 140: ;!Critical Paths under _main in BANK1
- 141: ;!
- 142: ;! None.
- 143:
- 144: ;;
- 145: ;;Main: autosize = 0, tempsize = 1, incstack = 0, save=0
- 146: ;;
- 147:
- 148: ;!
- 149: ;!Call Graph Tables:
- 150: ;!
- 151: ;! ---------------------------------------------------------------------------------
- 152: ;! (Depth) Function Calls Base Space Used Autos Params Refs
- 153: ;! ---------------------------------------------------------------------------------
- 154: ;! (0) _main 1 1 0 0
- 155: ;! 0 COMMON 1 1 0
- 156: ;! _fTask1
- 157: ;! _fTask2
- 158: ;! ---------------------------------------------------------------------------------
- 159: ;! (1) _fTask1 0 0 0 0
- 160: ;! ---------------------------------------------------------------------------------
- 161: ;! (1) _fTask2 0 0 0 0
- 162: ;! ---------------------------------------------------------------------------------
- 163: ;! Estimated maximum stack depth 1
- 164: ;! ---------------------------------------------------------------------------------
- 165: ;!
- 166: ;! Call Graph Graphs:
- 167: ;!
- 168: ;! _main (ROOT)
- 169: ;! _fTask1
- 170: ;! _fTask2
- 171: ;!
- 172:
- 173: ;! Address spaces:
- 174:
- 175: ;!Name Size Autos Total Cost Usage
- 176: ;!BITCOMMON E 0 0 0 0.0%
- 177: ;!NULL 0 0 0 0 0.0%
- 178: ;!CODE 0 0 0 0 0.0%
- 179: ;!COMMON E 1 6 1 42.9%
- 180: ;!BITSFR0 0 0 0 1 0.0%
- 181: ;!SFR0 0 0 0 1 0.0%
- 182: ;!BITSFR1 0 0 0 2 0.0%
- 183: ;!SFR1 0 0 0 2 0.0%
- 184: ;!STACK 0 0 1 2 0.0%
- 185: ;!BITBANK0 50 0 0 3 0.0%
- 186: ;!BANK0 50 0 0 4 0.0%
- 187: ;!BANK1 20 0 0 5 0.0%
- 188: ;!ABS 0 0 6 6 0.0%
- 189: ;!BITBANK1 20 0 0 7 0.0%
- 190: ;!DATA 0 0 7 8 0.0%
- 191:
- 192: global _main
- 193:
- 194: ;; *************** function _main *****************
- 195: ;; Defined at:
- 196: ;; line 18 in file "arrray_asm.c"
- 197: ;; Parameters: Size Location Type
- 198: ;; None
- 199: ;; Auto vars: Size Location Type
- 200: ;; None
- 201: ;; Return value: Size Location Type
- 202: ;; None void
- 203: ;; Registers used:
- 204: ;; wreg, status,2, status,0, pclath, cstack
- 205: ;; Tracked objects:
- 206: ;; On entry : 17F/0
- 207: ;; On exit : 0/0
- 208: ;; Unchanged: 0/0
- 209: ;; Data sizes: COMMON BANK0 BANK1
- 210: ;; Params: 0 0 0
- 211: ;; Locals: 0 0 0
- 212: ;; Temps: 1 0 0
- 213: ;; Totals: 1 0 0
- 214: ;;Total ram usage: 1 bytes
- 215: ;; Hardware stack levels required when called: 1
- 216: ;; This function calls:
- 217: ;; _fTask1
- 218: ;; _fTask2
- 219: ;; This function is called by:
- 220: ;; Startup code after reset
- 221: ;; This function uses a non-reentrant model
- 222: ;;
- 223: psect maintext,global,class=CODE,delta=2,split=1
- 224: global __pmaintext
- 225: __pmaintext:
- 226: psect maintext
- 227: file "arrray_asm.c"
- 228: line 18
- 229: global __size_of_main
- 230: __size_of_main equ __end_of_main-_main
- 231:
- 232: _main:
- 233: opt stack 7
- 234: ; Regs used in _main: [wreg+status,2+status,0+pclath+cstack]
- 235: line 19
- 236:
- 237: l414:
- 238: ;arrray_asm.c: 19: TRISA = 0;
- 239: bsf status, 5 ;RP0=1, select bank1
- 240: clrf (133)^080h ;volatile
- 241: line 20
- 242: ;arrray_asm.c: 20: TRISC = 0;
- 243: clrf (135)^080h ;volatile
- 244: line 21
- 245: ;arrray_asm.c: 21: ANSEL = 0;
- 246: clrf (145)^080h ;volatile
- 247: line 22
- 248: ;arrray_asm.c: 22: PORTA = 0;
- 249: bcf status, 5 ;RP0=0, select bank0
- 250: clrf (5) ;volatile
- 251: line 23
- 252: ;arrray_asm.c: 23: PORTC = 0;
- 253: clrf (7) ;volatile
- 254: line 25
- 255:
- 256: l416:
- 257: ;arrray_asm.c: 25: currentTask = 0;
- 258: clrf (_currentTask)
- 259: line 26
- 260:
- 261: l418:
- 262: ;arrray_asm.c: 26: fTask1();
- 263: fcall _fTask1
- 264: line 27
- 265:
- 266: l420:
- 267: ;arrray_asm.c: 27: currentTask++;
- 268: movlw (01h)
- 269: movwf (??_main+0)+0
- 270: movf (??_main+0)+0,w
- 271: addwf (_currentTask),f
- 272: line 28
- 273:
- 274: l422:
- 275: ;arrray_asm.c: 28: fTask2();
- 276: fcall _fTask2
- 277: line 31
- 278: # 31 "arrray_asm.c"
- 279: _taskswitcher ;#
- 280: line 32
- 281: # 32 "arrray_asm.c"
- 282: movlw 0x02 ; W = 2 ;#
- 283: line 33
- 284: # 33 "arrray_asm.c"
- 285: addwf _currentTask, f ; Add 2 to currentTask, store it in currentTask. ;#
- 286: line 34
- 287: # 34 "arrray_asm.c"
- 288: movlw 4 ; W = 4 ;#
- 289: line 35
- 290: # 35 "arrray_asm.c"
- 291: subwf _currentTask, w ; w= f - w ;#
- 292: line 36
- 293: # 36 "arrray_asm.c"
- 294: btfsc status, 0 ; If currentTask >= 4 ;#
- 295: line 37
- 296: # 37 "arrray_asm.c"
- 297: clrf _currentTask ; Clear currentTask ;#
- 298: line 39
- 299: # 39 "arrray_asm.c"
- 300: movlw _tasks ; Store the address of tasks, which is the start address of our task "array". ;#
- 301: line 40
- 302: # 40 "arrray_asm.c"
- 303: addwf _currentTask, w ; Add current task's index to the start address. ;#
- 304: line 41
- 305: ; For example; task1's index is 2: [task0_1][task0_2][task1_1][task1_2].... ;#
- 306: line 42
- 307: ; 0 1 2 3 ;#
- 308: line 43
- 309: # 43 "arrray_asm.c"
- 310: movwf fsr ; We have the index of current task in W. Copy it to FSR ;#
- 311: line 44
- 312: # 44 "arrray_asm.c"
- 313: movf indf, w ; Copy the contents of current task's first item to W ;#
- 314: line 45
- 315: # 45 "arrray_asm.c"
- 316: movwf pclath ; Copy W to PCLATH. As a result, current task's PCLATH will be in PCLATH register. ;#
- 317: line 47
- 318: # 47 "arrray_asm.c"
- 319: incf fsr, f ; Increment index, so that we will point to the next item of current task. ;#
- 320: line 48
- 321: # 48 "arrray_asm.c"
- 322: movf indf, w ; Copy the contents of current task's second item to W. ;#
- 323: line 49
- 324: # 49 "arrray_asm.c"
- 325: movwf pcl ; Copy W to PCL. Finally, current task's PCL will be in PCL register. ;#
- 326: psect maintext
- 327: line 51
- 328:
- 329: l21:
- 330: global start
- 331: ljmp start
- 332: opt stack 0
- 333: GLOBAL __end_of_main
- 334: __end_of_main:
- 335: signat _main,88
- 336: global _fTask1
- 337:
- 338: ;; *************** function _fTask1 *****************
- 339: ;; Defined at:
- 340: ;; line 54 in file "arrray_asm.c"
- 341: ;; Parameters: Size Location Type
- 342: ;; None
- 343: ;; Auto vars: Size Location Type
- 344: ;; None
- 345: ;; Return value: Size Location Type
- 346: ;; None void
- 347: ;; Registers used:
- 348: ;; wreg
- 349: ;; Tracked objects:
- 350: ;; On entry : 0/0
- 351: ;; On exit : 0/0
- 352: ;; Unchanged: 0/0
- 353: ;; Data sizes: COMMON BANK0 BANK1
- 354: ;; Params: 0 0 0
- 355: ;; Locals: 0 0 0
- 356: ;; Temps: 0 0 0
- 357: ;; Totals: 0 0 0
- 358: ;;Total ram usage: 0 bytes
- 359: ;; Hardware stack levels used: 1
- 360: ;; This function calls:
- 361: ;; Nothing
- 362: ;; This function is called by:
- 363: ;; _main
- 364: ;; This function uses a non-reentrant model
- 365: ;;
- 366: psect text37,local,class=CODE,delta=2,merge=1
- 367: global __ptext37
- 368: __ptext37:
- 369: psect text37
- 370: file "arrray_asm.c"
- 371: line 54
- 372: global __size_of_fTask1
- 373: __size_of_fTask1 equ __end_of_fTask1-_fTask1
- 374:
- 375: _fTask1:
- 376: opt stack 7
- 377: ; Regs used in _fTask1: [wreg]
- 378: line 56
- 379:
- 380: l406:
- 381: # 56 "arrray_asm.c"
- 382: movlw _tasks ; Store the address of tasks, which is the start address of our task "array". ;#
- 383: line 57
- 384: # 57 "arrray_asm.c"
- 385: addwf _currentTask, w ; Add current task's index to the start address. ;#
- 386: line 59
- 387: # 59 "arrray_asm.c"
- 388: movwf fsr ; We have the index of current task in W. Copy it to FSR ;#
- 389: line 60
- 390: # 60 "arrray_asm.c"
- 391: movf pclath, w ; Copy PCLATH register's contents to W register. ;#
- 392: line 61
- 393: # 61 "arrray_asm.c"
- 394: movwf indf ; Copy W to current task's first item. We now store PCLATH. ;#
- 395: line 63
- 396: # 63 "arrray_asm.c"
- 397: incf fsr,f ; Increment index, so that we will point to the next item of current task. ;#
- 398: line 64
- 399: # 64 "arrray_asm.c"
- 400: movlw low($+3) ; Copy PCL+3 to W register. This will let us save the PCL of the start of the task. ;#
- 401: line 65
- 402: # 65 "arrray_asm.c"
- 403: movwf indf ; Copy W to task's next item. With that, we will initialize the current task. ;#
- 404: line 66
- 405: # 66 "arrray_asm.c"
- 406: return ; We have gathered our initialazation information. Return back to main. ;#
- 407: psect text37
- 408: goto l408
- 409: line 69
- 410: ;arrray_asm.c: 69: while (1)
- 411:
- 412: l24:
- 413: line 71
- 414:
- 415: l408:
- 416: ;arrray_asm.c: 70: {
- 417: ;arrray_asm.c: 71: PORTA = 0xAA;
- 418: movlw (0AAh)
- 419: bcf status, 5 ;RP0=0, select bank0
- 420: movwf (5) ;volatile
- 421: line 74
- 422: # 74 "arrray_asm.c"
- 423: movlw _tasks ; Store the address of tasks, which is the start address of our task "array". ;#
- 424: line 75
- 425: # 75 "arrray_asm.c"
- 426: addwf _currentTask, w ; Add current task's index to the start address. ;#
- 427: line 77
- 428: # 77 "arrray_asm.c"
- 429: movwf fsr ; We have the index of current task in W. Copy it to FSR ;#
- 430: line 78
- 431: # 78 "arrray_asm.c"
- 432: movf pclath, w ; Copy PCLATH register's contents to W register. ;#
- 433: line 79
- 434: # 79 "arrray_asm.c"
- 435: movwf indf ; Copy W to current task's first item. We now store PCLATH of the current state of the task. ;#
- 436: line 81
- 437: # 81 "arrray_asm.c"
- 438: incf fsr, f ; Increment index, so that we will point to the next item of current task. ;#
- 439: line 82
- 440: # 82 "arrray_asm.c"
- 441: movlw low($+3) ; Copy PCL+3 to W register. This will let us save the PCL of the current state of the task. ;#
- 442: line 83
- 443: # 83 "arrray_asm.c"
- 444: movwf indf ; Copy W to task's next item. With that, we will initialize the current task. ;#
- 445: line 85
- 446: # 85 "arrray_asm.c"
- 447: goto _taskswitcher ; Yield the CPU to the awaiting task by going to task switcher. ;#
- 448: psect text37
- 449: line 88
- 450: ;arrray_asm.c: 88: PORTA = 0x55;
- 451: movlw (055h)
- 452: bcf status, 5 ;RP0=0, select bank0
- 453: movwf (5) ;volatile
- 454: goto l408
- 455: line 89
- 456:
- 457: l25:
- 458: line 69
- 459: goto l408
- 460:
- 461: l26:
- 462: line 90
- 463:
- 464: l27:
- 465: return
- 466: opt stack 0
- 467: GLOBAL __end_of_fTask1
- 468: __end_of_fTask1:
- 469: signat _fTask1,88
- 470: global _fTask2
- 471:
- 472: ;; *************** function _fTask2 *****************
- 473: ;; Defined at:
- 474: ;; line 93 in file "arrray_asm.c"
- 475: ;; Parameters: Size Location Type
- 476: ;; None
- 477: ;; Auto vars: Size Location Type
- 478: ;; None
- 479: ;; Return value: Size Location Type
- 480: ;; None void
- 481: ;; Registers used:
- 482: ;; wreg
- 483: ;; Tracked objects:
- 484: ;; On entry : 0/0
- 485: ;; On exit : 0/0
- 486: ;; Unchanged: 0/0
- 487: ;; Data sizes: COMMON BANK0 BANK1
- 488: ;; Params: 0 0 0
- 489: ;; Locals: 0 0 0
- 490: ;; Temps: 0 0 0
- 491: ;; Totals: 0 0 0
- 492: ;;Total ram usage: 0 bytes
- 493: ;; Hardware stack levels used: 1
- 494: ;; This function calls:
- 495: ;; Nothing
- 496: ;; This function is called by:
- 497: ;; _main
- 498: ;; This function uses a non-reentrant model
- 499: ;;
- 500: psect text38,local,class=CODE,delta=2,merge=1
- 501: global __ptext38
- 502: __ptext38:
- 503: psect text38
- 504: file "arrray_asm.c"
- 505: line 93
- 506: global __size_of_fTask2
- 507: __size_of_fTask2 equ __end_of_fTask2-_fTask2
- 508:
- 509: _fTask2:
- 510: opt stack 7
- 511: ; Regs used in _fTask2: [wreg]
- 512: line 95
- 513:
- 514: l410:
- 515: # 95 "arrray_asm.c"
- 516: movlw _tasks ; Store the address of tasks, which is the start address of our task "array". ;#
- 517: line 96
- 518: # 96 "arrray_asm.c"
- 519: addwf _currentTask, w ; Add current task's index to the start address. ;#
- 520: line 98
- 521: # 98 "arrray_asm.c"
- 522: movwf fsr ; We have the index of current task in W. Copy it to FSR ;#
- 523: line 99
- 524: # 99 "arrray_asm.c"
- 525: movf pclath, w ; Copy PCLATH register's contents to W register. ;#
- 526: line 100
- 527: # 100 "arrray_asm.c"
- 528: movwf indf ; Copy W to current task's first item. We now store PCLATH. ;#
- 529: line 102
- 530: # 102 "arrray_asm.c"
- 531: incf fsr,f ; Increment index, so that we will point to the next item of current task. ;#
- 532: line 103
- 533: # 103 "arrray_asm.c"
- 534: movlw low($+3) ; Copy PCL+3 to W register. This will let us save the PCL of the start of the task. ;#
- 535: line 104
- 536: # 104 "arrray_asm.c"
- 537: movwf indf ; Copy W to task's next item. With that, we will initialize the current task. ;#
- 538: line 105
- 539: # 105 "arrray_asm.c"
- 540: return ; We have gathered our initialazation information. Return back to main. ;#
- 541: psect text38
- 542: goto l412
- 543: line 108
- 544: ;arrray_asm.c: 108: while (1)
- 545:
- 546: l30:
- 547: line 110
- 548:
- 549: l412:
- 550: ;arrray_asm.c: 109: {
- 551: ;arrray_asm.c: 110: PORTA = 0xAA;
- 552: movlw (0AAh)
- 553: bcf status, 5 ;RP0=0, select bank0
- 554: movwf (5) ;volatile
- 555: line 113
- 556: # 113 "arrray_asm.c"
- 557: movlw _tasks ; Store the address of tasks, which is the start address of our task "array". ;#
- 558: line 114
- 559: # 114 "arrray_asm.c"
- 560: addwf _currentTask, w ; Add current task's index to the start address. ;#
- 561: line 116
- 562: # 116 "arrray_asm.c"
- 563: movwf fsr ; We have the index of current task in W. Copy it to FSR ;#
- 564: line 117
- 565: # 117 "arrray_asm.c"
- 566: movf pclath, w ; Copy PCLATH register's contents to W register. ;#
- 567: line 118
- 568: # 118 "arrray_asm.c"
- 569: movwf indf ; Copy W to current task's first item. We now store PCLATH of the current state of the task. ;#
- 570: line 120
- 571: # 120 "arrray_asm.c"
- 572: incf fsr, f ; Increment index, so that we will point to the next item of current task. ;#
- 573: line 121
- 574: # 121 "arrray_asm.c"
- 575: movlw low($+3) ; Copy PCL+3 to W register. This will let us save the PCL of the current state of the task. ;#
- 576: line 122
- 577: # 122 "arrray_asm.c"
- 578: movwf indf ; Copy W to task's next item. With that, we will initialize the current task. ;#
- 579: line 124
- 580: # 124 "arrray_asm.c"
- 581: goto _taskswitcher ; Yield the CPU to the awaiting task by going to task switcher. ;#
- 582: psect text38
- 583: line 127
- 584: ;arrray_asm.c: 127: PORTA = 0x55;
- 585: movlw (055h)
- 586: bcf status, 5 ;RP0=0, select bank0
- 587: movwf (5) ;volatile
- 588: goto l412
- 589: line 128
- 590:
- 591: l31:
- 592: line 108
- 593: goto l412
- 594:
- 595: l32:
- 596: line 129
- 597:
- 598: l33:
- 599: return
- 600: opt stack 0
- 601: GLOBAL __end_of_fTask2
- 602: __end_of_fTask2:
- 603: signat _fTask2,88
- 604: psect text39,local,class=CODE,delta=2,merge=1
- 605: global __ptext39
- 606: __ptext39:
- 607: global btemp
- 608: btemp set 07Eh
- 609:
- 610: DABS 1,126,2 ;btemp
- 611: global wtemp0
- 612: wtemp0 set btemp
- 613: end
- --- D:/Documents/MPLABXProjects/messingWithRTOS.X/arrray_asm.c ----------------------------------------
- 1: /*
- 2: * File: main.c
- 3: * Author: abdullah
- 4: *
- 5: * Created on 10 Haziran 2012 Pazar, 14:43
- 6: */
- 7: #include <xc.h> // Include the header file needed by the compiler
- 8: __CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF & IOSCFS_4MHZ & BOREN_ON);
- 9:
- 10: #define numOfTasks 4
- 11: unsigned char currentTask; // This TCB pointer will point to the current task's TCB.
- 12: unsigned char tasks[4];
- 13:
- 14: void fTask1(void); // Prototype the function for task1.
- 15: void fTask2(void); // Prototype the function for task2.
- 16:
- 17: void main(void)
- 18: {
- 19: TRISA = 0; // Set all of the PORTA pins as outputs.
- 07E3 1683 BSF STATUS, 0x5
- 07E4 0185 CLRF PORTA
- 20: TRISC = 0; // Set all of the PORTC pins as outputs.
- 07E5 0187 CLRF PORTC
- 21: ANSEL = 0; // Set all of the analog input pins as digital i/o.
- 07E6 0191 CLRF TMR2
- 22: PORTA = 0; // Clear PORTA bits.
- 07E7 1283 BCF STATUS, 0x5
- 07E8 0185 CLRF PORTA
- 23: PORTC = 0; // Clear PORTC bits.
- 07E9 0187 CLRF PORTC
- 24:
- 25: currentTask = 0;
- 07EA 01F4 CLRF currentTask
- 26: fTask1();
- 07EB 27C7 CALL 0x7C7
- 27: currentTask++;
- 07EC 3001 MOVLW 0x1
- 07ED 00F5 MOVWF 0x75
- 07EE 0875 MOVF 0x75, W
- 07EF 07F4 ADDWF currentTask, F
- 28: fTask2();
- 07F0 27AB CALL 0x7AB
- 29:
- 30: #asm
- 31: _taskswitcher
- 32: movlw 0x02 ; W = 2
- 07F1 3002 MOVLW 0x2
- 33: addwf _currentTask, f ; Add 2 to currentTask, store it in currentTask.
- 07F2 07F4 ADDWF currentTask, F
- 34: movlw numOfTasks ; W = numOfTasks
- 07F3 3004 MOVLW 0x4
- 35: subwf _currentTask, w ; w= f - w
- 07F4 0274 SUBWF currentTask, W
- 36: btfsc status, 0 ; If currentTask >= numOfTasks
- 07F5 1803 BTFSC STATUS, 0x0
- 37: clrf _currentTask ; Clear currentTask
- 07F6 01F4 CLRF currentTask
- 38:
- 39: movlw _tasks ; Store the address of tasks, which is the start address of our task "array".
- 07F7 3070 MOVLW 0x70
- 40: addwf _currentTask, w ; Add current task's index to the start address.
- 07F8 0774 ADDWF currentTask, W
- 41: ; For example; task1's index is 2: [task0_1][task0_2][task1_1][task1_2]....
- 42: ; 0 1 2 3
- 43: movwf fsr ; We have the index of current task in W. Copy it to FSR
- 07F9 0084 MOVWF FSR
- 44: movf indf, w ; Copy the contents of current task's first item to W
- 07FA 0800 MOVF INDF, W
- 45: movwf pclath ; Copy W to PCLATH. As a result, current task's PCLATH will be in PCLATH register.
- 07FB 008A MOVWF PCLATH
- 46:
- 47: incf fsr, f ; Increment index, so that we will point to the next item of current task.
- 07FC 0A84 INCF FSR, F
- 48: movf indf, w ; Copy the contents of current task's second item to W.
- 07FD 0800 MOVF INDF, W
- 49: movwf pcl ; Copy W to PCL. Finally, current task's PCL will be in PCL register.
- 07FE 0082 MOVWF PCL
- 50: #endasm
- 51: }
- 52:
- 53: void fTask1(void)
- 54: {
- 55: #asm
- 56: movlw _tasks ; Store the address of tasks, which is the start address of our task "array".
- 07C7 3070 MOVLW 0x70
- 57: addwf _currentTask, w ; Add current task's index to the start address.
- 07C8 0774 ADDWF currentTask, W
- 58:
- 59: movwf fsr ; We have the index of current task in W. Copy it to FSR
- 07C9 0084 MOVWF FSR
- 60: movf pclath, w ; Copy PCLATH register's contents to W register.
- 07CA 080A MOVF PCLATH, W
- 61: movwf indf ; Copy W to current task's first item. We now store PCLATH.
- 07CB 0080 MOVWF INDF
- 62:
- 63: incf fsr,f ; Increment index, so that we will point to the next item of current task.
- 07CC 0A84 INCF FSR, F
- 64: movlw low($+3) ; Copy PCL+3 to W register. This will let us save the PCL of the start of the task.
- 07CD 30D0 MOVLW 0xD0
- 65: movwf indf ; Copy W to task's next item. With that, we will initialize the current task.
- 07CE 0080 MOVWF INDF
- 66: return ; We have gathered our initialazation information. Return back to main.
- 07CF 0008 RETURN
- 07D0 2FD1 GOTO 0x7D1
- 67: #endasm
- 68:
- 69: while (1)
- 07E1 2FD1 GOTO 0x7D1
- 70: {
- 71: PORTA = 0xAA; // Toggle PORTA.0
- 07D1 30AA MOVLW 0xAA
- 07D2 1283 BCF STATUS, 0x5
- 07D3 0085 MOVWF PORTA
- 72:
- 73: #asm
- 74: movlw _tasks ; Store the address of tasks, which is the start address of our task "array".
- 07D4 3070 MOVLW 0x70
- 75: addwf _currentTask, w ; Add current task's index to the start address.
- 07D5 0774 ADDWF currentTask, W
- 76:
- 77: movwf fsr ; We have the index of current task in W. Copy it to FSR
- 07D6 0084 MOVWF FSR
- 78: movf pclath, w ; Copy PCLATH register's contents to W register.
- 07D7 080A MOVF PCLATH, W
- 79: movwf indf ; Copy W to current task's first item. We now store PCLATH of the current state of the task.
- 07D8 0080 MOVWF INDF
- 80:
- 81: incf fsr, f ; Increment index, so that we will point to the next item of current task.
- 07D9 0A84 INCF FSR, F
- 82: movlw low($+3) ; Copy PCL+3 to W register. This will let us save the PCL of the current state of the task.
- 07DA 30DD MOVLW 0xDD
- 83: movwf indf ; Copy W to task's next item. With that, we will initialize the current task.
- 07DB 0080 MOVWF INDF
- 84:
- 85: goto _taskswitcher ; Yield the CPU to the awaiting task by going to task switcher.
- 07DC 2FF1 GOTO 0x7F1
- 86: #endasm
- 87:
- 88: PORTA = 0x55; // Toggle PORTA.0
- 07DD 3055 MOVLW 0x55
- 07DE 1283 BCF STATUS, 0x5
- 07DF 0085 MOVWF PORTA
- 07E0 2FD1 GOTO 0x7D1
- 89: }
- 90: }
- 07E2 0008 RETURN
- 91:
- 92: void fTask2(void)
- 93: {
- 94: #asm
- 95: movlw _tasks ; Store the address of tasks, which is the start address of our task "array".
- 07AB 3070 MOVLW 0x70
- 96: addwf _currentTask, w ; Add current task's index to the start address.
- 07AC 0774 ADDWF currentTask, W
- 97:
- 98: movwf fsr ; We have the index of current task in W. Copy it to FSR
- 07AD 0084 MOVWF FSR
- 99: movf pclath, w ; Copy PCLATH register's contents to W register.
- 07AE 080A MOVF PCLATH, W
- 100: movwf indf ; Copy W to current task's first item. We now store PCLATH.
- 07AF 0080 MOVWF INDF
- 101:
- 102: incf fsr,f ; Increment index, so that we will point to the next item of current task.
- 07B0 0A84 INCF FSR, F
- 103: movlw low($+3) ; Copy PCL+3 to W register. This will let us save the PCL of the start of the task.
- 07B1 30B4 MOVLW 0xB4
- 104: movwf indf ; Copy W to task's next item. With that, we will initialize the current task.
- 07B2 0080 MOVWF INDF
- 105: return ; We have gathered our initialazation information. Return back to main.
- 07B3 0008 RETURN
- 07B4 2FB5 GOTO 0x7B5
- 106: #endasm
- 107:
- 108: while (1)
- 07C5 2FB5 GOTO 0x7B5
- 109: {
- 110: PORTA = 0xAA; // Toggle PORTA.0
- 07B5 30AA MOVLW 0xAA
- 07B6 1283 BCF STATUS, 0x5
- 07B7 0085 MOVWF PORTA
- 111:
- 112: #asm
- 113: movlw _tasks ; Store the address of tasks, which is the start address of our task "array".
- 07B8 3070 MOVLW 0x70
- 114: addwf _currentTask, w ; Add current task's index to the start address.
- 07B9 0774 ADDWF currentTask, W
- 115:
- 116: movwf fsr ; We have the index of current task in W. Copy it to FSR
- 07BA 0084 MOVWF FSR
- 117: movf pclath, w ; Copy PCLATH register's contents to W register.
- 07BB 080A MOVF PCLATH, W
- 118: movwf indf ; Copy W to current task's first item. We now store PCLATH of the current state of the task.
- 07BC 0080 MOVWF INDF
- 119:
- 120: incf fsr, f ; Increment index, so that we will point to the next item of current task.
- 07BD 0A84 INCF FSR, F
- 121: movlw low($+3) ; Copy PCL+3 to W register. This will let us save the PCL of the current state of the task.
- 07BE 30C1 MOVLW 0xC1
- 122: movwf indf ; Copy W to task's next item. With that, we will initialize the current task.
- 07BF 0080 MOVWF INDF
- 123:
- 124: goto _taskswitcher ; Yield the CPU to the awaiting task by going to task switcher.
- 07C0 2FF1 GOTO 0x7F1
- 125: #endasm
- 126:
- 127: PORTA = 0x55; // Toggle PORTA.0
- 07C1 3055 MOVLW 0x55
- 07C2 1283 BCF STATUS, 0x5
- 07C3 0085 MOVWF PORTA
- 07C4 2FB5 GOTO 0x7B5
- 128: }
- 129: }
- 07C6 0008 RETURN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement