Power: Restore peripheral clocks when starting HackRF firmware.

HackRF firmware assumes state specified in user manual, where all(?) peripheral clocks are enabled.
This commit is contained in:
Jared Boone 2017-07-18 21:47:04 -07:00
parent aa189a3462
commit ddd951f2d8

View File

@ -157,6 +157,59 @@ Backlight* backlight() {
: static_cast<portapack::Backlight*>(&backlight_on_off); : static_cast<portapack::Backlight*>(&backlight_on_off);
} }
static void configure_unused_mcu_peripherals(const bool enabled) {
/* Disabling these peripherals reduces "idle" (PortaPack at main
* menu) current by 42mA.
*/
/* Some surprising peripherals in use by PortaPack firmware:
*
* RITIMER: M0 SysTick substitute (because M0 has no SysTick)
* TIMER3: M0 cycle/PCLK counter
*/
const uint32_t clock_run_state = enabled ? 1 : 0;
LPC_CCU1->CLK_APB3_I2C1_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_APB3_DAC_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_APB3_CAN0_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_APB1_MOTOCON_PWM_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_APB1_CAN1_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_LCD_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_ETHERNET_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_USB0_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_EMC_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_SCT_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_USB1_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_EMCDIV_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_WWDT_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_USART0_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_UART1_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_SSP0_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_TIMER1_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_USART2_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_USART3_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_TIMER2_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_M4_QEI_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_USB1_CFG.RUN = clock_run_state;
LPC_CCU1->CLK_SPI_CFG.RUN = clock_run_state;
LPC_CCU2->CLK_APB2_USART3_CFG.RUN = clock_run_state;
LPC_CCU2->CLK_APB2_USART2_CFG.RUN = clock_run_state;
LPC_CCU2->CLK_APB0_UART1_CFG.RUN = clock_run_state;
LPC_CCU2->CLK_APB0_USART0_CFG.RUN = clock_run_state;
LPC_CCU2->CLK_APB0_SSP0_CFG.RUN = clock_run_state;
}
static void disable_unused_mcu_peripheral_clocks() {
configure_unused_mcu_peripherals(false);
}
static void enable_unused_mcu_peripheral_clocks() {
configure_unused_mcu_peripherals(true);
}
static void shutdown_base() { static void shutdown_base() {
clock_manager.shutdown(); clock_manager.shutdown();
@ -167,49 +220,11 @@ static void shutdown_base() {
systick_stop(); systick_stop();
enable_unused_mcu_peripheral_clocks();
hackrf::one::reset(); hackrf::one::reset();
} }
static void turn_off_unused_mcu_peripherals() {
/* RITIMER: M0 SysTick substitute (because M0 has no SysTick)
* TIMER3: M0 cycle/PCLK counter
*/
// Reclaim about 42mA when idle at top menu.
LPC_CCU1->CLK_APB3_I2C1_CFG.RUN = 0;
LPC_CCU1->CLK_APB3_DAC_CFG.RUN = 0;
LPC_CCU1->CLK_APB3_CAN0_CFG.RUN = 0;
LPC_CCU1->CLK_APB1_MOTOCON_PWM_CFG.RUN = 0;
LPC_CCU1->CLK_APB1_CAN1_CFG.RUN = 0;
LPC_CCU1->CLK_M4_LCD_CFG.RUN = 0;
LPC_CCU1->CLK_M4_ETHERNET_CFG.RUN = 0;
LPC_CCU1->CLK_M4_USB0_CFG.RUN = 0;
LPC_CCU1->CLK_M4_EMC_CFG.RUN = 0;
LPC_CCU1->CLK_M4_SCT_CFG.RUN = 0;
LPC_CCU1->CLK_M4_USB1_CFG.RUN = 0;
LPC_CCU1->CLK_M4_EMCDIV_CFG.RUN = 0;
LPC_CCU1->CLK_M4_WWDT_CFG.RUN = 0;
LPC_CCU1->CLK_M4_USART0_CFG.RUN = 0;
LPC_CCU1->CLK_M4_UART1_CFG.RUN = 0;
LPC_CCU1->CLK_M4_SSP0_CFG.RUN = 0;
LPC_CCU1->CLK_M4_TIMER1_CFG.RUN = 0;
LPC_CCU1->CLK_M4_USART2_CFG.RUN = 0;
LPC_CCU1->CLK_M4_USART3_CFG.RUN = 0;
LPC_CCU1->CLK_M4_TIMER2_CFG.RUN = 0;
LPC_CCU1->CLK_M4_QEI_CFG.RUN = 0;
LPC_CCU1->CLK_USB1_CFG.RUN = 0;
LPC_CCU1->CLK_SPI_CFG.RUN = 0;
LPC_CCU2->CLK_APB2_USART3_CFG.RUN = 0;
LPC_CCU2->CLK_APB2_USART2_CFG.RUN = 0;
LPC_CCU2->CLK_APB0_UART1_CFG.RUN = 0;
LPC_CCU2->CLK_APB0_USART0_CFG.RUN = 0;
LPC_CCU2->CLK_APB0_SSP0_CFG.RUN = 0;
LPC_CREG->CREG0 |= (1 << 5); // Disable USB0 PHY
}
bool init() { bool init() {
for(const auto& pin : pins) { for(const auto& pin : pins) {
pin.init(); pin.init();
@ -235,7 +250,9 @@ bool init() {
| (0U << 15) // SDA: Enable input glitch filter | (0U << 15) // SDA: Enable input glitch filter
; ;
turn_off_unused_mcu_peripherals(); disable_unused_mcu_peripheral_clocks();
LPC_CREG->CREG0 |= (1 << 5); // Disable USB0 PHY
power.init(); power.init();