Skip to content

Commit

Permalink
feat:[drivers][spi] rt_spi_configure 添加互斥保护
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterywolf committed Oct 6, 2024
1 parent 99503d3 commit 36f8f26
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
19 changes: 16 additions & 3 deletions components/drivers/spi/dev_qspi_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@ 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)
{
if (cfg->parent.mode & RT_SPI_CS_HIGH)
rt_pin_write(device->parent.cs_pin, PIN_LOW);
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
rt_pin_write(device->parent.cs_pin, PIN_HIGH);
{
return result;
}
}

/* If the configurations are the same, we don't need to set again. */
Expand Down
19 changes: 16 additions & 3 deletions components/drivers/spi/dev_spi_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,23 @@ rt_err_t rt_spi_configure(struct rt_spi_device *device,
/* reset the CS pin */
if (device->cs_pin != PIN_NONE)
{
if (cfg->mode & RT_SPI_CS_HIGH)
rt_pin_write(device->cs_pin, PIN_LOW);
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
rt_pin_write(device->cs_pin, PIN_HIGH);
{
return result;
}
}

/* If the configurations are the same, we don't need to set again. */
Expand Down

0 comments on commit 36f8f26

Please sign in to comment.