mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-02 10:51:35 +08:00
Updated PX4 use / API of low level GPIO and other hardware-centric system facilities
This commit is contained in:
@@ -273,9 +273,9 @@ ADC::read(file *filp, char *buffer, size_t len)
|
||||
}
|
||||
|
||||
/* block interrupts while copying samples to avoid racing with an update */
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
memcpy(buffer, _samples, len);
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
|
||||
return len;
|
||||
}
|
||||
@@ -343,9 +343,7 @@ ADC::update_adc_report(hrt_abstime now)
|
||||
void
|
||||
ADC::update_system_power(hrt_abstime now)
|
||||
{
|
||||
#if defined (CONFIG_ARCH_BOARD_PX4FMU_V2) || \
|
||||
defined (CONFIG_ARCH_BOARD_MINDPX_V2) || \
|
||||
defined (CONFIG_ARCH_BOARD_PX4FMU_V4)
|
||||
#if defined (BOARD_ADC_USB_CONNECTED)
|
||||
system_power_s system_power = {};
|
||||
system_power.timestamp = now;
|
||||
|
||||
@@ -358,35 +356,19 @@ ADC::update_system_power(hrt_abstime now)
|
||||
}
|
||||
}
|
||||
|
||||
/* Note once the board_config.h provides BOARD_ADC_USB_CONNECTED,
|
||||
* It must provide the true logic GPIO BOARD_ADC_xxxx macros.
|
||||
*/
|
||||
// these are not ADC related, but it is convenient to
|
||||
// publish these to the same topic
|
||||
system_power.usb_connected = stm32_gpioread(GPIO_OTGFS_VBUS);
|
||||
system_power.usb_connected = BOARD_ADC_USB_CONNECTED;
|
||||
|
||||
#if defined (CONFIG_ARCH_BOARD_MINDPX_V2)
|
||||
// note that the valid pins are active low
|
||||
system_power.brick_valid = 1;
|
||||
system_power.servo_valid = 1;
|
||||
system_power.brick_valid = BOARD_ADC_BRICK_VALID;
|
||||
system_power.servo_valid = BOARD_ADC_SERVO_VALID;
|
||||
|
||||
// OC pins are active low
|
||||
system_power.periph_5V_OC = 1;
|
||||
system_power.hipower_5V_OC = 1;
|
||||
#elif defined (CONFIG_ARCH_BOARD_PX4FMU_V4)
|
||||
// note that the valid pins are active high
|
||||
system_power.brick_valid = stm32_gpioread(GPIO_VDD_BRICK_VALID);
|
||||
system_power.servo_valid = 1;
|
||||
|
||||
// OC pins are not supported
|
||||
system_power.periph_5V_OC = 0;
|
||||
system_power.hipower_5V_OC = 0;
|
||||
#else
|
||||
// note that the valid pins are active low
|
||||
system_power.brick_valid = !stm32_gpioread(GPIO_VDD_BRICK_VALID);
|
||||
system_power.servo_valid = !stm32_gpioread(GPIO_VDD_SERVO_VALID);
|
||||
|
||||
// OC pins are active low
|
||||
system_power.periph_5V_OC = !stm32_gpioread(GPIO_VDD_5V_PERIPH_OC);
|
||||
system_power.hipower_5V_OC = !stm32_gpioread(GPIO_VDD_5V_HIPOWER_OC);
|
||||
#endif
|
||||
system_power.periph_5V_OC = BOARD_ADC_PERIPH_5V_OC;
|
||||
system_power.hipower_5V_OC = BOARD_ADC_HIPOWER_5V_OC;
|
||||
|
||||
/* lazily publish */
|
||||
if (_to_system_power != nullptr) {
|
||||
@@ -396,7 +378,7 @@ ADC::update_system_power(hrt_abstime now)
|
||||
_to_system_power = orb_advertise(ORB_ID(system_power), &system_power);
|
||||
}
|
||||
|
||||
#endif // CONFIG_ARCH_BOARD_PX4FMU_V2
|
||||
#endif // BOARD_ADC_USB_CONNECTED
|
||||
}
|
||||
|
||||
uint16_t
|
||||
|
||||
+11
-11
@@ -667,7 +667,7 @@ hrt_absolute_time(void)
|
||||
static volatile uint32_t last_count;
|
||||
|
||||
/* prevent re-entry */
|
||||
flags = irqsave();
|
||||
flags = px4_enter_critical_section();
|
||||
|
||||
/* get the current counter value */
|
||||
count = rCNT;
|
||||
@@ -689,7 +689,7 @@ hrt_absolute_time(void)
|
||||
/* compute the current time */
|
||||
abstime = HRT_COUNTER_SCALE(base_time + count);
|
||||
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
|
||||
return abstime;
|
||||
}
|
||||
@@ -725,11 +725,11 @@ abstime_to_ts(struct timespec *ts, hrt_abstime abstime)
|
||||
hrt_abstime
|
||||
hrt_elapsed_time(const volatile hrt_abstime *then)
|
||||
{
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
|
||||
hrt_abstime delta = hrt_absolute_time() - *then;
|
||||
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
|
||||
return delta;
|
||||
}
|
||||
@@ -740,11 +740,11 @@ hrt_elapsed_time(const volatile hrt_abstime *then)
|
||||
hrt_abstime
|
||||
hrt_store_absolute_time(volatile hrt_abstime *now)
|
||||
{
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
|
||||
hrt_abstime ts = hrt_absolute_time();
|
||||
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
|
||||
return ts;
|
||||
}
|
||||
@@ -760,7 +760,7 @@ hrt_init(void)
|
||||
|
||||
#ifdef HRT_PPM_CHANNEL
|
||||
/* configure the PPM input pin */
|
||||
stm32_configgpio(GPIO_PPM_IN);
|
||||
px4_arch_configgpio(GPIO_PPM_IN);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -802,7 +802,7 @@ hrt_call_every(struct hrt_call *entry, hrt_abstime delay, hrt_abstime interval,
|
||||
static void
|
||||
hrt_call_internal(struct hrt_call *entry, hrt_abstime deadline, hrt_abstime interval, hrt_callout callout, void *arg)
|
||||
{
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
|
||||
/* if the entry is currently queued, remove it */
|
||||
/* note that we are using a potentially uninitialised
|
||||
@@ -823,7 +823,7 @@ hrt_call_internal(struct hrt_call *entry, hrt_abstime deadline, hrt_abstime inte
|
||||
|
||||
hrt_call_enter(entry);
|
||||
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -843,7 +843,7 @@ hrt_called(struct hrt_call *entry)
|
||||
void
|
||||
hrt_cancel(struct hrt_call *entry)
|
||||
{
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
|
||||
sq_rem(&entry->link, &callout_queue);
|
||||
entry->deadline = 0;
|
||||
@@ -853,7 +853,7 @@ hrt_cancel(struct hrt_call *entry)
|
||||
*/
|
||||
entry->period = 0;
|
||||
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -107,7 +107,7 @@ static void input_capture_chan_handler(void *context, const io_timers_t *timer,
|
||||
hrt_abstime isrs_time , uint16_t isrs_rcnt)
|
||||
{
|
||||
uint16_t capture = _REG32(timer, chan->ccr_offset);
|
||||
channel_stats[chan_index].last_edge = stm32_gpioread(chan->gpio_in);
|
||||
channel_stats[chan_index].last_edge = px4_arch_gpioread(chan->gpio_in);
|
||||
|
||||
if ((isrs_rcnt - capture) > channel_stats[chan_index].latnecy) {
|
||||
channel_stats[chan_index].latnecy = (isrs_rcnt - capture);
|
||||
@@ -133,10 +133,10 @@ static void input_capture_chan_handler(void *context, const io_timers_t *timer,
|
||||
|
||||
static void input_capture_bind(unsigned channel, capture_callback_t callback, void *context)
|
||||
{
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
channel_handlers[channel].callback = callback;
|
||||
channel_handlers[channel].context = context;
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
}
|
||||
|
||||
static void input_capture_unbind(unsigned channel)
|
||||
@@ -258,7 +258,7 @@ int up_input_capture_set_filter(unsigned channel, capture_filter_t filter)
|
||||
uint32_t timer = timer_io_channels[channel].timer_index;
|
||||
uint16_t rvalue;
|
||||
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
|
||||
switch (timer_io_channels[channel].timer_channel) {
|
||||
|
||||
@@ -290,7 +290,7 @@ int up_input_capture_set_filter(unsigned channel, capture_filter_t filter)
|
||||
rv = -EIO;
|
||||
}
|
||||
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,7 +401,7 @@ int up_input_capture_set_trigger(unsigned channel, input_capture_edge edge)
|
||||
uint16_t rvalue;
|
||||
rv = OK;
|
||||
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
|
||||
switch (timer_io_channels[channel].timer_channel) {
|
||||
|
||||
@@ -437,7 +437,7 @@ int up_input_capture_set_trigger(unsigned channel, input_capture_edge edge)
|
||||
rv = -EIO;
|
||||
}
|
||||
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,10 +456,10 @@ int up_input_capture_get_callback(unsigned channel, capture_callback_t *callback
|
||||
|
||||
if (io_timer_get_channel_mode(channel) == IOTimerChanMode_Capture) {
|
||||
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
*callback = channel_handlers[channel].callback;
|
||||
*context = channel_handlers[channel].context;
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
rv = OK;
|
||||
}
|
||||
}
|
||||
@@ -492,14 +492,14 @@ int up_input_capture_get_stats(unsigned channel, input_capture_stats_t *stats, b
|
||||
int rv = io_timer_validate_channel_index(channel);
|
||||
|
||||
if (rv == 0) {
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
*stats = channel_stats[channel];
|
||||
|
||||
if (clear) {
|
||||
memset(&channel_stats[channel], 0, sizeof(*stats));
|
||||
}
|
||||
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
||||
@@ -397,7 +397,7 @@ static int io_timer_init_timer(unsigned timer)
|
||||
|
||||
if (rv == 0) {
|
||||
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
|
||||
set_timer_initalized(timer);
|
||||
|
||||
@@ -448,7 +448,7 @@ static int io_timer_init_timer(unsigned timer)
|
||||
|
||||
up_enable_irq(io_timers[timer].vectorno);
|
||||
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
}
|
||||
|
||||
return rv;
|
||||
@@ -520,11 +520,11 @@ int io_timer_channel_init(unsigned channel, io_timer_channel_mode_t mode,
|
||||
|
||||
io_timer_init_timer(channels_timer(channel));
|
||||
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
|
||||
/* Set up IO */
|
||||
if (gpio) {
|
||||
stm32_configgpio(gpio);
|
||||
px4_arch_configgpio(gpio);
|
||||
}
|
||||
|
||||
|
||||
@@ -570,7 +570,7 @@ int io_timer_channel_init(unsigned channel, io_timer_channel_mode_t mode,
|
||||
channel_handlers[channel].callback = channel_handler;
|
||||
channel_handlers[channel].context = context;
|
||||
rDIER(timer) |= dier_setbits << shifts;
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
}
|
||||
|
||||
return rv;
|
||||
@@ -643,7 +643,7 @@ int io_timer_set_enable(bool state, io_timer_channel_mode_t mode, io_timer_chann
|
||||
}
|
||||
}
|
||||
|
||||
irqstate_t flags = irqsave();
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
|
||||
for (unsigned actions = 0; actions < arraySize(action_cache) && action_cache[actions].base != 0 ; actions++) {
|
||||
uint32_t rvalue = _REG32(action_cache[actions].base, STM32_GTIM_CCER_OFFSET);
|
||||
@@ -667,7 +667,7 @@ int io_timer_set_enable(bool state, io_timer_channel_mode_t mode, io_timer_chann
|
||||
|
||||
for (unsigned chan = 0; chan < arraySize(action_cache[actions].gpio); chan++) {
|
||||
if (action_cache[actions].gpio[chan]) {
|
||||
stm32_configgpio(action_cache[actions].gpio[chan]);
|
||||
px4_arch_configgpio(action_cache[actions].gpio[chan]);
|
||||
action_cache[actions].gpio[chan] = 0;
|
||||
}
|
||||
}
|
||||
@@ -681,7 +681,7 @@ int io_timer_set_enable(bool state, io_timer_channel_mode_t mode, io_timer_chann
|
||||
}
|
||||
}
|
||||
|
||||
irqrestore(flags);
|
||||
px4_leave_critical_section(flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -439,7 +439,7 @@ ToneAlarm::init()
|
||||
}
|
||||
|
||||
/* configure the GPIO to the idle state */
|
||||
stm32_configgpio(GPIO_TONE_ALARM_IDLE);
|
||||
px4_arch_configgpio(GPIO_TONE_ALARM_IDLE);
|
||||
|
||||
/* clock/power on our timer */
|
||||
modifyreg32(TONE_ALARM_CLOCK_POWER_REG, 0, TONE_ALARM_CLOCK_ENABLE);
|
||||
@@ -571,7 +571,7 @@ ToneAlarm::start_note(unsigned note)
|
||||
rCCER |= TONE_CCER; // enable the output
|
||||
|
||||
// configure the GPIO to enable timer output
|
||||
stm32_configgpio(GPIO_TONE_ALARM);
|
||||
px4_arch_configgpio(GPIO_TONE_ALARM);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -583,7 +583,7 @@ ToneAlarm::stop_note()
|
||||
/*
|
||||
* Make sure the GPIO is not driving the speaker.
|
||||
*/
|
||||
stm32_configgpio(GPIO_TONE_ALARM_IDLE);
|
||||
px4_arch_configgpio(GPIO_TONE_ALARM_IDLE);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -876,7 +876,7 @@ ToneAlarm::ioctl(file *filp, int cmd, unsigned long arg)
|
||||
|
||||
DEVICE_DEBUG("ioctl %i %u", cmd, arg);
|
||||
|
||||
// irqstate_t flags = irqsave();
|
||||
// irqstate_t flags = px4_enter_critical_section();
|
||||
|
||||
/* decide whether to increase the alarm level to cmd or leave it alone */
|
||||
switch (cmd) {
|
||||
@@ -911,7 +911,7 @@ ToneAlarm::ioctl(file *filp, int cmd, unsigned long arg)
|
||||
break;
|
||||
}
|
||||
|
||||
// irqrestore(flags);
|
||||
// px4_leave_critical_section(flags);
|
||||
|
||||
/* give it to the superclass if we didn't like it */
|
||||
if (result == -ENOTTY) {
|
||||
|
||||
Reference in New Issue
Block a user