HCS12 - How to make a read only absolute variable non initialized ?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

HCS12 - How to make a read only absolute variable non initialized ?

跳至解决方案
1,809 次查看
djsimpson
Contributor III

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

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,570 次查看
kef
Specialist I

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.

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,571 次查看
kef
Specialist I

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.

0 项奖励
回复
1,570 次查看
djsimpson
Contributor III

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

0 项奖励
回复
1,570 次查看
kef
Specialist I

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

1,570 次查看
djsimpson
Contributor III

The union seems works OK. I will give it try and see.

Only minor issue is remembering the variable has a trailing underscore in the debugger.

 

Thanks

David

 

0 项奖励
回复