Serial Driver - Error

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Serial Driver - Error

Post 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 ?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Serial Driver - Error

Post 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
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Serial Driver - Error

Post 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 ?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Serial Driver - Error

Post 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
Post Reply