TaskYIELD in critical section

jdupre wrote on Tuesday, July 13, 2010:

Is it appropriate/allowed to call taskYIELD() in a critical section???  I am attempting to have a UART send a break signal for a time period less than the tick frequency if possible.

    portENTER_CRITICAL();
    U2LCR |= serBREAK;
    timestamp = timer3GetValue();
    while (timer3GetValue() - timestamp < 500) {
        taskYIELD();
    }
    U2LCR &= ~serBREAK;
    portEXIT_CRITICAL();

If this code is bogus, is there a way to have my break sent for a period less than the tick frequency without halting everything for the duration?

richard_damon wrote on Wednesday, July 14, 2010:

I am not sure if it will work on all ports, but it will (sort of) on many. Where it works, the YIELD effectively ends the critical section until that task restarts (so it might not be doing what you want). A few comments though, only tasks of the same priority will be able to get time from the YIELD, lower priority tasks will stay blocked. Also, if there are other tasks on this level that are ready, this task won’t get restarted from the YIELD until all of them YIELD themselves from either an explicit YIELD, blocking for something, or running when a timer tick expires, do it may well be longer than a timer tick before it get restarted.

A second comment, is that your probably don’t really need a critical section, you may just need to disable that serial ports interrupt and set a flag for the transmit routine to not try to send during the break.