Part Number:CC2642ROther Parts Discussed in Thread:SYSBIOS
我需要动态的开关I2C Slave 模式(为了省电)
int8_t hpi_i2c_open()
{
if(m_is_open == 0)
{
Power_setDependency(PowerCC26XX_PERIPH_I2C0);
Power_setConstraint(PowerCC26XX_SB_DISALLOW);
Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
i2cPinHandle = PIN_open(&i2cPinState, i2cPinTable);
if ((PIN_SUCCESS == PINCC26XX_setMux(i2cPinHandle, CONFIG_PIN_2, IOC_PORT_MCU_I2C_MSSCL))
&& (PIN_SUCCESS == PINCC26XX_setMux(i2cPinHandle, CONFIG_PIN_1,IOC_PORT_MCU_I2C_MSSDA))) {
LOGI("I2C PIN set succ.");
} else {
LOGI("I2C PIN set failed.");
}
/* init i2c for slave-mode and enable interrupt */
I2CSlaveInit(I2C0_BASE, slaveAddress);
LOGI("I2CSlaveInit.");
/* Create an RTOS aware hardware interrupt */
Hwi_Params i2cSlave_hwiParams;
Hwi_Params_init(&i2cSlave_hwiParams);
LOGI("Hwi_Params_init.");
i2cSlave_hwiParams.priority = INT_PRI_LEVEL7; //INTERRUPT_PRIORITY;
i2cSlave_hwiHandle = Hwi_create(INT_I2C_IRQ, i2cCB, &i2cSlave_hwiParams,NULL);
LOGI("Hwi_create.");
if (NULL == i2cSlave_hwiHandle) {
//some error occurred
LOGI("i2c init error");
return -1;
}
I2CSlaveIntEnable(I2C0_BASE,
I2C_SLAVE_INT_START | I2C_SLAVE_INT_STOP | I2C_SLAVE_INT_DATA);
m_is_open = 1;
LOGW("i2c open ok!!");
}
return 0;
}
int8_t hpi_i2c_close()
{
if(m_is_open == 1)
{
PIN_close(i2cPinHandle);
Hwi_delete(i2cSlave_hwiHandle);
Power_releaseDependency(PowerCC26XX_PERIPH_I2C0);
Power_releaseConstraint(PowerCC26XX_SB_DISALLOW);
Power_releaseConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
m_is_open = 0;
LOGW("i2c close ok!!");
}
return 0;
}
代码如上。
进行open ->close ->open 时 卡在Hwi_create里面。请问怎样解决。
Cherry Zhou:
您好我们已收到您的问题并升级到英文论坛寻求帮助,如有答复将尽快回复您。谢谢!
,
Cherry Zhou:
您好,
不建议删除和重新创建 Hwi。我们建议您使用 Hwi_disable 和 Hwi_enable。这将实现类似的功能。您还可以参考 TI-RTOS Kernel User's Guide 和 TI-RTOS Kernel Runtime APIs and Configuration (module ti.sysbios.hal.Hwi)。
如果仍无法解决您的问题,您是否能够提供更多debug信息或代码的轻量级示例,方便工程师重现故障?