Skip to content

Commit c2da668

Browse files
committed
libraries/Wire: RingBuffer implementation.
Signed-off-by: MDin <Dinesh.M-EE@infineon.com>
1 parent f344948 commit c2da668

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

libraries/Wire/src/Wire.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ size_t TwoWire::requestFrom(uint8_t address, size_t quantity, uint32_t iaddress
227227
XMC_I2C_CH_STATUS_FLAG_RECEIVE_INDICATION |
228228
XMC_I2C_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION);
229229

230-
rxBuffer[count] = XMC_I2C_CH_GetReceivedData(XMC_I2C_config->channel);
230+
rx_ringBuffer.store_char(XMC_I2C_CH_GetReceivedData(XMC_I2C_config->channel));
231231
}
232232

233233
XMC_I2C_CH_MasterReceiveNack(XMC_I2C_config->channel);
@@ -250,7 +250,7 @@ size_t TwoWire::requestFrom(uint8_t address, size_t quantity, uint32_t iaddress
250250
XMC_I2C_CH_STATUS_FLAG_RECEIVE_INDICATION |
251251
XMC_I2C_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION);
252252

253-
rxBuffer[quantity - 1] = XMC_I2C_CH_GetReceivedData(XMC_I2C_config->channel);
253+
rx_ringBuffer.store_char(XMC_I2C_CH_GetReceivedData(XMC_I2C_config->channel));
254254

255255
if (sendStop) {
256256
XMC_I2C_CH_MasterStop(XMC_I2C_config->channel);
@@ -549,19 +549,13 @@ void TwoWire::OnReceiveService() {
549549
if (!user_onReceive) {
550550
return;
551551
}
552-
while(pre_rx_ringBuffer.available()) {
553-
// read from pre-receive buffer
554-
if(rx_ringBuffer.availableForStore()) {
555-
// buffer is full, stop reading
556-
rx_ringBuffer.store_char(pre_rx_ringBuffer.read_char());
557-
} else {
558-
// buffer is full, stop reading
559-
hasError = true;
560-
break;
561-
}
562-
}
552+
uint8_t count = pre_rx_ringBuffer.available();
553+
while(pre_rx_ringBuffer.available()>0 && rx_ringBuffer.availableForStore()>0) {
554+
rx_ringBuffer.store_char(pre_rx_ringBuffer.read_char());
555+
}
556+
563557
// alert user program
564-
user_onReceive(rx_ringBuffer.available());
558+
user_onReceive(count);
565559

566560
/*Flush receive buffer*/
567561
(void)XMC_I2C_CH_GetReceivedData(XMC_I2C_config->channel);

0 commit comments

Comments
 (0)