|
有没有人做过基于S12XS128的UCOS_II 移植??帮我解脱熬夜之苦
程序是要实现三个任务,其实是邵贝贝老师的《嵌入式系统中的双核技术》中的内容,看上去比较烦了
,见谅啊!!
我经过调试感觉系统就根本没启动··
下面是具体修改程序,求分析,先谢了
includes.h:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-1999, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* MASTER INCLUDE FILE
*********************************************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <setjmp.h>
#include <hidef.h> //系统的头文件
#include "os_cpu.h" //与CPU相关的头文件
#include "os_cfg.h" //uCOS-II配置文件
#include "ucos_ii.h" //与CPU无关的头文件
OS_CFG.h
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-2001, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* uC/OS-II Configuration File for V2.51
*
* File : OS_CFG.H
* By : Jean J. Labrosse
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* uC/OS-II CONFIGURATION
*********************************************************************************************************
*/
#define OS_MAX_EVENTS 2 /* Max. number of event control blocks in your application ... */
/* ... MUST be > 0 */
#define OS_MAX_FLAGS 2 /* Max. number of Event Flag Groups in your application ... */
/* ... MUST be > 0 */
#define OS_MAX_MEM_PART 2 /* Max. number of memory partitions ... */
/* ... MUST be > 0 */
#define OS_MAX_QS 2 /* Max. number of queue control blocks in your application ... */
/* ... MUST be > 0 */
#define OS_MAX_TASKS 6 /* Max. number of tasks in your application ... */
/* ... MUST be >= 2 */
#define OS_LOWEST_PRIO 31 /* Defines the lowest priority that can be assigned ... */
/* ... MUST NEVER be higher than 63! */
#define OS_TASK_IDLE_STK_SIZE 64 /* Idle task stack size (# of OS_STK wide entries) */
#define OS_TASK_STAT_EN 0 /* Enable (1) or Disable(0) the statistics task */
#define OS_TASK_STAT_STK_SIZE 64 /* Statistics task stack size (# of OS_STK wide entries) */
#define OS_ARG_CHK_EN 1 /* Enable (1) or Disable (0) argument checking */
#define OS_CPU_HOOKS_EN 1 /* uC/OS-II hooks are found in the processor port files */
/* ----------------------- EVENT FLAGS ------------------------ */
#define OS_FLAG_EN 0 /* Enable (1) or Disable (0) code generation for EVENT FLAGS */
#define OS_FLAG_WAIT_CLR_EN 0 /* Include code for Wait on Clear EVENT FLAGS */
#define OS_FLAG_ACCEPT_EN 0 /* Include code for OSFlagAccept() */
#define OS_FLAG_DEL_EN 0 /* Include code for OSFlagDel() */
#define OS_FLAG_QUERY_EN 0 /* Include code for OSFlagQuery() */
/* -------------------- MESSAGE MAILBOXES --------------------- */
#define OS_MBOX_EN 0 /* Enable (1) or Disable (0) code generation for MAILBOXES */
#define OS_MBOX_ACCEPT_EN 0 /* Include code for OSMboxAccept() */
#define OS_MBOX_DEL_EN 0 /* Include code for OSMboxDel() */
#define OS_MBOX_POST_EN 0 /* Include code for OSMboxPost() */
#define OS_MBOX_POST_OPT_EN 0 /* Include code for OSMboxPostOpt() */
#define OS_MBOX_QUERY_EN 0 /* Include code for OSMboxQuery() */
/* --------------------- MEMORY MANAGEMENT -------------------- */
#define OS_MEM_EN 0 /* Enable (1) or Disable (0) code generation for MEMORY MANAGER */
#define OS_MEM_QUERY_EN 0 /* Include code for OSMemQuery() */
/* ---------------- MUTUAL EXCLUSION SEMAPHORES --------------- */
#define OS_MUTEX_EN 0 /* Enable (1) or Disable (0) code generation for MUTEX */
#define OS_MUTEX_ACCEPT_EN 0 /* Include code for OSMutexAccept() */
#define OS_MUTEX_DEL_EN 0 /* Include code for OSMutexDel() */
#define OS_MUTEX_QUERY_EN 0 /* Include code for OSMutexQuery() */
/* ---------------------- MESSAGE QUEUES ---------------------- */
#define OS_Q_EN 0 /* Enable (1) or Disable (0) code generation for QUEUES */
#define OS_Q_ACCEPT_EN 0 /* Include code for OSQAccept() */
#define OS_Q_DEL_EN 0 /* Include code for OSQDel() */
#define OS_Q_FLUSH_EN 0 /* Include code for OSQFlush() */
#define OS_Q_POST_EN 0 /* Include code for OSQPost() */
#define OS_Q_POST_FRONT_EN 0 /* Include code for OSQPostFront() */
#define OS_Q_POST_OPT_EN 0 /* Include code for OSQPostOpt() */
#define OS_Q_QUERY_EN 0 /* Include code for OSQQuery() */
/* ------------------------ SEMAPHORES ------------------------ */
#define OS_SEM_EN 1 /* Enable (1) or Disable (0) code generation for SEMAPHORES */
#define OS_SEM_ACCEPT_EN 0 /* Include code for OSSemAccept() */
#define OS_SEM_DEL_EN 0 /* Include code for OSSemDel() */
#define OS_SEM_QUERY_EN 0 /* Include code for OSSemQuery() */
/* --------------------- TASK MANAGEMENT ---------------------- */
#define OS_TASK_CHANGE_PRIO_EN 0 /* Include code for OSTaskChangePrio() */
#define OS_TASK_CREATE_EN 1 /* Include code for OSTaskCreate() */
#define OS_TASK_CREATE_EXT_EN 0 /* Include code for OSTaskCreateExt() */
#define OS_TASK_DEL_EN 0 /* Include code for OSTaskDel() */
#define OS_TASK_SUSPEND_EN 0 /* Include code for OSTaskSuspend() and OSTaskResume() */
#define OS_TASK_QUERY_EN 0 /* Include code for OSTaskQuery() */
/* --------------------- TIME MANAGEMENT ---------------------- */
#define OS_TIME_DLY_HMSM_EN 0 /* Include code for OSTimeDlyHMSM() */
#define OS_TIME_DLY_RESUME_EN 0 /* Include code for OSTimeDlyResume() */
#define OS_TIME_GET_SET_EN 0 /* Include code for OSTimeGet() and OSTimeSet() */
/* ---------------------- MISCELLANEOUS ----------------------- */
#define OS_SCHED_LOCK_EN 0 /* Include code for OSSchedLock() and OSSchedUnlock() */
#define OS_TICKS_PER_SEC 50 /* Set the number of ticks in one second */
//定义为8位的标志位
typedef INT8U OS_FLAGS; /* Date type for event flag bits (8, 16 or 32 bits) */
OS_CPU_C.C
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
*
* 80x86/80x88 Specific code
* LARGE MEMORY MODEL
*
* Borland C/C++ V4.51
*
* File : OS_CPU_C.C
* By : Jean J. Labrosse
*********************************************************************************************************
*/
#define OS_CPU_GLOBALS
#include "includes.h"
//时钟节拍中断服务子程序OSTickISR()
#define CRGFLG (*((volatile unsigned char *)(0x0037)))
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void OSTickISR (void) {
asm{
ldaa $30
psha
}
OSIntEnter();
OS_SAVE_SP();
CRGFLG |=0x80;
OSTimeTick();
OSIntExit();
asm{
pula
staa $30
nop
rti
}
}
/*
*********************************************************************************************************
* OS INITIALIZATION HOOK
* (BEGINNING)
*
* Description: This function is called by OSInit() at the beginning of OSInit().
*
* Arguments : none
*
* Note(s) : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void OSInitHookBegin (void)
{
}
#endif
/*
*********************************************************************************************************
* OS INITIALIZATION HOOK
* (END)
*
* Description: This function is called by OSInit() at the end of OSInit().
*
* Arguments : none
*
* Note(s) : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void OSInitHookEnd (void)
{
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* TASK CREATION HOOK
*
* Description: This function is called when a task is created.
*
* Arguments : ptcb is a pointer to the task control block of the task being created.
*
* Note(s) : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskCreateHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent compiler warning */
}
#endif
/*
*********************************************************************************************************
* TASK DELETION HOOK
*
* Description: This function is called when a task is deleted.
*
* Arguments : ptcb is a pointer to the task control block of the task being deleted.
*
* Note(s) : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskDelHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent compiler warning */
}
#endif
/*
*********************************************************************************************************
* IDLE TASK HOOK
*
* Description: This function is called by the idle task. This hook has been added to allow you to do
* such things as STOP the CPU to conserve power.
*
* Arguments : none
*
* Note(s) : 1) Interrupts are enabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION >= 251
void OSTaskIdleHook (void)
{
}
#endif
/*
*********************************************************************************************************
* STATISTIC TASK HOOK
*
* Description: This function is called every second by uC/OS-II's statistics task. This allows your
* application to add functionality to the statistics task.
*
* Arguments : none
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskStatHook (void)
{
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* INITIALIZE A TASK'S STACK
*
* Description: This function is called by either OSTaskCreate() or OSTaskCreateExt() to initialize the
* stack frame of the task being created. This function is highly processor specific.
*
* Arguments : task is a pointer to the task code
*
* pdata is a pointer to a user supplied data area that will be passed to the task
* when the task first executes.
*
* ptos is a pointer to the top of stack. It is assumed that 'ptos' points to
* a 'free' entry on the task stack. If OS_STK_GROWTH is set to 1 then
* 'ptos' will contain the HIGHEST valid address of the stack. Similarly, if
* OS_STK_GROWTH is set to 0, the 'ptos' will contains the LOWEST valid address
* of the stack.
*
* opt specifies options that can be used to alter the behavior of OSTaskStkInit().
* (see uCOS_II.H for OS_TASK_OPT_???).
*
* Returns : Always returns the location of the new top-of-stack' once the processor registers have
* been placed on the stack in the proper order.
*
* Note(s) : Interrupts are enabled when your task starts executing. You can change this by setting the
* PSW to 0x0002 instead. In this case, interrupts would be disabled upon task startup. The
* application code would be responsible for enabling interrupts at the beginning of the task
* code. You will need to modify OSTaskIdle() and OSTaskStat() so that they enable
* interrupts. Failure to do this will make your system crash!
*********************************************************************************************************
*/
void *OSTaskStkInit (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT16U opt)
{
//INT16U *stk;
//opt = opt; /* 'opt' is not used, prevent warning */
//stk = (INT16U *)ptos; /* Load stack pointer */
//*stk-- = (INT16U)FP_SEG(pdata); /* Simulate call to function with argument */
//*stk-- = (INT16U)FP_OFF(pdata);
//*stk-- = (INT16U)FP_SEG(task);
//*stk-- = (INT16U)FP_OFF(task);
//*stk-- = (INT16U)0x0202; /* SW = Interrupts enabled */
//*stk-- = (INT16U)FP_SEG(task); /* Put pointer to task on top of stack */
//*stk-- = (INT16U)FP_OFF(task);
//*stk-- = (INT16U)0xAAAA; /* AX = 0xAAAA */
//*stk-- = (INT16U)0xCCCC; /* CX = 0xCCCC */
//*stk-- = (INT16U)0xDDDD; /* DX = 0xDDDD */
//*stk-- = (INT16U)0xBBBB; /* BX = 0xBBBB */
//*stk-- = (INT16U)0x0000; /* SP = 0x0000 */
//*stk-- = (INT16U)0x1111; /* BP = 0x1111 */
//*stk-- = (INT16U)0x2222; /* SI = 0x2222 */
//*stk-- = (INT16U)0x3333; /* DI = 0x3333 */
//*stk-- = (INT16U)0x4444; /* ES = 0x4444 */
//*stk = _DS; /* DS = Current value of DS */
//return ((OS_STK *)stk);
//改写任务堆栈初始化函数
INT16U *stk;
// SCISend1((INT8U)(((INT16U)pdata)>>8));
// SCISend1((INT8U)(pdata));
// SCISend1(*(INT8U *)pdata);
stk = (INT16U *)ptos; //加载堆栈指针,空两个字节
*--stk = opt; //该一个字节为特殊选项,存用户参数
*--stk = (INT16U)task; //PC入栈
*--stk = (INT16U)(0x1122); //Y
*--stk = (INT16U)(0x3344); //X
((INT8U *)stk)--;
*(INT8U *)stk = (INT8U)(((INT16U)pdata)>>8); //A
((INT8U *)stk)--;
*(INT8U *)stk = (INT8U)(pdata); //B
((INT8U *)stk)--;
*(INT8U *)stk = (INT8U)(0x00); //CCR
((INT8U *)stk)--;
*(INT8U *)stk = (INT8U)(0x00);
((INT8U *)stk)--;
*(INT8U *)stk = *(INT8U *)pdata; //只有PPAGE一个内容
return ((void *)stk);
}
/*$PAGE*/
/*
*********************************************************************************************************
* INITIALIZE A TASK'S STACK FOR FLOATING POINT EMULATION
*
* Description: This function MUST be called BEFORE calling either OSTaskCreate() or OSTaskCreateExt() in
* order to initialize the task's stack to allow the task to use the Borland floating-point
* emulation. The returned pointer MUST be used in the task creation call.
*
* Ex.: OS_STK TaskStk[1000];
*
*
* void main (void)
* {
* OS_STK *ptos;
* OS_STK *pbos;
* INT32U size;
*
*
* OSInit();
* .
* .
* ptos = &TaskStk[999];
* pbos = &TaskStk[0];
* psize = 1000;
* OSTaskStkInit_FPE_x86(&ptos, &pbos, &size);
* OSTaskCreate(Task, (void *)0, ptos, 10);
* .
* .
* OSStart();
* }
*
* Arguments : pptos is the pointer to the task's top-of-stack pointer which would be passed to
* OSTaskCreate() or OSTaskCreateExt().
*
* ppbos is the pointer to the new bottom of stack pointer which would be passed to
* OSTaskCreateExt().
*
* psize is a pointer to the size of the stack (in number of stack elements). You
* MUST allocate sufficient stack space to leave at least 384 bytes for the
* floating-point emulation.
*
* Returns : The new size of the stack once memory is allocated to the floating-point emulation.
*
* Note(s) : 1) _SS is a Borland 'pseudo-register' and returns the contents of the Stack Segment (SS)
* 2) The pointer to the top-of-stack (pptos) will be modified so that it points to the new
* top-of-stack.
* 3) The pointer to the bottom-of-stack (ppbos) will be modified so that it points to the new
* bottom-of-stack.
* 4) The new size of the stack is adjusted to reflect the fact that memory was reserved on
* the stack for the floating-point emulation.
*********************************************************************************************************
*/
/*$PAGE*/
//void OSTaskStkInit_FPE_x86 (OS_STK **pptos, OS_STK **ppbos, INT32U *psize)
//{
// INT32U lin_tos; /* 'Linear' version of top-of-stack address */
// INT32U lin_bos; /* 'Linear' version of bottom-of-stack address */
// INT16U seg;
// INT16U off;
// INT32U bytes;
// seg = FP_SEG(*pptos); /* Decompose top-of-stack pointer into seg:off */
// off = FP_OFF(*pptos);
// lin_tos = ((INT32U)seg << 4) + (INT32U)off; /* Convert seg:off to linear address */
// bytes = *psize * sizeof(OS_STK); /* Determine how many bytes for the stack */
// lin_bos = (lin_tos - bytes + 15) & 0xFFFFFFF0L; /* Ensure paragraph alignment for BOS */
// seg = (INT16U)(lin_bos >> 4); /* Get new 'normalized' segment */
// *ppbos = (OS_STK *)MK_FP(seg, 0x0000); /* Create 'normalized' BOS pointer */
// memcpy(*ppbos, MK_FP(_SS, 0), 384); /* Copy FP emulation memory to task's stack */
// bytes = bytes - 16; /* Loose 16 bytes because of alignment */
// *pptos = (OS_STK *)MK_FP(seg, (INT16U)bytes); /* Determine new top-of-stack */
// *ppbos = (OS_STK *)MK_FP(seg, 384); /* Determine new bottom-of-stack */
// bytes = bytes - 384;
// *psize = bytes / sizeof(OS_STK); /* Determine new stack size */
//}
/*$PAGE*/
/*
*********************************************************************************************************
* TASK SWITCH HOOK
*
* Description: This function is called when a task switch is performed. This allows you to perform other
* operations during a context switch.
*
* Arguments : none
*
* Note(s) : 1) Interrupts are disabled during this call.
* 2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
* will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
* task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskSwHook (void)
{
}
#endif
/*
*********************************************************************************************************
* OSTCBInit() HOOK
*
* Description: This function is called by OS_TCBInit() after setting up most of the TCB.
*
* Arguments : ptcb is a pointer to the TCB of the task being created.
*
* Note(s) : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void OSTCBInitHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent Compiler warning */
}
#endif
/*
*********************************************************************************************************
* TICK HOOK
*
* Description: This function is called every tick.
*
* Arguments : none
*
* Note(s) : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTimeTickHook (void)
{
}
#endif
//OSStartHighRdy:让优先级最高的任务运行函数--------------------------------*
//功 能:让优先级最高的就绪态任务开始运行 *
//参 数:无 *
//返 回:无 *
//-------------------------------------------------------------------------*
//#pragma CODE_SEG __NEAR_SEG NON_BANKED
void OSStartHighRdy(void)
{
OSTaskSwHook();
//OSRunning = 1;
asm{
ldx OSTCBCur //将TCB的地址给X
lds 0,X //将值给SP
ldaa OSRunning
inca
staa OSRunning
pula
staa $30 //恢复页面寄存器
nop //延时
rti
}
}
//OSCtxSw:任务级任务切换函数-----------------------------------------------*
//功 能:当优先级更高的任务进入就绪状态,系统将当前任务挂起,让更高优先级任务运行
//参 数:无 *
//返 回:无
//-------------------------------------------------------------------------*
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void OSCtxSw(void) {
asm{
ldaa $30
psha
ldx OSTCBCur
sts 0,x
}
OSTaskSwHook();
OSTCBCur=OSTCBHighRdy;
OSPrioCur=OSPrioHighRdy;
asm{
ldx OSTCBCur
lds 0,x
pula
staa $30
nop
rti
}
}
//OSIntCtxSw:中断级任务切换函数--------------------------------------------*
//功 能:如果在中断服务结束时,中断中激活了更高优先级的任务,则调用该函数 *
//参 数:无 *
//返 回:无 *
//-------------------------------------------------------------------------*
//#pragma CODE_SEG __NEAR_SEG NON_BANKED
void OSIntCtxSw(void)
{
OSTaskSwHook();
OSTCBCur = OSTCBHighRdy; //Change OSTCBCur and OSPrioCur
OSPrioCur = OSPrioHighRdy;
asm{
ldx OSTCBCur //get the new task's TCB's address
lds 0,x
pula
staa $30
nop //retore ppage from stack
rti
}
}
/********************************************************************
*main.c文件
********************************************************************/
//包含头文件
#include <hidef.h> /* common defines and macros */
#include <mc9s12xs128.h>
#include "derivative.h" /* derivative-specific definitions */
#pragma LINK_INFO DERIVATIVE "MC9S12XS128"
#include "includes.h" //总头文件
//#include " main_asm.h"
typedef struct{
INT8U PPAGE1;
}TASKDATA;
//任务堆栈定义
#define TASK_STK_SIZE 100
OS_STK TaskStartStk[TASK_STK_SIZE];
OS_STK Task1Stk[TASK_STK_SIZE];
OS_STK Task2Stk[TASK_STK_SIZE];
//实时时钟中断寄存器宏定义
//#define CRGINT (*((volatile unsigned char *)(0x0038)))
//#define RTICTL (*((volatile unsigned char *)(0x003B)))
//任务通信
OS_EVENT *Semi_1;
INT8U err;
//任务数据结构类型
TASKDATA TaskStartData;
TASKDATA Task1Data;
TASKDATA Task2Data;
//函数声明
void TaskStart();
void Task1();
void Task2();
//主函数
void main(void)
{
DDRB=0XFF;
PORTB=0XFF;
//给任务分配页面,这里三任务放在一页上
TaskStartData.PPAGE1=0XFE;
Task1Data.PPAGE1=0XFE;
Task2Data.PPAGE1=0XFE;
//操作系统初始化
OSInit();
Semi_1=OSSemCreate(1);
//用户代码开始
OSTaskCreate(TaskStart,&TaskStartData,&TaskStartStk[TASK_STK_SIZE -1],5);
OSTaskCreate(Task1,&Task1Data,&Task1Stk[TASK_STK_SIZE -1],7);
OSTaskCreate(Task2,&Task2Data,&Task2Stk[TASK_STK_SIZE -1],9);
//用户代码结束
OSStart(); //os运行
TaskStart();
Task1();
Task2();
}
#pragma CODE_SEG TASKCODESEG
#pragma STRING_SEG TASKSTRINGSEG
void TaskStart (TASKDATA* pdata);
void TaskStart (TASKDATA* pdata) {
RTICTL=0xcf;
CRGINT|=0x80;
for(;;) {
PORTB^=0x01;
OSSemPost(Semi_1);
OSTimeDly(50);
}
}
void Task1 (TASKDATA* pdata) {
for(;;) {
PORTB ^=0x04;
OSSemPend(Semi_1,0,&err);
OSTimeDly(25);
}
}
void Task2 (TASKDATA* pdata) {
for(;;) {
PORTB^=0x10;
OSTimeDly(10);
}
}
#pragma CODE_SEG DEFAULT
#pragma STRING_SEG DEFAULT |
阿莫论坛20周年了!感谢大家的支持与爱护!!
你熬了10碗粥,别人一桶水倒进去,淘走90碗,剩下10碗给你,你看似没亏,其实你那10碗已经没有之前的裹腹了,人家的一桶水换90碗,继续卖。说白了,通货膨胀就是,你的钱是挣来的,他的钱是印来的,掺和在一起,你的钱就贬值了。
|