Device API

The following diagram highlights the different devices accessible by your application:

These devices can be on-chip sensors (temperature, battery), interfaces to external sensors and actuators (e.g. GPIO, SPI, I2C), or miscellaneous devices (e.g. the random number generator).

All these devices are accessed through the same set of 5 functions, which define the Device API. This API is designed to make the devices look like files. Having a common interface greatly simplifies your application.

  • dn_open() is used to open a device. The exact arguments to pass to this function depends on the device that is opened. Some devices require no arguments. Others, such as the I2C device, require you to pass an pass an argument (e.g. the baudrate).
  • dn_close() is used to close a previously opened device. Once it is closed, this device can be re-opened and re-used, for example, by a different task.
  • dn_ioctl() is used to configure a previously opened device, and is only available on select devices. An example use case is re-configuring the baudrate on the UART device.
  • dn_read() is used to read a value from a previously opened device, and is only available on select devices. An example use case is retrieving the voltage from an ADC channel.
  • dn_write() is used to write a value to a previously opened device, and is only available on select devices. An example use case is setting the output state of a GPIO.

Refer to the

SmartMesh On-Chip API html documentation

in the /doc directory of the 

On-Chip SDK repository

for documentation about this feature.