49 #define INCREMENT(_x, _lim) do { __typeof__(_x) _tmp = _x+1; if (_tmp >= _lim) _tmp = 0; _x = _tmp; } while(0) 52 #define POW2(_x) ((_x) * (_x)) 58 #define MPL3115A2_CONVERSION_INTERVAL 10000 59 #define MPL3115A2_OSR 2 60 #define MPL3115A2_CTRL_TRIGGER (CTRL_REG1_OST | CTRL_REG1_OS(MPL3115A2_OSR)) 61 #define MPL3115A2_BARO_DEVICE_PATH_EXT "/dev/mpl3115a2_ext" 62 #define MPL3115A2_BARO_DEVICE_PATH_INT "/dev/mpl3115a2_int" 72 virtual ssize_t
read(
struct file *filp,
char *buffer,
size_t buflen);
73 virtual int ioctl(
struct file *filp,
int cmd,
unsigned long arg);
108 void start(
unsigned delay_us = 1);
151 ScheduledWorkItem(MODULE_NAME,
px4::device_bus_to_wq(interface->get_device_id())),
198 PX4_DEBUG(
"CDev init failed");
206 PX4_DEBUG(
"can't get memory for reports");
223 if (ret == -EAGAIN) {
226 }
while (ret == -EAGAIN);
237 if (ret == -EAGAIN) {
240 }
while (ret == -EAGAIN);
261 warnx(
"failed to create sensor_baro publication");
299 return ret ? ret : -EAGAIN;
310 if (ret == -EAGAIN) {
313 }
while (ret == -EAGAIN);
369 unsigned interval = (1000000 / arg);
405 return CDev::ioctl(filp, cmd, arg);
416 ScheduleDelayed(delay_us);
448 if (ret == -EAGAIN) {
538 _T = (float) reading.temperature.b[1] + ((
float)(reading.temperature.b[0]) / 16.0
f);
539 _P = (float)(reading.pressure.q >> 8) + ((float)(reading.pressure.b[0]) / 4.0f);
569 _reports->print_info(
"report queue");
592 #if defined(PX4_SPIDEV_EXT_BARO) && defined(PX4_SPI_BUS_EXT) 593 { MPL3115A2_BUS_SPI_EXTERNAL,
"/dev/mpl3115a2_spi_ext", &MPL3115A2_spi_interface, PX4_SPI_BUS_EXT, NULL },
595 #ifdef PX4_SPIDEV_BARO 596 { MPL3115A2_BUS_SPI_INTERNAL,
"/dev/mpl3115a2_spi_int", &MPL3115A2_spi_interface, PX4_SPI_BUS_BARO, NULL },
598 #ifdef PX4_I2C_BUS_ONBOARD 601 #ifdef PX4_I2C_BUS_EXPANSION 604 #ifdef PX4_I2C_BUS_EXPANSION1 607 #ifdef PX4_I2C_BUS_EXPANSION2 611 #define NUM_BUS_OPTIONS (sizeof(bus_options)/sizeof(bus_options[0])) 613 bool start_bus(
struct mpl3115a2_bus_option &bus);
627 if (bus.
dev !=
nullptr) {
628 errx(1,
"bus option already started");
631 device::Device *
interface = bus.interface_constructor(bus.busnum);
633 if (interface->init() !=
OK) {
635 warnx(
"no device on bus %u", (
unsigned)bus.busid);
639 bus.dev =
new MPL3115A2(interface, bus.devpath);
641 if (bus.dev !=
nullptr &&
OK != bus.dev->init()) {
647 int fd =
open(bus.devpath, O_RDONLY);
651 errx(1,
"can't open baro device");
656 errx(1,
"failed setting default poll rate");
674 bool started =
false;
711 errx(1,
"bus %u not started", (
unsigned)busid);
732 err(1,
"open failed (try 'mpl3115a2 start' if the driver is not running)");
736 sz =
read(fd, &report,
sizeof(report));
738 if (sz !=
sizeof(report)) {
739 err(1,
"immediate read failed");
742 print_message(report);
745 for (
unsigned i = 0; i < 5; i++) {
751 ret =
poll(&fds, 1, 2000);
754 errx(1,
"timed out waiting for sensor data");
758 sz =
read(fd, &report,
sizeof(report));
760 if (sz !=
sizeof(report)) {
761 err(1,
"periodic read failed");
764 print_message(report);
787 err(1,
"driver reset failed");
791 err(1,
"driver poll restart failed");
806 if (bus.
dev !=
nullptr) {
818 warnx(
"missing command: try 'start', 'info', 'test', 'reset'");
820 warnx(
" -X (external I2C bus)");
821 warnx(
" -I (intternal I2C bus)");
833 const char *myoptarg = NULL;
836 while ((ch = px4_getopt(argc, argv,
"XI", &myoptind, &myoptarg)) != EOF) {
852 if (myoptind >= argc) {
857 const char *verb = argv[myoptind];
862 if (!strcmp(verb,
"start")) {
869 if (!strcmp(verb,
"test")) {
876 if (!strcmp(verb,
"reset")) {
883 if (!strcmp(verb,
"info")) {
device::Device *(* MPL3115A2_constructor)(uint8_t busnum)
unsigned _measure_interval
virtual int open(file_t *filep)
Handle an open of the device.
#define BARO_BASE_DEVICE_PATH
measure the time elapsed performing an event
void info()
Print a little info about the driver.
virtual int measure()
Issue a measurement command for the current state.
virtual int register_class_devname(const char *class_devname)
Register a class device name, automatically adding device class instance suffix if need be...
Shared defines for the mpl3115a2 driver.
#define SENSOR_POLLRATE_DEFAULT
poll at driver normal rate
void usage(const char *reason)
Print the correct usage.
MPL3115A2_constructor interface_constructor
__EXPORT int mpl3115a2_main(int argc, char *argv[])
perf_counter_t _comms_errors
virtual ssize_t read(struct file *filp, char *buffer, size_t buflen)
void usage()
Prints info about the driver argument usage.
count the number of times an event occurs
ringbuffer::RingBuffer * _reports
void reset(enum MPL3115A2_BUS busid)
Reset the driver.
struct mpl3115a2::mpl3115a2_bus_option bus_options[]
virtual int close(file_t *filep)
Handle a close of the device.
virtual void poll_notify(pollevent_t events)
Report new poll events.
uint32_t get_device_id() const
#define SENSORIOCSPOLLRATE
Set the driver polling rate to (arg) Hz, or one of the SENSOR_POLLRATE constants. ...
#define DRV_BARO_DEVTYPE_MPL3115A2
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
void perf_count(perf_counter_t handle)
Count a performance event.
Abstract class for any character device.
void start(unsigned delay_us=1)
Initialize the automatic measurement state machine and start it.
void stop()
Stop the automatic measurement state machine.
void perf_free(perf_counter_t handle)
Free a counter.
void init()
Activates/configures the hardware registers.
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...
#define MPL3115A2_CTRL_REG1
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
Local functions in support of the shell command.
bool start_bus(struct mpl3115a2_bus_option &bus)
Start the driver.
void perf_end(perf_counter_t handle)
End a performance event.
void print_info()
Diagnostics - print some basic information about the driver.
virtual int ioctl(struct file *filp, int cmd, unsigned long arg)
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data)
virtual int ioctl(unsigned operation, unsigned &arg)
Perform a device-specific operation.
perf_counter_t _sample_perf
void set_device_type(uint8_t devtype)
#define MPL3115A2_CONVERSION_INTERVAL
virtual bool external() const
device::Device * MPL3115A2_i2c_interface(uint8_t busnum)
void start(enum MPL3115A2_BUS busid)
Start the driver.
const char * get_devname() const
Get the device name.
struct @83::@85::@87 file
void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
#define SENSORIOCRESET
Reset the sensor to its default configuration.
uint64_t perf_event_count(perf_counter_t handle)
Return current event_count.
void test(enum MPL3115A2_BUS busid)
Perform some basic functional tests on the driver; make sure we can collect data from the sensor in p...
Fundamental base class for all physical drivers (I2C, SPI).
CDev(const char *devname)
Constructor.
virtual int collect()
Collect the result of the most recent measurement.
device::Device * _interface
MPL3115A2(device::Device *interface, const char *path)
void Run() override
Perform a poll cycle; collect from the previous measurement and start a new one.
orb_advert_t orb_advertise_multi(const struct orb_metadata *meta, const void *data, int *instance, int priority)
#define MPL3115A2_CTRL_TRIGGER
void perf_begin(perf_counter_t handle)
Begin a performance event.
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
virtual int read(unsigned address, void *data, unsigned count)
Read directly from the device.
virtual int poll(file_t *filep, px4_pollfd_struct_t *fds, bool setup)
Perform a poll setup/teardown operation.
struct mpl3115a2_bus_option & find_bus(enum MPL3115A2_BUS busid)
find a bus structure for a busid
perf_counter_t _measure_perf