Reader Tasks Reader-Writer Tasks navigation bar

Writer Tasks

As its name suggests, writer tasks write to the hardware. The channels to be written to are selected when the task is created. Once the task has been started, it reads data from the task buffer at the sampling rate specified when the task was started and writes the data to the hardware. The user can write any number of samples to the task buffer using one of the hil_task_write functions. If there is not enough room to store the given number of samples in the task buffer, then the hil_task_write operation blocks until space becomes available or the task is stopped. Note that for writer tasks, data must be written to the task buffer prior to starting the task so that the task will have data to write to the hardware as soon as it starts. If the task runs out of data in the task buffer then the next hil_task_write operation will return a buffer underflow error.

This process is illustrated in the figure below. In this case, the application is writing four samples at a time using one of the hil_task_write functions. A "sample" constitutes a set of channels that are written in a single sampling instant. Each square in the figure represents a sample. The buffer passed to the hil_task_write function contains the data to write to the task buffer (hence portrayed as yellow) before the hil_task_write function returns.

The task buffer is read by the task interrupt service routine (ISR) at the sampling rate specified when the task was created. Each sampling instant, the task reads the next available sample from the task buffer and writes it to the output channels selected when the task was created. The light orange squares represent samples that were written to the task buffer in a previous call to the hil_task_write function and have already been written to the hardware by the task. The dark orange squares represent samples that have been stored in the task buffer by previous calls to the hil_task_write function but which have not yet been written to the hardware by the task ISR.

The task buffer operates like a circular buffer. However, the same samples are never written to the hardware twice. Hence, if all the samples in the task buffer are written to the hardware before the next call to the hil_task_write function so that the task buffer becomes empty, then the next call to the hil_task_write function will fail with an QERR_BUFFER_OVERFLOW error (indicating a buffer underflow).

Figure 1

The task functions associated with writer tasks are:

 

navigation bar