use*_*230 3 c embedded portability freertos
我很想知道如何在我的应用程序中使用FreeRTOS.让我提出一个简单的方案.假设我有main和一个具有一些硬件特定代码的模块.该代码可用于控制系统或传感器中的特定电机......具有定义角色的任何硬件.在module.c中,我有一个名为的函数ModuleNameTask.在main我创建任务使用xTaskCreate,我通过ModuleNameTask.由于我ModuleNameTask是在module.c而不是main.c中定义的,所以我现在必须在module.c中包含一些FreeRTOS,以便使用类似的函数vTaskDelay.我不喜欢我在module.c中包含这些文件的事实,因为我觉得它不再可移植.
那么,我该如何处理呢?我应该ModuleNameTask从module.c中删除它并将其放在main.c中吗?或者只是接受我必须将FreeRTOS的位包含到module.c中的事实.有什么建议?
What functionality do you require from FreeRTOS for your module to work. Obviously there are some things or you wouldn't need to include the headers and you wouldn't be calling the functions.
Take these functions and put them in a separate header called os/<operating_sys>/freertos.h and wrap them in your own function names (e.g. my_createtask(<args>).). Now to port to a different OS you will need to provide a new file with new wrappers for your own functions.
If you do this poorly you'll notice that your createtask function looks exactly like the FreeRTOS function and can be easily mapped but when you want to use linux/vxWorks/other OS that the function doesn't have the right arguments.
您的createtask函数应该只包含您关心的参数.其他应该在包装器中进行硬编码.这将使端口更容易(您将在其他操作系统中具有与硬代码不同的参数).
摘要RTOS和设备层.
定义设计的OS接口(这可能只是FreeRTOS功能的一个子集,甚至包括使用RTOS原语实现的更高级接口),并使用FreeRTOS实现此接口.
然后,仅使用RTOS抽象层接口定义整个应用程序,包括设备层.当您将应用程序移植到另一个平台或RTOS时,您只需要更改抽象层实现,确保保持与原始实现相同的语义.如果设备层也被适当地抽象,以便能够在不同硬件上通用,那么您可以对硬件依赖性做同样的事情(即从物理实现中抽象它们).
我已成功使用这种方法多年,使用C++中的RTOS抽象,我已移植到FreeRTOS,VxWorks,Segger embOS和Keil RTX,甚至Windows和Linux(用于测试和模拟).你当然不需要使用C++,但它非常适合这项任务.
在您的抽象中,您需要考虑以下事项:
您的界面可能与FreeRTOS本身有很大不同,可能值得查看其他一些RTOS界面,以了解您可能需要哪些功能.