/* 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;
+ if (on_off == 1) {
+ sys_ctrl->sys_AHB_clk_ctrl |= power_bit;
+ } else {
+ sys_ctrl->sys_AHB_clk_ctrl &= ~(power_bit);
+ }
+}
+
/***************************************************************************** */
/* System Clock */
/***************************************************************************** */
void config_gpio(volatile uint32_t* handle, uint32_t mode)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
-
/* Make sure IO_Config is clocked */
- sys_ctrl->sys_AHB_clk_ctrl |= LPC_SYS_ABH_CLK_CTRL_IO_CONFIG;
+ subsystem_power(LPC_SYS_ABH_CLK_CTRL_IO_CONFIG, 1);
*handle = mode;
/* Config done, power off IO_CONFIG block */
- sys_ctrl->sys_AHB_clk_ctrl &= ~LPC_SYS_ABH_CLK_CTRL_IO_CONFIG;
+ subsystem_power(LPC_SYS_ABH_CLK_CTRL_IO_CONFIG, 0);
}
void gpio_on(void)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
- /* Provide power to IO ports */
- sys_ctrl->sys_AHB_clk_ctrl |= LPC_SYS_ABH_CLK_CTRL_GPIO0;
- sys_ctrl->sys_AHB_clk_ctrl |= LPC_SYS_ABH_CLK_CTRL_GPIO1;
+ /* Provide power to GPIO control blocks */
+ subsystem_power(LPC_SYS_ABH_CLK_CTRL_GPIO0, 1);
+ subsystem_power(LPC_SYS_ABH_CLK_CTRL_GPIO1, 1);
}
void gpio_off(void)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
- /* Provide power to IO ports */
- sys_ctrl->sys_AHB_clk_ctrl &= ~(LPC_SYS_ABH_CLK_CTRL_GPIO0);
- sys_ctrl->sys_AHB_clk_ctrl &= ~(LPC_SYS_ABH_CLK_CTRL_GPIO1);
+ /* Remove power from GPIO control blocks */
+ subsystem_power(LPC_SYS_ABH_CLK_CTRL_GPIO0, 0);
+ subsystem_power(LPC_SYS_ABH_CLK_CTRL_GPIO1, 0);
}
/* Set all GPIO used on the GPIO_Demo module in a default state */
void set_gpio_pins(void)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
struct lpc_io_control* ioctrl = LPC_IO_CONTROL;
/* Make sure IO_Config is clocked */
- sys_ctrl->sys_AHB_clk_ctrl |= LPC_SYS_ABH_CLK_CTRL_IO_CONFIG;
+ subsystem_power(LPC_SYS_ABH_CLK_CTRL_IO_CONFIG, 1);
/* Configure GPIO pins */
ioctrl->pio0_0 = LPC_IO_FUNC_ALT(0) | LPC_IO_MODE_PULL_UP;
ioctrl->pio1_3 = LPC_IO_FUNC_ALT(1) | LPC_IO_ANALOG;
/* Config done, power off IO_CONFIG block */
- sys_ctrl->sys_AHB_clk_ctrl &= ~LPC_SYS_ABH_CLK_CTRL_IO_CONFIG;
+ subsystem_power(LPC_SYS_ABH_CLK_CTRL_IO_CONFIG, 1);
}
/* Handlers */
void set_i2c_pins(void)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
struct lpc_io_control* ioctrl = LPC_IO_CONTROL;
/* Make sure IO_Config is clocked */
- sys_ctrl->sys_AHB_clk_ctrl |= LPC_SYS_ABH_CLK_CTRL_IO_CONFIG;
+ subsystem_power(LPC_SYS_ABH_CLK_CTRL_IO_CONFIG, 1);
ioctrl->pio0_10 = LPC_IO_FUNC_ALT(2) | LPC_IO_OPEN_DRAIN_ENABLE; /* True open drain */
ioctrl->pio0_11 = LPC_IO_FUNC_ALT(2) | LPC_IO_OPEN_DRAIN_ENABLE;
/* Config done, power off IO_CONFIG block */
- sys_ctrl->sys_AHB_clk_ctrl &= ~LPC_SYS_ABH_CLK_CTRL_IO_CONFIG;
+ subsystem_power(LPC_SYS_ABH_CLK_CTRL_IO_CONFIG, 0);
}
void i2c_on(uint32_t i2c_clk_freq)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
struct lpc_i2c* i2c = LPC_I2C0;
NVIC_DisableIRQ(I2C0_IRQ);
/* Power on I2C 0 block */
- sys_ctrl->sys_AHB_clk_ctrl |= LPC_SYS_ABH_CLK_CTRL_I2C;
+ subsystem_power(LPC_SYS_ABH_CLK_CTRL_I2C, 1);
/* Set clock */
i2c_clock_on(i2c_clk_freq);
mod_i2c.clock = i2c_clk_freq;
void i2c_off(void)
{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
NVIC_DisableIRQ(I2C0_IRQ);
- sys_ctrl->sys_AHB_clk_ctrl &= ~(LPC_SYS_ABH_CLK_CTRL_I2C);
+ subsystem_power(LPC_SYS_ABH_CLK_CTRL_I2C, 0);
mod_i2c.clock = 0;
}
sys_ctrl->uart_clk_div[uart_num] = 0;
}
-static void uart_power(uint32_t power_bit, uint32_t on_off)
-{
- struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL;
- if (on_off == 1) {
- sys_ctrl->sys_AHB_clk_ctrl |= power_bit;
- } else {
- sys_ctrl->sys_AHB_clk_ctrl &= ~(power_bit);
- }
-}
-
static uint32_t uart_mode_setup(uint32_t uart_num)
{
struct lpc_uart* uart = uarts[uart_num].regs; /* Get the right registers */
NVIC_DisableIRQ( uart->irq );
/* Setup pins, must be done before clock setup and with uart powered off. */
uart_clk_off(uart_num);
- uart_power(uart->power_offset, 0);
+ subsystem_power(uart->power_offset, 0);
uart_set_pin_func(uart_num);
/* Turn On power */
- uart_power(uart->power_offset, 1);
+ subsystem_power(uart->power_offset, 1);
/* Setup clock acording to baudrate */
uart_clk_on(uart_num, baudrate);
/* Setup mode, fifo, ... */
NVIC_DisableIRQ( uart->irq );
uart_clk_off(uart_num);
/* Turn Off power */
- uart_power(uart->power_offset, 0);
+ subsystem_power(uart->power_offset, 0);
}
/***************************************************************************** */
void enter_deep_sleep(void);
+/* Power on or off a subsystem */
+void subsystem_power(uint32_t power_bit, uint32_t on_off);
+
/* Configure the brown-out detection */
void system_brown_out_detection_config(uint32_t level);