Пример #1
0
/*
 * Translate termios flags into SCI settings
 */
int sh_sci_set_attributes(
  int minor,
  const struct termios *t
)
{
    uint8_t  	smr;
    uint8_t  	brr;
    int a;

    tcflag_t c_cflag = t->c_cflag;

    if ( c_cflag & CBAUD ) {
        if ( _sci_get_brparms( c_cflag, &smr, &brr ) != 0 )
            return -1 ;
    }

    if ( c_cflag & CSIZE ) {
        if ( c_cflag & CS8 )
            smr &= ~SCI_SEVEN_BIT_DATA;
        else if ( c_cflag & CS7 )
            smr |= SCI_SEVEN_BIT_DATA;
        else
            return -1 ;
    }

    if ( c_cflag & CSTOPB )
        smr |= SCI_STOP_BITS_2;
    else
        smr &= ~SCI_STOP_BITS_2;

    if ( c_cflag & PARENB )
        smr |= SCI_PARITY_ON ;
    else
        smr &= ~SCI_PARITY_ON ;

    if ( c_cflag & PARODD )
        smr |= SCI_ODD_PARITY ;
    else
        smr &= ~SCI_ODD_PARITY;

    SH_SCI_REG_MASK((SCI_RE | SCI_TE), minor, SCI_SCR);

    SH_SCI_REG_DATA(smr, minor, SCI_SMR);
    SH_SCI_REG_DATA(brr, minor, SCI_BRR);

    for (a=0; a < 10000L; a++) { /* Delay one bit */
        __asm__ volatile ("nop");
    }

    SH_SCI_REG_FLAG((SCI_RE | SCI_TE), minor, SCI_SCR);

    return 0;
}
Пример #2
0
/* Translate termios' tcflag_t into sci settings */
static int _sci_set_cflags(
  struct scidev_t  *sci_dev,
  tcflag_t          c_cflag
)
{
  uint8_t  	smr;
  uint8_t  	brr;

  if ( c_cflag & CBAUD )
  {
    if ( _sci_get_brparms( c_cflag, &smr, &brr ) != 0 )
      return -1;
  }

  if ( c_cflag & CSIZE )
  {
    if ( c_cflag & CS8 )
      smr &= ~SCI_SEVEN_BIT_DATA;
    else if ( c_cflag & CS7 )
      smr |= SCI_SEVEN_BIT_DATA;
    else
      return -1;
  }

  if ( c_cflag & CSTOPB )
    smr |= SCI_STOP_BITS_2;
  else
    smr &= ~SCI_STOP_BITS_2;

  if ( c_cflag & PARENB )
    smr |= SCI_PARITY_ON;
  else
    smr &= ~SCI_PARITY_ON;

  if ( c_cflag & PARODD )
    smr |= SCI_ODD_PARITY;
  else
    smr &= ~SCI_ODD_PARITY;

  write8( smr, sci_dev->addr + SCI_SMR );
  write8( brr, sci_dev->addr + SCI_BRR );

  return 0;
}