unleashed-firmware/firmware/targets/f4/api-hal/api-hal-spi.c
DrZlo13 8b6e7fd4ae
FL-443 Move sd card to second spi (#271)
* sd card spi 2 fix, add spi mgr
2020-12-19 13:52:17 +06:00

32 lines
No EOL
721 B
C

#include "api-hal-spi.h"
osMutexId_t spi_mutex_r;
osMutexId_t spi_mutex_d;
extern SPI_HandleTypeDef SPI_R;
extern SPI_HandleTypeDef SPI_D;
void api_hal_spi_init() {
spi_mutex_r = osMutexNew(NULL);
spi_mutex_d = osMutexNew(NULL);
}
void api_hal_spi_lock(SPI_HandleTypeDef* spi) {
if(spi == &SPI_D) {
osMutexAcquire(spi_mutex_d, osWaitForever);
} else if(spi == &SPI_R) {
osMutexAcquire(spi_mutex_r, osWaitForever);
} else {
Error_Handler();
}
}
void api_hal_spi_unlock(SPI_HandleTypeDef* spi) {
if(spi == &SPI_D) {
osMutexRelease(spi_mutex_d);
} else if(spi == &SPI_R) {
osMutexRelease(spi_mutex_r);
} else {
Error_Handler();
}
}