Hello,
upon program start, In my isr, the variable
sensorState[sensorStateIndex].timeStamp=epochLocal
is updated before the corresponding interrupts are being enabled.
Here is the code
declarations
...
ISR(PCINT0_vect){sensorISR();}
ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect));
ISR(PCINT2_vect, ISR_ALIASOF(PCINT0_vect));
...
setup
...
get epoch from Internet, setup epochLocal
...
initInterrupts()
...
initInterrupts
void initInterrupts(){
cli();
attachInterrupt (0, sensorISR, CHANGE);
attachInterrupt (1, sensorISR, CHANGE);
attachInterrupt (2, sensorISR, CHANGE);
attachInterrupt (3, sensorISR, CHANGE);
attachInterrupt (4, sensorISR, CHANGE);
attachInterrupt (5, sensorISR, CHANGE);
//INT0-5 control
DDRD&=0x0f; //PORTD0-3 inputs
PORTD|=0x0f; //pull ups on pins PORTD0-3
DDRE&=0xcf;//PORT E4-5 as inputs
PORTE|=0x30;//pull ups on PORTE 4-5
//guess enabled by the attachInterrupts
//PCINT0-2 control
DDRB&=0x9f; // set pin portB 5-6 as input, leave other untouched
PORTB|=0x60;// pull ups on pins 5-6
PCMSK0|=0x60;//enable interrupts on portB 5-6
DDRJ&=0xfc; // pins 0-1 input
PORTJ|=0x03;// pins 0-1 pull ups
PCMSK1|=0x06;// set PCMSK1_1-2. PCMSK1_0-PCINT8-PE0, PCMSK1_1-PCINT9-PJ0, PCMSK1_2-PCINT10-PJ1, PCMSK1_3-PCINT11-PJ2 ... PCMSK1_7-PCINT15-PJ6
DDRK=0x00; //inputs
PORTK=0xff;//add pull ups
PCMSK2=0xff;// enable interrupts on all port k
PCICR=0b00000111; //enable PCINT0-2
EIFR=0Xff; //clear all 8 bits interrupt flags of ext interrupt eifr
PCIFR=0x07; //clear all 3 bits interrupt flug of pin change interrupr
sei();
}
isr
void sensorISR(){
...
sensorState[sensorStateIndex].timeStamp=epochLocal;
...
}
So, the assumption is that before initInterrupt is executed, sensorISR won't be visited(!) and if so, once visited, epochLocal has the correct time and so for the first element of sensorState array
In practice, oftentimes, if a sensor is stimulated after the program starts and before initInterrupts is executed, the value loaded into sensorState is the initial value of epochLocal - either compilerr's generated 0 or any other value i assign to it in the declaration