📄 main.c
字号:
/*
* File: main.c
* Purpose: Main process
*
*/
/*
* Include the generic CPU header file
*/
#include "mcf5xxx.h"
/*
* Include the specific CPU header file
*/
#include "mcf5213.h"
/*
* Include the board specific header file
*/
//#if (defined(M5213EVB))
#include "m5213evb/m5213evb.h"
//#elif (defined(M5211DEMO))
//#include "m5211demo/m5211demo.h"
//#elif (defined(M5213P))
//#include "m5213p/m5213p.h"
//#else
//#error "No valid platform defined"
//#endif
/*
* Include any toolchain specfic header files
*/
#if (defined(__MWERKS__))
#include "build/mwerks/mwerks.h"
#elif (defined(__DCC__))
#include "build/wrs/diab.h"
#elif (defined(__ghs__))
#include "build/ghs/ghs.h"
#endif
/*
* Include common utilities
*/
#include "assert.h"
#include "io.h"
//#include "stdlib.h"
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 2000, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* MCF5282 Sample code
*
*
*
* File : MAIN.C
* Originally by: Jean J. Labrosse
* Modified by : Mark D. Medonis
* Modified by : Carlton Heyer for CF5282
*********************************************************************************************************
*/
#include "INCLUDES.H"
#define TASK_WORK 100
#define APP_START_TASK_LED 1
#define APP_TASK_1_LED 2
#define APP_TASK_2_LED 4
/*
*********************************************************************************************************
* 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
*
* Commented out printf statements in the Tasks because they were causing errors.
* Added code to blink LEDs for the Avnet Coldfire board (5282 based).
* Modified for 5282 timer0.
* Carlton Heyer 4/28/04
*
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
OS_STK AppStartTaskStk[256];
OS_STK AppTask1Stk[256];
OS_STK AppTask2Stk[256];
INT8U leds = 0xff; // Assume all LEDs are lit
INT8U led_ptr = 0x80; // Point to LED7
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppStartTask(void *pdata);
static void AppTask1(void *pdata);
static void AppTask2(void *pdata);
static void AppTickInit(void);
void gpt_init();
void led_toggle(INT8U);
void led_enable(INT8U);
void led_disable(INT8U);
void isr_init(void);
INT8U get_sw(void);
extern void timer0_handler(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)
{
/* Enable signals as GPIO */
MCF_GPIO_PTCPAR = 0
| MCF_GPIO_PTCPAR_TIN3_GPIO
| MCF_GPIO_PTCPAR_TIN2_GPIO
| MCF_GPIO_PTCPAR_TIN1_GPIO
| MCF_GPIO_PTCPAR_TIN0_GPIO;
/* Set output values */
MCF_GPIO_PORTTC = 0x0F;
/* Enable signals as digital outputs */
MCF_GPIO_DDRTC = 0
| MCF_GPIO_DDRTC_DDRTC3
| MCF_GPIO_DDRTC_DDRTC2
| MCF_GPIO_DDRTC_DDRTC1
| MCF_GPIO_DDRTC_DDRTC0;
printf("\n\nStart uCOS-II on MCF5213 doggle board.\n\n");
InitVBR();
// Init int vectors to default routine
isr_init();
OSVectSet(47, (void (*)(void))OSCtxSw); /* Setup the context switch exception */
/*---- 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[255], 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)
{
INT32U i=0; // Task counter
INT32U work;
pdata = pdata; /* 'pdata' should contain 0x12345678! */
AppTickInit(); /* Initialize the ticker */
/*---- Task initialization code goes HERE! --------------------------------------------------------*/
OSTaskCreate(AppTask1, (void *)0, (void *)&AppTask1Stk[255], 10);
OSTaskCreate(AppTask2, (void *)0, (void *)&AppTask2Stk[255], 20);
while (TRUE) { /* Task body, always written as an infinite loop. */
/*---- Task code goes HERE! -------------------------------------------------------------------*/
i++;
led_toggle(APP_START_TASK_LED);
// printf("Start %i\r\n", i); // printf statements cause runtime errors
// Have the task pretend to do some work
work = 5 * TASK_WORK;
while(work--); // App Start Task work
OSTimeDly(3000); /* 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)
{
INT32U Task1Ctr = 0;
INT32U work;
pdata = pdata;
/*---- Task initialization code goes HERE! --------------------------------------------------------*/
while (TRUE) { /* Task body, always written as an infinite loop. */
/*---- Task code goes HERE! -------------------------------------------------------------------*/
Task1Ctr++;
led_toggle(APP_TASK_1_LED);
// printf("AvTask1 %d\r\n",Task1Ctr); // printf statements cause runtime errors
// Have the task pretend to do some work
work = 50 * TASK_WORK;
while(work--); // Task 1 work
OSTimeDly(80); /* 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)
{
INT32U Task2Ctr = 0;
INT32U work;
pdata = pdata;
// /*---- Task initialization code goes HERE! --------------------------------------------------------*/
while (TRUE) { /* Task body, always written as an infinite loop. */
/*---- Task code goes HERE! -------------------------------------------------------------------*/
Task2Ctr++;
led_toggle(APP_TASK_2_LED);
// printf("AvTask2 %d\r\n", Task2Ctr); // printf statements cause runtime errors
// Have the task pretend to do some work
work = 500 * TASK_WORK;
while(work--); // Do some work
OSTimeDly(50); /* Delay task execution for one clock tick */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TICKER INITIALIZATION
*
* Description : This function is called to initialize a periodic time source which will be used as the
* clock tick for uC/OS-II. The interrupt handler MUST point to OSTickISR (see OS_CPU_A.S).
*
*********************************************************************************************************
*/
static void AppTickInit (void)
{
OSVectSet(119, (void (*)(void))OSTickISR); /* Point the Timer 0 vector 55 to the int handler */
MCF_PIT0_PCSR = MCF_PIT_PCSR_PRE(8) | MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD;
MCF_PIT0_PMR = 312500/OS_TICKS_PER_SEC;
MCF_PIT0_PCSR |= MCF_PIT_PCSR_PIF | MCF_PIT_PCSR_EN;
return;
}
void led_toggle(INT8U led)
{
unsigned char i;
switch(led)
{
case 0x01:
case 0x02:
case 0x04:
case 0x08:
case 0x10:
case 0x20:
case 0x40:
case 0x80:
OS_ENTER_CRITICAL();
leds ^= led;
printf("\nled is %02X.\n", led);
i = MCF_GPIO_PORTTC;
//printf("\ni is %02X.\n", i);
i = i & led;
if(i == 0x00)
{
MCF_GPIO_PORTTC = MCF_GPIO_PORTTC | led;
}
else
{
MCF_GPIO_CLRTC = MCF_GPIO_PORTTC & ~led;
}
OS_EXIT_CRITICAL();
(leds & led) ? led_enable(led) : led_disable(led);
default:
break;
}
}
void led_disable(INT8U led)
{
}
void led_enable(INT8U led)
{
}
unsigned char get_sw(void)
{
return 0x55;
}
void gpt_init(void)
{
}
void isr_init()
{
INT16U int_no;
MCF_INTC_IMRH = 0xFF7FFFFF; // Enable PIT0 Int
MCF_INTC_IMRL = 0xFFFFFFFE; // Enable Global Ints
MCF_INTC_ICR55 = 0x08; // Int level 1, priority 0
OSVectSet(0x45, (void (*)(void))timer0_handler); /* Setup the context switch exception */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -