reimplementing semephore and bus locking seems to have helped overall stability, particularly on first init
This commit is contained in:
parent
dc78e9b137
commit
8f07873624
1 changed files with 7 additions and 7 deletions
|
@ -31,7 +31,7 @@ static TaskHandle_t dio_task_handle;
|
|||
static SemaphoreHandle_t spi_semaphore;
|
||||
|
||||
uint8_t lora32_read_reg(lora32_cfg_t *lora, uint8_t address) {
|
||||
//xSemaphoreTake(spi_semaphore, portMAX_DELAY);
|
||||
xSemaphoreTake(spi_semaphore, portMAX_DELAY);
|
||||
|
||||
spi_transaction_t t;
|
||||
memset(&t, 0, sizeof(spi_transaction_t));
|
||||
|
@ -45,13 +45,13 @@ uint8_t lora32_read_reg(lora32_cfg_t *lora, uint8_t address) {
|
|||
|
||||
ESP_LOGV(TAG, "<%2X<%2X", address, t.rx_data[1]);
|
||||
|
||||
//xSemaphoreGive(spi_semaphore);
|
||||
xSemaphoreGive(spi_semaphore);
|
||||
|
||||
return t.rx_data[1];
|
||||
}
|
||||
|
||||
void lora32_write_reg(lora32_cfg_t *lora, uint8_t address, uint8_t value) {
|
||||
//xSemaphoreTake(spi_semaphore, portMAX_DELAY);
|
||||
xSemaphoreTake(spi_semaphore, portMAX_DELAY);
|
||||
|
||||
spi_device_handle_t spi = lora->spi;
|
||||
|
||||
|
@ -67,7 +67,7 @@ void lora32_write_reg(lora32_cfg_t *lora, uint8_t address, uint8_t value) {
|
|||
|
||||
ESP_ERROR_CHECK(spi_device_transmit(spi, &t));
|
||||
|
||||
//xSemaphoreGive(spi_semaphore);
|
||||
xSemaphoreGive(spi_semaphore);
|
||||
};
|
||||
|
||||
double lora32_calc_datarate(lora32_cfg_t *lora) {
|
||||
|
@ -117,7 +117,7 @@ void lora32_enable_tx(lora32_cfg_t *lora) {
|
|||
}
|
||||
|
||||
void lora32_send(lora32_cfg_t *lora, uint8_t *data, uint8_t len) {
|
||||
spi_device_acquire_bus(lora->spi, portMAX_DELAY);
|
||||
ESP_ERROR_CHECK(spi_device_acquire_bus(lora->spi, portMAX_DELAY));
|
||||
|
||||
lora32_write_reg(lora, REG_DIO_MAPPING_1, DIO0_MODE_TXDONE);
|
||||
|
||||
|
@ -361,6 +361,8 @@ static void IRAM_ATTR lora32_dio_task(void *arg) {
|
|||
ESP_LOGD(TAG, "clearing irqs");
|
||||
lora32_write_reg(lora, REG_IRQ_FLAGS, irqs);
|
||||
|
||||
spi_device_release_bus(lora->spi);
|
||||
|
||||
// TODO handle header validation
|
||||
if((irqs & IRQ_RX_DONE) == IRQ_RX_DONE) {
|
||||
lora32_handle_receive(lora);
|
||||
|
@ -385,8 +387,6 @@ static void IRAM_ATTR lora32_dio_task(void *arg) {
|
|||
// these *should* fire at the same time, defaults to false
|
||||
if(lora->cad_done != NULL) lora->cad_done(lora, cad_detected);
|
||||
}
|
||||
|
||||
spi_device_release_bus(lora->spi);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue