/*---------------------------------------------------------------------------*/ void rf_core_power_down() { bool interrupts_disabled = ti_lib_int_master_disable(); ti_lib_int_disable(INT_RF_CPE0); ti_lib_int_disable(INT_RF_CPE1); if(rf_core_is_accessible()) { HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIFG) = 0x0; HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIEN) = 0x0; /* need to send FS_POWERDOWN or analog components will use power */ fs_powerdown(); } /* Shut down the RFCORE clock domain in the MCU VD */ ti_lib_prcm_domain_disable(PRCM_DOMAIN_RFCORE); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()); /* Turn off RFCORE PD */ ti_lib_prcm_power_domain_off(PRCM_DOMAIN_RFCORE); while(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_RFCORE) != PRCM_DOMAIN_POWER_OFF); ti_lib_int_pend_clear(INT_RF_CPE0); ti_lib_int_pend_clear(INT_RF_CPE1); ti_lib_int_enable(INT_RF_CPE0); ti_lib_int_enable(INT_RF_CPE1); if(!interrupts_disabled) { ti_lib_int_master_enable(); } }
/*---------------------------------------------------------------------------*/ static void wakeup_handler(void) { /* Turn on the PERIPH PD */ ti_lib_prcm_power_domain_on(PRCM_DOMAIN_PERIPH); while ((ti_lib_prcm_power_domain_status(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON)) ; }
/*---------------------------------------------------------------------------*/ uint8_t rf_core_is_accessible() { if(ti_lib_prcm_rf_ready() && ti_lib_prcm_power_domain_status(PRCM_DOMAIN_RFCORE) == PRCM_DOMAIN_POWER_ON) { return RF_CORE_ACCESSIBLE; } return RF_CORE_NOT_ACCESSIBLE; }
/*---------------------------------------------------------------------------*/ static void power_domains_on(void) { /* Turn on relevant power domains */ ti_lib_prcm_power_domain_on(PRCM_DOMAINS); /* Wait for domains to power on */ while((ti_lib_prcm_power_domain_status(PRCM_DOMAINS) != PRCM_DOMAIN_POWER_ON)); }
/*---------------------------------------------------------------------------*/ static void power_and_clock(void) { /* Power on the SERIAL PD */ ti_lib_prcm_power_domain_on(PRCM_DOMAIN_SERIAL); while(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_SERIAL) != PRCM_DOMAIN_POWER_ON); /* Enable UART clock in active mode */ ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_UART0); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()); }
/* * Returns 0 if either the SERIAL PD is off, or the PD is on but the run mode * clock is gated. If this function would return 0, accessing UART registers * will return a precise bus fault. If this function returns 1, it is safe to * access UART registers. * * This function only checks the 'run mode' clock gate, since it can only ever * be called with the MCU in run mode. */ static bool accessible(void) { /* First, check the PD */ if(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_SERIAL) != PRCM_DOMAIN_POWER_ON) { return false; } /* Then check the 'run mode' clock gate */ if(!(HWREG(PRCM_BASE + PRCM_O_UARTCLKGR) & PRCM_UARTCLKGR_CLK_EN)) { return false; } return true; }
/*---------------------------------------------------------------------------*/ void board_i2c_wakeup() { /* First, make sure the SERIAL PD is on */ ti_lib_prcm_power_domain_on(PRCM_DOMAIN_SERIAL); while((ti_lib_prcm_power_domain_status(PRCM_DOMAIN_SERIAL) != PRCM_DOMAIN_POWER_ON)); /* Enable the clock to I2C */ ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_I2C0); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()); /* Enable and initialize the I2C master module */ ti_lib_i2c_master_init_exp_clk(I2C0_BASE, ti_lib_sys_ctrl_clock_get(), true); }
/*---------------------------------------------------------------------------*/ int rf_core_power_up() { uint32_t cmd_status; bool interrupts_disabled = ti_lib_int_master_disable(); ti_lib_int_pend_clear(INT_RF_CPE0); ti_lib_int_pend_clear(INT_RF_CPE1); ti_lib_int_disable(INT_RF_CPE0); ti_lib_int_disable(INT_RF_CPE1); /* Enable RF Core power domain */ ti_lib_prcm_power_domain_on(PRCM_DOMAIN_RFCORE); while(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_RFCORE) != PRCM_DOMAIN_POWER_ON); ti_lib_prcm_domain_enable(PRCM_DOMAIN_RFCORE); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()); while(!rf_core_is_accessible()) { PRINTF("rf_core_power_up: Not ready\n"); } HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIFG) = 0x0; HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIEN) = 0x0; ti_lib_int_enable(INT_RF_CPE0); ti_lib_int_enable(INT_RF_CPE1); if(!interrupts_disabled) { ti_lib_int_master_enable(); } /* Let CPE boot */ HWREG(RFC_PWR_NONBUF_BASE + RFC_PWR_O_PWMCLKEN) = RF_CORE_CLOCKS_MASK; /* Send ping (to verify RFCore is ready and alive) */ if(rf_core_send_cmd(CMDR_DIR_CMD(CMD_PING), &cmd_status) != RF_CORE_CMD_OK) { PRINTF("rf_core_power_up: CMD_PING fail, CMDSTA=0x%08lx\n", cmd_status); return RF_CORE_CMD_ERROR; } return RF_CORE_CMD_OK; }