Skip to content

Commit dd0bb84

Browse files
author
Adrian Negreanu
committed
lpc43xx_hic,system: extract SELI setup as anadeci_new
1 parent abcbeec commit dd0bb84

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

source/hic_hal/nxp/lpc4322/system_LPC43xx.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,22 @@ static unsigned mdec_new (unsigned msel)
369369
return x;
370370
}
371371
}
372+
373+
/* bandwidth: compute seli from msel */
374+
unsigned anadeci_new(unsigned msel)
375+
{
376+
unsigned tmp;
377+
if (msel > 16384) return 1;
378+
if (msel > 8192) return 2;
379+
if (msel > 2048) return 4;
380+
if (msel >= 501) return 8;
381+
if (msel >= 60)
382+
{
383+
tmp=1024/(msel+9);
384+
return ( 1024 == ( tmp*(msel+9)) ) == 0 ? tmp*4 : (tmp+1)*4 ;
385+
}
386+
return (msel & 0x3c) + 4;
387+
}
372388
/******************************************************************************
373389
* SetClock
374390
******************************************************************************/
@@ -469,13 +485,7 @@ static void SetClock (void) {
469485

470486
if (PLL0USB_M < 60) selp = (PLL0USB_M >> 1) + 1;
471487
else selp = 31;
472-
473-
if (PLL0USB_M > 16384) seli = 1;
474-
else if (PLL0USB_M > 8192) seli = 2;
475-
else if (PLL0USB_M > 2048) seli = 4;
476-
else if (PLL0USB_M >= 501) seli = 8;
477-
else if (PLL0USB_M >= 60) seli = 4 * (1024 / (PLL0USB_M + 9));
478-
else seli = (PLL0USB_M & 0x3C) + 4;
488+
seli = anadeci_new(PLL0USB_M);
479489
LPC_CGU->PLL0USB_MDIV = (selp << 17) |
480490
(seli << 22) |
481491
(x << 0);

0 commit comments

Comments
 (0)