Hi,
I have a read only register defined
volatile const unsigned short pitcnt0 @0x034a;
When I define the register as above, the linker creates an entry in hex file for that address, which is causing issues.
From the map file:
.abs_section_34a R 0x34A 0x34B .absSeg148
This generates data in the hex and abs, which I don't want.
A register not defined at const works ok:
volatile unsigned short pitld1 @0x034c;
The map file shows it as non initialized:
.abs_section_34c 2 N/I 0x34C 0x34D .absSeg149
I would like to define read only registers as const, to have the compile complain if I try to write to them. Any Ideas?
Thanks
David
已解决! 转到解答。
What about not using not portable C extension @, and define pitcnt0 like this
#define pitcnt0 (*(volatile const unsigned short *)0x34A)
If you need debugger visible variable for pitcnt0, then I think you need to define your own N/I segment for pitcnt0 in PRM file and allocate pitcnt0 in that segment. A lot of work for not very important result.
What about not using not portable C extension @, and define pitcnt0 like this
#define pitcnt0 (*(volatile const unsigned short *)0x34A)
If you need debugger visible variable for pitcnt0, then I think you need to define your own N/I segment for pitcnt0 in PRM file and allocate pitcnt0 in that segment. A lot of work for not very important result.
Thanks Kef.
I will try your suggestion, but it is nice to be able to view the variables in the debugger when needed.
My aim was to try to stop myself (and other engineers in my company) from making silly mistakes. This comes from experience where I spent considerable time staring at code not working because I confused variables in the PIT, and was writing to a read only register.
I figured if I defined the read only variables as const, then the compiler will flag my error before I even get to run my code. I did think about defining individual sections, but agree that did seem like too much effort.
David
You may use union or struct with const fields. Map file shows N/I for such struct and it should be visible in debugger.
union {const unsigned short data;} pitcnt0_ @ 0x34A;
#define pitcnt0 pitcnt0_.data