⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eg2.c

📁 武汉创维特的arm培训例程试验程序
💻 C
字号:
/*
 * File:        eg2.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, };

/* semaphores event control blocks */
OS_EVENT *Sem1;
OS_EVENT *Sem2;

/* 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. 
 *     this task blink the led every 200 ticks
 *     that is 2s.
 */
void TaskLED(void *Id)
{
    INT8U Reply;
  
    for (;;)
    {
        /* wait for the semaphore  */
        OSSemPend(Sem2, 0, &Reply);

        uHALr_printf("[");
        User_LED_Blink();
        uHALr_printf("TaskLED]");

        /* signal the semaphore */
        OSSemPost(Sem1);
        
        /* wait a short while */
		OSTimeDly(200);
    }
}

/*
 * Task entry function. 
 *     this task blink the seg every 200 ticks
 *     that is 1s.
 */
void TaskSEG(void *Id)
{
    INT8U Reply;

    for (;;)
    {
        /* wait for the semaphore */
        OSSemPend(Sem1, 0, &Reply);

      	uHALr_printf("[");
        User_SEG_Blink();
        uHALr_printf("TaskSEG]");

        /* signal the semaphore */
        OSSemPost(Sem2);

        /* wait a short while */
		OSTimeDly(100);
    }
}

/*
 * Main function.
 */
void Main(void)
{
    /* 
     * do target (uHAL based ARM system) initialisation 
     */
	ARMTargetInit();

    uHALr_printf("#########Example 2#########\n");
    
    /* 
     * needed by uC/OS 
     */
	OSInit();

    /* 
     * create the semaphores
     */
    Sem1 = OSSemCreate(0);
    Sem2 = OSSemCreate(1);

    /* 
     * 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 + -