-
Notifications
You must be signed in to change notification settings - Fork 3
Specialization_of_Channels
Typical a channel is specialized to a data container, but it can also be specialized as a device driver, e.g. to read from a serial interface. A specialization as a channel with a single data buffer looks like:
#include <taskChannel.h>
template <typename Type>
class SingleDataBuffer: public Tasking::Channel
{
public:
void push(const Type& inData);
const Type& read(void) const;
private:
Type data;
};
template <typename Type>
void SingleDataBuffer<Type>::push(const Type& inData)
{
data = inData;
Channel::push();
}
template <typename Type>
const Type& SingleDataBuffer<Type>::read(void) const
{
return data;
}Important in the specialization is the push operation when the data is copied into the single data buffer. This operation notifies associated tasks that new data is available on the channel.
Another specialization of channels is providing interfaces to hardware devices, e.g. interfacing a serial bus with one channel to send data to the serial bus and one channel to read data from the serial bus. For such an interface the implementation will use the channel as a buffer and report the acceptance of a message by a call to push. The implementation can be an interrupt service routine, or a thread interacting with the interfaces of the operating system or board support package. Another way would be a time triggered event provided by the class Event in the Tasking Framework.
The class Channel provides three methods intended to be overridden by a specialization.
Two of them are intended for the synchronization of data in the channel.
These are synchronizeStart and synchronizeEnd. Both methods have as a parameter a pointer to the task to be executed. synchronizeStart also provides the parameter volume. Volume depends on the configuration of the associated input of the task and gives the number of data elements the task wants to consume from the channel.
The methods are called by the executor directly before the execution starts and after the execution is finished.
Both calls are inside a region protected by a mutex of the scheduler the executor comes from, so, no concurrent call to these methods will happen by this scheduler.
One application of these abstract methods, which can be found in the subfolder channels of the Tasking Framework, is the implementation of a FIFO channel. The implementation of the FIFO channel provides a reader class for non-concurrent access to the data on the channel. Data items will be released for reuse only when all receiving tasks have read the data item.
The third abstract method is reset, called by default directly after the call of synchronizedEnd, but outside of the protected area of the scheduler.