Hi,
I want to improve my multitasking management.
Of course the basic system of running the functions is round robin.
But it came now where I want to run a sequence of functions as a thread, and also running another thread that has other tasks in parallel.
The main idea of the thread manager is:
Each thread may has multiple tasks that should run in sequential mode, if not then just put the functions in loop area and they should run in round robin.
I was thinking of a way to store the addresses of the functions I want to run in sequential mode, because functions pointers didn't work very well because when calling back a function pointer, I didn't find a way to pass the required arguments so I decided to find another way.
Which is to use array of function pointer to store addresses of functions, then use these addresses to match the counter in the thread manager so this way I can run the functions in sequential mode.
But one thing now I noticed is that just storing only 7 function pointers raised the program memory usage from 1438 to 3034 !
As each function pointer is only 8 bytes long, so 7 x 8 = 54 bytes, but the difference is 3034 - 1438 = 1,596 bytes ! Why this jump in used memory for only 7 function pointers ?
This is the code:
- task_manager.h
typedef void (*f_ptr)(void);
- Arduino sketch file:
#include "task_manager.h"
#include "glcd_spi.h"
#include "sensors_modules.h"
#include "arrays.h"
#define LCD_THRD 0
#define SERIAL_THRD 1
#define LCD_TASKS 4
#define SERIAL_TASKS 3
THREAD_STATE pgm_thread[2]; // 2 threads: lcd & serial threads
f_ptr lcd_fptr[LCD_TASKS];
f_ptr serial_fptr[SERIAL_TASKS];
void setup() {
Serial.begin(9600);
lcd_fptr[0] = glcd_init; // just uncommenting this line,
// the program space jumps from 1438 to 2404
// lcd_fptr[1] = glcd_graphics_mode;
// lcd_fptr[2] = glcd_clr;
// lcd_fptr[3] = glcd_img;
//
// serial_fptr[0] = function1;
// serial_fptr[1] = function2;
// serial_fptr[2] = function3;
}
Now my first problem is the memory usage with defining one function pointer in arduino sketch ! What is the reason for that and how to solve it ?
If this problem is solved then I can proceed using them in source files to match address of the function called and unlock it in program run until it's finished, then open the lock for the next function and so on.