FreeRTOS 在调度程序启动之前(或停止之后)对 IO 进行排队
我正在寻找有关如何在操作系统调度程序可能尚未启动、正在运行、挂起或可能已停止的环境中最好地实现线程安全 IO(例如,printf 进入调试串行端口)的建议。坠毁了。我正在使用 Newlib 和 FreeRTOS。
目前,我正在采用(看似标准的)FreeRTOS 方法,将 _write 系统调用(Newlib)队列字符放入 FreeRTOS 队列,然后从中断服务程序中清空(填充串行端口硬件 FIFO,然后等待 FIFO 空中断)。
这样做的缺点是(至少在 FreeRTOS 上)队列只能在调度程序运行时安全使用,并且在禁用中断时无法打印调试输出(因为它们在引导期间直到调度程序启动,或者在致命错误之后)错误条件(正是调试 printf 输出最有用的地方:-)
最好让 _write 系统调用查询调度程序和/或中断状态,并在调度程序正在运行时使用队列并使用阻塞/轮询串行 IO。当中断被禁用时?有一个我还没有想到的更优雅的想法吗
?
I'm looking for advice on how to best implement thread-safe IO (e.g. for printf going to a debug serial port) in an environment in which the operating system scheduler may yet to have started, be running, suspended or may have stopped or crashed. I'm using Newlib and FreeRTOS.
At the moment, I'm doing the (seemingly-standard) FreeRTOS approach of having the _write system call (Newlib) queue characters into a FreeRTOS queue which is then emptied from an interrupt service routine (filling the serial port hardware FIFO then waiting for the FIFO empty interrupt).
This has the disadvantage that (at least on FreeRTOS) the queue can only be used safely when the scheduler is running, and debug output can not be printed when interrupts are disabled (as they are during boot until the scheduler starts, or after a fatal error condition (exactly where debug printf output would be most useful :-).
Would it be best to have the _write system call query the scheduler and/or interrupt status, and use queues if the scheduler is running and use blocking/polling serial IO when interrupts are disabled? Is there a more elegant idea I haven't thought of yet?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许稍微优雅一点的是在 _write 系统调用中使用间接。不检查状态,而是根据调度程序是否正在运行、是否启用中断等,使用函数指针来实现所需的功能。然后在程序状态发生变化时设置适当的回调函数。
或者,您可以定义一个不同的调试函数,绕过标准库流系统(即 printf),以在您知道没有中断/RTOS 设施的地方使用(例如异常处理程序)。
Perhaps slightly more elegant would be to use indirection in the _write system call. Instead of checking the status, use a function pointer to achieve the desired functionality based on whether the scheduler is running, interrupts enabled, etc. Then set the appropriate callback function when the program state changes.
Alternatively, you define a different debug function that bypasses the standard library stream system (i.e. printf) to use in places that you know will not have interrupt/RTOS facilities (e.g. exception handlers).