Skip to content

Commit

Permalink
semaphore handling added for SPI interface
Browse files Browse the repository at this point in the history
  • Loading branch information
gschorcht committed Jan 5, 2018
1 parent 37a0ce5 commit 3271b58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion components/esp8266_wrapper/esp8266_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ int i2c_slave_read (uint8_t bus, uint8_t addr, const uint8_t *reg,

// esp-open-rtos SPI interface wrapper

#define SPI_MAX_BUS 3 // ESP32 features three SPIs (SPI, HSPI and VSPI)
#define SPI_MAX_BUS 3 // ESP32 features three SPIs (SPI_HOST, HSPI_HOST and VSPI_HOST)
#define SPI_MAX_CS 34 // GPIO 33 is the last port that can be used as output

SemaphoreHandle_t spi_semaphores[SPI_MAX_BUS] = { 0 };
spi_device_handle_t spi_handles[SPI_MAX_CS] = { 0 };

bool spi_bus_init (spi_host_device_t host, uint8_t sclk , uint8_t miso, uint8_t mosi)
Expand Down
7 changes: 7 additions & 0 deletions components/esp8266_wrapper/esp8266_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ bool spi_device_init (uint8_t bus, uint8_t cs);
size_t spi_transfer_pf(uint8_t bus, uint8_t cs,
const uint8_t *mosi, uint8_t *miso, uint16_t len);

extern SemaphoreHandle_t spi_semaphores[];

// platform specific definitions
#define spi_semaphore_take(d) if (d) xSemaphoreTake(spi_semaphores[d->bus], portMAX_DELAY)
#define spi_semaphore_give(d) if (d) xSemaphoreGive(spi_semaphores[d->bus])
#define spi_semaphore_init(d) if (d && !spi_semaphores[d->bus]) spi_semaphores[d->bus] = xSemaphoreCreateMutex()

/*
* freertos api wrapper
*/
Expand Down

0 comments on commit 3271b58

Please sign in to comment.