52 #define UART0_RX_PORT (-1)
55 #define UART0_RX_PIN (-1)
57 #if UART0_RX_PORT >= 0 && UART0_RX_PIN < 0 || \
58 UART0_RX_PORT < 0 && UART0_RX_PIN >= 0
59 #error Both UART0_RX_PORT and UART0_RX_PIN must be valid or invalid
63 #define UART0_TX_PORT (-1)
66 #define UART0_TX_PIN (-1)
68 #if UART0_TX_PORT >= 0 && UART0_TX_PIN < 0 || \
69 UART0_TX_PORT < 0 && UART0_TX_PIN >= 0
70 #error Both UART0_TX_PORT and UART0_TX_PIN must be valid or invalid
73 #if UART0_RX_PORT >= 0 && UART0_TX_PORT < 0 || \
74 UART0_RX_PORT < 0 && UART0_TX_PORT >= 0
75 #error Both UART0_RX and UART0_TX pads must be valid or invalid
78 #if UART_IN_USE(0) && UART0_RX_PORT < 0
79 #error Contiki is configured to use UART0, but its pads are not valid
83 #define UART1_RX_PORT (-1)
86 #define UART1_RX_PIN (-1)
88 #if UART1_RX_PORT >= 0 && UART1_RX_PIN < 0 || \
89 UART1_RX_PORT < 0 && UART1_RX_PIN >= 0
90 #error Both UART1_RX_PORT and UART1_RX_PIN must be valid or invalid
94 #define UART1_TX_PORT (-1)
97 #define UART1_TX_PIN (-1)
99 #if UART1_TX_PORT >= 0 && UART1_TX_PIN < 0 || \
100 UART1_TX_PORT < 0 && UART1_TX_PIN >= 0
101 #error Both UART1_TX_PORT and UART1_TX_PIN must be valid or invalid
104 #if UART1_RX_PORT >= 0 && UART1_TX_PORT < 0 || \
105 UART1_RX_PORT < 0 && UART1_TX_PORT >= 0
106 #error Both UART1_RX and UART1_TX pads must be valid or invalid
109 #if UART_IN_USE(1) && UART1_RX_PORT < 0
110 #error Contiki is configured to use UART1, but its pads are not valid
113 #ifndef UART1_CTS_PORT
114 #define UART1_CTS_PORT (-1)
116 #ifndef UART1_CTS_PIN
117 #define UART1_CTS_PIN (-1)
119 #if UART1_CTS_PORT >= 0 && UART1_CTS_PIN < 0 || \
120 UART1_CTS_PORT < 0 && UART1_CTS_PIN >= 0
121 #error Both UART1_CTS_PORT and UART1_CTS_PIN must be valid or invalid
124 #ifndef UART1_RTS_PORT
125 #define UART1_RTS_PORT (-1)
127 #ifndef UART1_RTS_PIN
128 #define UART1_RTS_PIN (-1)
130 #if UART1_RTS_PORT >= 0 && UART1_RTS_PIN < 0 || \
131 UART1_RTS_PORT < 0 && UART1_RTS_PIN >= 0
132 #error Both UART1_RTS_PORT and UART1_RTS_PIN must be valid or invalid
139 #define UART_CLOCK_RATE 16000000
140 #define UART_CTL_HSE_VALUE 0
141 #define UART_CTL_VALUE (UART_CTL_RXE | UART_CTL_TXE | (UART_CTL_HSE_VALUE << 5))
144 #define DIV_ROUND(num, denom) (((num) + (denom) / 2) / (denom))
146 #define BAUD2BRD(baud) DIV_ROUND(UART_CLOCK_RATE << (UART_CTL_HSE_VALUE + 2), (baud))
147 #define BAUD2IBRD(baud) (BAUD2BRD(baud) >> 6)
148 #define BAUD2FBRD(baud) (BAUD2BRD(baud) & 0x3f)
155 uint32_t sys_ctrl_rcgcuart_uart;
156 uint32_t sys_ctrl_scgcuart_uart;
157 uint32_t sys_ctrl_dcgcuart_uart;
159 uint32_t ioc_uartrxd_uart;
160 uint32_t ioc_pxx_sel_uart_txd;
170 static const uart_regs_t uart_regs[UART_INSTANCE_COUNT] = {
177 .ioc_pxx_sel_uart_txd = IOC_PXX_SEL_UART0_TXD,
180 .rx = {UART0_RX_PORT, UART0_RX_PIN},
181 .tx = {UART0_TX_PORT, UART0_TX_PIN},
191 .ioc_pxx_sel_uart_txd = IOC_PXX_SEL_UART1_TXD,
194 .rx = {UART1_RX_PORT, UART1_RX_PIN},
195 .tx = {UART1_TX_PORT, UART1_TX_PIN},
196 .cts = {UART1_CTS_PORT, UART1_CTS_PIN},
197 .rts = {UART1_RTS_PORT, UART1_RTS_PIN},
201 static int (* input_handler[UART_INSTANCE_COUNT])(
unsigned char c);
204 reset(uint32_t uart_base)
209 REG(uart_base |
UART_CTL) = UART_CTL_VALUE;
230 const uart_regs_t *regs;
232 for(regs = &uart_regs[0]; regs < &uart_regs[UART_INSTANCE_COUNT]; regs++) {
246 const uart_regs_t *regs;
248 if(uart >= UART_INSTANCE_COUNT) {
251 regs = &uart_regs[uart];
252 if(regs->rx.port < 0 || regs->tx.port < 0) {
274 REG(regs->ioc_uartrxd_uart) = (regs->rx.port << 3) + regs->rx.pin;
281 ioc_set_sel(regs->tx.port, regs->tx.pin, regs->ioc_pxx_sel_uart_txd);
302 REG(regs->base |
UART_CTL) = UART_CTL_VALUE;
305 REG(regs->base |
UART_IBRD) = regs->ibrd;
306 REG(regs->base |
UART_FBRD) = regs->fbrd;
315 if(regs->cts.port >= 0) {
322 if(regs->rts.port >= 0) {
323 ioc_set_sel(regs->rts.port, regs->rts.pin, IOC_PXX_SEL_UART1_RTS);
339 if(uart >= UART_INSTANCE_COUNT) {
343 input_handler[uart] = input;
351 if(uart >= UART_INSTANCE_COUNT) {
354 uart_base = uart_regs[uart].base;
363 uart_isr(uint8_t uart)
368 ENERGEST_ON(ENERGEST_TYPE_IRQ);
370 uart_base = uart_regs[uart].base;
374 mis = REG(uart_base |
UART_MIS) & 0x0000FFFF;
376 REG(uart_base |
UART_ICR) = 0x0000FFBF;
380 if(input_handler[uart] !=
NULL) {
381 input_handler[uart]((
unsigned char)(REG(uart_base |
UART_DR) & 0xFF));
385 mis = REG(uart_base |
UART_DR);
393 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
396 #define UART_ISR(u) void uart##u##_isr(void) { uart_isr(u); }
#define GPIO_PORT_TO_BASE(PORT)
Converts a port number to the port base address.
#define SYS_CTRL_RCGCUART_UART0
UART0 Clock, CPU running.
#define UART_FR
UART flag.
#define NVIC_INT_UART1
UART1.
#define NVIC_INT_UART0
UART0.
#define UART_CTL_RTSEN
UART RTS flow-control enable (UART1 only)
#define UART_CTL_CTSEN
UART CTS flow-control enable (UART1 only)
#define SYS_CTRL_DCGCUART_UART0
UART0 Clock, PM0.
#define UART_DR
UART data.
#define SYS_CTRL_DCGCUART
UART[1:0] clocks - PM0.
#define UART_IM_RXIM
UART receive interrupt mask.
Header file with register and macro declarations for the cc2538 GPIO module.
void uart_set_input(uint8_t uart, int(*input)(unsigned char c))
Assigns a callback to be called when the UART receives a byte.
void uart_init(const unsigned int uart_num, uint32_t module_clk_hz, const uint32_t baud)
Initialize UART.
#define UART_IM_BEIM
UART break error mask.
#define SYS_CTRL_SCGCUART_UART1
UART1 Clock, CPU IDLE.
#define UART1_CONF_BAUD_RATE
Default UART1 baud rate.
#define SYS_CTRL_RCGCUART_UART1
UART1 Clock, CPU running.
#define UART_MIS
UART masked interrupt status.
void ioc_set_over(uint8_t port, uint8_t pin, uint8_t over)
Set Port:Pin override function.
#define NULL
The null pointer.
Header file with declarations for the I/O Control module.
#define UART_CTL_UARTEN
UART enable.
#define SYS_CTRL_SCGCUART
UART[1:0] clocks - sleep mode.
#define UART_IFLS_TXIFLSEL_1_2
UART TX FIFO >= 1/2 empty.
#define UART_IFLS_RXIFLSEL_1_8
UART RX FIFO >= 1/8 full.
#define UART_IM_RTIM
UART receive time-out mask.
#define GPIO_PERIPHERAL_CONTROL(PORT_BASE, PIN_MASK)
Configure the pin to be under peripheral control with PIN_MASK of port with PORT_BASE.
#define UART_FR_TXFE
UART transmit FIFO empty.
void nvic_interrupt_enable(uint32_t intr)
Enables interrupt intr.
#define UART_MIS_OEMIS
UART overrun err masked stat.
#define ioc_input_sel(port, pin)
Generates an IOC_INPUT_SEL_PXn value from a port/pin number.
#define UART_FR_TXFF
UART transmit FIFO full.
#define IOC_OVERRIDE_DIS
Override Disabled.
#define UART_LCRH
UART line control.
Header file with register manipulation macro definitions.
Header file for the energy estimation mechanism
void ioc_set_sel(uint8_t port, uint8_t pin, uint8_t sel)
Function select for Port:Pin.
#define UART_IM_FEIM
UART framing error.
#define UART_IM
UART interrupt mask.
#define UART_CC
UART clock configuration.
Header file for the cc2538 System Control driver.
#define UART_MIS_FEMIS
UART framing err masked stat.
#define UART_LCRH_FEN
UART enable FIFOs.
#define UART_FBRD
UART BAUD divisor: fractional.
#define UART_CTL
UART control.
#define IOC_OVERRIDE_OE
Output Enable.
#define UART_MIS_BEMIS
UART break err masked stat.
#define UART_IFLS
UART interrupt FIFO level.
#define SYS_CTRL_SCGCUART_UART0
UART0 Clock, CPU IDLE.
#define UART_MIS_RTMIS
UART RX time-out masked stat.
void lpm_register_peripheral(lpm_periph_permit_pm1_func_t permit_pm1_func)
Register a peripheral function which will get called by the LPM module to get 'permission' to drop to...
void uart_write_byte(uint8_t uart, uint8_t b)
Sends a single character down the UART.
#define GPIO_PIN_MASK(PIN)
Converts a pin number to a pin mask.
#define UART_ECR
UART RX status and err clear.
#define UART_ICR
UART interrupt clear.
#define UART_FR_RXFE
UART receive FIFO empty.
#define SYS_CTRL_DCGCUART_UART1
UART1 Clock, PM0.
#define UART_IBRD
UART BAUD divisor: integer.
#define IOC_UARTCTS_UART1
UART1 CTS.
#define UART_IM_OEIM
UART overrun error mask.
#define SYS_CTRL_RCGCUART
UART[1:0] clocks - active mode.
#define IOC_UARTRXD_UART0
UART0 RX.
#define UART_MIS_RXMIS
UART RX masked intr stat.
#define IOC_UARTRXD_UART1
UART1 RX.
#define UART0_CONF_BAUD_RATE
Default UART0 baud rate.