你好,游客 登录 注册 搜索
背景:
阅读新闻

UCOS_II的移植到S3C2440 ADS 1.2

[日期:2012-07-22] 来源:Linux社区  作者:k122769836 [字体:大 中 小]

对Os_cpu_a.s的修改:

  1. ;*********************************************************************************************************  
  2. ;                                               uC/OS-II  
  3. ;                                         The Real-Time Kernel  
  4. ;  
  5. ;                          (c) Copyright 1992-2003, Jean J. Labrosse, Weston, FL  
  6. ;                                          All Rights Reserved  
  7. ;  
  8. ;                                               ARM920T Port  
  9. ;                                            ADS v1.2 Compiler  
  10. ;                                             Samsung S3C2440A  
  11. ;  
  12. ; File    : os_cpu_a.s refrence to ucos application note for arm AN-1014  
  13. ; Des     : S3C2440 uC/OS-II Port   
  14. ; by      : tangxiaofeng xidian 503  
  15. ; History :   
  16. ;  OSCtxSw(), OSIntCtxSw()  OSStartHighRdy() OS_CPU_IRQ_ISR() OSTickISR()  
  17. ;******************************************************************************************************** */  
  18.   
  19. SRCPND      EQU  0x4a000000    ; Source pending  
  20. INTPND      EQU  0x4a000010    ; Interrupt request status  
  21.   
  22. rEINTPEND   EQU  0x560000a8  
  23. INTOFFSET   EQU  0x4a000014  
  24.   
  25.   
  26. USERMODE    EQU     0x10  
  27. FIQMODE     EQU     0x11  
  28. IRQMODE     EQU     0x12  
  29. SVCMODE     EQU     0x13  
  30. ABORTMODE   EQU     0x17  
  31. UNDEFMODE   EQU     0x1b  
  32. MODEMASK    EQU     0x1f  
  33. NOINT       EQU     0xc0  
  34.   
  35. ;*********************************************************************************************************  
  36. ;                                    EXPORT and EXTERNAL REFERENCES  
  37. ;*********************************************************************************************************/  
  38.     IMPORT  OSRunning  
  39.     IMPORT  OSTCBCur  
  40.     IMPORT  OSTCBHighRdy  
  41.     IMPORT  OSPrioCur  
  42.     IMPORT  OSPrioHighRdy  
  43.     IMPORT  OSIntNesting  
  44.       
  45.               
  46.     IMPORT  OSIntEnter  
  47.     IMPORT  OSIntExit  
  48.     IMPORT  OSTaskSwHook  
  49.     IMPORT  OSTimeTick  
  50.       
  51.     IMPORT  HandleEINT0  
  52.       
  53.   
  54.     EXPORT  OSStartHighRdy  
  55.     EXPORT  OSCtxSw  
  56.     EXPORT  OSTickISR     
  57.     EXPORT  OSIntCtxSw  
  58.   
  59.     EXPORT  OSCPUSaveSR  
  60.     EXPORT  OSCPURestoreSR  
  61.       
  62.     EXPORT  OS_CPU_IRQ_ISR  
  63.       
  64.       
  65.     AREA UCOS_ARM, CODE, READONLY  
  66.       
  67. ;*********************************************************************************************************  
  68. ;                                          START MULTITASKING  
  69. ;                                       void OSStartHighRdy(void)  
  70. ;  
  71. ; The stack frame is assumed to look as follows:  
  72. ;  
  73. ;                               Entry Point(Task Name)              (High memory)  
  74. ;                               LR(R14)  
  75. ;                               R12  
  76. ;                               R11  
  77. ;                               R10  
  78. ;                               R9  
  79. ;                               R8  
  80. ;                               R7  
  81. ;                               R6  
  82. ;                               R5  
  83. ;                               R4  
  84. ;                               R3  
  85. ;                               R2  
  86. ;                               R1  
  87. ;                               R0 : argument  
  88. ; OSTCBHighRdy->OSTCBStkPtr --> CPSR                              (Low memory)  
  89. ;  
  90. ; Note : OSStartHighRdy() MUST:  
  91. ;           a) Call OSTaskSwHook() then,  
  92. ;           b) Set OSRunning to TRUE,  
  93. ;           c) Switch to the highest priority task.  
  94. ;********************************************************************************************************** */  
  95. OSStartHighRdy    
  96.     ;----------------------------------------------------------------------------------   
  97.     ; OSRunning = TRUE;  
  98.     ;----------------------------------------------------------------------------------   
  99.       
  100.     MSR     CPSR_cxsf,#SVCMODE|NOINT     ;Switch to SVC mode with IRQ&FIQ disable  
  101.       
  102.     BL      OSTaskSwHook            ;Call user define Task switch hook  
  103.       
  104.     LDR     R0, =OSRunning          ; OSRunning =TRUE  
  105.     MOV     R1, #1  
  106.     STRB    R1, [R0]  
  107.   
  108.     ;----------------------------------------------------------------------------------       
  109.     ;       SP = OSTCBHighRdy->OSTCBStkPtr;  
  110.     ;----------------------------------------------------------------------------------   
  111.     LDR     R0, =OSTCBHighRdy  
  112.     LDR     R0, [R0]           
  113.     LDR     SP, [R0]           
  114.   
  115.     ;----------------------------------------------------------------------------------       
  116.     ; Prepare to return to proper mode  
  117.     ;----------------------------------------------------------------------------------   
  118.     LDMFD   SP!, {R0}    
  119.     MSR     SPSR_cxsf, R0  
  120.     LDMFD   SP!, {R0-R12, LR, PC}^  
  121.   
  122.   
  123. ;**********************************************************************************************************  
  124. ;                                PERFORM A CONTEXT SWITCH (From task level)  
  125. ;                                           void OSCtxSw(void)  
  126. ;  
  127. ; Note(s):     1) Upon entry:   
  128. ;                 OSTCBCur      points to the OS_TCB of the task to suspend  
  129. ;                 OSTCBHighRdy  points to the OS_TCB of the task to resume  
  130. ;  
  131. ;              2) The stack frame of the task to suspend looks as follows:  
  132. ;                                                     
  133. ;                                                   PC                    (High memory)  
  134. ;                                                   LR(R14)                   
  135. ;                                                   R12  
  136. ;                                                   R11  
  137. ;                                                   R10  
  138. ;                                                   R9  
  139. ;                                                   R8  
  140. ;                                                   R7  
  141. ;                                                   R6  
  142. ;                                                   R5  
  143. ;                                                   R4  
  144. ;                                                   R3  
  145. ;                                                   R2  
  146. ;                                                   R1  
  147. ;                                                   R0  
  148. ;                       OSTCBCur->OSTCBStkPtr ----> CPSR                  (Low memory)  
  149. ;  
  150. ;  
  151. ;              3) The stack frame of the task to resume looks as follows:  
  152. ;  
  153. ;                                                   PC              (High memory)  
  154. ;                                                   LR(R14)   
  155. ;                                                   R12  
  156. ;                                                   R11  
  157. ;                                                   R10  
  158. ;                                                   R9  
  159. ;                                                   R8  
  160. ;                                                   R7  
  161. ;                                                   R6  
  162. ;                                                   R5  
  163. ;                                                   R4  
  164. ;                                                   R3  
  165. ;                                                   R2  
  166. ;                                                   R1  
  167. ;                                                   R0  
  168. ;                   OSTCBHighRdy->OSTCBStkPtr ---->   CPSR                    (Low memory)  
  169. ;*********************************************************************************************************/  
  170. OSCtxSw  
  171.       
  172.     STMFD   SP!, {LR}           ;PC  
  173.     STMFD   SP!, {R0-R12, LR}   ;R0-R12 LR  
  174.     MRS     R0,  CPSR       ;Push CPSR  
  175.     STMFD   SP!, {R0}     
  176.           
  177.     ;----------------------------------------------------------------------------------  
  178.     ;       OSTCBCur->OSTCBStkPtr = SP  
  179.     ;----------------------------------------------------------------------------------       
  180.     LDR     R0, =OSTCBCur  
  181.     LDR     R0, [R0]  
  182.     STR     SP, [R0]  
  183.       
  184.     ;----------------------------------------------------------------------------------       
  185.     ; OSTaskSwHook();  
  186.     ;---------------------------------------------------------------------------------    
  187.     BL      OSTaskSwHook  
  188.   
  189.     ;----------------------------------------------------------------------------------           
  190.     ; OSTCBCur = OSTCBHighRdy;  
  191.     ;----------------------------------------------------------------------------------       
  192.     LDR     R0, =OSTCBHighRdy  
  193.     LDR     R1, =OSTCBCur  
  194.     LDR     R0, [R0]  
  195.     STR     R0, [R1]  
  196.       
  197.     ;----------------------------------------------------------------------------------       
  198.     ; OSPrioCur = OSPrioHighRdy;  
  199.     ;----------------------------------------------------------------------------------       
  200.     LDR     R0, =OSPrioHighRdy  
  201.     LDR     R1, =OSPrioCur  
  202.     LDRB    R0, [R0]  
  203.     STRB    R0, [R1]  
  204.       
  205.     ;----------------------------------------------------------------------------------       
  206.     ;  OSTCBHighRdy->OSTCBStkPtr;  
  207.     ;----------------------------------------------------------------------------------       
  208.     LDR     R0, =OSTCBHighRdy  
  209.     LDR     R0, [R0]  
  210.     LDR     SP, [R0]  
  211.   
  212.     ;----------------------------------------------------------------------------------   
  213.     ;Restore New task context  
  214.     ;----------------------------------------------------------------------------------   
  215.     LDMFD   SP!, {R0}       ;POP CPSR  
  216.     MSR     SPSR_cxsf, R0  
  217.     LDMFD   SP!, {R0-R12, LR, PC}^    
  218.   
  219.       
  220. ;*********************************************************************************************************  
  221. ;                                            TICK HANDLER  
  222. ;  
  223. ; Description:    
  224. ;     This handles all the Timer0(INT_TIMER0) interrupt which is used to generate the uC/OS-II tick.  
  225. ;*********************************************************************************************************/  
  226.   
  227. OSTickISR  
  228.     MOV     R5,LR     
  229.     MOV     R1, #1  
  230.     MOV     R1, R1, LSL #10     ; Timer0 Source Pending Reg.  
  231.     LDR     R0, =SRCPND  
  232.     LDR     R2, [R0]  
  233.     ORR     R1, R1,R2  
  234.     STR     R1, [R0]  
  235.   
  236.     LDR     R0, =INTPND  
  237.     LDR     R1, [R0]  
  238.     STR     R1, [R0]          
  239.   
  240.     ;----------------------------------------------------------------------------------       
  241.     ; OSTimeTick();  
  242.     ;----------------------------------------------------------------------------------   
  243.     BL      OSTimeTick  
  244.       
  245.       
  246.     MOV    PC, R5               ; Return      
  247.       
  248. ;*********************************************************************************************************  
  249. ;                                PERFORM A CONTEXT SWITCH (From an ISR)  
  250. ;                                        void OSIntCtxSw(void)  
  251. ;  
  252. ; Description: 1) This code performs a context switch if a higher priority task has been made ready-to-run  
  253. ;                   during an ISR.  
  254. ;  
  255. ;              2) The stack frame of the task to suspend looks as follows:  
  256. ;  
  257. ;                                                   PC                  (High memory)  
  258. ;                                                   LR(R14)  
  259. ;                                                   R12  
  260. ;                                                   R11  
  261. ;                                                   R10  
  262. ;                                                   R9  
  263. ;                                                   R8  
  264. ;                                                   R7  
  265. ;                                                   R6  
  266. ;                                                   R5  
  267. ;                                                   R4  
  268. ;                                                   R3  
  269. ;                                                   R2  
  270. ;                                                   R1  
  271. ;                                                   R0  
  272. ;                                                     
  273. ;                       OSTCBCur->OSTCBStkPtr ----> CPSR                  (Low memory)  
  274. ;  
  275. ;  
  276. ;              3) The stack frame of the task to resume looks as follows:  
  277. ;  
  278. ;                                                   PC                  (High memory)  
  279. ;                                                   LR(R14)   
  280. ;                                                   R12  
  281. ;                                                   R11  
  282. ;                                                   R10  
  283. ;                                                   R9  
  284. ;                                                   R8  
  285. ;                                                   R7  
  286. ;                                                   R6  
  287. ;                                                   R5  
  288. ;                                                   R4  
  289. ;                                                   R3  
  290. ;                                                   R2  
  291. ;                                                   R1  
  292. ;                                                   R0  
  293. ;                   OSTCBHighRdy->OSTCBStkPtr ---->   CPSR                    (Low memory)  
  294. ;*********************************************************************************************************/  
  295. OSIntCtxSw  
  296.     ;----------------------------------------------------------------------------------       
  297.     ; Call OSTaskSwHook();  
  298.     ;----------------------------------------------------------------------------------   
  299.     BL      OSTaskSwHook  
  300.       
  301.     ;----------------------------------------------------------------------------------           
  302.     ; OSTCBCur = OSTCBHighRdy;  
  303.     ;----------------------------------------------------------------------------------       
  304.     LDR     R0, =OSTCBHighRdy  
  305.     LDR     R1, =OSTCBCur  
  306.     LDR     R0, [R0]  
  307.     STR     R0, [R1]  
  308.       
  309.     ;----------------------------------------------------------------------------------       
  310.     ; OSPrioCur = OSPrioHighRdy;  
  311.     ;----------------------------------------------------------------------------------       
  312.     LDR     R0, =OSPrioHighRdy  
  313.     LDR     R1, =OSPrioCur  
  314.     LDRB    R0, [R0]  
  315.     STRB    R0, [R1]  
  316.       
  317.     ;----------------------------------------------------------------------------------       
  318.     ;       SP = OSTCBHighRdy->OSTCBStkPtr;  
  319.     ;----------------------------------------------------------------------------------       
  320.     LDR     R0, =OSTCBHighRdy  
  321.     LDR     R0, [R0]  
  322.     LDR     SP, [R0]  
  323.       
  324.     ;----------------------------------------------------------------------------------   
  325.     ; Restore New Task context  
  326.     ;----------------------------------------------------------------------------------   
  327.     LDMFD   SP!, {R0}              ;POP CPSR  
  328.     MSR     SPSR_cxsf, R0  
  329.     LDMFD   SP!, {R0-R12, LR, PC}^    
  330.       
  331.   
  332.       
  333. OS_CPU_IRQ_ISR    
  334.   
  335.     STMFD   SP!, {R1-R3}            ; We will use R1-R3 as temporary registers  
  336. ;----------------------------------------------------------------------------  
  337. ;   R1--SP  
  338. ;   R2--PC   
  339. ;   R3--SPSR  
  340. ;------------------------------------------------------------------------  
  341.     MOV     R1, SP  
  342.     ADD     SP, SP, #12             ;Adjust IRQ stack pointer  
  343.     SUB     R2, LR, #4              ;Adjust PC for return address to task  
  344.   
  345.     MRS     R3, SPSR                ; Copy SPSR (Task CPSR)  
  346.       
  347.      
  348.   
  349.     MSR     CPSR_cxsf, #SVCMODE|NOINT   ;Change to SVC mode  
  350.   
  351.                                     ; SAVE TASK''S CONTEXT ONTO OLD TASK''S STACK  
  352.                                       
  353.     STMFD   SP!, {R2}               ; Push task''s PC   
  354.     STMFD   SP!, {R4-R12, LR}       ; Push task''s LR,R12-R4  
  355.       
  356.     LDMFD   R1!, {R4-R6}            ; Load Task''s R1-R3 from IRQ stack   
  357.     STMFD   SP!, {R4-R6}            ; Push Task''s R1-R3 to SVC stack  
  358.     STMFD   SP!, {R0}               ; Push Task''s R0 to SVC stack  
  359.       
  360.     STMFD   SP!, {R3}               ; Push task''s CPSR  
  361.       
  362.     LDR     R0,=OSIntNesting        ;OSIntNesting++  
  363.     LDRB    R1,[R0]  
  364.     ADD     R1,R1,#1  
  365.     STRB    R1,[R0]   
  366.       
  367.     CMP     R1,#1                   ;if(OSIntNesting==1){  
  368.     BNE     %F1  
  369.        
  370.     LDR     R4,=OSTCBCur            ;OSTCBHighRdy->OSTCBStkPtr=SP;  
  371.     LDR     R5,[R4]  
  372.     STR     SP,[R5]                 ;}  
  373.       
  374. 1  
  375.     MSR    CPSR_c,#IRQMODE|NOINT    ;Change to IRQ mode to use IRQ stack to handle interrupt  
  376.       
  377.     LDR     R0, =INTOFFSET  
  378.     LDR     R0, [R0]  
  379.          
  380.     LDR     R1, IRQIsrVect  
  381.     MOV     LR, PC                          ; Save LR befor jump to the C function we need return back  
  382.     LDR     PC, [R1, R0, LSL #2]            ; Call OS_CPU_IRQ_ISR_handler();     
  383.       
  384.     MSR     CPSR_c,#SVCMODE|NOINT   ;Change to SVC mode  
  385.     BL      OSIntExit           ;Call OSIntExit  
  386.       
  387.     LDMFD   SP!,{R4}               ;POP the task''s CPSR   
  388.     MSR     SPSR_cxsf,R4  
  389.     LDMFD   SP!,{R0-R12,LR,PC}^    ;POP new Task''s context  
  390.   
  391. IRQIsrVect DCD HandleEINT0    
  392.       
  393. ;*********************************************************************************************************  
  394. ;                                   CRITICAL SECTION METHOD 3 FUNCTIONS  
  395. ;  
  396. ; Description: Disable/Enable interrupts by preserving the state of interrupts.  Generally speaking you  
  397. ;              would store the state of the interrupt disable flag in the local variable 'cpu_sr' and then  
  398. ;              disable interrupts.  'cpu_sr' is allocated in all of uC/OS-II''s functions that need to   
  399. ;              disable interrupts.  You would restore the interrupt disable state by copying back 'cpu_sr'  
  400. ;              into the CPU''s status register.  
  401. ;  
  402. ; Prototypes : OS_CPU_SR  OSCPUSaveSR(void);  
  403. ;              void       OSCPURestoreSR(OS_CPU_SR cpu_sr);  
  404. ;  
  405. ;  
  406. ; Note(s)    : 1) These functions are used in general like this:  
  407. ;  
  408. ;                 void Task (void *p_arg)  
  409. ;                 {  
  410. ;                 #if OS_CRITICAL_METHOD == 3          /* Allocate storage for CPU status register */  
  411. ;                     OS_CPU_SR  cpu_sr;  
  412. ;                 #endif  
  413. ;  
  414. ;                          :  
  415. ;                          :  
  416. ;                     OS_ENTER_CRITICAL();             /* cpu_sr = OSCPUSaveSR();                */  
  417. ;                          :  
  418. ;                          :  
  419. ;                     OS_EXIT_CRITICAL();              /* OSCPURestoreSR(cpu_sr);                */  
  420. ;                          :  
  421. ;                          :  
  422. ;                 }  
  423. ;  
  424. ;              2) OSCPUSaveSR() is implemented as recommended by Atmel''s application note:  
  425. ;  
  426. ;                    "Disabling Interrupts at Processor Level"  
  427. ;*********************************************************************************************************  
  428. OSCPUSaveSR  
  429.     MRS     R0, CPSR                ; Set IRQ and FIQ bits in CPSR to disable all interrupts  
  430.     ORR     R1, R0, #0xC0  
  431.     MSR     CPSR_c, R1  
  432.     MRS     R1, CPSR                ; Confirm that CPSR contains the proper interrupt disable flags  
  433.     AND     R1, R1, #0xC0  
  434.     CMP     R1, #0xC0  
  435.     BNE     OSCPUSaveSR             ; Not properly disabled (try again)  
  436.     MOV     PC, LR                  ; Disabled, return the original CPSR contents in R0  
  437.   
  438. OSCPURestoreSR  
  439.     MSR     CPSR_c, R0  
  440.     MOV     PC, LR  
  441.               
  442.     END  

 

  1. ;*********************************************************************************************************  
  2. ;                                               uC/OS-II  
  3. ;                                         The Real-Time Kernel  
  4. ;  
  5. ;                          (c) Copyright 1992-2003, Jean J. Labrosse, Weston, FL  
  6. ;                                          All Rights Reserved  
  7. ;  
  8. ;                                               ARM920T Port  
  9. ;                                            ADS v1.2 Compiler  
  10. ;                                             Samsung S3C2440A  
  11. ;  
  12. ; File    : os_cpu_a.s refrence to ucos application note for arm AN-1014  
  13. ; Des     : S3C2440 uC/OS-II Port   
  14. ; by      : tangxiaofeng xidian 503  
  15. ; History :   
  16. ;  OSCtxSw(), OSIntCtxSw()  OSStartHighRdy() OS_CPU_IRQ_ISR() OSTickISR()  
  17. ;******************************************************************************************************** */  
  18.   
  19. SRCPND      EQU  0x4a000000    ; Source pending  
  20. INTPND      EQU  0x4a000010    ; Interrupt request status  
  21.   
  22. rEINTPEND   EQU  0x560000a8  
  23. INTOFFSET   EQU  0x4a000014  
  24.   
  25.   
  26. USERMODE    EQU     0x10  
  27. FIQMODE     EQU     0x11  
  28. IRQMODE     EQU     0x12  
  29. SVCMODE     EQU     0x13  
  30. ABORTMODE   EQU     0x17  
  31. UNDEFMODE   EQU     0x1b  
  32. MODEMASK    EQU     0x1f  
  33. NOINT       EQU     0xc0  
  34.   
  35. ;*********************************************************************************************************  
  36. ;                                    EXPORT and EXTERNAL REFERENCES  
  37. ;*********************************************************************************************************/  
  38.     IMPORT  OSRunning  
  39.     IMPORT  OSTCBCur  
  40.     IMPORT  OSTCBHighRdy  
  41.     IMPORT  OSPrioCur  
  42.     IMPORT  OSPrioHighRdy  
  43.     IMPORT  OSIntNesting  
  44.       
  45.               
  46.     IMPORT  OSIntEnter  
  47.     IMPORT  OSIntExit  
  48.     IMPORT  OSTaskSwHook  
  49.     IMPORT  OSTimeTick  
  50.       
  51.     IMPORT  HandleEINT0  
  52.       
  53.   
  54.     EXPORT  OSStartHighRdy  
  55.     EXPORT  OSCtxSw  
  56.     EXPORT  OSTickISR     
  57.     EXPORT  OSIntCtxSw  
  58.   
  59.     EXPORT  OSCPUSaveSR  
  60.     EXPORT  OSCPURestoreSR  
  61.       
  62.     EXPORT  OS_CPU_IRQ_ISR  
  63.       
  64.       
  65.     AREA UCOS_ARM, CODE, READONLY  
  66.       
  67. ;*********************************************************************************************************  
  68. ;                                          START MULTITASKING  
  69. ;                                       void OSStartHighRdy(void)  
  70. ;  
  71. ; The stack frame is assumed to look as follows:  
  72. ;  
  73. ;                               Entry Point(Task Name)              (High memory)  
  74. ;                               LR(R14)  
  75. ;                               R12  
  76. ;                               R11  
  77. ;                               R10  
  78. ;                               R9  
  79. ;                               R8  
  80. ;                               R7  
  81. ;                               R6  
  82. ;                               R5  
  83. ;                               R4  
  84. ;                               R3  
  85. ;                               R2  
  86. ;                               R1  
  87. ;                               R0 : argument  
  88. ; OSTCBHighRdy->OSTCBStkPtr --> CPSR                              (Low memory)  
  89. ;  
  90. ; Note : OSStartHighRdy() MUST:  
  91. ;           a) Call OSTaskSwHook() then,  
  92. ;           b) Set OSRunning to TRUE,  
  93. ;           c) Switch to the highest priority task.  
  94. ;********************************************************************************************************** */  
  95. OSStartHighRdy    
  96.     ;----------------------------------------------------------------------------------   
  97.     ; OSRunning = TRUE;  
  98.     ;----------------------------------------------------------------------------------   
  99.       
  100.     MSR     CPSR_cxsf,#SVCMODE|NOINT     ;Switch to SVC mode with IRQ&FIQ disable  
  101.       
  102.     BL      OSTaskSwHook            ;Call user define Task switch hook  
  103.       
  104.     LDR     R0, =OSRunning          ; OSRunning =TRUE  
  105.     MOV     R1, #1  
  106.     STRB    R1, [R0]  
  107.   
  108.     ;----------------------------------------------------------------------------------       
  109.     ;       SP = OSTCBHighRdy->OSTCBStkPtr;  
  110.     ;----------------------------------------------------------------------------------   
  111.     LDR     R0, =OSTCBHighRdy  
  112.     LDR     R0, [R0]           
  113.     LDR     SP, [R0]           
  114.   
  115.     ;----------------------------------------------------------------------------------       
  116.     ; Prepare to return to proper mode  
  117.     ;----------------------------------------------------------------------------------   
  118.     LDMFD   SP!, {R0}    
  119.     MSR     SPSR_cxsf, R0  
  120.     LDMFD   SP!, {R0-R12, LR, PC}^  
  121.   
  122.   
  123. ;**********************************************************************************************************  
  124. ;                                PERFORM A CONTEXT SWITCH (From task level)  
  125. ;                                           void OSCtxSw(void)  
  126. ;  
  127. ; Note(s):     1) Upon entry:   
  128. ;                 OSTCBCur      points to the OS_TCB of the task to suspend  
  129. ;                 OSTCBHighRdy  points to the OS_TCB of the task to resume  
  130. ;  
  131. ;              2) The stack frame of the task to suspend looks as follows:  
  132. ;                                                     
  133. ;                                                   PC                    (High memory)  
  134. ;                                                   LR(R14)                   
  135. ;                                                   R12  
  136. ;                                                   R11  
  137. ;                                                   R10  
  138. ;                                                   R9  
  139. ;                                                   R8  
  140. ;                                                   R7  
  141. ;                                                   R6  
  142. ;                                                   R5  
  143. ;                                                   R4  
  144. ;                                                   R3  
  145. ;                                                   R2  
  146. ;                                                   R1  
  147. ;                                                   R0  
  148. ;                       OSTCBCur->OSTCBStkPtr ----> CPSR                  (Low memory)  
  149. ;  
  150. ;  
  151. ;              3) The stack frame of the task to resume looks as follows:  
  152. ;  
  153. ;                                                   PC              (High memory)  
  154. ;                                                   LR(R14)   
  155. ;                                                   R12  
  156. ;                                                   R11  
  157. ;                                                   R10  
  158. ;                                                   R9  
  159. ;                                                   R8  
  160. ;                                                   R7  
  161. ;                                                   R6  
  162. ;                                                   R5  
  163. ;                                                   R4  
  164. ;                                                   R3  
  165. ;                                                   R2  
  166. ;                                                   R1  
  167. ;                                                   R0  
  168. ;                   OSTCBHighRdy->OSTCBStkPtr ---->   CPSR                    (Low memory)  
  169. ;*********************************************************************************************************/  
  170. OSCtxSw  
  171.       
  172.     STMFD   SP!, {LR}           ;PC  
  173.     STMFD   SP!, {R0-R12, LR}   ;R0-R12 LR  
  174.     MRS     R0,  CPSR       ;Push CPSR  
  175.     STMFD   SP!, {R0}     
  176.           
  177.     ;----------------------------------------------------------------------------------  
  178.     ;       OSTCBCur->OSTCBStkPtr = SP  
  179.     ;----------------------------------------------------------------------------------       
  180.     LDR     R0, =OSTCBCur  
  181.     LDR     R0, [R0]  
  182.     STR     SP, [R0]  
  183.       
  184.     ;----------------------------------------------------------------------------------       
  185.     ; OSTaskSwHook();  
  186.     ;---------------------------------------------------------------------------------    
  187.     BL      OSTaskSwHook  
  188.   
  189.     ;----------------------------------------------------------------------------------           
  190.     ; OSTCBCur = OSTCBHighRdy;  
  191.     ;----------------------------------------------------------------------------------       
  192.     LDR     R0, =OSTCBHighRdy  
  193.     LDR     R1, =OSTCBCur  
  194.     LDR     R0, [R0]  
  195.     STR     R0, [R1]  
  196.       
  197.     ;----------------------------------------------------------------------------------       
  198.     ; OSPrioCur = OSPrioHighRdy;  
  199.     ;----------------------------------------------------------------------------------       
  200.     LDR     R0, =OSPrioHighRdy  
  201.     LDR     R1, =OSPrioCur  
  202.     LDRB    R0, [R0]  
  203.     STRB    R0, [R1]  
  204.       
  205.     ;----------------------------------------------------------------------------------       
  206.     ;  OSTCBHighRdy->OSTCBStkPtr;  
  207.     ;----------------------------------------------------------------------------------       
  208.     LDR     R0, =OSTCBHighRdy  
  209.     LDR     R0, [R0]  
  210.     LDR     SP, [R0]  
  211.   
  212.     ;----------------------------------------------------------------------------------   
  213.     ;Restore New task context  
  214.     ;----------------------------------------------------------------------------------   
  215.     LDMFD   SP!, {R0}       ;POP CPSR  
  216.     MSR     SPSR_cxsf, R0  
  217.     LDMFD   SP!, {R0-R12, LR, PC}^    
  218.   
  219.       
  220. ;*********************************************************************************************************  
  221. ;                                            TICK HANDLER  
  222. ;  
  223. ; Description:    
  224. ;     This handles all the Timer0(INT_TIMER0) interrupt which is used to generate the uC/OS-II tick.  
  225. ;*********************************************************************************************************/  
  226.   
  227. OSTickISR  
  228.     MOV     R5,LR     
  229.     MOV     R1, #1  
  230.     MOV     R1, R1, LSL #10     ; Timer0 Source Pending Reg.  
  231.     LDR     R0, =SRCPND  
  232.     LDR     R2, [R0]  
  233.     ORR     R1, R1,R2  
  234.     STR     R1, [R0]  
  235.   
  236.     LDR     R0, =INTPND  
  237.     LDR     R1, [R0]  
  238.     STR     R1, [R0]          
  239.   
  240.     ;----------------------------------------------------------------------------------       
  241.     ; OSTimeTick();  
  242.     ;----------------------------------------------------------------------------------   
  243.     BL      OSTimeTick  
  244.       
  245.       
  246.     MOV    PC, R5               ; Return      
  247.       
  248. ;*********************************************************************************************************  
  249. ;                                PERFORM A CONTEXT SWITCH (From an ISR)  
  250. ;                                        void OSIntCtxSw(void)  
  251. ;  
  252. ; Description: 1) This code performs a context switch if a higher priority task has been made ready-to-run  
  253. ;                   during an ISR.  
  254. ;  
  255. ;              2) The stack frame of the task to suspend looks as follows:  
  256. ;  
  257. ;                                                   PC                  (High memory)  
  258. ;                                                   LR(R14)  
  259. ;                                                   R12  
  260. ;                                                   R11  
  261. ;                                                   R10  
  262. ;                                                   R9  
  263. ;                                                   R8  
  264. ;                                                   R7  
  265. ;                                                   R6  
  266. ;                                                   R5  
  267. ;                                                   R4  
  268. ;                                                   R3  
  269. ;                                                   R2  
  270. ;                                                   R1  
  271. ;                                                   R0  
  272. ;                                                     
  273. ;                       OSTCBCur->OSTCBStkPtr ----> CPSR                  (Low memory)  
  274. ;  
  275. ;  
  276. ;              3) The stack frame of the task to resume looks as follows:  
  277. ;  
  278. ;                                                   PC                  (High memory)  
  279. ;                                                   LR(R14)   
  280. ;                                                   R12  
  281. ;                                                   R11  
  282. ;                                                   R10  
  283. ;                                                   R9  
  284. ;                                                   R8  
  285. ;                                                   R7  
  286. ;                                                   R6  
  287. ;                                                   R5  
  288. ;                                                   R4  
  289. ;                                                   R3  
  290. ;                                                   R2  
  291. ;                                                   R1  
  292. ;                                                   R0  
  293. ;                   OSTCBHighRdy->OSTCBStkPtr ---->   CPSR                    (Low memory)  
  294. ;*********************************************************************************************************/  
  295. OSIntCtxSw  
  296.     ;----------------------------------------------------------------------------------       
  297.     ; Call OSTaskSwHook();  
  298.     ;----------------------------------------------------------------------------------   
  299.     BL      OSTaskSwHook  
  300.       
  301.     ;----------------------------------------------------------------------------------           
  302.     ; OSTCBCur = OSTCBHighRdy;  
  303.     ;----------------------------------------------------------------------------------       
  304.     LDR     R0, =OSTCBHighRdy  
  305.     LDR     R1, =OSTCBCur  
  306.     LDR     R0, [R0]  
  307.     STR     R0, [R1]  
  308.       
  309.     ;----------------------------------------------------------------------------------       
  310.     ; OSPrioCur = OSPrioHighRdy;  
  311.     ;----------------------------------------------------------------------------------       
  312.     LDR     R0, =OSPrioHighRdy  
  313.     LDR     R1, =OSPrioCur  
  314.     LDRB    R0, [R0]  
  315.     STRB    R0, [R1]  
  316.       
  317.     ;----------------------------------------------------------------------------------       
  318.     ;       SP = OSTCBHighRdy->OSTCBStkPtr;  
  319.     ;----------------------------------------------------------------------------------       
  320.     LDR     R0, =OSTCBHighRdy  
  321.     LDR     R0, [R0]  
  322.     LDR     SP, [R0]  
  323.       
  324.     ;----------------------------------------------------------------------------------   
  325.     ; Restore New Task context  
  326.     ;----------------------------------------------------------------------------------   
  327.     LDMFD   SP!, {R0}              ;POP CPSR  
  328.     MSR     SPSR_cxsf, R0  
  329.     LDMFD   SP!, {R0-R12, LR, PC}^    
  330.       
  331.   
  332.       
  333. OS_CPU_IRQ_ISR    
  334.   
  335.     STMFD   SP!, {R1-R3}            ; We will use R1-R3 as temporary registers  
  336. ;----------------------------------------------------------------------------  
  337. ;   R1--SP  
  338. ;   R2--PC   
  339. ;   R3--SPSR  
  340. ;------------------------------------------------------------------------  
  341.     MOV     R1, SP  
  342.     ADD     SP, SP, #12             ;Adjust IRQ stack pointer  
  343.     SUB     R2, LR, #4              ;Adjust PC for return address to task  
  344.   
  345.     MRS     R3, SPSR                ; Copy SPSR (Task CPSR)  
  346.       
  347.      
  348.   
  349.     MSR     CPSR_cxsf, #SVCMODE|NOINT   ;Change to SVC mode  
  350.   
  351.                                     ; SAVE TASK''S CONTEXT ONTO OLD TASK''S STACK  
  352.                                       
  353.     STMFD   SP!, {R2}               ; Push task''s PC   
  354.     STMFD   SP!, {R4-R12, LR}       ; Push task''s LR,R12-R4  
  355.       
  356.     LDMFD   R1!, {R4-R6}            ; Load Task''s R1-R3 from IRQ stack   
  357.     STMFD   SP!, {R4-R6}            ; Push Task''s R1-R3 to SVC stack  
  358.     STMFD   SP!, {R0}               ; Push Task''s R0 to SVC stack  
  359.       
  360.     STMFD   SP!, {R3}               ; Push task''s CPSR  
  361.       
  362.     LDR     R0,=OSIntNesting        ;OSIntNesting++  
  363.     LDRB    R1,[R0]  
  364.     ADD     R1,R1,#1  
  365.     STRB    R1,[R0]   
  366.       
  367.     CMP     R1,#1                   ;if(OSIntNesting==1){  
  368.     BNE     %F1  
  369.        
  370.     LDR     R4,=OSTCBCur            ;OSTCBHighRdy->OSTCBStkPtr=SP;  
  371.     LDR     R5,[R4]  
  372.     STR     SP,[R5]                 ;}  
  373.       
  374. 1  
  375.     MSR    CPSR_c,#IRQMODE|NOINT    ;Change to IRQ mode to use IRQ stack to handle interrupt  
  376.       
  377.     LDR     R0, =INTOFFSET  
  378.     LDR     R0, [R0]  
  379.          
  380.     LDR     R1, IRQIsrVect  
  381.     MOV     LR, PC                          ; Save LR befor jump to the C function we need return back  
  382.     LDR     PC, [R1, R0, LSL #2]            ; Call OS_CPU_IRQ_ISR_handler();     
  383.       
  384.     MSR     CPSR_c,#SVCMODE|NOINT   ;Change to SVC mode  
  385.     BL      OSIntExit           ;Call OSIntExit  
  386.       
  387.     LDMFD   SP!,{R4}               ;POP the task''s CPSR   
  388.     MSR     SPSR_cxsf,R4  
  389.     LDMFD   SP!,{R0-R12,LR,PC}^    ;POP new Task''s context  
  390.   
  391. IRQIsrVect DCD HandleEINT0    
  392.       
  393. ;*********************************************************************************************************  
  394. ;                                   CRITICAL SECTION METHOD 3 FUNCTIONS  
  395. ;  
  396. ; Description: Disable/Enable interrupts by preserving the state of interrupts.  Generally speaking you  
  397. ;              would store the state of the interrupt disable flag in the local variable 'cpu_sr' and then  
  398. ;              disable interrupts.  'cpu_sr' is allocated in all of uC/OS-II''s functions that need to   
  399. ;              disable interrupts.  You would restore the interrupt disable state by copying back 'cpu_sr'  
  400. ;              into the CPU''s status register.  
  401. ;  
  402. ; Prototypes : OS_CPU_SR  OSCPUSaveSR(void);  
  403. ;              void       OSCPURestoreSR(OS_CPU_SR cpu_sr);  
  404. ;  
  405. ;  
  406. ; Note(s)    : 1) These functions are used in general like this:  
  407. ;  
  408. ;                 void Task (void *p_arg)  
  409. ;                 {  
  410. ;                 #if OS_CRITICAL_METHOD == 3          /* Allocate storage for CPU status register */  
  411. ;                     OS_CPU_SR  cpu_sr;  
  412. ;                 #endif  
  413. ;  
  414. ;                          :  
  415. ;                          :  
  416. ;                     OS_ENTER_CRITICAL();             /* cpu_sr = OSCPUSaveSR();                */  
  417. ;                          :  
  418. ;                          :  
  419. ;                     OS_EXIT_CRITICAL();              /* OSCPURestoreSR(cpu_sr);                */  
  420. ;                          :  
  421. ;                          :  
  422. ;                 }  
  423. ;  
  424. ;              2) OSCPUSaveSR() is implemented as recommended by Atmel''s application note:  
  425. ;  
  426. ;                    "Disabling Interrupts at Processor Level"  
  427. ;*********************************************************************************************************  
  428. OSCPUSaveSR  
  429.     MRS     R0, CPSR                ; Set IRQ and FIQ bits in CPSR to disable all interrupts  
  430.     ORR     R1, R0, #0xC0  
  431.     MSR     CPSR_c, R1  
  432.     MRS     R1, CPSR                ; Confirm that CPSR contains the proper interrupt disable flags  
  433.     AND     R1, R1, #0xC0  
  434.     CMP     R1, #0xC0  
  435.     BNE     OSCPUSaveSR             ; Not properly disabled (try again)  
  436.     MOV     PC, LR                  ; Disabled, return the original CPSR contents in R0  
  437.   
  438. OSCPURestoreSR  
  439.     MSR     CPSR_c, R0  
  440.     MOV     PC, LR  
  441.               
  442.     END  
linux
相关资讯       S3C2440  UCOS_II  UCOS 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款