Device Drivers

Nano-RK implements device drivers in a similar fashion to most Unix based operating
systems. Open calls get access to a device descriptor which can then be passed to read,
write, set status, and get status commands. In Nano-RK, the details of the device driver
functionality is left to the device driver designer. Typically devices will power up when
open, and power down when closed.

int8_t nrk_register_driver(void *devicemanager,uint8_t driver_name)

This function registers a driver to be used by the system. This should be called before
nrk_start() to ensure that the driver is available by the time a task can invoke it.
driver_name is a staticly define value that must be listed in nrk_driver_list.h. Make sure that any drivers you are using do not have conflicting driver numbers. Also, be sure to read the particular driver documentation to see if resources etc must be added to nrk_cfg.h.

int8_t nrk_open(uint8_t dev_id,uint8_t opt)

This function opens a device descriptor with a stream associated with it. opt allows
initial configuration options to be specified on a device by device basis. You should
refer to the particular driver implementation for details.

int8_t nrk_read(uint8_t dev_fd,uint8_t *buffer,uint8_t size)

This function attempts to read up to size bytes from file descriptor fd into the buffer
buf. NRK_ERROR is returned upon failure.

uint8_t nrk_write(uint8_t dev_fd,uint8_t *buffer,uint8_t size)

This function writes up to size bytes to the file referenced by the file descriptor fd
from the buffer starting at buf. NRK_ERROR is returned upon error otherwise the return value depends on the driver implementation.

uint8_t nrk_close(uint8_t dev_fd)

This function closes a file descriptor internally, this typically lets a device go
into a power down state. Any record locks held on the file it was associated with, and
owned by the process, are removed.

int8_t nrk_get_status(uint8_t dev_fd,uint8_t key)
This function can be used to read internal state associated with each device. Refer to
the particular device driver implementation for details.

int8_t nrk_set_status(uint8_t dev_fd,uint8_t key)
This function can be used to set internal state associated with each device. Refer to
the particular device driver implementation for details.

Prev: Signals and Semaphores Next: LEDs and GPIO Top