[457b6ae] | 1 | /* |
---|
| 2 | * Initialize SMC1 for console IO. |
---|
| 3 | * |
---|
| 4 | * Based on the `gen68302' board support package, and covered by the |
---|
| 5 | * original distribution terms. |
---|
| 6 | * |
---|
| 7 | * W. Eric Norum |
---|
| 8 | * Saskatchewan Accelerator Laboratory |
---|
| 9 | * University of Saskatchewan |
---|
| 10 | * Saskatoon, Saskatchewan, CANADA |
---|
| 11 | * eric@skatter.usask.ca |
---|
| 12 | * |
---|
| 13 | * $Id$ |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | /* |
---|
| 17 | * |
---|
| 18 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
| 19 | * On-Line Applications Research Corporation (OAR). |
---|
| 20 | * All rights assigned to U.S. Government, 1994. |
---|
| 21 | * |
---|
| 22 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
| 23 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
| 24 | * notice must appear in all copies of this file and its derivatives. |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | #define GEN68360_INIT |
---|
| 28 | |
---|
| 29 | #include <bsp.h> |
---|
| 30 | #include <rtems/libio.h> |
---|
[bdf531ee] | 31 | #include "m68360.h" |
---|
[457b6ae] | 32 | |
---|
| 33 | /* console_initialize |
---|
| 34 | * |
---|
| 35 | * This routine initializes the console IO driver. |
---|
| 36 | * |
---|
| 37 | * Input parameters: NONE |
---|
| 38 | * |
---|
| 39 | * Output parameters: NONE |
---|
| 40 | * |
---|
| 41 | * Return values: |
---|
| 42 | */ |
---|
| 43 | |
---|
| 44 | /* |
---|
| 45 | * Place buffer descriptors at end of User Data/BD space in dual-port RAM |
---|
| 46 | */ |
---|
| 47 | #define consoleRxBd ((volatile m360BufferDescriptor_t *)((char *)m360.dpram1 + \ |
---|
| 48 | (sizeof(m360.dpram2) - 2*sizeof(m360BufferDescriptor_t)))) |
---|
| 49 | #define consoleTxBd ((volatile m360BufferDescriptor_t *)((char *)m360.dpram1 + \ |
---|
| 50 | (sizeof(m360.dpram2) - sizeof(m360BufferDescriptor_t)))) |
---|
| 51 | |
---|
| 52 | /* |
---|
| 53 | * I/O buffers can be in ordindary RAM |
---|
| 54 | */ |
---|
| 55 | static volatile char rxBuf, txBuf; |
---|
| 56 | |
---|
| 57 | rtems_device_driver console_initialize( |
---|
| 58 | rtems_device_major_number major, |
---|
| 59 | rtems_device_minor_number minor, |
---|
| 60 | void *arg |
---|
| 61 | ) |
---|
| 62 | { |
---|
| 63 | rtems_status_code status; |
---|
| 64 | |
---|
| 65 | /* |
---|
| 66 | * Configure port B pins to enable SMTXD1 and SMRXD1 pins |
---|
| 67 | */ |
---|
| 68 | m360.pbpar |= 0xC0; |
---|
| 69 | m360.pbdir &= ~0xC0; |
---|
| 70 | m360.pbodr &= ~0xC0; |
---|
| 71 | |
---|
| 72 | /* |
---|
| 73 | * Set up BRG1 (9,600 baud) |
---|
| 74 | */ |
---|
| 75 | m360.brgc1 = M360_BRG_RST; |
---|
| 76 | m360.brgc1 = M360_BRG_EN | M360_BRG_EXTC_BRGCLK | M360_BRG_9600; |
---|
| 77 | |
---|
| 78 | /* |
---|
| 79 | * Put SMC1 in NMSI mode, connect SMC1 to BRG1 |
---|
| 80 | */ |
---|
| 81 | m360.simode |= M360_SI_SMC1_BRG1; |
---|
| 82 | |
---|
| 83 | /* |
---|
| 84 | * Set up SMC1 parameter RAM common to all protocols |
---|
| 85 | */ |
---|
| 86 | m360.smc1p.rbase = (char *)consoleRxBd - (char *)&m360; |
---|
| 87 | m360.smc1p.tbase = (char *)consoleTxBd - (char *)&m360; |
---|
| 88 | m360.smc1p.rfcr = M360_RFCR_MOT | M360_RFCR_DMA_SPACE; |
---|
| 89 | m360.smc1p.tfcr = M360_TFCR_MOT | M360_TFCR_DMA_SPACE; |
---|
| 90 | m360.smc1p.mrblr = 1; |
---|
| 91 | |
---|
| 92 | /* |
---|
| 93 | * Set up SMC1 parameter RAM UART-specific parameters |
---|
| 94 | */ |
---|
| 95 | m360.smc1p.un.uart.max_idl = 0; |
---|
| 96 | m360.smc1p.un.uart.brklen = 0; |
---|
| 97 | m360.smc1p.un.uart.brkec = 0; |
---|
| 98 | m360.smc1p.un.uart.brkcr = 0; |
---|
| 99 | |
---|
| 100 | /* |
---|
| 101 | * Set up the Receive Buffer Descriptor |
---|
| 102 | */ |
---|
| 103 | consoleRxBd->status = M360_BD_EMPTY | M360_BD_WRAP; |
---|
| 104 | consoleRxBd->length = 0; |
---|
| 105 | consoleRxBd->buffer = &rxBuf; |
---|
| 106 | |
---|
| 107 | /* |
---|
| 108 | * Setup the Transmit Buffer Descriptor |
---|
| 109 | */ |
---|
| 110 | consoleTxBd->length = 1; |
---|
| 111 | consoleTxBd->status = M360_BD_WRAP; |
---|
| 112 | consoleTxBd->buffer = &txBuf; |
---|
| 113 | |
---|
| 114 | /* |
---|
| 115 | * Set up SMC1 general and protocol-specific mode registers |
---|
| 116 | */ |
---|
| 117 | m360.smc1.smce = ~0; /* Clear any pending events */ |
---|
| 118 | m360.smc1.smcm = 0; /* Mask all interrupt/event sources */ |
---|
| 119 | m360.smc1.smcmr = M360_SMCMR_CLEN(9) | M360_SMCMR_SM_UART; |
---|
| 120 | |
---|
| 121 | /* |
---|
| 122 | * Send "Init parameters" command |
---|
| 123 | */ |
---|
| 124 | m360.cr = M360_CR_OP_INIT_RX_TX | M360_CR_CHAN_SMC1 | M360_CR_FLG; |
---|
| 125 | while (m360.cr & M360_CR_FLG) |
---|
| 126 | continue; |
---|
| 127 | |
---|
| 128 | /* |
---|
| 129 | * Enable receiver and transmitter |
---|
| 130 | */ |
---|
| 131 | m360.smc1.smcmr |= M360_SMCMR_TEN | M360_SMCMR_REN; |
---|
| 132 | |
---|
| 133 | status = rtems_io_register_name( |
---|
| 134 | "/dev/console", |
---|
| 135 | major, |
---|
| 136 | (rtems_device_minor_number)0); |
---|
| 137 | if (status != RTEMS_SUCCESSFUL) |
---|
| 138 | rtems_fatal_error_occurred(status); |
---|
| 139 | return RTEMS_SUCCESSFUL; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | /* is_character_ready |
---|
| 143 | * |
---|
| 144 | * Check to see if a character is available on the console port. If so, |
---|
| 145 | * then return a TRUE (along with the character). Otherwise return FALSE. |
---|
| 146 | * |
---|
| 147 | * Input parameters: pointer to location in which to return character |
---|
| 148 | * |
---|
| 149 | * Output parameters: character (if available) |
---|
| 150 | * |
---|
| 151 | * Return values: TRUE - character available |
---|
| 152 | * FALSE - no character available |
---|
| 153 | */ |
---|
| 154 | |
---|
| 155 | rtems_boolean is_character_ready( |
---|
| 156 | char *ch /* -> character */ |
---|
| 157 | ) |
---|
| 158 | { |
---|
| 159 | if (consoleRxBd->status & M360_BD_EMPTY) |
---|
| 160 | return FALSE; |
---|
| 161 | *ch = rxBuf; |
---|
| 162 | consoleRxBd->status = M360_BD_EMPTY | M360_BD_WRAP; |
---|
| 163 | return TRUE; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | /* inbyte |
---|
| 168 | * |
---|
| 169 | * Receive a character from the console port |
---|
| 170 | * |
---|
| 171 | * Input parameters: NONE |
---|
| 172 | * |
---|
| 173 | * Output parameters: NONE |
---|
| 174 | * |
---|
| 175 | * Return values: character read |
---|
| 176 | */ |
---|
| 177 | |
---|
| 178 | char inbyte( void ) |
---|
| 179 | { |
---|
| 180 | char ch; |
---|
| 181 | |
---|
| 182 | while (is_character_ready (&ch) == FALSE) |
---|
| 183 | continue; |
---|
| 184 | return ch; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | /* outbyte |
---|
| 189 | * |
---|
| 190 | * Transmit a character to the console serial port |
---|
| 191 | * |
---|
| 192 | * Input parameters: |
---|
| 193 | * ch - character to be transmitted |
---|
| 194 | * |
---|
| 195 | * Output parameters: NONE |
---|
| 196 | */ |
---|
| 197 | |
---|
| 198 | void outbyte( |
---|
| 199 | char ch |
---|
| 200 | ) |
---|
| 201 | { |
---|
| 202 | if (ch == '\n') |
---|
| 203 | outbyte('\r'); |
---|
| 204 | while (consoleTxBd->status & M360_BD_READY) |
---|
| 205 | continue; |
---|
| 206 | txBuf = ch; |
---|
| 207 | consoleTxBd->status = M360_BD_READY | M360_BD_WRAP; |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | /* |
---|
| 211 | * Open entry point |
---|
| 212 | */ |
---|
| 213 | |
---|
| 214 | rtems_device_driver console_open( |
---|
| 215 | rtems_device_major_number major, |
---|
| 216 | rtems_device_minor_number minor, |
---|
| 217 | void * arg |
---|
| 218 | ) |
---|
| 219 | { |
---|
| 220 | return RTEMS_SUCCESSFUL; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | /* |
---|
| 224 | * Close entry point |
---|
| 225 | */ |
---|
| 226 | |
---|
| 227 | rtems_device_driver console_close( |
---|
| 228 | rtems_device_major_number major, |
---|
| 229 | rtems_device_minor_number minor, |
---|
| 230 | void * arg |
---|
| 231 | ) |
---|
| 232 | { |
---|
| 233 | return RTEMS_SUCCESSFUL; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | /* |
---|
| 237 | * read bytes from the serial port. We only have stdin. |
---|
| 238 | */ |
---|
| 239 | |
---|
| 240 | rtems_device_driver console_read( |
---|
| 241 | rtems_device_major_number major, |
---|
| 242 | rtems_device_minor_number minor, |
---|
| 243 | void * arg |
---|
| 244 | ) |
---|
| 245 | { |
---|
| 246 | rtems_libio_rw_args_t *rw_args; |
---|
| 247 | char *buffer; |
---|
| 248 | int maximum; |
---|
| 249 | int count = 0; |
---|
| 250 | |
---|
| 251 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 252 | |
---|
| 253 | buffer = rw_args->buffer; |
---|
| 254 | maximum = rw_args->count; |
---|
| 255 | |
---|
| 256 | for (count = 0; count < maximum; count++) { |
---|
| 257 | buffer[ count ] = inbyte(); |
---|
| 258 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
| 259 | buffer[ count++ ] = '\n'; |
---|
| 260 | buffer[ count ] = 0; |
---|
| 261 | break; |
---|
| 262 | } |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | rw_args->bytes_moved = count; |
---|
| 266 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | /* |
---|
| 270 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
| 271 | */ |
---|
| 272 | |
---|
| 273 | rtems_device_driver console_write( |
---|
| 274 | rtems_device_major_number major, |
---|
| 275 | rtems_device_minor_number minor, |
---|
| 276 | void * arg |
---|
| 277 | ) |
---|
| 278 | { |
---|
| 279 | int count; |
---|
| 280 | int maximum; |
---|
| 281 | rtems_libio_rw_args_t *rw_args; |
---|
| 282 | char *buffer; |
---|
| 283 | |
---|
| 284 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 285 | |
---|
| 286 | buffer = rw_args->buffer; |
---|
| 287 | maximum = rw_args->count; |
---|
| 288 | |
---|
| 289 | for (count = 0; count < maximum; count++) { |
---|
| 290 | if ( buffer[ count ] == '\n') { |
---|
| 291 | outbyte('\r'); |
---|
| 292 | } |
---|
| 293 | outbyte( buffer[ count ] ); |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | rw_args->bytes_moved = maximum; |
---|
| 297 | return 0; |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | /* |
---|
| 301 | * IO Control entry point |
---|
| 302 | */ |
---|
| 303 | |
---|
| 304 | rtems_device_driver console_control( |
---|
| 305 | rtems_device_major_number major, |
---|
| 306 | rtems_device_minor_number minor, |
---|
| 307 | void * arg |
---|
| 308 | ) |
---|
| 309 | { |
---|
| 310 | return RTEMS_SUCCESSFUL; |
---|
| 311 | } |
---|