mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 14:08:52 +08:00
drivers device nuttx remove unused interrupt support
This commit is contained in:
committed by
Lorenz Meier
parent
5d20cf6b57
commit
c6b6164cf7
@@ -89,10 +89,9 @@ poll : cdev_poll
|
||||
};
|
||||
|
||||
CDev::CDev(const char *name,
|
||||
const char *devname,
|
||||
int irq) :
|
||||
const char *devname) :
|
||||
// base class
|
||||
Device(name, irq),
|
||||
Device(name),
|
||||
// public
|
||||
// protected
|
||||
_pub_blocked(false),
|
||||
|
||||
@@ -48,50 +48,11 @@
|
||||
namespace device
|
||||
{
|
||||
|
||||
/**
|
||||
* Interrupt dispatch table entry.
|
||||
*/
|
||||
struct irq_entry {
|
||||
int irq;
|
||||
Device *owner;
|
||||
};
|
||||
|
||||
static const unsigned irq_nentries = 8; /**< size of the interrupt dispatch table */
|
||||
static irq_entry irq_entries[irq_nentries]; /**< interrupt dispatch table (XXX should be a vector) */
|
||||
|
||||
/**
|
||||
* Register an interrupt to a specific device.
|
||||
*
|
||||
* @param irq The interrupt number to register.
|
||||
* @param owner The device receiving the interrupt.
|
||||
* @return OK if the interrupt was registered.
|
||||
*/
|
||||
static int register_interrupt(int irq, Device *owner);
|
||||
|
||||
/**
|
||||
* Unregister an interrupt.
|
||||
*
|
||||
* @param irq The previously-registered interrupt to be de-registered.
|
||||
*/
|
||||
static void unregister_interrupt(int irq);
|
||||
|
||||
/**
|
||||
* Handle an interrupt.
|
||||
*
|
||||
* @param irq The interrupt being invoked.
|
||||
* @param context The interrupt register context.
|
||||
* @return Always returns OK.
|
||||
*/
|
||||
static int interrupt(int irq, void *context, void *arg);
|
||||
|
||||
Device::Device(const char *name,
|
||||
int irq) :
|
||||
Device::Device(const char *name) :
|
||||
// public
|
||||
// protected
|
||||
_name(name),
|
||||
_debug_enabled(false),
|
||||
// private
|
||||
_irq(irq)
|
||||
_debug_enabled(false)
|
||||
{
|
||||
sem_init(&_lock, 0, 1);
|
||||
|
||||
@@ -107,10 +68,6 @@ Device::Device(const char *name,
|
||||
Device::~Device()
|
||||
{
|
||||
sem_destroy(&_lock);
|
||||
|
||||
if (_irq) {
|
||||
unregister_interrupt(_irq);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
@@ -118,93 +75,9 @@ Device::init()
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
// If assigned an interrupt, connect it
|
||||
if (_irq) {
|
||||
/* ensure it's disabled */
|
||||
up_disable_irq(_irq);
|
||||
|
||||
/* register */
|
||||
ret = register_interrupt(_irq, this);
|
||||
|
||||
if (ret != OK) {
|
||||
_irq = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
Device::interrupt_enable()
|
||||
{
|
||||
if (_irq) {
|
||||
up_enable_irq(_irq);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Device::interrupt_disable()
|
||||
{
|
||||
if (_irq) {
|
||||
up_disable_irq(_irq);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Device::interrupt(void *context)
|
||||
{
|
||||
// default action is to disable the interrupt so we don't get called again
|
||||
interrupt_disable();
|
||||
}
|
||||
|
||||
static int
|
||||
register_interrupt(int irq, Device *owner)
|
||||
{
|
||||
int ret = -ENOMEM;
|
||||
|
||||
// look for a slot where we can register the interrupt
|
||||
for (unsigned i = 0; i < irq_nentries; i++) {
|
||||
if (irq_entries[i].irq == 0) {
|
||||
|
||||
// great, we could put it here; try attaching it
|
||||
ret = irq_attach(irq, &interrupt, owner);
|
||||
|
||||
if (ret == OK) {
|
||||
irq_entries[i].irq = irq;
|
||||
irq_entries[i].owner = owner;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
unregister_interrupt(int irq)
|
||||
{
|
||||
for (unsigned i = 0; i < irq_nentries; i++) {
|
||||
if (irq_entries[i].irq == irq) {
|
||||
irq_entries[i].irq = 0;
|
||||
irq_entries[i].owner = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
interrupt(int irq, void *context, void *arg)
|
||||
{
|
||||
for (unsigned i = 0; i < irq_nentries; i++) {
|
||||
if (irq_entries[i].irq == irq) {
|
||||
irq_entries[i].owner->interrupt(context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int
|
||||
Device::read(unsigned offset, void *data, unsigned count)
|
||||
{
|
||||
|
||||
@@ -81,11 +81,6 @@ public:
|
||||
*/
|
||||
virtual ~Device();
|
||||
|
||||
/**
|
||||
* Interrupt handler.
|
||||
*/
|
||||
virtual void interrupt(void *ctx); /**< interrupt handler */
|
||||
|
||||
/*
|
||||
* Direct access methods.
|
||||
*/
|
||||
@@ -193,10 +188,8 @@ protected:
|
||||
* Constructor
|
||||
*
|
||||
* @param name Driver name
|
||||
* @param irq Interrupt assigned to the device.
|
||||
*/
|
||||
Device(const char *name,
|
||||
int irq = 0);
|
||||
Device(const char *name);
|
||||
|
||||
/**
|
||||
* Enable the device interrupt
|
||||
@@ -235,7 +228,6 @@ protected:
|
||||
sem_t _lock; /**< lock to protect access to all class members (also for derived classes) */
|
||||
|
||||
private:
|
||||
int _irq; /**< if non-zero, it's a valid IRQ */
|
||||
|
||||
/** disable copy construction for this and all subclasses */
|
||||
Device(const Device &);
|
||||
@@ -243,27 +235,6 @@ private:
|
||||
/** disable assignment for this and all subclasses */
|
||||
Device &operator = (const Device &);
|
||||
|
||||
/**
|
||||
* Register ourselves as a handler for an interrupt
|
||||
*
|
||||
* @param irq The interrupt to claim
|
||||
* @return OK if the interrupt was registered
|
||||
*/
|
||||
int dev_register_interrupt(int irq);
|
||||
|
||||
/**
|
||||
* Unregister ourselves as a handler for any interrupt
|
||||
*/
|
||||
void dev_unregister_interrupt();
|
||||
|
||||
/**
|
||||
* Interrupt dispatcher
|
||||
*
|
||||
* @param irq The interrupt that has been triggered.
|
||||
* @param context Pointer to the interrupted context.
|
||||
*/
|
||||
static void dev_interrupt(int irq, void *context);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -277,9 +248,8 @@ public:
|
||||
*
|
||||
* @param name Driver name
|
||||
* @param devname Device node name
|
||||
* @param irq Interrupt assigned to the device
|
||||
*/
|
||||
CDev(const char *name, const char *devname, int irq = 0);
|
||||
CDev(const char *name, const char *devname);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
|
||||
@@ -55,10 +55,9 @@ I2C::I2C(const char *name,
|
||||
const char *devname,
|
||||
int bus,
|
||||
uint16_t address,
|
||||
uint32_t frequency,
|
||||
int irq) :
|
||||
uint32_t frequency) :
|
||||
// base class
|
||||
CDev(name, devname, irq),
|
||||
CDev(name, devname),
|
||||
// public
|
||||
// protected
|
||||
_retries(0),
|
||||
|
||||
@@ -84,14 +84,12 @@ protected:
|
||||
* @param bus I2C bus on which the device lives
|
||||
* @param address I2C bus address, or zero if set_address will be used
|
||||
* @param frequency I2C bus frequency for the device (currently not used)
|
||||
* @param irq Interrupt assigned to the device (or zero if none)
|
||||
*/
|
||||
I2C(const char *name,
|
||||
const char *devname,
|
||||
int bus,
|
||||
uint16_t address,
|
||||
uint32_t frequency,
|
||||
int irq = 0);
|
||||
uint32_t frequency);
|
||||
virtual ~I2C();
|
||||
|
||||
virtual int init();
|
||||
|
||||
@@ -61,10 +61,9 @@ SPI::SPI(const char *name,
|
||||
int bus,
|
||||
uint32_t device,
|
||||
enum spi_mode_e mode,
|
||||
uint32_t frequency,
|
||||
int irq) :
|
||||
uint32_t frequency) :
|
||||
// base class
|
||||
CDev(name, devname, irq),
|
||||
CDev(name, devname),
|
||||
// public
|
||||
// protected
|
||||
locking_mode(LOCK_PREEMPTION),
|
||||
|
||||
@@ -449,75 +449,6 @@ private:
|
||||
//CDev operator=(const CDev&);
|
||||
};
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Abstract class for character device accessed via PIO
|
||||
*/
|
||||
class __EXPORT VPIO : public CDev
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name Driver name
|
||||
* @param devname Device node name
|
||||
* @param base Base address of the device PIO area
|
||||
* @param irq Interrupt assigned to the device (or zero if none)
|
||||
*/
|
||||
PIO(const char *name,
|
||||
const char *devname,
|
||||
unsigned long base
|
||||
);
|
||||
virtual ~PIO();
|
||||
|
||||
virtual int init();
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Read a register
|
||||
*
|
||||
* @param offset Register offset in bytes from the base address.
|
||||
*/
|
||||
uint32_t reg(uint32_t offset)
|
||||
{
|
||||
return *(volatile uint32_t *)(_base + offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a register
|
||||
*
|
||||
* @param offset Register offset in bytes from the base address.
|
||||
* @param value Value to write.
|
||||
*/
|
||||
void reg(uint32_t offset, uint32_t value)
|
||||
{
|
||||
*(volatile uint32_t *)(_base + offset) = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify a register
|
||||
*
|
||||
* Note that there is a risk of a race during the read/modify/write cycle
|
||||
* that must be taken care of by the caller.
|
||||
*
|
||||
* @param offset Register offset in bytes from the base address.
|
||||
* @param clearbits Bits to clear in the register
|
||||
* @param setbits Bits to set in the register
|
||||
*/
|
||||
void modify(uint32_t offset, uint32_t clearbits, uint32_t setbits)
|
||||
{
|
||||
uint32_t val = reg(offset);
|
||||
val &= ~clearbits;
|
||||
val |= setbits;
|
||||
reg(offset, val);
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned long _base;
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace device
|
||||
|
||||
// class instance for primary driver of each class
|
||||
|
||||
@@ -62,15 +62,13 @@ protected:
|
||||
* @param device Device handle (used by SPI_SELECT)
|
||||
* @param mode SPI clock/data mode
|
||||
* @param frequency SPI clock frequency
|
||||
* @param irq Interrupt assigned to the device (or zero if none)
|
||||
*/
|
||||
SPI(const char *name,
|
||||
const char *devname,
|
||||
int bus,
|
||||
uint32_t device,
|
||||
enum spi_mode_e mode,
|
||||
uint32_t frequency,
|
||||
int irq = 0);
|
||||
uint32_t frequency);
|
||||
virtual ~SPI();
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user