fix to not use mutex in ISR

This commit is contained in:
ogatatsu committed 2020-10-04 16:42:39 +09:00
1 parent 2316b0f0b9
commit 2e5ed87044
2 files changed
+11 -1

No files matched your search

+10 -1
View File
@@ -44,6 +44,7 @@ Uart::Uart(NRF_UARTE_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _p
uc_hwFlow = 0;
_mutex = NULL;
_end_tx_sem = NULL;
_begun = false;
}
@@ -58,6 +59,7 @@ Uart::Uart(NRF_UARTE_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _p
uc_hwFlow = 1;
_mutex = NULL;
_end_tx_sem = NULL;
_begun = false;
}
@@ -142,6 +144,7 @@ void Uart::begin(unsigned long baudrate, uint16_t config)
NVIC_EnableIRQ(IRQn);
_mutex = xSemaphoreCreateMutex();
_end_tx_sem = xSemaphoreCreateBinary();
_begun = true;
}
@@ -165,7 +168,9 @@ void Uart::end()
rxBuffer.clear();
vSemaphoreDelete(_mutex);
vSemaphoreDelete(_end_tx_sem);
_mutex = NULL;
_end_tx_sem = NULL;
_begun = false;
}
@@ -192,7 +197,7 @@ void Uart::IrqHandler()
if (nrfUart->EVENTS_ENDTX)
{
nrfUart->EVENTS_ENDTX = 0x0UL;
xSemaphoreGiveFromISR(_mutex, NULL);
xSemaphoreGiveFromISR(_end_tx_sem, NULL);
}
}
@@ -235,6 +240,10 @@ size_t Uart::write(const uint8_t *buffer, size_t size)
nrfUart->TASKS_STARTTX = 0x1UL;
sent += txSize;
xSemaphoreTake(_end_tx_sem, portMAX_DELAY);
xSemaphoreGive(_mutex);
} while (sent < size);
return sent;
+1
View File
@@ -71,6 +71,7 @@ class Uart : public HardwareSerial
// Adafruit
SemaphoreHandle_t _mutex;
SemaphoreHandle_t _end_tx_sem;
};