XON / XOFF uart flow control

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
sethu_jangala
XCore Expert
Posts: 589
Joined: Wed Feb 29, 2012 10:03 am

XON / XOFF uart flow control

Post by sethu_jangala »

Hi everybody,

I'm working with a project that needs to transfer higth speed serial data from a XMOS device to a HOST PC.

I used the modules fast uart (https://github.com/xcore/sc_uart) prensent in gihub repository.

I want to implement a serial XON/XOFF software flow control to transfer data from XMOS device to a host PC.

I wrote the following code, but seems doesn't work well.


//Send buffer data to UART
void SendToSerial(streaming chanend DataFromFIFO, streaming chanend DataFromHostPC, streaming chanend DataToHostPC) {
    unsigned int     rx;
    unsigned char  XON = 1;
    unsigned char     RxFlow;    
    
    while(1){
        select {
        // xon/xoff char received from PC
        case DataFromHostPC:> RxFlow:

            if ( RxFlow == XOFF_CHAR){
                XON = 0;
            }
            if ( RxFlow == XON_CHAR ){
                XON = 1;

            }
            break;
            
        // data from fifo to be sent over uart to the host pc
        case DataFromFIFO :> rx:

                // Checking if the transmission must be stopped
                while( XON == 0 ){
                    DataFromHostPC:>RxFlow; // wait PC command

                    if ( RxFlow == XON_CHAR ){
                        XON = 1;
                    }

                }        // wating xon char ok

                DataToHostPC <: rx;
                break;


        }
    }

}

In main, i have:

    par {
        GetFromFIFO(DataFromFIFO);                                        //  Get data from fifo
        HandleUart(DataFromFIFO,DataFromHostPC,DataToHostPC);            //     Send data to UART
        ReceiveXOFF(DataFromHostPC);                                    // Get data received from PC via UART
        SendToHost(DataToHostPC);                                        //     Send data to UART
    }

 

Checking the serial lines with the oscilloscope, when the XOFF char is sent by the host pc, the data doesn't stops. Where is the problem?

How to proper implement xon/xoff software flow control? Is there any sample code?

Thanks in advance.

 

 

 
 
Read


Last edited by sethu_jangala on Wed Sep 24, 2014 5:17 am, edited 4 times in total.
Reason: Edit


User avatar
sethu_jangala
XCore Expert
Posts: 589
Joined: Wed Feb 29, 2012 10:03 am

Post by sethu_jangala »

Try changing streaming channels to normal channels and see if this solves your issue. Can you export and send the workspace if possible?
fdaniii
Member
Posts: 9
Joined: Tue Nov 22, 2011 3:20 pm

Post by fdaniii »

sethu wrote:Try changing streaming channels to normal channels and see if this solves your issue. Can you export and send the workspace if possible?
Thanks for your replay.

The uart fast library has a prototype that takes as input a streaming channel:

Code: Select all

void uart_rx_fast(in port p, streaming chanend c, int clocks);
i need to change the library...

In this case what is the difference between streaming channel and channel??
User avatar
sethu_jangala
XCore Expert
Posts: 589
Joined: Wed Feb 29, 2012 10:03 am

Post by sethu_jangala »

fdaniii wrote: The uart fast library has a prototype that takes as input a streaming channel:

Code: Select all

void uart_rx_fast(in port p, streaming chanend c, int clocks);
i need to change the library...

In this case what is the difference between streaming channel and channel??
If the module uses streaming channel you have to use streaming channel in the application. You can find information regarding the difference between streaming channel and normal channel from the following link:
http://www.xcore.com/questions/1778/how ... al-channel

Sethu.