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

4.104.115
Last change on this file since d7a915da was d7a915da, checked in by Joel Sherrill <joel.sherrill@…>, on 06/04/09 at 16:33:31

2009-06-04 Xi Yang <hiyangxi@…>

  • Makefile.am, configure.ac, preinstall.am: New Gumstix BSP and PXA255 support.
  • pxa255/clock/clock.c, pxa255/ffuart/ffuart.c, pxa255/include/bits.h, pxa255/include/ffuart.h, pxa255/include/pxa255.h, pxa255/irq/bsp_irq_asm.S, pxa255/irq/bsp_irq_init.c, pxa255/irq/irq.c, pxa255/irq/irq.h, pxa255/pmc/pmc.c, pxa255/timer/timer.c: New files.
  • Property mode set to 100755
File size: 5.1 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
13#include <bsp.h>
14#include <rtems/libio.h>
15#include <termios.h>
16
17#include <pxa255.h>
18#include <ffuart.h>
19#include <rtems/bspIo.h>
20#include <libchip/serial.h>
21#include <libchip/sersupp.h>
22
23volatile int dbg_dly;
24
25/* static function prototypes */
26static int     ffuart_first_open(int major, int minor, void *arg);
27static int     ffuart_last_close(int major, int minor, void *arg);
28static int     ffuart_read(int minor);
29static int     ffuart_write(int minor, const char *buf, int len);
30static void    ffuart_init(int minor);
31static void    ffuart_write_polled(int minor, char c);
32static int     ffuart_set_attributes(int minor, const struct termios *t);
33
34/* Pointers to functions for handling the UART. */
35console_fns ffuart_fns =
36{
37    libchip_serial_default_probe,
38    ffuart_first_open,
39    ffuart_last_close,
40    ffuart_read,
41    ffuart_write,
42    ffuart_init,
43    ffuart_write_polled,   /* not used in this driver */
44    ffuart_set_attributes,
45    FALSE      /* TRUE if interrupt driven, FALSE if not. */
46};
47
48
49/*
50 * This is called the first time each device is opened. Since
51 * the driver is polled, we don't have to do anything. If the driver
52 * were interrupt driven, we'd enable interrupts here.
53 */
54static int ffuart_first_open(int major, int minor, void *arg)
55{
56    return 0;
57}
58
59
60/*
61 * This is called the last time each device is closed.  Since
62 * the driver is polled, we don't have to do anything. If the driver
63 * were interrupt driven, we'd disable interrupts here.
64 */
65static int ffuart_last_close(int major, int minor, void *arg)
66{
67    return 0;
68}
69
70
71/*
72 * Read one character from UART.
73 *
74 * return -1 if there's no data, otherwise return
75 * the character in lowest 8 bits of returned int.
76 */
77static int ffuart_read(int minor)
78{
79    char c;
80    console_tbl *console_entry;
81    ffuart_reg_t *ffuart;
82
83    console_entry = BSP_get_uart_from_minor(minor);
84
85    if (console_entry == NULL) {
86        return -1;
87    }
88
89    ffuart = (ffuart_reg_t *)console_entry->ulCtrlPort1;
90
91    if (!(ffuart->lsr & FULL_RECEIVE)) {
92        return -1;
93    }
94   
95    c  = ffuart->rbr & 0xff;
96   
97    return c;
98}
99
100
101/*
102 * Write buffer to UART
103 *
104 * return 1 on success, -1 on error
105 */
106static int ffuart_write(int minor, const char *buf, int len)
107{
108    int i, x;
109    char c;
110    console_tbl *console_entry;
111    ffuart_reg_t *ffuart;
112
113    console_entry = BSP_get_uart_from_minor(minor);
114
115    if (console_entry == NULL) {
116        return -1;
117    }
118
119    ffuart = (ffuart_reg_t *)console_entry->ulCtrlPort1;
120
121    for (i = 0; i < len; i++) {
122
123        while(1) {
124            if (ffuart->lsr & SEND_EMPTY) {
125                break;
126            }
127        }
128       
129        c = (char) buf[i];
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          ffuart->rbr = c;
141        }
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
224BSP_output_char_function_type BSP_output_char = _BSP_put_char;
Note: See TracBrowser for help on using the repository browser.