uC/OS-II源码解析(os_cpu_c.c)

本文详细介绍了uC/OS-II实时操作系统在Intel 80x86处理器上的移植过程与配置细节。主要内容包括数据类型的定义、中断管理的三种方法、堆栈增长方向设置及任务切换的实现。通过具体代码示例,展示了如何在80x86平台上为uC/OS-II定制OS_CPU.H头文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自:https://blog.youkuaiyun.com/u010650845/article/details/72466995

/*
** ver   : 2.52
** file  : OS_CPU.H
** brief : 头文件,与处理器类型相关
*/
#ifdef  OS_CPU_GLOBALS
#define OS_CPU_EXT
#else
#define OS_CPU_EXT  extern
#endif

/*
******************************************************************************************
*                                              数据类型
*                                         
******************************************************************************************
*/

typedef unsigned char  BOOLEAN;            /* 布尔           */
typedef unsigned char  INT8U;               /* 无符号8位整数  */
typedef signed   char  INT8S;               /* 有符号8位整数  */
typedef unsigned int   INT16U;              /* 无符号16位整数 */
typedef signed   int   INT16S;              /* 有符号16位整数 */
typedef unsigned long  INT32U;              /* 无符号32位整数 */
typedef signed   long  INT32S;              /* 有符号32位整数 */
typedef float          FP32;                 /* 单精度浮点     */
typedef double         FP64;                 /* 双精度浮点     */

typedef unsigned int   OS_STK;               /* 对站入口宽度16位      */
typedef unsigned short OS_CPU_SR;           /* CPU状态寄存器宽度16位 */

#define BYTE           INT8S                   
#define UBYTE          INT8U                   
#define WORD           INT16S                                                 
#define UWORD          INT16U
#define LONG           INT32S
#define ULONG          INT32U

/* 
*****************************************************************************************
*                              Intel 80x86 (实模式, 大模式)
*
* Method #1:  最简单的一种方法实现开关中断,但是在这个过程中存在着小小的问题,如果在中断
*              禁止的情况下调用ucosii函数,那么从ucosii返回时,中断可能会变成允许的了.
*
* Method #2:  先将中断状态保存然后在关中断,开中断时从堆栈中恢复原来的中断状态,如果调用
*             前中断是开着的则调用后中断还是开着的,调用前中断时关掉的则调用后中断还是断
*             掉的
*
* Method #3:  得到当前PSW寄存器的值,并保存在局部变量cpu_sr中,开中断时将局部变量的值赋值
*             给PSW
*******************************************************************************************
*/
#define  OS_CRITICAL_METHOD    2                 /* 实现临界段的方法 */

#if      OS_CRITICAL_METHOD == 1
#define  OS_ENTER_CRITICAL()  asm  CLI                    /* 关中断 */
#define  OS_EXIT_CRITICAL()   asm  STI                    /* 开中断 */
#endif

#if      OS_CRITICAL_METHOD == 2
#define  OS_ENTER_CRITICAL()  asm {PUSHF; CLI}            /* 关中断 */           
#define  OS_EXIT_CRITICAL()   asm  POPF                   /* 开中断 */                     
#endif

#if      OS_CRITICAL_METHOD == 3
#define  OS_ENTER_CRITICAL()  (cpu_sr = OSCPUSaveSR())    /* 关中断 */                      
#define  OS_EXIT_CRITICAL()   (OSCPURestoreSR(cpu_sr))    /* 关中断 */                      
#endif

/*
****************************************************************************************
*                           Intel 80x86 (实模式, 大模式) 杂项
****************************************************************************************
*/

#define  OS_STK_GROWTH        1                  /* 堆栈增长方向,高地址向低地址  */

#define  uCOS                 0x80               /* 中断向量表用于任务切换       */

#define  OS_TASK_SW()         asm  INT   uCOS

/*
****************************************************************************************
*                                            全局变量
****************************************************************************************
*/

OS_CPU_EXT  INT8U  OSTickDOSCtr;      

/*
***************************************************************************************
*                                              声明
***************************************************************************************
*/

void       OSTaskStkInit_FPE_x86(OS_STK **pptos, OS_STK **ppbos, INT32U *psize);

#if OS_CRITICAL_METHOD == 3                        
OS_CPU_SR  OSCPUSaveSR(void);
void       OSCPURestoreSR(OS_CPU_SR cpu_sr);
#endif

 

\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、付费专栏及课程。

余额充值