xcodes 发表于 2009-9-10 14:26:49

avrx的一个bug

调用了avrxdelay函数之后不能返回
估计是bug
代码如下:
AVRX_GCC_TASK(task1, 20, 3);
AVRX_GCC_TASK(task2, 20, 1);
AVRX_GCC_TASK(task3, 20, 1);
AVRX_MUTEX(TimerSemaphore);        //声明一个信号量
AVRX_TIMER(myTimer);
//TimerControlBlock myTimer,myTimer2,myTimer3;
int main(void)
{
    AvrXSetKernelStack(0);
        DS1302_Init();
        GUI_Init();       
        GUI_VarInit();
        Key_Init();
        MCUCR = _BV(SE);      // Initialize Timer Hardware
    TCNT0 = TCNT0_INIT;
    TCCR0 = TMC8_CK256;
    TIMSK = _BV(TOIE0);    // Enable Timer overflow interrupt       
       
    AvrXRunTask(&task1Tcb);
    AvrXRunTask(&task2Tcb);
    AvrXRunTask(&task3Tcb);
    Epilog();                   // Switch from AvrX Stack to first task
    while (1);
}

AVRX_SIGINT(SIG_OVERFLOW0)
{
    IntProlog();
    TCNT0 = TCNT0_INIT;
        AvrXTimerHandler();      // Call Time queue manager
       
//    while (AvrXIntTestSemaphore(&TimerSemaphore) == SEM_WAIT)
//    AvrXIntSetSemaphore(&TimerSemaphore);   // Flush all waiting tasks
    AvrXIntSetSemaphore(&TimerSemaphore);   // Set Semaphore (short path)
       
    Epilog();
}


NAKEDFUNC(task1)
{       
        uint myKey;
        uchar Key;                //按键
        while (1)
    {
                AvrXWaitSemaphore(&TimerSemaphore);
                AvrXWaitSemaphore(&TimerSemaphore);
                if(GUI_Flash)
                {
            cli();
            GUI_Clear();        //清空                       
                        str1=*(pMenu.Text+Item);
                        str2=*(pMenu.Text+Item+1);
                       
            GUI_PutStrAt(str1,0,0);
            GUI_PutStrAt(str2,0,1);
                        if(Where<MaxDispY)
            {
                GUI_SetPos(15,Where);
                GUI_PutStr("<");
            }
                        GUI_Flash=0;
            sei();
      }

                myKey=PINA;               
                AvrXDelay(&myTimer,20);//<-----------------------------程序会在这里死掉,诸君可以验证
                Key=PINA;
                if(Key!=myKey)continue;
                while(myKey!=0xf0)
                {
                        myKey=PINA;               
                        myKey&=0xf0;
                        AvrXDelay(&myTimer,1);
                }

                if(myKey!=0xf0)continue;
                Key&=0xf0;               
/*
                        cli();
                        GUI_Clear();        //清空
                        GUI_PutStrAt("Key=",0,0);
                        GUI_PutNum(myKey&0xf0);
                        GUI_PutStrAt("Keytest",0,1);
                        GUI_SetPos(15,Where);
                        GUI_PutStr("<");
                        sei();
                        continue;
*/
      switch (Key)
      {
      case UP:                                        //向上键
                        KeyFuncIndex=KeyTab.KeyUpState;       
                        KeyFuncPtr=KeyTab.CurrentOperate;
                        (*KeyFuncPtr)();//执行当前按键的操作
                        break;
      case DN:                                        //向下键
                        KeyFuncIndex=KeyTab.KeyDnState;
                        KeyFuncPtr=KeyTab.CurrentOperate;
                        (*KeyFuncPtr)();//执行当前按键的操作               
                        break;
                case ESC:                                        //返回键
                        KeyFuncIndex=KeyTab.KeyEscState;
                        KeyFuncPtr=KeyTab.CurrentOperate;
                        (*KeyFuncPtr)();//执行当前按键的操作       
                        break;
                case ETR:                                        //进入键
                        KeyFuncIndex=KeyTab.KeyEtrState;
                        KeyFuncPtr=KeyTab.CurrentOperate;
                        (*KeyFuncPtr)();//执行当前按键的操作       
                        break;
                default:
            break;
                }
       
        }
}

NAKEDFUNC(task2)
{
    while (1)
    {
                AvrXWaitSemaphore(&TimerSemaphore);
    }
}

NAKEDFUNC(task3)
{
    while(1)
    {
                AvrXWaitSemaphore(&TimerSemaphore);

    }
}

ShangGuan 发表于 2009-9-10 20:44:53

以前用过一点avrx,avrxdelay没问题。

楼主简化点程序,把不必须要的程序删除,提供一个能反映最简工程,大家才好帮你找原因。

xcodes 发表于 2009-9-11 08:41:14

NAKEDFUNC(task1)
实际上是一个菜单系统

其他的任务均 是等待一个信号量

上官 能否把你的例子发出来?
让我参考一下

caocao 发表于 2009-9-11 09:08:22

这两天也在搞avrx,avrxdelay似乎是有点问题,我在两个互斥任务中调用同一个子函数,子函数里有avrxdelay延迟,运行中会死在这里。后来把子函数的代码分别copy一份到各自的任务里,运行没有问题。

xcodes 发表于 2009-9-11 09:25:37

楼上能否把你的代码 发一下 看看?
页: [1]
查看完整版本: avrx的一个bug