HALFRED  0.4.0
Functions
IOComposite device

Detailed Description

Overview.

The IOComposite device is a special kind of IODevice. It is used to simultaneously read and write to multiple other IODevices.

Creating and destroying composite IODevices.

In order to use IOComposite device it must be first created through a call to IOCOMPOSITE_Create. In the end the device should be destroyed by a complementary call to IOCOMPOSITE_Destroy. Both these functions use HEAP module for dynamic memory allocation.

Using composite IODevices.

The IOComposite device groups (associates) one ore more other IODevices. To associate an IODevice with the IOComposite device the IOCOMPOSITE_SetAssociation function is used. Here's an example.

IODevice composite;
// first we create the IOComposite device
composite = IOCOMPOSITE_Create(2);
if (composite) {
// next we associate other IODevices (USART1, USART2) with the created IOComposite device
IOCOMPOSITE_SetAssociation(composite, 0, USART1);
IOCOMPOSITE_SetAssociation(composite, 1, USART2);
// now we can use the IOComposite device just like any other IODevice
IODEV_Init(composite);
IODEV_EnableWrite(composite);
// this will write to both USART1 and USART2
IODEV_Write(composite, "hello", 5, 0);
// etc..
// on exit, we must destroy the IOComposite device
IOCOMPOSITE_Destroy(composite);
} else {
// create failed - do some error handling here
}

Functions

IODevice IOCOMPOSITE_Create (unsigned int max_associates)
 
void IOCOMPOSITE_Destroy (IODevice iocomposite)
 
HALRESULT IOCOMPOSITE_SetAssociation (IODevice iocomposite, unsigned int index, IODevice iodevice)
 
HALRESULT IOCOMPOSITE_ClearAssociation (IODevice iocomposite, unsigned int index)
 
IODevice IOCOMPOSITE_GetAssociation (IODevice iocomposite, unsigned int index)
 

Function Documentation

IODevice IOCOMPOSITE_Create ( unsigned int  max_associates)

Creates a new IODevice, that reads and writes to multiple other IODevices.

Parameters
max_associatesmaximum number of associated IODevices
Returns
new composite IODevice handle or NULL if creation failed
void IOCOMPOSITE_Destroy ( IODevice  iocomposite)

Destroys a composite IODevice and frees all memory allocated for it. This call does NOT destroy nor deinitialize associated IODevices. Note, that this function should NOT be used to free other types of IODevices.

Parameters
iocompositeIODevice handle of the IOComposite device
HALRESULT IOCOMPOSITE_SetAssociation ( IODevice  iocomposite,
unsigned int  index,
IODevice  iodevice 
)

Associates an IODevice to the IOComposite device under given index.

Parameters
iocompositeIODevice handle of the IOComposite device
indexassociation index
iodeviceIODevice handle to associate
Returns
HALRESULT_OK on success, otherwise HALRESULT_ERROR
HALRESULT IOCOMPOSITE_ClearAssociation ( IODevice  iocomposite,
unsigned int  index 
)

Clears association of an IODevice with the IOComposite device under given index.

Parameters
iocompositeIODevice handle of the IOComposite device
indexassociation index
Returns
HALRESULT_OK on success, otherwise HALRESULT_ERROR
IODevice IOCOMPOSITE_GetAssociation ( IODevice  iocomposite,
unsigned int  index 
)

Gets the IODevice associated with the IOComposite device under given index.

Parameters
iocompositeIODevice handle of the IOComposite device
indexassociation index
Returns
IODevice handle or NULL if there is no IODevice associated under given index