From 5b85962c95f46a035a161d8ae76ee86acada8ae2 Mon Sep 17 00:00:00 2001 From: Mahadevan Mahesh Date: Fri, 12 May 2017 08:30:28 -0500 Subject: [PATCH] LPC: Move platform specific code out of the analog api file Signed-off-by: Mahadevan Mahesh --- .../TARGET_LPCXpresso/mbed_overrides.c | 14 +++++++++++++ .../TARGET_LPCXpresso/mbed_overrides.c | 20 +++++++++++++++++++ .../TARGET_MCUXpresso_MCUS/api/analogin_api.c | 11 ++-------- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/TARGET_LPCXpresso/mbed_overrides.c b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/TARGET_LPCXpresso/mbed_overrides.c index b99f22a95d..3d49a8cca5 100644 --- a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/TARGET_LPCXpresso/mbed_overrides.c +++ b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/TARGET_LPCXpresso/mbed_overrides.c @@ -15,6 +15,7 @@ */ #include "gpio_api.h" #include "clock_config.h" +#include "fsl_power.h" // called before main void mbed_sdk_init() @@ -31,6 +32,19 @@ void NMI_Handler(void) //gpio_init_in(&gpio, PTA4); } +void ADC_ClockPower_Configuration(void) +{ + /* SYSCON power. */ + POWER_DisablePD(kPDRUNCFG_PD_ADC0); /* Power on the ADC converter. */ + POWER_DisablePD(kPDRUNCFG_PD_VD7_ENA); /* Power on the analog power supply. */ + POWER_DisablePD(kPDRUNCFG_PD_VREFP_SW); /* Power on the reference voltage source. */ + POWER_DisablePD(kPDRUNCFG_PD_TEMPS); /* Power on the temperature sensor. */ + + /* Enable the clock. */ + CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); + CLOCK_EnableClock(kCLOCK_Adc0); +} + // Enable the RTC oscillator if available on the board void rtc_setup_oscillator(void) { diff --git a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54608/TARGET_LPCXpresso/mbed_overrides.c b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54608/TARGET_LPCXpresso/mbed_overrides.c index 35afd4e887..b727924a6a 100644 --- a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54608/TARGET_LPCXpresso/mbed_overrides.c +++ b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54608/TARGET_LPCXpresso/mbed_overrides.c @@ -16,6 +16,7 @@ #include "gpio_api.h" #include "clock_config.h" #include "fsl_emc.h" +#include "fsl_power.h" /******************************************************************************* * Definitions @@ -58,6 +59,25 @@ void rtc_setup_oscillator(void) SYSCON->RTCOSCCTRL |= SYSCON_RTCOSCCTRL_EN_MASK; } +void ADC_ClockPower_Configuration(void) +{ + /* SYSCON power. */ + POWER_DisablePD(kPDRUNCFG_PD_VDDA); /* Power on VDDA. */ + POWER_DisablePD(kPDRUNCFG_PD_ADC0); /* Power on the ADC converter. */ + POWER_DisablePD(kPDRUNCFG_PD_VD2_ANA); /* Power on the analog power supply. */ + POWER_DisablePD(kPDRUNCFG_PD_VREFP); /* Power on the reference voltage source. */ + POWER_DisablePD(kPDRUNCFG_PD_TS); /* Power on the temperature sensor. */ + + /* Enable the clock. */ + CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); + + /* CLOCK_AttachClk(kMAIN_CLK_to_ADC_CLK); */ + /* Sync clock source is not used. Using sync clock source and would be divided by 2. + * The divider would be set when configuring the converter. + */ + CLOCK_EnableClock(kCLOCK_Adc0); /* SYSCON->AHBCLKCTRL[0] |= SYSCON_AHBCLKCTRL_ADC0_MASK; */ +} + /* Initialize the external memory. */ void BOARD_InitSDRAM(void) { diff --git a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/api/analogin_api.c b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/api/analogin_api.c index 63bd1c058d..01bd11da78 100644 --- a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/api/analogin_api.c +++ b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/api/analogin_api.c @@ -27,6 +27,7 @@ /* Array of ADC peripheral base address. */ static ADC_Type *const adc_addrs[] = ADC_BASE_PTRS; +extern void ADC_ClockPower_Configuration(void); #define MAX_FADC 6000000 @@ -38,15 +39,7 @@ void analogin_init(analogin_t *obj, PinName pin) uint32_t instance = obj->adc >> ADC_INSTANCE_SHIFT; adc_config_t adc_config; - /* SYSCON power. */ - POWER_DisablePD(kPDRUNCFG_PD_ADC0); /* Power on the ADC converter. */ - POWER_DisablePD(kPDRUNCFG_PD_VD7_ENA); /* Power on the analog power supply. */ - POWER_DisablePD(kPDRUNCFG_PD_VREFP_SW); /* Power on the reference voltage source. */ - POWER_DisablePD(kPDRUNCFG_PD_TEMPS); /* Power on the temperature sensor. */ - - /* Enable the clock. */ - CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); - CLOCK_EnableClock(kCLOCK_Adc0); + ADC_ClockPower_Configuration(); /* Calibration after power up. */ if (!(ADC_DoSelfCalibration(adc_addrs[instance]))) {