source: rtems/c/src/lib/libbsp/lm32/shared/console/uart.c @ c2e32ff

4.115
Last change on this file since c2e32ff was c2e32ff, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 20, 2014 at 2:25:41 PM

lm32 BSP shared and lm32_evr: Fix BSPs

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2 *  Uart driver for Lattice Mico32 (lm32) UART
3 */
4
5/*
6 *  COPYRIGHT (c) 1989-1999.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.org/license/LICENSE.
12 *
13 *  Jukka Pietarinen <jukka.pietarinen@mrf.fi>, 2008,
14 *  Micro-Research Finland Oy
15 */
16
17#include "../include/system_conf.h"
18#include "uart.h"
19#include <bsp.h>
20#include <rtems/libio.h>
21
22static inline int uartread(unsigned int reg)
23{
24  return *((int*)(UART_BASE_ADDRESS + reg));
25}
26
27static inline void uartwrite(unsigned int reg, int value)
28{
29  *((int*)(UART_BASE_ADDRESS + reg)) = value;
30}
31
32void BSP_uart_init(int baud)
33{
34  /* Disable UART interrupts */
35  uartwrite(LM32_UART_IER, 0);
36
37  /* Line control 8 bit, 1 stop, no parity */
38  uartwrite(LM32_UART_LCR, LM32_UART_LCR_8BIT);
39
40  /* Modem control, DTR = 1, RTS = 1 */
41  uartwrite(LM32_UART_MCR, LM32_UART_MCR_DTR | LM32_UART_MCR_RTS);
42
43  /* Set baud rate */
44  uartwrite(LM32_UART_DIV, CPU_FREQUENCY/baud);
45}
46
47void BSP_uart_polled_write(char ch)
48{
49  /* Insert CR before LF */
50  if (ch == '\n')
51    BSP_uart_polled_write('\r');
52  /* Wait until THR is empty. */
53  while (!(uartread(LM32_UART_LSR) & LM32_UART_LSR_THRE));
54  uartwrite(LM32_UART_RBR, ch);
55}
56
57int BSP_uart_polled_read( void )
58{
59  /* Wait until there is a byte in RBR */
60  while (!(uartread(LM32_UART_LSR) & LM32_UART_LSR_DR));
61  return (int) uartread(LM32_UART_RBR);
62}
63
64char BSP_uart_is_character_ready(char *ch)
65{
66  if (uartread(LM32_UART_LSR) & LM32_UART_LSR_DR)
67    {
68      *ch = (char) uartread(LM32_UART_RBR);
69      return true;
70    }
71  *ch = '0';
72  return false;
73}
Note: See TracBrowser for help on using the repository browser.