43 #include <px4_platform_common/px4_config.h> 44 #include <px4_platform_common/posix.h> 67 explicit CDev(
const char *devname);
71 CDev &operator=(
const CDev &) =
delete;
88 virtual int open(
file_t *filep);
99 virtual int close(
file_t *filep);
111 virtual ssize_t
read(
file_t *filep,
char *buffer,
size_t buflen) {
return -ENOSYS; }
123 virtual ssize_t
write(
file_t *filep,
const char *buffer,
size_t buflen) {
return -ENOSYS; }
135 virtual off_t
seek(
file_t *filep, off_t offset,
int whence) {
return -ENOSYS; }
149 virtual int ioctl(
file_t *filep,
int cmd,
unsigned long arg);
162 virtual int poll(
file_t *filep, px4_pollfd_struct_t *fds,
bool setup);
200 virtual void poll_notify(pollevent_t
events);
208 virtual void poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events);
243 virtual int register_class_devname(
const char *class_devname);
253 virtual int unregister_class_devname(
const char *class_devname,
unsigned class_instance);
264 void lock() {
do {}
while (px4_sem_wait(&_lock) != 0); }
282 int unregister_driver_and_memory();
285 const char *_devname{
nullptr};
287 px4_pollfd_struct_t **_pollset{
nullptr};
289 bool _registered{
false};
291 uint8_t _max_pollwaiters{0};
292 uint16_t _open_count{0};
301 inline int store_poll_waiter(px4_pollfd_struct_t *fds);
308 inline int remove_poll_waiter(px4_pollfd_struct_t *fds);
virtual int close_last(file_t *filep)
Notification of the last close.
px4_sem_t _lock
lock to protect access to all class members (also for derived classes)
void lock()
Take the driver lock.
virtual pollevent_t poll_state(file_t *filep)
Check the current state of the device for poll events from the perspective of the file...
static const px4_file_operations_t fops
Pointer to the default cdev file operations table; useful for registering clone devices etc...
virtual ssize_t read(file_t *filep, char *buffer, size_t buflen)
Perform a read from the device.
virtual int open_first(file_t *filep)
Notification of the first open.
virtual off_t seek(file_t *filep, off_t offset, int whence)
Perform a logical seek operation on the device.
Abstract class for any character device.
void init()
Activates/configures the hardware registers.
virtual ssize_t write(file_t *filep, const char *buffer, size_t buflen)
Perform a write to the device.
const char * get_devname() const
Get the device name.
void unlock()
Release the driver lock.