CTL semaphore timeout issue

Comments

9 comments

  • Avatar
    Michael Johnson

    If you breakpoint on the false timeout does the ctl timer variable look as you expect?

    0
    Comment actions Permalink
  • Avatar
    Michael Freeman

    No, timeout and timeout_occured do not have values to my understanding of how thing work, that make any sense.

     

    In file ctl.c:  ((long)(t->timeout - ctl_current_time) < 0

     

    The value of timeout is greater than ctl_current_time when the false timeout happens, this code should not go active.

     

    Also the member variable timeout_occurred is set to zero when this false timeout happens. I suspect ctl_semaphore_wait is returning a zero when it should be returning a one.

     

     

     

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    ctl_semaphore_wait returns the timeout_occured value as follows

     return ctl_task_executing->timeout_occured==0;

    Did you try changing task/irq stack sizes?

    0
    Comment actions Permalink
  • Avatar
    Michael Freeman

    No I have not touched the IRQ size, I will bump it up alittle and see if that make the problem go away.

    Somehow the task is getting rescheduled when it should not be. Any ideas how this can happen?

    0
    Comment actions Permalink
  • Avatar
    Michael Freeman

    I just doubled the IRQ and the user/system stacks from 256/1024 to 512/2048. I am still catching false timeouts

    0
    Comment actions Permalink
  • Avatar
    Michael Freeman

    Hold on I think I am lying here. The code I am breaking on has two threads with pointers to their data sets. One of the thraed should be timing out and the other should not.  Let me retest the last thing you had me try. I will disable this extra thread and test again.

    Sorry

    0
    Comment actions Permalink
  • Avatar
    Michael Freeman

    Okay I pinned the tail on the donkey. I put both stacks back to size they were and disable the second thread that was tripping. I remembered, there was a change I made around the same time this problem showed up. My tick timer has two functions one to tick the CTL OS and the other to make “soft-timer” callbacks. For the last 2 ½ years this code was a single ISR. Every now and then I would want to make CTL call from one of those soft timers, but since it was a ISR I could not. So I changed it to be a thread with ISR control. Note the line of code I commented out. This one line was breaking the semaphores.

    Now to the real question, why would this break the semaphores??

    //*****************************************************************************
    //#############################################################################
    //*****************************************************************************
    //      Name:           fnTimersIsr()
    //
    //      Description:    This is the timer isr. It is called at ~1mS intervals.
    //      The callback timers counter are decremented to zero. Then
    //      callback is then called and its counter is reloaded.  
    //
    //  Notes:   Isr
    //
    //  MP safe:  Should be ok
    //
    void fnTimersIsr(void)
    {
     if(g_bTimersIsrBusy)
        {
            g_bTimersIsrOverrun = true;
        }
       
        ctl_increment_tick_from_isr();
        ctl_semaphore_signal(&g_srTimerSemaphore);
        //ctl_task_reschedule(); //This is the bad line of code

     return;
    }

     

    //*****************************************************************************
    //#############################################################################
    //*****************************************************************************
    //      Name:           fnTimersThread()
    //
    //      Description:    This is the timer thread. It is called at ~1mS intervals.
    //      The callback timers counter are decremented to zero. Then
    //      callback is then called and its counter is reloaded.  
    //
    //  Notes:   
    //
    //  MP safe:  Should be ok
    //
    void fnTimersThread(void *p)
    {
     unsigned char ucTimerId;
     
        while(1)
        {    
            if((ctl_semaphore_wait(&g_srTimerSemaphore, CTL_TIMEOUT_NONE, WAIT_FOREVER)) != 0)
            {
                //Let Isr know we are busy
                g_bTimersIsrBusy = true;
                g_bTimersOnline = true;
               
                for(ucTimerId = 0; ucTimerId < MAX_NUMBER_OF_1MS_TIMERS; ucTimerId++)
                { //Is this timer active?
                    if(g_bTimerEnable[ucTimerId])
                    { //Yes, check counter for zero
                        if(g_usTimerCounters[ucTimerId])
                        { //Not ready dec
                            g_usTimerCounters[ucTimerId]--;
                        }
                        else
                        { //Ready to run, reload and run timer callback
                            g_usTimerCounters[ucTimerId] = g_usTimerReloads[ucTimerId];
                            g_apfnTimerCallbacks[ucTimerId]();
                        }
                    }
                }
                //Timers are done
                g_bTimersIsrBusy = false;
            }
        }
        return;
    }

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    I can see how calling ctl_task_reschedule at this point causes the problem. I'll fix it for the next release or I can provide the source code if you want it today.

    Thanks

    Michael

    0
    Comment actions Permalink
  • Avatar
    Michael Freeman

    I will wait for update.

    Thanks for all the help

    Michael Freeman

    0
    Comment actions Permalink

Please sign in to leave a comment.