static void flash_accelerator_config(uint32_t freq_sel)
{
struct lpc_flash_control* fcfg = LPC_FLASH_CONTROL;
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
if (freq_sel & 0x01) {
/* 1 cycle read mode */
- sys_ctrl->peripheral_reset_ctrl |= LPC_FLASH_OVERRIDE;
+ sys_config->peripheral_reset_ctrl |= LPC_FLASH_OVERRIDE;
} else {
/* multiple cycle flash read mode */
- sys_ctrl->peripheral_reset_ctrl &= ~(LPC_FLASH_OVERRIDE);
+ sys_config->peripheral_reset_ctrl &= ~(LPC_FLASH_OVERRIDE);
fcfg->flash_cfg &= ~(LPC_FLASH_CFG_MASK);
fcfg->flash_cfg |= ((freq_sel & 0x06) >> 1);
}
/* Configure the brown-out detection */
void system_brown_out_detection_config(uint32_t level)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
if (level == 0) {
/* Disable Brown-Out Detection, power it down */
- sys_ctrl->powerdown_run_cfg |= LPC_POWER_DOWN_BOD;
+ sys_config->powerdown_run_cfg |= LPC_POWER_DOWN_BOD;
lpc_private.brown_out_detection_enabled = 0;
} else {
/* Power on Brown-Out Detection.
* (Needed for ADC, See Section 19.2 of UM10441 revision 2.1 or newer for more information) */
- sys_ctrl->powerdown_run_cfg &= ~(LPC_POWER_DOWN_BOD);
+ sys_config->powerdown_run_cfg &= ~(LPC_POWER_DOWN_BOD);
lpc_private.brown_out_detection_enabled = 1;
/* Configure Brown-Out Detection */
/* FIXME */
*/
void system_set_default_power_state(void)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
/* Start with all memory powered on and nothing else */
- sys_ctrl->sys_AHB_clk_ctrl = LPC_SYS_ABH_CLK_CTRL_MEM_ALL;
+ sys_config->sys_AHB_clk_ctrl = LPC_SYS_ABH_CLK_CTRL_MEM_ALL;
}
/* Enter deep sleep.
*/
void enter_deep_sleep(void)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
/* Ask for the same clock status when waking up */
- sys_ctrl->powerdown_wake_cfg = sys_ctrl->powerdown_run_cfg;
+ sys_config->powerdown_wake_cfg = sys_config->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;
+ sys_config->powerdown_sleep_cfg = LPC_DEEP_SLEEP_CFG_NOWDTLOCK_BOD_ON;
} else {
- sys_ctrl->powerdown_sleep_cfg = LPC_DEEP_SLEEP_CFG_NOWDTLOCK_BOD_OFF;
+ sys_config->powerdown_sleep_cfg = LPC_DEEP_SLEEP_CFG_NOWDTLOCK_BOD_OFF;
}
/* Enter deep sleep */
/* FIXME */
/* Power on or off a subsystem */
void subsystem_power(uint32_t power_bit, uint32_t on_off)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
if (on_off == 1) {
- sys_ctrl->sys_AHB_clk_ctrl |= power_bit;
+ sys_config->sys_AHB_clk_ctrl |= power_bit;
} else {
- sys_ctrl->sys_AHB_clk_ctrl &= ~(power_bit);
+ sys_config->sys_AHB_clk_ctrl &= ~(power_bit);
}
}
*/
void clock_config(uint32_t freq_sel)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
lpc_disable_irq();
/* Turn on IRC */
- sys_ctrl->powerdown_run_cfg &= ~(LPC_POWER_DOWN_IRC);
- sys_ctrl->powerdown_run_cfg &= ~(LPC_POWER_DOWN_IRC_OUT);
+ sys_config->powerdown_run_cfg &= ~(LPC_POWER_DOWN_IRC);
+ sys_config->powerdown_run_cfg &= ~(LPC_POWER_DOWN_IRC_OUT);
/* Use IRC clock for main clock */
- sys_ctrl->main_clk_sel = LPC_MAIN_CLK_SRC_IRC_OSC;
+ sys_config->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;
+ sys_config->main_clk_upd_en = 0;
+ sys_config->main_clk_upd_en = 1;
/* Turn off / power off external crystal */
- sys_ctrl->powerdown_run_cfg |= LPC_POWER_DOWN_SYS_OSC;
+ sys_config->powerdown_run_cfg |= LPC_POWER_DOWN_SYS_OSC;
/* Set AHB clock divider : divide by one ... */
- sys_ctrl->sys_AHB_clk_div = 1;
+ sys_config->sys_AHB_clk_div = 1;
/* Configure number of CPU clocks for flash access before setting the new clock */
flash_accelerator_config(freq_sel);
/* power off PLL */
- sys_ctrl->powerdown_run_cfg |= LPC_POWER_DOWN_SYSPLL;
+ sys_config->powerdown_run_cfg |= LPC_POWER_DOWN_SYSPLL;
/* If using only internal RC, we are done */
if (freq_sel == FREQ_SEL_IRC) {
}
lpc_private.main_clock = (((freq_sel >> 3) & 0xFF) * 12 * 1000 * 1000);
/* Setup PLL dividers */
- sys_ctrl->sys_pll_ctrl = (((M - 1) & 0x1F) | (N << 5));
+ sys_config->sys_pll_ctrl = (((M - 1) & 0x1F) | (N << 5));
/* Set sys_pll_clk to internal RC */
- 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;
+ sys_config->sys_pll_clk_sel = LPC_PLL_CLK_SRC_IRC_OSC;
+ sys_config->sys_pll_clk_upd_en = 0; /* SYSPLLCLKUEN must go from LOW to HIGH */
+ sys_config->sys_pll_clk_upd_en = 1;
/* Power-up PLL */
- sys_ctrl->powerdown_run_cfg &= ~(LPC_POWER_DOWN_SYSPLL);
+ sys_config->powerdown_run_cfg &= ~(LPC_POWER_DOWN_SYSPLL);
/* Wait Until PLL Locked */
- while (!(sys_ctrl->sys_pll_status & 0x01));
+ while (!(sys_config->sys_pll_status & 0x01));
/* Use PLL as main clock */
- sys_ctrl->main_clk_sel = LPC_MAIN_CLK_SRC_PLL_OUT;
+ sys_config->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;
+ sys_config->main_clk_upd_en = 0;
+ sys_config->main_clk_upd_en = 1;
}
/* And call all clock updaters */
void clkout_on(uint32_t src, uint32_t div)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
/* Select clk_out clock source */
- sys_ctrl->clk_out_src_sel = (src & 0x03);
+ sys_config->clk_out_src_sel = (src & 0x03);
/* Activate clk_out */
- sys_ctrl->clk_out_div = (div & 0xFF);
- sys_ctrl->clk_out_upd_en = 0;
- sys_ctrl->clk_out_upd_en = 1;
+ sys_config->clk_out_div = (div & 0xFF);
+ sys_config->clk_out_upd_en = 0;
+ sys_config->clk_out_upd_en = 1;
}
void clkout_off(void)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
- sys_ctrl->clk_out_div = 0; /* Disable CLKOUT */
- sys_ctrl->clk_out_upd_en = 0;
- sys_ctrl->clk_out_upd_en = 1;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
+ sys_config->clk_out_div = 0; /* Disable CLKOUT */
+ sys_config->clk_out_upd_en = 0;
+ sys_config->clk_out_upd_en = 1;
}
*/
void watchdog_lock_clk_src_power(void)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
struct lpc_watchdog* wdt = LPC_WDT;
if (wdt->clk_src_sel & LPC_WDT_CLK_WDOSC) {
- sys_ctrl->powerdown_sleep_cfg &= ~(LPC_POWER_DOWN_WDT_OSC);
- sys_ctrl->powerdown_wake_cfg &= ~(LPC_POWER_DOWN_WDT_OSC);
+ sys_config->powerdown_sleep_cfg &= ~(LPC_POWER_DOWN_WDT_OSC);
+ sys_config->powerdown_wake_cfg &= ~(LPC_POWER_DOWN_WDT_OSC);
} else {
- sys_ctrl->powerdown_wake_cfg &= ~(LPC_POWER_DOWN_IRC);
- sys_ctrl->powerdown_wake_cfg &= ~(LPC_POWER_DOWN_IRC_OUT);
+ sys_config->powerdown_wake_cfg &= ~(LPC_POWER_DOWN_IRC);
+ sys_config->powerdown_wake_cfg &= ~(LPC_POWER_DOWN_IRC_OUT);
}
wdt->mode |= LPC_WDT_CLK_POWER_LOCK;
}
*/
void watchdog_config(const struct wdt_config* wd_conf)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
struct lpc_watchdog* wdt = LPC_WDT;
NVIC_DisableIRQ(WDT_IRQ);
wdt->timer_const = ((wd_conf->nb_clk >> 2) & LPC_WDT_TIMER_MAX);
/* Watchdog clock select */
if (wd_conf->clk_sel == LPC_WDT_CLK_IRC) {
- sys_ctrl->powerdown_run_cfg &= ~(LPC_POWER_DOWN_IRC);
- sys_ctrl->powerdown_run_cfg &= ~(LPC_POWER_DOWN_IRC_OUT);
+ sys_config->powerdown_run_cfg &= ~(LPC_POWER_DOWN_IRC);
+ sys_config->powerdown_run_cfg &= ~(LPC_POWER_DOWN_IRC_OUT);
wdt->clk_src_sel = LPC_WDT_CLK_IRC;
} else {
- sys_ctrl->powerdown_run_cfg &= ~(LPC_POWER_DOWN_WDT_OSC);
+ sys_config->powerdown_run_cfg &= ~(LPC_POWER_DOWN_WDT_OSC);
wdt->clk_src_sel = LPC_WDT_CLK_WDOSC;
}
/* Use the windows functionnality ? */
if (wd_conf->locks & WDT_CLK_POWER_LOCK) {
mode |= LPC_WDT_CLK_POWER_LOCK;
if (wd_conf->clk_sel == LPC_WDT_CLK_WDOSC) {
- sys_ctrl->powerdown_sleep_cfg &= ~(LPC_POWER_DOWN_WDT_OSC);
- sys_ctrl->powerdown_wake_cfg &= ~(LPC_POWER_DOWN_WDT_OSC);
+ sys_config->powerdown_sleep_cfg &= ~(LPC_POWER_DOWN_WDT_OSC);
+ sys_config->powerdown_wake_cfg &= ~(LPC_POWER_DOWN_WDT_OSC);
} else {
- sys_ctrl->powerdown_wake_cfg &= ~(LPC_POWER_DOWN_IRC);
- sys_ctrl->powerdown_wake_cfg &= ~(LPC_POWER_DOWN_IRC_OUT);
+ sys_config->powerdown_wake_cfg &= ~(LPC_POWER_DOWN_IRC);
+ sys_config->powerdown_wake_cfg &= ~(LPC_POWER_DOWN_IRC_OUT);
}
}
if (wd_conf->locks & WDT_CLK_SRC_LOCK) {
*/
int stop_watchdog(void)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
struct lpc_watchdog* wdt = LPC_WDT;
int ret = -1;
if ((wdt->clk_src_sel == LPC_WDT_CLK_WDOSC) && (wdt->mode & LPC_WDT_CLK_POWER_LOCK)) {
wdt->clk_src_sel = LPC_WDT_CLK_IRC;
}
- sys_ctrl->powerdown_run_cfg |= LPC_POWER_DOWN_WDT_OSC;
+ sys_config->powerdown_run_cfg |= LPC_POWER_DOWN_WDT_OSC;
/* Power wadchdog block before changing it's configuration */
wdt->clk_src_sel = LPC_WDT_CLK_WDOSC;
ret = 0;
return 0;
}
/* If main clock and clkout not running from IRC (possibly through PLL), turn off IRC */
- if ((sys_ctrl->main_clk_sel != LPC_MAIN_CLK_SRC_IRC_OSC) &&
- ((sys_ctrl->main_clk_sel & 0x01) && (sys_ctrl->sys_pll_clk_sel != LPC_PLL_CLK_SRC_IRC_OSC)) &&
- (sys_ctrl->clk_out_src_sel != LPC_CLKOUT_SRC_IRC_OSC)) {
- sys_ctrl->powerdown_run_cfg |= LPC_POWER_DOWN_IRC;
- sys_ctrl->powerdown_run_cfg |= LPC_POWER_DOWN_IRC_OUT;
+ if ((sys_config->main_clk_sel != LPC_MAIN_CLK_SRC_IRC_OSC) &&
+ ((sys_config->main_clk_sel & 0x01) && (sys_config->sys_pll_clk_sel != LPC_PLL_CLK_SRC_IRC_OSC)) &&
+ (sys_config->clk_out_src_sel != LPC_CLKOUT_SRC_IRC_OSC)) {
+ sys_config->powerdown_run_cfg |= LPC_POWER_DOWN_IRC;
+ sys_config->powerdown_run_cfg |= LPC_POWER_DOWN_IRC_OUT;
}
subsystem_power(LPC_SYS_ABH_CLK_CTRL_Watchdog, 0);
return 0;
*/
void startup_watchdog_disable(void)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
struct lpc_watchdog* wdt = LPC_WDT;
/* Power wadchdog block before changing it's configuration */
watchdog_feed();
/* And power it down */
subsystem_power(LPC_SYS_ABH_CLK_CTRL_Watchdog, 0);
- sys_ctrl->powerdown_run_cfg |= LPC_POWER_DOWN_WDT_OSC;
+ sys_config->powerdown_run_cfg |= LPC_POWER_DOWN_WDT_OSC;
NVIC_DisableIRQ(WDT_IRQ);
}
void adc_on(void)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
struct lpc_adc* adc = LPC_ADC;
/* Disable ADC Interrupt */
/* Brown-Out detection must be powered to operate the ADC.
* See Section 19.2 of UM10441 revision 2.1 or newer for more information */
- sys_ctrl->powerdown_run_cfg &= ~LPC_POWER_DOWN_BOD;
+ sys_config->powerdown_run_cfg &= ~LPC_POWER_DOWN_BOD;
/* Power-up ADC */
- sys_ctrl->powerdown_run_cfg &= ~LPC_POWER_DOWN_ADC;
+ sys_config->powerdown_run_cfg &= ~LPC_POWER_DOWN_ADC;
/* Provide clock to ADC */
subsystem_power(LPC_SYS_ABH_CLK_CTRL_ADC, 1);
adc_clk_update();
void adc_off(void)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
/* Disable ADC Interrupt */
NVIC_DisableIRQ(ADC_IRQ);
/* Power Down ADC */
- sys_ctrl->powerdown_run_cfg |= LPC_POWER_DOWN_ADC;
+ sys_config->powerdown_run_cfg |= LPC_POWER_DOWN_ADC;
/* Remove clock from ADC block */
subsystem_power(LPC_SYS_ABH_CLK_CTRL_ADC, 0);
}
/* In case someone wants the RTC to count something different from seconds */
void rtc_clk_src_select(uint8_t source, uint8_t clk_div)
{
- struct lpc_sys_control* sysctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
struct lpc_pm_unit* pm_unit = LPC_PMU;
uint32_t tmp = 0;
pm_unit->system_config = (tmp | ((source & 0x0F) << LPC_RTC_CLK_SRC_SHIFT));
/* Change the RTC Clock divider if source is PCLK */
if (source == LPC_RTC_CLK_PCLK) {
- sysctrl->rtc_clk_div = clk_div;
+ sys_config->rtc_clk_div = clk_div;
} else {
- sysctrl->rtc_clk_div = 0;
+ sys_config->rtc_clk_div = 0;
}
}
*/
static void uart_clk_on(uint32_t uart_num, uint32_t baudrate)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
struct lpc_uart* uart = uarts[uart_num].regs; /* Get the right registers */
uint32_t div = 0, pclk = 0;
/* Save baudrate value */
/* Configure UART clock */
pclk = get_main_clock(); /* See above note */
div = (pclk / (baudrate * 16));
- sys_ctrl->uart_clk_div[uart_num] = 0x01;
+ sys_config->uart_clk_div[uart_num] = 0x01;
/* The easy one : divider is an integer, or baudrate is low enough for the aproximation */
if ((baudrate <= 115200) || ((div * baudrate * 16) == pclk)) {
uart->line_ctrl |= LPC_UART_ENABLE_DLAB;
}
static void uart_clk_off(uint32_t uart_num)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
/* Erase saved baudrate */
uarts[uart_num].baudrate = 0;
- sys_ctrl->uart_clk_div[uart_num] = 0;
+ sys_config->uart_clk_div[uart_num] = 0;
}
static uint32_t uart_setup(uint32_t uart_num)
/***************************************************************************** */
uint32_t ssp_clk_on(uint8_t ssp_num, uint32_t rate)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
+ struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
struct lpc_ssp* ssp_regs = ssps[ssp_num].regs;
uint32_t prescale = 0, pclk_div = 0;
uint32_t pclk = 0, div = 0;
/* Activate the SSP clock (maybe divide main clock) */
switch (ssp_num) {
case 0 :
- sys_ctrl->ssp0_clk_div = pclk_div;
+ sys_config->ssp0_clk_div = pclk_div;
break;
}
volatile uint32_t reset; /* 0x08 : reset Register 0 (-/W) */
volatile uint32_t status; /* 0x0C : status Register 0 (R/-) */
};
-struct lpc_sys_control
+struct lpc_sys_config
{
volatile uint32_t sys_mem_remap; /* 0x000 System memory remap (R/W) */
volatile uint32_t peripheral_reset_ctrl; /* 0x004 Peripheral reset control (R/W) */
volatile const uint32_t device_id; /* 0x3F4 : Device ID (R/ ) */
};
-#define LPC_SYS_CONTROL ((struct lpc_sys_control *) LPC_SYSCON_BASE)
+#define LPC_SYS_CONFIG ((struct lpc_sys_config *) LPC_SYSCON_BASE)
/* AHB control bits
* 0 (System (cortexM0, syscon, PMU, ...)) is a read only bit (system cannot be disabled)