// LPC11xx.h
// General Purpose Input/Output (GPIO)
typedef struct
{
...
__IO uint32_t DATA;
...
__IO uint32_t DIR;
...
} LPC_GPIO_TypeDef;
// Peripheral memory map
#define LPC_FLASH_BASE (0x00000000UL)
#define LPC_RAM_BASE (0x10000000UL)
#define LPC_APB0_BASE (0x40000000UL)
#define LPC_AHB_BASE (0x50000000UL)
// APB0 peripherals
...
// AHB peripherals
#define LPC_GPIO_BASE (LPC_AHB_BASE + 0x00000)
#define LPC_GPIO0_BASE (LPC_AHB_BASE + 0x00000)
#define LPC_GPIO1_BASE (LPC_AHB_BASE + 0x10000)
#define LPC_GPIO2_BASE (LPC_AHB_BASE + 0x20000)
#define LPC_GPIO3_BASE (LPC_AHB_BASE + 0x30000)
Peripheral declaration
#define LPC_GPIO0 ((LPC_GPIO_TypeDef *) LPC_GPIO0_BASE )
#define LPC_GPIO1 ((LPC_GPIO_TypeDef *) LPC_GPIO1_BASE )
#define LPC_GPIO2 ((LPC_GPIO_TypeDef *) LPC_GPIO2_BASE )
#define LPC_GPIO3 ((LPC_GPIO_TypeDef *) LPC_GPIO3_BASE )
.END
Now let me think aloud.
1. LPC_GPIO_TypeDef is the type of a struct as defined.
2. #define LPC_GPIO0 is expanded as below.
LPC_GPIO_TypeDef *LPC_GPIO0_BASE
So similar to the declaration
int *p
where p is a pointer to an integer,
LPC_GPIO0_BASE is a pointer to a LPC_GPIO_TypeDef structure.
But now I know I am very wrong. LPC_GPIO_TypeDef *LPC_GPIO0_BASE is not a structure variable declaration.
The * is a derefencing operator here.
In other words, LPC_GPIO_TypeDef *LPC_GPIO0_BASE means LPC_GPIO0 is the structure object at address LPC_GPIO0_BASE.
The LPC_GPIO_TypeDef prefix might be used as shortcut thing as described in the wikipedia.
Then I understand why I can use the following statement.
LPC_GPIO1->DATA &= ~(1 << pinNumber);
Here LPC_GPIO1 is the structure object, then of course the member can be assessed like LPC_GPIO1->DATA.
Now if I would like to pass pointer of the structure object LPC_GPIO1 as a function parameter, then the pointer should be
&LPC_GPIO1
This is indeed confusing. I am only 80% sure that I am thinking correctly.
.END
No comments:
Post a Comment