From 50ba44fb0243500e73edc65bac857dd837fa5462 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Mon, 21 Apr 2014 23:20:51 +0200 Subject: [PATCH] CLKOUT support and test --- core/system.c | 18 ++++++++++++++++++ include/core/lpc_regs_12xx.h | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/core/system.c b/core/system.c index 1768a66..f0ab8ba 100644 --- a/core/system.c +++ b/core/system.c @@ -27,6 +27,7 @@ #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" +#include "core/pio.h" /* Private defines */ @@ -270,11 +271,28 @@ void io_config_clk_off(void) /* This is mainly a debug feature, but can be used to provide a clock to an * external peripheral */ /* Note that the CLK_Out pin PIO0_12 is multiplexed with ISP mode selection on reset */ +extern struct pio clkout_pin[]; + void clkout_on(uint32_t src, uint32_t div) { + struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL; + + /* Only one possible pin, and no specific configuration */ + config_pio(&clkout_pin[0], 0); + + /* Select clk_out clock source */ + sys_ctrl->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; } 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; } diff --git a/include/core/lpc_regs_12xx.h b/include/core/lpc_regs_12xx.h index 80dafb5..5070a5c 100644 --- a/include/core/lpc_regs_12xx.h +++ b/include/core/lpc_regs_12xx.h @@ -199,6 +199,10 @@ struct lpc_sys_control #define LPC_DEEP_SLEEP_CFG_NOWDTLOCK_BOD_ON 0x0000FFF7 #define LPC_DEEP_SLEEP_CFG_NOWDTLOCK_BOD_OFF 0x0000FFFF +#define LPC_CLKOUT_SRC_IRC_OSC 0x00 +#define LPC_CLKOUT_SRC_XTAL_OSC 0x01 +#define LPC_CLKOUT_SRC_WATCHDOG_OSC 0x02 +#define LPC_CLKOUT_SRC_MAIN_CLK 0x03 /***************************************************************************** */ -- 2.43.0