简体   繁体   English

如何在 FreeRTOS 任务中使用函数

[英]How to use Functions in FreeRTOS Tasks

I was wondering how i can use functions that im going to implement myself in FreeRTOS.我想知道如何使用我将在 FreeRTOS 中实现自己的函数。
Example: if i want to create any function like calculateTotal of two values (just an example), how can i use it with the Task?示例:如果我想创建任何函数,如两个值的calculateTotal (只是一个示例),我如何将它与任务一起使用? should i prevent using functions outside Tasks and instead write plain code of all functions in the Task ?我应该防止外界使用的功能Tasks ,而是写在所有功能明码Task can anybody help me out ?有人可以帮我吗?

void randomTask(void* param) {
    //initialize something

    for(;;){

    //can i call functions here and define them outside?
    
    }
}

Yes, you can define functions outside and call them from the tasks.是的,您可以在外部定义函数并从任务中调用它们。 These functions are executed in the context of the calling task, and they use the stack memory allocated for the task.这些函数在调用任务的上下文中执行,它们使用为任务分配的堆栈内存。

You can also call the same function from different tasks, as long as they are stateless.您还可以从不同的任务调用相同的函数,只要它们是无状态的。 A function is stateless if it doesn't use global variables and static local variables.如果函数不使用全局变量和静态局部变量,则它是无状态的。 Of course, you can provide a state (context) as a function parameter.当然,您可以提供状态(上下文)作为函数参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM