/*---------------------------------------------------------------------------*/ void lpm_init() { list_init(modules_list); /* Always wake up on any DIO edge detection */ ti_lib_aon_event_mcu_wake_up_set(AON_EVENT_MCU_WU2, AON_EVENT_IO); }
/*---------------------------------------------------------------------------*/ void cc26xx_rtc_init(void) { uint32_t compare_value; bool interrupts_disabled; /* Disable and clear interrupts */ interrupts_disabled = ti_lib_int_master_disable(); ti_lib_aon_rtc_disable(); ti_lib_aon_rtc_event_clear(AON_RTC_CH0); ti_lib_aon_rtc_event_clear(AON_RTC_CH2); /* Setup the wakeup event */ ti_lib_aon_event_mcu_wake_up_set(AON_EVENT_MCU_WU0, AON_EVENT_RTC0); ti_lib_aon_event_mcu_wake_up_set(AON_EVENT_MCU_WU1, AON_EVENT_RTC2); ti_lib_aon_rtc_combined_event_config(AON_RTC_CH0 | AON_RTC_CH2); /* Configure channel 2 in continuous compare, 128 ticks / sec */ ti_lib_aon_rtc_inc_value_ch2_set(RTIMER_SECOND / CLOCK_SECOND); ti_lib_aon_rtc_mode_ch2_set(AON_RTC_MODE_CH2_CONTINUOUS); compare_value = (RTIMER_SECOND / CLOCK_SECOND) + ti_lib_aon_rtc_current_compare_value_get(); ti_lib_aon_rtc_compare_value_set(AON_RTC_CH2, compare_value); /* Enable channel 2 and the RTC */ ti_lib_aon_rtc_channel_enable(AON_RTC_CH2); ti_lib_aon_rtc_enable(); ti_lib_int_enable(INT_AON_RTC); /* Re-enable interrupts */ if(!interrupts_disabled) { ti_lib_int_master_enable(); } }
/*---------------------------------------------------------------------------*/ void lpm_shutdown(uint32_t wakeup_pin, uint32_t io_pull, uint32_t wake_on) { lpm_registered_module_t *module; int i; uint32_t io_cfg = (IOC_STD_INPUT & ~IOC_IOPULL_M) | io_pull | wake_on; /* This procedure may not be interrupted */ ti_lib_int_master_disable(); /* Disable the RTC */ ti_lib_aon_rtc_disable(); ti_lib_aon_rtc_event_clear(AON_RTC_CH0); ti_lib_aon_rtc_event_clear(AON_RTC_CH1); ti_lib_aon_rtc_event_clear(AON_RTC_CH2); /* Reset AON even fabric to default wakeup sources */ for(i = AON_EVENT_MCU_WU0; i <= AON_EVENT_MCU_WU3; i++) { ti_lib_aon_event_mcu_wake_up_set(i, AON_EVENT_NONE); } for(i = AON_EVENT_AUX_WU0; i <= AON_EVENT_AUX_WU2; i++) { ti_lib_aon_event_aux_wake_up_set(i, AON_EVENT_NONE); } ti_lib_sys_ctrl_aon_sync(); watchdog_periodic(); /* Notify all modules that we're shutting down */ for(module = list_head(modules_list); module != NULL; module = module->next) { if(module->shutdown) { module->shutdown(LPM_MODE_SHUTDOWN); } } /* Configure the wakeup trigger */ if(wakeup_pin != IOID_UNUSED) { ti_lib_gpio_dir_mode_set((1 << wakeup_pin), GPIO_DIR_MODE_IN); ti_lib_ioc_port_configure_set(wakeup_pin, IOC_PORT_GPIO, io_cfg); } /* Freeze I/O latches in AON */ ti_lib_aon_ioc_freeze_enable(); /* Turn off RFCORE, SERIAL and PERIPH PDs. This will happen immediately */ ti_lib_prcm_power_domain_off(PRCM_DOMAIN_RFCORE | PRCM_DOMAIN_SERIAL | PRCM_DOMAIN_PERIPH); oscillators_switch_to_hf_rc(); oscillators_select_lf_rcosc(); /* Configure clock sources for MCU and AUX: No clock */ ti_lib_aon_wuc_mcu_power_down_config(AONWUC_NO_CLOCK); ti_lib_aon_wuc_aux_power_down_config(AONWUC_NO_CLOCK); /* Disable SRAM and AUX retentions */ ti_lib_aon_wuc_mcu_sram_config(0); ti_lib_aon_wuc_aux_sram_config(false); /* * Request CPU, SYSBYS and VIMS PD off. * This will only happen when the CM3 enters deep sleep */ ti_lib_prcm_power_domain_off(PRCM_DOMAIN_CPU | PRCM_DOMAIN_VIMS | PRCM_DOMAIN_SYSBUS); /* Request JTAG domain power off */ ti_lib_aon_wuc_jtag_power_off(); /* Turn off AUX */ ti_lib_aux_wuc_power_ctrl(AUX_WUC_POWER_OFF); ti_lib_aon_wuc_domain_power_down_enable(); while(ti_lib_aon_wuc_power_status_get() & AONWUC_AUX_POWER_ON); /* * Request MCU VD power off. * This will only happen when the CM3 enters deep sleep */ ti_lib_prcm_mcu_power_off(); /* Set MCU wakeup to immediate and disable virtual power off */ ti_lib_aon_wuc_mcu_wake_up_config(MCU_IMM_WAKE_UP); ti_lib_aon_wuc_mcu_power_off_config(MCU_VIRT_PWOFF_DISABLE); /* Latch the IOs in the padring and enable I/O pad sleep mode */ ti_lib_pwr_ctrl_io_freeze_enable(); /* Turn off VIMS cache, CRAM and TRAM - possibly not required */ ti_lib_prcm_cache_retention_disable(); ti_lib_vims_mode_set(VIMS_BASE, VIMS_MODE_OFF); /* Enable shutdown and sync AON */ ti_lib_aon_wuc_shut_down_enable(); ti_lib_sys_ctrl_aon_sync(); /* Deep Sleep */ ti_lib_prcm_deep_sleep(); }