Skip to content

Commit 73e1d1d

Browse files
author
Adrian Negreanu
committed
lpc43xx_hic,system: extract N setup as ndec_new
1 parent 94b70ac commit 73e1d1d

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

source/hic_hal/nxp/lpc4322/system_LPC43xx.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,22 @@ uint32_t GetClockFreq (uint32_t clk_src);
319319
uint32_t SystemCoreClock = 120000000U; /* System Clock Frequency (Core Clock) */
320320

321321

322+
#define PLL0_NSEL_MAX (1<<8)
323+
/* pre-divider: compute ndec from nsel */
324+
static unsigned ndec_new(unsigned nsel)
325+
{
326+
unsigned x=0x80, in;
327+
switch (nsel)
328+
{
329+
case 0: return 0xFFFFFFFF;
330+
case 1: return 0x302;
331+
case 2: return 0x202;
332+
default:
333+
for (in = nsel; in <= PLL0_NSEL_MAX; in++)
334+
x = ((x ^ x>>2 ^ x>>3 ^ x>>4) & 1) << 7 | x>>1 & 0xFF;
335+
return x;
336+
}
337+
}
322338
/******************************************************************************
323339
* SetClock
324340
******************************************************************************/
@@ -443,19 +459,7 @@ static void SetClock (void) {
443459
(x << 0);
444460

445461
/* N divider */
446-
x = 0x80;
447-
switch (PLL0USB_N) {
448-
case 0: x = 0xFFFFFFFF;
449-
break;
450-
case 1: x = 0x00000302;
451-
break;
452-
case 2: x = 0x00000202;
453-
break;
454-
default:
455-
for (i = PLL0USB_N; i <= 0x0100; i++) {
456-
x =(((x ^ (x >> 2) ^ (x >> 3) ^ (x >> 4)) & 1) << 7) | ((x >> 1) & 0x7F);
457-
}
458-
}
462+
x = ndec_new(PLL0USB_N);
459463
LPC_CGU->PLL0USB_NP_DIV = (x << 12);
460464

461465
/* P divider */

0 commit comments

Comments
 (0)