From: Nathael Pajani Date: Wed, 6 Nov 2013 01:03:10 +0000 (+0100) Subject: Add and use io_config_clk_on/off functions. X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=55b5bae47c5b160597e81c189649eb5cd78138c5;p=soft%2Flpc122x%2Fcore Add and use io_config_clk_on/off functions. --- diff --git a/core/system.c b/core/system.c index e320de1..5d0db4f 100644 --- a/core/system.c +++ b/core/system.c @@ -251,6 +251,17 @@ static void propagate_main_clock(void) spi_clk_update(); } +/* IO config clock */ +/* To change GPIO config the io config block must be powered on */ +void io_config_clk_on(void) +{ + subsystem_power(LPC_SYS_ABH_CLK_CTRL_IO_CONFIG, 1); +} +void io_config_clk_off(void) +{ + subsystem_power(LPC_SYS_ABH_CLK_CTRL_IO_CONFIG, 0); +} + /***************************************************************************** */ /* CLK Out */ /***************************************************************************** */ diff --git a/drivers/gpio.c b/drivers/gpio.c index c6ffce1..aff5e3c 100644 --- a/drivers/gpio.c +++ b/drivers/gpio.c @@ -37,10 +37,10 @@ void config_gpio(volatile uint32_t* handle, uint32_t mode) { /* Make sure IO_Config is clocked */ - subsystem_power(LPC_SYS_ABH_CLK_CTRL_IO_CONFIG, 1); + io_config_clk_on(); *handle = mode; /* Config done, power off IO_CONFIG block */ - subsystem_power(LPC_SYS_ABH_CLK_CTRL_IO_CONFIG, 0); + io_config_clk_off(); } void gpio_on(void) @@ -63,7 +63,7 @@ void set_gpio_pins(void) struct lpc_io_control* ioctrl = LPC_IO_CONTROL; /* Make sure IO_Config is clocked */ - subsystem_power(LPC_SYS_ABH_CLK_CTRL_IO_CONFIG, 1); + io_config_clk_on(); /* Configure GPIO pins */ ioctrl->pio0_0 = LPC_IO_FUNC_ALT(0) | LPC_IO_MODE_PULL_UP; @@ -92,7 +92,7 @@ void set_gpio_pins(void) ioctrl->pio1_3 = LPC_IO_FUNC_ALT(1) | LPC_IO_ANALOG; /* Config done, power off IO_CONFIG block */ - subsystem_power(LPC_SYS_ABH_CLK_CTRL_IO_CONFIG, 1); + io_config_clk_off(); } /* Handlers */ diff --git a/drivers/i2c.c b/drivers/i2c.c index ac9e73b..dc25e7a 100644 --- a/drivers/i2c.c +++ b/drivers/i2c.c @@ -452,11 +452,11 @@ void set_i2c_pins(void) struct lpc_io_control* ioctrl = LPC_IO_CONTROL; /* Make sure IO_Config is clocked */ - subsystem_power(LPC_SYS_ABH_CLK_CTRL_IO_CONFIG, 1); + io_config_clk_on(); 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 */ - subsystem_power(LPC_SYS_ABH_CLK_CTRL_IO_CONFIG, 0); + io_config_clk_off(); } void i2c_on(uint32_t i2c_clk_freq) diff --git a/drivers/serial.c b/drivers/serial.c index 405e94b..612856e 100644 --- a/drivers/serial.c +++ b/drivers/serial.c @@ -219,11 +219,10 @@ static uint32_t uart_mode_setup(uint32_t uart_num) */ static void uart_set_pin_func(uint32_t uart_num) { - 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; + io_config_clk_on(); /* Configure UART pins (Only Rx and Tx) */ switch (uart_num) { case 0: @@ -236,7 +235,7 @@ static void uart_set_pin_func(uint32_t uart_num) break; } /* Config done, power off IO_CONFIG block */ - sys_ctrl->sys_AHB_clk_ctrl &= ~LPC_SYS_ABH_CLK_CTRL_IO_CONFIG; + io_config_clk_off(); } struct uart_def { diff --git a/include/core/system.h b/include/core/system.h index 2e92403..17b7834 100644 --- a/include/core/system.h +++ b/include/core/system.h @@ -92,6 +92,10 @@ void clock_config(uint32_t freq_sel); /* return current main clock */ uint32_t get_main_clock(void); +/* IO config clock */ +/* To change GPIO config the io config block must be powered on */ +void io_config_clk_on(void); +void io_config_clk_off(void); /* This is mainly a debug feature, but can be used to provide a clock to an * external peripheral */