PX4 Firmware
PX4 Autopilot Software http://px4.io
ADC Class Reference
Inheritance diagram for ADC:
Collaboration diagram for ADC:

Public Member Functions

 ADC (uint32_t base_address, uint32_t channels)
 
 ~ADC ()
 
virtual int init ()
 
virtual int ioctl (file *filp, int cmd, unsigned long arg)
 
virtual ssize_t read (file *filp, char *buffer, size_t len)
 
- Public Member Functions inherited from cdev::CDev
 CDev (const char *devname)
 Constructor. More...
 
 CDev (const CDev &)=delete
 
CDevoperator= (const CDev &)=delete
 
 CDev (CDev &&)=delete
 
CDevoperator= (CDev &&)=delete
 
virtual ~CDev ()
 
virtual int open (file_t *filep)
 Handle an open of the device. More...
 
virtual int close (file_t *filep)
 Handle a close of the device. More...
 
virtual ssize_t read (file_t *filep, char *buffer, size_t buflen)
 Perform a read from the device. More...
 
virtual ssize_t write (file_t *filep, const char *buffer, size_t buflen)
 Perform a write to the device. More...
 
virtual off_t seek (file_t *filep, off_t offset, int whence)
 Perform a logical seek operation on the device. More...
 
virtual int ioctl (file_t *filep, int cmd, unsigned long arg)
 Perform an ioctl operation on the device. More...
 
virtual int poll (file_t *filep, px4_pollfd_struct_t *fds, bool setup)
 Perform a poll setup/teardown operation. More...
 
const char * get_devname () const
 Get the device name. More...
 

Protected Member Functions

virtual int open_first (struct file *filp)
 
virtual int close_last (struct file *filp)
 
- Protected Member Functions inherited from cdev::CDev
virtual pollevent_t poll_state (file_t *filep)
 Check the current state of the device for poll events from the perspective of the file. More...
 
virtual void poll_notify (pollevent_t events)
 Report new poll events. More...
 
virtual void poll_notify_one (px4_pollfd_struct_t *fds, pollevent_t events)
 Internal implementation of poll_notify. More...
 
virtual int open_first (file_t *filep)
 Notification of the first open. More...
 
virtual int close_last (file_t *filep)
 Notification of the last close. More...
 
virtual int register_class_devname (const char *class_devname)
 Register a class device name, automatically adding device class instance suffix if need be. More...
 
virtual int unregister_class_devname (const char *class_devname, unsigned class_instance)
 Register a class device name, automatically adding device class instance suffix if need be. More...
 
void lock ()
 Take the driver lock. More...
 
void unlock ()
 Release the driver lock. More...
 
int unregister_driver_and_memory ()
 First, unregisters the driver. More...
 

Private Member Functions

void Run () override
 
uint32_t sample (unsigned channel)
 Sample a single channel and return the measured value. More...
 
void update_adc_report (hrt_abstime now)
 
void update_system_power (hrt_abstime now)
 

Private Attributes

perf_counter_t _sample_perf
 
unsigned _channel_count {0}
 
const uint32_t _base_address
 
px4_adc_msg_t_samples {nullptr}
 sample buffer More...
 
uORB::Publication< adc_report_s_to_adc_report {ORB_ID(adc_report)}
 
uORB::Publication< system_power_s_to_system_power {ORB_ID(system_power)}
 

Static Private Attributes

static const hrt_abstime kINTERVAL {10_ms}
 100Hz base rate More...
 

Additional Inherited Members

- Protected Attributes inherited from cdev::CDev
px4_sem_t _lock
 lock to protect access to all class members (also for derived classes) More...
 
- Static Protected Attributes inherited from cdev::CDev
static const px4_file_operations_t fops = {}
 Pointer to the default cdev file operations table; useful for registering clone devices etc. More...
 

Detailed Description

Definition at line 63 of file adc.cpp.

Constructor & Destructor Documentation

◆ ADC()

ADC::ADC ( uint32_t  base_address,
uint32_t  channels 
)

Definition at line 105 of file adc.cpp.

References _channel_count, _samples, ADC_TOTAL_CHANNELS, px4_adc_msg_t, px4_arch_adc_temp_sensor_mask(), and PX4_MAX_ADC_CHANNELS.

Referenced by adc_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~ADC()

ADC::~ADC ( )

Definition at line 141 of file adc.cpp.

References _base_address, _sample_perf, _samples, perf_free(), and px4_arch_adc_uninit().

Here is the call graph for this function:

Member Function Documentation

◆ close_last()

int ADC::close_last ( struct file filp)
protectedvirtual

Definition at line 201 of file adc.cpp.

◆ init()

int ADC::init ( )
virtual

Reimplemented from cdev::CDev.

Definition at line 152 of file adc.cpp.

References _base_address, ToneAlarmInterface::init(), and px4_arch_adc_init().

Here is the call graph for this function:

◆ ioctl()

int ADC::ioctl ( file filp,
int  cmd,
unsigned long  arg 
)
virtual

Definition at line 166 of file adc.cpp.

◆ open_first()

int ADC::open_first ( struct file filp)
protectedvirtual

Definition at line 189 of file adc.cpp.

References kINTERVAL, and Run().

Here is the call graph for this function:

◆ read()

ssize_t ADC::read ( file filp,
char *  buffer,
size_t  len 
)
virtual

Definition at line 172 of file adc.cpp.

References _channel_count, _samples, and px4_adc_msg_t.

Referenced by sample().

Here is the caller graph for this function:

◆ Run()

void ADC::Run ( )
overrideprivate

Definition at line 209 of file adc.cpp.

References _channel_count, _samples, hrt_absolute_time(), hrt_abstime, sample(), update_adc_report(), and update_system_power().

Referenced by open_first().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sample()

uint32_t ADC::sample ( unsigned  channel)
private

Sample a single channel and return the measured value.

Parameters
channelThe channel to sample.
Returns
The sampled value, or UINT32_MAX if sampling failed.

Definition at line 328 of file adc.cpp.

References _base_address, _sample_perf, ADC0_DEVICE_PATH, adc_main(), ADC_TOTAL_CHANNELS, data, fd, cdev::CDev::open(), perf_begin(), perf_end(), px4_adc_msg_t, px4_arch_adc_sample(), read(), and lps25h::test().

Referenced by Run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_adc_report()

void ADC::update_adc_report ( hrt_abstime  now)
private

Definition at line 223 of file adc.cpp.

References _channel_count, _samples, _to_adc_report, adc_report_s::channel_id, adc_report_s::channel_value, uORB::Publication< T >::publish(), px4_arch_adc_dn_fullcount(), and adc_report_s::timestamp.

Referenced by Run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_system_power()

void ADC::update_system_power ( hrt_abstime  now)
private

Definition at line 244 of file adc.cpp.

References _channel_count, _samples, _to_system_power, uORB::Publication< T >::publish(), px4_arch_adc_dn_fullcount(), and system_power_s::timestamp.

Referenced by Run().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _base_address

const uint32_t ADC::_base_address
private

Definition at line 98 of file adc.cpp.

Referenced by init(), sample(), and ~ADC().

◆ _channel_count

unsigned ADC::_channel_count {0}
private

Definition at line 97 of file adc.cpp.

Referenced by ADC(), read(), Run(), update_adc_report(), and update_system_power().

◆ _sample_perf

perf_counter_t ADC::_sample_perf
private

Definition at line 95 of file adc.cpp.

Referenced by sample(), and ~ADC().

◆ _samples

px4_adc_msg_t* ADC::_samples {nullptr}
private

sample buffer

Definition at line 99 of file adc.cpp.

Referenced by ADC(), read(), Run(), update_adc_report(), update_system_power(), and ~ADC().

◆ _to_adc_report

uORB::Publication<adc_report_s> ADC::_to_adc_report {ORB_ID(adc_report)}
private

Definition at line 101 of file adc.cpp.

Referenced by update_adc_report().

◆ _to_system_power

uORB::Publication<system_power_s> ADC::_to_system_power {ORB_ID(system_power)}
private

Definition at line 102 of file adc.cpp.

Referenced by update_system_power().

◆ kINTERVAL

const hrt_abstime ADC::kINTERVAL {10_ms}
staticprivate

100Hz base rate

Definition at line 93 of file adc.cpp.

Referenced by open_first().


The documentation for this class was generated from the following file: