Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/sam3: cleaned up UART driver #4170

Merged
merged 3 commits into from
Nov 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boards/arduino-due/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern "C" {
* @name Define UART device and baudrate for stdio
* @{
*/
#define STDIO UART_0
#define STDIO UART_DEV(0)
#define STDIO_BAUDRATE (115200U)
#define STDIO_RX_BUFSIZE (64U)
/** @} */
Expand Down
54 changes: 13 additions & 41 deletions boards/arduino-due/include/periph_conf.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
* Copyright (C) 2014-2015 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
Expand All @@ -21,6 +21,8 @@
#ifndef PERIPH_CONF_H_
#define PERIPH_CONF_H_

#include "periph_cpu.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -60,51 +62,21 @@ extern "C" {
* @name UART configuration
* @{
*/
#define UART_NUMOF (4U)
#define UART_0_EN 1
#define UART_1_EN 1
#define UART_2_EN 1
#define UART_3_EN 1
static const uart_conf_t uart_config[] = {
/* device, rx port, tx port, rx pin, tx pin, mux, PMC bit, IRGn line */
{(Uart *)UART, PIOA, PIOA, 8, 9, GPIO_MUX_A, ID_UART, UART_IRQn},
{(Uart *)USART0, PIOA, PIOA, 10, 11, GPIO_MUX_A, ID_USART0, USART0_IRQn},
{(Uart *)USART1, PIOA, PIOA, 12, 13, GPIO_MUX_A, ID_USART1, USART1_IRQn},
{(Uart *)USART3, PIOD, PIOD, 4, 5, GPIO_MUX_B, ID_USART3, USART3_IRQn}
};

/* UART 0 device configuration */
#define UART_0_DEV UART
#define UART_0_CLKEN() (PMC->PMC_PCER0 |= (1 << ID_UART))
#define UART_0_CLKDIS() (PMC->PMC_PCER0 &= ~(1 << ID_UART))
#define UART_0_IRQ UART_IRQn
/* define interrupt vectors */
#define UART_0_ISR isr_uart
/* UART 0 pin configuration */
#define UART_0_PORT PIOA
#define UART_0_PINS (PIO_PA8 | PIO_PA9)

/* UART 1 device configuration */
#define UART_1_DEV USART0
#define UART_1_CLKEN() (PMC->PMC_PCER0 |= (1 << ID_USART0))
#define UART_1_CLKDIS() (PMC->PMC_PCER0 &= ~(1 << ID_USART0))
#define UART_1_IRQ USART0_IRQn
#define UART_1_ISR isr_usart0
/* UART 1 pin configuration */
#define UART_1_PORT PIOA
#define UART_1_PINS (PIO_PA10 | PIO_PA11)

/* UART 1 device configuration */
#define UART_2_DEV USART1
#define UART_2_CLKEN() (PMC->PMC_PCER0 |= (1 << ID_USART1))
#define UART_2_CLKDIS() (PMC->PMC_PCER0 &= ~(1 << ID_USART1))
#define UART_2_IRQ USART1_IRQn
#define UART_2_ISR isr_usart1
/* UART 1 pin configuration */
#define UART_2_PORT PIOA
#define UART_2_PINS (PIO_PA12 | PIO_PA13)

/* UART 1 device configuration */
#define UART_3_DEV USART3
#define UART_3_CLKEN() (PMC->PMC_PCER0 |= (1 << ID_USART3))
#define UART_3_CLKDIS() (PMC->PMC_PCER0 &= ~(1 << ID_USART3))
#define UART_3_IRQ USART3_IRQn
#define UART_3_ISR isr_usart3
/* UART 1 pin configuration */
#define UART_3_PORT PIOD
#define UART_3_PINS (PIO_PD4 | PIO_PD5)

#define UART_NUMOF (sizeof(uart_config) / sizeof(uart_config[0]))
/** @} */

/**
Expand Down
2 changes: 1 addition & 1 deletion boards/udoo/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern "C" {
* @name Define UART device and baudrate for stdio
* @{
*/
#define STDIO UART_0
#define STDIO UART_DEV(0)
#define STDIO_BAUDRATE (115200U)
#define STDIO_RX_BUFSIZE (64U)
/** @} */
Expand Down
55 changes: 13 additions & 42 deletions boards/udoo/include/periph_conf.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
* Copyright (C) 2014-2015 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
Expand All @@ -19,6 +19,8 @@
#ifndef PERIPH_CONF_H_
#define PERIPH_CONF_H_

#include "periph_cpu.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -58,52 +60,21 @@ extern "C" {
* @name UART configuration
* @{
*/
#define UART_NUMOF (4U)
#define UART_0_EN 1
#define UART_1_EN 1
#define UART_2_EN 1
#define UART_3_EN 1
#define UART_IRQ_PRIO 1
static const uart_conf_t uart_config[] = {
/* device, rx port, tx port, rx pin, tx pin, mux, PMC bit, IRGn line */
{(Uart *)UART, PIOA, PIOA, 8, 9, GPIO_MUX_A, ID_UART, UART_IRQn},
{(Uart *)USART0, PIOA, PIOA, 10, 11, GPIO_MUX_A, ID_USART0, USART0_IRQn},
{(Uart *)USART1, PIOA, PIOA, 12, 13, GPIO_MUX_A, ID_USART1, USART1_IRQn},
{(Uart *)USART3, PIOD, PIOD, 4, 5, GPIO_MUX_B, ID_USART3, USART3_IRQn}
};

/* UART 0 device configuration */
#define UART_0_DEV UART
#define UART_0_CLKEN() (PMC->PMC_PCER0 |= (1 << ID_UART))
#define UART_0_CLKDIS() (PMC->PMC_PCER0 &= ~(1 << ID_UART))
#define UART_0_IRQ UART_IRQn
/* define interrupt vectors */
#define UART_0_ISR isr_uart
/* UART 0 pin configuration */
#define UART_0_PORT PIOA
#define UART_0_PINS (PIO_PA8 | PIO_PA9)

/* UART 1 device configuration */
#define UART_1_DEV USART0
#define UART_1_CLKEN() (PMC->PMC_PCER0 |= (1 << ID_USART0))
#define UART_1_CLKDIS() (PMC->PMC_PCER0 &= ~(1 << ID_USART0))
#define UART_1_IRQ USART0_IRQn
#define UART_1_ISR isr_usart0
/* UART 1 pin configuration */
#define UART_1_PORT PIOA
#define UART_1_PINS (PIO_PA10 | PIO_PA11)

/* UART 1 device configuration */
#define UART_2_DEV USART1
#define UART_2_CLKEN() (PMC->PMC_PCER0 |= (1 << ID_USART1))
#define UART_2_CLKDIS() (PMC->PMC_PCER0 &= ~(1 << ID_USART1))
#define UART_2_IRQ USART1_IRQn
#define UART_2_ISR isr_usart1
/* UART 1 pin configuration */
#define UART_2_PORT PIOA
#define UART_2_PINS (PIO_PA12 | PIO_PA13)

/* UART 1 device configuration */
#define UART_3_DEV USART3
#define UART_3_CLKEN() (PMC->PMC_PCER0 |= (1 << ID_USART3))
#define UART_3_CLKDIS() (PMC->PMC_PCER0 &= ~(1 << ID_USART3))
#define UART_3_IRQ USART3_IRQn
#define UART_3_ISR isr_usart3
/* UART 1 pin configuration */
#define UART_3_PORT PIOD
#define UART_3_PINS (PIO_PD4 | PIO_PD5)

#define UART_NUMOF (sizeof(uart_config) / sizeof(uart_config[0]))
/** @} */

/**
Expand Down
24 changes: 23 additions & 1 deletion cpu/sam3/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifndef PERIPH_CPU_H_
#define PERIPH_CPU_H_

#include "periph/dev_enums.h"
#include "cpu.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -34,6 +34,28 @@ extern "C" {
#define PERIPH_SPI_NEEDS_TRANSFER_REGS
/** @} */

/**
* @brief GPIO mux configuration
*/
typedef enum {
GPIO_MUX_A = 0, /**< alternate function A */
GPIO_MUX_B = 1, /**< alternate function B */
} gpio_mux_t;

/**
* @brief UART configuration data
*/
typedef struct {
Uart *dev; /**< U(S)ART device used */
Pio *rx_port; /**< port for RX pin */
Pio *tx_port; /**< port for TX pin */
uint8_t rx_pin; /**< RX pin */
uint8_t tx_pin; /**< TX pin */
gpio_mux_t mux; /**< MUX used for pins */
uint8_t pmc_id; /**< bit in the PMC register of the device*/
uint8_t irqn; /**< interrupt number of the device */
} uart_conf_t;

#ifdef __cplusplus
}
#endif
Expand Down
Loading