This is the mail archive of the crossgcc@cygnus.com mailing list for the crossgcc project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
> > I've seen structures defined for devices with large register sets. Then > an instance of that structure is defined as extern for each device. > These go in a header file. > > eg. > typedef struct device > { > unsigned short reg1; > unsigned long reg2; > } > > extern device device1; > extern device device3; > extern device device2; > > The address of each device is then defined/set in a linker command file. > (eg. linkcmds). The symbols can also be set by linker flags/switches on > the CC or LD command. > > I think this will do what you want. I do not think this is a good idea at all. The compiler may put that structure packed or unpacked into memory, so this is highly compiler dependent. And then you start messing around with #pragma pack and all that nonsense. I have even seen this kind of code for network applications, for structures of data that is going to be sent via the interface... yak. Furthermore there should at least be a volatile, otherwise you may end up not reading the chips register but the copy in a CPU register. why not have something like: volatile const unsigned long *chip_base=(const unsigned char *)0x12345678; It is smart not to use int for long when accessing hardware - if you want your code to be portable :-). enum offsets { FIRST_REG, SECOND_REG, etc. }; and access by referencing chip_base[SECOND_REG] Problem here is that is you want to use the same definition in more than one C-File you have to create a header-file and a seperately linked C file for it, or make the pointer static. -- +-----------------+--------------------------------------------------+ | _____ | Rolf Fiedler | | / ___/ | Electronic Design Engineer | | / _/ | Ferrari electronic AG | | /_/e/r/r/a/r/i/ | phone: +49 3328 4559 0 fax: +49 3328 4559 60 | | electronic | E-Mail: Rolf.Fiedler@Ferrari.DE | +-----------------+--------------------------------------------------+ "Where do you want to go tomorrow?" _______________________________________________ New CrossGCC FAQ: http://www.objsw.com/CrossGCC _______________________________________________ To remove yourself from the crossgcc list, send mail to crossgcc-request@cygnus.com with the text 'unsubscribe' (without the quotes) in the body of the message.