Priority order violation associated with events (using timeout)

Report here problems in any of ChibiOS components. This forum is NOT for support.
User avatar
Posts: 62
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 12 times
Been thanked: 14 times

Priority order violation associated with events (using timeout)

Postby FXCoder » Tue Mar 13, 2018 2:55 pm

Similar to post viewtopic.php?f=24&t=3943 I've encountered a "priority order violation".
This happens when multiple threads use one of the chEvtWaitxxxTimeout(...) set of functions and the chEvtGetAndClearEvents() function.
The problem was exposed when some monitoring was added to the main thread to check for events being broadcast by other threads.
In this case the other thread is a decoder taking PWM data and decoding it as audio FSK.

I can cure the issue by adding a chSchRescheduleS() prior to the ChSysUnlock() in the locked code section that throws the priority order violation.
This locked section is called just after an event posted from another thread (not main) is detected in the PWM decoder thread by the chEvtGetAndClearEvents() function.

Unfortunately the project is somewhat complex with multiple threads and event signalling.

The following code is the event processing and the function that throws the "priority order violation"...

A thread running a decoder of PWM data...

Code: Select all

      case DECODER_IDLE: {
         *  Check for stop event.
        eventmask_t evt = chEvtGetAndClearEvents(DEC_COMMAND_STOP);
        if(evt) {
          myDriver->decoder_state = DECODER_WAIT;
          pktAddEventFlags(myDriver, DEC_STOP_EXEC);
        myDriver->decoder_state = DECODER_POLL;
      }  /* End case DECODER_IDLE. */

The function it calls when the decoder finds an event requesting it to stop (pause really).

Code: Select all

 * @brief   Disables PWM stream from radio.
 * @post    The ICU capture is stopped.
 * @post    The port for CCA input is disabled.
 * @post    The PWM buffer reference is removed.
 * @post    The ICU remains ready to be restarted.
 * @param[in]   myDriver   pointer to a @p AFSKDemodDriver structure
 * @api
void pktDisablePWM(AFSKDemodDriver *myDriver) {

  chDbgAssert(myDriver->icudriver != NULL, "no ICU driver");


  /* Close the PWM stream. */
  pktClosePWMChannelI(myDriver->icudriver, 0, PWM_TERM_DECODE_STOP);

  /* Stop ICU capture. */

  /* Stop any timeouts in ICU handling. */

  /* Disable CCA port event. */

  myDriver->icustate = PKT_PWM_STOP;

   * FIXME: This reschedule is required to avoid a "priority order violation".

All the interrupt levels in the mcuconf.h are at standard ChibiOS settings.

Any thoughts?



User avatar
Site Admin
Posts: 10650
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 282 times
Been thanked: 244 times

Re: Priority order violation associated with events (using timeout)

Postby Giovanni » Tue Mar 13, 2018 3:10 pm

The reschedule should prevent that assertion, it is possible you have a similar problem is some other place.

Look at the stack trace after stopping in the assertion.


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 1 guest