Browse Source

Let's have some direct-access I/O methods as well.

sbg
px4dev 12 years ago
parent
commit
c459901f26
  1. 35
      src/drivers/device/cdev.cpp
  2. 47
      src/drivers/device/device.h

35
src/drivers/device/cdev.cpp

@ -111,21 +111,21 @@ CDev::~CDev()
int int
CDev::init() CDev::init()
{ {
int ret = OK;
// base class init first // base class init first
ret = Device::init(); int ret = Device::init();
if (ret != OK) if (ret != OK)
goto out; goto out;
// now register the driver // now register the driver
ret = register_driver(_devname, &fops, 0666, (void *)this); if (_devname != nullptr) {
ret = register_driver(_devname, &fops, 0666, (void *)this);
if (ret != OK) if (ret != OK)
goto out; goto out;
_registered = true; _registered = true;
}
out: out:
return ret; return ret;
@ -395,4 +395,25 @@ cdev_poll(struct file *filp, struct pollfd *fds, bool setup)
return cdev->poll(filp, fds, 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 } // namespace device

47
src/drivers/device/device.h

@ -85,7 +85,7 @@ protected:
*/ */
Device(const char *name, Device(const char *name,
int irq = 0); int irq = 0);
~Device(); virtual ~Device();
/** /**
* Initialise the driver and make it ready for use. * Initialise the driver and make it ready for use.
@ -189,7 +189,7 @@ public:
/** /**
* Destructor * Destructor
*/ */
~CDev(); virtual ~CDev();
virtual int init(); virtual int init();
@ -287,6 +287,43 @@ public:
*/ */
bool is_open() { return _open_count > 0; } 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: protected:
/** /**
* Pointer to the default cdev file operations table; useful for * Pointer to the default cdev file operations table; useful for
@ -396,9 +433,9 @@ public:
const char *devname, const char *devname,
uint32_t base, uint32_t base,
int irq = 0); int irq = 0);
~PIO(); virtual ~PIO();
int init(); virtual int init();
protected: protected:
@ -407,7 +444,7 @@ protected:
* *
* @param offset Register offset in bytes from the base address. * @param offset Register offset in bytes from the base address.
*/ */
uint32_t reg(uint32_t offset) { uint32_t reg(uint32_t offset) {
return *(volatile uint32_t *)(_base + offset); return *(volatile uint32_t *)(_base + offset);
} }

Loading…
Cancel
Save