Program elements related to DevBlkCDIDeviceDriver, which defines a device driver. The core DevBlkCDI calls the driver when the client calls the related public DevBlkCDI function.
Before the client can create an DevBlkCDIDevice object (a device), it must provide a device driver. The DevBlkCDIDeviceDriver object contains the following data fields and function pointers.
- Data Fields
- deviceName The name of the device. This is a null-terminated string.
- regLength Target device offset length in bytes. Valid Range: [1, 2].
- dataLength Target device data length in bytes. Valid Range: [1, 2].
- Function Pointers
- DriverCreate (mandatory). Invoked when the client calls DevBlkCDIDeviceCreate().
- DriverDestroy (mandatory). Invoked when the client calls DevBlkCDIDeviceDestroy().
- GetModuleConfig (optional). Invoked when the client calls DevBlkCDIGetModuleConfig(). Not supported for safety use cases.
- ParseEmbedDataInfo (optional). Invoked when the client calls DevBlkCDIParseEmbedDataInfo().
- SetSensorControls (optional). Invoked when the client calls DevBlkCDISetSensorControls().
- GetSensorAttributes (optional). Invoked when the client calls DevBlkCDIGetSensorAttributes().
- SetSensorCharMode (optional). Invoked when the client calls DevBlkCDISetSensorCharMode(). Not supported for safety use cases.
- ReadRegister (optional). Not supported for safety use cases.
- WriteRegister (optional). Not supported for safety use cases.
Here is a sample device driver implementation. The source file defines the driver by creating an DevBlkCDIDeviceDriver struct and setting its function pointers. The header file provides a function that retrieves a pointer to the driver struct.
- Header File
Source File
#include "cdi_sample_device.h"
DriverCreate(
void *clientContext)
{
if(!handle)
Can be used to maintain local device context
or can be set to NULL.
}
.DriverCreate = DriverCreate
};
GetSAMPLEDEVICEDriver(void)
{
Return device driver descriptor structure
return &deviceDriver;
}