os_cpu_a.s
上传用户:dongxin
上传日期:2022-06-22
资源大小:370k
文件大小:15k
源码类别:

uCOS

开发平台:

Others

  1. /*
  2. ;************************************************************************************************
  3. ;                                         uC/OS-II
  4. ;                                    The Real-Time Kernel
  5. ;                         (c) Copyright 2006, Micrium, Inc., Weston, FL
  6. ;                                     All Rights Reserved
  7. ;  
  8. ; File        : OS_CPU_A.ASM
  9. ; By          : Jean J. Labrosse
  10. ;
  11. ; Note(s)     : 1) This port uses the MOVEM.L (A7),D0-D7/A0-A6, LEA 60(A7)A7 construct instead of        
  12. ;                  the traditional 68xxx MOVEM.L (A7)+,D0-D7/A0-A6.  
  13. ;                                           
  14. ;               2) The LEA instruction is required because the ColdFire cannot push multiple 
  15. ;                  registers directly to the stack.         
  16. ;*************************************************************************************************
  17. */
  18. /*
  19. ;*************************************************************************************************
  20. ;                                       PUBLIC DECLARATIONS
  21. ;*************************************************************************************************
  22. */
  23.         .global  _OS_CPU_SR_Save
  24.         .global  _OS_CPU_SR_Restore
  25.         .global  _OSCtxSw
  26.         .global  _OSIntCtxSw
  27.         .global  _OSStartHighRdy
  28.         .global  _OSInitVBR
  29. //定义自己的中断函数  
  30.   .global  _pit0_handler
  31.   .global  _uart0_handler
  32.   .global  _irq1_handler
  33.   .global  _irq7_handler
  34.         .global  _OS_My_ISR
  35. /*
  36. ;**************************************************************************************************
  37. ;                                     EXTERNAL DECLARATIONS
  38. ;**************************************************************************************************
  39. */
  40.         .extern  _OSRunning
  41.         .extern  _OSIntExit
  42.         .extern  _OSIntNesting
  43.         .extern  _OSLockNesting
  44.         .extern  _OSPrioCur
  45.         .extern  _OSPrioHighRdy
  46.         .extern  _OSRdyGrp
  47.         .extern  _OSRdyTbl
  48.         .extern  _OSTaskSwHook
  49.         .extern  _OSTCBCur
  50.         .extern  _OSTCBHighRdy
  51.         .extern  _OSIntEnter
  52. //声明自己的中断服务函数
  53.   .extern  _OS_IRQ1_ISR_Handler
  54.   .extern  _OS_IRQ7_ISR_Handler
  55. .extern  _OS_PIT0_ISR_Handler
  56.         .extern  _OS_UART0_ISR_Handler
  57.         .text
  58.         .align 4
  59. /*
  60. ;********************************************************************************************************
  61. ;                              OSCPUSaveSR() for OS_CRITICAL_METHOD #3
  62. ;
  63. ; Description : This functions implements the OS_CRITICAL_METHOD #3 function to preserve the state of the 
  64. ;               interrupt disable flag in order to be able to restore it later.
  65. ;
  66. ; Arguments   : none
  67. ;
  68. ; Returns     : It is assumed that the return value is placed in the D0 register as expected by the
  69. ;               compiler.
  70. ;
  71. ; Note(s)     : 1) It is assumed that the compiler uses the STANDARD calling convention
  72. ;********************************************************************************************************
  73. */
  74. _OS_CPU_SR_Save:
  75.         MOVE.W   SR,D0            ; Copy SR into D0 
  76.         MOVE.L   D0,-(A7)         ; Save D0
  77.         ORI.L    #0x0700,D0       ; Disable interrupts
  78.         MOVE     D0,SR
  79.         MOVE.L   (A7)+,D0         ; Restore D0
  80.         RTS
  81. /*
  82. ;********************************************************************************************************
  83. ;                              OSCPURestoreSR() for OS_CRITICAL_METHOD #3
  84. ;
  85. ; Description : This functions implements the OS_CRITICAL_METHOD #function to restore the state of the
  86. ;               interrupt flag.
  87. ;
  88. ; Arguments   : os_cpu_sr   is the contents of the SR to restore.  It is assumed that this 'argument' is
  89. ;                           passed on the stack
  90. ;
  91. ; Returns     : None 
  92. ;
  93. ; Note(s)     : 1) It is assumed that the compiler uses the STANDARD calling convention
  94. ;********************************************************************************************************
  95. */
  96. _OS_CPU_SR_Restore:
  97.         MOVE.L   D0,-(A7)         ; Save D0
  98.         MOVE.W   10(A7),D0
  99.         MOVE.W    D0,SR
  100.         MOVE.L   (A7)+,D0         ; Restore D0
  101.         RTS
  102. /*
  103. ;*************************************************************************************************
  104. ;                              VECTOR BASE REGISTER INITIALIZATION
  105. ;
  106. ; This is to set the Vector Base Register to 0x00000000, in case the startup bootloader moved it
  107. ; somewhere else.
  108. ;*******************************************************************************************
  109. */
  110. _OSInitVBR:
  111.         MOVE.L   D0,-(A7)         ; Save D0
  112.         MOVEQ    #0,D0
  113.         MOVEC    D0,VBR
  114.         MOVE.L   (A7)+,D0         ; Restore D0
  115.         RTS
  116. /*
  117. ;*******************************************************************************************
  118. ;                            START HIGHEST PRIORITY TASK READY-TO-RUN
  119. ;
  120. ; Description: This function is called by OSStart() to start the highest priority task that
  121. ;              was created by your application before calling OSStart().
  122. ;
  123. ; Arguments  : none
  124. ;
  125. ; Note(s)    : 1) The stack frame is assumed to look as follows:
  126. ;             
  127. ;                  OSTCBHighRdy->OSTCBStkPtr +  0  ---->  D0         Low Memory
  128. ;                                            +  4         D1 
  129. ;                                            +  8         D2
  130. ;                                            + 12         D3
  131. ;                                            + 16         D4
  132. ;                                            + 20         D5
  133. ;                                            + 24         D6
  134. ;                                            + 28         D7
  135. ;                                            + 32         A0
  136. ;                                            + 36         A1
  137. ;                                            + 40         A2
  138. ;                                            + 44         A3
  139. ;                                            + 48         A4
  140. ;                                            + 52         A5
  141. ;                                            + 56         A6
  142. ;                                            + 60         Format, Vector, OS_INITIAL_SR
  143. ;                                            + 64         task
  144. ;                                            + 68         task
  145. ;                                            + 72         p_arg       High Memory
  146. ;
  147. ;              2) OSStartHighRdy() MUST:
  148. ;                    a) Call OSTaskSwHook() then,
  149. ;                    b) Set OSRunning to TRUE,
  150. ;                    c) Switch to the highest priority task.
  151. ;*******************************************************************************************
  152. */
  153. _OSStartHighRdy:
  154.        JSR       _OSTaskSwHook   
  155.        MOVEQ.L   #1, D4                   //OSRunning = TRUE;说明多任务运行                             
  156.        MOVE.B    D4,_OSRunning                    
  157.        MOVE.L    (_OSTCBHighRdy),A1       //取得最高优先级任务的TCB地址
  158.        MOVE.L    (A1),A7                  //取得其堆栈地址  
  159.        MOVEM.L   (A7),D0-D7/A0-A6         //恢复寄存器                           
  160.        LEA       60(A7),A7                //修改堆栈指针                    
  161.        RTE                                                              
  162. /*
  163. ;*******************************************************************************************
  164. ;                                     TASK LEVEL CONTEXT SWITCH
  165. ;
  166. ; Description : This function is called when a task makes a higher prio task ready-to-run.
  167. ; Arguments   : none
  168. ;
  169. ; Note(s)     : 1) Upon entry,
  170. ;                   OSTCBCur     points to the OS_TCB of the task to suspend
  171. ;                   OSTCBHighRdy points to the OS_TCB of the task to resume
  172. ;
  173. ;               2) The stack frame of the task to suspend looks as follows (the registers 
  174. ;                  for task to suspend need to be saved):
  175. ;
  176. ;                                         SP +  0  ---->  Format, Vector, SR   Low Memory
  177. ;                                            +  4         PC of task           High Memory
  178. ;
  179. ;               3) The stack frame of the task to resume looks as follows:
  180. ;                  OSTCBHighRdy->OSTCBStkPtr +  0  ---->  D0                   Low Memory
  181. ;                                            +  4         D1
  182. ;                                            +  8         D2
  183. ;                                            + 12         D3
  184. ;                                            + 16         D4
  185. ;                                            + 20         D5
  186. ;                                            + 24         D6
  187. ;                                            + 28         D7
  188. ;                                            + 32         A0
  189. ;                                            + 36         A1
  190. ;                                            + 40         A2
  191. ;                                            + 44         A3
  192. ;                                            + 48         A4
  193. ;                                            + 52         A5
  194. ;                                            + 56         A6
  195. ;                                            + 60         SR of task
  196. ;                                            + 64         PC of task           High Memory
  197. ;
  198. ;*******************************************************************************************
  199. */
  200. _OSCtxSw:
  201.        LEA       -60(A7),A7
  202.        MOVEM.L   D0-D7/A0-A6,(A7)         //保存寄存器到当前任务的堆栈
  203.        JSR       _OSTaskSwHook            
  204.        MOVE.L    (_OSTCBCur),A1           //在当前任务TCB中保存栈顶指针
  205.        MOVE.L    A7,(A1)
  206.        MOVE.L    (_OSTCBHighRdy),A1       // OSTCBCur = OSTCBHighRdy
  207.        MOVE.L    A1,(_OSTCBCur)
  208.        MOVE.L    (A1),A7                  //取得将要运行任务的堆栈
  209.   
  210.        MOVE.B    (_OSPrioHighRdy),D0      // OSPrioCur = OSPrioHighRdy 
  211.        MOVE.B    D0,(_OSPrioCur)
  212.   
  213.        MOVEM.L   (A7),D0-D7/A0-A6         //恢复CPU寄存器
  214.        LEA       60(A7),A7
  215.        RTE                                
  216. /*
  217. ;*******************************************************************************************
  218. ;                                 INTERRUPT LEVEL CONTEXT SWITCH
  219. ;
  220. ;
  221. ; Description : This function is provided for backward compatibility and to 
  222. ;               satisfy OSIntExit() 
  223. ;               in OS_CORE.C.
  224. ;
  225. ; Arguments   : none
  226. ;*******************************************************************************************
  227. */
  228. _OSIntCtxSw: 
  229.       JSR        _OSTaskSwHook       
  230.       MOVE.B     (_OSPrioHighRdy),D0      //OSPrioCur = OSPrioHighRdy 
  231.       MOVE.B     D0,(_OSPrioCur)
  232.     
  233.       MOVE.L     (_OSTCBHighRdy),A1       //OSTCBCur  = OSTCBHighRdy
  234.       MOVE.L     A1,(_OSTCBCur)
  235.       MOVE.L     (A1),A7                  //SP        = OSTCBHighRdy->OSTCBStkPtr
  236.     
  237.       MOVEM.L    (A7),D0-D7/A0-A6         //恢复CPU寄存器
  238.       LEA        60(A7),A7
  239.       RTE                                 //运行任务
  240. /*
  241. ;*******************************************************************************************
  242. ;                                        GENERIC ISR
  243. ;
  244. ; Description : This function shows how to write ISRs
  245. ;
  246. ; Arguments   : none
  247. ;
  248. ; Notes       : 1) You MUST save ALL the CPU registers as shown below
  249. ;               2) You MUST increment 'OSIntNesting' and NOT call OSIntEnter()
  250. ;               3) You MUST use OSIntExit() to exit an ISR with the MCF5275.
  251. ;*******************************************************************************************
  252. */
  253. _OS_My_ISR:
  254.       LEA        -60(A7),A7               /* Save processor registers onto stack           */
  255.       MOVEM.L    D0-D7/A0-A6,(A7)
  256.       MOVEQ.L    #0,D0                    /* OSIntNesting++                                */
  257.       MOVE.B     (_OSIntNesting),D0
  258.       ADDQ.L     #1,D0            
  259.       MOVE.B     D0,(_OSIntNesting)
  260.       CMPI.L     #1, D0                   /* if (OSIntNesting == 1)                        */
  261.       BNE        _OS_My_ISR_1
  262.       MOVE.L     (_OSTCBCur), A1          /*     OSTCBCur-<OSTCBStkPtr = SP                */
  263.       MOVE.L     A7,(A1)
  264. _OS_My_ISR_1:
  265.       JSR        _OS_My_ISR_Handler       /* OS_My_ISR_Handler()                           */
  266.       JSR        _OSIntExit               /* Exit the ISR                                  */
  267.       MOVEM.L    (A7),D0-D7/A0-A6         /* Restore processor registers from stack        */
  268.       LEA        60(A7),A7
  269.       RTE                                 /* Return to task or nested ISR                  */
  270. _OS_My_ISR_Handler:
  271.       RTS
  272.       
  273. /* create my ISR function */
  274. /* SW2 按键中断*/
  275. _irq1_handler:
  276. //SAVE ALL REGISTERS
  277. LEA -60(A7),A7
  278. MOVEM.L D0-D7/A0-A6,(A7)
  279. //OSIntNesting++,中断嵌套次数加1
  280. MOVEQ.L #0,D0
  281. MOVE.B (_OSIntNesting),D0
  282. ADDQ.L #1,D0
  283. MOVE.B D0,(_OSIntNesting)
  284. //如果OSIntNesting == 1,保存SP到当前任务的堆栈中
  285. CMPI.L #1,D0
  286. BNE _OS_IRQ1_ISR_1
  287. MOVE.L (_OSTCBCur),A1
  288. MOVE.L A7,(A1)
  289. _OS_IRQ1_ISR_1:
  290. JSR _OS_IRQ1_ISR_Handler
  291. JSR _OSIntExit
  292. //RESTORE ALL REGISTERS
  293. MOVEM.L (A7),D0-D7/A0-A6
  294. LEA 60(A7),A7
  295. RTE
  296. // sw2 按键中断
  297. _irq7_handler:
  298. //SAVE ALL REGISTERS
  299. LEA -60(A7),A7
  300. MOVEM.L D0-D7/A0-A6,(A7)
  301. //OSIntNesting++,中断嵌套次数加1
  302. MOVEQ.L #0,D0
  303. MOVE.B (_OSIntNesting),D0
  304. ADDQ.L #1,D0
  305. MOVE.B D0,(_OSIntNesting)
  306. //如果OSIntNesting == 1,保存SP到当前任务的堆栈中
  307. CMPI.L #1,D0
  308. BNE _OS_IRQ7_ISR_1
  309. MOVE.L (_OSTCBCur),A1
  310. MOVE.L A7,(A1)
  311. _OS_IRQ7_ISR_1:
  312. JSR _OS_IRQ7_ISR_Handler
  313. JSR _OSIntExit
  314. //RESTORE ALL REGISTERS
  315. MOVEM.L (A7),D0-D7/A0-A6
  316. LEA 60(A7),A7
  317. RTE
  318. // 时钟中断
  319. _pit0_handler:
  320. //SAVE ALL REGISTERS
  321. LEA -60(A7),A7
  322. MOVEM.L D0-D7/A0-A6,(A7)
  323. //OSIntNesting++,中断嵌套次数加1
  324. MOVEQ.L #0,D0
  325. MOVE.B (_OSIntNesting),D0
  326. ADDQ.L #1,D0
  327. MOVE.B D0,(_OSIntNesting)
  328. //如果OSIntNesting == 1,保存SP到当前任务的堆栈中
  329. CMPI.L #1,D0
  330. BNE _OS_PIT0_ISR_1
  331. MOVE.L (_OSTCBCur),A1
  332. MOVE.L A7,(A1)
  333. _OS_PIT0_ISR_1:
  334. JSR _OS_PIT0_ISR_Handler
  335. JSR _OSIntExit
  336. //RESTORE ALL REGISTERS
  337. MOVEM.L (A7),D0-D7/A0-A6
  338. LEA 60(A7),A7
  339. RTE
  340. // 串口中断
  341. _uart0_handler:
  342. //SAVE ALL REGISTERS
  343. LEA -60(A7),A7
  344. MOVEM.L D0-D7/A0-A6,(A7)
  345. //OSIntNesting++,中断嵌套次数加1
  346. MOVEQ.L #0,D0
  347. MOVE.B (_OSIntNesting),D0
  348. ADDQ.L #1,D0
  349. MOVE.B D0,(_OSIntNesting)
  350. //如果OSIntNesting == 1,保存SP到当前任务的堆栈中
  351. CMPI.L #1,D0
  352. BNE _OS_UART0_ISR_1
  353. MOVE.L (_OSTCBCur),A1
  354. MOVE.L A7,(A1)
  355. _OS_UART0_ISR_1:
  356. JSR _OS_UART0_ISR_Handler
  357. JSR _OSIntExit
  358. //RESTORE ALL REGISTERS
  359. MOVEM.L (A7),D0-D7/A0-A6
  360. LEA 60(A7),A7
  361. RTE        
  362. .end