39 #include <px4_platform_common/px4_config.h> 40 #include <px4_platform_common/defines.h> 43 #include <sys/types.h> 48 #include <semaphore.h> 59 #include <nuttx/arch.h> 60 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp> 61 #include <nuttx/clock.h> 64 #include <board_config.h> 69 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp> 71 #define ACCEL_DEVICE_PATH "/dev/bma180" 74 #define DIR_READ (1<<7) 75 #define DIR_WRITE (0<<7) 77 #define ADDR_CHIP_ID 0x00 80 #define ADDR_ACC_X_LSB 0x02 81 #define ADDR_ACC_Y_LSB 0x04 82 #define ADDR_ACC_Z_LSB 0x06 83 #define ADDR_TEMPERATURE 0x08 85 #define ADDR_CTRL_REG0 0x0D 86 #define REG0_WRITE_ENABLE 0x10 88 #define ADDR_RESET 0x10 89 #define SOFT_RESET 0xB6 91 #define ADDR_BW_TCS 0x20 92 #define BW_TCS_BW_MASK (0xf<<4) 93 #define BW_TCS_BW_10HZ (0<<4) 94 #define BW_TCS_BW_20HZ (1<<4) 95 #define BW_TCS_BW_40HZ (2<<4) 96 #define BW_TCS_BW_75HZ (3<<4) 97 #define BW_TCS_BW_150HZ (4<<4) 98 #define BW_TCS_BW_300HZ (5<<4) 99 #define BW_TCS_BW_600HZ (6<<4) 100 #define BW_TCS_BW_1200HZ (7<<4) 102 #define ADDR_HIGH_DUR 0x27 103 #define HIGH_DUR_DIS_I2C (1<<0) 105 #define ADDR_TCO_Z 0x30 106 #define TCO_Z_MODE_MASK 0x3 108 #define ADDR_GAIN_Y 0x33 109 #define GAIN_Y_SHADOW_DIS (1<<0) 111 #define ADDR_OFFSET_LSB1 0x35 112 #define OFFSET_LSB1_RANGE_MASK (7<<1) 113 #define OFFSET_LSB1_RANGE_1G (0<<1) 114 #define OFFSET_LSB1_RANGE_2G (2<<1) 115 #define OFFSET_LSB1_RANGE_3G (3<<1) 116 #define OFFSET_LSB1_RANGE_4G (4<<1) 117 #define OFFSET_LSB1_RANGE_8G (5<<1) 118 #define OFFSET_LSB1_RANGE_16G (6<<1) 120 #define ADDR_OFFSET_T 0x37 121 #define OFFSET_T_READOUT_12BIT (1<<0) 125 class BMA180 :
public device::SPI,
public px4::ScheduledWorkItem
133 virtual ssize_t
read(
struct file *filp,
char *buffer,
size_t buflen);
134 virtual int ioctl(
struct file *filp,
int cmd,
unsigned long arg);
192 void write_reg(
unsigned reg, uint8_t value);
203 void modify_reg(
unsigned reg, uint8_t clearbits, uint8_t setbits);
226 ScheduledWorkItem(MODULE_NAME,
px4::device_bus_to_wq(this->get_device_id())),
372 return ret ? ret : -EAGAIN;
411 unsigned interval = 1000000 / arg;
414 if (interval < 1000) {
439 return SPI::ioctl(filp, cmd, arg);
450 transfer(cmd, cmd,
sizeof(cmd));
463 transfer(cmd,
nullptr,
sizeof(cmd));
494 }
else if (max_g <= 3) {
498 }
else if (max_g <= 4) {
502 }
else if (max_g <= 8) {
506 }
else if (max_g <= 16) {
537 if (frequency > 1200) {
540 }
else if (frequency > 600) {
543 }
else if (frequency > 300) {
546 }
else if (frequency > 150) {
549 }
else if (frequency > 75) {
552 }
else if (frequency > 40) {
555 }
else if (frequency > 20) {
558 }
else if (frequency > 10) {
683 _reports->print_info(
"report queue");
707 if (g_dev !=
nullptr) {
708 errx(1,
"already started");
712 g_dev =
new BMA180(1 , PX4_SPIDEV_BMA);
714 if (g_dev ==
nullptr) {
718 if (
OK != g_dev->
init()) {
736 if (g_dev !=
nullptr) {
741 errx(1,
"driver start failed");
760 err(1,
"%s open failed (try 'bma180 start' if the driver is not running)",
766 sz =
read(fd, &a_report,
sizeof(a_report));
768 if (sz !=
sizeof(a_report)) {
769 err(1,
"immediate acc read failed");
772 print_message(a_report);
791 err(1,
"driver reset failed");
795 err(1,
"driver poll restart failed");
807 if (g_dev ==
nullptr) {
808 errx(1,
"BMA180: driver not running");
811 printf(
"state @ %p\n", g_dev);
830 if (!strcmp(argv[1],
"start")) {
837 if (!strcmp(argv[1],
"test")) {
844 if (!strcmp(argv[1],
"reset")) {
851 if (!strcmp(argv[1],
"info")) {
856 errx(1,
"unrecognised command, try 'start', 'test', 'reset' or 'info'");
Accelerometer driver interface.
ringbuffer::RingBuffer * _reports
int set_range(unsigned max_g)
Set the BMA180 measurement range.
orb_advert_t _accel_topic
virtual ssize_t read(struct file *filp, char *buffer, size_t buflen)
measure the time elapsed performing an event
#define OFFSET_LSB1_RANGE_8G
void test()
Perform some basic functional tests on the driver; make sure we can collect data from the sensor in p...
Definition of geo / math functions to perform geodesic calculations.
void print_info()
Diagnostics - print some basic information about the driver.
void modify_reg(unsigned reg, uint8_t clearbits, uint8_t setbits)
Modify a register in the BMA180.
void measure()
Fetch measurements from the sensor and update the report ring.
#define REG0_WRITE_ENABLE
#define SENSOR_POLLRATE_DEFAULT
poll at driver normal rate
void stop()
Stop automatic measurement.
orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *data)
void start()
Start the driver.
#define OFFSET_T_READOUT_12BIT
BMA180(int bus, uint32_t device)
#define OFFSET_LSB1_RANGE_MASK
Namespace encapsulating all device framework classes, functions and data.
High-resolution timer with callouts and timekeeping.
Local functions in support of the shell command.
static constexpr float CONSTANTS_ONE_G
accel scaling factors; Vout = Vscale * (Vin + Voffset)
uint8_t read_reg(unsigned reg)
Read a register from the BMA180.
#define SENSORIOCSPOLLRATE
Set the driver polling rate to (arg) Hz, or one of the SENSOR_POLLRATE constants. ...
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
#define OFFSET_LSB1_RANGE_2G
void perf_free(perf_counter_t handle)
Free a counter.
void init()
Activates/configures the hardware registers.
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
void perf_end(perf_counter_t handle)
End a performance event.
#define GAIN_Y_SHADOW_DIS
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)
#define OFFSET_LSB1_RANGE_16G
void start()
Start automatic measurement.
perf_counter_t _sample_perf
#define OFFSET_LSB1_RANGE_3G
#define ACCELIOCSSCALE
set the accel scaling constants to the structure pointed to by (arg)
#define OFFSET_LSB1_RANGE_4G
struct @83::@85::@87 file
void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
__EXPORT int bma180_main(int argc, char *argv[])
#define SENSORIOCRESET
Reset the sensor to its default configuration.
struct accel_calibration_s _accel_scale
int set_lowpass(unsigned frequency)
Set the BMA180 internal lowpass filter frequency.
#define DRV_ACC_DEVTYPE_BMA180
void write_reg(unsigned reg, uint8_t value)
Write a register in the BMA180.
#define ACCEL_DEVICE_PATH
void info()
Print a little info about the driver.
void reset()
Reset the driver.
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).
unsigned _current_lowpass
Performance measuring tools.