//============================================================================= // hal_SdioWakeUp //----------------------------------------------------------------------------- /// This function requests a resource of #HAL_SYS_FREQ_52M. /// hal_SdioSleep() must be called before any other //============================================================================= PUBLIC VOID hal_SdioWakeUp(VOID) { // Take a resource (The idea is to be able to get a 25Mhz clock) // hwp_sysCtrl->Clk_Per_Enable |= SYS_CTRL_ENABLE_PER_SDMMC2;//modify 2012-02-24 ,wuys // wifi_i2c_rf_write_data(0x3f, 0x0000,1); hal_SysRequestFreq(HAL_SYS_FREQ_SDMMC2, HAL_SYS_FREQ_104M, hal_SdioUpdateDivider); UINT32 scStatus = hal_SysEnterCriticalSection(); // Make sure the last clock is set hal_SdioUpdateDivider(hal_SysGetFreq()); hal_SysExitCriticalSection(scStatus); // hwp_configRegs->GPIO_Mode &= ~CFG_REGS_MODE_PIN_SPI1_CLK;//modify 2012-02-24 ,wuys #if 0 hwp_configRegs->GPIO_Mode &= ~0x1D000;;//modify 2012-02-24 ,wuys // hwp_configRegs->Alt_mux_select &= ~0x800;//modify 2012-02-24 ,wuys hwp_configRegs->Alt_mux_select |= 0x800;//modify 2012-02-24 ,wuys #endif //hal_SdioGpioClr(); //hwp_gpio->gpio_oen_set_out //hwp_sysCtrl->Clk_Per_Enable |= SYS_CTRL_ENABLE_PER_SDMMC2;//modify 2012-02-24 ,wuys //hal_SdioSetClk(2000000); }
PUBLIC VOID hal_SdioOpen(UINT8 clk_adj, HAL_SDIO_IRQ_HANDLER_T handler) { g_halSdioRegistry = handler; // Take the module out of reset hwp_sysCtrl->REG_DBG = SYS_CTRL_PROTECT_UNLOCK; hwp_sysCtrl->BB_Rst_Clr = SYS_CTRL_CLR_RST_SDMMC2; hwp_sysCtrl->Clk_Per_Enable |= SYS_CTRL_ENABLE_PER_SDMMC2; hwp_sysCtrl->Clk_Sys_Mode |= SYS_CTRL_MODE_SYS_PCLK_DATA_MANUAL; // hwp_sysCtrl->Sys_Rst_Clr = SYS_CTRL_CLR_RST_SDMMC2; hwp_sysCtrl->REG_DBG = SYS_CTRL_PROTECT_LOCK; // We don't use interrupts. // hwp_sdmmc2->SDMMC2_INT_MASK = 0x80; hwp_sdmmc2->SDMMC2_INT_MASK = 0x00; hwp_sdmmc2->SDMMC2_MCLK_ADJUST = clk_adj; // Take a resource (The idea is to be able to get a 25Mhz clock) hal_SysRequestFreq(HAL_SYS_FREQ_SDMMC2, HAL_SYS_FREQ_104M, hal_SdioUpdateDivider); UINT32 scStatus = hal_SysEnterCriticalSection(); // Make sure the last clock is set hal_SdioUpdateDivider(hal_SysGetFreq()); hal_SysExitCriticalSection(scStatus); // pmd_EnablePower(PMD_POWER_SDMMC2, TRUE); }
// ============================================================================= // hal_SdioSetClk // ----------------------------------------------------------------------------- /// Set the SDMMC2 clock frequency to something inferior but close to that, /// taking into account system frequency. // ============================================================================= PUBLIC VOID hal_SdioSetClk(UINT32 clock) { // TODO Add assert to stay on supported values ? g_halSdioFreq = clock; UINT32 scStatus = hal_SysEnterCriticalSection(); // Update the divider takes care of the registers configuration hal_SdioUpdateDivider(hal_SysGetFreq()); hal_SysExitCriticalSection(scStatus); }
// ============================================================================ // hal_I2cOpen // ---------------------------------------------------------------------------- /// This function opens the I2C modules and enable the use of its API. /// /// @param id ID of the I2C bus /// @param freq Frequency of the I2C bus // ============================================================================ PUBLIC HAL_ERR_T hal_I2cOpen(HAL_I2C_BUS_ID_T id) { HAL_ASSERT(id < HAL_I2C_BUS_ID_QTY, g_halI2cErrStrIdOutOfRange, id); if (id == HAL_I2C_BUS_ID_1) { HAL_ASSERT(g_halCfg->i2cCfg.i2cUsed == TRUE, g_halI2cErrStrIdNotUsed, id); } #if (CHIP_ASIC_ID != CHIP_ASIC_ID_GREENSTONE) else if (id == HAL_I2C_BUS_ID_2) { HAL_ASSERT(g_halCfg->i2cCfg.i2c2Used == TRUE, g_halI2cErrStrIdNotUsed, id); } else // if (id == HAL_I2C_BUS_ID_3) { HAL_ASSERT(g_halCfg->i2cCfg.i2c3Used == TRUE, g_halI2cErrStrIdNotUsed, id); } #endif // (CHIP_ASIC_ID != CHIP_ASIC_ID_GREENSTONE) // I2C Pin's are not in GPIO mode // TODO Implement once the register is readable HAL_I2C_TAKE_BUS(id); #if (CHIP_ASIC_ID == CHIP_ASIC_ID_GALLITE) // I2C needs 2 sets of power supply, one for I/O, and the other for pull-up resistor pmd_EnablePower(PMD_POWER_I2C, TRUE); #endif // (CHIP_ASIC_ID == CHIP_ASIC_ID_GALLITE) HWP_I2C_MASTER_T* CONST i2cMaster = g_halI2cMasterAddr[id]; // I2C is initialized at the first open if (!g_halI2cOpened[id]) { // Register Bps as a global variable. if (id == HAL_I2C_BUS_ID_1) { g_halI2cBps[id] = g_halCfg->i2cCfg.i2cBps; } #if (CHIP_ASIC_ID != CHIP_ASIC_ID_GREENSTONE) else if (id == HAL_I2C_BUS_ID_2) { g_halI2cBps[id] = g_halCfg->i2cCfg.i2c2Bps; } else // if (id == HAL_I2C_BUS_ID_3) { g_halI2cBps[id] = g_halCfg->i2cCfg.i2c3Bps; } #endif // (CHIP_ASIC_ID != CHIP_ASIC_ID_GREENSTONE) // Set initial clock divider hal_I2cUpdateDivider(hal_SysGetFreq()); // Enable the I2c i2cMaster->CTRL |= I2C_MASTER_EN; i2cMaster->CMD = I2C_MASTER_STO; while(!(i2cMaster -> STATUS & I2C_MASTER_IRQ_STATUS)); i2cMaster->IRQ_CLR = I2C_MASTER_IRQ_CLR; g_halI2cOpened[id] = TRUE; } // When I2C is powered off, some I2C slave devices might see a fake // start bit in the I2C bus. Then after I2C is powered on again, // the device might interpret the signal in a wrong manner. // Send a series of '1' to this I2C bus so as to avoid the possible // wrong interpretation. while(i2cMaster -> STATUS & I2C_MASTER_TIP); i2cMaster->TXRX_BUFFER = 0xFE; i2cMaster->CMD = I2C_MASTER_WR|I2C_MASTER_STA; while(i2cMaster -> STATUS & I2C_MASTER_TIP); i2cMaster->TXRX_BUFFER = 0xFF; i2cMaster->CMD = I2C_MASTER_WR; while(i2cMaster -> STATUS & I2C_MASTER_TIP); i2cMaster->TXRX_BUFFER = 0xFF; i2cMaster->CMD = I2C_MASTER_WR; while(i2cMaster -> STATUS & I2C_MASTER_TIP); i2cMaster->TXRX_BUFFER = 0xFF; i2cMaster->CMD = I2C_MASTER_WR|I2C_MASTER_STO; // Allow HAL_I2C_RELEASE_BUS(id); return HAL_ERR_NO; }