spi synchronization mechanism moved to webguiapp system

This commit is contained in:
Bogdan Pilyugin 2022-12-20 20:35:07 +02:00
parent 0fe87215ef
commit 0c0e089419

View File

@ -57,6 +57,10 @@
static SYS_CONFIG SysConfig;
#define SPI_LOCK_TIMEOUT_MS (1000)
SemaphoreHandle_t xSemaphoreSPIHandle = NULL;
StaticSemaphore_t xSemaphoreSPIBuf;
#define NETWORK_START_TIMEOUT (60)
static int NetworkStartTimeout = 0;
@ -66,6 +70,21 @@ static void InitSysIO(void);
static void InitSysSPI(void);
static void InitSysI2C(void);
esp_err_t spi_device_polling_transmit_synchronized(spi_device_handle_t handle, spi_transaction_t *trans_desc)
{
esp_err_t res;
if (xSemaphoreTake(xSemaphoreSPIHandle,pdMS_TO_TICKS(SPI_LOCK_TIMEOUT_MS)) == pdTRUE)
{
res = spi_device_polling_transmit(handle, trans_desc);
xSemaphoreGive(xSemaphoreSPIHandle);
}
else
{
res = ESP_ERR_TIMEOUT;
}
return res;
}
esp_err_t WebGuiAppInit(void)
{
InitSysIO();
@ -203,6 +222,8 @@ gpio_set_level(CONFIG_ETH_SPI_PHY_RST0_GPIO, 0);
static void InitSysSPI(void)
{
#ifdef CONFIG_WEBGUIAPP_SPI_ENABLE
xSemaphoreSPIHandle = xSemaphoreCreateBinaryStatic(&xSemaphoreSPIBuf);
xSemaphoreGive(xSemaphoreSPIHandle);
spi_bus_config_t buscfg =
{
.miso_io_num = CONFIG_SPI_MISO_GPIO,
@ -436,3 +457,6 @@ void SetUserAppNeedReset(bool res)
{
isUserAppNeedReset = res;
}