Go Down

Topic: Modifying the Interrupt Vector Table (Read 387 times) previous topic - next topic

crakerbr

I'm working on a project creating a new Arduino compatible board, which has more than one UART, I2C, and SPI interface. I'm trying to figure out from the software & compiler side how to support these new interfaces, specifically how to handle the hardware interrupts required. I've found documentation for the 328p interrupt table, and I've found the iom328p.h file which defines the vectors. I want to add vectors to the table and then attach ISRs to those vectors.

I thought perhaps I could modify the vector table simply by adding the following code as a starting point into my library:

Code: [Select]
#define MY_vect_num 26
#define MY_vect _VECTOR(26)
#define _VECTORS_SIZE (27 * 4)


However, this code didn't have an impact on the compiled code so that can't be correct.

I know that there are different board variants in the Arduino libraries, do I need to create a new variant? Or am I putting my code in the wrong place? Or maybe I have the wrong idea on how to add new interrupts.

DrAzzy

#1
Dec 04, 2017, 07:42 pm Last Edit: Dec 04, 2017, 07:42 pm by DrAzzy
You're putting your code in the wrong place. io.h (part of the compiler, supplied by Atmel) will automatically include the correct iomxxx.h file for the microcontroller you are using (the one specified in your boards.txt); you do not need to concern yourself with the interrupt table if you're doing everything else right.
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

crakerbr

I am working with a new board, not an existing Arduino board. It is Arduino compatible, but it has extra UART, SPI, and I2C interfaces, including new physical pins and new register addresses for these interfaces. It does not yet have it's own boards.txt, or it's own board variant. I am trying to create the software that will make these interfaces usable, I think in this case I do need to modify the interrupt table. From your comment, it sounds like I probably need to create a new io.h file for this board, my impression is that once the interrupt table is built it cannot easily be modified.

westfw

Quote
I think in this case I do need to modify the interrupt table.
Unless you're using a non-Atmel chip, the interrupt table is all defined in the C startup code that is sucked in from (ie) ...avr/lib/avr5/crtatmega328p.o (source code probably at http://svn.savannah.gnu.org/viewvc/avr-libc/trunk/avr-libc/crt1/gcrt1.S?revision=2519&view=markup)  It looks like:
Code: [Select]
__vectors:
54              XJMP    __init
55              vector  __vector_1
56              vector  __vector_2
57              vector  __vector_3
58              vector  __vector_4
   :



Then a file included via avr/io.h associates names with those symbols:

Code: [Select]
#define USART_RX_vect_num 18
#define USART_RX_vect     _VECTOR(18)  /* USART Rx Complete */

#define USART_UDRE_vect_num   19
#define USART_UDRE_vect   _VECTOR(19)  /* USART, Data Register Empty */


And your only responsibility as a C level programmer is to define ISR handlers with the appropriate names:

Code: [Select]

#if defined(HAVE_HWSERIAL3)
ISR(USART3_RX_vect)
{
  Serial3._rx_complete_irq();
}

ISR(USART3_UDRE_vect)
{
  Serial3._tx_udr_empty_irq();
}


The vector table is in FLASH, and can't be modified at runtime, nor relocated (except to the beginning of the boot section, which is not useful.)
If you're using a very new Atmel chip, it might not be supported in the current Arduino IDE toolchain (no ioXXXXX.h or crtxx.o exists), in which case there is usually a "Pack" (or complete replacement toolchain) that can be downloaded from atmel and added, somehow.
The only time you should need to write your own ioXXXXX.h or similar is if you're using a non-Atmel chip that isn't that compatible (LFT8f328D?  FPGA-implemntation?)
Entirely different rules apply for non-AVR chips.

crakerbr

Okay thanks, that's information that I need to know. This is a non-Atmel chip, this is an FPGA implementation. I have an RTL designer who is adding the new hardware interfaces and rebuilding the FPGA image. I found the object file you reference in my Arduino install. So if I got this to work, I'm assuming I need one of these precompiled object files built for my hardware image, and have to specify this as a board variant as well. The mechanism to bring in a non-default object file must be the mcu option at compile time.

westfw

Quote
I need one of these precompiled object files built for my hardware image, and have to specify this as a board variant as well. The mechanism to bring in a non-default object file must be the mcu option at compile time.
More or less.  I'm pretty unclear on exactly what the C compiler does to turn "-mmcu=atmega328p" into
     #define __AVR_ATmega328P__ 1
and the other (many) pre-defined constants.
Another option would be to use -mmcu=xxxx of the 'closest" AVR (you might have noticed that "AVR" has been divided up into 10 or so slightly different architectures (depending on width of PC, SP, presence of multiply, etc..), use compiler options to omit the standard startup code ("-nostartfiles" ?) and replace that with your own code (which need not be pre-compiled.)
If your program memory is writable, they you have additional options!

Go Up