Section 4.8. Using Output Streams


4.8. Using Output Streams

Output streams may be written using the co_stream_write function as follows:

 co_stream_open(output_stream, O_WRONLY, INT_TYPE(32)); for (i=0; i < ARRAYSIZE; i++) {     co_stream_write(output_stream, &data[i], sizeof(int32)); } co_stream_close(output_stream); 

The stream must be a writable stream (opened with the O_WRONLY direction indicator), and the data must match the size of the stream datatype.

The co_stream_write function, when invoked, first checks to see if the specified output stream is full. If the stream is full, the function blocks until there is room in the stream buffer for a write operation to be performed. This is an important aspect of stream behavior: once a stream has been opened and is being used by a producer and consumer process, there is no need for you (as the application programmer) to manage the stream in terms of acknowledgments or other control signals.

There is, of course, a downside to the standard behavior of streams. If your producer and consumer processes are not properly designed, there can be a risk of deadlock conditions, in which neither the producer nor the consumer can proceed with its operations. We'll discuss the issue of stream synchronization and deadlocks in more detail in later chapters.



    Practical FPGA Programming in C
    Practical FPGA Programming in C
    ISBN: 0131543180
    EAN: 2147483647
    Year: 2005
    Pages: 208

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net