Files
PX4-Autopilot/src/platforms/px4_i2c.h
T
Mark Charlebois d013ac0927 Support for building more modules with Linux
Added more queue support to linux/px4_layer.

Use virt char devices for ms5611, and mavlink.

Added more HRT functionality. uORB latency test
now fails. Likely due to bad HRT impl for Linux.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2015-04-20 11:07:00 -07:00

130 lines
4.5 KiB
C

/****************************************************************************
*
* Copyright (c) 2015 Mark Charlebois. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file px4_i2c.h
*
* Includes device headers depending on the build target
*/
#pragma once
#define PX4_I2C_M_READ 0x0001 /* read data, from slave to master */
#if defined(__PX4_ROS)
#error "Devices not supported in ROS"
#elif defined (__PX4_NUTTX)
/*
* Building for NuttX
*/
#include <sys/ioctl.h>
#include <nuttx/arch.h>
#include <nuttx/wqueue.h>
#include <nuttx/clock.h>
#include <nuttx/i2c.h>
#include <nuttx/irq.h>
#include <nuttx/wqueue.h>
#include <chip.h>
#include <arch/board/board.h>
#include <arch/chip/chip.h>
#include "up_internal.h"
#include "up_arch.h"
#define px4_i2c_msg_t i2c_msg_s
typedef struct i2c_dev_s px4_i2c_dev_t;
#define px4_i2cuninitialize(x) up_i2cuninitialize(x)
#define px4_i2cinitialize(x) up_i2cinitialize(x)
#define px4_i2creset(x) up_i2creset(x)
#define px4_interrupt_context() up_interrupt_context()
#elif defined(__PX4_LINUX)
#include <stdint.h>
#define I2C_M_READ 0x0001 /* read data, from slave to master */
#define I2C_M_TEN 0x0002 /* ten bit address */
#define I2C_M_NORESTART 0x0080 /* message should not begin with (re-)start of transfer */
// NOTE - This is a copy of the NuttX i2c_msg_s structure
typedef struct {
uint16_t addr; /* Slave address */
uint16_t flags; /* See I2C_M_* definitions */
uint8_t *buffer;
int length;
} px4_i2c_msg_t;
struct px4_i2c_ops_t;
// NOTE - This is a copy of the NuttX i2c_ops_s structure
typedef struct {
const struct px4_i2c_ops_t *ops; /* I2C vtable */
} px4_i2c_dev_t;
// FIXME - Stub implementations
inline void px4_i2cuninitialize(px4_i2c_dev_t *dev);
inline void px4_i2cuninitialize(px4_i2c_dev_t *dev) {}
inline px4_i2c_dev_t *px4_i2cinitialize(int bus);
inline px4_i2c_dev_t *px4_i2cinitialize(int bus) { return (px4_i2c_dev_t *)0; }
inline void px4_i2creset(px4_i2c_dev_t *dev);
inline void px4_i2creset(px4_i2c_dev_t *dev) { }
inline bool px4_interrupt_context(void);
inline bool px4_interrupt_context(void) { return false; }
// FIXME - Empty defines for I2C ops
// Original version commented out
//#define I2C_SETFREQUENCY(d,f) ((d)->ops->setfrequency(d,f))
#define I2C_SETFREQUENCY(d,f)
//#define SPI_SELECT(d,id,s) ((d)->ops->select(d,id,s))
#define SPI_SELECT(d,id,s)
// FIXME - Stub implementation
// Original version commented out
//#define I2C_TRANSFER(d,m,c) ((d)->ops->transfer(d,m,c))
inline int I2C_TRANSFER(px4_i2c_dev_t *dev, px4_i2c_msg_t *msg, int count);
inline int I2C_TRANSFER(px4_i2c_dev_t *dev, px4_i2c_msg_t *msg, int count) { return 0; }
struct i2c_msg_s
{
uint16_t addr; /* Slave address */
uint16_t flags; /* See I2C_M_* definitions */
uint8_t *buffer;
int length;
};
#else
#error "No target platform defined"
#endif