Author Topic: UART XON/XOFF  (Read 10467 times)

Offline kyork

  • Newbie
  • *
  • Posts: 6
    • View Profile
UART XON/XOFF
« on: August 29, 2008, 10:23:43 PM »
This may be a simple misunderstanding on my part.  When operating in XON/XOFF mode, should the driver pass those control bytes to the application when fnRead() is called?

Code: [Select]
TTYTABLE tInterfaceParameters;       //table for passing information to driver
QUEUE_HANDLE serialPortId;

tInterfaceParameters.Channel = 1;  // serial 0, 1, 2, 3, 4, etc.
tInterfaceParameters.ucSpeed =  SERIAL_BAUD_57600; // baud rate
tInterfaceParameters.Rx_tx_sizes.RxQueueSize = RX_BUFFER_SIZE;       // input buffer size
tInterfaceParameters.Rx_tx_sizes.TxQueueSize = TX_BUFFER_SIZE; // outpu buffer size
tInterfaceParameters.Task_to_wake = 0;
tInterfaceParameters.usConfig = (CHAR_8 | NO_PARITY | USE_XON_OFF | ONE_STOP | NO_HANDSHAKE | CHAR_MODE);    

serialPortId = fnOpen(TYPE_TTY, FOR_I_O, &tInterfaceParameters);
if ( serialPortId != 0 )  // open or change the channel with defined configurations (initially inactive)
{
fnDriver( serialPortId, (RX_ON | TX_ON), 0 );        // enable RX & TX
}

And then later
Code: [Select]
int count = fnRead(serialPortId, inBuffer, inBlockLen);

inBuffer will contain a 0x11, the XON byte.  Should this be the case?  Shouldn't the driver remove those control bytes? 

Offline kyork

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: UART XON/XOFF
« Reply #1 on: August 29, 2008, 11:48:46 PM »
I don't know if the behavior is correct, but I changed:

Code: [Select]
else if ((XON_CODE == ch) && (tx_ctl->ucState & TX_WAIT)) {
    tx_ctl->ucState &= ~TX_WAIT;                                 // unblock transmitter
    send_next_byte(Channel, tx_ctl);                             // restart transmission, if paused
    return;
}
to
Code: [Select]
else if(XON_CODE == ch) {           
    if (tx_ctl->ucState & TX_WAIT) {
        tx_ctl->ucState &= ~TX_WAIT;                                 // unblock transmitter
        send_next_byte(Channel, tx_ctl);                             // restart transmission, if paused           
    }
    return;
}
in fnSciRxByte() in Tty_drv.c and it fixed my issue.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: UART XON/XOFF
« Reply #2 on: August 30, 2008, 12:12:11 AM »
Hi

I believe your understand is correct. When the sequence XOFF, XON, XOFF, XON occurs it works correctly. If, however, XON is received when not expected (no XOFF before) I think that it is not correct to pass the character to the input buffer.

It seems sensible to improve this:

        else if (XON_CODE == ch) {                                       // {13}
            if (tx_ctl->ucState & TX_WAIT) {                             // if in XOFF state
                tx_ctl->ucState &= ~TX_WAIT;                             // unblock transmitter
                send_next_byte(Channel, tx_ctl);                         // restart transmission
            }
            return;
        }


This is slightly different from your fix since it doesn't call send_next_byte() if it was not in XOFF state. Probably calling this will not cause any real problem but this takes no risks.

Thanks!

Regards

Mark