EmbeddedRelated.com
Forums

gnu arm - lpc register definitions

Started by klemen_dovrtel November 5, 2006
--- In l..., "klemen_dovrtel"
wrote:
>
> But i still don't know if this register definition are correct.
> Shouldn't be there another REG_8 _pad0[3]; after the REG_8 feed;?
> Isn't the WDTV pointing at wrong adress (0x0xE000 0009)?
>
> // lpcWD.h
> // Watchdog Registers
> typedef struct
> {
> REG_8 mod; // Watchdog Mode Register
> REG_8 _pad0[3];
> REG32 tc; // Watchdog Time Constant Register
> REG_8 feed; // Watchdog Feed Register
> REG32 tv; // Watchdog Time Value Register
> } wdRegs_t;
>
> //lpc21xx.h
> #define WD ((wdRegs_t *)0xE0000000)
> // Watchdog Registers
> #define WDMOD WD->mod /* Watchdog Mode Register */
> #define WDTC WD->tc /* Watchdog Time Constant
> Register */
> #define WDFEED WD->feed /* Watchdog Feed Register */
> #define WDTV WD->tv /* Watchdog Time Value Register */
>

The short answer is that nobody can answer your question ("is the
definition correct?"), as it's entirely dependent on what compiler
you're using.

That's why I recommended not using structs to map onto hardware.

If you insist on doing this, you'll have to either read the
compiler's documentation and/or experiment to see what it's doing
and then play around with packing to get it to work as expected.

Brendan.

An Engineer's Guide to the LPC2100 Series

klemen_dovrtel wrote:
> But i still don't know if this register definition are correct.
> Shouldn't be there another REG_8 _pad0[3]; after the REG_8 feed;?
> Isn't the WDTV pointing at wrong adress (0x0xE000 0009)?
>
> // lpcWD.h
> // Watchdog Registers
> typedef struct
> {
> REG_8 mod; // Watchdog Mode Register
> REG_8 _pad0[3];
> REG32 tc; // Watchdog Time Constant Register
> REG_8 feed; // Watchdog Feed Register
> REG32 tv; // Watchdog Time Value Register
> } wdRegs_t;
>
> //lpc21xx.h
> #define WD ((wdRegs_t *)0xE0000000)
> // Watchdog Registers
> #define WDMOD WD->mod /* Watchdog Mode Register */
> #define WDTC WD->tc /* Watchdog Time Constant
> Register */
> #define WDFEED WD->feed /* Watchdog Feed Register */
> #define WDTV WD->tv /* Watchdog Time Value Register */

Yes there should be, but should probably be called _pad1[3]. However as
pointed out in other replies, the code will probably work as is unless
the struct is marked as 'packed'.

-Bill Knight
R O SoftWare &
http://www.theARMPatch.com