Advertisement
abdullahkahraman

Disassembly Listing For RTOS for x16PIC

Jun 11th, 2012
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Disassembly Listing for messingWithRTOS
  2. Generated From:
  3.  
  4. ---  D:/Documents/MPLABXProjects/messingWithRTOS.X/main.c  ----------------------------------------------
  5. 1:             /*
  6. 2:              * File:   main.c
  7. 3:              * Author: abdullah
  8. 4:              *
  9. 5:              * Created on 10 Haziran 2012 Pazar, 14:43
  10. 6:              */
  11. 7:             #include <xc.h> // Include the header file needed by the compiler
  12. 8:             __CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF & IOSCFS_4MHZ & BOREN_ON);
  13. 9:             /*
  14. 10:             * INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
  15. 11:             * WDT disabled and can be enabled by SWDTEN bit of the WDTCON register
  16. 12:             * PWRT enabled
  17. 13:             * MCLR pin function is digital input, MCLR internally tied to VDD
  18. 14:             * Program memory code protection is disabled
  19. 15:             * Internal Oscillator Frequency Select bit : 4MHz
  20. 16:             * Brown-out Reset Selection bits : BOR enabled
  21. 17:             */
  22. 18:            
  23. 19:            /*
  24. 20:             * OS_initializeTask(); definition will copy the PCLATH register to the task's PCLATH  , which is held in taskx.pch
  25. 21:             * This will help us hold the PCLATH at the point we yield.
  26. 22:             * After that, it will copy the (PCL register + 8) to current task's PCL which is held in taskx.pcl.
  27. 23:             * 8 is added to PCL because this line plus the "return" takes 8 instructions.
  28. 24:             * We will set the PCL after these instructions, because
  29. 25:             * we want to be in the point after OS_initializeTask when we come back to this task.
  30. 26:             * After all, the function returns without doing anything more. This will initialize the task's PCLATH and PCL.
  31. 27:             */
  32. 28:            #define OS_initializeTask(); currentTask->pch = PCLATH;\
  33. 29:                                         currentTask->pcl = PCL + 8;\
  34. 30:                                         asm("return");
  35. 31:            
  36. 32:            /*
  37. 33:             * OS_yield(); definition will do the same stuff that OS_initializeTask(); definition do, however
  38. 34:             * it will return to "taskswitcher" label, which is the start of OS_runTasks(); definition.
  39. 35:             */
  40. 36:            
  41. 37:            #define OS_yield();          currentTask->pch = PCLATH;\
  42. 38:                                         currentTask->pcl = PCL + 8;\
  43. 39:                                         asm("goto _taskswitcher");
  44. 40:            
  45. 41:            /*
  46. 42:             * OS_runTasks(); definition will set the "taskswitcher" label. After that it will change the
  47. 43:             * current task to the next task, by pointing the next item in the linked list of "TCB"s.
  48. 44:             * After that, it will change the PCLATH and PCL registers with the current task's. That will
  49. 45:             * make the program continue the next task from the place it left last time.
  50. 46:             */
  51. 47:            
  52. 48:            #define OS_runTasks();       asm("_taskswitcher");\
  53. 49:                                         currentTask = currentTask -> next;\
  54. 50:                                         PCLATH = currentTask->pch;\
  55. 51:                                         PCL = currentTask->pcl;
  56. 52:            
  57. 53:            typedef struct _TCB // Create task control block and type define it as "TCB"
  58. 54:            {
  59. 55:                unsigned char pch; // pch register will hold the PCLATH value of the task after the last yield.
  60. 56:                unsigned char pcl; // pcl register will hold the PCL value of the task after the last yield.
  61. 57:                struct _TCB* next; // This pointer points to the next task. We are creating a linked list.
  62. 58:            } TCB;
  63. 59:            
  64. 60:            TCB* currentTask; // This TCB pointer will point to the current task's TCB.
  65. 61:            
  66. 62:            TCB task1; // Define the TCB for task1.
  67. 63:            TCB task2; // Define the TCB for task2.
  68. 64:            
  69. 65:            void fTask1(void); // Prototype the function for task1.
  70. 66:            void fTask2(void); // Prototype the function for task2.
  71. 67:            
  72. 68:            void main(void)
  73. 69:            {
  74. 70:                TRISA = 0; // Set all of the PORTA pins as outputs.
  75. 07D4  1683     BSF STATUS, 0x5
  76. 07D5  0185     CLRF PORTA
  77. 71:                ANSEL = 0; // Set all of the analog input pins as digital i/o.
  78. 07D6  0191     CLRF TMR2
  79. 72:                PORTA = 0; // Clear PORTA bits.
  80. 07D7  1283     BCF STATUS, 0x5
  81. 07D8  0185     CLRF PORTA
  82. 73:            
  83. 74:                currentTask = &task1; // We will point the currentTask pointer to point the first task.
  84. 07D9  3070     MOVLW 0x70
  85. 07DA  00F7     MOVWF 0x77
  86. 07DB  0877     MOVF 0x77, W
  87. 07DC  00F8     MOVWF currentTask
  88. 75:            
  89. 76:                task1.next = &task2; // We will create a ringed linked list as follows:
  90. 07DD  3073     MOVLW 0x73
  91. 07DE  00F7     MOVWF 0x77
  92. 07DF  0877     MOVF 0x77, W
  93. 07E0  00F2     MOVWF 0x72
  94. 77:                task2.next = &task1; // task1 -> task2 -> task1 -> task2 ....
  95. 07E1  3070     MOVLW 0x70
  96. 07E2  00F7     MOVWF 0x77
  97. 07E3  0877     MOVF 0x77, W
  98. 07E4  00F5     MOVWF 0x75
  99. 78:            
  100. 79:                /*
  101. 80:                 * Before running the tasks, we should initialize the PCL and PCLATH registers for the tasks.
  102. 81:                 * In order to do this, we could have looked up the absolute address with a function pointer.
  103. 82:                 * However, it seems like this is not possible with this compiler (or all the x16 PICs?)
  104. 83:                 * What this compiler creates is a table of the addresses of the functions and a bunch of GOTOs.
  105. 84:                 * This will not let us get the absolute address of the function by doing something like:
  106. 85:                 * "currentTask->pcl=low(functionpointer);"
  107. 86:                 */
  108. 87:                fTask1(); // Run task1 so that we get the address of it and initialize pch and pcl registers.
  109. 07E5  27AB     CALL 0x7AB
  110. 88:                currentTask = currentTask -> next; // Point the currentTask pointer to the next pointer which
  111. 07E6  0878     MOVF currentTask, W
  112. 07E7  3E02     ADDLW 0x2
  113. 07E8  0084     MOVWF FSR
  114. 07E9  0800     MOVF INDF, W
  115. 07EA  00F7     MOVWF 0x77
  116. 07EB  0877     MOVF 0x77, W
  117. 07EC  00F8     MOVWF currentTask
  118. 89:                fTask2(); // is task2. And run task2 so that we get the correct pch and pcl.
  119. 077A  01F0     CLRF task1
  120. 07ED  2782     CALL 0x782
  121. 90:            
  122. 077B  01F1     CLRF 0x71
  123. 91:                OS_runTasks(); // Task switcher. See the comments in the definitions above.
  124. 077C  01F2     CLRF 0x72
  125. 07EE  0878     MOVF currentTask, W
  126. 07EF  3E02     ADDLW 0x2
  127. 07F0  0084     MOVWF FSR
  128. 07F1  0800     MOVF INDF, W
  129. 07F2  00F7     MOVWF 0x77
  130. 07F3  0877     MOVF 0x77, W
  131. 07F4  00F8     MOVWF currentTask
  132. 07F5  0878     MOVF currentTask, W
  133. 07F6  0084     MOVWF FSR
  134. 07F7  0800     MOVF INDF, W
  135. 07F8  1283     BCF STATUS, 0x5
  136. 07F9  008A     MOVWF PCLATH
  137. 07FA  0878     MOVF currentTask, W
  138. 07FB  3E01     ADDLW 0x1
  139. 07FC  0084     MOVWF FSR
  140. 07FD  0800     MOVF INDF, W
  141. 07FE  0082     MOVWF PCL
  142. 92:            }
  143. 077D  01F3     CLRF task2
  144. 93:            
  145. 94:            void fTask1(void)
  146. 95:            {
  147. 96:                OS_initializeTask(); // Initialize the task
  148. 07AB  1283     BCF STATUS, 0x5
  149. 07AC  080A     MOVF PCLATH, W
  150. 07AD  00F6     MOVWF 0x76
  151. 07AE  0878     MOVF currentTask, W
  152. 07AF  0084     MOVWF FSR
  153. 07B0  0876     MOVF 0x76, W
  154. 07B1  0080     MOVWF INDF
  155. 07B2  0802     MOVF PCL, W
  156. 07B3  3E08     ADDLW 0x8
  157. 07B4  00F6     MOVWF 0x76
  158. 07B5  0878     MOVF currentTask, W
  159. 07B6  3E01     ADDLW 0x1
  160. 07B7  0084     MOVWF FSR
  161. 07B8  0876     MOVF 0x76, W
  162. 07B9  0080     MOVWF INDF
  163. 07BA  0008     RETURN
  164. 07BB  2FBC     GOTO 0x7BC
  165. 97:                while (1)
  166. 07D2  2FBC     GOTO 0x7BC
  167. 98:                {
  168. 99:                    RA0 = ~RA0; // Toggle PORTA.0
  169. 07BC  3001     MOVLW 0x1
  170. 07BD  1283     BCF STATUS, 0x5
  171. 07BE  0685     XORWF PORTA, F
  172. 100:                   OS_yield(); // Yield
  173. 07BF  080A     MOVF PCLATH, W
  174. 07C0  00F6     MOVWF 0x76
  175. 07C1  0878     MOVF currentTask, W
  176. 07C2  0084     MOVWF FSR
  177. 07C3  0876     MOVF 0x76, W
  178. 07C4  0080     MOVWF INDF
  179. 07C5  0802     MOVF PCL, W
  180. 07C6  3E08     ADDLW 0x8
  181. 07C7  00F6     MOVWF 0x76
  182. 07C8  0878     MOVF currentTask, W
  183. 07C9  3E01     ADDLW 0x1
  184. 07CA  0084     MOVWF FSR
  185. 07CB  0876     MOVF 0x76, W
  186. 07CC  0080     MOVWF INDF
  187. 07CD  2FEE     GOTO 0x7EE
  188. 101:                   RA0 = ~RA0; // Toggle PORTA.0
  189. 0780  0183     CLRF STATUS
  190. 07CE  3001     MOVLW 0x1
  191. 07CF  1283     BCF STATUS, 0x5
  192. 07D0  0685     XORWF PORTA, F
  193. 07D1  2FBC     GOTO 0x7BC
  194. 102:               }
  195. 0781  2FD4     GOTO 0x7D4
  196. 103:           }
  197. 07D3  0008     RETURN
  198. 104:          
  199. 105:           void fTask2(void)
  200. 106:           {
  201. 107:               OS_initializeTask(); // Initialize the task
  202. 0782  1283     BCF STATUS, 0x5
  203. 0783  080A     MOVF PCLATH, W
  204. 0784  00F6     MOVWF 0x76
  205. 0785  0878     MOVF currentTask, W
  206. 0786  0084     MOVWF FSR
  207. 0787  0876     MOVF 0x76, W
  208. 0788  0080     MOVWF INDF
  209. 0789  0802     MOVF PCL, W
  210. 078A  3E08     ADDLW 0x8
  211. 078B  00F6     MOVWF 0x76
  212. 078C  0878     MOVF currentTask, W
  213. 078D  3E01     ADDLW 0x1
  214. 078E  0084     MOVWF FSR
  215. 078F  0876     MOVF 0x76, W
  216. 0790  0080     MOVWF INDF
  217. 0791  0008     RETURN
  218. 0792  2F93     GOTO 0x793
  219. 108:               while (1)
  220. 07A9  2F93     GOTO 0x793
  221. 109:               {
  222. 110:                   RA1 = ~RA1; // Toggle PORTA.1
  223. 0793  3002     MOVLW 0x2
  224. 0794  1283     BCF STATUS, 0x5
  225. 0795  0685     XORWF PORTA, F
  226. 111:                   OS_yield(); // Yield
  227. 0796  080A     MOVF PCLATH, W
  228. 0797  00F6     MOVWF 0x76
  229. 0798  0878     MOVF currentTask, W
  230. 0799  0084     MOVWF FSR
  231. 079A  0876     MOVF 0x76, W
  232. 079B  0080     MOVWF INDF
  233. 079C  0802     MOVF PCL, W
  234. 079D  3E08     ADDLW 0x8
  235. 079E  00F6     MOVWF 0x76
  236. 079F  0878     MOVF currentTask, W
  237. 07A0  3E01     ADDLW 0x1
  238. 07A1  0084     MOVWF FSR
  239. 07A2  0876     MOVF 0x76, W
  240. 07A3  0080     MOVWF INDF
  241. 07A4  2FEE     GOTO 0x7EE
  242. 112:                   RA1 = ~RA1; // Toggle PORTA.1
  243. 07A5  3002     MOVLW 0x2
  244. 07A6  1283     BCF STATUS, 0x5
  245. 07A7  0685     XORWF PORTA, F
  246. 07A8  2F93     GOTO 0x793
  247. 113:               }
  248. 114:           }
  249. 07AA  0008     RETURN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement