Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Arduino Core for SAMD21 CPU
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
josc941e
Arduino Core for SAMD21 CPU
Commits
7fc402f3
Commit
7fc402f3
authored
7 years ago
by
Sandeep Mistry
Committed by
Cristian Maglie
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Leverage SERCOM h/w functionality for RTS and CTS
parent
bd1bd608
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cores/arduino/SERCOM.cpp
+10
-0
10 additions, 0 deletions
cores/arduino/SERCOM.cpp
cores/arduino/SERCOM.h
+2
-0
2 additions, 0 deletions
cores/arduino/SERCOM.h
cores/arduino/Uart.cpp
+20
-21
20 additions, 21 deletions
cores/arduino/Uart.cpp
with
32 additions
and
21 deletions
cores/arduino/SERCOM.cpp
+
10
−
0
View file @
7fc402f3
...
@@ -183,6 +183,16 @@ void SERCOM::disableDataRegisterEmptyInterruptUART()
...
@@ -183,6 +183,16 @@ void SERCOM::disableDataRegisterEmptyInterruptUART()
sercom
->
USART
.
INTENCLR
.
reg
=
SERCOM_USART_INTENCLR_DRE
;
sercom
->
USART
.
INTENCLR
.
reg
=
SERCOM_USART_INTENCLR_DRE
;
}
}
void
SERCOM
::
enableReceiveCompleteInterruptUART
()
{
sercom
->
USART
.
INTENSET
.
reg
|=
SERCOM_USART_INTENSET_RXC
;
}
void
SERCOM
::
disableReceiveCompleteInterruptUART
()
{
sercom
->
USART
.
INTENCLR
.
reg
=
SERCOM_USART_INTENCLR_RXC
;
}
/* =========================
/* =========================
* ===== Sercom SPI
* ===== Sercom SPI
* =========================
* =========================
...
...
This diff is collapsed.
Click to expand it.
cores/arduino/SERCOM.h
+
2
−
0
View file @
7fc402f3
...
@@ -165,6 +165,8 @@ class SERCOM
...
@@ -165,6 +165,8 @@ class SERCOM
void
acknowledgeUARTError
()
;
void
acknowledgeUARTError
()
;
void
enableDataRegisterEmptyInterruptUART
();
void
enableDataRegisterEmptyInterruptUART
();
void
disableDataRegisterEmptyInterruptUART
();
void
disableDataRegisterEmptyInterruptUART
();
void
enableReceiveCompleteInterruptUART
();
void
disableReceiveCompleteInterruptUART
();
/* ========== SPI ========== */
/* ========== SPI ========== */
void
initSPI
(
SercomSpiTXPad
mosi
,
SercomRXPad
miso
,
SercomSpiCharSize
charSize
,
SercomDataOrder
dataOrder
)
;
void
initSPI
(
SercomSpiTXPad
mosi
,
SercomRXPad
miso
,
SercomSpiCharSize
charSize
,
SercomDataOrder
dataOrder
)
;
...
...
This diff is collapsed.
Click to expand it.
cores/arduino/Uart.cpp
+
20
−
21
View file @
7fc402f3
...
@@ -46,12 +46,11 @@ void Uart::begin(unsigned long baudrate, uint16_t config)
...
@@ -46,12 +46,11 @@ void Uart::begin(unsigned long baudrate, uint16_t config)
pinPeripheral
(
uc_pinTX
,
g_APinDescription
[
uc_pinTX
].
ulPinType
);
pinPeripheral
(
uc_pinTX
,
g_APinDescription
[
uc_pinTX
].
ulPinType
);
if
(
uc_pinRTS
!=
NO_RTS_PIN
)
{
if
(
uc_pinRTS
!=
NO_RTS_PIN
)
{
pinMode
(
uc_pinRTS
,
OUTPUT
);
pinPeripheral
(
uc_pinRTS
,
g_APinDescription
[
uc_pinRTS
].
ulPinType
);
digitalWrite
(
uc_pinRTS
,
LOW
);
}
}
if
(
uc_pinCTS
!=
NO_CTS_PIN
)
{
if
(
uc_pinCTS
!=
NO_CTS_PIN
)
{
pin
Mode
(
uc_pinCTS
,
INPUT
);
pin
Peripheral
(
uc_pinCTS
,
g_APinDescription
[
uc_pinCTS
].
ulPinType
);
}
}
sercom
->
initUART
(
UART_INT_CLOCK
,
SAMPLE_RATE_x16
,
baudrate
);
sercom
->
initUART
(
UART_INT_CLOCK
,
SAMPLE_RATE_x16
,
baudrate
);
...
@@ -86,9 +85,10 @@ void Uart::IrqHandler()
...
@@ -86,9 +85,10 @@ void Uart::IrqHandler()
rxBuffer
.
store_char
(
sercom
->
readDataUART
());
rxBuffer
.
store_char
(
sercom
->
readDataUART
());
if
(
uc_pinRTS
!=
NO_RTS_PIN
)
{
if
(
uc_pinRTS
!=
NO_RTS_PIN
)
{
// if there is NOT enough space in the RX buffer, de-assert RTS
// if there is NOT enough space in the RX buffer,
// diable the receive complete interrupt
if
(
rxBuffer
.
availableForStore
()
<
RTS_RX_THRESHOLD
)
{
if
(
rxBuffer
.
availableForStore
()
<
RTS_RX_THRESHOLD
)
{
digitalWrite
(
uc_pinRTS
,
HIGH
);
sercom
->
disableReceiveCompleteInterruptUART
(
);
}
}
}
}
}
}
...
@@ -132,9 +132,10 @@ int Uart::read()
...
@@ -132,9 +132,10 @@ int Uart::read()
int
c
=
rxBuffer
.
read_char
();
int
c
=
rxBuffer
.
read_char
();
if
(
uc_pinRTS
!=
NO_RTS_PIN
)
{
if
(
uc_pinRTS
!=
NO_RTS_PIN
)
{
// if there is enough space in the RX buffer, assert RTS
// if there is enough space in the RX buffer,
// enable the receive completer interrupt
if
(
rxBuffer
.
availableForStore
()
>
RTS_RX_THRESHOLD
)
{
if
(
rxBuffer
.
availableForStore
()
>
RTS_RX_THRESHOLD
)
{
digitalWrite
(
uc_pinRTS
,
LOW
);
sercom
->
enableReceiveCompleteInterruptUART
(
);
}
}
}
}
...
@@ -143,16 +144,6 @@ int Uart::read()
...
@@ -143,16 +144,6 @@ int Uart::read()
size_t
Uart
::
write
(
const
uint8_t
data
)
size_t
Uart
::
write
(
const
uint8_t
data
)
{
{
if
(
uc_pinRTS
!=
NO_RTS_PIN
)
{
// assert RTS
digitalWrite
(
uc_pinRTS
,
LOW
);
}
if
(
uc_pinCTS
!=
NO_CTS_PIN
)
{
// wait until CTS is asserted
while
(
digitalRead
(
uc_pinCTS
)
!=
LOW
);
}
if
(
sercom
->
isDataRegisterEmptyUART
()
&&
txBuffer
.
available
()
==
0
)
{
if
(
sercom
->
isDataRegisterEmptyUART
()
&&
txBuffer
.
available
()
==
0
)
{
sercom
->
writeDataUART
(
data
);
sercom
->
writeDataUART
(
data
);
}
else
{
}
else
{
...
@@ -217,14 +208,22 @@ SercomParityMode Uart::extractParity(uint16_t config)
...
@@ -217,14 +208,22 @@ SercomParityMode Uart::extractParity(uint16_t config)
int
Uart
::
attachRts
(
uint8_t
pin
)
int
Uart
::
attachRts
(
uint8_t
pin
)
{
{
uc_pinRTS
=
pin
;
if
(
uc_padTX
==
UART_TX_RTS_CTS_PAD_0_2_3
)
{
uc_pinRTS
=
pin
;
return
1
;
return
1
;
}
return
0
;
}
}
int
Uart
::
attachCts
(
uint8_t
pin
)
int
Uart
::
attachCts
(
uint8_t
pin
)
{
{
uc_pinCTS
=
pin
;
if
(
uc_padTX
==
UART_TX_RTS_CTS_PAD_0_2_3
)
{
uc_pinCTS
=
pin
;
return
1
;
return
1
;
}
return
0
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment