how to set up interrupt vector programmatically

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
MaxAnarki
Posts: 11
Joined: Tue Dec 25, 2007 6:54 pm
Contact:

how to set up interrupt vector programmatically

Post by MaxAnarki » Fri Jan 25, 2008 6:00 pm

how to set up interrupt vector programmatically ?

for example, it is easy to define interrupt vector at the compile time like this, using winavr lib:

ISR(INT0_vect)
{
}

but I need select INT0_vect or INT1_vect... etc programmatically, depending on some conditions..

What is the easiest way ?

Thanks a lot

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Tue Jan 29, 2008 1:07 pm

Since the interrupt vector is in flash memory, it's hard to modify it from your code. I would recommend that you define ISRs for INT0 AND INT1 and call your routine from either one.

MaxAnarki
Posts: 11
Joined: Tue Dec 25, 2007 6:54 pm
Contact:

Post by MaxAnarki » Tue Jan 29, 2008 1:42 pm

If disengage from that problem and use winavr lib's functions for writing to flash memory, how to write in C lang correct piece of code to define interrupt handler and how to correctly program vector table ?

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Tue Jan 29, 2008 1:49 pm

The vector table consists of relative jump instructions. You must compute the correct rjmp instruction and write it to the vector table slot.

Please note that flash memory can only be programmed page-wise. You must read the entire page, modify the vector and write back the page. Also, some AVRs require that you run code which modifies the main flash memory from the boot loader section. And finally: While programming the flash memory, the CPU may be halted.

MaxAnarki
Posts: 11
Joined: Tue Dec 25, 2007 6:54 pm
Contact:

Post by MaxAnarki » Tue Jan 29, 2008 2:12 pm

As I understand the CPU during working uses RAM. Vector table is loaded from flash to RAM isn't it ? It is convenient to me to modify the RAM only after my software is started.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Tue Jan 29, 2008 7:34 pm

This is not correct. The vector table is in flash memory.

Post Reply