1 | /* |
---|
2 | * uMon Support Output Driver |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2009. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * Modified by Fernando Nicodemos <fgnicodemos@terra.com.br> |
---|
8 | * from NCB - Sistemas Embarcados Ltda. (Brazil) |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.com/license/LICENSE. |
---|
13 | * |
---|
14 | * $Id$ |
---|
15 | */ |
---|
16 | |
---|
17 | #include <rtems/umon.h> |
---|
18 | #include <libchip/serial.h> |
---|
19 | #include <libchip/sersupp.h> |
---|
20 | |
---|
21 | /* static function prototypes */ |
---|
22 | static int umoncons_first_open(int major, int minor, void *arg); |
---|
23 | static int umoncons_last_close(int major, int minor, void *arg); |
---|
24 | static int umoncons_read(int minor); |
---|
25 | static ssize_t umoncons_write(int minor, const char *buf, size_t len); |
---|
26 | static void umoncons_init(int minor); |
---|
27 | static void umoncons_write_polled(int minor, char c); |
---|
28 | static int umoncons_set_attributes(int minor, const struct termios *t); |
---|
29 | |
---|
30 | /* Pointers to functions for handling the UART. */ |
---|
31 | console_fns umoncons_fns = |
---|
32 | { |
---|
33 | libchip_serial_default_probe, |
---|
34 | umoncons_first_open, |
---|
35 | umoncons_last_close, |
---|
36 | umoncons_read, |
---|
37 | umoncons_write, |
---|
38 | umoncons_init, |
---|
39 | umoncons_write_polled, /* not used in this driver */ |
---|
40 | umoncons_set_attributes, |
---|
41 | false /* TRUE if interrupt driven, FALSE if not. */ |
---|
42 | }; |
---|
43 | |
---|
44 | /*********************************************************************/ |
---|
45 | /* Functions called via callbacks (i.e. the ones in uart_fns */ |
---|
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 | */ |
---|
53 | static int umoncons_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 | */ |
---|
64 | static int umoncons_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 | */ |
---|
76 | static int umoncons_read(int minor) |
---|
77 | { |
---|
78 | if ( !mon_gotachar() ) |
---|
79 | return -1; |
---|
80 | return mon_getchar(); |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | /* |
---|
85 | * Write buffer to LCD |
---|
86 | * |
---|
87 | * return 1 on success, -1 on error |
---|
88 | */ |
---|
89 | static ssize_t umoncons_write(int minor, const char *buf, size_t len) |
---|
90 | { |
---|
91 | size_t i; |
---|
92 | |
---|
93 | for ( i=0 ; i<len ; i++ ) |
---|
94 | mon_putchar( buf[i] ); |
---|
95 | |
---|
96 | return len; |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | /* Set up the uMon driver. */ |
---|
101 | static void umoncons_init(int minor) |
---|
102 | { |
---|
103 | rtems_umon_connect(); |
---|
104 | } |
---|
105 | |
---|
106 | /* This is used for putchark support */ |
---|
107 | static void umoncons_write_polled(int minor, char c) |
---|
108 | { |
---|
109 | mon_putchar( c ); |
---|
110 | } |
---|
111 | |
---|
112 | /* This is for setting baud rate, bits, etc. */ |
---|
113 | static int umoncons_set_attributes(int minor, const struct termios *t) |
---|
114 | { |
---|
115 | return 0; |
---|
116 | } |
---|
117 | |
---|
118 | /***********************************************************************/ |
---|
119 | /* |
---|
120 | * The following functions are not used by TERMIOS, but other RTEMS |
---|
121 | * functions use them instead. |
---|
122 | */ |
---|
123 | /***********************************************************************/ |
---|
124 | /* |
---|
125 | * Read from UART. This is used in the exit code, and can't |
---|
126 | * rely on interrupts. |
---|
127 | */ |
---|
128 | int umoncons_poll_read(int minor) |
---|
129 | { |
---|
130 | if (!mon_gotachar()) |
---|
131 | return -1; |
---|
132 | return mon_getchar(); |
---|
133 | } |
---|