PX4 Firmware
PX4 Autopilot Software http://px4.io
registers.c File Reference

Implementation of the PX4IO register space. More...

#include <px4_platform_common/px4_config.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <drivers/drv_hrt.h>
#include <drivers/drv_pwm_output.h>
#include <stm32_pwr.h>
#include <rc/dsm.h>
#include <rc/sbus.h>
#include "px4io.h"
#include "protocol.h"
Include dependency graph for registers.c:

Go to the source code of this file.

Macros

#define PX4IO_P_SETUP_FEATURES_VALID
 
#define PX4IO_P_SETUP_ARMING_VALID
 
#define PX4IO_P_SETUP_RATES_VALID   ((1 << PX4IO_SERVO_COUNT) - 1)
 
#define PX4IO_P_SETUP_RELAYS_VALID   ((1 << PX4IO_RELAY_CHANNELS) - 1)
 
#define PX4IO_P_RC_CONFIG_OPTIONS_VALID   (PX4IO_P_RC_CONFIG_OPTIONS_REVERSE | PX4IO_P_RC_CONFIG_OPTIONS_ENABLED)
 
#define SELECT_PAGE(_page_name)
 

Functions

static int registers_set_one (uint8_t page, uint8_t offset, uint16_t value)
 
static void pwm_configure_rates (uint16_t map, uint16_t defaultrate, uint16_t altrate)
 
int registers_set (uint8_t page, uint8_t offset, const uint16_t *values, unsigned num_values)
 Register space. More...
 
int registers_get (uint8_t page, uint8_t offset, uint16_t **values, unsigned *num_values)
 

Variables

bool update_mc_thrust_param
 
bool update_trims
 
static const uint16_t r_page_config []
 PAGE 0. More...
 
volatile uint16_t r_page_status []
 PAGE 1. More...
 
uint16_t r_page_actuators [PX4IO_SERVO_COUNT]
 PAGE 2. More...
 
uint16_t r_page_servos [PX4IO_SERVO_COUNT]
 PAGE 3. More...
 
uint16_t r_page_raw_rc_input []
 PAGE 4. More...
 
uint16_t r_page_rc_input []
 PAGE 5. More...
 
uint16_t r_page_scratch [32]
 Scratch page; used for registers that are constructed as-read. More...
 
uint16_t r_page_direct_pwm [PX4IO_SERVO_COUNT]
 PAGE 8. More...
 
volatile uint16_t r_page_setup []
 PAGE 100. More...
 
uint16_t r_page_controls [PX4IO_CONTROL_GROUPS *PX4IO_CONTROL_CHANNELS]
 PAGE 101. More...
 
uint16_t r_page_rc_input_config [PX4IO_RC_INPUT_CHANNELS *PX4IO_P_RC_CONFIG_STRIDE]
 PAGE 103. More...
 
uint16_t r_page_servo_failsafe [PX4IO_SERVO_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0 }
 PAGE 105. More...
 
uint16_t r_page_servo_control_min [PX4IO_SERVO_COUNT] = { PWM_DEFAULT_MIN, PWM_DEFAULT_MIN, PWM_DEFAULT_MIN, PWM_DEFAULT_MIN, PWM_DEFAULT_MIN, PWM_DEFAULT_MIN, PWM_DEFAULT_MIN, PWM_DEFAULT_MIN }
 PAGE 106. More...
 
uint16_t r_page_servo_control_max [PX4IO_SERVO_COUNT] = { PWM_DEFAULT_MAX, PWM_DEFAULT_MAX, PWM_DEFAULT_MAX, PWM_DEFAULT_MAX, PWM_DEFAULT_MAX, PWM_DEFAULT_MAX, PWM_DEFAULT_MAX, PWM_DEFAULT_MAX }
 PAGE 107. More...
 
int16_t r_page_servo_control_trim [PX4IO_SERVO_COUNT] = { PWM_DEFAULT_TRIM, PWM_DEFAULT_TRIM, PWM_DEFAULT_TRIM, PWM_DEFAULT_TRIM, PWM_DEFAULT_TRIM, PWM_DEFAULT_TRIM, PWM_DEFAULT_TRIM, PWM_DEFAULT_TRIM }
 PAGE 108. More...
 
uint16_t r_page_servo_disarmed [PX4IO_SERVO_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0 }
 PAGE 109. More...
 
uint8_t last_page
 
uint8_t last_offset
 

Detailed Description

Implementation of the PX4IO register space.

Author
Lorenz Meier loren.nosp@m.z@px.nosp@m.4.io

Definition in file registers.c.

Macro Definition Documentation

◆ PX4IO_P_RC_CONFIG_OPTIONS_VALID

#define PX4IO_P_RC_CONFIG_OPTIONS_VALID   (PX4IO_P_RC_CONFIG_OPTIONS_REVERSE | PX4IO_P_RC_CONFIG_OPTIONS_ENABLED)

Definition at line 227 of file registers.c.

Referenced by registers_set_one().

◆ PX4IO_P_SETUP_ARMING_VALID

#define PX4IO_P_SETUP_ARMING_VALID
Value:
PX4IO_P_SETUP_ARMING_FMU_PREARMED | \
PX4IO_P_SETUP_ARMING_MANUAL_OVERRIDE_OK | \
PX4IO_P_SETUP_ARMING_INAIR_RESTART_OK | \
PX4IO_P_SETUP_ARMING_IO_ARM_OK | \
PX4IO_P_SETUP_ARMING_FAILSAFE_CUSTOM | \
PX4IO_P_SETUP_ARMING_ALWAYS_PWM_ENABLE | \
PX4IO_P_SETUP_ARMING_RC_HANDLING_DISABLED | \
PX4IO_P_SETUP_ARMING_LOCKDOWN | \
PX4IO_P_SETUP_ARMING_FORCE_FAILSAFE | \
PX4IO_P_SETUP_ARMING_TERMINATION_FAILSAFE | \
PX4IO_P_SETUP_ARMING_OVERRIDE_IMMEDIATE)
#define PX4IO_P_SETUP_ARMING_FMU_ARMED
Definition: protocol.h:184

Definition at line 193 of file registers.c.

Referenced by registers_set_one().

◆ PX4IO_P_SETUP_FEATURES_VALID

#define PX4IO_P_SETUP_FEATURES_VALID
Value:
PX4IO_P_SETUP_FEATURES_SBUS2_OUT | \
PX4IO_P_SETUP_FEATURES_ADC_RSSI | \
PX4IO_P_SETUP_FEATURES_PWM_RSSI)
#define PX4IO_P_SETUP_FEATURES_SBUS1_OUT
enable S.Bus v1 output
Definition: protocol.h:177

Definition at line 188 of file registers.c.

Referenced by registers_set_one().

◆ PX4IO_P_SETUP_RATES_VALID

#define PX4IO_P_SETUP_RATES_VALID   ((1 << PX4IO_SERVO_COUNT) - 1)

Definition at line 205 of file registers.c.

Referenced by registers_set_one().

◆ PX4IO_P_SETUP_RELAYS_VALID

#define PX4IO_P_SETUP_RELAYS_VALID   ((1 << PX4IO_RELAY_CHANNELS) - 1)

Definition at line 206 of file registers.c.

◆ SELECT_PAGE

#define SELECT_PAGE (   _page_name)
Value:
do { \
*values = (uint16_t *)&_page_name[0]; \
*num_values = sizeof(_page_name) / sizeof(_page_name[0]); \
} while(0)

Referenced by registers_get().

Function Documentation

◆ pwm_configure_rates()

static void pwm_configure_rates ( uint16_t  map,
uint16_t  defaultrate,
uint16_t  altrate 
)
static

Definition at line 1054 of file registers.c.

References OK, PX4IO_P_STATUS_ALARMS_PWM_ERROR, PX4IO_SERVO_COUNT, r_setup_pwm_altrate, r_setup_pwm_defaultrate, r_setup_pwm_rates, r_status_alarms, up_pwm_servo_get_rate_group(), and up_pwm_servo_set_rate_group_update().

Referenced by registers_set_one().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ registers_get()

◆ registers_set()

int registers_set ( uint8_t  page,
uint8_t  offset,
const uint16_t *  values,
unsigned  num_values 
)

◆ registers_set_one()

static int registers_set_one ( uint8_t  page,
uint8_t  offset,
uint16_t  value 
)
static

do not allow a RC config change while safety is off

Definition at line 490 of file registers.c.

References ENABLE_SBUS_OUT, isr_debug(), LED_AMBER, mixer_set_failsafe(), pwm_configure_rates(), PX4IO_FORCE_SAFETY_MAGIC, PX4IO_P_RC_CONFIG_ASSIGNMENT, PX4IO_P_RC_CONFIG_ASSIGNMENT_MODESWITCH, PX4IO_P_RC_CONFIG_CENTER, PX4IO_P_RC_CONFIG_DEADZONE, PX4IO_P_RC_CONFIG_MAX, PX4IO_P_RC_CONFIG_MIN, PX4IO_P_RC_CONFIG_OPTIONS, PX4IO_P_RC_CONFIG_OPTIONS_ENABLED, PX4IO_P_RC_CONFIG_OPTIONS_VALID, PX4IO_P_RC_CONFIG_STRIDE, PX4IO_P_SETUP_AIRMODE, PX4IO_P_SETUP_ARMING, PX4IO_P_SETUP_ARMING_FORCE_FAILSAFE, PX4IO_P_SETUP_ARMING_RC_HANDLING_DISABLED, PX4IO_P_SETUP_ARMING_TERMINATION_FAILSAFE, PX4IO_P_SETUP_ARMING_VALID, PX4IO_P_SETUP_DSM, PX4IO_P_SETUP_ENABLE_FLIGHTTERMINATION, PX4IO_P_SETUP_FEATURES, PX4IO_P_SETUP_FEATURES_ADC_RSSI, PX4IO_P_SETUP_FEATURES_PWM_RSSI, PX4IO_P_SETUP_FEATURES_SBUS1_OUT, PX4IO_P_SETUP_FEATURES_SBUS2_OUT, PX4IO_P_SETUP_FEATURES_VALID, PX4IO_P_SETUP_FORCE_SAFETY_OFF, PX4IO_P_SETUP_FORCE_SAFETY_ON, PX4IO_P_SETUP_MOTOR_SLEW_MAX, PX4IO_P_SETUP_PWM_ALTRATE, PX4IO_P_SETUP_PWM_DEFAULTRATE, PX4IO_P_SETUP_PWM_RATES, PX4IO_P_SETUP_PWM_REVERSE, PX4IO_P_SETUP_RATES_VALID, PX4IO_P_SETUP_RC_THR_FAILSAFE_US, PX4IO_P_SETUP_REBOOT_BL, PX4IO_P_SETUP_SBUS_RATE, PX4IO_P_SETUP_SCALE_PITCH, PX4IO_P_SETUP_SCALE_ROLL, PX4IO_P_SETUP_SCALE_YAW, PX4IO_P_SETUP_SET_DEBUG, PX4IO_P_SETUP_THERMAL, PX4IO_P_SETUP_THR_MDL_FAC, PX4IO_P_SETUP_TRIM_PITCH, PX4IO_P_SETUP_TRIM_ROLL, PX4IO_P_SETUP_TRIM_YAW, PX4IO_P_STATUS_ALARMS, PX4IO_P_STATUS_FLAGS, PX4IO_P_STATUS_FLAGS_ARM_SYNC, PX4IO_P_STATUS_FLAGS_INIT_OK, PX4IO_P_STATUS_FLAGS_MIXER_OK, PX4IO_P_STATUS_FLAGS_SAFETY_OFF, PX4IO_P_TEST_LED, PX4IO_PAGE_RC_CONFIG, PX4IO_PAGE_SETUP, PX4IO_PAGE_STATUS, PX4IO_PAGE_TEST, PX4IO_RC_INPUT_CHANNELS, PX4IO_RC_MAPPED_CONTROL_CHANNELS, PX4IO_REBOOT_BL_MAGIC, r_page_rc_input_config, r_page_setup, r_setup_arming, r_setup_features, r_setup_pwm_altrate, r_setup_pwm_defaultrate, r_setup_pwm_rates, r_status_alarms, r_status_flags, sbus1_set_output_rate_hz(), schedule_reboot(), and update_mc_thrust_param.

Referenced by registers_set().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ last_offset

uint8_t last_offset

Definition at line 841 of file registers.c.

Referenced by registers_get().

◆ last_page

uint8_t last_page

Definition at line 840 of file registers.c.

Referenced by registers_get().

◆ r_page_actuators

uint16_t r_page_actuators[PX4IO_SERVO_COUNT]

PAGE 2.

Post-mixed actuator values.

Definition at line 101 of file registers.c.

Referenced by mixer_tick(), and registers_get().

◆ r_page_config

const uint16_t r_page_config[]
static
Initial value:
= {
}
#define PX4IO_P_CONFIG_CONTROL_COUNT
Definition: protocol.h:94
#define PX4IO_P_CONFIG_ADC_INPUT_COUNT
Definition: protocol.h:97
#define PX4IO_P_CONFIG_RC_INPUT_COUNT
Definition: protocol.h:96
#define PX4IO_P_CONFIG_RELAY_COUNT
Definition: protocol.h:98
#define PX4IO_RC_INPUT_CHANNELS
Definition: px4io.h:68
#define PX4IO_P_CONFIG_MAX_TRANSFER
Definition: protocol.h:93
#define PX4IO_P_CONFIG_PROTOCOL_VERSION
Definition: protocol.h:90
#define PX4IO_CONTROL_CHANNELS
Definition: px4io.h:66
#define PX4IO_P_CONFIG_ACTUATOR_COUNT
Definition: protocol.h:95
#define PX4IO_MAX_TRANSFER_LEN
Definition: protocol.h:99
#define PX4IO_ADC_CHANNEL_COUNT
Definition: px4io.h:179
#define PX4IO_BL_VERSION
Definition: px4io.h:64
#define PX4IO_RELAY_CHANNELS
Definition: px4io.h:174
#define PX4IO_SERVO_COUNT
Definition: px4io.h:65
#define PX4IO_PROTOCOL_VERSION
Definition: protocol.h:83
#define PX4IO_P_CONFIG_BOOTLOADER_VERSION
Definition: protocol.h:92
#define PX4IO_P_CONFIG_HARDWARE_VERSION
Definition: protocol.h:91

PAGE 0.

Static configuration parameters.

Definition at line 68 of file registers.c.

Referenced by registers_get().

◆ r_page_controls

uint16_t r_page_controls[PX4IO_CONTROL_GROUPS *PX4IO_CONTROL_CHANNELS]

PAGE 101.

Control values from the FMU.

Definition at line 213 of file registers.c.

Referenced by mixer_callback(), registers_get(), and registers_set().

◆ r_page_direct_pwm

uint16_t r_page_direct_pwm[PX4IO_SERVO_COUNT]

PAGE 8.

RAW PWM values

Definition at line 148 of file registers.c.

Referenced by mixer_tick(), registers_get(), and registers_set().

◆ r_page_raw_rc_input

uint16_t r_page_raw_rc_input[]
Initial value:
= {
[PX4IO_P_RAW_RC_BASE ...(PX4IO_P_RAW_RC_BASE + PX4IO_RC_INPUT_CHANNELS)] = 0
}
#define PX4IO_P_RAW_FRAME_COUNT
Definition: protocol.h:158
#define PX4IO_P_RAW_RC_BASE
Definition: protocol.h:160
#define PX4IO_RC_INPUT_CHANNELS
Definition: px4io.h:68
#define PX4IO_P_RAW_LOST_FRAME_COUNT
Definition: protocol.h:159
#define PX4IO_P_RAW_RC_FLAGS
Definition: protocol.h:149
#define PX4IO_P_RAW_RC_COUNT
Definition: protocol.h:148
#define PX4IO_P_RAW_RC_NRSSI
Definition: protocol.h:156
#define PX4IO_P_RAW_RC_DATA
Definition: protocol.h:157

PAGE 4.

Raw RC input

Definition at line 115 of file registers.c.

Referenced by controls_tick(), and registers_get().

◆ r_page_rc_input

uint16_t r_page_rc_input[]
Initial value:
= {
}
#define PX4IO_P_RC_BASE
Definition: protocol.h:165
#define PX4IO_P_RC_VALID
Definition: protocol.h:164
#define PX4IO_RC_MAPPED_CONTROL_CHANNELS
This is the maximum number of channels mapped/used.
Definition: px4io.h:69

PAGE 5.

Scaled/routed RC input

Definition at line 130 of file registers.c.

Referenced by mixer_callback(), and registers_get().

◆ r_page_rc_input_config

uint16_t r_page_rc_input_config[PX4IO_RC_INPUT_CHANNELS *PX4IO_P_RC_CONFIG_STRIDE]

PAGE 103.

R/C channel input configuration.

Definition at line 224 of file registers.c.

Referenced by controls_init(), controls_tick(), registers_get(), and registers_set_one().

◆ r_page_scratch

uint16_t r_page_scratch[32]

Scratch page; used for registers that are constructed as-read.

PAGE 6 Raw ADC input. PAGE 7 PWM rate maps.

Definition at line 141 of file registers.c.

Referenced by registers_get().

◆ r_page_servo_control_max

◆ r_page_servo_control_min

◆ r_page_servo_control_trim

PAGE 108.

trim values for center position

Definition at line 264 of file registers.c.

Referenced by mixer_tick(), registers_get(), and registers_set().

◆ r_page_servo_disarmed

uint16_t r_page_servo_disarmed[PX4IO_SERVO_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0 }

PAGE 109.

disarmed PWM values for difficult ESCs

Definition at line 272 of file registers.c.

Referenced by mixer_tick(), MixerTest::mixerTest(), registers_get(), and registers_set().

◆ r_page_servo_failsafe

uint16_t r_page_servo_failsafe[PX4IO_SERVO_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0 }

PAGE 105.

Failsafe servo PWM values

Disable pulses as default.

Definition at line 240 of file registers.c.

Referenced by mixer_set_failsafe(), mixer_tick(), registers_get(), and registers_set().

◆ r_page_servos

uint16_t r_page_servos[PX4IO_SERVO_COUNT]

PAGE 3.

Servo PWM values

Definition at line 108 of file registers.c.

Referenced by mixer_tick(), MixerTest::mixerTest(), and registers_get().

◆ r_page_setup

volatile uint16_t r_page_setup[]

PAGE 100.

Setup registers

Definition at line 155 of file registers.c.

Referenced by calculate_fw_crc(), isr_debug(), registers_get(), registers_set_one(), and user_start().

◆ r_page_status

volatile uint16_t r_page_status[]
Initial value:
= {
}
#define PX4IO_P_STATUS_VSERVO
Definition: protocol.h:134
#define PX4IO_P_STATUS_PRSSI
Definition: protocol.h:136
#define PX4IO_P_STATUS_CPULOAD
Definition: protocol.h:104
#define PX4IO_P_STATUS_MIXER
Definition: protocol.h:138
#define PX4IO_P_STATUS_FLAGS
Definition: protocol.h:106
#define PX4IO_P_STATUS_VRSSI
Definition: protocol.h:135
#define PX4IO_P_STATUS_FREEMEM
Definition: protocol.h:103
#define PX4IO_P_STATUS_ALARMS
Definition: protocol.h:124

PAGE 1.

Status values.

Definition at line 85 of file registers.c.

Referenced by registers_get(), update_mem_usage(), and user_start().

◆ update_mc_thrust_param

bool update_mc_thrust_param

Definition at line 60 of file registers.c.

Referenced by mixer_handle_text(), mixer_set_failsafe(), mixer_tick(), and registers_set_one().

◆ update_trims

bool update_trims

Definition at line 61 of file registers.c.

Referenced by mixer_handle_text(), mixer_tick(), and registers_set().