From fd6dc53e9c574ad20fb518b88cb0ee1bbfba6c28 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Mon, 23 Nov 2015 13:01:42 +0100 Subject: [PATCH] Use defines instead of hard-coded values Fix field name in lpc_sys_control structure --- core/system.c | 13 ++++++++----- include/core/lpc_regs_12xx.h | 10 +++++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/core/system.c b/core/system.c index 5671d13..347295b 100644 --- a/core/system.c +++ b/core/system.c @@ -43,11 +43,13 @@ /***************************************************************************** */ struct lpc_desc_private { uint32_t main_clock; - uint32_t brown_out_detection_enabled; + uint8_t brown_out_detection_enabled; + uint8_t need_IRC; }; static struct lpc_desc_private lpc_private = { .main_clock = LPC_IRC_OSC_CLK, .brown_out_detection_enabled = 0, + .need_IRC = 1, }; /***************************************************************************** */ @@ -138,7 +140,7 @@ void enter_deep_sleep(void) struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL; /* Ask for the same clock status when waking up */ - sys_ctrl->powerdown_awake_cfg = sys_ctrl->powerdown_run_cfg; + sys_ctrl->powerdown_wake_cfg = sys_ctrl->powerdown_run_cfg; /* Set deep_sleep config */ if (lpc_private.brown_out_detection_enabled) { sys_ctrl->powerdown_sleep_cfg = LPC_DEEP_SLEEP_CFG_NOWDTLOCK_BOD_ON; @@ -187,7 +189,8 @@ void clock_config(uint32_t freq_sel) sys_ctrl->powerdown_run_cfg &= ~(LPC_POWER_DOWN_IRC); sys_ctrl->powerdown_run_cfg &= ~(LPC_POWER_DOWN_IRC_OUT); /* Use IRC clock for main clock */ - sys_ctrl->main_clk_sel = 0; + sys_ctrl->main_clk_sel = LPC_MAIN_CLK_SRC_IRC_OSC; + lpc_private.need_IRC = 1; /* Switch the main clock source */ sys_ctrl->main_clk_upd_en = 0; sys_ctrl->main_clk_upd_en = 1; @@ -223,7 +226,7 @@ void clock_config(uint32_t freq_sel) /* Setup PLL dividers */ sys_ctrl->sys_pll_ctrl = (((M - 1) & 0x1F) | (N << 5)); /* Set sys_pll_clk to internal RC */ - sys_ctrl->sys_pll_clk_sel = 0; + sys_ctrl->sys_pll_clk_sel = LPC_PLL_CLK_SRC_IRC_OSC; sys_ctrl->sys_pll_clk_upd_en = 0; /* SYSPLLCLKUEN must go from LOW to HIGH */ sys_ctrl->sys_pll_clk_upd_en = 1; /* Power-up PLL */ @@ -231,7 +234,7 @@ void clock_config(uint32_t freq_sel) /* Wait Until PLL Locked */ while (!(sys_ctrl->sys_pll_status & 0x01)); /* Use PLL as main clock */ - sys_ctrl->main_clk_sel = 0x03; + sys_ctrl->main_clk_sel = LPC_MAIN_CLK_SRC_PLL_OUT; /* Switch the main clock source */ sys_ctrl->main_clk_upd_en = 0; sys_ctrl->main_clk_upd_en = 1; diff --git a/include/core/lpc_regs_12xx.h b/include/core/lpc_regs_12xx.h index 570f563..36ef88f 100644 --- a/include/core/lpc_regs_12xx.h +++ b/include/core/lpc_regs_12xx.h @@ -142,7 +142,7 @@ struct lpc_sys_control uint32_t reserved_11[4]; volatile uint32_t powerdown_sleep_cfg; /* 0x230 : Power-down states in Deep-sleep mode (R/W) */ - volatile uint32_t powerdown_awake_cfg; /* 0x234 : Power-down states after wake-up (R/W) */ + volatile uint32_t powerdown_wake_cfg; /* 0x234 : Power-down states after wake-up (R/W) */ volatile uint32_t powerdown_run_cfg; /* 0x238 : Power-down configuration Register (R/W) */ uint32_t reserved_12[110]; volatile const uint32_t device_id; /* 0x3F4 : Device ID (R/ ) */ @@ -199,6 +199,14 @@ struct lpc_sys_control #define LPC_DEEP_SLEEP_CFG_NOWDTLOCK_BOD_ON 0x0000FFF7 #define LPC_DEEP_SLEEP_CFG_NOWDTLOCK_BOD_OFF 0x0000FFFF +#define LPC_MAIN_CLK_SRC_IRC_OSC 0x00 +#define LPC_MAIN_CLK_SRC_PLL_IN 0x01 +#define LPC_MAIN_CLK_SRC_WATCHDOG_OSC 0x02 +#define LPC_MAIN_CLK_SRC_PLL_OUT 0x03 + +#define LPC_PLL_CLK_SRC_IRC_OSC 0x00 +#define LPC_PLL_CLK_SRC_EXT_OSC 0x01 + #define LPC_CLKOUT_SRC_IRC_OSC 0x00 #define LPC_CLKOUT_SRC_XTAL_OSC 0x01 #define LPC_CLKOUT_SRC_WATCHDOG_OSC 0x02 -- 2.43.0