I just took over a project which has many contributors over the years. The project consists of a robot with distance sensors that collects and processes data and sends it to a server for plotting the area. The robot runs FreeRTOS on a nrf52832 chip and I think it has some weird solution to global variables. In main() it starts several tasks, but the most relevant ones are, sensor-tower-task, estimator-task and controller-task which has their own source and header file.
Each header files only contains the declaration of the respective tasks, like:
taskX.h
void vSensorTowerTask(void *pvParameters);
Each sourcefile for the three mentioned tasks contains the following declarations for the global variables:
taskX.c
extern int16_t gX_hat;
extern int16_t gY_hat;
extern float gTheta_hat;
// +several lines with global variables
main.c
int16_t gX_hat = 0;
int16_t gY_hat = 0;
float gTheta_hat = 0;
// +several more
It looks like the gTheta_hat in main() gets updated when the estimator-task updates it, but not in the controller and sensor-tower tasks. If a global and local variable has the same name, shouldn't that give some kind of warning from the compiler. Is there any reason at all the declaration of the globals are done in this manner? It should be noted that reading and writing to these globals are protected with mutex.