mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 19:03:33 +08:00
PX4 System:Expunge the nuttx adc structure from the system
This PR is preliminary ground work for FMUv5. PX4 does not use the NuttX adc driver. But used the same format for the data returned by the nuttx ADC driver. There was a fixme:in src/platforms/px4_adc.h "this needs to be a px4_adc_msg_s type" With this PR the need for src/platforms/px4_adc.h goes away as the driver drv_adc.h now describes the px4_adc_msg_t.
This commit is contained in:
committed by
Lorenz Meier
parent
d92377a6e6
commit
4349f49610
@@ -73,7 +73,7 @@ private:
|
||||
static void cycle_trampoline(void *arg);
|
||||
|
||||
struct work_s _work;
|
||||
adc_msg_s _sample;
|
||||
px4_adc_msg_t _sample;
|
||||
pthread_mutex_t _sample_mutex;
|
||||
};
|
||||
|
||||
@@ -87,7 +87,7 @@ static void test()
|
||||
err(1, "can't open ADC device");
|
||||
}
|
||||
|
||||
adc_msg_s data[MAX_CHANNEL];
|
||||
px4_adc_msg_t data[MAX_CHANNEL];
|
||||
ssize_t count = read(fd, data, sizeof(data));
|
||||
|
||||
if (count < 0) {
|
||||
|
||||
@@ -45,6 +45,19 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* Define the PX4 low level format ADC and the maximum
|
||||
* number of channels that can be returned by a lowlevel
|
||||
* ADC driver. Drivers may return less than PX4_MAX_ADC_CHANNELS
|
||||
* but no more than PX4_MAX_ADC_CHANNELS.
|
||||
*
|
||||
*/
|
||||
#define PX4_MAX_ADC_CHANNELS 12
|
||||
typedef struct __attribute__((packed)) px4_adc_msg_t {
|
||||
uint8_t am_channel; /* The 8-bit ADC Channel */
|
||||
int32_t am_data; /* ADC convert result (4 bytes) */
|
||||
} px4_adc_msg_t;
|
||||
|
||||
|
||||
#define ADC0_DEVICE_PATH "/dev/adc0"
|
||||
|
||||
/*
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
#include <px4_config.h>
|
||||
#include <px4_tasks.h>
|
||||
#include <px4_posix.h>
|
||||
#include <px4_adc.h>
|
||||
#include <drivers/drv_adc.h>
|
||||
|
||||
#include <VirtDevObj.hpp>
|
||||
@@ -90,11 +89,11 @@ protected:
|
||||
virtual void _measure() override;
|
||||
|
||||
private:
|
||||
int read_channel(struct adc_msg_s *adc_msg, int channel);
|
||||
int read_channel(px4_adc_msg_t *adc_msg, int channel);
|
||||
|
||||
pthread_mutex_t _samples_lock;
|
||||
int _fd[ADC_MAX_CHAN];
|
||||
adc_msg_s _samples[ADC_MAX_CHAN];
|
||||
px4_adc_msg_t _samples[ADC_MAX_CHAN];
|
||||
};
|
||||
|
||||
NavioADC::NavioADC()
|
||||
@@ -120,7 +119,7 @@ NavioADC::~NavioADC()
|
||||
|
||||
void NavioADC::_measure()
|
||||
{
|
||||
adc_msg_s tmp_samples[ADC_MAX_CHAN];
|
||||
px4_adc_msg_t tmp_samples[ADC_MAX_CHAN];
|
||||
|
||||
for (int i = 0; i < ADC_MAX_CHAN; ++i) {
|
||||
int ret;
|
||||
@@ -216,7 +215,7 @@ ssize_t NavioADC::devRead(void *buf, size_t count)
|
||||
return count;
|
||||
}
|
||||
|
||||
int NavioADC::read_channel(struct adc_msg_s *adc_msg, int channel)
|
||||
int NavioADC::read_channel(px4_adc_msg_t *adc_msg, int channel)
|
||||
{
|
||||
char buffer[11]; /* 32bit max INT has maximum 10 chars */
|
||||
int ret;
|
||||
@@ -304,7 +303,7 @@ int navio_adc_main(int argc, char *argv[])
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
struct adc_msg_s adc_msgs[ADC_MAX_CHAN];
|
||||
px4_adc_msg_t adc_msgs[ADC_MAX_CHAN];
|
||||
|
||||
ret = instance->devRead((char *)&adc_msgs, sizeof(adc_msgs));
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
#include <px4_config.h>
|
||||
#include <px4_tasks.h>
|
||||
#include <px4_posix.h>
|
||||
#include <px4_adc.h>
|
||||
#include <drivers/drv_adc.h>
|
||||
|
||||
#include <VirtDevObj.hpp>
|
||||
@@ -75,10 +74,10 @@ protected:
|
||||
virtual void _measure() override;
|
||||
|
||||
private:
|
||||
int read(struct adc_msg_s(*buf)[12], unsigned int len);
|
||||
int read(px4_adc_msg_t(*buf)[PX4_MAX_ADC_CHANNELS], unsigned int len);
|
||||
|
||||
pthread_mutex_t _samples_lock;
|
||||
adc_msg_s _samples;
|
||||
px4_adc_msg_t _samples;
|
||||
};
|
||||
|
||||
OcpocADC::OcpocADC()
|
||||
@@ -94,7 +93,7 @@ OcpocADC::~OcpocADC()
|
||||
|
||||
void OcpocADC::_measure()
|
||||
{
|
||||
struct adc_msg_s tmp_samples[12];
|
||||
px4_adc_msg_t tmp_samples[PX4_MAX_ADC_CHANNELS];
|
||||
|
||||
int ret = read(&tmp_samples, sizeof(tmp_samples));
|
||||
|
||||
@@ -147,7 +146,7 @@ ssize_t OcpocADC::devRead(void *buf, size_t count)
|
||||
return count;
|
||||
}
|
||||
|
||||
int OcpocADC::read(struct adc_msg_s(*buf)[12], unsigned int len)
|
||||
int OcpocADC::read(px4_adc_msg_t(*buf)[PX4_MAX_ADC_CHANNELS], unsigned int len)
|
||||
{
|
||||
uint32_t buff[1];
|
||||
int ret = 0;
|
||||
@@ -219,7 +218,7 @@ int ocpoc_adc_main(int argc, char *argv[])
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
struct adc_msg_s adc_msgs[12];
|
||||
px4_adc_msg_t adc_msgs[PX4_MAX_ADC_CHANNELS];
|
||||
|
||||
ret = instance->devRead((char *)&adc_msgs, sizeof(adc_msgs));
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ private:
|
||||
perf_counter_t _sample_perf;
|
||||
|
||||
unsigned _channel_count;
|
||||
adc_msg_s *_samples; /**< sample buffer */
|
||||
px4_adc_msg_t *_samples; /**< sample buffer */
|
||||
|
||||
orb_advert_t _to_system_power;
|
||||
orb_advert_t _to_adc_report;
|
||||
@@ -168,7 +168,11 @@ ADC::ADC(uint32_t channels) :
|
||||
}
|
||||
}
|
||||
|
||||
_samples = new adc_msg_s[_channel_count];
|
||||
if (_channel_count > PX4_MAX_ADC_CHANNELS) {
|
||||
PX4_ERR("PX4_MAX_ADC_CHANNELS is too small:is %d needed:%d", PX4_MAX_ADC_CHANNELS, _channel_count);
|
||||
}
|
||||
|
||||
_samples = new px4_adc_msg_t[_channel_count];
|
||||
|
||||
/* prefill the channel numbers in the sample array */
|
||||
if (_samples != nullptr) {
|
||||
@@ -265,7 +269,7 @@ ADC::ioctl(file *filp, int cmd, unsigned long arg)
|
||||
ssize_t
|
||||
ADC::read(file *filp, char *buffer, size_t len)
|
||||
{
|
||||
const size_t maxsize = sizeof(adc_msg_s) * _channel_count;
|
||||
const size_t maxsize = sizeof(px4_adc_msg_t) * _channel_count;
|
||||
|
||||
if (len > maxsize) {
|
||||
len = maxsize;
|
||||
@@ -441,7 +445,7 @@ test(void)
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < 50; i++) {
|
||||
adc_msg_s data[12];
|
||||
px4_adc_msg_t data[PX4_MAX_ADC_CHANNELS];
|
||||
ssize_t count = read(fd, data, sizeof(data));
|
||||
|
||||
if (count < 0) {
|
||||
|
||||
Reference in New Issue
Block a user