ucosII实验代码解读及移植方法

OS_CPU_C.C修改部分:增加OSTaskReturnHook

删除OS_CPU_SysTickHandler()

#define SYSCLK_FREQ_72MHz  72000000

#define OS_TICKS_PER_SEC    200u          // Set the number of ticks in one second

系统滴答服务是5ms  1次,每秒200次 

 

OSCtxSw任务切换函数

OSIntCtxSw()中断中切换任务

这里是在中断中切换函数时的入口,最终任务切换在PendSV_Handler中完成,代码和上面的代码是基本一样的,区别在于在执行该函数时硬件无需再保存cpu寄存器,因为在调用之前已经发生了中断,已经保存过了。

 BX      LR

lr就是连接寄存器(Link Register, LR),在ARM体系中LR的特殊用途有两种:一是用来保存子程序返回地址;二是当异常发生时,LR中保存的值等于异常发生时PC的值减4(或减2),因此在各种异常模式下可以根据LR的值返回到异常发生前的相应位置继续执行。  

当通过BL或BLX指令调用子程序时,硬件自动将子程序返回地址保存在R14寄存器中。在子程序返回时,把LR的值复制到程序计数器PC即可实现子程序返回。

 

OSPrioCur和OSPrioHighRdy存放的是用户应用任务的优先级
OSTCBCur和OSTCBHighRdy二者都指向用户任务的任务控制块。

 

/**********************************************************************************************/

    LDR     R0, =OSPrioCur                         ; OSPrioCur = OSPrioHighRdy;

    LDR     R1, =OSPrioHighRdy

    LDRB    R2, [R1]

    STRB    R2, [R0]

PS:

   将全局变量OSPrioCur地址给R0,即R0=&OSPrioCur,

   将全局变量OSPrioHighRdy地址给R1,即R1=& OSPrioHighRdy,

   R2 = *R1 = OSPrioHighRdy,

   将R2的值赋给*R0,即*(& OSPrioCur)= OSPrioHighRdy。

  /*****************************************************************************************/

  /*****************************************************************************************/

LDR     R0, =OSTCBCur                         ; OSTCBCur  = OSTCBHighRdy;

    LDR     R1, =OSTCBHighRdy

    LDR     R2, [R1]

    STR     R2, [R0]

/*******************************************************************************************/

 

 

注释OS_CPU_SysTickInit()

注释void  OS_CPU_SysTickHandler (void)

 

OS_CPU.H修改部分: 删除Critical Section Management

OS_CPU_A.ASM修改部分:CODE GENERATION DIRECTIVES

LDR   R4, =NVIC_INT_CTRL     ;rigger the PendSV exception (causes context switch)

LDR  R5, =NVIC_PENDSVSET  置PENDSV中断触发,中断开启后就能进入PENDSV中断了

 

 

CRITICAL SECTION METHOD 3 FUNCTIONS包含:R0,R1替换成R4,R5

OSStartHighRdy部分

PendSV_Handler部分R0,R1修改不完全

 

 

 

 

OSTaskStkInit()并未修改

 

                  

 

 

 

临界区管理

#define OS_CRITICAL_METHOD     3u

#if     OS_CRITICAL_METHOD ==  3u

#define OS_ENTER_CRITICAL()

  {

   cpu_sr = OS_CPU_SR_Save();

}

#define OS_EXIT_CRITICAL()

  {

   OS_CPU_SR_Restore(cpu_sr );

}

# end if

采用方法3进入临界区,即在进入临界区的时候,保存寄存器的值到变量,然后关中断;在离开临界区的时候,开中断,然后将变量的值送回register。

 

OS_CPU_SR_Save

    MRS     R0, PRIMASK              ; Set prio int mask to mask all (except faults)

    CPSID   I

    BX      LR

//

OS_CPU_SR_Restore

    MSR     PRIMASK, R0

    BX      LR

PRIMASK是1位的寄存器,被置位后,可以屏蔽除不可屏蔽中断NMI之外的所有中断

 

移植工作包括以下几个内容:

  1. #define设置一个常量的值(OS_CPU.H)
  2. 声明10个数据类型(OS_CPU.H)

typedef unsigned char BOOLEAN;

typedef unsigned char INT8U; /*Unsigned 8bit quantity */   

typedef signed char   INT8S; /* Signed 8bit quantity */

typedef unsigned short INT16U; /* Unsigned 16bit quantity */

typedef signed short INT16S; /* Signed   16bit quantity */

typedef unsigned int   INT32U; /* Unsigned 32bit quantity */

typedef signed int    INT32S; /* Signed   32bit quantity */

typedef float          FP32; /* Single precision floating point */

typedef double         FP64; /* Double precision floating point */

typedef unsigned int   OS_STK; /* Each stack entry is 32-bit wide*/

typedef unsigned int    OS_CPU_SR; /* Define size of CPU status register (PSR = 32 bits) */

  1. #define声明三个宏(OS_CPU.H)
  2. C语言编写六个简单的函数(OS_CPU_C.C)
  3. 编写四个汇编语言函数(OS_CPU_A.ASM)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
\SOFTWARE The main directory from the root where all software-related files are placed. \SOFTWARE\BLOCKS The main directory where all ‘Building Blocks’ are located. With μC/OS-II, I included a ‘building block’ that handles DOS-type compatible functions that are used by the example code. \SOFTWARE\BLOCKS\TO This directory contains the files for the TO utility (see Appendix E, TO). The source file is TO.C and is found in the \SOFTWARE\TO\SOURCE directory. The DOS executable file (TO.EXE) is found in the \SOFTWARE\TO\EXE directory. Note that TO requires a file called TO.TBL which must reside on your root directory. An example of TO.TBL is also found in the \SOFTWARE\TO\EXE directory. You will need to move TO.TBL to the root directory if you are to use TO.EXE. \SOFTWARE\uCOS-II The main directory where all μC/OS-II files are located. \SOFTWARE\uCOS-II\EX1_x86L This directory contains the source code for EXAMPLE #1 (see section 1.07, Example #1) which is intended to run under DOS (or a DOS window under Windows 95). \SOFTWARE\uCOS-II\EX2_x86L This directory contains the source code for EXAMPLE #2 (see section 1.08, Example #2) which is intended to run under DOS (or a DOS window under Windows 95). \SOFTWARE\uCOS-II\EX3_x86L This directory contains the source code for EXAMPLE #3 (see section 1.09, Example #3) which is intended to run under DOS (or a DOS window under Windows 95). \SOFTWARE\uCOS-II\Ix86L This directory contains the source code for the processor dependent code (a.k.a. the port) of μC/OS-II for an 80x86 Real-Mode, Large Model processor. \SOFTWARE\uCOS-II\SOURCE This directory contains the source code for processor independent portion of μC/OS-II. This code is fully portable to other processor architectures.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值