Errors with macros

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

I'm having these errors...:

expected declaration specifiers or '...' before numeric constant

...on every line.

This is the header file IntHandler.h

 

#ifndef INTHANDLER_H_
#define INTHANDLER_H_

#define INTERRUPT_HANDLER(vect) \
	EMPTY_INTERRUPT(vect) \
	{ \
		asm("jmp 0x8000+vect"); \
	}


#endif /* INTHANDLER_H_ */

And this is the IntHandler.c c file

#include "IntHandler.h"

INTERRUPT_HANDLER(2)
INTERRUPT_HANDLER(4)
INTERRUPT_HANDLER(6)
INTERRUPT_HANDLER(8)
INTERRUPT_HANDLER(10)
INTERRUPT_HANDLER(12)
INTERRUPT_HANDLER(14)
INTERRUPT_HANDLER(16)
INTERRUPT_HANDLER(18)
INTERRUPT_HANDLER(20)
INTERRUPT_HANDLER(22)
INTERRUPT_HANDLER(24)
INTERRUPT_HANDLER(26)
INTERRUPT_HANDLER(28)
INTERRUPT_HANDLER(30)
INTERRUPT_HANDLER(32)
INTERRUPT_HANDLER(34)
INTERRUPT_HANDLER(36)
INTERRUPT_HANDLER(38)
INTERRUPT_HANDLER(40)
INTERRUPT_HANDLER(42)
INTERRUPT_HANDLER(44)
INTERRUPT_HANDLER(46)
INTERRUPT_HANDLER(48)
INTERRUPT_HANDLER(50)
INTERRUPT_HANDLER(52)
INTERRUPT_HANDLER(54)
INTERRUPT_HANDLER(56)
INTERRUPT_HANDLER(58)
INTERRUPT_HANDLER(60)
INTERRUPT_HANDLER(62)
INTERRUPT_HANDLER(64)
INTERRUPT_HANDLER(66)
INTERRUPT_HANDLER(68)
INTERRUPT_HANDLER(70)
INTERRUPT_HANDLER(72)
INTERRUPT_HANDLER(74)
INTERRUPT_HANDLER(76)
INTERRUPT_HANDLER(78)
INTERRUPT_HANDLER(80)
INTERRUPT_HANDLER(82)
INTERRUPT_HANDLER(84)
INTERRUPT_HANDLER(86)
INTERRUPT_HANDLER(88)
INTERRUPT_HANDLER(90)
INTERRUPT_HANDLER(92)
INTERRUPT_HANDLER(94)
INTERRUPT_HANDLER(96)
INTERRUPT_HANDLER(98)
INTERRUPT_HANDLER(100)
INTERRUPT_HANDLER(102)
INTERRUPT_HANDLER(104)
INTERRUPT_HANDLER(106)
INTERRUPT_HANDLER(108)
INTERRUPT_HANDLER(110)
INTERRUPT_HANDLER(112)
INTERRUPT_HANDLER(114)
INTERRUPT_HANDLER(116)
INTERRUPT_HANDLER(118)
INTERRUPT_HANDLER(120)
INTERRUPT_HANDLER(122)
INTERRUPT_HANDLER(124)
INTERRUPT_HANDLER(126)
INTERRUPT_HANDLER(128)
INTERRUPT_HANDLER(130)
INTERRUPT_HANDLER(132)
INTERRUPT_HANDLER(134)
INTERRUPT_HANDLER(136)
INTERRUPT_HANDLER(138)
INTERRUPT_HANDLER(140)
INTERRUPT_HANDLER(142)
INTERRUPT_HANDLER(144)
INTERRUPT_HANDLER(146)
INTERRUPT_HANDLER(148)
INTERRUPT_HANDLER(150)
INTERRUPT_HANDLER(152)
INTERRUPT_HANDLER(154)
INTERRUPT_HANDLER(156)
INTERRUPT_HANDLER(158)
INTERRUPT_HANDLER(160)
INTERRUPT_HANDLER(162)
INTERRUPT_HANDLER(164)
INTERRUPT_HANDLER(166)
INTERRUPT_HANDLER(168)
INTERRUPT_HANDLER(170)
INTERRUPT_HANDLER(172)
INTERRUPT_HANDLER(174)
INTERRUPT_HANDLER(176)
INTERRUPT_HANDLER(178)
INTERRUPT_HANDLER(180)
INTERRUPT_HANDLER(182)
INTERRUPT_HANDLER(184)
INTERRUPT_HANDLER(186)
INTERRUPT_HANDLER(188)
INTERRUPT_HANDLER(190)
INTERRUPT_HANDLER(192)
INTERRUPT_HANDLER(194)
INTERRUPT_HANDLER(196)
INTERRUPT_HANDLER(198)
INTERRUPT_HANDLER(200)
INTERRUPT_HANDLER(202)
INTERRUPT_HANDLER(204)
INTERRUPT_HANDLER(206)
INTERRUPT_HANDLER(208)
INTERRUPT_HANDLER(210)
INTERRUPT_HANDLER(212)
INTERRUPT_HANDLER(214)
INTERRUPT_HANDLER(216)
INTERRUPT_HANDLER(218)
INTERRUPT_HANDLER(220)
INTERRUPT_HANDLER(222)
INTERRUPT_HANDLER(224)
INTERRUPT_HANDLER(226)
INTERRUPT_HANDLER(228)
INTERRUPT_HANDLER(230)
INTERRUPT_HANDLER(232)
INTERRUPT_HANDLER(234)
INTERRUPT_HANDLER(236)
INTERRUPT_HANDLER(238)
INTERRUPT_HANDLER(240)
INTERRUPT_HANDLER(242)
INTERRUPT_HANDLER(244)
INTERRUPT_HANDLER(246)
INTERRUPT_HANDLER(248)

Basically what I want to do is make each unused interrupt jump on the vector table located at 0x8000. So this...:

EMPTY_INTERRUPT(PORTC_INT0_vect)
{
    asm("jmp 0x8000+PORTC_INT0_vect");
}

...will become this:

ISR(PORTC_INT0_vect)
{
    asm("jump 0x8004");
}

But I have no space and time to do that for each unused interrupt!

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

I've never had to do anything fancy with interrupt handlers like that before, but I would try something like this:

#define STRING2(x) #x
#define STRING(x) STRING2(x)

#define INTERRUPT_HANDLER(vect) \
    ISR(vect) \
    { \
        asm("jmp 0x8000+" STRING(vect)); \
    }

INTERRUPT_HANDLER(PORTC_INT0_vect)

That will "stringize" the C vector name into a vector name that the assembler recognizes:

    jmp 0x8000+__vector_2

You probably also need to specify a "naked" ISR so there's no C prologue code added:

#define INTERRUPT_HANDLER(vect) \
    ISR(vect, ISR_NAKED) \
    { \
        asm("jmp 0x8000+" STRING(vect)); \
    }

 

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

Oof oof ooofff!!! Errors!

expected identifier or '(' before numeric constant in IntHandler.c

C file has these

INTERRUPT_HANDLER(2)
INTERRUPT_HANDLER(4)
INTERRUPT_HANDLER(6)
INTERRUPT_HANDLER(8)

And the header file is

#ifndef INTHANDLER_H_
#define INTHANDLER_H_
#include <avr/interrupt.h>

#define STRING2(x) #x
#define STRING(x) STRING2(x)

#define INTERRUPT_HANDLER(vect) \
ISR(vect, ISR_NAKED) \
{ \
	asm("jmp 0x8000+" STRING(vect)); \
}

#endif /* INTHANDLER_H_ */

 

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

This may work better with numeric interrupt numbers:

#define INTERRUPT_HANDLER(n) \
    ISR(_VECTOR(n), ISR_NAKED) \
    { \
        asm("jmp 0x8000+" STRING(2*n)); \
    }

I'm not entirely sure if it should be n or 2*n (or even 4*n) inside the STRING() to account for byte vs word addresses (and it looks like you're using even numbers for the vector numbers), so good luck figuring out those details! :)

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

No need to stringify:

#define INTERRUPT_HANDLER(n) \
ISR(_VECTOR(n), ISR_NAKED) \
{ \
	asm("jmp 0x8000+%[v]" :: [v] "M" (n) ); \
}

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

joeymorin wrote:

No need to stringify:

#define INTERRUPT_HANDLER(n) \
ISR(_VECTOR(n), ISR_NAKED) \
{ \
	asm("jmp 0x8000+%[v]" :: [v] "M" (n) ); \
}

 

Can you explain what this +%[v] :: [v] "M" (n) means?

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

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Foxcat385 wrote:
I have no space (sic?) and time to do that for each unused interrupt!

I don't see how you can save any space doing this at all?!

 

As to saving time, it isn't actually that hard to just do this long-hand in a text editor (or Excel) - if you lay the text out suitably, and know how to use your editor's column editing features:

 

ISR(PORTC_INT0_vect){    asm("jump 0x8000 + PORTC_INT0_vect"); }
ISR(PORTC_INT1_vect){    asm("jump 0x8000 + PORTC_INT1_vect"); }
This also has the advantage that your debugger won't be confused by it - it will be able to find the source lines for the vectors!

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...