0

i need to override the interrupt vector generated automatically from Atmel Studio. can anyone help me with this ?

Update with the interrupt code generated by the Atmel Studio.

00000000 <__vectors>:
   0:   0c 94 34 00     jmp 0x68    ; 0x68 <__ctors_end>
   4:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
   8:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
   c:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  10:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  14:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  18:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  1c:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  20:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  24:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  28:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  2c:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  30:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  34:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  38:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  3c:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  40:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  44:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  48:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  4c:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  50:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  54:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  58:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  5c:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  60:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>
  64:   0c 94 3e 00     jmp 0x7c    ; 0x7c <__bad_interrupt>

00000068 <__ctors_end>:
  68:   11 24           eor r1, r1
  6a:   1f be           out 0x3f, r1    ; 63
  6c:   cf ef           ldi r28, 0xFF   ; 255
  6e:   d8 e0           ldi r29, 0x08   ; 8
  70:   de bf           out 0x3e, r29   ; 62
  72:   cd bf           out 0x3d, r28   ; 61
  74:   0e 94 44 00     call    0x88    ; 0x88 <main>
  78:   0c 94 47 00     jmp 0x8e    ; 0x8e <_exit>

0000007c <__bad_interrupt>:
  7c:   0c 94 00 00     jmp 0   ; 0x0 <__vectors>

Update register interrupt

void (*fnVectors[NUM_INTERRUPTS])(void);

void IntRegister(unsigned int intrNum, void (*fnHandler)(void))
{
    /* Assign ISR */
    fnVectors[intrNum] = fnHandler;
}
Radu
  • 73
  • 1
  • 3
  • 10
  • what is the "interrupt vector generated automatically from Atmel Studio"??? – AterLux May 04 '18 at 12:59
  • Is generated from the assembly file gcrt1.S and i want to disable this. – Radu May 04 '18 at 13:08
  • Then, why not to change the file gcrt1.S in the corresponding way? – AterLux May 04 '18 at 13:09
  • Because i can't find the gcrt1.S file – Radu May 04 '18 at 13:11
  • It is just a startup code, which fills all unused interrupt entries in the interrupt table with default template. Just do `#include ` and write your own interrupt handler using `ISR(INTERRUPT_NAME_vect) { .... }` – AterLux May 04 '18 at 13:14
  • So let's start with the beginning. I want to make a function who receive a function address and the number of the interrupt and in the body i will give to a pointer to function the address of the function and i will load the interrupt vector with the context of my pointer to function vector. See my update number 2 – Radu May 04 '18 at 13:23
  • AVR interrupt vectors aren't normally stored in RAM. For instance, even though ATmega168 has two interrupt vector locations, both are in program memory (application or bootloader). You could of course have an ISR check a RAM variable to decide what to do. – Yann Vernier May 04 '18 at 13:28
  • Okey i understand but i want to disable the atmel studio assembly part before call main because i want to write the interrupt vector and name the interrupt routines how i want. – Radu May 04 '18 at 19:15
  • Not sure why you want to do that (you can only save a handful of words if you aren't using all the ISRs), but `-nostartfiles` should tell gcc to skip loading the crt startup file at all. You'll have to provide something suitable to put in the `.vectors` section, set up the stack, zero and status registers, et cetera. – Yann Vernier May 04 '18 at 20:44
  • okey so where i need to call the nostartfiles command, there is a command prompt in atmel ? – Radu May 05 '18 at 09:54

1 Answers1

1

These are linked using weak symbols in avr-libc; what you need is to declare your own ISRs using the ISR macro. See for instance the avr-libc interrupt documentation.

The actual source code for gcrt1.S uses a macro, which expands to a jump to symbols like __vector_4 and weakly defines that name equal to __bad_interrupt. If you define such routines (which the ISR macro helps you do), the weak definition is ignored. This same gcrt1.S file is assembled for each different MCU creating files such as crtatmega168.o. If you inspect one of those with avr-objdump -xd you'll find the weak references:

SYMBOL TABLE:
...
00000000  w      .init0 00000000 __init
00000000  w      .text  00000000 __vector_1
00000000 g       .text  00000000 __bad_interrupt
...
00000000 <__vectors>:
   0:   0c 94 00 00     jmp     0       ; 0x0 <__vectors>
                        0: R_AVR_CALL   __init
   4:   0c 94 00 00     jmp     0       ; 0x0 <__vectors>
                        4: R_AVR_CALL   __vector_1
Yann Vernier
  • 15,414
  • 2
  • 28
  • 26