linux boards (ocpoc, bbblue, navio2) replace custom adc drivers with simple px4_arch implementation

This commit is contained in:
Daniel Agar
2020-01-07 11:08:37 -05:00
parent fc9df31653
commit d19f18d40b
38 changed files with 528 additions and 1065 deletions
+11 -8
View File
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (C) 2012-2019 PX4 Development Team. All rights reserved.
* Copyright (C) 2012-2020 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -68,7 +68,7 @@ public:
int init() override;
ssize_t read(file *filp, char *buffer, size_t len) override;
ssize_t read(cdev::file_t *filp, char *buffer, size_t len) override;
private:
void Run() override;
@@ -170,7 +170,7 @@ ADC::init()
}
ssize_t
ADC::read(file *filp, char *buffer, size_t len)
ADC::read(cdev::file_t *filp, char *buffer, size_t len)
{
const size_t maxsize = sizeof(px4_adc_msg_t) * _channel_count;
@@ -179,9 +179,9 @@ ADC::read(file *filp, char *buffer, size_t len)
}
/* block interrupts while copying samples to avoid racing with an update */
irqstate_t flags = px4_enter_critical_section();
lock();
memcpy(buffer, _samples, len);
px4_leave_critical_section(flags);
unlock();
return len;
}
@@ -189,6 +189,7 @@ ADC::read(file *filp, char *buffer, size_t len)
void
ADC::Run()
{
lock();
hrt_abstime now = hrt_absolute_time();
/* scan the channel set and sample each */
@@ -198,6 +199,7 @@ ADC::Run()
update_adc_report(now);
update_system_power(now);
unlock();
}
void
@@ -215,7 +217,6 @@ ADC::update_adc_report(hrt_abstime now)
for (unsigned i = 0; i < max_num; i++) {
adc.channel_id[i] = _samples[i].am_channel;
adc.channel_value[i] = _samples[i].am_data * 3.3f / px4_arch_adc_dn_fullcount();
;
}
_to_adc_report.publish(adc);
@@ -332,7 +333,7 @@ int
test(void)
{
int fd = open(ADC0_DEVICE_PATH, O_RDONLY);
int fd = px4_open(ADC0_DEVICE_PATH, O_RDONLY);
if (fd < 0) {
PX4_ERR("can't open ADC device %d", errno);
@@ -341,7 +342,7 @@ test(void)
for (unsigned i = 0; i < 20; i++) {
px4_adc_msg_t data[ADC_TOTAL_CHANNELS];
ssize_t count = read(fd, data, sizeof(data));
ssize_t count = px4_read(fd, data, sizeof(data));
if (count < 0) {
PX4_ERR("read error");
@@ -358,6 +359,8 @@ test(void)
px4_usleep(500000);
}
px4_close(fd);
return 0;
}
}
+2 -3
View File
@@ -1,6 +1,6 @@
############################################################################
#
# Copyright (c) 2015-2019 PX4 Development Team. All rights reserved.
# Copyright (c) 2015-2020 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -37,11 +37,10 @@ px4_add_module(
SRCS
battery_status.cpp
analog_battery.cpp
MODULE_CONFIG
module.yaml
DEPENDS
arch_adc
battery
conversion
drivers__device
+12 -59
View File
@@ -63,40 +63,14 @@
#include <uORB/topics/battery_status.h>
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
#include <DevMgr.hpp>
#include "analog_battery.h"
using namespace DriverFramework;
using namespace time_literals;
/**
* Analog layout:
* FMU:
* IN2 - battery voltage
* IN3 - battery current
* IN4 - 5V sense
* IN10 - spare (we could actually trim these from the set)
* IN11 - spare on FMUv2 & v3, RC RSSI on FMUv4
* IN12 - spare (we could actually trim these from the set)
* IN13 - aux1 on FMUv2, unavaible on v3 & v4
* IN14 - aux2 on FMUv2, unavaible on v3 & v4
* IN15 - pressure sensor on FMUv2, unavaible on v3 & v4
*
* IO:
* IN4 - servo supply rail
* IN5 - analog RSSI on FMUv2 & v3
*
* The channel definitions (e.g., ADC_BATTERY_VOLTAGE_CHANNEL, ADC_BATTERY_CURRENT_CHANNEL, and ADC_AIRSPEED_VOLTAGE_CHANNEL) are defined in board_config.h
*/
/**
* Battery status app start / stop handling function
*
* @ingroup apps
*/
extern "C" __EXPORT int battery_status_main(int argc, char *argv[]);
#ifndef BOARD_NUMBER_BRICKS
#error "battery_status module requires power bricks"
#endif
@@ -123,11 +97,8 @@ public:
void Run() override;
bool init();
/** @see ModuleBase::print_status() */
int print_status() override;
private:
DevHandle _h_adc; /**< ADC driver handle */
int _adc_fd{-1}; /**< ADC file handle */
uORB::Subscription _actuator_ctrl_0_sub{ORB_ID(actuator_controls_0)}; /**< attitude controls sub */
uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)}; /**< notification of parameter updates */
@@ -151,11 +122,6 @@ private:
perf_counter_t _loop_perf; /**< loop performance counter */
/**
* Do adc-related initialisation.
*/
int adc_init();
/**
* Check for changes in parameters.
*/
@@ -187,19 +153,6 @@ BatteryStatus::~BatteryStatus()
ScheduleClear();
}
int
BatteryStatus::adc_init()
{
DevMgr::getHandle(ADC0_DEVICE_PATH, _h_adc);
if (!_h_adc.isValid()) {
PX4_ERR("no ADC found: %s (%d)", ADC0_DEVICE_PATH, _h_adc.getError());
return PX4_ERROR;
}
return OK;
}
void
BatteryStatus::parameter_update_poll(bool forced)
{
@@ -221,7 +174,7 @@ BatteryStatus::adc_poll()
px4_adc_msg_t buf_adc[PX4_MAX_ADC_CHANNELS];
/* read all channels available */
int ret = _h_adc.read(&buf_adc, sizeof(buf_adc));
int ret = px4_read(_adc_fd, &buf_adc, sizeof(buf_adc));
/* For legacy support we publish the battery_status for the Battery that is
* associated with the Brick that is the selected source for VDD_5V_IN
@@ -307,12 +260,17 @@ BatteryStatus::Run()
return;
}
if (!_h_adc.isValid()) {
adc_init();
}
perf_begin(_loop_perf);
if (_adc_fd < 0) {
_adc_fd = px4_open(ADC0_DEVICE_PATH, O_RDONLY);
if (_adc_fd < 0) {
PX4_ERR("unable to open ADC: %s", ADC0_DEVICE_PATH);
return;
}
}
/* check parameters for updates */
parameter_update_poll();
@@ -354,11 +312,6 @@ BatteryStatus::init()
return true;
}
int BatteryStatus::print_status()
{
return 0;
}
int BatteryStatus::custom_command(int argc, char *argv[])
{
return print_usage("unknown command");
@@ -390,7 +343,7 @@ It runs in its own thread and polls on the currently selected gyro topic.
return 0;
}
int battery_status_main(int argc, char *argv[])
extern "C" __EXPORT int battery_status_main(int argc, char *argv[])
{
return BatteryStatus::main(argc, argv);
}