I've got some pretty basic questions regarding my application and implementing the Scheduler Library. I'm very much a novice, so I apologize before hand.
First a note about my application:
Imagine a factory with a number of different stations all controlled by a central "hub". This central hub will be the Due and the stations can be divided into two subgroups: smart and dumb stations. The smart stations have another Due that communicates via RS-435 with the hub. The dumb stations are controlled by the GPIO of the hub.
I've got a large amount of data that consists of "addresses" and "times". Initially, (before the main loop) this data is processed and sent to an external EEPROM chips on I2C bus. (After processing data from SD card, the user should be able to remove the SD card and power down the unit, come back the next day without the SD card and still have it work). This much is more or less complete. I have not decided whether I want to try and read directly from the EEPROM or whether it would be beneficial to load the data out of EEPROM and into SRAM before entering the main loop.
Now, in the main loop I've got something that basically looks like (in pseudocode)
unsigned long time[800]; //In reality, arrays like these will take up about 23 kB of SRAM
byte address[800];
int i = 0;
int interval = 1;
void loop(){
if (time[i] >= millis() && time[i] <= millis() + interval){
//turn on address[i]
++i;
if (i > 800) reset();
}
}
I want to do other things while this is running but I need to be sure that I always return to this "stuff" within the 1 mS window. I don't want to accidentally miss a "turn-on event" because I was busy working on a different thread. The trouble is, sometimes these these events are separated by several seconds or even minutes while other times they are only separated by a couple of milliseconds. For instance, I'm interested in using the Audio library to output some analog wave forms from the onboard DACs but I want the main loop to have priority. I'd also like to ping the smart stations regularly over the RS-435 to make sure they are still active.
The problems that I see are the following:
1)memory; I assume that the schedule requires separate "heaps" (right word?) for each "thread" that it runs.
2)timing; how do I know when the scheduler will return to test the if statement in my code? I am under the impression that yield will pass the control to another task, but does that task have to complete before the scheduler returns to the main task?
With 1 mS "accuracy", I have an approximate minimum of 80,000 clock cycles where I'm not doing anything except killing time. I'd like to squeeze some useful instructions in there but always return to check the main loop after 80,000 cycles so I know I don't miss an event.
Does any of this make sense? Is there anyone who has the time to bring a novice up to speed on this topic?