Controlling Streams
7-22
7.5 Controlling Streams
A physical device typically requires one or more specialized control signals in
order to operate as desired. SIO_ctrl makes it possible to communicate with
the device, passing it commands and arguments. Since each device admits
only specialized commands, you need to consult the documentation for each
particular device. The general calling format is shown in Example 7-10.
Example 7-10.
Using SIO_ctrl to Communicate with a Device
The device associated with stream is passed the command represented by
the device-specific cmd. A generic pointer to the command’s arguments is
also passed to the device. The actual control function that is part of the device
driver then interprets the command and arguments and acts accordingly.
Assume that an analog-to-digital converter device /a2d has a control
operation to change the sample rate. The sample rate might be changed to
12 kHz as shown in Example 7-11.
Example 7-11.
Changing Sample Rate
In some situations, you can synchronize with an I/O device that is doing
buffered I/O. There are two methods to synchronize with the devices:
SIO_idle and SIO_flush. Either function leaves the device in the idled state.
Idling a device means that all buffers are returned to the queues that they
were in when the device was initially created. That is, the device is returned
to its initial state, and streaming is stopped.
For an input stream, the two functions have the same results: all unread input
is lost. For an output stream, SIO_idle blocks until all buffered data has been
written to the device. However, SIO_flush discards any data that has not
already been written. SIO_flush does not block as shown in Example 7-12.
Example 7-12.
Synchronizing with a Device
An idle stream does not perform I/O with its underlying device. Thus, you can
turn a stream off until further I/O is needed by calling SIO_idle or SIO_flush.
Int SIO_ctrl(stream, cmd, arg)
SIO_Handle stream;
Uns cmd;
Ptr arg;
SIO_Handle stream;
stream = SIO_create("/a2d", ...);
SIO_ctrl(stream, DAC_RATE, 12000);
Void SIO_idle(stream);
SIO_Handle stream;
Void SIO_flush(stream);
SIO_Handle stream;
Summary of Contents for TMS320 Series
Page 1: ...TMS320 DSP BIOS v5 40 User s Guide Literature Number SPRU423G April 2009 ...
Page 16: ...xvi ...
Page 152: ...Tasks 4 48 Figure 4 12 Trace from Example 4 7 ...
Page 168: ...Semaphores 4 64 Figure 4 14 Trace Results from Example 4 11 ...
Page 202: ...5 20 ...
Page 287: ...Index 9 Index Void 1 11 W words data memory 3 15 of code 1 5 wrapper function 2 29 ...
Page 288: ...Index 10 Index ...