📄 console.c
字号:
/* * Serial Channel Configuration */ DUMR1A = m340_uart_config[UART_CHANNEL_A].parity_mode | m340_uart_config[UART_CHANNEL_A].bits_per_char | m340_RxRTS; if (m340_uart_config[UART_CHANNEL_A].rx_mode==UART_FIFO_FULL) DUMR1A |= m340_R_F | m340_ERR; /* * Serial Channel Configuration 2 */ DUMR2A |= m340_normal; /* * Enable Channel A: transmitter and receiver */ DUCRA = m340_Transmitter_Enable | m340_Receiver_Enable; } /* channel A enabled */ /***************************************************************************** ** CHANNEL B ** *****************************************************************************/ if (CHANNEL_ENABLED_B) { /* we mustn't set the console vector twice! */ if ((USE_INTERRUPTS_B && !(CHANNEL_ENABLED_A)) || (USE_INTERRUPTS_B && CHANNEL_ENABLED_A && !USE_INTERRUPTS_A)) { rtems_isr_entry old_handler; rtems_status_code sc; extern void _Debug_ISR_Handler_Console(void); sc = rtems_interrupt_catch (InterruptHandler, CONSOLE_VECTOR, &old_handler); /* uncomment this if you want to pass control to your own ISR handler it may be usefull to do so to check for performances with an oscilloscope */ /* { proc_ptr ignored; _CPU_ISR_install_raw_handler( CONSOLE_VECTOR, _Debug_ISR_Handler_Console, &ignored ); } */ /* * Interrupt Enable Register * Enable Interrupts on Channel A Receiver Ready */ set_DUIER(m340_RxRDYB); } else { /* * Disable Interrupts on channel B */ unset_DUIER(m340_RxRDYB&m340_TxRDYB); } /* * Change set of baud speeds * disable input control */ /* no good uart configuration ? */ if (uart_config.nb<2) rtems_fatal_error_occurred (-1); /* don't set DUACR twice! */ if (!CHANNEL_ENABLED_A) { if (uart_config.baud_speed_table[UART_CHANNEL_B].set==1) DUACR = m340_BRG_Set1; else DUACR = m340_BRG_Set2; } /* * make OPCR an auxiliary function serving the communication channels */ if (!CHANNEL_ENABLED_A) DUOPCR = m340_OPCR_Aux; /* poll the XTAL_RDY bit until it is cleared to ensure that an unstable crystal input is not applied to the baud rate generator */ while (DUISR & m340_XTAL_RDY) continue; /* * Serial Channel Baud Speed */ DUCSRB = (uart_config.baud_speed_table[UART_CHANNEL_B].rcs << 4) | (uart_config.baud_speed_table[UART_CHANNEL_B].tcs); /* * Serial Channel Configuration */ DUMR1B = m340_uart_config[UART_CHANNEL_B].parity_mode | m340_uart_config[UART_CHANNEL_B].bits_per_char | m340_RxRTS; if (m340_uart_config[UART_CHANNEL_B].rx_mode==UART_FIFO_FULL) DUMR1B |= m340_R_F | m340_ERR; /* * Serial Channel Configuration 2 */ DUMR2B |= m340_normal; /* * Enable Channel A: transmitter and receiver */ DUCRB = m340_Transmitter_Enable | m340_Receiver_Enable; } /* channel B enabled */}/****************************************************** Name: SetAttributes Input parameters: termios structure, channel Output parameters: - Description: return whether there's a character in the receive buffer TO DO: add the channel # to check for!! *****************************************************/static intSetAttributes (int minor, const struct termios *t){ rtems_interrupt_level level; float ispeed, ospeed; int isp, osp; /* output speed */ if (t->c_cflag & CBAUDEX) osp = (t->c_cflag & CBAUD) + CBAUD + 1; else osp = t->c_cflag & CBAUD; /* input speed */ isp = (t->c_cflag / (CIBAUD / CBAUD)) & CBAUD; /* convert it */ ispeed = termios_baud_rates_equivalence(isp); ospeed = termios_baud_rates_equivalence(osp); if (ispeed || ospeed) { /* update config table */ m340_uart_config[UART_CHANNEL_A].rx_baudrate = ((minor==UART_CHANNEL_A)&&(ispeed!=0)) ? ispeed : m340_uart_config[UART_CHANNEL_A].rx_baudrate; m340_uart_config[UART_CHANNEL_A].tx_baudrate = ((minor==UART_CHANNEL_A)&&(ospeed!=0)) ? ospeed : m340_uart_config[UART_CHANNEL_A].tx_baudrate; m340_uart_config[UART_CHANNEL_B].rx_baudrate = ((minor==UART_CHANNEL_B)&&(ispeed!=0)) ? ispeed : m340_uart_config[UART_CHANNEL_B].rx_baudrate; m340_uart_config[UART_CHANNEL_B].tx_baudrate = ((minor==UART_CHANNEL_B)&&(ospeed!=0)) ? ospeed : m340_uart_config[UART_CHANNEL_B].tx_baudrate; } /* change parity */ if (t->c_cflag & PARENB) { if (t->c_cflag & PARODD) m340_uart_config[minor].parity_mode = m340_Odd_Parity; else m340_uart_config[minor].parity_mode = m340_Even_Parity; } /* change bits per character */ if (t->c_cflag & CSIZE) { switch (t->c_cflag & CSIZE) { default: break; case CS5: m340_uart_config[minor].bits_per_char = m340_5bpc; break; case CS6: m340_uart_config[minor].bits_per_char = m340_6bpc; break; case CS7: m340_uart_config[minor].bits_per_char = m340_7bpc; break; case CS8: m340_uart_config[minor].bits_per_char = m340_8bpc; break; } } /* if serial module configuration has been changed */ if (t->c_cflag & (CBAUD | CIBAUD | CSIZE | PARENB)) { rtems_interrupt_disable(level); /* reinit the UART */ dbugInitialise(); rtems_interrupt_enable (level); } return 0;}/****************************************************** Name: console_initialize Input parameters: MAJOR # of console_driver, minor is always 0, args are always NULL Output parameters: - Description: Reserve resources consumed by this driver TODO: We should pass m340_uart_config table in arg *****************************************************/rtems_device_driver console_initialize( rtems_device_major_number major, rtems_device_minor_number minor, void *arg){ rtems_status_code status; int i; /* * Set up TERMIOS */ rtems_termios_initialize (); /* * Do device-specific initialization */ Init_UART_Table(); dbugInitialise (); Fifo_Full_Timer_initialize(); /* * Register the devices */ for (i=0; i<UART_NUMBER_OF_CHANNELS; i++) { if (m340_uart_config[i].enable) { status = rtems_io_register_name (m340_uart_config[i].name, major, i); if (status != RTEMS_SUCCESSFUL) rtems_fatal_error_occurred (status); } } return RTEMS_SUCCESSFUL;}/****************************************************** Name: console_open Input parameters: channel #, arg Output parameters: - Description: open the device *****************************************************/rtems_device_driver console_open( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){ rtems_status_code sc = 0; static const rtems_termios_callbacks intrCallbacks = { NULL, /* firstOpen */ NULL, /* lastClose */ NULL, /* pollRead */ InterruptWrite, /* write */ SetAttributes, /* setAttributes */ NULL, /* stopRemoteTx */ NULL, /* startRemoteTx */ 1 /* outputUsesInterrupts */ }; static const rtems_termios_callbacks pollCallbacks = { NULL, /* firstOpen */ NULL, /* lastClose */ dbugRead, /* pollRead */ dbugWrite, /* write */ SetAttributes, /* setAttributes */ NULL, /* stopRemoteTx */ NULL, /* startRemoteTx */ 0 /* outputUsesInterrupts */ }; if (minor==UART_CHANNEL_A) { if (USE_INTERRUPTS_A) { rtems_libio_open_close_args_t *args = arg; sc |= rtems_termios_open (major, minor, arg, &intrCallbacks); ttypA = args->iop->data1; } else { sc |= rtems_termios_open (major, minor, arg, &pollCallbacks); } } else if (minor==UART_CHANNEL_B) { if (USE_INTERRUPTS_B) { rtems_libio_open_close_args_t *args = arg; sc |= rtems_termios_open (major, minor, arg, &intrCallbacks); ttypB = args->iop->data1; } else { sc |= rtems_termios_open (major, minor, arg, &pollCallbacks); } } else return RTEMS_INVALID_NUMBER; return sc;} /****************************************************** Name: console_close Input parameters: channel #, termios args Output parameters: - Description: close the device *****************************************************/rtems_device_driver console_close( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){ return rtems_termios_close (arg);}/****************************************************** Name: console_read Input parameters: channel #, termios args Output parameters: - Description: read the device *****************************************************/rtems_device_driver console_read( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){ return rtems_termios_read (arg);}/****************************************************** Name: console_write Input parameters: channel #, termios args Output parameters: - Description: write to the device *****************************************************/rtems_device_driver console_write( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){ return rtems_termios_write (arg);}/****************************************************** Name: console_control Input parameters: channel #, termios args Output parameters: - Description: Handle ioctl request *****************************************************/rtems_device_driver console_control( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){ rtems_libio_ioctl_args_t *args = arg; if (args->command == RTEMS_IO_SET_ATTRIBUTES) SetAttributes (minor, (struct termios *)args->buffer); return rtems_termios_ioctl (arg);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -