Greetings -
I want to write the entire ISR in assembly (rest of my program is in C) but having trouble with the static local variables inside ISR. For example looking at the following dummy test program.
#include <avr/io.h> #include <avr/interrupt.h> ISR(TIMER1_COMPA_vect) { static uint8_t counter = 0; // Stored in SRAM static uint8_t data_1[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; // Stored in SRAM static const uint8_t data_2[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; // Stored in SRAM PORTA = data_1[counter]; PORTB = data_2[counter]; if (++counter == 8) { counter = 0; } } int main(void) { DDRA = 0xff; DDRB = 0xff; TIMSK1 |= (1 << OCIE1A); OCR1A = 800; TCCR1B |= (1 << WGM12) | (1 << CS10) ; sei(); while (1) { asm("nop"); } }
How/Where do I create counter/data_1 variable in assembly and also data_2 which is constant (I'd like it to be in SRAM, not in program memory) ?
I am writing assembly is separate .S file. Looking like this.
#include <avr/io.h> .global TIMER1_COMPA_vect TIMER1_COMPA_vect: PUSH R16 IN R16, 0x3F // Writing ISR asm here. OUT 0x3F, R16 POP R16 reti
One sure way I know is if I make counter, data_1, data_2 global in C then I can access their address by using their name in assembly. ( Is this the optimal way? )
If not then I think in assembly I have to declare them first in some place in dseg, but then how C complier will know to not overwrite them with other variables in rest of the C program?
Thanks !!!