初级会员
- 积分
- 198
- 金钱
- 198
- 注册时间
- 2018-7-8
- 在线时间
- 57 小时
|
5金钱
bool i2cdrvMessageTransfer(I2cDrv* i2c, I2cMessage* message)
{
bool status = false;
xSemaphoreTake(i2c->isBusFreeMutex, portMAX_DELAY); // Protect message data
// Copy message
memcpy((char*)&i2c->txMessage, (char*)message, sizeof(I2cMessage));
// We can now start the ISR sending this message.
i2cdrvStartTransfer(i2c);//éèÖÃDMA IIC
// Wait for transaction to be done
if (xSemaphoreTake(i2c->isBusFreeSemaphore, I2C_MESSAGE_TIMEOUT) == pdTRUE)
{
if (i2c->txMessage.status == i2cAck)
{
status = true;
}
}
else
{
i2cdrvClearDMA(i2c);//Çå3yDMAÖD¶Ï±êÖ¾
i2cdrvTryToRestartBus(i2c);//ÖØÆôIIC×üÏß
//TODO: If bus is really hanged... fail safe
}
xSemaphoreGive(i2c->isBusFreeMutex);
return status;
}
这是原子四轴里面IIC通过DMA获取数据的子程序,我想问一下在程序开头
xSemaphoreTake(i2c->isBusFreeMutex, portMAX_DELAY); 获取信号量,
程序结尾xSemaphoreGive(i2c->isBusFreeMutex);
又释放信号量 这样做的意义在哪 哪位大佬知道
|
|