cancel
Showing results for 
Search instead for 
Did you mean: 

Pointer Arithmetic

md21028
Associate II
Posted on September 07, 2005 at 04:40

Pointer Arithmetic

9 REPLIES 9
md21028
Associate II
Posted on January 12, 2005 at 09:53

I am trying to perform an IAP function. I am able to erase and program the micro without problem. My problem, however, is when the new code is programmed....the interrupt vectors do not line up. I am now creating a double jump table to alleviate this. I created a table at 0x1000 that contains a jump command and the interrupt addresses. It looks something like this:

#pragma section (Table1)

void table1()

{

#asm

jp _interrupt1 //fist interrupt

jp _interrupt2 //second interrupt

....etc.

#endasm

}

#pragma end

The second table looks like this:

void (* const _vectab[])() = {

table1,

table1 + 3,

etc....

}

When I compile this with just table1 in the second table it works. I can see that address 0x1000 is at 0xFFE0. However, when I insert the second line (table1 + 3) I get an error in the compiler: size unknown. Am I missing something here, or is this simple pointer arithmetic? Also, another note to mention, I tried typecasting the table1 + 3 and that didn't compile either. Any suggestions? TIA.

wolfgang2399
Associate II
Posted on January 12, 2005 at 11:00

Hi,

the HiWare Compiler removes any unused address that is not called by any part of the program.

Try to add _vectab under ENTRIES to your .prm-file

I post here my .prm-file (e.g. LITE29.prm) for example :

--------------------------------------------------------

NAMES END

SECTIONS

ZRAM = READ_WRITE 0x0080 TO 0x00FF;

MYSTACK = READ_WRITE 0x0180 TO 0x01FF;

RAM_1 = READ_WRITE 0x0100 TO 0x017F;

ROM = READ_ONLY 0xE000 TO 0xFFDF;

EERCCR = READ_WRITE 0x1000 TO 0x1001;

EEPROM = READ_WRITE 0x1002 TO 0x107F;

IRVECTOR = READ_ONLY 0xFFE0 TO 0xFFFF;

C_REGS = READ_WRITE 0x0000 TO 0x007F;

PLACEMENT

REG_SEG INTO C_REGS;

PROJECT_CONST INTO ROM;

DEFAULT_ROM, ROM_VAR, STRINGS INTO ROM;

DEFAULT_RAM INTO RAM_1;

RAM1 INTO RAM_1;

RAM2 INTO RAM_1;

BSCT INTO ZRAM;

_ZEROPAGE, _OVERLAP INTO ZRAM;

SSTACK INTO MYSTACK;

EE_RCCR INTO EERCCR;

EE_PROM INTO EEPROM;

IR_VECTOR INTO IRVECTOR;

END

ENTRIES

_vectabs

_TIME

END

--------------------------------------------------------

Does it help ??

Regards WoRo

md21028
Associate II
Posted on January 12, 2005 at 11:13

Sorry, I forgot to specify...Cosmic compiler

Other details:

ST72F521

InDart ST7 debugger

luca239955_st
Associate III
Posted on January 12, 2005 at 12:49

Hi,

the pointer arithmetic you are trying to apply will not work, because, in the expression (table1+3), the number 3 in interpreted as ''3 times the size of table1'', which is unknown. See section 4.8 in the document clanguage.pdf that comes with your compiler for more details.

There would be a solution for what you want to do, but it is quite complex and I'm not sure you actually need it; why do you want to ''indirect'' the call of interrupt functions if the indirection (table1) is done with constants anyway? To me it looks like you are only slowing down the interrupt response, but probably there is something I haven't understood...

Regards,

Luca (Cosmic)

md21028
Associate II
Posted on January 12, 2005 at 13:05

Thanks for the response, I now understand why it won't work. I still need a solution however.

To answer your question as to why I would use this indirection table (table1), the table is not filled with constants. The table is filled with the interrupt service routine address. The compiler comes up with these addresses and I want to be sure that when I am loading new code into sectors 1 and 2 the interrupt vectors for the newly loaded software are aligned with the vectors in sector 0.

luca239955_st
Associate III
Posted on January 12, 2005 at 17:56

Hi again,

after checking with the collegues there is a solution that is not so complex; you must trick the compiler into believing that table1 is not a function but a char (whose size is known and equal to 1), like this:

extern char Table1[];

char * const _vectab[] = {

Table1,

Table1 + 3,

Table1 + 6,

....

}

this should work.

Regards,

Luca

PS: another solution might be declaring the interrupt functions at absolute addresses... but maybe less flexible... just a thougth.

md21028
Associate II
Posted on January 12, 2005 at 19:47

Hmm, I think we are getting closer. We aren't there yet though. When I try to compile this I get the following errors:

symbol _irq_rtc not defined

symbol _irq_trap not defined

...etc...etc...

I don't understand how these are not defined. By the way, there is a funciton header for each that is an extern.

extern void irq_trap();

extern void irq_sci();

extern void irq_rtc();

#pragma section(INT_JMP)

char INT_jump_table()

{

#asm

jp _irq_trap // PWM ART

jp _irq_sci // SCI

jp _irq_rtc // MCC/RTC

#endasm

}

#pragma END

char (* const _vectab[])() = {

INT_jump_table, /* PWM ART */

// INT_jump_table + 3, /* IIC */

NULL, /* TRAP */

_stext, /* RESET */

};

Another question: In the vectab above ''NULL'' is defined above with the following command:

#define NULL 0

If I change the initializer to anything other than 0 the program will not compile. Any idea why not? If I could get this to work I could hard code the specific address into vectab.

md21028
Associate II
Posted on January 13, 2005 at 14:17

Just thought I would let everyone interested know that I solved my problem. I will document it and post it later today....if anyone is interested.

[ This message was edited by: drew1296 on 13-01-2005 18:47 ]

christiangaertner9
Associate II
Posted on September 07, 2005 at 04:40

Hello,

can you please post your solution. I am working at the same problem

Regards,

Christian