打印

用44b0跑了UCOS的程序,臭一下 激励自己

[复制链接]
1991|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
IC1008|  楼主 | 2007-5-7 09:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
ucos, ST, se, TE, AC
/*
 * File:        main.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 Marco Graziano (marcog@crl.com).
 *
 */

#include    "includes.h"               /* uC/OS interface */

/* allocate memory for tasks' stacks */
#ifdef SEMIHOSTED
#define STACKSIZE       (SEMIHOSTED_STACK_NEEDS+64)
#else
#define    STACKSIZE    128
#endif
unsigned int Stack1[STACKSIZE];
unsigned int Stack2[STACKSIZE];
unsigned int Stack3[STACKSIZE];

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

OS_EVENT    *KeyPress;
void *KeyMsg[10];
/*
* Task running at the highest priority. 
*/

void Task1(void *i)
{
    unsigned char key[5];
    unsigned char i1,temp;
    unsigned char NewKey,OldKey;
    ARMTargetStart();
    for (;;)
    {
        NewKey=rPDATG&0xf0;
        if(NewKey!=OldKey)
        {
            OldKey=NewKey;
            if((NewKey&0x10)==0)        temp='a';
            else if((NewKey&0x20)==0)    temp='b';
            else if((NewKey&0x40)==0)    temp='c';
            else if((NewKey&0x80)==0)    temp='d';
            else    temp=0;
            if(temp!=0)
            {
                for(i1=0;i1<5;i1++)    if(key[i1]==0)    break;
                key[i1]=temp;
                OSQPost(KeyPress,&(key[i1]));
            }
        }
        OSTimeDly(20);        //20ms
    }
}

void Task2(void *i)
{
    unsigned char key[5];
    unsigned char i1;
    unsigned char NewKey;
    for (;;)
    {
        NewKey=Uart_GetKey();
        if(NewKey!=0)
        {
                for(i1=0;i1<5;i1++)    if(key[i1]==0)    break;
                key[i1]=NewKey;
                OSQPost(KeyPress,&(key[i1]));            
        }
        OSTimeDly(10);
    }
}

void Task3(void *i)
{
    unsigned char *ip;
    INT8U    err;
    for (;;)
    {
        ip=OSQPend(KeyPress,0,&err);
        if(*ip=='a')        Uart_Printf("\nYou Press a!");
        else if(*ip=='b')    Uart_Printf("\nYou Press b!");
        else if(*ip=='c')    Uart_Printf("\nYou Press c!");
        else if(*ip=='d')    Uart_Printf("\nYou Press d!");
        *ip=0;
    }
}

/*
 * Main function.
 */
void Main(void)
{
    char Id1 = '1';
    char Id2 = '2';
     char Id3 = '3';
    Port_Init();
    Uart_Init(0,57600);
    
    Delay(1000);
    Uart_Select(0); //Select UART0

    Uart_Printf("Uc-OS ii will run at once!");
    

    /* do target (uHAL based ARM system) initialisation */
    ARMTargetInit();

    /* needed by uC/OS */
    OSInit();

    OSTimeSet(0);
    /* 
     * create the semaphores
     */
    //Sem1 = OSSemCreate(1);
    //Sem2 = OSSemCreate(1);
//Sem3 = OSSemCreate(1);
    /* 
     * create the tasks in uC/OS and assign decreasing
     * priority to them 
     */
    OSTaskCreate(Task1, (void *)&Id1, (void *)&Stack1[STACKSIZE - 1], 1);
    OSTaskCreate(Task2, (void *)&Id2, (void *)&Stack2[STACKSIZE - 1], 2);
    OSTaskCreate(Task3, (void *)&Id3, (void *)&Stack3[STACKSIZE - 1], 3);
    /* Start the (uHAL based ARM system) system running */
    //ARMTargetStart();
    KeyPress=OSQCreate(KeyMsg,10);                //创建一个按键的消息队列

    /* start the game */
    OSStart();

    /* never reached */
}                               /* main */

相关帖子

沙发
IC1008|  楼主 | 2007-5-7 14:53 | 只看该作者

说明

两个按键任务 一个显示任务
按键任务1 真实按键
按键任务2 串口接收
显示任务3 串口向电脑发送消息

显示任务一直等待按键消息队列.

所以要创建一个事件指针 OS_EVENT    *KeyPress;
因为是消息队列 所以必须还要创建一个消息指针堆栈 void *KeyMsg[10];
定义事件为消息队列 KeyPress=OSQCreate(KeyMsg,10); 
任务1 任务2 检测到按键事件,向消息队列添加一个消息 OSQPost(KeyPress,&(key[i1]));
任务3 等待消息队列里面的消息 ip=OSQPend(KeyPress,0,&err);使用完消息将消息清零 *ip=0;

使用特权

评论回复
板凳
lufeijian| | 2007-5-8 09:35 | 只看该作者

不错,学习中~那天也让UCOS在DSP上跑跑啊

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

41

主题

229

帖子

0

粉丝