vector table

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I have written a C program using GCC for the ATtiny24V, and all is working well... however I haven't personally defined the RESET or WATCHDOG vectors.

//ISR(RESET_vect)
//ISR(INT0_vect)
//ISR(PCINT0_vect)
//ISR(PCINT1_vect )
//ISR(WDT_vect)
//ISR(TIM1_CAPT_vect)

ISR(TIM1_COMPA_vect) {}

//ISR(TIM1_COMPB_vect)
//ISR(TIM1_OVF_vect)

ISR(TIM0_COMPA_vect) {}

//ISR(TIM0_COMPB_vect)
//ISR(TIM0_OVF_vect)
//ISR(ANA_COMP_vect)
//ISR(ADC_vect)
//ISR(EE_RDY_vect)
//ISR(USI_STR_vect)
//ISR(USI_OVF_vect)

I have put in dummy vectors for the timers 0/1 on compare (as above).

How do I define the other vectors ? Something like :

ISR(RESET_vect) { jmp main }
ISR(WDT_vect) { jmp main }

What's the normal (best) practice ? What would you do ?

All the best

Dren

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why do you do that? This is normally handled by the gcrt0.S file. There is no need to define all ISRs and all other vectors. Especially the reset vector is doing a lot more than calling main.
Please explain your idea why you want to make this table.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The vector table is already taken care of by the c runtime object file that automatically links into your compiled code. The ISR macro is to define a function as an interrupt function, and the ISR 'friendly' name will end up being converted to an actual name that the vector table uses (to jmp to). The ISR macro has nothing to do with the vector table (except for the isr name- which 'connects' the two together via a jmp).

You don't have to define an ISR that is not used. The vector table handles that, too.

In your project, enable creating the lss file, then compile and view the lss file. The vector table is there.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't just want to make this table for fun, there are strict coding standards I have to design to, (and I agree with them in this case). One of the quality/testing issues is a known starting point, and I can't just say oh it runs 'main()'. I need to be able to show the reset and watchdog vectors.

I want to know what they are and have them all defined so that they are 'safe'... good coding practice and all that. I mean what sort of p1ss poor micro/compiler doesn't have a proper fully defined vector table ? So it saves (at most) 34 bytes of space ? That is not worth having potentially dangerous undefined vectors in code, it's OK for a hobbiest, but not acceptable in most industries - grrr OK, rant over !

What else is RESET doing other than jumping to main ? I need to know these sort of things, or I'll have to decompile the hex files... arrgh !

Basically if I can't clearly show them, the easiest solution would be to define the entire vector table...

What is regarded as the 'best' practice ? What do other professional engineers do in this situation ?

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks curtvm, I am so glad to see that vector table and that it seems to handle 'bad vectors' by jumping to the start of the table and resetting :)

How do I define that the watchdog vector jumps to the reset vector ? At the moment it jumps to 'bad_vector' which then jumps to the start of the table - so all is 'well' but I would like to actually define it.

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not on this project (luckily) but for interest how would I cause a full reset after a watchdog interrupt ?

To clarify, if I have a function:

ISR(WDT_vect)
{
(do something here )
(then "reset")
}

How do I get it to jump to the reset vector ?

Thanks for all your help so far

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are 3 modes for the watchdog- 'normal' watchdog function (does a hardware reset like any other reset), interrupt mode (just fires the irq only), and interrupt + reset (first time is interrupt, then WDIE clears and is now in reset only mode unless you set WDIE again).

If you are using interrupt mode, and want to reset inside the irq code, just change to reset mode, and let it time out with a while(1); loop. If in irq + reset mode, just need the while(1); loop (unless you need to shorten the timer so it resets sooner). If in reset mode only, you never get to the irq, so then it will be not needed.

Grab a mega88 datasheet, it explains the watchdog a bit better than the tiny24 datasheet.

Also keep in mind any time the watchdog does a reset, the WDRF flag will be set, and since WDRF overrides WDE, the watchdog will be enabled after a watchdog reset with the default timeout of 16ms. Either clear WDRF, then disable the watchdog early in your app, or if using the watchdog simply set the watchdog to whatever you need.

Last Edited: Tue. Nov 11, 2008 - 06:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Excellent !

Thanks for your help - that's exactly what I needed to know.

I'm sure everything will be OK to pass scrutiny now...

2nd Atmel project done !

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

What else is RESET doing other than jumping to main ? I need to know these sort of things, or I'll have to decompile the hex files

No you dont. the startup code is in avr-libc and
Quote:
AVR Libc is licensed under a single unified license. This so-called modified Berkeley license is intented to be compatible with most Free Software licenses like the GPL, yet impose as little restrictions for the use of the library in closed-source commercial applications as possible.

http://www.nongnu.org/avr-libc/

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To learn more about what happens after reset, read the Memory Sections part of the Avr-libc manual here.

Stu

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dren wrote:
I am so glad to see that vector table and that it seems to handle 'bad vectors' by jumping to the start of the table and resetting
The documentation clearly describes how you can specify your own default ISR for all vectors not otherwise specified. See section 6.15 of the avr-libc documentation.

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net