add error checks of rt_mutex_take()

This commit is contained in:
Xinrong Han 2021-01-04 17:08:56 +08:00
parent 0f9d1ac282
commit 3f1407827d
5 changed files with 110 additions and 11 deletions

View File

@ -312,8 +312,19 @@ struct pbuf *rt_cme_eth_rx(rt_device_t dev)
ETH_RX_DESC *desc;
uint32_t framelength;
struct rt_cme_eth * cme_eth = (struct rt_cme_eth *)dev;
rt_err_t result;
rt_mutex_take(&cme_eth->lock, RT_WAITING_FOREVER);
result = rt_mutex_take(&cme_eth->lock, RT_WAITING_FOREVER);
if (result == -RT_ETIMEOUT)
{
rt_kprintf("Take mutex time out.\n");
goto _exit;
}
else if (result == -RT_ERROR)
{
rt_kprintf("Take mutex error.\n");
goto _exit;
}
desc = ETH_AcquireFreeRxDesc();
if(desc == RT_NULL)

View File

@ -87,7 +87,10 @@ static rt_size_t fh_i2c_xfer(struct rt_i2c_bus_device *dev,
rt_completion_init(&i2c_drv->transfer_completion);
ret = rt_mutex_take(i2c_drv->lock, RT_WAITING_FOREVER );
ret = rt_mutex_take(i2c_drv->lock, RT_WAITING_FOREVER);
if (ret != RT_EOK) {
goto done;
}
i2c_drv->msgs = msgs;
i2c_drv->msgs_num = num;

View File

@ -52,8 +52,19 @@ static rt_size_t rt_mci_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_siz
{
rt_uint8_t status = kStatus_Success;
struct mci_device *mci = (struct mci_device *)dev;
int ret;
rt_mutex_take(&mci->lock, RT_WAITING_FOREVER);
ret = rt_mutex_take(&mci->lock, RT_WAITING_FOREVER);
if (ret == -RT_ETIMEOUT)
{
rt_kprintf("Take mutex time out.\n");
return ret;
}
else if (ret == -RT_ERROR)
{
rt_kprintf("Take mutex error.\n");
return ret;
}
{
/* non-aligned. */
@ -66,7 +77,7 @@ static rt_size_t rt_mci_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_siz
for(i=0; i<size; i++)
{
status=SD_ReadBlocks(&mci->card, sdio_buffer, sector_adr, 1);
status = SD_ReadBlocks(&mci->card, sdio_buffer, sector_adr, 1);
memcpy(copy_buffer, sdio_buffer, mci->card.blockSize);
sector_adr ++;
@ -85,8 +96,19 @@ static rt_size_t rt_mci_write(rt_device_t dev, rt_off_t pos, const void *buffer,
{
rt_uint8_t status = kStatus_Success;
struct mci_device *mci = (struct mci_device *)dev;
int ret;
rt_mutex_take(&mci->lock, RT_WAITING_FOREVER);
ret = rt_mutex_take(&mci->lock, RT_WAITING_FOREVER);
if (ret == -RT_ETIMEOUT)
{
rt_kprintf("Take mutex time out.\n");
return ret;
}
else if (ret == -RT_ERROR)
{
rt_kprintf("Take mutex error.\n");
return ret;
}
{
/* non-aligned. */

View File

@ -58,7 +58,17 @@ static int sst25vfxx_read(struct rt_mtd_nor_device *device, rt_off_t position, r
sst25 = SST25_MTD(device);
RT_ASSERT(sst25 != RT_NULL);
rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
result = rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
if (result == -RT_ETIMEOUT)
{
rt_kprintf("Take mutex time out.\n");
return result;
}
else if (result == -RT_ERROR)
{
rt_kprintf("Take mutex error.\n");
return result;
}
fseek(sst25->file, position, SEEK_SET);
result = fread(data, size, 1, sst25->file);
@ -78,7 +88,17 @@ static int sst25vfxx_write(struct rt_mtd_nor_device *device, rt_off_t position,
sst25 = SST25_MTD(device);
RT_ASSERT(sst25 != RT_NULL);
rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
result = rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
if (result == -RT_ETIMEOUT)
{
rt_kprintf("Take mutex time out.\n");
return result;
}
else if (result == -RT_ERROR)
{
rt_kprintf("Take mutex error.\n");
return result;
}
fseek(sst25->file, position, SEEK_SET);
result = fwrite(data, size, 1, sst25->file);
@ -99,7 +119,17 @@ static rt_err_t sst25vfxx_erase_block(struct rt_mtd_nor_device *device, rt_off_t
RT_ASSERT(sst25 != RT_NULL);
rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
result = rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
if (result == -RT_ETIMEOUT)
{
rt_kprintf("Take mutex time out.\n");
return -RT_ETIMEOUT;
}
else if (result == -RT_ERROR)
{
rt_kprintf("Take mutex error.\n");
return -RT_ERROR;
}
memset(block_buffer, 0xFF, BLOCK_SIZE);
fseek(sst25->file, offset, SEEK_SET);

View File

@ -32,7 +32,18 @@ static rt_size_t swm320_read(struct rt_mtd_nor_device *device,
rt_uint8_t *data,
rt_size_t size)
{
rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
int ret = rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
if (ret == -RT_ETIMEOUT)
{
rt_kprintf("Take mutex time out.\n");
return ret;
}
else if (ret == -RT_ERROR)
{
rt_kprintf("Take mutex error.\n");
return ret;
}
memcpy(data, ((const void *)(NORFLM_BASE + position)), size);
rt_mutex_release(&flash_lock);
return size;
@ -45,7 +56,18 @@ static rt_size_t swm320_write(struct rt_mtd_nor_device *device,
{
rt_size_t i;
const rt_uint16_t *hwdata = (const rt_uint16_t *)data;
rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
int ret = rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
if (ret == -RT_ETIMEOUT)
{
rt_kprintf("Take mutex time out.\n");
return ret;
}
else if (ret == -RT_ERROR)
{
rt_kprintf("Take mutex error.\n");
return ret;
}
for (i = 0; i < size / 2; i++)
{
NORFL_Write(position, hwdata[i]);
@ -59,7 +81,18 @@ static rt_err_t swm320_erase_block(struct rt_mtd_nor_device *device,
rt_off_t offset,
rt_uint32_t length)
{
rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
rt_err_t ret = rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
if (ret == -RT_ETIMEOUT)
{
rt_kprintf("Take mutex time out.\n");
return ret;
}
else if (ret == -RT_ERROR)
{
rt_kprintf("Take mutex error.\n");
return ret;
}
NORFL_SectorErase(offset);
rt_mutex_release(&flash_lock);
return RT_EOK;