Start of trail Writer Tasks navigation bar

Reader Tasks

As its name suggests, a reader task reads from the hardware. The channels to be read are selected when the task is created. Once the task has been started, it reads the data at the sampling rate specified when the task was started and stores the values read into the task buffer. The user can then read any number of samples from the task buffer using one of the hil_task_read functions. If the task has not yet stored the requested number of samples in the task buffer, then the hil_task_read operation will block until the requested number of samples has been read or the task is stopped. Data must be read from the task buffer frequently enough so that the task buffer does not overflow. If the task buffer would overflow, then the next hil_task_read operation will return a buffer overflow error.

This process is illustrated in the figure below. In this case, the application is reading four samples at a time using one of the hil_task_read functions. A "sample" constitutes a set of channels that are read in a single sampling instant. Each square in the figure represents a sample. The buffer passed to the hil_task_read function is initially empty (hence portrayed as white), but will be filled with the samples read from the task buffer before the hil_task_read function returns. The light orange squares represent samples that were read in the previous call to the hil_task_read function.

The task buffer is filled by the task interrupt service routine (ISR) at the sampling rate specified when the task was created. Each sampling instant, the task reads one sample from the channels selected when the task was created. The sample is stored at the next available location in the task buffer. The dark orange squares represent samples that have been stored in the task buffer by the task ISR since the last call to the hil_task_read function.

The task buffer operates like a circular buffer. However, new samples are not allowed to overwrite old samples in the buffer. Hence, if the hil_task_read function has not been called for a long time and the task buffer becomes full, then the next call to the hil_task_read function will fail with an QERR_BUFFER_OVERFLOW error.

Figure 1

The task functions associated with reader tasks are:

 

navigation bar