struct init_entry_ {
volatile uint32_t *loc;
uint32_t value;
};
void writeregs(const struct init_entry_ *p)
{
for (; p->loc; p ++)
*p->loc = p->value;
}
static const struct init_entry_ init0_table[] = {
{&LPC_SC->PCONP, 0xA060965e}, // USB, DMA, SSP0, SSP1, TIMER2...
{&LPC_SC->PCLKSEL1, 0x800}, // SSP0: /2
{&LPC_PINCON->PINMODE1, 0x002a8000}, // adc inputs, DAC output
{&LPC_PINCON->PINSEL1, 0x14254028}, // DAC, ad2, ad1, ad0, USB, MOSI0, MISO0
{&LPC_PINCON->PINMODE2, 0x00030000}, // pulldown PSEN
{&LPC_PINCON->PINMODE4, 0x03000000}, // extpwr pulldn
// Port init
//10987654321098765432109876543210
{&LPC_GPIO0->FIOPIN, 0b00010000000000010000000101000010}, // oe, mtr control, SD ss, hlat, Flash_ss
{&LPC_GPIO0->FIODIR, 0b00010100011110010000010101000010}, // bits 28- BLU, 16 - HLAT, OE, RTSOUT
{&LPC_PWM1->PR, 25000000ul / PWM_CLK - 1},
// many more entries follow - actually the table has about 100 entries in a typical app
{0, 0} // end of table marker
};
int main (void)
{
writeregs(init0_table); // most of initialization
// do the real stuff...
}
|