4 Streaming I/O

Because TTA/TCE is an environment without operating system, there is also no file system available for implementing file-based I/O. Therefore, one popular way to get input and output to/from the TTA is using shared memory for communicating the data. For stream processing type of applications, one can also use an I/O function unit that implements the required operations for streaming.

TCE ships with example operations for implementing stream type input/output. These operations can be used to read and write samples from streams in the designed TTA processor. The basic interface of the operations allows reading and writing samples from the streams and querying the status of an input or output stream (buffer full/empty, etc.). The status operations are provided to allow the software running in the TTA to do something useful while the buffer is empty or full, for example switch to another thread. Otherwise, in case one tries to read/write a sample from/to a stream whose buffer is empty/full, the TTA is locked and the cycles until the situation resolves are wasted.

The example streaming operations in the base operation set are called STREAM_IN, STREAM_OUT, STREAM_IN_STATUS, and STREAM_OUT_STATUS. These operations have a simulation behavior definition which simulates the stream I/O by reading/writing from/to files stored in the file system of the simulator host. The files are called ttasim_stream.in for the input stream and ttasim_stream.out for the output stream and should reside in the directory where the simulator is started. The file names can be customized using environment variables TTASIM_STREAM_OUT_FILE and TTASIM_STREAM_IN_FILE, respectively.

Here is an example C code that implements streaming I/O with the operations:

#include "tceops.h"

int main()
{
    char byte;
    int status;

    while (1)
    {
        _TCE_STREAM_IN_STATUS(0, status);

        if (status == 0)
            break;

        _TCE_STREAM_IN(0, byte);
        _TCE_STREAM_OUT(byte);
    }

    return 0;
}

This code uses the TCE operation invocation macros from tceops.h to read bytes from the input stream and write the same bytes to the output stream until there is no more data left. This situation is indicated with the status code 0 queried with the STREAM_IN_STATUS operation. The value means the stream buffer is empty, which means the file simulating the input buffer has reached the end of file.

You can test the code by creating a file ttasim_stream.in with some test data. The code should create a copy of that file to the stream output file ttasim_stream.out.

Pekka Jääskeläinen 2010-05-28