optimize by deleting mutex

This commit is contained in:
ogatatsu committed 2020-10-06 21:20:12 +09:00
1 parent 2e5ed87044
commit 60a4c7784c
2 files changed
+4 -13

No files matched your search

+4 -12
View File
@@ -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;
-1
View File
@@ -70,7 +70,6 @@ class Uart : public HardwareSerial
bool _begun;
// Adafruit
SemaphoreHandle_t _mutex;
SemaphoreHandle_t _end_tx_sem;
};