Skip to content

Commit af14b97

Browse files
sandeepmistrycmaglie
authored andcommitted
Use port manipulation instead of SERCOM h/w for UART RTS
1 parent c26a21f commit af14b97

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

cores/arduino/SERCOM.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,6 @@ void SERCOM::disableDataRegisterEmptyInterruptUART()
183183
sercom->USART.INTENCLR.reg = SERCOM_USART_INTENCLR_DRE;
184184
}
185185

186-
void SERCOM::enableReceiveCompleteInterruptUART()
187-
{
188-
sercom->USART.INTENSET.reg |= SERCOM_USART_INTENSET_RXC;
189-
}
190-
191-
void SERCOM::disableReceiveCompleteInterruptUART()
192-
{
193-
sercom->USART.INTENCLR.reg = SERCOM_USART_INTENCLR_RXC;
194-
}
195-
196186
/* =========================
197187
* ===== Sercom SPI
198188
* =========================

cores/arduino/SERCOM.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ class SERCOM
165165
void acknowledgeUARTError() ;
166166
void enableDataRegisterEmptyInterruptUART();
167167
void disableDataRegisterEmptyInterruptUART();
168-
void enableReceiveCompleteInterruptUART();
169-
void disableReceiveCompleteInterruptUART();
170168

171169
/* ========== SPI ========== */
172170
void initSPI(SercomSpiTXPad mosi, SercomRXPad miso, SercomSpiCharSize charSize, SercomDataOrder dataOrder) ;

cores/arduino/Uart.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,21 @@ void Uart::begin(unsigned long baudrate, uint16_t config)
5050
pinPeripheral(uc_pinRX, g_APinDescription[uc_pinRX].ulPinType);
5151
pinPeripheral(uc_pinTX, g_APinDescription[uc_pinTX].ulPinType);
5252

53-
if (uc_padTX == UART_TX_RTS_CTS_PAD_0_2_3 && uc_pinRTS != NO_RTS_PIN && uc_pinCTS != NO_CTS_PIN) {
54-
pinPeripheral(uc_pinRTS, g_APinDescription[uc_pinRTS].ulPinType);
55-
pinPeripheral(uc_pinCTS, g_APinDescription[uc_pinCTS].ulPinType);
53+
if (uc_padTX == UART_TX_RTS_CTS_PAD_0_2_3) {
54+
if (uc_pinCTS != NO_CTS_PIN) {
55+
pinPeripheral(uc_pinCTS, g_APinDescription[uc_pinCTS].ulPinType);
56+
}
57+
}
58+
59+
if (uc_pinRTS != NO_RTS_PIN) {
60+
pinMode(uc_pinRTS, OUTPUT);
61+
62+
EPortType rtsPort = g_APinDescription[uc_pinRTS].ulPort;
63+
pul_outsetRTS = &PORT->Group[rtsPort].OUTSET.reg;
64+
pul_outclrRTS = &PORT->Group[rtsPort].OUTCLR.reg;
65+
ul_pinMaskRTS = (1ul << g_APinDescription[uc_pinRTS].ulPin);
66+
67+
*pul_outclrRTS = ul_pinMaskRTS;
5668
}
5769

5870
sercom->initUART(UART_INT_CLOCK, SAMPLE_RATE_x16, baudrate);
@@ -82,10 +94,9 @@ void Uart::IrqHandler()
8294
rxBuffer.store_char(sercom->readDataUART());
8395

8496
if (uc_pinRTS != NO_RTS_PIN) {
85-
// if there is NOT enough space in the RX buffer,
86-
// diable the receive complete interrupt
97+
// RX buffer space is below the threshold, de-assert RTS
8798
if (rxBuffer.availableForStore() < RTS_RX_THRESHOLD) {
88-
sercom->disableReceiveCompleteInterruptUART();
99+
*pul_outsetRTS = ul_pinMaskRTS;
89100
}
90101
}
91102
}
@@ -129,10 +140,9 @@ int Uart::read()
129140
int c = rxBuffer.read_char();
130141

131142
if (uc_pinRTS != NO_RTS_PIN) {
132-
// if there is enough space in the RX buffer,
133-
// enable the receive completer interrupt
143+
// if there is enough space in the RX buffer, assert RTS
134144
if (rxBuffer.availableForStore() > RTS_RX_THRESHOLD) {
135-
sercom->enableReceiveCompleteInterruptUART();
145+
*pul_outclrRTS = ul_pinMaskRTS;
136146
}
137147
}
138148

cores/arduino/Uart.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class Uart : public HardwareSerial
5454
SercomRXPad uc_padRX;
5555
SercomUartTXPad uc_padTX;
5656
uint8_t uc_pinRTS;
57+
volatile uint32_t* pul_outsetRTS;
58+
volatile uint32_t* pul_outclrRTS;
59+
uint32_t ul_pinMaskRTS;
5760
uint8_t uc_pinCTS;
5861

5962
SercomNumberStopBit extractNbStopBit(uint16_t config);

0 commit comments

Comments
 (0)