source: rtems/c/src/lib/libcpu/arm/pxa255/ffuart/ffuart.c @ 010d830

4.115
Last change on this file since 010d830 was 010d830, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 15, 2010 at 11:28:46 PM

2010-08-15 Joel Sherrill <joel.sherrilL@…>

  • at91rm9200/dbgu/dbgu.c, pxa255/ffuart/ffuart.c: Add BSP_poll_char.
  • Property mode set to 100755
File size: 5.2 KB
Line 
1/*
2 * Console driver for pxa255 full function port by Yang Xi <hiyangxi@gmail.com>
3 * Copyright (c) 2004 by Jay Monkman <jtm@lopingdog.com>
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#include <bsp.h>
13#include <rtems/libio.h>
14#include <termios.h>
15
16#include <pxa255.h>
17#include <ffuart.h>
18#include <rtems/bspIo.h>
19#include <libchip/serial.h>
20#include <libchip/sersupp.h>
21
22volatile int dbg_dly;
23
24/* static function prototypes */
25static int     ffuart_first_open(int major, int minor, void *arg);
26static int     ffuart_last_close(int major, int minor, void *arg);
27static int     ffuart_read(int minor);
28static ssize_t ffuart_write(int minor, const char *buf, size_t len);
29static void    ffuart_init(int minor);
30static void    ffuart_write_polled(int minor, char c);
31static int     ffuart_set_attributes(int minor, const struct termios *t);
32
33/* Pointers to functions for handling the UART. */
34console_fns ffuart_fns =
35{
36    libchip_serial_default_probe,
37    ffuart_first_open,
38    ffuart_last_close,
39    ffuart_read,
40    ffuart_write,
41    ffuart_init,
42    ffuart_write_polled,   /* not used in this driver */
43    ffuart_set_attributes,
44    FALSE      /* TRUE if interrupt driven, FALSE if not. */
45};
46
47
48/*
49 * This is called the first time each device is opened. Since
50 * the driver is polled, we don't have to do anything. If the driver
51 * were interrupt driven, we'd enable interrupts here.
52 */
53static int ffuart_first_open(int major, int minor, void *arg)
54{
55    return 0;
56}
57
58
59/*
60 * This is called the last time each device is closed.  Since
61 * the driver is polled, we don't have to do anything. If the driver
62 * were interrupt driven, we'd disable interrupts here.
63 */
64static int ffuart_last_close(int major, int minor, void *arg)
65{
66    return 0;
67}
68
69
70/*
71 * Read one character from UART.
72 *
73 * return -1 if there's no data, otherwise return
74 * the character in lowest 8 bits of returned int.
75 */
76static int ffuart_read(int minor)
77{
78    char c;
79    console_tbl *console_entry;
80    ffuart_reg_t *ffuart;
81
82    console_entry = BSP_get_uart_from_minor(minor);
83
84    if (console_entry == NULL) {
85        return -1;
86    }
87
88    ffuart = (ffuart_reg_t *)console_entry->ulCtrlPort1;
89
90    if (!(ffuart->lsr & FULL_RECEIVE)) {
91        return -1;
92    }
93
94    c  = ffuart->rbr & 0xff;
95
96    return c;
97}
98
99
100/*
101 * Write buffer to UART
102 *
103 * return 1 on success, -1 on error
104 */
105static ssize_t ffuart_write(int minor, const char *buf, size_t len)
106{
107    size_t i, x;
108    char c;
109    console_tbl *console_entry;
110    ffuart_reg_t *ffuart;
111
112    console_entry = BSP_get_uart_from_minor(minor);
113
114    if (console_entry == NULL) {
115        return -1;
116    }
117
118    ffuart = (ffuart_reg_t *)console_entry->ulCtrlPort1;
119
120    for (i = 0; i < len; i++) {
121
122        while(1) {
123            if (ffuart->lsr & SEND_EMPTY) {
124                break;
125            }
126        }
127
128        c = (char) buf[i];
129#if ON_SKYEYE != 1
130        if(c=='\n'){
131          ffuart->rbr = '\r';
132          for (x = 0; x < 100; x++) {
133            dbg_dly++; /* using a global so this doesn't get optimized out */
134          }
135          while(1){
136            if(ffuart->lsr & SEND_EMPTY){
137              break;
138            }
139          }
140        }
141#endif
142        ffuart->rbr = c;
143
144        /* the TXRDY flag does not seem to update right away (is this true?) */
145        /* so we wait a bit before continuing */
146        for (x = 0; x < 100; x++) {
147            dbg_dly++; /* using a global so this doesn't get optimized out */
148        }
149    }
150
151    return 1;
152}
153
154
155static void ffuart_init(int minor)
156{
157
158
159    console_tbl *console_entry;
160    ffuart_reg_t  *ffuart;
161    unsigned int divisor;
162
163    console_entry = BSP_get_uart_from_minor(minor);
164
165
166
167    if (console_entry == NULL) {
168        return;
169    }
170
171    ffuart = (ffuart_reg_t *)console_entry->ulCtrlPort1;
172    ffuart->lcr |= DLAB;
173    /*Set the Bound*/
174    ffuart->lcr |= DLAB;
175    divisor = FREQUENCY_UART / (115200*16);
176    ffuart->rbr = divisor & 0xff;
177    ffuart->ier = (divisor >> 8)&0xff;
178    /*Disable FIFO*/
179    ffuart->iir = 0;
180    ffuart->lcr &=~DLAB;
181    /*Enable UART*/
182    ffuart->ier = 0x40;
183    ffuart->lcr = EIGHT_BITS_NOPARITY_1STOPBIT;
184
185}
186
187/* I'm not sure this is needed for the shared console driver. */
188static void ffuart_write_polled(int minor, char c)
189{
190    ffuart_write(minor, &c, 1);
191}
192
193/* This is for setting baud rate, bits, etc. */
194static int ffuart_set_attributes(int minor, const struct termios *t)
195{
196    return 0;
197}
198
199/***********************************************************************/
200/*
201 * The following functions are not used by TERMIOS, but other RTEMS
202 * functions use them instead.
203 */
204/***********************************************************************/
205/*
206 * Read from UART. This is used in the exit code, and can't
207 * rely on interrupts.
208 */
209int ffuart_poll_read(int minor)
210{
211    return ffuart_read(minor);
212}
213
214
215/*
216 * Write a character to the console. This is used by printk() and
217 * maybe other low level functions. It should not use interrupts or any
218 * RTEMS system calls. It needs to be very simple
219 */
220static void _BSP_put_char( char c ) {
221    ffuart_write_polled(0, c);
222}
223
224static int _BSP_poll_char(void) {
225  return ffuart_poll_read(0);
226}
227
228BSP_output_char_function_type     BSP_output_char = _BSP_put_char;
229BSP_polling_getchar_function_type BSP_poll_char = _BSP_poll_char;
Note: See TracBrowser for help on using the repository browser.