Appearance
Peripheral Drivers
Peripheral Driver API.
The following functions are needed to access peripheral drivers before using them. The functions open(const char *) and close(int) are used to manage power saving and concurrency. Some devices like UARTs or ADC/DACs can only be opened once and need to be closed first before the device can be accessed from another thread while others (I2C e.g.) can be opened multiple times. The API also makes sure that a device that currently isn't open anywhere can be put to sleep in order to save power.
Functions Overview
Name | |
---|---|
int | open(const char * device_name) opens a device for use by the caller and returns a handle to the device |
int | close(int hdev) closes a device and makes it available for other threads and power sleep. |
Function Details
function open
cpp
int open(
const char * device_name
)
opens a device for use by the caller and returns a handle to the device
Parameters:
- device_name the string that has been assigned to the device in the SysConf
Return: the handle for referencing the device in calls to driver functions or -1 on failure.
this function might return -1 in two situations: a) the device does not exist b) the device can only be opened once and has already be opened.
function close
cpp
int close(
int hdev
)
closes a device and makes it available for other threads and power sleep.
Parameters:
- hdev the handle returned from a previous call to open(const char*).
Return: 0 on successful close, -1 if either the handle doesn't exist or the device is not open.