8000 lpc4322_hic: clock enhancements by groleo · Pull Request #925 · ARMmbed/DAPLink · GitHub
[go: up one dir, main page]

Skip to content

lpc4322_hic: clock enhancements #925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
lpc43xx_hic,system: extract N setup as ndec_new
  • Loading branch information
Adrian Negreanu committed Feb 10, 2022
commit f1315ba65368ce1bf76eecd70a0c865ce5b0d1a7
30 changes: 17 additions & 13 deletions source/hic_hal/nxp/lpc4322/system_LPC43xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,22 @@ uint32_t GetClockFreq (uint32_t clk_src);
uint32_t SystemCoreClock = 120000000U; /* System Clock Frequency (Core Clock) */


#define PLL0_NSEL_MAX (1<<8)
/* pre-divider: compute ndec from nsel */
static unsigned ndec_new(unsigned nsel)
{
unsigned x=0x80, in;
switch (nsel)
{
case 0: return 0xFFFFFFFF;
case 1: return 0x302;
case 2: return 0x202;
default:
for (in = nsel; in <= PLL0_NSEL_MAX; in++)
x = ((x ^ x>>2 ^ x>>3 ^ x>>4) & 1) << 7 | x>>1 & 0xFF;
return x;
}
}
/******************************************************************************
* SetClock
******************************************************************************/
Expand Down Expand Up @@ -443,19 +459,7 @@ static void SetClock (void) {
(x << 0);

/* N divider */
x = 0x80;
switch (PLL0USB_N) {
case 0: x = 0xFFFFFFFF;
break;
case 1: x = 0x00000302;
break;
case 2: x = 0x00000202;
break;
default:
for (i = PLL0USB_N; i <= 0x0100; i++) {
x =(((x ^ (x >> 2) ^ (x >> 3) ^ (x >> 4)) & 1) << 7) | ((x >> 1) & 0x7F);
}
}
x = ndec_new(PLL0USB_N);
LPC_CGU->PLL0USB_NP_DIV = (x << 12);

/* P divider */
Expand Down
0