Page 1 of 1

Serial Driver - Error

Posted: Tue Dec 06, 2016 12:57 pm
by Tabulous
Below is my current GPS thread, but i am seeing a weird issue.

Code: Select all

static THD_FUNCTION(ThreadGPS, arg)
{
msg_t c;
eventflags_t flags;
event_listener_t elGPSdata;


    (void)arg;

    sdStart(GPS, &gpsconfig);
    chRegSetThreadName("gpsd");

    chEvtRegisterMask(chnGetEventSource(GPS),
                      &elGPSdata,
                      EVENT_MASK(1));

    while( TRUE )
    {
        chEvtWaitAll(EVENT_MASK(1));
        flags = chEvtGetAndClearFlags(&elGPSdata);

        if(flags & SD_OVERRUN_ERROR)
        {
            TGL_DEBUG(DBG_MASK_GPS, "$ GPS - Overrun!\r\n");
        }

        if(flags & CHN_INPUT_AVAILABLE)
        {
           do
           {
              c = chnGetTimeout( GPS, TIME_IMMEDIATE );

              if ( c != Q_TIMEOUT )
              {
                  decodeNMEAstateMachine( (char)c );
              }
           }
           while (c != Q_TIMEOUT);
        }
    }
}


All of a sudden, the events stop firing and i stop receiving data.
If i break on the interrupt, that is still firing, and tracing it through to

Code: Select all

void sdIncomingDataI(SerialDriver *sdp, uint8_t b) {

  osalDbgCheckClassI();
  osalDbgCheck(sdp != NULL);

  if (iqIsEmptyI(&sdp->iqueue))
    chnAddFlagsI(sdp, CHN_INPUT_AVAILABLE);
  if (iqPutI(&sdp->iqueue, b) < Q_OK)
    chnAddFlagsI(sdp, SD_OVERRUN_ERROR);


it fails the iqIsEmptyI test and thus never sets flag CHN_INPUT_AVAILABLE.

So this says to me the buffer is full, and yes i can see in my debug SD_OVERRUN_ERROR was set some time prior to this happening.
But also interesting chnAddFlagsI(sdp, SD_OVERRUN_ERROR); is called but the event never fires in the once it locks.
When in this state q_counter = 512, this is same as my buffer size.

So the question is what is the correct way to recover from this issue ?

Re: Serial Driver - Error

Posted: Wed Dec 07, 2016 10:04 am
by Giovanni
Hi,

Is it possible that the first char is received before the thread is registered on the event?

If so then you could register the thread and then reset the input queue, this will make sure the first received char will trigger the event.

Giovanni

Re: Serial Driver - Error

Posted: Wed Dec 07, 2016 10:15 am
by Tabulous
Giovanni wrote:Hi,

Is it possible that the first char is received before the thread is registered on the event?

If so then you could register the thread and then reset the input queue, this will make sure the first received char will trigger the event.

Giovanni


This is a possibility, when in my debug mode the sdStart is called seconds before the start of the GPS thread, see this thread for details why

http://www.chibios.com/forum/viewtopic.php?f=25&t=3690


If this is the case how does one safely recover ?

Re: Serial Driver - Error

Posted: Wed Dec 07, 2016 10:23 am
by Giovanni
By resetting the input queue you make sure that the next received character will trigger the event, the previous queue state is lost.

Alternatively you can self-broadcast the event after registering in order to trigger processing of data already in the queue.

Giovanni