Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Micrium uC-OS/II on Dynamic C/Rabbit - might have task starvation

I'm trying to get 2 tasks to run in my Dynamic C under Micrium uC-OS/II. One task is the http handler, the other reads from the serial port. The serial port task seems to inhibit the http task from running. Any ideas why this is? I thought uC-OS/II was preemtive.

void httptask(void* ptr)
{
 http_init();

 while(1) {
  http_handler();
 }
}

void gpstask(void* ptr) {

 int c;

 while (1) {
        c = serFgetc();
    }
}

Both threads are set to the same default priority.

like image 443
fred basset Avatar asked Jan 21 '23 19:01

fred basset


2 Answers

uC/OS-II is preemptive, but only in one direction - it will preempt a lower-priority thread to allow a higher priority thread to run, but will not do the reverse. That is to say, higher-priority threads need to explicitly give up control of the CPU in order to allow lower priority threads to run. I'm betting that your serial thread is higher priority than the HTTP thread, and that serFgetc() doesn't give up control at all (through OSMboxPend, or OSTimeDly or some other routine).

Try either making the serial thread the lowest priority thread in the system, or putting something into its code to allow it to give up control of the CPU. (For example, waiting on a semaphore when no characters are available, which semaphore you can post from a data-available interrupt.) Either should work.

like image 71
Aidan Cully Avatar answered Jan 24 '23 08:01

Aidan Cully


uC/OS-II supports only unique priorities. Also you need something like OSTimeDLY(x) or some other item in your task loops to give up control to the scheduler.

like image 42
ValiRossi Avatar answered Jan 24 '23 09:01

ValiRossi