UCOS_II的移植到S3C2440 ADS 1.2

来源:互联网 发布:安卓网游源码 编辑:程序博客网 时间:2024/05/18 20:47

UCOS_II的移植到S3C2440 ADS 1.2

分类: uC/OSii 581人阅读 评论(2) 收藏 举报
 一、新建工程
1.新建一个ARM Executable Image
2.创建uCOS_II文件夹,创建两个子文件夹,分别为ARM、SOURCE
ARM存放和平台相关的文件("OS_CPU.H" "Os_cpu_a.s" "Os_cpu_c.c" )
SOURCE下存入和平台无关的文件("ucos_ii.h" "os_cfg.h" "os_core.c" "os_flag.c" "os_mbox.c" "os_mem.c" "os_mutex.c" "os_q.c" "os_sem.c" "os_task.c" "os_time.c" "os_tmr.c" )
3.创建一个S3C2440文件夹,创建两个子文件夹,分别为INC、SRC
INC存放S3C2440相关头文件("2440addr.h" "2440lib.h" "2440slib.h" "config.h" "Def1.h" "lcd.h" "mmu.h" "Option.h" "Target.h" "Timer.h" )
SRC存放S3C2440相关源文件("Timer.c" "2440init.s" "2440lib.c" "2440slib.s" "Font_Libs.c" "iphone.c" "lcd.c" "mmu.c" "nand.c" "Target.c" )
4.创建一个app文件夹(app_cfg.h、main.c、Printf.c、Printf.h)
二、工程设置Edit->DebugRel Settings下
1.Target->Target Settings,Post-linker:ARM fromELF
2.Target->Access Paths选中Always Search User Paths(ucos_ii部分文件采用#include <>包涵,不修改这里找不到文件)
3.Language Settings下ARM Assembler、ARM C Compliler、ARM C++ Complier处理器设置成ARM920T
4.Language Settings下ARM C Compliler下Errors下去掉Implicit pointer c,ARM C Compliler下Warnings下去掉Unused declaration(-O1 -g+ -cpu ARM920T -Wx -Ec)
5.ARM Linker下,Output下RO Base设置成0x30000000,Options下Image entry point设置成0x30000000,Layout下Place at beginning of image下的Object/Symbol设置成2440init.o,Section设置成Init,Listings下选勾Image map、List file设置list.txt,勾上Sizes、Totals、Unused、Veneers

6.ARM fromELF下Output file name下填写输出的二进制

三、移植文件的修改

对OS_CPU.H的修改:

view plaincopy to clipboard
  1. /*   
  2. *********************************************************************************************************  
  3. *                                              ARM  
  4. *  
  5. * Method #1:  NOT IMPLEMENTED  
  6. *             Disable/Enable interrupts using simple instructions.  After critical section, interrupts  
  7. *             will be enabled even if they were disabled before entering the critical section.  
  8. *               
  9. * Method #2:  NOT IMPLEMENTED  
  10. *             Disable/Enable interrupts by preserving the state of interrupts.  In other words, if   
  11. *             interrupts were disabled before entering the critical section, they will be disabled when  
  12. *             leaving the critical section.  
  13. *             NOT IMPLEMENTED  
  14. *  
  15. * Method #3:  Disable/Enable interrupts by preserving the state of interrupts.  Generally speaking you  
  16. *             would store the state of the interrupt disable flag in the local variable 'cpu_sr' and then  
  17. *             disable interrupts.  'cpu_sr' is allocated in all of uC/OS-II's functions that need to   
  18. *             disable interrupts.  You would restore the interrupt disable state by copying back 'cpu_sr'  
  19. *             into the CPU's status register.  This is the prefered method to disable interrupts.  
  20. *********************************************************************************************************  
  21. */  
  22.   
  23. #define  OS_CRITICAL_METHOD    3  
  24.   
  25. #if      OS_CRITICAL_METHOD == 3  
  26. #define  OS_ENTER_CRITICAL()  (cpu_sr = OSCPUSaveSR())  /* Disable interrupts                        */  
  27. #define  OS_EXIT_CRITICAL()   (OSCPURestoreSR(cpu_sr))  /* Restore  interrupts                       */  
  28. #endif  
  29.   
  30. /*  
  31. *********************************************************************************************************  
  32. *                                         ARM Miscellaneous  
  33. *********************************************************************************************************  
  34. */  
  35.   
  36. #define  OS_STK_GROWTH        1                       /* Stack grows from HIGH to LOW memory on ARM    */  
  37.   
  38. #define  OS_TASK_SW()         OSCtxSw()  
[html] view plaincopy
  1. /*   
  2. *********************************************************************************************************  
  3. *                                              ARM  
  4. *  
  5. * Method #1:  NOT IMPLEMENTED  
  6. *             Disable/Enable interrupts using simple instructions.  After critical section, interrupts  
  7. *             will be enabled even if they were disabled before entering the critical section.  
  8. *               
  9. * Method #2:  NOT IMPLEMENTED  
  10. *             Disable/Enable interrupts by preserving the state of interrupts.  In other words, if   
  11. *             interrupts were disabled before entering the critical section, they will be disabled when  
  12. *             leaving the critical section.  
  13. *             NOT IMPLEMENTED  
  14. *  
  15. * Method #3:  Disable/Enable interrupts by preserving the state of interrupts.  Generally speaking you  
  16. *             would store the state of the interrupt disable flag in the local variable 'cpu_sr' and then  
  17. *             disable interrupts.  'cpu_sr' is allocated in all of uC/OS-II's functions that need to   
  18. *             disable interrupts.  You would restore the interrupt disable state by copying back 'cpu_sr'  
  19. *             into the CPU's status register.  This is the prefered method to disable interrupts.  
  20. *********************************************************************************************************  
  21. */  
  22.   
  23. #define  OS_CRITICAL_METHOD    3  
  24.   
  25. #if      OS_CRITICAL_METHOD == 3  
  26. #define  OS_ENTER_CRITICAL()  (cpu_sr = OSCPUSaveSR())  /* Disable interrupts                        */  
  27. #define  OS_EXIT_CRITICAL()   (OSCPURestoreSR(cpu_sr))  /* Restore  interrupts                       */  
  28. #endif  
  29.   
  30. /*  
  31. *********************************************************************************************************  
  32. *                                         ARM Miscellaneous  
  33. *********************************************************************************************************  
  34. */  
  35.   
  36. #define  OS_STK_GROWTH        1                       /* Stack grows from HIGH to LOW memory on ARM    */  
  37.   
  38. #define  OS_TASK_SW()         OSCtxSw()  

对Os_cpu_c.c的修改:

view plaincopy to clipboard
  1. /*  
  2. *********************************************************************************************************  
  3. *                                               uC/OS-II  
  4. *                                        The Real-Time Kernel  
  5. *  
  6. *                           (c) Copyright 1992-2003, Micrium, Inc., Weston, FL  
  7. *                                          All Rights Reserved  
  8. *  
  9. *                                               ARM9 Port  
  10. *  
  11. * File : OS_CPU_C.C  
  12. *********************************************************************************************************  
  13. */  
  14.   
  15. //#define  OS_CPU_GLOBALS  
  16. #include "ucos_ii.h"  
  17.   
  18.   
  19. /*  
  20. *********************************************************************************************************  
  21. *                                        INITIALIZE A TASK'S STACK  
  22. *  
  23. * Description: This function is called by either OSTaskCreate() or OSTaskCreateExt() to initialize the  
  24. *              stack frame of the task being created.  This function is highly processor specific.  
  25. *  
  26. * Arguments  : task          is a pointer to the task code  
  27. *  
  28. *              p_arg         is a pointer to a user supplied data area that will be passed to the task  
  29. *                            when the task first executes.  
  30. *  
  31. *              ptos          is a pointer to the top of stack.  It is assumed that 'ptos' points to  
  32. *                            a 'free' entry on the task stack.  If OS_STK_GROWTH is set to 1 then   
  33. *                            'ptos' will contain the HIGHEST valid address of the stack.  Similarly, if  
  34. *                            OS_STK_GROWTH is set to 0, the 'ptos' will contains the LOWEST valid address  
  35. *                            of the stack.  
  36. *  
  37. *              opt           specifies options that can be used to alter the behavior of OSTaskStkInit().  
  38. *                            (see uCOS_II.H for OS_TASK_OPT_???).  
  39. *  
  40. * Returns    : Always returns the location of the new top-of-stack' once the processor registers have  
  41. *              been placed on the stack in the proper order.  
  42. *  
  43. * Note(s)    : 1) Interrupts are enabled when your task starts executing.   
  44. *              2) All tasks run in SVC mode.  
  45. *********************************************************************************************************  
  46. */  
  47.   
  48. OS_STK *OSTaskStkInit (void (*task)(void *pd), void *p_arg, OS_STK *ptos, INT16U opt)  
  49. {  
  50.     OS_STK *stk;  
  51.   
  52.     optopt      = opt;                 /* 'opt' is not used, prevent warning                      */  
  53.       
  54.     stk      = ptos;                /* Load stack pointer                                      */  
  55.       
  56.     *(stk)   = (OS_STK)task;        /* Entry Point                                             */  
  57.     *(--stk) = (INT32U)0;           /* LR                                                      */  
  58.     *(--stk) = (INT32U)0;           /* R12                                                     */  
  59.     *(--stk) = (INT32U)0;           /* R11                                                     */  
  60.     *(--stk) = (INT32U)0;           /* R10                                                     */  
  61.     *(--stk) = (INT32U)0;           /* R9                                                      */  
  62.     *(--stk) = (INT32U)0;           /* R8                                                      */  
  63.     *(--stk) = (INT32U)0;           /* R7                                                      */  
  64.     *(--stk) = (INT32U)0;           /* R6                                                      */  
  65.     *(--stk) = (INT32U)0;           /* R5                                                      */  
  66.     *(--stk) = (INT32U)0;           /* R4                                                      */  
  67.     *(--stk) = (INT32U)0;           /* R3                                                      */  
  68.     *(--stk) = (INT32U)0;           /* R2                                                      */  
  69.     *(--stk) = (INT32U)0;           /* R1                                                      */  
  70.     *(--stk) = (INT32U)p_arg;       /* R0 : argument                                           */  
  71.     *(--stk) = (INT32U)0x00000013L; /* CPSR  (SVC mode, Enable both IRQ and FIQ interrupts)    */  
  72.                                                
  73.     return (stk);  
  74. }  
  75.   
  76. #if OS_CPU_HOOKS_EN  
  77. /*  
  78. *********************************************************************************************************  
  79. *                                       OS INITIALIZATION HOOK  
  80. *                                            (BEGINNING)  
  81. *  
  82. * Description: This function is called by OSInit() at the beginning of OSInit().  
  83. *  
  84. * Arguments  : none  
  85. *  
  86. * Note(s)    : 1) Interrupts should be disabled during this call.  
  87. *********************************************************************************************************  
  88. */  
  89. #if OS_VERSION > 203  
  90. void OSInitHookBegin (void)  
  91. {  
  92. }  
  93. #endif  
  94.   
  95. /*  
  96. *********************************************************************************************************  
  97. *                                       OS INITIALIZATION HOOK  
  98. *                                               (END)  
  99. *  
  100. * Description: This function is called by OSInit() at the end of OSInit().  
  101. *  
  102. * Arguments  : none  
  103. *  
  104. * Note(s)    : 1) Interrupts should be disabled during this call.  
  105. *********************************************************************************************************  
  106. */  
  107. #if OS_VERSION > 203  
  108. void OSInitHookEnd (void)  
  109. {  
  110. }  
  111. #endif  
  112.   
  113.   
  114. /*  
  115. *********************************************************************************************************  
  116. *                                          TASK CREATION HOOK  
  117. *  
  118. * Description: This function is called when a task is created.  
  119. *  
  120. * Arguments  : ptcb   is a pointer to the task control block of the task being created.  
  121. *  
  122. * Note(s)    : 1) Interrupts are disabled during this call.  
  123. *********************************************************************************************************  
  124. */  
  125. void OSTaskCreateHook (OS_TCB *ptcb)  
  126. {  
  127.     ptcbptcb = ptcb;                       /* Prevent compiler warning                                     */  
  128. }  
  129.   
  130.   
  131. /*  
  132. *********************************************************************************************************  
  133. *                                           TASK DELETION HOOK  
  134. *  
  135. * Description: This function is called when a task is deleted.  
  136. *  
  137. * Arguments  : ptcb   is a pointer to the task control block of the task being deleted.  
  138. *  
  139. * Note(s)    : 1) Interrupts are disabled during this call.  
  140. *********************************************************************************************************  
  141. */  
  142. void OSTaskDelHook (OS_TCB *ptcb)  
  143. {  
  144.     ptcbptcb = ptcb;                       /* Prevent compiler warning                                     */  
  145. }  
  146.   
  147. /*  
  148. *********************************************************************************************************  
  149. *                                           TASK SWITCH HOOK  
  150. *  
  151. * Description: This function is called when a task switch is performed.  This allows you to perform other  
  152. *              operations during a context switch.  
  153. *  
  154. * Arguments  : none  
  155. *  
  156. * Note(s)    : 1) Interrupts are disabled during this call.  
  157. *              2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that  
  158. *                 will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the   
  159. *                 task being switched out (i.e. the preempted task).  
  160. *********************************************************************************************************  
  161. */  
  162. void OSTaskSwHook (void)  
  163. {  
  164. }  
  165.   
  166. /*  
  167. *********************************************************************************************************  
  168. *                                           STATISTIC TASK HOOK  
  169. *  
  170. * Description: This function is called every second by uC/OS-II's statistics task.  This allows your   
  171. *              application to add functionality to the statistics task.  
  172. *  
  173. * Arguments  : none  
  174. *********************************************************************************************************  
  175. */  
  176. void OSTaskStatHook (void)  
  177. {  
  178. }  
  179.   
  180. /*  
  181. *********************************************************************************************************  
  182. *                                           OSTCBInit() HOOK  
  183. *  
  184. * Description: This function is called by OSTCBInit() after setting up most of the TCB.  
  185. *  
  186. * Arguments  : ptcb    is a pointer to the TCB of the task being created.  
  187. *  
  188. * Note(s)    : 1) Interrupts may or may not be ENABLED during this call.  
  189. *********************************************************************************************************  
  190. */  
  191. #if OS_VERSION > 203  
  192. void OSTCBInitHook (OS_TCB *ptcb)  
  193. {  
  194.     ptcbptcb = ptcb;                                           /* Prevent Compiler warning                 */  
  195. }  
  196. #endif  
  197.   
  198.   
  199. /*  
  200. *********************************************************************************************************  
  201. *                                               TICK HOOK  
  202. *  
  203. * Description: This function is called every tick.  
  204. *  
  205. * Arguments  : none  
  206. *  
  207. * Note(s)    : 1) Interrupts may or may not be ENABLED during this call.  
  208. *********************************************************************************************************  
  209. */  
  210. void OSTimeTickHook (void)  
  211. {  
  212. }  
  213.   
  214.   
  215. /*  
  216. *********************************************************************************************************  
  217. *                                             IDLE TASK HOOK  
  218. *  
  219. * Description: This function is called by the idle task.  This hook has been added to allow you to do    
  220. *              such things as STOP the CPU to conserve power.  
  221. *  
  222. * Arguments  : none  
  223. *  
  224. * Note(s)    : 1) Interrupts are enabled during this call.  
  225. *********************************************************************************************************  
  226. */  
  227. #if OS_VERSION >= 251  
  228. void OSTaskIdleHook (void)  
  229. {  
  230. }  
  231. #endif  
  232.   
  233. #endif  
[html] view plaincopy
  1. /*  
  2. *********************************************************************************************************  
  3. *                                               uC/OS-II  
  4. *                                        The Real-Time Kernel  
  5. *  
  6. *                           (c) Copyright 1992-2003, Micrium, Inc., Weston, FL  
  7. *                                          All Rights Reserved  
  8. *  
  9. *                                               ARM9 Port  
  10. *  
  11. * File : OS_CPU_C.C  
  12. *********************************************************************************************************  
  13. */  
  14.   
  15. //#define  OS_CPU_GLOBALS  
  16. #include "ucos_ii.h"  
  17.   
  18.   
  19. /*  
  20. *********************************************************************************************************  
  21. *                                        INITIALIZE A TASK'S STACK  
  22. *  
  23. * Description: This function is called by either OSTaskCreate() or OSTaskCreateExt() to initialize the  
  24. *              stack frame of the task being created.  This function is highly processor specific.  
  25. *  
  26. * Arguments  : task          is a pointer to the task code  
  27. *  
  28. *              p_arg         is a pointer to a user supplied data area that will be passed to the task  
  29. *                            when the task first executes.  
  30. *  
  31. *              ptos          is a pointer to the top of stack.  It is assumed that 'ptos' points to  
  32. *                            a 'free' entry on the task stack.  If OS_STK_GROWTH is set to 1 then   
  33. *                            'ptos' will contain the HIGHEST valid address of the stack.  Similarly, if  
  34. *                            OS_STK_GROWTH is set to 0, the 'ptos' will contains the LOWEST valid address  
  35. *                            of the stack.  
  36. *  
  37. *              opt           specifies options that can be used to alter the behavior of OSTaskStkInit().  
  38. *                            (see uCOS_II.H for OS_TASK_OPT_???).  
  39. *  
  40. * Returns    : Always returns the location of the new top-of-stack' once the processor registers have  
  41. *              been placed on the stack in the proper order.  
  42. *  
  43. * Note(s)    : 1) Interrupts are enabled when your task starts executing.   
  44. *              2) All tasks run in SVC mode.  
  45. *********************************************************************************************************  
  46. */  
  47.   
  48. OS_STK *OSTaskStkInit (void (*task)(void *pd), void *p_arg, OS_STK *ptos, INT16U opt)  
  49. {  
  50.     OS_STK *stk;  
  51.   
  52.     opt      = opt;                 /* 'opt' is not used, prevent warning                      */  
  53.       
  54.     stk      = ptos;                /* Load stack pointer                                      */  
  55.       
  56.     *(stk)   = (OS_STK)task;        /* Entry Point                                             */  
  57.     *(--stk) = (INT32U)0;           /* LR                                                      */  
  58.     *(--stk) = (INT32U)0;           /* R12                                                     */  
  59.     *(--stk) = (INT32U)0;           /* R11                                                     */  
  60.     *(--stk) = (INT32U)0;           /* R10                                                     */  
  61.     *(--stk) = (INT32U)0;           /* R9                                                      */  
  62.     *(--stk) = (INT32U)0;           /* R8                                                      */  
  63.     *(--stk) = (INT32U)0;           /* R7                                                      */  
  64.     *(--stk) = (INT32U)0;           /* R6                                                      */  
  65.     *(--stk) = (INT32U)0;           /* R5                                                      */  
  66.     *(--stk) = (INT32U)0;           /* R4                                                      */  
  67.     *(--stk) = (INT32U)0;           /* R3                                                      */  
  68.     *(--stk) = (INT32U)0;           /* R2                                                      */  
  69.     *(--stk) = (INT32U)0;           /* R1                                                      */  
  70.     *(--stk) = (INT32U)p_arg;       /* R0 : argument                                           */  
  71.     *(--stk) = (INT32U)0x00000013L; /* CPSR  (SVC mode, Enable both IRQ and FIQ interrupts)    */  
  72.                                                
  73.     return (stk);  
  74. }  
  75.   
  76. #if OS_CPU_HOOKS_EN  
  77. /*  
  78. *********************************************************************************************************  
  79. *                                       OS INITIALIZATION HOOK  
  80. *                                            (BEGINNING)  
  81. *  
  82. * Description: This function is called by OSInit() at the beginning of OSInit().  
  83. *  
  84. * Arguments  : none  
  85. *  
  86. * Note(s)    : 1) Interrupts should be disabled during this call.  
  87. *********************************************************************************************************  
  88. */  
  89. #if OS_VERSION > 203  
  90. void OSInitHookBegin (void)  
  91. {  
  92. }  
  93. #endif  
  94.   
  95. /*  
  96. *********************************************************************************************************  
  97. *                                       OS INITIALIZATION HOOK  
  98. *                                               (END)  
  99. *  
  100. * Description: This function is called by OSInit() at the end of OSInit().  
  101. *  
  102. * Arguments  : none  
  103. *  
  104. * Note(s)    : 1) Interrupts should be disabled during this call.  
  105. *********************************************************************************************************  
  106. */  
  107. #if OS_VERSION > 203  
  108. void OSInitHookEnd (void)  
  109. {  
  110. }  
  111. #endif  
  112.   
  113.   
  114. /*  
  115. *********************************************************************************************************  
  116. *                                          TASK CREATION HOOK  
  117. *  
  118. * Description: This function is called when a task is created.  
  119. *  
  120. * Arguments  : ptcb   is a pointer to the task control block of the task being created.  
  121. *  
  122. * Note(s)    : 1) Interrupts are disabled during this call.  
  123. *********************************************************************************************************  
  124. */  
  125. void OSTaskCreateHook (OS_TCB *ptcb)  
  126. {  
  127.     ptcb = ptcb;                       /* Prevent compiler warning                                     */  
  128. }  
  129.   
  130.   
  131. /*  
  132. *********************************************************************************************************  
  133. *                                           TASK DELETION HOOK  
  134. *  
  135. * Description: This function is called when a task is deleted.  
  136. *  
  137. * Arguments  : ptcb   is a pointer to the task control block of the task being deleted.  
  138. *  
  139. * Note(s)    : 1) Interrupts are disabled during this call.  
  140. *********************************************************************************************************  
  141. */  
  142. void OSTaskDelHook (OS_TCB *ptcb)  
  143. {  
  144.     ptcb = ptcb;                       /* Prevent compiler warning                                     */  
  145. }  
  146.   
  147. /*  
  148. *********************************************************************************************************  
  149. *                                           TASK SWITCH HOOK  
  150. *  
  151. * Description: This function is called when a task switch is performed.  This allows you to perform other  
  152. *              operations during a context switch.  
  153. *  
  154. * Arguments  : none  
  155. *  
  156. * Note(s)    : 1) Interrupts are disabled during this call.  
  157. *              2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that  
  158. *                 will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the   
  159. *                 task being switched out (i.e. the preempted task).  
  160. *********************************************************************************************************  
  161. */  
  162. void OSTaskSwHook (void)  
  163. {  
  164. }  
  165.   
  166. /*  
  167. *********************************************************************************************************  
  168. *                                           STATISTIC TASK HOOK  
  169. *  
  170. * Description: This function is called every second by uC/OS-II's statistics task.  This allows your   
  171. *              application to add functionality to the statistics task.  
  172. *  
  173. * Arguments  : none  
  174. *********************************************************************************************************  
  175. */  
  176. void OSTaskStatHook (void)  
  177. {  
  178. }  
  179.   
  180. /*  
  181. *********************************************************************************************************  
  182. *                                           OSTCBInit() HOOK  
  183. *  
  184. * Description: This function is called by OSTCBInit() after setting up most of the TCB.  
  185. *  
  186. * Arguments  : ptcb    is a pointer to the TCB of the task being created.  
  187. *  
  188. * Note(s)    : 1) Interrupts may or may not be ENABLED during this call.  
  189. *********************************************************************************************************  
  190. */  
  191. #if OS_VERSION > 203  
  192. void OSTCBInitHook (OS_TCB *ptcb)  
  193. {  
  194.     ptcb = ptcb;                                           /* Prevent Compiler warning                 */  
  195. }  
  196. #endif  
  197.   
  198.   
  199. /*  
  200. *********************************************************************************************************  
  201. *                                               TICK HOOK  
  202. *  
  203. * Description: This function is called every tick.  
  204. *  
  205. * Arguments  : none  
  206. *  
  207. * Note(s)    : 1) Interrupts may or may not be ENABLED during this call.  
  208. *********************************************************************************************************  
  209. */  
  210. void OSTimeTickHook (void)  
  211. {  
  212. }  
  213.   
  214.   
  215. /*  
  216. *********************************************************************************************************  
  217. *                                             IDLE TASK HOOK  
  218. *  
  219. * Description: This function is called by the idle task.  This hook has been added to allow you to do    
  220. *              such things as STOP the CPU to conserve power.  
  221. *  
  222. * Arguments  : none  
  223. *  
  224. * Note(s)    : 1) Interrupts are enabled during this call.  
  225. *********************************************************************************************************  
  226. */  
  227. #if OS_VERSION >= 251  
  228. void OSTaskIdleHook (void)  
  229. {  
  230. }  
  231. #endif  
  232.   
  233. #endif  

对Os_cpu_a.s的修改:

view plaincopy to clipboard
  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  
[html] view plaincopy
  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  
原创粉丝点击