From d5ee5fef3e33c7fe634a0b416394be9a5aacaf60 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 25 Apr 2011 22:08:30 -0400 Subject: Adding rcc_dev_clk(), an accessor for a peripheral's clock line. --- libmaple/rcc.c | 23 +++++++++++++++-------- libmaple/rcc.h | 8 ++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'libmaple') diff --git a/libmaple/rcc.c b/libmaple/rcc.c index 78abbcf..efb2599 100644 --- a/libmaple/rcc.c +++ b/libmaple/rcc.c @@ -32,14 +32,12 @@ #include "rcc.h" #include "bitband.h" -enum { - APB1, - APB2, - AHB -}; +#define APB1 RCC_APB1 +#define APB2 RCC_APB2 +#define AHB RCC_AHB struct rcc_dev_info { - const uint8 clk_domain; + const rcc_clk_domain clk_domain; const uint8 line_num; }; @@ -149,7 +147,7 @@ void rcc_clk_enable(rcc_clk_id device) { [AHB] = &RCC_BASE->AHBENR, }; - uint8 clk_domain = rcc_dev_table[device].clk_domain; + rcc_clk_domain clk_domain = rcc_dev_clk(device); __io uint32* enr = (__io uint32*)enable_regs[clk_domain]; uint8 lnum = rcc_dev_table[device].line_num; @@ -166,7 +164,7 @@ void rcc_reset_dev(rcc_clk_id device) { [APB2] = &RCC_BASE->APB2RSTR, }; - uint8 clk_domain = rcc_dev_table[device].clk_domain; + rcc_clk_domain clk_domain = rcc_dev_clk(device); __io void* addr = (__io void*)reset_regs[clk_domain]; uint8 lnum = rcc_dev_table[device].line_num; @@ -174,6 +172,15 @@ void rcc_reset_dev(rcc_clk_id device) { bb_peri_set_bit(addr, lnum, 0); } +/** + * @brief Get a device's clock domain + * @param device Device whose clock domain to return + * @return Device's clock source + */ +rcc_clk_domain rcc_dev_clk(rcc_clk_id device) { + return rcc_dev_table[device].clk_domain; +} + /** * @brief Set the divider on a device prescaler * @param prescaler prescaler to set diff --git a/libmaple/rcc.h b/libmaple/rcc.h index 91f77d0..08f8977 100644 --- a/libmaple/rcc.h +++ b/libmaple/rcc.h @@ -484,6 +484,14 @@ void rcc_clk_init(rcc_sysclk_src sysclk_src, void rcc_clk_enable(rcc_clk_id device); void rcc_reset_dev(rcc_clk_id device); +typedef enum rcc_clk_domain { + RCC_APB1, + RCC_APB2, + RCC_AHB +} rcc_clk_domain; + +rcc_clk_domain rcc_dev_clk(rcc_clk_id device); + /** * Prescaler identifiers * @see rcc_set_prescaler() -- cgit v1.2.3