3
\$\begingroup\$

I have initialized the Micrium Rtos and there is no error when I compile the project but there is a OSTimeDly function in my code that is not working.

I should notify that when I give the first argument of this function ( related to number of ticks to specify the time delay ) the value of 0 , my task is working well but giving any other value to this argument (500 in my code) , stops the program . Do I need to activate something else to enable using delay functions ??

Here is my code :

#include <GPIO_LPC17xx.h>
#include <app_cfg.h>
#include <os.h>
static          OS_TCB      AppTaskStartTCB;
static          CPU_STK     AppTaskStartStk[1000];
static          void            AppTaskStart(void *p_arg);

void SysTick_Handler(void)
{
OS_CPU_SysTickHandler();
}
int main(void)
{
    OS_ERR err; 
    GPIO_SetDir(0,20,GPIO_DIR_OUTPUT);
    GPIO_PinWrite(0,20,1);
    OSInit(&err);
    if (err !=OS_ERR_NONE) {
        GPIO_PinWrite(0,20,0);
    }
    OSTaskCreate((OS_TCB        *)&AppTaskStartTCB,
                            (CPU_CHAR       *)"App Task Start",
                            (OS_TASK_PTR)AppTaskStart,
                            (void           *)0,
                            (OS_PRIO         )5,
                            (CPU_STK        *)&AppTaskStartStk[0],
                            (CPU_STK_SIZE)1000/10,
                            (CPU_STK_SIZE)1000,
                            (OS_MSG_QTY  )0,
                            (OS_TICK         )0,
                            (void             *)0,
                            (OS_OPT          )(OS_OPT_TASK_STK_CHK  |  OS_OPT_TASK_STK_CLR),
                            (OS_ERR         *)&err);

    if (err !=OS_ERR_NONE) {
        GPIO_PinWrite(0,20,0);
    }                       
    OSStart(&err);
    if(err !=OS_ERR_NONE){
        GPIO_PinWrite(0,20,0);
    }
}
static void AppTaskStart (void *p_arg)
{
    OS_ERR err;
    p_arg = p_arg;
    CPU_Init();
    cpu_freq = 100000000; 
    cnts     = (cpu_freq / OSCfg_TickRate_Hz);              
    OS_CPU_SysTickInit(cnts); 
    SYSTICK_InternalInit(10);
    SYSTICK_IntCmd(ENABLE);
    SYSTICK_Cmd(ENABLE);
    GPIO_PinWrite(0,20,0);
    while(1)
    {
        OSTimeDly((CPU_INT16U   )   500,
                            (OS_OPT         )   OS_OPT_TIME_DLY,
                            (OS_ERR      *) &err);
        GPIO_PinWrite(0,20,1);
        OSTimeDly((CPU_INT16U   )   500,
                            (OS_OPT         )   OS_OPT_TIME_DLY,
                            (OS_ERR      *) &err);
        GPIO_PinWrite(0,20,0);
    }
}

Please help me to solve this problem.

My compiler is Keil.

Thanks in advance

\$\endgroup\$
  • \$\begingroup\$ You have defined your problem, could you also provide a specific question to make it easier for people to answer your post? This is a Q&A site. Thanks \$\endgroup\$ – Voltage Spike Aug 18 '16 at 19:28
  • \$\begingroup\$ My guess would be that the delay function is based on a timer interrupt. Are you sure that those interrupts are occurring? If they aren't, that would explain why only nonzero delays fail. \$\endgroup\$ – Dave Tweed Aug 18 '16 at 19:33
  • \$\begingroup\$ You should probably specify which version of the RTOS you are using. \$\endgroup\$ – user2943160 Aug 18 '16 at 23:57
  • \$\begingroup\$ @laptop2d I tried to consider your comment in my question and it is edited.Thank you \$\endgroup\$ – Nima Aug 19 '16 at 0:16
0
\$\begingroup\$

Open startup_LPC177xx.s Replace PendSV_Handler with OS_CPU_PendSVHandler and SysTick_Handler with OS_CPU_SysTickHandler. Press CTRL+F and use Replace tab to do this with your whole project.

It will work!

\$\endgroup\$
1
\$\begingroup\$

When you call OSTimeDly() with a nonzero value, it removes the task from the ready list and records the number of ticks in the task's control block (OS_TCB). The task will not be made ready to run again until it's tick count gets decremented to zero.

The task's tick count gets decremented when OSTimeTick() executes. OSTimeTick() should be called periodically at the tick rate. Your port of the OS needs to provide the mechanism to call OSTimeTick() periodically. Probably what you need to do is to setup a hardware timer to interrupt periodically at that tick rate. Then the hardware timer's ISR should call OSTimeTick().

\$\endgroup\$
  • \$\begingroup\$ Thank You @kkrabmo As you said, I set up the timer and activated its Interrupt by OS_CPU_SysTickInit(cnts) function(after CPU_Init line). Also in its ISR, I called the OS_CPU_SysTickHandler() function, but still the OSTimeDly() is not working. What do you suggest to do now? Do I need to change some parameters in cfg.h? I edited the code in question (considering your answer) \$\endgroup\$ – Nima Aug 19 '16 at 0:11
  • \$\begingroup\$ Set a break point on OSTimeTick(). Does it get called repeatedly? Step through OSTimeTick(). Does it decrement the task's delay counter? \$\endgroup\$ – kkrambo Aug 19 '16 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.