Hi,
I'm trying to run my multithreading code. During my initial run testing I encountered program problems.
Also I have to check that the addresses of the function pointers aren't affected of assignment in the .ino sketch or in the library.
But for now, the problem I want to know is that the content of the function arguments pointer doesn't hold up after the assignment of function pointers, but before the assignment it prints ok.
This is my sketch:
#include "glcd_spi.h"
////////////////////////////////////////////////////////////////////////////////////////
// enumerations
typedef enum: uint8_t {NOT_FINISHED,FINISHED,DONE}STATE;
// variables
typedef void (*f_ptr)(void *args);
// structs
typedef struct __attribute__((__packed__)){
uint8_t tsk_cnts, tsk_cntr;
uint8_t *tsk_args;
STATE thrd_st;
STATE *tsk_st;
f_ptr *fptr;
}THREAD_t;
// img example
const unsigned char heart [] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
// threads
THREAD_t LCD_THRD;
void setup() {
Serial.begin(9600);
// thread tasks
LCD_THRD.tsk_cnts = 4;
// thread tasks function pointers
LCD_THRD.fptr[LCD_THRD.tsk_cnts];
// thread functions arguments
uint8_t lcd_args[LCD_THRD.tsk_cnts] = {70,10,12,heart};
LCD_THRD.tsk_args = lcd_args;
// thread functions state flags
extern STATE lcd_st_flag;
LCD_THRD.tsk_st = &lcd_st_flag;
// here is no problem, index 0 works
Serial.println(LCD_THRD.tsk_args[0]);
Serial.println(LCD_THRD.tsk_args[1]);
// thread functions pointers
LCD_THRD.fptr[0] = glcd_init;
LCD_THRD.fptr[1] = glcd_graphics_mode;
LCD_THRD.fptr[2] = glcd_clr;
LCD_THRD.fptr[3] = glcd_img;
// here is the problem, index 0 doesn't work
Serial.println(LCD_THRD.tsk_args[0]);
Serial.println(LCD_THRD.tsk_args[1]);
}
void loop() {
}