简体   繁体   中英

How to use Functions in FreeRTOS Tasks

I was wondering how i can use functions that im going to implement myself in 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? should i prevent using functions outside Tasks and instead write plain code of all functions in the 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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