feat:[drivers][spi] rt_spi_configure 添加互斥保护
This commit is contained in:
parent
99503d3ff6
commit
36f8f266e9
|
@ -17,12 +17,25 @@ rt_err_t rt_qspi_configure(struct rt_qspi_device *device, struct rt_qspi_configu
|
|||
|
||||
/* reset the CS pin */
|
||||
if (device->parent.cs_pin != PIN_NONE)
|
||||
{
|
||||
rt_err_t result = rt_mutex_take(&(device->parent.bus->lock), RT_WAITING_FOREVER);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
if (cfg->parent.mode & RT_SPI_CS_HIGH)
|
||||
{
|
||||
rt_pin_write(device->parent.cs_pin, PIN_LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(device->parent.cs_pin, PIN_HIGH);
|
||||
}
|
||||
rt_mutex_release(&(device->parent.bus->lock));
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the configurations are the same, we don't need to set again. */
|
||||
if (device->config.medium_size == cfg->medium_size &&
|
||||
|
|
|
@ -134,12 +134,25 @@ rt_err_t rt_spi_configure(struct rt_spi_device *device,
|
|||
|
||||
/* reset the CS pin */
|
||||
if (device->cs_pin != PIN_NONE)
|
||||
{
|
||||
rt_err_t result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
if (cfg->mode & RT_SPI_CS_HIGH)
|
||||
{
|
||||
rt_pin_write(device->cs_pin, PIN_LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(device->cs_pin, PIN_HIGH);
|
||||
}
|
||||
rt_mutex_release(&(device->bus->lock));
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the configurations are the same, we don't need to set again. */
|
||||
if (device->config.data_width == cfg->data_width &&
|
||||
|
|
Loading…
Reference in New Issue