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
+33 -3
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);