📄 os_cpu.h
字号:
/*
*********************************************************************************************************
* uC/OS-II
* 实时内核
*
* (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
* 版权所有
*
* MCU-51 专用代码
* KEIL C51大模式编译
*
* 文件名 : OS_CPU.H
* 作者 : Jean J. Labrosse
* 改编 : 杨屹 gdtyy@ri.gdt.com.cn 巨龙公司系统集成开发部
*********************************************************************************************************
*/
#ifndef OS_CPU_H
#define OS_CPU_H
#ifdef OS_CPU_GLOBALS
#define OS_CPU_EXT
#else
#define OS_CPU_EXT extern
#endif
/*
*********************************************************************************************************
* 数据类型
* (编译器相关)
*********************************************************************************************************
*/
//详见C51.PDF第176页
typedef unsigned char BOOLEAN; //注意:不要使用bit定义,因为在结构体里无法使用
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 char OS_STK; //栈单元宽度为8比特
typedef unsigned char OS_CPU_SR; //51 IE宽度为8bit
#define BYTE INT8S //兼容以前版本的数据类型
#define UBYTE INT8U //uC/OS-II可以不用这些数据类型
#define WORD INT16S
#define UWORD INT16U
#define LONG INT32S
#define ULONG INT32U
/*
*********************************************************************************************************
* Intel 80x51 Large Model
*
* Method #1: Disable/Enable interrupts using simple instructions. After critical section, interrupts
* will be enabled even if they were disabled before entering the critical section.
*
* Method #2: Disable/Enable interrupts by preserving the state of interrupts. In other words, if
* interrupts were disabled before entering the critical section, they will be disabled when
* leaving the critical section.
*
* Method #3: Disable/Enable interrupts by preserving the state of interrupts. Generally speaking you
* would store the state of the interrupt disable flag in the local variable 'cpu_sr' and then
* disable interrupts. 'cpu_sr' is allocated in all of uC/OS-II's functions that need to
* disable interrupts. You would restore the interrupt disable state by copying back 'cpu_sr'
* into the CPU's status register.
*********************************************************************************************************
*/
#if OS_CRITICAL_METHOD == 1
#define OS_ENTER_CRITICAL() EA=0 /* Disable interrupts */
#define OS_EXIT_CRITICAL() EA=1 /* Enable interrupts */
#endif
#if OS_CRITICAL_METHOD == 2
#define OS_ENTER_CRITICAL() /* Disable interrupts */
#define OS_EXIT_CRITICAL() /* Enable interrupts */
#endif
#if OS_CRITICAL_METHOD == 3
#define OS_ENTER_CRITICAL() cpu_sr = IE & 0x80; IE &= 0x7F /* Disable interrupts */
#define OS_EXIT_CRITICAL() IE |= cpu_sr /* Enable interrupts */
#endif
#define OS_TICKS_PER_SEC 50 /* Set the number of ticks in one second */
#define OS_STK_GROWTH 0 //MCU-51堆栈从下往上增长 1=向下,0=向上
#define OS_TASK_SW() OSCtxSw() //因为MCU-51没有软中断指令,所以用程序调用代替。两者的堆栈格式相同,
//RETI指令复位中断系统,RET则没有。实践表明,对于MCU-51,用子程序调
//用入栈,用中断返回指令RETI出栈是没有问题的,反之中断入栈RET出栈则
//不行。总之,对于入栈,子程序调用与中断调用效果是一样的,可以混用。
//在没有中断发生的情况下复位中断系统也不会影响系统正常运行。
//详见《uC/OS-II》第八章193页第12行
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -