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/main.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: * INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
- 11: * WDT disabled and can be enabled by SWDTEN bit of the WDTCON register
- 12: * PWRT enabled
- 13: * MCLR pin function is digital input, MCLR internally tied to VDD
- 14: * Program memory code protection is disabled
- 15: * Internal Oscillator Frequency Select bit : 4MHz
- 16: * Brown-out Reset Selection bits : BOR enabled
- 17: */
- 18:
- 19: /*
- 20: * OS_initializeTask(); definition will copy the PCLATH register to the task's PCLATH , which is held in taskx.pch
- 21: * This will help us hold the PCLATH at the point we yield.
- 22: * After that, it will copy the (PCL register + 8) to current task's PCL which is held in taskx.pcl.
- 23: * 8 is added to PCL because this line plus the "return" takes 8 instructions.
- 24: * We will set the PCL after these instructions, because
- 25: * we want to be in the point after OS_initializeTask when we come back to this task.
- 26: * After all, the function returns without doing anything more. This will initialize the task's PCLATH and PCL.
- 27: */
- 28: #define OS_initializeTask(); currentTask->pch = PCLATH;\
- 29: currentTask->pcl = PCL + 8;\
- 30: asm("return");
- 31:
- 32: /*
- 33: * OS_yield(); definition will do the same stuff that OS_initializeTask(); definition do, however
- 34: * it will return to "taskswitcher" label, which is the start of OS_runTasks(); definition.
- 35: */
- 36:
- 37: #define OS_yield(); currentTask->pch = PCLATH;\
- 38: currentTask->pcl = PCL + 8;\
- 39: asm("goto _taskswitcher");
- 40:
- 41: /*
- 42: * OS_runTasks(); definition will set the "taskswitcher" label. After that it will change the
- 43: * current task to the next task, by pointing the next item in the linked list of "TCB"s.
- 44: * After that, it will change the PCLATH and PCL registers with the current task's. That will
- 45: * make the program continue the next task from the place it left last time.
- 46: */
- 47:
- 48: #define OS_runTasks(); asm("_taskswitcher");\
- 49: currentTask = currentTask -> next;\
- 50: PCLATH = currentTask->pch;\
- 51: PCL = currentTask->pcl;
- 52:
- 53: typedef struct _TCB // Create task control block and type define it as "TCB"
- 54: {
- 55: unsigned char pch; // pch register will hold the PCLATH value of the task after the last yield.
- 56: unsigned char pcl; // pcl register will hold the PCL value of the task after the last yield.
- 57: struct _TCB* next; // This pointer points to the next task. We are creating a linked list.
- 58: } TCB;
- 59:
- 60: TCB* currentTask; // This TCB pointer will point to the current task's TCB.
- 61:
- 62: TCB task1; // Define the TCB for task1.
- 63: TCB task2; // Define the TCB for task2.
- 64:
- 65: void fTask1(void); // Prototype the function for task1.
- 66: void fTask2(void); // Prototype the function for task2.
- 67:
- 68: void main(void)
- 69: {
- 70: TRISA = 0; // Set all of the PORTA pins as outputs.
- 07D4 1683 BSF STATUS, 0x5
- 07D5 0185 CLRF PORTA
- 71: ANSEL = 0; // Set all of the analog input pins as digital i/o.
- 07D6 0191 CLRF TMR2
- 72: PORTA = 0; // Clear PORTA bits.
- 07D7 1283 BCF STATUS, 0x5
- 07D8 0185 CLRF PORTA
- 73:
- 74: currentTask = &task1; // We will point the currentTask pointer to point the first task.
- 07D9 3070 MOVLW 0x70
- 07DA 00F7 MOVWF 0x77
- 07DB 0877 MOVF 0x77, W
- 07DC 00F8 MOVWF currentTask
- 75:
- 76: task1.next = &task2; // We will create a ringed linked list as follows:
- 07DD 3073 MOVLW 0x73
- 07DE 00F7 MOVWF 0x77
- 07DF 0877 MOVF 0x77, W
- 07E0 00F2 MOVWF 0x72
- 77: task2.next = &task1; // task1 -> task2 -> task1 -> task2 ....
- 07E1 3070 MOVLW 0x70
- 07E2 00F7 MOVWF 0x77
- 07E3 0877 MOVF 0x77, W
- 07E4 00F5 MOVWF 0x75
- 78:
- 79: /*
- 80: * Before running the tasks, we should initialize the PCL and PCLATH registers for the tasks.
- 81: * In order to do this, we could have looked up the absolute address with a function pointer.
- 82: * However, it seems like this is not possible with this compiler (or all the x16 PICs?)
- 83: * What this compiler creates is a table of the addresses of the functions and a bunch of GOTOs.
- 84: * This will not let us get the absolute address of the function by doing something like:
- 85: * "currentTask->pcl=low(functionpointer);"
- 86: */
- 87: fTask1(); // Run task1 so that we get the address of it and initialize pch and pcl registers.
- 07E5 27AB CALL 0x7AB
- 88: currentTask = currentTask -> next; // Point the currentTask pointer to the next pointer which
- 07E6 0878 MOVF currentTask, W
- 07E7 3E02 ADDLW 0x2
- 07E8 0084 MOVWF FSR
- 07E9 0800 MOVF INDF, W
- 07EA 00F7 MOVWF 0x77
- 07EB 0877 MOVF 0x77, W
- 07EC 00F8 MOVWF currentTask
- 89: fTask2(); // is task2. And run task2 so that we get the correct pch and pcl.
- 077A 01F0 CLRF task1
- 07ED 2782 CALL 0x782
- 90:
- 077B 01F1 CLRF 0x71
- 91: OS_runTasks(); // Task switcher. See the comments in the definitions above.
- 077C 01F2 CLRF 0x72
- 07EE 0878 MOVF currentTask, W
- 07EF 3E02 ADDLW 0x2
- 07F0 0084 MOVWF FSR
- 07F1 0800 MOVF INDF, W
- 07F2 00F7 MOVWF 0x77
- 07F3 0877 MOVF 0x77, W
- 07F4 00F8 MOVWF currentTask
- 07F5 0878 MOVF currentTask, W
- 07F6 0084 MOVWF FSR
- 07F7 0800 MOVF INDF, W
- 07F8 1283 BCF STATUS, 0x5
- 07F9 008A MOVWF PCLATH
- 07FA 0878 MOVF currentTask, W
- 07FB 3E01 ADDLW 0x1
- 07FC 0084 MOVWF FSR
- 07FD 0800 MOVF INDF, W
- 07FE 0082 MOVWF PCL
- 92: }
- 077D 01F3 CLRF task2
- 93:
- 94: void fTask1(void)
- 95: {
- 96: OS_initializeTask(); // Initialize the task
- 07AB 1283 BCF STATUS, 0x5
- 07AC 080A MOVF PCLATH, W
- 07AD 00F6 MOVWF 0x76
- 07AE 0878 MOVF currentTask, W
- 07AF 0084 MOVWF FSR
- 07B0 0876 MOVF 0x76, W
- 07B1 0080 MOVWF INDF
- 07B2 0802 MOVF PCL, W
- 07B3 3E08 ADDLW 0x8
- 07B4 00F6 MOVWF 0x76
- 07B5 0878 MOVF currentTask, W
- 07B6 3E01 ADDLW 0x1
- 07B7 0084 MOVWF FSR
- 07B8 0876 MOVF 0x76, W
- 07B9 0080 MOVWF INDF
- 07BA 0008 RETURN
- 07BB 2FBC GOTO 0x7BC
- 97: while (1)
- 07D2 2FBC GOTO 0x7BC
- 98: {
- 99: RA0 = ~RA0; // Toggle PORTA.0
- 07BC 3001 MOVLW 0x1
- 07BD 1283 BCF STATUS, 0x5
- 07BE 0685 XORWF PORTA, F
- 100: OS_yield(); // Yield
- 07BF 080A MOVF PCLATH, W
- 07C0 00F6 MOVWF 0x76
- 07C1 0878 MOVF currentTask, W
- 07C2 0084 MOVWF FSR
- 07C3 0876 MOVF 0x76, W
- 07C4 0080 MOVWF INDF
- 07C5 0802 MOVF PCL, W
- 07C6 3E08 ADDLW 0x8
- 07C7 00F6 MOVWF 0x76
- 07C8 0878 MOVF currentTask, W
- 07C9 3E01 ADDLW 0x1
- 07CA 0084 MOVWF FSR
- 07CB 0876 MOVF 0x76, W
- 07CC 0080 MOVWF INDF
- 07CD 2FEE GOTO 0x7EE
- 101: RA0 = ~RA0; // Toggle PORTA.0
- 0780 0183 CLRF STATUS
- 07CE 3001 MOVLW 0x1
- 07CF 1283 BCF STATUS, 0x5
- 07D0 0685 XORWF PORTA, F
- 07D1 2FBC GOTO 0x7BC
- 102: }
- 0781 2FD4 GOTO 0x7D4
- 103: }
- 07D3 0008 RETURN
- 104:
- 105: void fTask2(void)
- 106: {
- 107: OS_initializeTask(); // Initialize the task
- 0782 1283 BCF STATUS, 0x5
- 0783 080A MOVF PCLATH, W
- 0784 00F6 MOVWF 0x76
- 0785 0878 MOVF currentTask, W
- 0786 0084 MOVWF FSR
- 0787 0876 MOVF 0x76, W
- 0788 0080 MOVWF INDF
- 0789 0802 MOVF PCL, W
- 078A 3E08 ADDLW 0x8
- 078B 00F6 MOVWF 0x76
- 078C 0878 MOVF currentTask, W
- 078D 3E01 ADDLW 0x1
- 078E 0084 MOVWF FSR
- 078F 0876 MOVF 0x76, W
- 0790 0080 MOVWF INDF
- 0791 0008 RETURN
- 0792 2F93 GOTO 0x793
- 108: while (1)
- 07A9 2F93 GOTO 0x793
- 109: {
- 110: RA1 = ~RA1; // Toggle PORTA.1
- 0793 3002 MOVLW 0x2
- 0794 1283 BCF STATUS, 0x5
- 0795 0685 XORWF PORTA, F
- 111: OS_yield(); // Yield
- 0796 080A MOVF PCLATH, W
- 0797 00F6 MOVWF 0x76
- 0798 0878 MOVF currentTask, W
- 0799 0084 MOVWF FSR
- 079A 0876 MOVF 0x76, W
- 079B 0080 MOVWF INDF
- 079C 0802 MOVF PCL, W
- 079D 3E08 ADDLW 0x8
- 079E 00F6 MOVWF 0x76
- 079F 0878 MOVF currentTask, W
- 07A0 3E01 ADDLW 0x1
- 07A1 0084 MOVWF FSR
- 07A2 0876 MOVF 0x76, W
- 07A3 0080 MOVWF INDF
- 07A4 2FEE GOTO 0x7EE
- 112: RA1 = ~RA1; // Toggle PORTA.1
- 07A5 3002 MOVLW 0x2
- 07A6 1283 BCF STATUS, 0x5
- 07A7 0685 XORWF PORTA, F
- 07A8 2F93 GOTO 0x793
- 113: }
- 114: }
- 07AA 0008 RETURN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement