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

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

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