Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
4c3a397f
Commit
4c3a397f
authored
9 years ago
by
Hauke Petersen
Browse files
Options
Downloads
Patches
Plain Diff
cpu/sam3: adapted UART driver
parent
2bf81361
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cpu/sam3/periph/uart.c
+16
-135
16 additions, 135 deletions
cpu/sam3/periph/uart.c
with
16 additions
and
135 deletions
cpu/sam3/periph/uart.c
+
16
−
135
View file @
4c3a397f
...
...
@@ -28,63 +28,47 @@
#define ENABLE_DEBUG (0)
#include
"debug.h"
/* guard file in case no UART device was specified */
#if UART_NUMOF
/**
* @brief Each UART device has to store two callbacks.
*/
typedef
struct
{
uart_rx_cb_t
rx_cb
;
uart_tx_cb_t
tx_cb
;
void
*
arg
;
}
uart_conf_t
;
/**
* @brief Allocate memory to store the callback functions.
*/
static
uart_
conf
_t
uart_config
[
UART_NUMOF
];
static
uart_
isr_ctx
_t
uart_config
[
UART_NUMOF
];
static
int
init_base
(
uart_t
uart
,
uint32_t
baudrate
);
int
uart_init
(
uart_t
uart
,
uint32_t
baudrate
,
uart_rx_cb_t
rx_cb
,
uart_tx_cb_t
tx_cb
,
void
*
arg
)
int
uart_init
(
uart_t
uart
,
uint32_t
baudrate
,
uart_rx_cb_t
rx_cb
,
void
*
arg
)
{
/* initialize basic functionality */
int
res
=
uart_
init_b
locking
(
uart
,
baudrate
);
int
res
=
init_b
ase
(
uart
,
baudrate
);
if
(
res
!=
0
)
{
return
res
;
}
/* register callbacks */
uart_config
[
uart
].
rx_cb
=
rx_cb
;
uart_config
[
uart
].
tx_cb
=
tx_cb
;
uart_config
[
uart
].
arg
=
arg
;
/* configure interrupts and enable RX interrupt */
switch
(
uart
)
{
#if UART_0_EN
case
UART_0
:
NVIC_SetPriority
(
UART_0_IRQ
,
UART_IRQ_PRIO
);
NVIC_EnableIRQ
(
UART_0_IRQ
);
UART_0_DEV
->
UART_IER
=
UART_IER_RXRDY
;
break
;
#endif
#if UART_1_EN
case
UART_1
:
NVIC_SetPriority
(
UART_1_IRQ
,
UART_IRQ_PRIO
);
NVIC_EnableIRQ
(
UART_1_IRQ
);
UART_1_DEV
->
US_IER
=
US_IER_RXRDY
;
break
;
#endif
#if UART_2_EN
case
UART_2
:
NVIC_SetPriority
(
UART_2_IRQ
,
UART_IRQ_PRIO
);
NVIC_EnableIRQ
(
UART_2_IRQ
);
UART_2_DEV
->
US_IER
=
US_IER_RXRDY
;
break
;
#endif
#if UART_3_EN
case
UART_3
:
NVIC_SetPriority
(
UART_3_IRQ
,
UART_IRQ_PRIO
);
NVIC_EnableIRQ
(
UART_3_IRQ
);
UART_3_DEV
->
US_IER
=
US_IER_RXRDY
;
break
;
...
...
@@ -93,7 +77,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, uart_tx_cb_t t
return
0
;
}
int
uart_init_blocking
(
uart_t
uart
,
uint32_t
baudrate
)
static
int
init_base
(
uart_t
uart
,
uint32_t
baudrate
)
{
switch
(
uart
)
{
#if UART_0_EN
...
...
@@ -168,120 +152,39 @@ int uart_init_blocking(uart_t uart, uint32_t baudrate)
return
0
;
}
void
uart_
tx_begin
(
uart_t
uart
)
void
uart_
write
(
uart_t
uart
,
const
uint8_t
*
data
,
size_t
len
)
{
switch
(
uart
)
{
#if UART_0_EN
case
UART_0
:
UART_0_DEV
->
UART_IER
=
UART_IER_TXRDY
;
break
;
#endif
#if UART_1_EN
case
UART_1
:
UART_1_DEV
->
US_IER
=
US_IER_TXRDY
;
break
;
#endif
#if UART_2_EN
case
UART_2
:
UART_2_DEV
->
US_IER
=
US_IER_TXRDY
;
break
;
#endif
#if UART_3_EN
case
UART_3
:
UART_3_DEV
->
US_IER
=
US_IER_TXRDY
;
break
;
#endif
}
}
int
uart_write
(
uart_t
uart
,
char
data
)
{
switch
(
uart
)
{
#if UART_0_EN
case
UART_0
:
UART_0_DEV
->
UART_THR
=
data
;
break
;
#endif
#if UART_1_EN
case
UART_1
:
UART_1_DEV
->
US_THR
=
data
;
break
;
#endif
#if UART_2_EN
case
UART_2
:
UART_2_DEV
->
US_THR
=
data
;
break
;
#endif
#if UART_3_EN
case
UART_3
:
UART_3_DEV
->
US_THR
=
data
;
break
;
#endif
}
return
1
;
}
Uart
*
dev
;
int
uart_read_blocking
(
uart_t
uart
,
char
*
data
)
{
switch
(
uart
)
{
#if UART_0_EN
case
UART_0
:
while
(
!
(
UART_0_DEV
->
UART_SR
&
UART_SR_RXRDY
));
*
data
=
(
char
)
UART_0_DEV
->
UART_RHR
;
dev
=
(
Uart
*
)
UART_0_DEV
;
break
;
#endif
#if UART_1_EN
case
UART_1
:
while
(
!
(
UART_1_DEV
->
US_CSR
&
US_CSR_RXRDY
));
*
data
=
(
char
)
UART_1_DEV
->
US_RHR
;
dev
=
(
Uart
*
)
UART_1_DEV
;
break
;
#endif
#if UART_2_EN
case
UART_2
:
while
(
!
(
UART_2_DEV
->
US_CSR
&
US_CSR_RXRDY
));
*
data
=
(
char
)
UART_2_DEV
->
US_RHR
;
dev
=
(
Uart
*
)
UART_2_DEV
;
break
;
#endif
#if UART_3_EN
case
UART_3
:
while
(
!
(
UART_3_DEV
->
US_CSR
&
US_CSR_RXRDY
));
*
data
=
(
char
)
UART_3_DEV
->
US_RHR
;
dev
=
(
Uart
*
)
UART_3_DEV
;
break
;
#endif
default:
return
;
}
return
1
;
}
int
uart_write_blocking
(
uart_t
uart
,
char
data
)
{
switch
(
uart
)
{
#if UART_0_EN
case
UART_0
:
while
(
!
(
UART_0_DEV
->
UART_SR
&
UART_SR_TXRDY
));
UART_0_DEV
->
UART_THR
=
data
;
break
;
#endif
#if UART_1_EN
case
UART_1
:
while
(
!
(
UART_1_DEV
->
US_CSR
&
US_CSR_TXRDY
));
UART_1_DEV
->
US_THR
=
data
;
break
;
#endif
#if UART_2_EN
case
UART_2
:
while
(
!
(
UART_2_DEV
->
US_CSR
&
US_CSR_TXRDY
));
UART_2_DEV
->
US_THR
=
data
;
break
;
#endif
#if UART_3_EN
case
UART_3
:
while
(
!
(
UART_3_DEV
->
US_CSR
&
US_CSR_TXRDY
));
UART_3_DEV
->
US_THR
=
data
;
break
;
#endif
for
(
size_t
i
=
0
;
i
<
len
;
i
++
)
{
while
(
!
(
dev
->
UART_SR
&
UART_SR_TXRDY
));
dev
->
UART_THR
=
data
[
i
];
}
return
1
;
}
void
uart_poweron
(
uart_t
uart
)
...
...
@@ -343,11 +246,6 @@ void UART_0_ISR(void)
char
data
=
(
char
)
UART_0_DEV
->
UART_RHR
;
uart_config
[
UART_0
].
rx_cb
(
uart_config
[
UART_0
].
arg
,
data
);
}
if
((
UART_0_DEV
->
UART_SR
&
UART_SR_TXRDY
)
&&
(
UART_0_DEV
->
UART_IMR
&
UART_IMR_TXRDY
))
{
if
(
uart_config
[
UART_0
].
tx_cb
(
uart_config
[
UART_0
].
arg
)
==
0
)
{
UART_0_DEV
->
UART_IDR
=
UART_IDR_TXRDY
;
}
}
if
(
sched_context_switch_request
)
{
thread_yield
();
}
...
...
@@ -361,11 +259,6 @@ void UART_1_ISR(void)
char
data
=
(
char
)
UART_1_DEV
->
US_RHR
;
uart_config
[
UART_1
].
rx_cb
(
uart_config
[
UART_1
].
arg
,
data
);
}
if
((
UART_1_DEV
->
US_CSR
&
US_CSR_TXRDY
)
&&
(
UART_1_DEV
->
US_IMR
&
US_IMR_TXRDY
))
{
if
(
uart_config
[
UART_1
].
tx_cb
(
uart_config
[
UART_1
].
arg
)
==
0
)
{
UART_1_DEV
->
US_IDR
=
US_IDR_TXRDY
;
}
}
if
(
sched_context_switch_request
)
{
thread_yield
();
}
...
...
@@ -379,11 +272,6 @@ void UART_2_ISR(void)
char
data
=
(
char
)
UART_2_DEV
->
US_RHR
;
uart_config
[
UART_2
].
rx_cb
(
uart_config
[
UART_2
].
arg
,
data
);
}
if
((
UART_2_DEV
->
US_CSR
&
US_CSR_TXRDY
)
&&
(
UART_2_DEV
->
US_IMR
&
US_IMR_TXRDY
))
{
if
(
uart_config
[
UART_2
].
tx_cb
(
uart_config
[
UART_2
].
arg
)
==
0
)
{
UART_2_DEV
->
US_IDR
=
US_IDR_TXRDY
;
}
}
if
(
sched_context_switch_request
)
{
thread_yield
();
}
...
...
@@ -397,15 +285,8 @@ void UART_3_ISR(void)
char
data
=
(
char
)
UART_3_DEV
->
US_RHR
;
uart_config
[
UART_3
].
rx_cb
(
uart_config
[
UART_3
].
arg
,
data
);
}
if
((
UART_3_DEV
->
US_CSR
&
US_CSR_TXRDY
)
&&
(
UART_3_DEV
->
US_IMR
&
US_IMR_TXRDY
))
{
if
(
uart_config
[
UART_3
].
tx_cb
(
uart_config
[
UART_3
].
arg
)
==
0
)
{
UART_3_DEV
->
US_IDR
=
US_IDR_TXRDY
;
}
}
if
(
sched_context_switch_request
)
{
thread_yield
();
}
}
#endif
#endif
/* UART_NUMOF */
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