diff --git a/cores/nRF5/Uart.cpp b/cores/nRF5/Uart.cpp index c88746bd..5dd05dfb 100644 --- a/cores/nRF5/Uart.cpp +++ b/cores/nRF5/Uart.cpp @@ -43,7 +43,6 @@ Uart::Uart(NRF_UARTE_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _p uc_pinTX = g_ADigitalPinMap[_pinTX]; uc_hwFlow = 0; - _mutex = NULL; _end_tx_sem = NULL; _begun = false; } @@ -58,7 +57,6 @@ Uart::Uart(NRF_UARTE_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _p uc_pinRTS = g_ADigitalPinMap[_pinRTS]; uc_hwFlow = 1; - _mutex = NULL; _end_tx_sem = NULL; _begun = false; } @@ -143,8 +141,8 @@ void Uart::begin(unsigned long baudrate, uint16_t config) NVIC_SetPriority(IRQn, 3); NVIC_EnableIRQ(IRQn); - _mutex = xSemaphoreCreateMutex(); _end_tx_sem = xSemaphoreCreateBinary(); + xSemaphoreGive(_end_tx_sem); _begun = true; } @@ -167,9 +165,7 @@ void Uart::end() rxBuffer.clear(); - vSemaphoreDelete(_mutex); vSemaphoreDelete(_end_tx_sem); - _mutex = NULL; _end_tx_sem = NULL; _begun = false; } @@ -177,8 +173,8 @@ void Uart::end() void Uart::flush() { if ( _begun ) { - xSemaphoreTake(_mutex, portMAX_DELAY); - xSemaphoreGive(_mutex); + xSemaphoreTake(_end_tx_sem, portMAX_DELAY); + xSemaphoreGive(_end_tx_sem); } } @@ -232,7 +228,7 @@ size_t Uart::write(const uint8_t *buffer, size_t size) size_t remaining = size - sent; size_t txSize = min(remaining, (size_t)SERIAL_BUFFER_SIZE); - xSemaphoreTake(_mutex, portMAX_DELAY); + xSemaphoreTake(_end_tx_sem, portMAX_DELAY); memcpy(txBuffer, buffer + sent, txSize); @@ -240,10 +236,6 @@ 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; diff --git a/cores/nRF5/Uart.h b/cores/nRF5/Uart.h index bcd92db3..9aa78fce 100644 --- a/cores/nRF5/Uart.h +++ b/cores/nRF5/Uart.h @@ -70,7 +70,6 @@ class Uart : public HardwareSerial bool _begun; // Adafruit - SemaphoreHandle_t _mutex; SemaphoreHandle_t _end_tx_sem; };