📄 main.c
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 2000-2002, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* MCF5206e Sample code
*
*
*
* File : MAIN.C
* Originally by: Jean J. Labrosse
* Modified by : Mark D. Medonis
* Paul S. Carpenter
*
* Description : Sets up MCF5206e hardware Timer 1 for RTOS use. Creates 10 sample tasks that run forever,
* each with an OS delay while "looping".
*
*********************************************************************************************************
*/
#include "target.h"
#include "OS_CPU.H"
#include "OS_CFG.H"
#include "ucos_ii.h"
#define TASK_STK_SIZE 256 // task stack size (mult. by 4 for num. of bytes)
// these defines are for TEST PURPOSES ONLY!
#define LOGGING 1
//#define printf(x) asm{nop} // whatever you use to for program output with your target, put code/call here
/*
*********************************************************************************************************
* REVISION HISTORY
*
*
* 0.a
* Port for Motorola MCF5272 ColdFire microprocessor.
* Added some printf statements to the AppTasks to monitor multitasking. This
* is used with the BDM debugger and the console I/O libraries provided by CodeWarrior.
* M. Medonis 4/16/2002
*
* 0.b
* Port for Motorola MCF5206e ColdFire microprocessor.
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
OS_STK AppStartTaskStk[TASK_STK_SIZE];
OS_STK AppTask1Stk[TASK_STK_SIZE];
OS_STK AppTask2Stk[TASK_STK_SIZE];
OS_STK AppTask3Stk[TASK_STK_SIZE];
OS_STK AppTask4Stk[TASK_STK_SIZE];
OS_STK AppTask5Stk[TASK_STK_SIZE];
OS_STK AppTask6Stk[TASK_STK_SIZE];
OS_STK AppTask7Stk[TASK_STK_SIZE];
OS_STK AppTask8Stk[TASK_STK_SIZE];
OS_STK AppTask9Stk[TASK_STK_SIZE];
OS_STK AppTask10Stk[TASK_STK_SIZE];
static INT16U Task1Ctr;
static INT16U Task2Ctr;
static INT16U Task3Ctr;
static INT16U Task4Ctr;
static INT16U Task5Ctr;
static INT16U Task6Ctr;
static INT16U Task7Ctr;
static INT16U Task8Ctr;
static INT16U Task9Ctr;
static INT16U Task10Ctr;
volatile mcf5206e_IMM *pIMM = (mcf5206e_IMM *)MBAR; // pointer to start of CPU's SIM registers
volatile PVECTORTABLE pEVT = (PVECTORTABLE)EVT_ADDRESS; // pointer to Exception Vector Table
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppStartTask(void *pdata);
static void AppTask1(void *pdata);
static void AppTask2(void *pdata);
static void AppTask3(void *pdata);
static void AppTask4(void *pdata);
static void AppTask5(void *pdata);
static void AppTask6(void *pdata);
static void AppTask7(void *pdata);
static void AppTask8(void *pdata);
static void AppTask9(void *pdata);
static void AppTask10(void *pdata);
void timerInit(uint32 ticksPerSec,
void *pTimerISR);
void evtInit(void);
extern void isrGeneric(void);
extern void _genericISRstub(void);
/*
*********************************************************************************************************
* main()
*
* Description : This is the standard entry point for C code. It is assumed that your code will call
* main() once you have performed all necessary 683xx and C initialization.
* Arguments : none
*********************************************************************************************************
*/
void main (void)
{
// mask all interrupts
pIMM->sim.IMR = 0xFFFF;
// initialize EVT
evtInit();
/*---- Any initialization code prior to calling OSInit() goes HERE --------------------------------*/
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
/*---- Any initialization code before starting multitasking ---------------------------------------*/
OSTaskCreate(AppStartTask, (void *)0x12345678L, (void *)&AppStartTaskStk[TASK_STK_SIZE-1], 0);
/*---- Create any other task you want before we start multitasking --------------------------------*/
OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
}
/*$PAGE*/
/*
*********************************************************************************************************
* STARTUP TASK
*
* Description : This is an example of a startup task. As mentioned in the book's text, you MUST
* initialize the ticker only once multitasking has started.
* Arguments : pdata is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
* Notes : 1) The first line of code is used to prevent a compiler warning because 'pdata' is not
* used. The compiler should not generate any code for this statement.
* 2) Interrupts are enabled once the task start because the I-bit of the CCR register was
* set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
static void AppStartTask (void *pdata)
{
INT8U rc;
int i=0;
#ifdef LOGGING
char temp[40];
#endif
pdata = pdata; // 'pdata' should contain 0x12345678! */
// initialize Timer 1 for the OS "heartbeat" and start it
timerInit(OS_TICKS_PER_SEC,
OSTickISR);
/*---- Task initialization code goes HERE! --------------------------------------------------------*/
rc = OSTaskCreate(AppTask1, (void *)0, (void *)&AppTask1Stk[TASK_STK_SIZE-1], 20);
rc = OSTaskCreate(AppTask2, (void *)0, (void *)&AppTask2Stk[TASK_STK_SIZE-1], 21);
rc = OSTaskCreate(AppTask3, (void *)0, (void *)&AppTask3Stk[TASK_STK_SIZE-1], 22);
rc = OSTaskCreate(AppTask4, (void *)0, (void *)&AppTask4Stk[TASK_STK_SIZE-1], 23);
rc = OSTaskCreate(AppTask5, (void *)0, (void *)&AppTask5Stk[TASK_STK_SIZE-1], 24);
rc = OSTaskCreate(AppTask6, (void *)0, (void *)&AppTask6Stk[TASK_STK_SIZE-1], 25);
rc = OSTaskCreate(AppTask7, (void *)0, (void *)&AppTask7Stk[TASK_STK_SIZE-1], 26);
rc = OSTaskCreate(AppTask8, (void *)0, (void *)&AppTask8Stk[TASK_STK_SIZE-1], 27);
rc = OSTaskCreate(AppTask9, (void *)0, (void *)&AppTask9Stk[TASK_STK_SIZE-1], 28);
rc = OSTaskCreate(AppTask10, (void *)0, (void *)&AppTask10Stk[TASK_STK_SIZE-1], 29);
while (TRUE) { /* Task body, always written as an infinite loop. */
/*---- Task code goes HERE! -------------------------------------------------------------------*/
i++;
#ifdef LOGGING
sprintf(temp, "%d", i);
printf("Start ");
printf(temp);
printf("\r\n");
#endif
OSTimeDly(250); /* Delay task execution for one clock tick */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TASK #1
*
* Description : This is an example of a task.
* Arguments : pdata is the argument passed to 'AppTask1()' by 'OSTaskCreate()'.
* Notes : 1) The first line of code is used to prevent a compiler warning because 'pdata' is not
* used. The compiler should not generate any code for this statement.
* 2) Interrupts are enabled once the task start because the I-bit of the CCR register was
* set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
static void AppTask1 (void *pdata)
{
#ifdef SEM_TEST
uint8 err;
#endif
pdata = pdata;
/*---- Task initialization code goes HERE! --------------------------------------------------------*/
while (TRUE) { /* Task body, always written as an infinite loop. */
/*---- Task code goes HERE! -------------------------------------------------------------------*/
Task1Ctr++;
#ifdef LOGGING
printf("App1*******\r\n");
#endif
OSTimeDly(100); /* Delay task execution for one clock tick */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TASK #2
*
* Description : This is an example of a task.
* Arguments : pdata is the argument passed to 'AppTask2()' by 'OSTaskCreate()'.
* Notes : 1) The first line of code is used to prevent a compiler warning because 'pdata' is not
* used. The compiler should not generate any code for this statement.
* 2) Interrupts are enabled once the task start because the I-bit of the CCR register was
* set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
static void AppTask2 (void *pdata)
{
pdata = pdata;
/*---- Task initialization code goes HERE! --------------------------------------------------------*/
while (TRUE) { /* Task body, always written as an infinite loop. */
/*---- Task code goes HERE! -------------------------------------------------------------------*/
Task2Ctr++;
#ifdef LOGGING
printf("App2\r\n");
#endif
OSTimeDly(500); /* Delay task execution for one clock tick */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TASK #3
*
* Description : This is an example of a task.
* Arguments : pdata is the argument passed to 'AppTask2()' by 'OSTaskCreate()'.
* Notes : 1) The first line of code is used to prevent a compiler warning because 'pdata' is not
* used. The compiler should not generate any code for this statement.
* 2) Interrupts are enabled once the task start because the I-bit of the CCR register was
* set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
static void AppTask3 (void *pdata)
{
pdata = pdata;
/*---- Task initialization code goes HERE! --------------------------------------------------------*/
while (TRUE) { /* Task body, always written as an infinite loop. */
/*---- Task code goes HERE! -------------------------------------------------------------------*/
Task3Ctr++;
#ifdef LOGGING
printf("App3\r\n");
#endif
OSTimeDly(50); /* Delay task execution for one clock tick */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TASK #4
*
* Description : This is an example of a task.
* Arguments : pdata is the argument passed to 'AppTask2()' by 'OSTaskCreate()'.
* Notes : 1) The first line of code is used to prevent a compiler warning because 'pdata' is not
* used. The compiler should not generate any code for this statement.
* 2) Interrupts are enabled once the task start because the I-bit of the CCR register was
* set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -