This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using stream and UART PSP driver

I have a problem in usage of the UART PSP driver with the Stream in receive mode.

When I try to read some amount of data from the stream it blocks and returns only when all 1024 bytes of data is received.

I need to get block of data immediately as it comes.

len = Stream_read (g_UART_rx,&g_UART_BUF_rx,1024,BIOS_WAIT_FOREVER,NULL);

How can I determine an amount of data ready to read in the stream?

My goal is to read each data burst from the UART device.

UART peripheral receives blocks of data with different length. The time data block comes is indeterministic.

I must process each block separately as it comes.

My system configuration:

ccsv_4.2.0.10018
bios_6.30.02.42
xdc_3.20.03.63
edma3_lld_2.10.03.04
ipc_1.21.02.23
ndk_2.20.00.19
psp_02.10.01

  • What device are you working on?

  • Hi Yuriy,

     Stream_read() is a synchronous call(blocking call) which blocks forever until all the bytes requested are not read. You can read blocks of data(block by block) provided you know the block size in prior.

     If you are reading variable lengths of data and the lengths are known in prior, then you can also use asynchronous calls to achieve what you desire.

    Like, you can replace Stream_read() with Stream_issue() and Stream_reclaim() pair. Stream_issue is a non blocking call, and it comes back to the application after submitting the packet. The received data can be reclaimed by Stream_reclaim() call.

    Yuriy Kubasov said:
    UART peripheral receives blocks of data with different length. The time data block comes is indeterministic.

    So, do you know what are the different lengths of data coming? I mean, are the data lengths known in advance or they are random?. If it is random, it is not possible to achieve what you are looking for (The read will wait(so does Stream_reclaim(..)) until specified number of bytes are read)

     

    By using these asynchronous calls you can do something like this(pseudo code) –

     Stream_issue(handle, buf, 256, NULL, NULL);

     Stream_issue(handle, buf, 256, NULL, NULL);

     Sream_issue(handle, buf, 512, NULL, NULL);

     

    And then, reclaim each of the buffers –

     Stream_reclaim(handle, (Ptr *)&buf, BIOS_WAIT_FOREVER, NULL, NULL);

     Stream_reclaim(handle, (Ptr *)&buf, BIOS_WAIT_FOREVER, NULL, NULL);

     Stream_reclaim(handle, (Ptr *)&buf, BIOS_WAIT_FOREVER, NULL, NULL);

     

    Please refer the BIOS Userguide for more details regarding these calls and its correct implementation.

    Hope this helps..

     

    Best Regards,

    Raghavendra

  • Raghavendra, thank you for clarification.

    I`m using OMAPL137.

    I`ll try to resolve this with the pair of  Stream_issue - Stream_reclaim with timeout.

    If timeout occures, I would call Stream_abort and then Stream_issue with the smaller buffer.

    Best regards, Yuriy

  • My solution:

    unsigned long Uart_recv(void* pBuf, unsigned long size)
    {
        size_t len;
        Uart_Stats rxStats;
        Ptr pbuf = &g_UART_BUF_rx;    
        if(size>UART_MAX_BUF_LEN)
            return 0;    
         Stream_issue(g_UART_rx, pbuf, size, NULL,NULL);      
      while(1){                                                                                                   //waiting for UART_RX packet
            Stream_control(g_UART_rx, Uart_IOCTL_GET_STATS, (UArg)&rxStats, NULL);
            if (rxStats.rxBytes!=g_rxBytes){
                len=rxStats.rxBytes-g_rxBytes;
                g_rxBytes=rxStats.rxBytes;
                break;
            }
            else{
                Task_sleep(100);
            }
      }
        Stream_abort(g_UART_rx, NULL);
        Stream_reclaim(g_UART_rx, &pbuf, BIOS_WAIT_FOREVER, NULL,NULL);
        if (len){

                                                  //after Stream_abort rxBytes in UART driver increase by packet length 
            g_rxBytes+=len;
            memcpy(pBuf,g_UART_BUF_rx,len);
        }
      return len;
    }