|
|
@ -64,19 +64,14 @@ class ADC : public cdev::CDev, public px4::ScheduledWorkItem |
|
|
|
{ |
|
|
|
{ |
|
|
|
public: |
|
|
|
public: |
|
|
|
ADC(uint32_t base_address, uint32_t channels); |
|
|
|
ADC(uint32_t base_address, uint32_t channels); |
|
|
|
~ADC(); |
|
|
|
~ADC() override; |
|
|
|
|
|
|
|
|
|
|
|
virtual int init(); |
|
|
|
int init() override; |
|
|
|
|
|
|
|
|
|
|
|
virtual int ioctl(file *filp, int cmd, unsigned long arg); |
|
|
|
ssize_t read(file *filp, char *buffer, size_t len) override; |
|
|
|
virtual ssize_t read(file *filp, char *buffer, size_t len); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
|
|
|
virtual int open_first(struct file *filp); |
|
|
|
|
|
|
|
virtual int close_last(struct file *filp); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
void Run() override; |
|
|
|
void Run() override; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Sample a single channel and return the measured value. |
|
|
|
* Sample a single channel and return the measured value. |
|
|
@ -105,7 +100,7 @@ private: |
|
|
|
ADC::ADC(uint32_t base_address, uint32_t channels) : |
|
|
|
ADC::ADC(uint32_t base_address, uint32_t channels) : |
|
|
|
CDev(ADC0_DEVICE_PATH), |
|
|
|
CDev(ADC0_DEVICE_PATH), |
|
|
|
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::hp_default), |
|
|
|
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::hp_default), |
|
|
|
_sample_perf(perf_alloc(PC_ELAPSED, "adc_samples")), |
|
|
|
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": sample")), |
|
|
|
_base_address(base_address) |
|
|
|
_base_address(base_address) |
|
|
|
{ |
|
|
|
{ |
|
|
|
/* always enable the temperature sensor */ |
|
|
|
/* always enable the temperature sensor */ |
|
|
@ -140,6 +135,8 @@ ADC::ADC(uint32_t base_address, uint32_t channels) : |
|
|
|
|
|
|
|
|
|
|
|
ADC::~ADC() |
|
|
|
ADC::~ADC() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
ScheduleClear(); |
|
|
|
|
|
|
|
|
|
|
|
if (_samples != nullptr) { |
|
|
|
if (_samples != nullptr) { |
|
|
|
delete _samples; |
|
|
|
delete _samples; |
|
|
|
} |
|
|
|
} |
|
|
@ -151,21 +148,25 @@ ADC::~ADC() |
|
|
|
int |
|
|
|
int |
|
|
|
ADC::init() |
|
|
|
ADC::init() |
|
|
|
{ |
|
|
|
{ |
|
|
|
int rv = px4_arch_adc_init(_base_address); |
|
|
|
int ret_init = px4_arch_adc_init(_base_address); |
|
|
|
|
|
|
|
|
|
|
|
if (rv < 0) { |
|
|
|
if (ret_init < 0) { |
|
|
|
PX4_DEBUG("sample timeout"); |
|
|
|
PX4_ERR("arch adc init failed"); |
|
|
|
return rv; |
|
|
|
return ret_init; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* create the device node */ |
|
|
|
/* create the device node */ |
|
|
|
return CDev::init(); |
|
|
|
int ret_cdev = CDev::init(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
if (ret_cdev != PX4_OK) { |
|
|
|
ADC::ioctl(file *filp, int cmd, unsigned long arg) |
|
|
|
PX4_ERR("CDev init failed"); |
|
|
|
{ |
|
|
|
return ret_cdev; |
|
|
|
return -ENOTTY; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// schedule regular updates
|
|
|
|
|
|
|
|
ScheduleOnInterval(kINTERVAL, kINTERVAL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return PX4_OK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ssize_t |
|
|
|
ssize_t |
|
|
@ -185,26 +186,6 @@ ADC::read(file *filp, char *buffer, size_t len) |
|
|
|
return len; |
|
|
|
return len; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
|
|
|
ADC::open_first(struct file *filp) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
/* get fresh data */ |
|
|
|
|
|
|
|
Run(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* and schedule regular updates */ |
|
|
|
|
|
|
|
ScheduleOnInterval(kINTERVAL, kINTERVAL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
|
|
|
ADC::close_last(struct file *filp) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ScheduleClear(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
ADC::Run() |
|
|
|
ADC::Run() |
|
|
|
{ |
|
|
|
{ |
|
|
|