This question is more about what in your opinion is most efficient for embedded systems running C with RTOS.
I have a task that only updates a variable every period. This variable is used in other tasks in the program:
TaskA.c
int someVar = 0
void TaskFunc(void) {
updateVar(someVar);
}
The other tasks in the application are not blocked waiting for this variable, so that tells me that a FreeRTOS queue might be more than needed. It is more of a global variable like reading time.
So the other option is to have an extern to this variable in the header file.
TaskA.h
extern int someVar;
I am hesitant to do this since global variables are usually not advised. So what if I added a function and have that be global instead?
So TaskA.c would change to:
static int someVar;
void TaskFunc(void) {
updateVar(someVar);
}
void readVar(int *reader){
*reader = someVar;
}
And TaskA.h:
void readVar(int *reader);
Then I can call readVar from any other tasks running in the program to read the static variable in TaskA.c . Is the use of a pointer here doing more harm than good versus just returning someVar?
Are there drawbacks to this that I am not seeing, or am I just overthinking it? Specifically asking for embedded systems if that makes a difference in this case.
Appreciate the feedback!