mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-16 15:13:35 +08:00
Updated PX4 use / API of low level GPIO and other hardware-centric system facilities
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
* @author Julian Oes <julian@oes.ch>
|
||||
* @author Sander Smeets <sander@droneslab.com>
|
||||
*/
|
||||
#include <px4_config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@@ -167,7 +168,7 @@ transition_result_t arming_state_transition(struct vehicle_status_s *status,
|
||||
* Perform an atomic state update
|
||||
*/
|
||||
#ifdef __PX4_NUTTX
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
#endif
|
||||
|
||||
/* enforce lockdown in HIL */
|
||||
@@ -306,7 +307,7 @@ transition_result_t arming_state_transition(struct vehicle_status_s *status,
|
||||
|
||||
/* end of atomic state update */
|
||||
#ifdef __PX4_NUTTX
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -542,7 +542,7 @@ ppm_input(uint16_t *values, uint16_t *num_values, uint16_t *frame_len)
|
||||
}
|
||||
|
||||
/* avoid racing with PPM updates */
|
||||
irqstate_t state = irqsave();
|
||||
irqstate_t state = px4_enter_critical_section();
|
||||
|
||||
/*
|
||||
* If we have received a new PPM frame within the last 200ms, accept it
|
||||
@@ -571,7 +571,7 @@ ppm_input(uint16_t *values, uint16_t *num_values, uint16_t *frame_len)
|
||||
result = (*num_values > 0);
|
||||
}
|
||||
|
||||
irqrestore(state);
|
||||
px4_leave_critical_section(state);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -112,8 +112,8 @@ interface_init(void)
|
||||
modifyreg32(STM32_RCC_APB1RSTR, RCC_APB1RSTR_I2C1RST, 0);
|
||||
|
||||
/* configure the i2c GPIOs */
|
||||
stm32_configgpio(GPIO_I2C1_SCL);
|
||||
stm32_configgpio(GPIO_I2C1_SDA);
|
||||
px4_arch_configgpio(GPIO_I2C1_SCL);
|
||||
px4_arch_configgpio(GPIO_I2C1_SDA);
|
||||
|
||||
/* soft-reset the block */
|
||||
rCR1 |= I2C_CR1_SWRST;
|
||||
@@ -301,12 +301,12 @@ i2c_rx_complete(void)
|
||||
}
|
||||
|
||||
/* disable interrupts while reconfiguring DMA for the selected registers */
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
|
||||
stm32_dmastop(tx_dma);
|
||||
i2c_tx_setup();
|
||||
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,22 +151,22 @@ extern pwm_limit_t pwm_limit;
|
||||
/*
|
||||
* GPIO handling.
|
||||
*/
|
||||
#define LED_BLUE(_s) stm32_gpiowrite(GPIO_LED1, !(_s))
|
||||
#define LED_AMBER(_s) stm32_gpiowrite(GPIO_LED2, !(_s))
|
||||
#define LED_SAFETY(_s) stm32_gpiowrite(GPIO_LED3, !(_s))
|
||||
#define LED_RING(_s) stm32_gpiowrite(GPIO_LED4, (_s))
|
||||
#define LED_BLUE(_s) px4_arch_gpiowrite(GPIO_LED1, !(_s))
|
||||
#define LED_AMBER(_s) px4_arch_gpiowrite(GPIO_LED2, !(_s))
|
||||
#define LED_SAFETY(_s) px4_arch_gpiowrite(GPIO_LED3, !(_s))
|
||||
#define LED_RING(_s) px4_arch_gpiowrite(GPIO_LED4, (_s))
|
||||
|
||||
#ifdef CONFIG_ARCH_BOARD_PX4IO_V1
|
||||
|
||||
# define PX4IO_RELAY_CHANNELS 4
|
||||
# define POWER_SERVO(_s) stm32_gpiowrite(GPIO_SERVO_PWR_EN, (_s))
|
||||
# define POWER_ACC1(_s) stm32_gpiowrite(GPIO_ACC1_PWR_EN, (_s))
|
||||
# define POWER_ACC2(_s) stm32_gpiowrite(GPIO_ACC2_PWR_EN, (_s))
|
||||
# define POWER_RELAY1(_s) stm32_gpiowrite(GPIO_RELAY1_EN, (_s))
|
||||
# define POWER_RELAY2(_s) stm32_gpiowrite(GPIO_RELAY2_EN, (_s))
|
||||
# define POWER_SERVO(_s) px4_arch_gpiowrite(GPIO_SERVO_PWR_EN, (_s))
|
||||
# define POWER_ACC1(_s) px4_arch_gpiowrite(GPIO_ACC1_PWR_EN, (_s))
|
||||
# define POWER_ACC2(_s) px4_arch_gpiowrite(GPIO_ACC2_PWR_EN, (_s))
|
||||
# define POWER_RELAY1(_s) px4_arch_gpiowrite(GPIO_RELAY1_EN, (_s))
|
||||
# define POWER_RELAY2(_s) px4_arch_gpiowrite(GPIO_RELAY2_EN, (_s))
|
||||
|
||||
# define OVERCURRENT_ACC (!stm32_gpioread(GPIO_ACC_OC_DETECT))
|
||||
# define OVERCURRENT_SERVO (!stm32_gpioread(GPIO_SERVO_OC_DETECT))
|
||||
# define OVERCURRENT_ACC (!px4_arch_gpioread(GPIO_ACC_OC_DETECT))
|
||||
# define OVERCURRENT_SERVO (!px4_arch_gpioread(GPIO_SERVO_OC_DETECT))
|
||||
|
||||
# define PX4IO_ADC_CHANNEL_COUNT 2
|
||||
# define ADC_VBATT 4
|
||||
@@ -177,9 +177,9 @@ extern pwm_limit_t pwm_limit;
|
||||
#ifdef CONFIG_ARCH_BOARD_PX4IO_V2
|
||||
|
||||
# define PX4IO_RELAY_CHANNELS 0
|
||||
# define ENABLE_SBUS_OUT(_s) stm32_gpiowrite(GPIO_SBUS_OENABLE, !(_s))
|
||||
# define ENABLE_SBUS_OUT(_s) px4_arch_gpiowrite(GPIO_SBUS_OENABLE, !(_s))
|
||||
|
||||
# define VDD_SERVO_FAULT (!stm32_gpioread(GPIO_SERVO_FAULT_DETECT))
|
||||
# define VDD_SERVO_FAULT (!px4_arch_gpioread(GPIO_SERVO_FAULT_DETECT))
|
||||
|
||||
# define PX4IO_ADC_CHANNEL_COUNT 2
|
||||
# define ADC_VSERVO 4
|
||||
@@ -187,7 +187,7 @@ extern pwm_limit_t pwm_limit;
|
||||
|
||||
#endif
|
||||
|
||||
#define BUTTON_SAFETY stm32_gpioread(GPIO_BTN_SAFETY)
|
||||
#define BUTTON_SAFETY px4_arch_gpioread(GPIO_BTN_SAFETY)
|
||||
|
||||
#define CONTROL_PAGE_INDEX(_group, _channel) (_group * PX4IO_CONTROL_CHANNELS + _channel)
|
||||
|
||||
|
||||
@@ -104,8 +104,8 @@ interface_init(void)
|
||||
rx_dma = stm32_dmachannel(PX4FMU_SERIAL_RX_DMA);
|
||||
|
||||
/* configure pins for serial use */
|
||||
stm32_configgpio(PX4FMU_SERIAL_TX_GPIO);
|
||||
stm32_configgpio(PX4FMU_SERIAL_RX_GPIO);
|
||||
px4_arch_configgpio(PX4FMU_SERIAL_TX_GPIO);
|
||||
px4_arch_configgpio(PX4FMU_SERIAL_RX_GPIO);
|
||||
|
||||
/* reset and configure the UART */
|
||||
rCR1 = 0;
|
||||
|
||||
@@ -807,17 +807,17 @@ param_bus_lock(bool lock)
|
||||
|
||||
// XXX this would be the preferred locking method
|
||||
// if (dev == nullptr) {
|
||||
// dev = up_spiinitialize(PX4_SPI_BUS_BARO);
|
||||
// dev = px4_spibus_initialize(PX4_SPI_BUS_BARO);
|
||||
// }
|
||||
|
||||
// SPI_LOCK(dev, lock);
|
||||
|
||||
// we lock like this for Pixracer for now
|
||||
if (lock) {
|
||||
irq_state = irqsave();
|
||||
irq_state = px4_enter_critical_section();
|
||||
|
||||
} else {
|
||||
irqrestore(irq_state);
|
||||
px4_leave_critical_section(irq_state);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2014 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
|
||||
* 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_macros.h
|
||||
*
|
||||
* A set of useful macros for enhanced runtime and compile time
|
||||
* error detection and warning suppression.
|
||||
*
|
||||
* Define NO_BLOAT to reduce bloat from file name inclusion.
|
||||
*
|
||||
* The arraySize() will compute the size of an array regardless
|
||||
* it's type
|
||||
*
|
||||
* INVALID_CASE(c) should be used is case statements to ferret out
|
||||
* unintended behavior
|
||||
*
|
||||
* UNUSED(var) will suppress compile time warnings of unused
|
||||
* variables
|
||||
*
|
||||
* CCASSERT(predicate) Will generate a compile time error it the
|
||||
* predicate is false
|
||||
*/
|
||||
#include <assert.h>
|
||||
|
||||
#ifndef _PX4_MACROS_H
|
||||
#define _PX4_MACROS_H
|
||||
|
||||
|
||||
#if !defined(arraySize)
|
||||
#define arraySize(a) (sizeof((a))/sizeof((a[0])))
|
||||
#endif
|
||||
|
||||
#if !defined(NO_BLOAT)
|
||||
#if defined(__BASE_FILE__)
|
||||
#define _FILE_NAME_ __BASE_FILE__
|
||||
#else
|
||||
#define _FILE_NAME_ __FILE__
|
||||
#endif
|
||||
#else
|
||||
#define _FILE_NAME_ ""
|
||||
#endif
|
||||
|
||||
#if !defined(INVALID_CASE)
|
||||
#define INVALID_CASE(c) printf("Invalid Case %d, %s:%d",(c),__BASE_FILE__,__LINE__) /* todo use PANIC */
|
||||
#endif
|
||||
|
||||
#if !defined(UNUSED)
|
||||
#define UNUSED(var) (void)(var)
|
||||
#endif
|
||||
|
||||
#if !defined(CAT)
|
||||
#if !defined(_CAT)
|
||||
#define _CAT(a, b) a ## b
|
||||
#endif
|
||||
#define CAT(a, b) _CAT(a, b)
|
||||
#endif
|
||||
|
||||
#if !defined(CCASSERT)
|
||||
#if defined(static_assert)
|
||||
# define CCASSERT(predicate) static_assert(predicate)
|
||||
# else
|
||||
# define CCASSERT(predicate) _x_CCASSERT_LINE(predicate, __LINE__)
|
||||
# if !defined(_x_CCASSERT_LINE)
|
||||
# define _x_CCASSERT_LINE(predicate, line) typedef char CAT(constraint_violated_on_line_,line)[2*((predicate)!=0)-1] __attribute__ ((unused)) ;
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define DO_PRAGMA(x) _Pragma (#x)
|
||||
#define TODO(x) DO_PRAGMA(message ("TODO - " #x))
|
||||
|
||||
#endif /* _PX4_MACROS_H */
|
||||
@@ -183,7 +183,7 @@ uORB::DeviceNode::read(struct file *filp, char *buffer, size_t buflen)
|
||||
/*
|
||||
* Perform an atomic copy & state update
|
||||
*/
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
|
||||
/* if the caller doesn't want the data, don't give it to them */
|
||||
if (nullptr != buffer) {
|
||||
@@ -202,7 +202,7 @@ uORB::DeviceNode::read(struct file *filp, char *buffer, size_t buflen)
|
||||
*/
|
||||
sd->update_reported = false;
|
||||
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
|
||||
return _meta->o_size;
|
||||
}
|
||||
@@ -244,7 +244,7 @@ uORB::DeviceNode::write(struct file *filp, const char *buffer, size_t buflen)
|
||||
}
|
||||
|
||||
/* Perform an atomic copy. */
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
memcpy(_data, buffer, _meta->o_size);
|
||||
|
||||
/* update the timestamp and generation count */
|
||||
@@ -253,7 +253,7 @@ uORB::DeviceNode::write(struct file *filp, const char *buffer, size_t buflen)
|
||||
|
||||
_published = true;
|
||||
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
|
||||
/* notify any poll waiters */
|
||||
poll_notify(POLLIN);
|
||||
@@ -268,9 +268,9 @@ uORB::DeviceNode::ioctl(struct file *filp, int cmd, unsigned long arg)
|
||||
|
||||
switch (cmd) {
|
||||
case ORBIOCLASTUPDATE: {
|
||||
irqstate_t state = irqsave();
|
||||
irqstate_t state = px4_enter_critical_section();
|
||||
*(hrt_abstime *)arg = _last_update;
|
||||
irqrestore(state);
|
||||
px4_leave_critical_section(state);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ uORB::DeviceNode::appears_updated(SubscriberData *sd)
|
||||
bool ret = false;
|
||||
|
||||
/* avoid racing between interrupt and non-interrupt context calls */
|
||||
irqstate_t state = irqsave();
|
||||
irqstate_t state = px4_enter_critical_section();
|
||||
|
||||
/* check if this topic has been published yet, if not bail out */
|
||||
if (_data == nullptr) {
|
||||
@@ -466,7 +466,7 @@ uORB::DeviceNode::appears_updated(SubscriberData *sd)
|
||||
}
|
||||
|
||||
out:
|
||||
irqrestore(state);
|
||||
px4_leave_critical_section(state);
|
||||
|
||||
/* consider it updated */
|
||||
return ret;
|
||||
|
||||
@@ -123,14 +123,14 @@ int UavcanBarometerBridge::ioctl(struct file *filp, int cmd, unsigned long arg)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
|
||||
if (!_reports.resize(arg)) {
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -537,12 +537,12 @@ int UavcanNode::start(uavcan::NodeID node_id, uint32_t bitrate)
|
||||
* fail during initialization.
|
||||
*/
|
||||
#if defined(GPIO_CAN1_RX)
|
||||
stm32_configgpio(GPIO_CAN1_RX);
|
||||
stm32_configgpio(GPIO_CAN1_TX);
|
||||
px4_arch_configgpio(GPIO_CAN1_RX);
|
||||
px4_arch_configgpio(GPIO_CAN1_TX);
|
||||
#endif
|
||||
#if defined(GPIO_CAN2_RX)
|
||||
stm32_configgpio(GPIO_CAN2_RX | GPIO_PULLUP);
|
||||
stm32_configgpio(GPIO_CAN2_TX);
|
||||
px4_arch_configgpio(GPIO_CAN2_RX | GPIO_PULLUP);
|
||||
px4_arch_configgpio(GPIO_CAN2_TX);
|
||||
#endif
|
||||
#if !defined(GPIO_CAN1_RX) && !defined(GPIO_CAN2_RX)
|
||||
# error "Need to define GPIO_CAN1_RX and/or GPIO_CAN2_RX"
|
||||
|
||||
Reference in New Issue
Block a user