Content originally posted in LPCWare by fjrg76 on Thu Nov 03 23:06:11 MST 2011
Quote: Skashkash
I just started working with masked access yesterday.
It's pretty simple using the CMSIS structure
Just create a bit mask for the pins in question.
#define BIT_MASK 0x07 // we only want the lower three bits
// now output your data via the bit mask
LPC_GPIO0->MASKED_ACCESS[ BIT_MASK ] = address;
Only the lower 3 bits of address will actually be copied to GPIO0.0 through GPIO0.2, all the other pins remain unaffected.
Note that the bits in the mask can be non continuous.
Bit banding might be faster, but it appears that the 1343 does not have bit banding for the IO ports. I'm still looking into that, and would be happy to be proven wrong.
Hi
I got a doubt while reading this entry, but after looking at the user manual (LPC1114) I have answered myself, so I'll post my thoughts just in case someone else gets the same doubt:
[B]Doubt[/B]: The LPC_GPIO_TypeDef CMSIS structure is 4096 words!! So, if you declare a variable of this type, you'll waste 4096 words of the valuable SRAM, right?
[B]Answer[/B]: Wrong!! When one declares a variable of LPC_GPIO_TypeDef type, the variable is mapped into the GPIO's peripheral memory map in the AHB bus, so not a single byte in user's SRAM is touched. I can imagine the AHB memory region as very special and exclusive kind of RAM, in which the user has no rights to use it, but only for the peripheral's convenience.
In fact, 4 variables of LPC_GPIO_TypeDef type are declared, one for each GPIO port.
LPC11xx.h excerpt
[FONT=Courier New]...
/* 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)
...
#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 )
...
[/FONT]
Greetings