Dynamic C/Rabbit 上的 Micrium uC-OS/II - 可能出现任务匮乏
我正在尝试在 Micrium uC-OS/II 下的 Dynamic C 中运行 2 个任务。一项任务是 http 处理程序,另一项任务是从串行端口读取数据。串口任务似乎抑制了http任务的运行。有什么想法吗?我认为 uC-OS/II 是先发制人的。
void httptask(void* ptr)
{
http_init();
while(1) {
http_handler();
}
}
void gpstask(void* ptr) {
int c;
while (1) {
c = serFgetc();
}
}
两个线程都设置为相同的默认优先级。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
uC/OS-II 是抢占式的,但仅限于一个方向 - 它会抢占较低优先级的线程以允许较高优先级的线程运行,但不会执行相反的操作。也就是说,较高优先级的线程需要显式放弃对CPU的控制才能允许较低优先级的线程运行。我敢打赌,您的串行线程的优先级高于 HTTP 线程,并且
serFgetc()
根本不会放弃控制(通过OSMboxPend
或>OSTimeDly
或其他一些例程)。尝试使串行线程成为系统中优先级最低的线程,或者在其代码中添加一些内容以允许其放弃对 CPU 的控制。 (例如,当没有可用字符时等待信号量,您可以从数据可用中断中发布该信号量。)两者都应该有效。
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 (throughOSMboxPend
, orOSTimeDly
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 仅支持唯一的优先级。此外,您还需要类似 OSTimeDLY(x) 或任务循环中的其他项目来放弃对调度程序的控制。
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.