forked from Archive/PX4-Autopilot
Move the direct-access methods from CDev to Device… makes more sense that way.
This commit is contained in:
parent
e67f6a51a3
commit
26eb0b9d72
|
@ -395,25 +395,4 @@ cdev_poll(struct file *filp, struct pollfd *fds, bool setup)
|
|||
return cdev->poll(filp, fds, setup);
|
||||
}
|
||||
|
||||
int
|
||||
CDev::read(unsigned offset, void *data, unsigned count)
|
||||
{
|
||||
errno = ENODEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
CDev::write(unsigned offset, void *data, unsigned count)
|
||||
{
|
||||
errno = ENODEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
CDev::ioctl(unsigned operation, unsigned &arg)
|
||||
{
|
||||
errno = ENODEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace device
|
|
@ -223,5 +223,31 @@ interrupt(int irq, void *context)
|
|||
return OK;
|
||||
}
|
||||
|
||||
int
|
||||
Device::probe()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
Device::read(unsigned offset, void *data, unsigned count)
|
||||
{
|
||||
errno = ENODEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
Device::write(unsigned offset, void *data, unsigned count)
|
||||
{
|
||||
errno = ENODEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
Device::ioctl(unsigned operation, unsigned &arg)
|
||||
{
|
||||
errno = ENODEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace device
|
|
@ -68,11 +68,62 @@ namespace device __EXPORT
|
|||
class __EXPORT Device
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
*
|
||||
* Public so that anonymous devices can be destroyed.
|
||||
*/
|
||||
virtual ~Device();
|
||||
|
||||
/**
|
||||
* Interrupt handler.
|
||||
*/
|
||||
virtual void interrupt(void *ctx); /**< interrupt handler */
|
||||
|
||||
/*
|
||||
* Direct access methods.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Probe to test whether the device is present.
|
||||
*
|
||||
* @return Zero if present, < 0 (error) otherwise.
|
||||
*/
|
||||
virtual int probe();
|
||||
|
||||
/**
|
||||
* Read directly from the device.
|
||||
*
|
||||
* The actual size of each unit quantity is device-specific.
|
||||
*
|
||||
* @param offset The device address at which to start reading
|
||||
* @param data The buffer into which the read values should be placed.
|
||||
* @param count The number of items to read, defaults to 1.
|
||||
* @return count on success, < 0 on error.
|
||||
*/
|
||||
virtual int read(unsigned address, void *data, unsigned count = 1);
|
||||
|
||||
/**
|
||||
* Write directly to the device.
|
||||
*
|
||||
* The actual size of each unit quantity is device-specific.
|
||||
*
|
||||
* @param address The device address at which to start writing.
|
||||
* @param data The buffer from which values should be read.
|
||||
* @param count The number of registers to write, defaults to 1.
|
||||
* @return count on success, < 0 on error.
|
||||
*/
|
||||
virtual int write(unsigned address, void *data, unsigned count = 1);
|
||||
|
||||
/**
|
||||
* Perform a device-specific operation.
|
||||
*
|
||||
* @param operation The operation to perform
|
||||
* @param arg An argument to the operation.
|
||||
* @return < 0 on error
|
||||
*/
|
||||
virtual int ioctl(unsigned operation, unsigned &arg);
|
||||
|
||||
protected:
|
||||
const char *_name; /**< driver name */
|
||||
bool _debug_enabled; /**< if true, debug messages are printed */
|
||||
|
@ -85,7 +136,6 @@ protected:
|
|||
*/
|
||||
Device(const char *name,
|
||||
int irq = 0);
|
||||
virtual ~Device();
|
||||
|
||||
/**
|
||||
* Initialise the driver and make it ready for use.
|
||||
|
@ -282,48 +332,12 @@ public:
|
|||
* Test whether the device is currently open.
|
||||
*
|
||||
* This can be used to avoid tearing down a device that is still active.
|
||||
* Note - not virtual, cannot be overridden by a subclass.
|
||||
*
|
||||
* @return True if the device is currently open.
|
||||
*/
|
||||
bool is_open() { return _open_count > 0; }
|
||||
|
||||
/*
|
||||
* Direct access methods.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Read directly from the device.
|
||||
*
|
||||
* The actual size of each unit quantity is device-specific.
|
||||
*
|
||||
* @param offset The device offset at which to start reading
|
||||
* @param data The buffer into which the read values should be placed.
|
||||
* @param count The number of items to read, defaults to 1.
|
||||
* @return count on success, < 0 on error.
|
||||
*/
|
||||
virtual int read(unsigned offset, void *data, unsigned count = 1);
|
||||
|
||||
/**
|
||||
* Write directly to the device.
|
||||
*
|
||||
* The actual size of each unit quantity is device-specific.
|
||||
*
|
||||
* @param address The device address at which to start writing.
|
||||
* @param data The buffer from which values should be read.
|
||||
* @param count The number of registers to write, defaults to 1.
|
||||
* @return count on success, < 0 on error.
|
||||
*/
|
||||
virtual int write(unsigned address, void *data, unsigned count = 1);
|
||||
|
||||
/**
|
||||
* Perform a device-specific operation.
|
||||
*
|
||||
* @param operation The operation to perform
|
||||
* @param arg An argument to the operation.
|
||||
* @return < 0 on error
|
||||
*/
|
||||
virtual int ioctl(unsigned operation, unsigned &arg);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Pointer to the default cdev file operations table; useful for
|
||||
|
|
|
@ -58,9 +58,7 @@ public:
|
|||
/**
|
||||
* Get the address
|
||||
*/
|
||||
uint16_t get_address() {
|
||||
return _address;
|
||||
}
|
||||
int16_t get_address() { return _address; }
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue