really24
asked on
Help with a #define line of code
Hi,
I found this when reading some C code. Can someone explain how to read this define statement in terms of Syntax?
#define[DEFINE_INTVEC(][,$ 1);][zdata at $0 struct INTVEC $1;]
Thanks!!
I found this when reading some C code. Can someone explain how to read this define statement in terms of Syntax?
#define[DEFINE_INTVEC(][,$
Thanks!!
That doesn't look like a valid C #define to me. Maybe there is another pre-compiler step that is executed after passing the code to the compiler ?
>> that is executed after passing the code to the compiler ?
that is executed *before* passing the code to the compiler
that is executed *before* passing the code to the compiler
Do you have a makefile ?
What is the context of this? The code you've posted isn't a valid C Preprocessor #define. Are you sure this code isn't meant to be pre-parsed, for instance by a Perl script?
That is not valid C syntax
/*Macro format looks like below */
#define <identifier> <Replacement token List>
#define <identifier>(<parameter list>) <replacement token list>
/* In your case it is not valid one */
ASKER
First of all, thanks for all the quick replies. Ok, I guess the consensus is that this is some strange syntax.
There is no other pre-parser or pre-pre processing that I know of.
Anyway, I think what is happening is that the the writer was trying to make some kind of macro or format so that later in the code they can write this kind of syntax in another header file. Notice the "at" keyword, which isn't a C Keyword at all.
zdata at 0xE400 volatile BYTE GPIF_WAVE_DATA[128];
using this
#define[DEFINE_INTVEC(][,$ 1);][zdata at $0 struct INTVEC $1;]
where DEFINE_INTVEC() is
#define[DEFINE_INTVEC(][,$ 1);][ .org $0
reti]
_asm
.area ABSCODE (ABS,CODE)
.org 0x0000
ENTRY:
ljmp #0x0200
INTVECS;
.org 0x01b8
INTVEC_DUMMY:
reti
.area CSEG (CODE)
_endasm;
Sorry, that my question turned out strange. The more I dig the stranger it is getting.
There is no other pre-parser or pre-pre processing that I know of.
Anyway, I think what is happening is that the the writer was trying to make some kind of macro or format so that later in the code they can write this kind of syntax in another header file. Notice the "at" keyword, which isn't a C Keyword at all.
zdata at 0xE400 volatile BYTE GPIF_WAVE_DATA[128];
using this
#define[DEFINE_INTVEC(][,$
where DEFINE_INTVEC() is
#define[DEFINE_INTVEC(][,$
reti]
_asm
.area ABSCODE (ABS,CODE)
.org 0x0000
ENTRY:
ljmp #0x0200
INTVECS;
.org 0x01b8
INTVEC_DUMMY:
reti
.area CSEG (CODE)
_endasm;
Sorry, that my question turned out strange. The more I dig the stranger it is getting.
ASKER
Then can you not use square brackets in a #define macro?
By the way this code is compiled with SDCC for an 8051 based processor.
By the way this code is compiled with SDCC for an 8051 based processor.
Maybe you could show us all the code as, often, context does help make things a lot clearer?
It could be an assembly language macro
ASKER
/*!
ZTEX Firmware Kit for EZ-USB Microcontrollers
Copyright (C) 2009-2010 ZTEX e.K.
http://www.ztex.de
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see http://www.gnu.org/licenses/.
!*/
/*
EZ-USB Autovectors
*/
#ifndef[EZINTAVECS_H]
#define[EZINTAVECS_H]
#include[ztex-utils.h]
struct INTVEC {
BYTE op;
BYTE addrH;
BYTE addrL;
};
#define[INTVECS;][DEFINE_I NTVEC(0x00 03,INT0VEC _IE0);
DEFINE_INTVEC(0x000b,INT1V EC_T0);
DEFINE_INTVEC(0x0013,INT2V EC_IE1);
DEFINE_INTVEC(0x001b,INT3V EC_T1);
DEFINE_INTVEC(0x0023,INT4V EC_USART0) ;
DEFINE_INTVEC(0x002b,INT5V EC_T2);
DEFINE_INTVEC(0x0033,INT6V EC_RESUME) ;
DEFINE_INTVEC(0x003b,INT7V EC_USART1) ;
DEFINE_INTVEC(0x0043,INT8V EC_USB);
DEFINE_INTVEC(0x004b,INT9V EC_I2C);
DEFINE_INTVEC(0x0053,INT10 VEC_GPIF);
DEFINE_INTVEC(0x005b,INT11 VEC_IE5);
DEFINE_INTVEC(0x0063,INT12 VEC_IE6);
DEFINE_INTVEC(0x0100,INTVE C_SUDAV);
DEFINE_INTVEC(0x0104,INTVE C_SOF);
DEFINE_INTVEC(0x0108,INTVE C_SUTOK);
DEFINE_INTVEC(0x010C,INTVE C_SUSPEND) ;
DEFINE_INTVEC(0x0110,INTVE C_USBRESET );
DEFINE_INTVEC(0x0114,INTVE C_HISPEED) ;
DEFINE_INTVEC(0x0118,INTVE C_EP0ACK);
DEFINE_INTVEC(0x0120,INTVE C_EP0IN);
DEFINE_INTVEC(0x0124,INTVE C_EP0OUT);
DEFINE_INTVEC(0x0128,INTVE C_EP1IN);
DEFINE_INTVEC(0x012C,INTVE C_EP1OUT);
DEFINE_INTVEC(0x0130,INTVE C_EP2);
DEFINE_INTVEC(0x0134,INTVE C_EP4);
DEFINE_INTVEC(0x0138,INTVE C_EP6);
DEFINE_INTVEC(0x013C,INTVE C_EP8);
DEFINE_INTVEC(0x0140,INTVE C_IBN);
DEFINE_INTVEC(0x0148,INTVE C_EP0PING) ;
DEFINE_INTVEC(0x014C,INTVE C_EP1PING) ;
DEFINE_INTVEC(0x0150,INTVE C_EP2PING) ;
DEFINE_INTVEC(0x0154,INTVE C_EP4PING) ;
DEFINE_INTVEC(0x0158,INTVE C_EP6PING) ;
DEFINE_INTVEC(0x015C,INTVE C_EP8PING) ;
DEFINE_INTVEC(0x0160,INTVE C_ERRLIMIT );
DEFINE_INTVEC(0x0170,INTVE C_EP2ISOER R);
DEFINE_INTVEC(0x0174,INTVE C_EP4ISOER R);
DEFINE_INTVEC(0x0178,INTVE C_EP6ISOER R);
DEFINE_INTVEC(0x017C,INTVE C_EP8ISOER R);
DEFINE_INTVEC(0x0180,INTVE C_EP2PF);
DEFINE_INTVEC(0x0184,INTVE C_EP4PF);
DEFINE_INTVEC(0x0188,INTVE C_EP6PF);
DEFINE_INTVEC(0x018C,INTVE C_EP8PF);
DEFINE_INTVEC(0x0190,INTVE C_EP2EF);
DEFINE_INTVEC(0x0194,INTVE C_EP4EF);
DEFINE_INTVEC(0x0198,INTVE C_EP6EF);
DEFINE_INTVEC(0x019C,INTVE C_EP8EF);
DEFINE_INTVEC(0x01A0,INTVE C_EP2FF);
DEFINE_INTVEC(0x01A8,INTVE C_EP6FF);
DEFINE_INTVEC(0x01AC,INTVE C_EP8FF);
DEFINE_INTVEC(0x01B0,INTVE C_GPIFDONE );
DEFINE_INTVEC(0x01B4,INTVE C_GPIFWF); ]
#define[DEFINE_INTVEC(][,$ 1);][zdata at $0 struct INTVEC $1;]
INTVECS;
#udefine[DEFINE_INTVEC(]
void abscode_intvec() _naked
{
#define[DEFINE_INTVEC(][,$ 1);][ .org $0
reti]
_asm
.area ABSCODE (ABS,CODE)
.org 0x0000
ENTRY:
ljmp #0x0200
INTVECS;
.org 0x01b8
INTVEC_DUMMY:
reti
.area CSEG (CODE)
_endasm;
}
#udefine[INTVECS;]
#udefine[DEFINE_INTVEC(]
/* Init an interrupt vector */
#define[INIT_INTERRUPT_VEC TOR(][,$1) ;][{
$0.op=0x02;
$0.addrH=((unsigned short)(&$1)) >> 8;
$0.addrL=(unsigned short)(&$1);
}]
/* Enable USB autovectors */
#define[ENABLE_AVUSB;][{
INT8VEC_USB.op=0x02;
INT8VEC_USB.addrH = 0x01;
INT8VEC_USB.addrL = 0xb8;
INTSETUP |= 8;
}]
/* Disable USB autovectors */
#define[DISABLE_AVUSB;][IN TSETUP &= ~8;]
/* Enable GPIF autovectors */
#define[ENABLE_AVGPIF;][{
INT10VEC_GPIF.op=0x02;
INT10VEC_GPIF.addrH = 0x01;
INT10VEC_GPIF.addrL = 0xb8;
INTSETUP |= 3;
}]
/* Disable GPIF autovectors */
#define[DISABLE_AVPGIF;][I NTSETUP &= ~3;]
#endif /* INTAVECS_H */
ZTEX Firmware Kit for EZ-USB Microcontrollers
Copyright (C) 2009-2010 ZTEX e.K.
http://www.ztex.de
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see http://www.gnu.org/licenses/.
!*/
/*
EZ-USB Autovectors
*/
#ifndef[EZINTAVECS_H]
#define[EZINTAVECS_H]
#include[ztex-utils.h]
struct INTVEC {
BYTE op;
BYTE addrH;
BYTE addrL;
};
#define[INTVECS;][DEFINE_I
DEFINE_INTVEC(0x000b,INT1V
DEFINE_INTVEC(0x0013,INT2V
DEFINE_INTVEC(0x001b,INT3V
DEFINE_INTVEC(0x0023,INT4V
DEFINE_INTVEC(0x002b,INT5V
DEFINE_INTVEC(0x0033,INT6V
DEFINE_INTVEC(0x003b,INT7V
DEFINE_INTVEC(0x0043,INT8V
DEFINE_INTVEC(0x004b,INT9V
DEFINE_INTVEC(0x0053,INT10
DEFINE_INTVEC(0x005b,INT11
DEFINE_INTVEC(0x0063,INT12
DEFINE_INTVEC(0x0100,INTVE
DEFINE_INTVEC(0x0104,INTVE
DEFINE_INTVEC(0x0108,INTVE
DEFINE_INTVEC(0x010C,INTVE
DEFINE_INTVEC(0x0110,INTVE
DEFINE_INTVEC(0x0114,INTVE
DEFINE_INTVEC(0x0118,INTVE
DEFINE_INTVEC(0x0120,INTVE
DEFINE_INTVEC(0x0124,INTVE
DEFINE_INTVEC(0x0128,INTVE
DEFINE_INTVEC(0x012C,INTVE
DEFINE_INTVEC(0x0130,INTVE
DEFINE_INTVEC(0x0134,INTVE
DEFINE_INTVEC(0x0138,INTVE
DEFINE_INTVEC(0x013C,INTVE
DEFINE_INTVEC(0x0140,INTVE
DEFINE_INTVEC(0x0148,INTVE
DEFINE_INTVEC(0x014C,INTVE
DEFINE_INTVEC(0x0150,INTVE
DEFINE_INTVEC(0x0154,INTVE
DEFINE_INTVEC(0x0158,INTVE
DEFINE_INTVEC(0x015C,INTVE
DEFINE_INTVEC(0x0160,INTVE
DEFINE_INTVEC(0x0170,INTVE
DEFINE_INTVEC(0x0174,INTVE
DEFINE_INTVEC(0x0178,INTVE
DEFINE_INTVEC(0x017C,INTVE
DEFINE_INTVEC(0x0180,INTVE
DEFINE_INTVEC(0x0184,INTVE
DEFINE_INTVEC(0x0188,INTVE
DEFINE_INTVEC(0x018C,INTVE
DEFINE_INTVEC(0x0190,INTVE
DEFINE_INTVEC(0x0194,INTVE
DEFINE_INTVEC(0x0198,INTVE
DEFINE_INTVEC(0x019C,INTVE
DEFINE_INTVEC(0x01A0,INTVE
DEFINE_INTVEC(0x01A8,INTVE
DEFINE_INTVEC(0x01AC,INTVE
DEFINE_INTVEC(0x01B0,INTVE
DEFINE_INTVEC(0x01B4,INTVE
#define[DEFINE_INTVEC(][,$
INTVECS;
#udefine[DEFINE_INTVEC(]
void abscode_intvec() _naked
{
#define[DEFINE_INTVEC(][,$
reti]
_asm
.area ABSCODE (ABS,CODE)
.org 0x0000
ENTRY:
ljmp #0x0200
INTVECS;
.org 0x01b8
INTVEC_DUMMY:
reti
.area CSEG (CODE)
_endasm;
}
#udefine[INTVECS;]
#udefine[DEFINE_INTVEC(]
/* Init an interrupt vector */
#define[INIT_INTERRUPT_VEC
$0.op=0x02;
$0.addrH=((unsigned short)(&$1)) >> 8;
$0.addrL=(unsigned short)(&$1);
}]
/* Enable USB autovectors */
#define[ENABLE_AVUSB;][{
INT8VEC_USB.op=0x02;
INT8VEC_USB.addrH = 0x01;
INT8VEC_USB.addrL = 0xb8;
INTSETUP |= 8;
}]
/* Disable USB autovectors */
#define[DISABLE_AVUSB;][IN
/* Enable GPIF autovectors */
#define[ENABLE_AVGPIF;][{
INT10VEC_GPIF.op=0x02;
INT10VEC_GPIF.addrH = 0x01;
INT10VEC_GPIF.addrL = 0xb8;
INTSETUP |= 3;
}]
/* Disable GPIF autovectors */
#define[DISABLE_AVPGIF;][I
#endif /* INTAVECS_H */
ASKER
My main point is just to understand using the #define syntax in a deeper way and understanding macros. It just seemed like interesting syntax.
That's why I asked.
That's why I asked.
Hi really24,
unfortunateley you didn't answer 'Infinity08's question: Do you have a makefile? If so could you post it's content?
ZOPPO
unfortunateley you didn't answer 'Infinity08's question: Do you have a makefile? If so could you post it's content?
ZOPPO
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help! I really feel silly now. I guess I just wasn't paying attention.