Skip to content

Commit 60a4c77

Browse files
committed
optimize by deleting mutex
1 parent 2e5ed87 commit 60a4c77

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

cores/nRF5/Uart.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ Uart::Uart(NRF_UARTE_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _p
4343
uc_pinTX = g_ADigitalPinMap[_pinTX];
4444
uc_hwFlow = 0;
4545

46-
_mutex = NULL;
4746
_end_tx_sem = NULL;
4847
_begun = false;
4948
}
@@ -58,7 +57,6 @@ Uart::Uart(NRF_UARTE_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _p
5857
uc_pinRTS = g_ADigitalPinMap[_pinRTS];
5958
uc_hwFlow = 1;
6059

61-
_mutex = NULL;
6260
_end_tx_sem = NULL;
6361
_begun = false;
6462
}
@@ -143,8 +141,8 @@ void Uart::begin(unsigned long baudrate, uint16_t config)
143141
NVIC_SetPriority(IRQn, 3);
144142
NVIC_EnableIRQ(IRQn);
145143

146-
_mutex = xSemaphoreCreateMutex();
147144
_end_tx_sem = xSemaphoreCreateBinary();
145+
xSemaphoreGive(_end_tx_sem);
148146
_begun = true;
149147
}
150148

@@ -167,18 +165,16 @@ void Uart::end()
167165

168166
rxBuffer.clear();
169167

170-
vSemaphoreDelete(_mutex);
171168
vSemaphoreDelete(_end_tx_sem);
172-
_mutex = NULL;
173169
_end_tx_sem = NULL;
174170
_begun = false;
175171
}
176172

177173
void Uart::flush()
178174
{
179175
if ( _begun ) {
180-
xSemaphoreTake(_mutex, portMAX_DELAY);
181-
xSemaphoreGive(_mutex);
176+
xSemaphoreTake(_end_tx_sem, portMAX_DELAY);
177+
xSemaphoreGive(_end_tx_sem);
182178
}
183179
}
184180

@@ -232,18 +228,14 @@ size_t Uart::write(const uint8_t *buffer, size_t size)
232228
size_t remaining = size - sent;
233229
size_t txSize = min(remaining, (size_t)SERIAL_BUFFER_SIZE);
234230

235-
xSemaphoreTake(_mutex, portMAX_DELAY);
231+
xSemaphoreTake(_end_tx_sem, portMAX_DELAY);
236232

237233
memcpy(txBuffer, buffer + sent, txSize);
238234

239235
nrfUart->TXD.MAXCNT = txSize;
240236
nrfUart->TASKS_STARTTX = 0x1UL;
241237
sent += txSize;
242238

243-
xSemaphoreTake(_end_tx_sem, portMAX_DELAY);
244-
245-
xSemaphoreGive(_mutex);
246-
247239
} while (sent < size);
248240

249241
return sent;

cores/nRF5/Uart.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ class Uart : public HardwareSerial
7070
bool _begun;
7171

7272
// Adafruit
73-
SemaphoreHandle_t _mutex;
7473
SemaphoreHandle_t _end_tx_sem;
7574
};
7675

0 commit comments

Comments
 (0)