📄 test.c
字号:
/* main.c
*
* Motorola Coldfire MCF5307 port to MicroC/OS-II
*
* Ross Berteig
* Cheshire Engineering Corp
* 650 Sierra Madre Villa, Suite 201
* Pasadena CA 91107
* +1-626-351-5493 +1-626-351-8645 FAX
* Ross@CheshireEng.com, www.CheshireEng.com
*
* Copyright (C) 1998 Cheshire Engineering Corporation.
* Based on a port to uCOS version 1.x by David Fiddes.
* Portions Copyright (C) 1997 David Fiddes, D.J.Fiddes@hw.ac.uk
* Anything that no longer works is probably not his fault.
*/
#include <stdio.h>
#include <limits.h>
#include "includes.h"
#define TASK_STK_SIZE 512 /* Size of each task's stacks (# of WORDs) */
#define N_TASKS 4 /* Number of identical tasks */
#define NTASK 4
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
OS_STK TaskStk[N_TASKS][TASK_STK_SIZE]; /* Tasks stacks */
OS_STK TaskStartStk[TASK_STK_SIZE];
char TaskData[N_TASKS]; /* Parameters to pass to each task */
OS_EVENT *RandomSem;
OS_STK ShortStack[1024][NTASK];
void TaskStart(void *data); /* Function prototypes of Startup task */
static void TaskStartCreateTasks(void);
void Task1 (){
INT8U x;
INT8U err;
unsigned char *abctask;
unsigned char task[]=" TASK1!!\r\n";
register MCF5307_IMM *imm = &__MBAR;
//pdata=pdata;
x=0;
for (x;x<NTASK;x++) {
OSSemPend(RandomSem, 0, &err);
UART1WritePacket(imm, task, sizeof(task)+1);
OSSemPost(RandomSem);
OSTimeDlyHMSM(0,0,0,500);
}
}
void Task2 (){
INT8U x;
INT8U err;
unsigned char *abctask;
unsigned char task[]=" TASK2!!!!\r\n";
register MCF5307_IMM *imm = &__MBAR;
//pdata=pdata;
x=0;
for (x;x<NTASK;x++) {
OSSemPend(RandomSem, 0, &err);
UART1WritePacket(imm, task, sizeof(task)+1);
OSSemPost(RandomSem);
OSTimeDly(500);
}
}
/* ShortTask
*
* Demonstrates that a task which returns does fall into the
* provided call site and subsequently calls OSTaskDel().
*/
void ShortTask(void *pdata)
{int d;
int i;
int LedOut;
INT8U err;
register MCF5307_IMM *imm = &__MBAR;
unsigned char task[]=" Now light the leds!!!!\r\n";
pdata = pdata;
OSTimeDlyHMSM(0,0,0,500);
d=0;
LedOut=0x01;
UART1WritePacket(imm, task, sizeof(task)+1);
for(i=20;i>0;i--)
{
OSSemPend(RandomSem, 0, &err);
imm->parallel_port.PADAT=~LedOut; //turn off the leds
if(d==0)
LedOut<<=1;
if(d==1)
LedOut>>=1;
OSTimeDlyHMSM(0,0,0,500);
if(LedOut==0x080||LedOut==0x1)
d=(d+1)%2;
OSSemPost(RandomSem);
}
}
/* DumpPrioTbl
*
* Print something about each priority with a
* task defined.
*/
void DumpPrioTbl(void)
{
OS_ENTER_CRITICAL();
OS_EXIT_CRITICAL();
}
/* StartupMain
*
* Called during the initialization task during uC/OS kernel
* startup to create all interesting tasks in the system. If this
* function exits, the startup task will commit suicide. If a system
* task running at a priority lower than all tasks other than the
* OS low priority tasks is needed, then the startup task may be
* recycled for that purpose by never returning from StartupMain().
*/
void StartupMain()
{
INT8U i;
OSTaskCreate(ShortTask,
(void *)0,
&ShortStack[1][1023],
5);
i=2;
TaskData[i] = '0' + i; /* Each task will display its own letter */
OSTaskCreate(Task1, (void *)&TaskData[i], &TaskStk[i][TASK_STK_SIZE - 1], (i) + 10);
TaskData[i] = '0' +1; /* Each task will display its own letter */
OSTaskCreate(Task2, (void *)(&(TaskData[i])+1), &TaskStk[i+1][TASK_STK_SIZE - 1], i + 11);
DumpPrioTbl();
OSTimeDly(500);
DumpPrioTbl();
for (;;) {
OSTimeDly(1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -