?? eg4.c
字號:
/*
* File: eg4.c
*
* uC/OS Real-time multitasking kernel for the ARM processor.
*
* This program is an example of multi task control.
*
* Created by cooljet (www.cvtech.com.cn)
*
*/
#include "Includes.h" /* uC/OS interface */
#include "44blib\option.h"
#include "44blib\44blib.h"
/* defines */
#define NUM_TASKS 3 /* must be number in range 1 to 62 */
/* task stack */
OS_STK TaskStk[NUM_TASKS+1][STACKSIZE];
int pZERO = 0; /* need a pointer to value of 0 */
/* mailbox event control blocks */
OS_EVENT *DispSem;
/* task name string */
char BLACK[] = {ESC,'[','3','0','m',0};
char RED[] = {ESC,'[','3','1','m',0};
char GREEN[] = {ESC,'[','3','2','m',0};
char BROWN[] = {ESC,'[','3','3','m',0};
char BLUE[] = {ESC,'[','3','4','m',0};
char MAGENTA[] = {ESC,'[','3','5','m',0};
char CYAN[] = {ESC,'[','3','6','m',0};
char WHITE[] = {ESC,'[','3','7','m',0};
/* functions */
void Task(void *id);
void IdleTask( void *id);
/*
* LED blink function.
* this function blink the led
*/
void User_LED_Blink(void)
{
static int led_status = 0;
led_status += 1;
if(led_status % 2 == 0)
*(char *)0x02000000 = 0xff;
else
*(char *)0x02000000 = 0x00;
}
/*
* LED blink function.
* this function blink the led
*/
void User_SEG_Blink(void)
{
static unsigned char seg_value[] = { 0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e };
static int seg_status = 0;
*((unsigned char *)0x8000000) = seg_value[seg_status];
seg_status += 1;
if(seg_status > 15)
seg_status = 0;
}
/*
* Main function.
*/
void Main(void)
{
static int id[NUM_TASKS];
int j;
for(j=0; j<NUM_TASKS; j++) /* generate the ID's */
{
id[j] = (int)'1' + j; /* create an id we can see */
}
/*
* do target (uHAL based ARM system) initialisation
*/
ARMTargetInit();
uHALr_printf("#########Example 4#########\n");
/*
* needed by uC/OS
*/
OSInit();
DispSem = OSSemCreate( 1 ); /* Display semaphore */
for(j=0; j<NUM_TASKS; j++) /* generate the tasks */
{
OSTaskCreate(Task, (void *)&id[j], (OS_STK *)&TaskStk[j][STACKSIZE-1], j+1);
}
OSTaskCreate(IdleTask,(void *)&pZERO,(OS_STK *)&TaskStk[j][STACKSIZE-1], j+1);
/* Start the (uHAL based ARM system) system running */
ARMTargetStart();
/*
* start the task
*/
OSStart();
/*
* never reached
*/
return;
}
/*
* T a s k
*
* This is being used by NUM_TASKS tasks.
*/
void Task(void *id)
{
INT8U err;
int j;
while(1)
{
OSTimeDly(10); /* Delay a while */
OSSemPend(DispSem, 0, &err);
switch(*(char *)id)
{
case '1' :
User_SEG_Blink(); /* print task's id */
uHALr_printf("%c", *(char *)id);
break;
case '2' :
User_LED_Blink(); /* print task's id */
uHALr_printf("%c", *(char *)id);
break;
case '3' :
User_SEG_Blink(); /* print task's id */
uHALr_printf("%c", *(char *)id);
break;
default:
User_LED_Blink(); /* print task's id */
uHALr_printf("%c", *(char *)id);
}
OSSemPost(DispSem);
}
}
/*
* I d l e T a s k
*
* idle task
*/
void IdleTask(void *id)
{
INT8U err;
while(1)
{
OSSemPend(DispSem, 0, &err);
uHALr_printf(".");
OSSemPost(DispSem);
OSTimeDly(1);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -