extern speed_t cfgetospeed( const struct termios *termios_p ) { CYG_REPORT_FUNCTYPE( "returning speed code %d" ); CYG_CHECK_DATA_PTRC( termios_p ); CYG_REPORT_FUNCARG1XV( termios_p ); CYG_REPORT_RETVAL( termios_p->c_ospeed ); return termios_p->c_ospeed; } // cfgetospeed()
extern int tcflush( int fildes, int queue_sel ) { cyg_file *fp; int ret; CYG_REPORT_FUNCTYPE( "returning %d" ); CYG_REPORT_FUNCARG2DV( fildes, queue_sel ); if ( !isatty(fildes) ) { errno = ENOTTY; CYG_REPORT_RETVAL( -1 ); return -1; } fp = cyg_fp_get( fildes ); if ( NULL == fp ) { errno = EBADF; CYG_REPORT_RETVAL( -1 ); return -1; } switch( queue_sel ) { case TCIOFLUSH: ret = fp->f_ops->fo_getinfo( fp, CYG_IO_GET_CONFIG_SERIAL_OUTPUT_FLUSH, NULL, 0 ); // fallthrough case TCIFLUSH: ret = fp->f_ops->fo_getinfo( fp, CYG_IO_GET_CONFIG_SERIAL_INPUT_FLUSH, NULL, 0 ); break; case TCOFLUSH: ret = fp->f_ops->fo_getinfo( fp, CYG_IO_GET_CONFIG_SERIAL_OUTPUT_FLUSH, NULL, 0 ); break; default: ret = EINVAL; break; } cyg_fp_free( fp ); if ( ret > 0 ) { errno = ret; CYG_REPORT_RETVAL( -1 ); return -1; } CYG_REPORT_RETVAL( 0 ); return 0; } // tcflush()
extern int tcsetattr( int fildes, int optact, const struct termios *termios_p ) { cyg_file *fp; int ret; setattr_struct attr; int len = sizeof( attr ); CYG_REPORT_FUNCTYPE( "returning %d" ); CYG_REPORT_FUNCARG3( "fildes=%d, optact=%d, termios_p=%08x", fildes, optact, termios_p ); CYG_CHECK_DATA_PTRC( termios_p ); if ( !isatty(fildes) ) { errno = ENOTTY; CYG_REPORT_RETVAL( -1 ); return -1; } if ( (optact != TCSANOW) && (optact != TCSADRAIN) && (optact != TCSAFLUSH) ) { errno = EINVAL; CYG_REPORT_RETVAL( -1 ); return -1; } fp = cyg_fp_get( fildes ); if ( NULL == fp ) { errno = EBADF; CYG_REPORT_RETVAL( -1 ); return -1; } attr.termios_p = termios_p; attr.optact = optact; ret = fp->f_ops->fo_setinfo( fp, CYG_IO_SET_CONFIG_TERMIOS, &attr, len); cyg_fp_free( fp ); if ( ret > 0 ) { errno = ret; CYG_REPORT_RETVAL( -1 ); return -1; } CYG_REPORT_RETVAL( 0 ); return 0; } // tcsetattr()
extern int cfsetispeed( struct termios *termios_p, speed_t speed ) { CYG_REPORT_FUNCTYPE( "returning %d" ); CYG_CHECK_DATA_PTRC( termios_p ); CYG_REPORT_FUNCARG2( "termios_p=%08x, speed=%d", termios_p, speed ); if ( speed > B115200 ) { errno = EINVAL; CYG_REPORT_RETVAL( -1 ); return -1; } termios_p->c_ispeed = speed; CYG_REPORT_RETVAL( 0 ); return 0; } // cfsetispeed()
extern int tcgetattr( int fildes, struct termios *termios_p ) { cyg_file *fp; int ret; int len = sizeof( *termios_p ); CYG_REPORT_FUNCTYPE( "returning %d" ); CYG_REPORT_FUNCARG2( "fildes=%d, termios_p=%08x", fildes, termios_p ); CYG_CHECK_DATA_PTRC( termios_p ); if ( !isatty(fildes) ) { errno = ENOTTY; CYG_REPORT_RETVAL( -1 ); return -1; } fp = cyg_fp_get( fildes ); if ( NULL == fp ) { errno = EBADF; CYG_REPORT_RETVAL( -1 ); return -1; } ret = fp->f_ops->fo_getinfo( fp, CYG_IO_GET_CONFIG_TERMIOS, termios_p, len); cyg_fp_free( fp ); if ( ret > 0 ) { errno = ret; CYG_REPORT_RETVAL( -1 ); return -1; } CYG_REPORT_RETVAL( 0 ); return 0; } // tcgetattr()
extern int tcdrain( int fildes ) { cyg_file *fp; int ret; CYG_REPORT_FUNCTYPE( "returning %d" ); CYG_REPORT_FUNCARG1DV( fildes ); if ( !isatty(fildes) ) { errno = ENOTTY; CYG_REPORT_RETVAL( -1 ); return -1; } fp = cyg_fp_get( fildes ); if ( NULL == fp ) { errno = EBADF; CYG_REPORT_RETVAL( -1 ); return -1; } ret = fp->f_ops->fo_getinfo( fp, CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN, NULL, 0 ); cyg_fp_free( fp ); if ( ret > 0 ) { errno = ret; CYG_REPORT_RETVAL( -1 ); return -1; } CYG_REPORT_RETVAL( 0 ); return 0; } // tcdrain()
static Cyg_ErrNo real_termios_init( struct termios_private_info *priv ) { Cyg_ErrNo res; struct termios *t; cyg_serial_info_t dev_conf; cyg_serial_buf_info_t dev_buf_conf; cyg_uint32 len = sizeof( dev_conf ); CYG_REPORT_FUNCTYPE("returning %d"); CYG_REPORT_FUNCARG1XV( priv ); CYG_CHECK_DATA_PTRC( priv ); t = &priv->termios; // Get info from driver res = cyg_io_get_config( priv->dev_handle, CYG_IO_GET_CONFIG_SERIAL_INFO, &dev_conf, &len ); if ( ENOERR == res ) { len = sizeof( dev_buf_conf ); res = cyg_io_get_config( priv->dev_handle, CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO, &dev_buf_conf, &len ); } priv->errbuf = (cyg_uint8 *)malloc( dev_buf_conf.rx_bufsize ); if ( NULL == priv->errbuf ) res = ENOMEM; // FIXME: Are we allowed to do this? priv->errbufpos = priv->errbuf; priv->errbufsize = dev_buf_conf.rx_bufsize; if ( ENOERR != res ) { CYG_REPORT_RETVAL( res ); return res; } // we only support symmetric baud rates t->c_ispeed = t->c_ospeed = map_ecosbaud_to_posixbaud( dev_conf.baud ); t->c_iflag = C_IFLAG_INIT; t->c_oflag = C_OFLAG_INIT; t->c_cflag = C_CFLAG_INIT; t->c_lflag = C_LFLAG_INIT; memcpy( t->c_cc, c_cc_init, sizeof( t->c_cc ) ); switch ( dev_conf.parity ) { case CYGNUM_SERIAL_PARITY_NONE: t->c_iflag |= IGNPAR; break; case CYGNUM_SERIAL_PARITY_ODD: t->c_cflag |= PARODD; // DROPTHROUGH case CYGNUM_SERIAL_PARITY_EVEN: t->c_iflag |= PARENB; break; default: CYG_FAIL( "Unsupported default parity" ); break; } switch( dev_conf.word_length ) { case CYGNUM_SERIAL_WORD_LENGTH_5: t->c_cflag |= CS5; break; case CYGNUM_SERIAL_WORD_LENGTH_6: t->c_cflag |= CS6; break; case CYGNUM_SERIAL_WORD_LENGTH_7: t->c_cflag |= CS7; break; case CYGNUM_SERIAL_WORD_LENGTH_8: t->c_cflag |= CS8; break; default: CYG_FAIL( "Unsupported word length" ); break; } switch ( dev_conf.stop ) { case CYGNUM_SERIAL_STOP_1: // Don't need to do anything break; case CYGNUM_SERIAL_STOP_2: t->c_cflag |= CSTOPB; break; default: CYG_FAIL( "Unsupported number of stop bits" ); break; } switch ( dev_conf.flags ) { case CYGNUM_SERIAL_FLOW_RTSCTS_RX: t->c_cflag |= CRTSCTS; // drop through case CYGNUM_SERIAL_FLOW_XONXOFF_RX: t->c_iflag |= IXOFF; break; case CYGNUM_SERIAL_FLOW_RTSCTS_TX: t->c_cflag |= CRTSCTS; // drop through case CYGNUM_SERIAL_FLOW_XONXOFF_TX: t->c_iflag |= IXON; break; default: // Ignore flags we don't grok break; } return ENOERR; } // real_termios_init()
extern int tcflow( int fildes, int action ) { cyg_file *fp; int ret; cyg_uint32 forcearg; int len = sizeof(forcearg); CYG_REPORT_FUNCTYPE( "returning %d" ); CYG_REPORT_FUNCARG2DV( fildes, action ); if ( !isatty(fildes) ) { errno = ENOTTY; CYG_REPORT_RETVAL( -1 ); return -1; } fp = cyg_fp_get( fildes ); if ( NULL == fp ) { errno = EBADF; CYG_REPORT_RETVAL( -1 ); return -1; } switch( action ) { case TCOOFF: forcearg = CYGNUM_SERIAL_FLOW_THROTTLE_TX; ret = fp->f_ops->fo_setinfo( fp, CYG_IO_SET_CONFIG_SERIAL_FLOW_CONTROL_FORCE, &forcearg, len ); break; case TCOON: forcearg = CYGNUM_SERIAL_FLOW_RESTART_TX; ret = fp->f_ops->fo_setinfo( fp, CYG_IO_SET_CONFIG_SERIAL_FLOW_CONTROL_FORCE, &forcearg, len ); break; case TCIOFF: forcearg = CYGNUM_SERIAL_FLOW_THROTTLE_RX; ret = fp->f_ops->fo_setinfo( fp, CYG_IO_SET_CONFIG_SERIAL_FLOW_CONTROL_FORCE, &forcearg, len ); break; case TCION: forcearg = CYGNUM_SERIAL_FLOW_RESTART_RX; ret = fp->f_ops->fo_setinfo( fp, CYG_IO_SET_CONFIG_SERIAL_FLOW_CONTROL_FORCE, &forcearg, len ); break; default: ret = EINVAL; break; } cyg_fp_free( fp ); if ( ret > 0 ) { errno = ret; CYG_REPORT_RETVAL( -1 ); return -1; } CYG_REPORT_RETVAL( 0 ); return 0; } // tcflow()