1 | /* |
---|
2 | * Driver for Milkymist UART |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.com/license/LICENSE. |
---|
7 | * |
---|
8 | * $Id$ |
---|
9 | * |
---|
10 | * COPYRIGHT (c) 2010 Sebastien Bourdeauducq |
---|
11 | * COPYRIGHT (c) Yann Sionneau <yann.sionneau@telecom-sudparis.eu> (GSoC 2010) |
---|
12 | * Telecom SudParis |
---|
13 | */ |
---|
14 | |
---|
15 | #include <rtems.h> |
---|
16 | #include <rtems/libio.h> |
---|
17 | #include "../include/system_conf.h" |
---|
18 | #include "uart.h" |
---|
19 | |
---|
20 | bool BSP_uart_txbusy; |
---|
21 | |
---|
22 | void BSP_uart_init(int baud) |
---|
23 | { |
---|
24 | MM_WRITE(MM_UART_DIV, CPU_FREQUENCY/baud/16); |
---|
25 | } |
---|
26 | |
---|
27 | void BSP_uart_polled_write(char ch) |
---|
28 | { |
---|
29 | int ip; |
---|
30 | rtems_interrupt_level level; |
---|
31 | |
---|
32 | rtems_interrupt_disable(level); |
---|
33 | if (BSP_uart_txbusy) { |
---|
34 | /* wait for the end of the transmission by the IRQ-based driver */ |
---|
35 | do { |
---|
36 | lm32_read_interrupts(ip); |
---|
37 | } while (!(ip & (1 << MM_IRQ_UARTTX))); |
---|
38 | lm32_interrupt_ack(1 << MM_IRQ_UARTTX); |
---|
39 | } |
---|
40 | MM_WRITE(MM_UART_RXTX, ch); |
---|
41 | do { |
---|
42 | lm32_read_interrupts(ip); |
---|
43 | } while (!(ip & (1 << MM_IRQ_UARTTX))); |
---|
44 | /* if TX was busy, do not ack the IRQ |
---|
45 | * so that the IRQ-based driver ISR is run */ |
---|
46 | if (!BSP_uart_txbusy) |
---|
47 | lm32_interrupt_ack(1 << MM_IRQ_UARTTX); |
---|
48 | rtems_interrupt_enable(level); |
---|
49 | } |
---|
50 | |
---|
51 | int BSP_uart_polled_read(void) |
---|
52 | { |
---|
53 | int ip; |
---|
54 | char r; |
---|
55 | rtems_interrupt_level level; |
---|
56 | |
---|
57 | rtems_interrupt_disable(level); |
---|
58 | do { |
---|
59 | lm32_read_interrupts(ip); |
---|
60 | } while (!(ip & (1 << MM_IRQ_UARTRX))); |
---|
61 | lm32_interrupt_ack(1 << MM_IRQ_UARTRX); |
---|
62 | r = MM_READ(MM_UART_RXTX); |
---|
63 | rtems_interrupt_enable(level); |
---|
64 | |
---|
65 | return r; |
---|
66 | } |
---|