Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:44

0001 /*
0002  *  Driver for Milkymist UART
0003  *
0004  *  The license and distribution terms for this file may be
0005  *  found in the file LICENSE in this distribution or at
0006  *  http://www.rtems.org/license/LICENSE.
0007  *
0008  *  COPYRIGHT (c) 2010 Sebastien Bourdeauducq
0009  *  COPYRIGHT (c) Yann Sionneau <yann.sionneau@telecom-sudparis.eu> (GSoC 2010)
0010  *  Telecom SudParis
0011  */
0012 
0013 #include <rtems.h>
0014 #include <rtems/libio.h>
0015 #include "../include/system_conf.h"
0016 #include "uart.h"
0017 
0018 void BSP_uart_init(int baud)
0019 {
0020   MM_WRITE(MM_UART_DIV, MM_READ(MM_FREQUENCY)/baud/16);
0021 }
0022 
0023 void BSP_uart_polled_write(char ch)
0024 {
0025   rtems_interrupt_level level;
0026 
0027   rtems_interrupt_disable(level);
0028   while(!(MM_READ(MM_UART_STAT) & UART_STAT_THRE));
0029   MM_WRITE(MM_UART_RXTX, ch);
0030   while(!(MM_READ(MM_UART_STAT) & UART_STAT_THRE));
0031   rtems_interrupt_enable(level);
0032 }
0033 
0034 int BSP_uart_polled_read(void)
0035 {
0036   char r;
0037   rtems_interrupt_level level;
0038 
0039   rtems_interrupt_disable(level);
0040   while(!(MM_READ(MM_UART_STAT) & UART_STAT_RX_EVT));
0041   r = MM_READ(MM_UART_RXTX);
0042   MM_WRITE(MM_UART_STAT, UART_STAT_RX_EVT);
0043   rtems_interrupt_enable(level);
0044 
0045   return r;
0046 }