Abstract class for any character device.
More...
#include <CDev.hpp>
|
| CDev (const char *devname) |
| Constructor. More...
|
|
virtual int | init () |
|
virtual int | open (file_t *filep) |
| Handle an open of the device. More...
|
|
virtual int | close (file_t *filep) |
| Handle a close of the device. More...
|
|
virtual ssize_t | read (file_t *filep, char *buffer, size_t buflen) |
| Perform a read from the device. More...
|
|
virtual ssize_t | write (file_t *filep, const char *buffer, size_t buflen) |
| Perform a write to the device. More...
|
|
virtual off_t | seek (file_t *filep, off_t offset, int whence) |
| Perform a logical seek operation on the device. More...
|
|
virtual int | ioctl (file_t *filep, int cmd, unsigned long arg) |
| Perform an ioctl operation on the device. More...
|
|
virtual int | poll (file_t *filep, px4_pollfd_struct_t *fds, bool setup) |
| Perform a poll setup/teardown operation. More...
|
|
const char * | get_devname () const |
| Get the device name. More...
|
|
|
virtual pollevent_t | poll_state (file_t *filep) |
| Check the current state of the device for poll events from the perspective of the file. More...
|
|
virtual void | poll_notify (pollevent_t events) |
| Report new poll events. More...
|
|
virtual void | poll_notify_one (px4_pollfd_struct_t *fds, pollevent_t events) |
| Internal implementation of poll_notify. More...
|
|
virtual int | open_first (file_t *filep) |
| Notification of the first open. More...
|
|
virtual int | close_last (file_t *filep) |
| Notification of the last close. More...
|
|
virtual int | register_class_devname (const char *class_devname) |
| Register a class device name, automatically adding device class instance suffix if need be. More...
|
|
virtual int | unregister_class_devname (const char *class_devname, unsigned class_instance) |
| Register a class device name, automatically adding device class instance suffix if need be. More...
|
|
void | lock () |
| Take the driver lock. More...
|
|
void | unlock () |
| Release the driver lock.
|
|
|
px4_sem_t | _lock |
| lock to protect access to all class members (also for derived classes)
|
|
|
static const px4_file_operations_t | fops = {} |
| Pointer to the default cdev file operations table; useful for registering clone devices etc.
|
|
Abstract class for any character device.
§ CDev()
CDev::CDev |
( |
const char * |
devname | ) |
|
Constructor.
- Parameters
-
name | Driver name |
devname | Device node name |
§ close()
int CDev::close |
( |
file_t * |
filep | ) |
|
|
virtual |
Handle a close of the device.
This function is called for every close of the device. The default implementation maintains _open_count and returns OK as long as it is not zero.
- Parameters
-
filep | Pointer to the NuttX file structure. |
- Returns
- OK if the close was successful, -errno otherwise.
Reimplemented in CDevNode, and uORB::DeviceNode.
§ close_last()
virtual int cdev::CDev::close_last |
( |
file_t * |
filep | ) |
|
|
inlineprotectedvirtual |
Notification of the last close.
This function is called when the device open count transitions from one to zero. The driver lock is held for the duration of the call.
The default implementation returns OK.
- Parameters
-
filep | Pointer to the NuttX file structure. |
- Returns
- OK if the open should return OK, -errno otherwise.
§ get_devname()
const char* cdev::CDev::get_devname |
( |
| ) |
const |
|
inline |
Get the device name.
- Returns
- the file system string of the device handle
§ ioctl()
int CDev::ioctl |
( |
file_t * |
filep, |
|
|
int |
cmd, |
|
|
unsigned long |
arg |
|
) |
| |
|
virtual |
Perform an ioctl operation on the device.
The default implementation handles DIOC_GETPRIV, and otherwise returns -ENOTTY. Subclasses should call the default implementation for any command they do not handle themselves.
- Parameters
-
filep | Pointer to the NuttX file structure. |
cmd | The ioctl command value. |
arg | The ioctl argument value. |
- Returns
- OK on success, or -errno otherwise.
Reimplemented in TAP_ESC, uORB::DeviceNode, TFMINI, CM8JL65, HC_SR04, SF0X, PWMSim, AirspeedSim, device::CDev, LED, PX4Magnetometer, PX4Accelerometer, and PX4Gyroscope.
§ lock()
void cdev::CDev::lock |
( |
| ) |
|
|
inlineprotected |
Take the driver lock.
Each driver instance has its own lock/semaphore.
Note that we must loop as the wait may be interrupted by a signal.
Careful: lock() calls cannot be nested!
§ open()
int CDev::open |
( |
file_t * |
filep | ) |
|
|
virtual |
Handle an open of the device.
This function is called for every open of the device. The default implementation maintains _open_count and always returns OK.
- Parameters
-
filep | Pointer to the NuttX file structure. |
- Returns
- OK if the open is allowed, -errno otherwise.
Reimplemented in CDevNode, and uORB::DeviceNode.
§ open_first()
virtual int cdev::CDev::open_first |
( |
file_t * |
filep | ) |
|
|
inlineprotectedvirtual |
Notification of the first open.
This function is called when the device open count transitions from zero to one. The driver lock is held for the duration of the call.
The default implementation returns OK.
- Parameters
-
filep | Pointer to the NuttX file structure. |
- Returns
- OK if the open should proceed, -errno otherwise.
§ poll()
int CDev::poll |
( |
file_t * |
filep, |
|
|
px4_pollfd_struct_t * |
fds, |
|
|
bool |
setup |
|
) |
| |
|
virtual |
Perform a poll setup/teardown operation.
This is handled internally and should not normally be overridden.
- Parameters
-
filep | Pointer to the internal file structure. |
fds | Poll descriptor being waited on. |
setup | True if this is establishing a request, false if it is being torn down. |
- Returns
- OK on success, or -errno otherwise.
§ poll_notify()
void CDev::poll_notify |
( |
pollevent_t |
events | ) |
|
|
protectedvirtual |
Report new poll events.
This function should be called anytime the state of the device changes in a fashion that might be interesting to a poll waiter.
- Parameters
-
events | The new event(s) being announced. |
§ poll_notify_one()
void CDev::poll_notify_one |
( |
px4_pollfd_struct_t * |
fds, |
|
|
pollevent_t |
events |
|
) |
| |
|
protectedvirtual |
Internal implementation of poll_notify.
- Parameters
-
fds | A poll waiter to notify. |
events | The event(s) to send to the waiter. |
Reimplemented in uORB::DeviceNode.
§ poll_state()
virtual pollevent_t cdev::CDev::poll_state |
( |
file_t * |
filep | ) |
|
|
inlineprotectedvirtual |
Check the current state of the device for poll events from the perspective of the file.
This function is called by the default poll() implementation when a poll is set up to determine whether the poll should return immediately.
The default implementation returns no events.
- Parameters
-
filep | The file that's interested. |
- Returns
- The current set of poll events.
Reimplemented in uORB::DeviceNode.
§ read()
virtual ssize_t cdev::CDev::read |
( |
file_t * |
filep, |
|
|
char * |
buffer, |
|
|
size_t |
buflen |
|
) |
| |
|
inlinevirtual |
Perform a read from the device.
The default implementation returns -ENOSYS.
- Parameters
-
filep | Pointer to the NuttX file structure. |
buffer | Pointer to the buffer into which data should be placed. |
buflen | The number of bytes to be read. |
- Returns
- The number of bytes read or -errno otherwise.
Reimplemented in CDevNode, TFMINI, HC_SR04, SF0X, uORB::DeviceNode, AirspeedSim, and LidarLitePWM.
§ register_class_devname()
int CDev::register_class_devname |
( |
const char * |
class_devname | ) |
|
|
protectedvirtual |
Register a class device name, automatically adding device class instance suffix if need be.
- Parameters
-
class_devname | Device class name |
- Returns
- class_instamce Class instance created, or -errno on failure
§ seek()
virtual off_t cdev::CDev::seek |
( |
file_t * |
filep, |
|
|
off_t |
offset, |
|
|
int |
whence |
|
) |
| |
|
inlinevirtual |
Perform a logical seek operation on the device.
The default implementation returns -ENOSYS.
- Parameters
-
filep | Pointer to the NuttX file structure. |
offset | The new file position relative to whence. |
whence | SEEK_OFS, SEEK_CUR or SEEK_END. |
- Returns
- The previous offset, or -errno otherwise.
§ unregister_class_devname()
int CDev::unregister_class_devname |
( |
const char * |
class_devname, |
|
|
unsigned |
class_instance |
|
) |
| |
|
protectedvirtual |
Register a class device name, automatically adding device class instance suffix if need be.
- Parameters
-
- Returns
- OK on success, -errno otherwise
§ write()
virtual ssize_t cdev::CDev::write |
( |
file_t * |
filep, |
|
|
const char * |
buffer, |
|
|
size_t |
buflen |
|
) |
| |
|
inlinevirtual |
Perform a write to the device.
The default implementation returns -ENOSYS.
- Parameters
-
filep | Pointer to the NuttX file structure. |
buffer | Pointer to the buffer from which data should be read. |
buflen | The number of bytes to be written. |
- Returns
- The number of bytes written or -errno otherwise.
Reimplemented in CDevNode, uORB::DeviceNode, and cdev::VFile.
The documentation for this class was generated from the following files:
- src/lib/cdev/CDev.hpp
- src/lib/cdev/CDev.cpp
- src/lib/cdev/posix/cdev_platform.cpp