📄 eg3.c
字号:
/*
* File: eg3.c
*
* uC/OS Real-time multitasking kernel for the ARM processor.
*
* This program is an example of using semaphore to
* implement task rendevous.
*
* Created by cooljet (www.cvtech.com.cn)
*
*/
#include "Includes.h" /* uC/OS interface */
#include "44blib\option.h"
#include "44blib\44blib.h"
/* task stack */
OS_STK StackLED[STACKSIZE]= {0, };
OS_STK StackSEG[STACKSIZE]= {0, };
/* mailbox event control blocks */
OS_EVENT *Mbox1;
char PassMsg[] = "Example 1";
/* task name string */
char IdLED = '1';
char IdSEG = '2';
/* task entry function */
void TaskLED(void *Id);
void TaskSEG(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;
}
/*
* Task entry function.
* Task running at the lowest priority.
* Wait for a message in the first mailbox and post
* a messages to the third mailbox.
*/
void TaskLED(void *Id)
{
char *Msg;
INT8U err;
for (;;) {
/* wait for a message from the input mailbox */
Msg = (char *)OSMboxPend(Mbox1, 0, &err);
/* print task's id */
uHALr_printf(Msg);
}
}
/*
* Task entry function.
* this task blink the seg every 200 ticks
* that is 1s.
*/
void TaskSEG(void *Id)
{
char Msg[100];
INT8U err;
int nCount = 0;
for (;;) {
/* post the input message to the output mailbox */
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
User_SEG_Blink();
OSTimeDly(100);
}
}
/*
* Main function.
*/
void Main(void)
{
/*
* do target (uHAL based ARM system) initialisation
*/
ARMTargetInit();
uHALr_printf("#########Example 3#########\n");
/*
* needed by uC/OS
*/
OSInit();
/*
* create the first mailbox in the pipeline with a message
* in it to get the first task started.
*/
Mbox1 = OSMboxCreate((void *)0);
/*
* create the tasks in uC/OS and assign increasing
* priorities to them so that Task3 at the end of
* the pipeline has the highest priority.
*/
OSTaskCreate(TaskLED, (void *)&IdLED, (OS_STK *)&StackLED[STACKSIZE - 1], 5);
/* Create seg blink tasks */
OSTaskCreate(TaskSEG, (void *)&IdSEG, (OS_STK *)&StackSEG[STACKSIZE - 1], 13);
/* Start the (uHAL based ARM system) system running */
ARMTargetStart();
/*
* start the task
*/
OSStart();
/*
* never reached
*/
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -