Skip to content

Commit abcbeec

Browse files
author
Adrian Negreanu
committed
lpc43xx_hic,system: extract M setup as mdec_new
1 parent ca753ed commit abcbeec

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
@@ -352,6 +352,23 @@ static unsigned pdec_new(unsigned psel)
352352
return x;
353353
}
354354
}
355+
356+
#define PLL0_MSEL_MAX (1<<15)
357+
/* multiplier: compute mdec from msel */
358+
static unsigned mdec_new (unsigned msel)
359+
{
360+
unsigned x=0x4000, im;
361+
switch (msel)
362+
{
363+
case 0: return 0xFFFFFFFF;
364+
case 1: return 0x18003;
365+
case 2: return 0x10003;
366+
default:
367+
for (im = msel; im <= PLL0_MSEL_MAX; im++)
368+
x = (((x ^ (x >> 1)) & 1) << 14) | ((x >> 1) & 0xFFFF);
369+
return x;
370+
}
371+
}
355372
/******************************************************************************
356373
* SetClock
357374
******************************************************************************/
@@ -448,19 +465,7 @@ static void SetClock (void) {
448465
LPC_CGU->PLL0USB_CTRL |= 1;
449466

450467
/* M divider */
451-
x = 0x00004000;
452-
switch (PLL0USB_M) {
453-
case 0: x = 0xFFFFFFFF;
454-
break;
455-
case 1: x = 0x00018003;
456-
break;
457-
case 2: x = 0x00010003;
458-
break;
459-
default:
460-
for (i = PLL0USB_M; i <= 0x8000; i++) {
461-
x = (((x ^ (x >> 1)) & 1) << 14) | ((x >> 1) & 0x3FFF);
462-
}
463-
}
468+
x = mdec_new(PLL0USB_M);
464469

465470
if (PLL0USB_M < 60) selp = (PLL0USB_M >> 1) + 1;
466471
else selp = 31;

0 commit comments

Comments
 (0)