Skip to content

Commit 717eabe

Browse files
author
Adrian Negreanu
committed
lpc43xx_hic,system: extract P setup as pdec_new
1 parent 73e1d1d commit 717eabe

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

source/hic_hal/nxp/lpc4322/system_LPC43xx.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,23 @@ static unsigned ndec_new(unsigned nsel)
335335
return x;
336336
}
337337
}
338+
339+
#define PLL0_PSEL_MAX (1<<5)
340+
/* post-divider: compute pdec from psel */
341+
static unsigned pdec_new(unsigned psel)
342+
{
343+
unsigned x=0x10, ip;
344+
switch (psel)
345+
{
346+
case 0: return 0xFFFFFFFF;
347+
case 1: return 0x62;
348+
case 2: return 0x42;
349+
default:
350+
for (ip = psel; ip <= PLL0_PSEL_MAX; ip++)
351+
x = ((x ^ x>>2) & 1) << 4 | x>>1 & 0x3F;
352+
return x;
353+
}
354+
}
338355
/******************************************************************************
339356
* SetClock
340357
******************************************************************************/
@@ -463,19 +480,7 @@ static void SetClock (void) {
463480
LPC_CGU->PLL0USB_NP_DIV = (x << 12);
464481

465482
/* P divider */
466-
x = 0x10;
467-
switch (PLL0USB_P) {
468-
case 0: x = 0xFFFFFFFF;
469-
break;
470-
case 1: x = 0x00000062;
471-
break;
472-
case 2: x = 0x00000042;
473-
break;
474-
default:
475-
for (i = PLL0USB_P; i <= 0x200; i++) {
476-
x = (((x ^ (x >> 2)) & 1) << 4) | ((x >> 1) &0x0F);
477-
}
478-
}
483+
x = pdec_new(PLL0USB_P);
479484
LPC_CGU->PLL0USB_NP_DIV |= x;
480485

481486
LPC_CGU->PLL0USB_CTRL = (PLL0USB_CLK_SEL << 24) | /* Clock source sel */

0 commit comments

Comments
 (0)