Mercurial > ecos
annotate packages/io/serial/current/src/arm/pid_serial_with_ints.c @ 48:1370c5e55234 ecos-sw-1999-10-25
Merge from eCos master repository on 1999-10-25-21:18:27-BST
| author | jlarmour |
|---|---|
| date | Mon, 25 Oct 1999 20:48:32 +0000 |
| parents | 7253dcc42a09 |
| children | 6e51d764f8f1 |
| rev | line source |
|---|---|
| 2 | 1 //========================================================================== |
| 2 // | |
| 3 // io/serial/arm/pid_serial_with_ints.c | |
| 4 // | |
| 5 // ARM PID Serial I/O Interface Module (interrupt driven) | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
| 9 // | |
| 10 // ------------------------------------------- | |
| 11 // The contents of this file are subject to the Cygnus eCos Public License | |
| 12 // Version 1.0 (the "License"); you may not use this file except in | |
| 13 // compliance with the License. You may obtain a copy of the License at | |
| 14 // http://sourceware.cygnus.com/ecos | |
| 15 // | |
| 16 // Software distributed under the License is distributed on an "AS IS" | |
| 17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 18 // License for the specific language governing rights and limitations under | |
| 19 // the License. | |
| 20 // | |
| 21 // The Original Code is eCos - Embedded Cygnus Operating System, released | |
| 22 // September 30, 1998. | |
| 23 // | |
| 24 // The Initial Developer of the Original Code is Cygnus. Portions created | |
| 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. | |
| 26 // ------------------------------------------- | |
| 27 // | |
| 28 //####COPYRIGHTEND#### | |
| 29 //========================================================================== | |
| 30 //#####DESCRIPTIONBEGIN#### | |
| 31 // | |
|
18
7253dcc42a09
Merge from eCos master repository on 1999-06-25-15:31:50-BST
jlarmour
parents:
6
diff
changeset
|
32 // Author(s): gthomas |
|
7253dcc42a09
Merge from eCos master repository on 1999-06-25-15:31:50-BST
jlarmour
parents:
6
diff
changeset
|
33 // Contributors: gthomas |
|
7253dcc42a09
Merge from eCos master repository on 1999-06-25-15:31:50-BST
jlarmour
parents:
6
diff
changeset
|
34 // Date: 1999-02-04 |
|
7253dcc42a09
Merge from eCos master repository on 1999-06-25-15:31:50-BST
jlarmour
parents:
6
diff
changeset
|
35 // Purpose: PID Serial I/O module (interrupt driven version) |
| 2 | 36 // Description: |
| 37 // | |
| 38 //####DESCRIPTIONEND#### | |
| 39 // | |
| 40 //========================================================================== | |
| 41 | |
| 42 #include <pkgconf/system.h> | |
| 43 #include <pkgconf/io_serial.h> | |
| 44 #include <pkgconf/io.h> | |
| 45 #include <cyg/io/io.h> | |
| 46 #include <cyg/hal/hal_intr.h> | |
| 47 #include <cyg/io/devtab.h> | |
| 48 #include <cyg/io/serial.h> | |
|
18
7253dcc42a09
Merge from eCos master repository on 1999-06-25-15:31:50-BST
jlarmour
parents:
6
diff
changeset
|
49 #include <cyg/infra/diag.h> |
| 2 | 50 |
| 51 #ifdef CYGPKG_IO_SERIAL_ARM_PID | |
| 52 #include "pid_serial.h" | |
| 53 | |
| 54 typedef struct pid_serial_info { | |
| 55 CYG_ADDRWORD base; | |
| 56 CYG_WORD int_num; | |
| 57 cyg_interrupt serial_interrupt; | |
| 58 cyg_handle_t serial_interrupt_handle; | |
| 59 } pid_serial_info; | |
| 60 | |
| 61 static bool pid_serial_init(struct cyg_devtab_entry *tab); | |
| 62 static bool pid_serial_putc(serial_channel *chan, unsigned char c); | |
| 63 static Cyg_ErrNo pid_serial_lookup(struct cyg_devtab_entry **tab, | |
| 64 struct cyg_devtab_entry *sub_tab, | |
| 65 const char *name); | |
| 66 static unsigned char pid_serial_getc(serial_channel *chan); | |
| 67 static bool pid_serial_set_config(serial_channel *chan, cyg_serial_info_t *config); | |
| 68 static void pid_serial_start_xmit(serial_channel *chan); | |
| 69 static void pid_serial_stop_xmit(serial_channel *chan); | |
| 70 | |
| 71 static cyg_uint32 pid_serial_ISR(cyg_vector_t vector, cyg_addrword_t data); | |
| 72 static void pid_serial_DSR(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data); | |
| 73 | |
| 74 static SERIAL_FUNS(pid_serial_funs, | |
| 75 pid_serial_putc, | |
| 76 pid_serial_getc, | |
| 77 pid_serial_set_config, | |
| 78 pid_serial_start_xmit, | |
| 79 pid_serial_stop_xmit | |
| 80 ); | |
| 81 | |
| 82 #ifdef CYGPKG_IO_SERIAL_ARM_PID_SERIAL0 | |
| 83 static pid_serial_info pid_serial_info0 = {0x0D800000, CYGNUM_HAL_INTERRUPT_SERIALA}; | |
| 84 #if CYGNUM_IO_SERIAL_ARM_PID_SERIAL0_BUFSIZE > 0 | |
| 85 static unsigned char pid_serial_out_buf0[CYGNUM_IO_SERIAL_ARM_PID_SERIAL0_BUFSIZE]; | |
| 86 static unsigned char pid_serial_in_buf0[CYGNUM_IO_SERIAL_ARM_PID_SERIAL0_BUFSIZE]; | |
| 87 | |
| 88 static SERIAL_CHANNEL_USING_INTERRUPTS(pid_serial_channel0, | |
| 89 pid_serial_funs, | |
| 90 pid_serial_info0, | |
| 91 CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_ARM_PID_SERIAL0_BAUD), | |
| 92 CYG_SERIAL_STOP_DEFAULT, | |
| 93 CYG_SERIAL_PARITY_DEFAULT, | |
| 94 CYG_SERIAL_WORD_LENGTH_DEFAULT, | |
| 95 CYG_SERIAL_FLAGS_DEFAULT, | |
| 96 &pid_serial_out_buf0[0], sizeof(pid_serial_out_buf0), | |
| 97 &pid_serial_in_buf0[0], sizeof(pid_serial_in_buf0) | |
| 98 ); | |
| 99 #else | |
| 100 static SERIAL_CHANNEL(pid_serial_channel0, | |
| 101 pid_serial_funs, | |
| 102 pid_serial_info0, | |
| 103 CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_ARM_PID_SERIAL0_BAUD), | |
| 104 CYG_SERIAL_STOP_DEFAULT, | |
| 105 CYG_SERIAL_PARITY_DEFAULT, | |
| 106 CYG_SERIAL_WORD_LENGTH_DEFAULT, | |
| 107 CYG_SERIAL_FLAGS_DEFAULT | |
| 108 ); | |
| 109 #endif | |
| 110 | |
| 111 DEVTAB_ENTRY(pid_serial_io0, | |
| 112 CYGDAT_IO_SERIAL_ARM_PID_SERIAL0_NAME, | |
| 113 0, // Does not depend on a lower level interface | |
| 114 &serial_devio, | |
| 115 pid_serial_init, | |
| 116 pid_serial_lookup, // Serial driver may need initializing | |
| 117 &pid_serial_channel0 | |
| 118 ); | |
| 119 #endif // CYGPKG_IO_SERIAL_ARM_PID_SERIAL0 | |
| 120 | |
| 121 #ifdef CYGPKG_IO_SERIAL_ARM_PID_SERIAL1 | |
| 122 static pid_serial_info pid_serial_info1 = {0x0D800020, CYGNUM_HAL_INTERRUPT_SERIALB}; | |
| 123 #if CYGNUM_IO_SERIAL_ARM_PID_SERIAL1_BUFSIZE > 0 | |
| 124 static unsigned char pid_serial_out_buf1[CYGNUM_IO_SERIAL_ARM_PID_SERIAL1_BUFSIZE]; | |
| 125 static unsigned char pid_serial_in_buf1[CYGNUM_IO_SERIAL_ARM_PID_SERIAL1_BUFSIZE]; | |
| 126 | |
| 127 static SERIAL_CHANNEL_USING_INTERRUPTS(pid_serial_channel1, | |
| 128 pid_serial_funs, | |
| 129 pid_serial_info1, | |
| 130 CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_ARM_PID_SERIAL1_BAUD), | |
| 131 CYG_SERIAL_STOP_DEFAULT, | |
| 132 CYG_SERIAL_PARITY_DEFAULT, | |
| 133 CYG_SERIAL_WORD_LENGTH_DEFAULT, | |
| 134 CYG_SERIAL_FLAGS_DEFAULT, | |
| 135 &pid_serial_out_buf1[0], sizeof(pid_serial_out_buf1), | |
| 136 &pid_serial_in_buf1[0], sizeof(pid_serial_in_buf1) | |
| 137 ); | |
| 138 #else | |
| 139 static SERIAL_CHANNEL(pid_serial_channel1, | |
| 140 pid_serial_funs, | |
| 141 pid_serial_info1, | |
| 142 CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_ARM_PID_SERIAL1_BAUD), | |
| 143 CYG_SERIAL_STOP_DEFAULT, | |
| 144 CYG_SERIAL_PARITY_DEFAULT, | |
| 145 CYG_SERIAL_WORD_LENGTH_DEFAULT, | |
| 146 CYG_SERIAL_FLAGS_DEFAULT | |
| 147 ); | |
| 148 #endif | |
| 149 | |
| 150 DEVTAB_ENTRY(pid_serial_io1, | |
| 151 CYGDAT_IO_SERIAL_ARM_PID_SERIAL1_NAME, | |
| 152 0, // Does not depend on a lower level interface | |
| 153 &serial_devio, | |
| 154 pid_serial_init, | |
| 155 pid_serial_lookup, // Serial driver may need initializing | |
| 156 &pid_serial_channel1 | |
| 157 ); | |
| 158 #endif // CYGPKG_IO_SERIAL_ARM_PID_SERIAL1 | |
| 159 | |
| 160 // Internal function to actually configure the hardware to desired baud rate, etc. | |
| 161 static bool | |
| 162 pid_serial_config_port(serial_channel *chan, cyg_serial_info_t *new_config, bool init) | |
| 163 { | |
| 164 pid_serial_info *pid_chan = (pid_serial_info *)chan->dev_priv; | |
| 165 volatile struct serial_port *port = (volatile struct serial_port *)pid_chan->base; | |
| 166 unsigned short baud_divisor = select_baud[new_config->baud]; | |
| 167 unsigned char _lcr, _ier; | |
| 168 if (baud_divisor == 0) return false; // Invalid configuration | |
| 169 _ier = port->ier; | |
| 170 port->ier = 0; // Disable port interrupts while changing hardware | |
| 171 _lcr = select_word_length[new_config->word_length - CYGNUM_SERIAL_WORD_LENGTH_5] | | |
| 172 select_stop_bits[new_config->stop] | | |
| 173 select_parity[new_config->parity]; | |
| 174 port->lcr = _lcr; | |
| 175 port->lcr |= LCR_DL; | |
| 176 port->mdl = baud_divisor >> 8; | |
| 177 port->ldl = baud_divisor & 0xFF; | |
| 178 port->lcr &= ~LCR_DL; | |
| 179 if (init) { | |
| 180 port->fcr = 0x07; // Enable and clear FIFO | |
| 181 if (chan->out_cbuf.len != 0) { | |
| 182 port->ier = IER_RCV; | |
| 183 } else { | |
| 184 port->ier = 0; | |
| 185 } | |
| 186 port->mcr = MCR_INT|MCR_DTR|MCR_RTS; // Master interrupt enable | |
| 187 } else { | |
| 188 port->ier = _ier; | |
| 189 } | |
| 190 if (new_config != &chan->config) { | |
| 191 chan->config = *new_config; | |
| 192 } | |
| 193 return true; | |
| 194 } | |
| 195 | |
| 196 // Function to initialize the device. Called at bootstrap time. | |
| 197 static bool | |
| 198 pid_serial_init(struct cyg_devtab_entry *tab) | |
| 199 { | |
| 200 serial_channel *chan = (serial_channel *)tab->priv; | |
| 201 pid_serial_info *pid_chan = (pid_serial_info *)chan->dev_priv; | |
| 202 #ifdef CYGDBG_IO_INIT | |
| 203 diag_printf("PID SERIAL init - dev: %x.%d\n", pid_chan->base, pid_chan->int_num); | |
| 204 #endif | |
| 205 (chan->callbacks->serial_init)(chan); // Really only required for interrupt driven devices | |
| 206 if (chan->out_cbuf.len != 0) { | |
| 207 cyg_drv_interrupt_create(pid_chan->int_num, | |
| 208 99, // Priority - what goes here? | |
| 209 (cyg_addrword_t)chan, // Data item passed to interrupt handler | |
| 210 pid_serial_ISR, | |
| 211 pid_serial_DSR, | |
| 212 &pid_chan->serial_interrupt_handle, | |
| 213 &pid_chan->serial_interrupt); | |
| 214 cyg_drv_interrupt_attach(pid_chan->serial_interrupt_handle); | |
| 215 cyg_drv_interrupt_unmask(pid_chan->int_num); | |
| 216 } | |
| 217 pid_serial_config_port(chan, &chan->config, true); | |
| 218 return true; | |
| 219 } | |
| 220 | |
| 221 // This routine is called when the device is "looked" up (i.e. attached) | |
| 222 static Cyg_ErrNo | |
| 223 pid_serial_lookup(struct cyg_devtab_entry **tab, | |
| 224 struct cyg_devtab_entry *sub_tab, | |
| 225 const char *name) | |
| 226 { | |
| 227 serial_channel *chan = (serial_channel *)(*tab)->priv; | |
| 228 (chan->callbacks->serial_init)(chan); // Really only required for interrupt driven devices | |
| 229 return ENOERR; | |
| 230 } | |
| 231 | |
| 232 // Send a character to the device output buffer. | |
| 233 // Return 'true' if character is sent to device | |
| 234 static bool | |
| 235 pid_serial_putc(serial_channel *chan, unsigned char c) | |
| 236 { | |
| 237 pid_serial_info *pid_chan = (pid_serial_info *)chan->dev_priv; | |
| 238 volatile struct serial_port *port = (volatile struct serial_port *)pid_chan->base; | |
| 239 if (port->lsr & LSR_THE) { | |
| 240 // Transmit buffer is empty | |
| 241 port->thr = c; | |
| 242 return true; | |
| 243 } else { | |
| 244 // No space | |
| 245 return false; | |
| 246 } | |
| 247 } | |
| 248 | |
| 249 // Fetch a character from the device input buffer, waiting if necessary | |
| 250 static unsigned char | |
| 251 pid_serial_getc(serial_channel *chan) | |
| 252 { | |
| 253 unsigned char c; | |
| 254 pid_serial_info *pid_chan = (pid_serial_info *)chan->dev_priv; | |
| 255 volatile struct serial_port *port = (volatile struct serial_port *)pid_chan->base; | |
| 256 while ((port->lsr & LSR_RSR) == 0) ; // Wait for char | |
| 257 c = port->rhr; | |
| 258 return c; | |
| 259 } | |
| 260 | |
| 261 // Set up the device characteristics; baud rate, etc. | |
| 262 static bool | |
| 263 pid_serial_set_config(serial_channel *chan, cyg_serial_info_t *config) | |
| 264 { | |
| 265 return pid_serial_config_port(chan, config, false); | |
| 266 } | |
| 267 | |
| 268 // Enable the transmitter on the device | |
| 269 static void | |
| 270 pid_serial_start_xmit(serial_channel *chan) | |
| 271 { | |
| 272 pid_serial_info *pid_chan = (pid_serial_info *)chan->dev_priv; | |
| 273 volatile struct serial_port *port = (volatile struct serial_port *)pid_chan->base; | |
| 274 port->ier |= IER_XMT; // Enable xmit interrupt | |
| 275 } | |
| 276 | |
| 277 // Disable the transmitter on the device | |
| 278 static void | |
| 279 pid_serial_stop_xmit(serial_channel *chan) | |
| 280 { | |
| 281 pid_serial_info *pid_chan = (pid_serial_info *)chan->dev_priv; | |
| 282 volatile struct serial_port *port = (volatile struct serial_port *)pid_chan->base; | |
| 283 port->ier &= ~IER_XMT; // Disable xmit interrupt | |
| 284 } | |
| 285 | |
| 286 // Serial I/O - low level interrupt handler (ISR) | |
| 287 static cyg_uint32 | |
| 288 pid_serial_ISR(cyg_vector_t vector, cyg_addrword_t data) | |
| 289 { | |
| 290 serial_channel *chan = (serial_channel *)data; | |
| 291 pid_serial_info *pid_chan = (pid_serial_info *)chan->dev_priv; | |
| 292 cyg_drv_interrupt_mask(pid_chan->int_num); | |
| 293 cyg_drv_interrupt_acknowledge(pid_chan->int_num); | |
| 294 return CYG_ISR_CALL_DSR; // Cause DSR to be run | |
| 295 } | |
| 296 | |
| 297 // Serial I/O - high level interrupt handler (DSR) | |
| 298 static void | |
| 299 pid_serial_DSR(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data) | |
| 300 { | |
| 301 serial_channel *chan = (serial_channel *)data; | |
| 302 pid_serial_info *pid_chan = (pid_serial_info *)chan->dev_priv; | |
| 303 volatile struct serial_port *port = (volatile struct serial_port *)pid_chan->base; | |
| 304 unsigned char isr; | |
|
6
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
305 isr = port->isr & 0x0E; |
|
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
306 if (isr == ISR_Tx) { |
| 2 | 307 (chan->callbacks->xmt_char)(chan); |
|
48
1370c5e55234
Merge from eCos master repository on 1999-10-25-21:18:27-BST
jlarmour
parents:
18
diff
changeset
|
308 } else if (isr == ISR_RxTO) { |
|
1370c5e55234
Merge from eCos master repository on 1999-10-25-21:18:27-BST
jlarmour
parents:
18
diff
changeset
|
309 (chan->callbacks->rcv_char)(chan, port->rhr); |
|
6
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
310 } else if (isr == ISR_Rx) { |
| 2 | 311 (chan->callbacks->rcv_char)(chan, port->rhr); |
| 312 } | |
| 313 cyg_drv_interrupt_unmask(pid_chan->int_num); | |
| 314 } | |
| 315 #endif |
