UCOS移植到MSP430过程与心得体会《2》
[复制链接]
以下是includes.h文件的内容.
#include
#include
#include
#include
#include
#include "stdbool.h"
#include
#include "OS_CPU.h"
#include "os_cfg.h"
#include "..\uCOS2\uCOS_II.h"//"..\uCOS2\uCOS_II.h"
以下是UCOS_II.C的内容
#defineOS_GLOBALS /* Declare GLOBAL variables */
#include "..\Ports\includes.h"
#defineOS_MASTER_FILE /* Prevent the following files from including includes.h */
#include "OS_CORE.C"
#include "OS_FLAG.C"
#include "OS_MBOX.C"
#include "OS_MEM.C"
#include "OS_MUTEX.C"
#include "OS_Q.C"
#include "OS_SEM.C"
#include "OS_TASK.C"
#include "OS_TIME.C"
Includes.h与UCOS_II.C位于同一文件夹内.要注意#include "..\Ports\includes.h"路径方式.
#include "..\Ports\includes.h"
//#include "lcd.c"
bool FlagLED;
unsigned char LED=0x01;
#define TASK_STK_SIZE 80
OS_STK TaskSTK2[TASK_STK_SIZE];
OS_STK TaskSTK3[TASK_STK_SIZE];
/*
********************************************************************************
*模块名称:MSP430F2274应用任务-->定时闪烁 P1.0 LED
* -----------------
*/|\| XIN|-
* | | |
* --|RST XOUT|-
* | |
* | P4 |-->LED
********************************************************************************
*/
void task(void *pdata)
{
//pdata= pdata; //如果编译器报警,则重新加入此行代码
WDTCTL = WDT_MDLY_8; //设置时钟节拍间隔为32ms
IE1 |= 0x01; //开看门狗定时器中断
//P4SEL &= BIT0;
P4DIR |=0xff;
//P4OUT=0xff;
while (1)
{ if(FlagLED==true)
{
LED=(LED==0x80)?(0x01):(LED<<1);
P4OUT=LED;
FlagLED=false;
}
if(FlagLED==false)
{
//P4OUT=0x80;
FlagLED=true;
}
//P4OUT ^= (BIT0+BIT1+BIT2+BIT3+BIT4+BIT5+BIT6+BIT7);
OSTimeDly(100); //定时函数括号内的内容为延时的时间,//1S=100ms
}
}
void task1(void *pdata)
{
WDTCTL=WDT_MDLY_8; //如果
IE1|=0X01;
P4DIR=0xFF;
while(1)
{
if(FlagLED==false)
{
//P4OUT=0x80;
FlagLED=true;
}
if(FlagLED==true)
{
LED=(LED==0x80)?(0x01):(LED<<1);
P4OUT=LED;
FlagLED=false;
}
}
}
void Init_System_Clock()
{
BCSCTL1=0X00;
do
{
IFG1&=~OFIFG;
for(unsigned char i=0;i<0xff;i++) ;
}
while(IFG1&OFIFG);
BCSCTL2|=SELM_2+SELS;
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗定时器
// Init_System_Clock(); //8MHZ //加此语句后,看不清屏幕显烁.
OSInit();
OSTaskCreate(task,(void *)0,&TaskSTK2[TASK_STK_SIZE-1],5);
//OSTaskCreate(task1,(void *)0,&TaskSTK3[TASK_STK_SIZE-1],6);
OSStart();
}
以上是MAIN.C的内容.在UCOS_II里关键就是对MAIN.C的部分分配任务.然后就是在OSStart()后进行任务调度.并按#define OS_TICKS_PER_SEC 64 /* Set the number of ticks in one second*/设定时中断时间任务切换..
根据上面的资料现在对UCOS执行的过程进行说明<单步执行>.
//根据OS_CFG.H的设定按顺序先对任务初始值,任务控制列表,事件列表..初始化.再对UCOS
操作系统的事件标志,内存标志,消息标志,任务标志量的初始化..
//消息邮箱是main主程序里建立.
//时间是在任务建立后OSTimeDly(100);时让当前任务挂起100的时间量.OSCtxSw()切换
voidOSInit (void) //系统初始化
{
#if OS_VERSION >= 204
OSInitHookBegin(); /* Call port specific initialization code */
#endif
OS_InitMisc(); /* Initialize miscellaneous variables */
OS_InitRdyList(); /* Initialize the Ready List */
OS_InitTCBList(); /* Initialize the free list of OS_TCBs */
OS_InitEventList(); /* Initialize the free list of OS_EVENTs */
#if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
OS_FlagInit(); /* Initialize the event flag structures */
#endif
#if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)
OS_MemInit(); /* Initialize the memory manager */
#endif
#if (OS_Q_EN > 0) && (OS_MAX_QS > 0)
OS_QInit(); /* Initialize the message queue structures*/
#endif
OS_InitTaskIdle(); /* Create the Idle Task */
#if OS_TASK_STAT_EN > 0
OS_InitTaskStat(); /* Create the Statistic Task */
#endif
#if OS_VERSION >= 204
OSInitHookEnd();
specific init. code */
#endif
}
//时间,任务,切换,挂起的各量都为0
staticvoidOS_InitMisc (void)
{
#if OS_TIME_GET_SET_EN > 0
OSTime = 0L; /* Clear the 32-bit system clock */
#endif
OSIntNesting= 0; /* Clear the interrupt nesting counter */
OSLockNesting = 0; /* Clear the scheduling lock counter */
OSTaskCtr = 0; /* Clear the number of tasks */
OSRunning = FALSE; /* Indicate that multitasking not started */
OSCtxSwCtr = 0; /* Clear the context switch counter */
OSIdleCtr = 0L; /* Clear the 32-bit idle counter */
#if (OS_TASK_STAT_EN > 0) && (OS_TASK_CREATE_EXT_EN > 0)
OSIdleCtrRun= 0L;
OSIdleCtrMax= 0L;
OSStatRdy = FALSE; /* Statistic task is not ready */
#endif
}
staticvoidOS_InitRdyList (void)
{
INT16U i;
INT8U *prdytbl;
OSRdyGrp = 0x00;
}