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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With