mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-31 16:52:10 +01:00
Merge branch 'safer_failsafe' into next
This commit is contained in:
commit
8f7712435f
@ -81,6 +81,7 @@ static void updateActuatorDesired(ManualControlCommandData * cmd);
|
|||||||
static void updateStabilizationDesired(ManualControlCommandData * cmd, ManualControlSettingsData * settings);
|
static void updateStabilizationDesired(ManualControlCommandData * cmd, ManualControlSettingsData * settings);
|
||||||
static void processFlightMode(ManualControlSettingsData * settings, float flightMode);
|
static void processFlightMode(ManualControlSettingsData * settings, float flightMode);
|
||||||
static void processArm(ManualControlCommandData * cmd, ManualControlSettingsData * settings);
|
static void processArm(ManualControlCommandData * cmd, ManualControlSettingsData * settings);
|
||||||
|
static void setArmedIfChanged(uint8_t val);
|
||||||
|
|
||||||
static void manualControlTask(void *parameters);
|
static void manualControlTask(void *parameters);
|
||||||
static float scaleChannel(int16_t value, int16_t max, int16_t min, int16_t neutral);
|
static float scaleChannel(int16_t value, int16_t max, int16_t min, int16_t neutral);
|
||||||
@ -202,6 +203,8 @@ static void manualControlTask(void *parameters)
|
|||||||
|
|
||||||
if (!ManualControlCommandReadOnly(&cmd)) {
|
if (!ManualControlCommandReadOnly(&cmd)) {
|
||||||
|
|
||||||
|
bool valid_input_detected = true;
|
||||||
|
|
||||||
// Read channel values in us
|
// Read channel values in us
|
||||||
for (uint8_t n = 0;
|
for (uint8_t n = 0;
|
||||||
n < MANUALCONTROLSETTINGS_CHANNELGROUPS_NUMELEM && n < MANUALCONTROLCOMMAND_CHANNEL_NUMELEM;
|
n < MANUALCONTROLSETTINGS_CHANNELGROUPS_NUMELEM && n < MANUALCONTROLCOMMAND_CHANNEL_NUMELEM;
|
||||||
@ -209,13 +212,17 @@ static void manualControlTask(void *parameters)
|
|||||||
extern uint32_t pios_rcvr_group_map[];
|
extern uint32_t pios_rcvr_group_map[];
|
||||||
|
|
||||||
if (settings.ChannelGroups[n] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
|
if (settings.ChannelGroups[n] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
|
||||||
cmd.Channel[n] = -1;
|
cmd.Channel[n] = PIOS_RCVR_INVALID;
|
||||||
} else if (!pios_rcvr_group_map[settings.ChannelGroups[n]]) {
|
|
||||||
cmd.Channel[n] = -2;
|
|
||||||
} else {
|
} else {
|
||||||
cmd.Channel[n] = PIOS_RCVR_Read(pios_rcvr_group_map[settings.ChannelGroups[n]],
|
cmd.Channel[n] = PIOS_RCVR_Read(pios_rcvr_group_map[settings.ChannelGroups[n]],
|
||||||
settings.ChannelNumber[n]);
|
settings.ChannelNumber[n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If a channel has timed out this is not valid data and we shouldn't update anything
|
||||||
|
// until we decide to go to failsafe
|
||||||
|
if(cmd.Channel[n] == PIOS_RCVR_TIMEOUT)
|
||||||
|
valid_input_detected = false;
|
||||||
|
else
|
||||||
scaledChannel[n] = scaleChannel(cmd.Channel[n], settings.ChannelMax[n], settings.ChannelMin[n], settings.ChannelNeutral[n]);
|
scaledChannel[n] = scaleChannel(cmd.Channel[n], settings.ChannelMax[n], settings.ChannelMin[n], settings.ChannelNeutral[n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,15 +231,33 @@ static void manualControlTask(void *parameters)
|
|||||||
settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE ||
|
settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE ||
|
||||||
settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE ||
|
settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE ||
|
||||||
settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE ||
|
settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE ||
|
||||||
settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_FLIGHTMODE] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
|
settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_FLIGHTMODE] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE ||
|
||||||
|
// Check all channel mappings are valid
|
||||||
|
cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL] == (uint16_t) PIOS_RCVR_INVALID ||
|
||||||
|
cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH] == (uint16_t) PIOS_RCVR_INVALID ||
|
||||||
|
cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW] == (uint16_t) PIOS_RCVR_INVALID ||
|
||||||
|
cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE] == (uint16_t) PIOS_RCVR_INVALID ||
|
||||||
|
cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_FLIGHTMODE] == (uint16_t) PIOS_RCVR_INVALID ||
|
||||||
|
// Check the driver is exists
|
||||||
|
cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL] == (uint16_t) PIOS_RCVR_NODRIVER ||
|
||||||
|
cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH] == (uint16_t) PIOS_RCVR_NODRIVER ||
|
||||||
|
cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW] == (uint16_t) PIOS_RCVR_NODRIVER ||
|
||||||
|
cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE] == (uint16_t) PIOS_RCVR_NODRIVER ||
|
||||||
|
cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_FLIGHTMODE] == (uint16_t) PIOS_RCVR_NODRIVER) {
|
||||||
|
|
||||||
AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_CRITICAL);
|
AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_CRITICAL);
|
||||||
cmd.Connected = MANUALCONTROLCOMMAND_CONNECTED_FALSE;
|
cmd.Connected = MANUALCONTROLCOMMAND_CONNECTED_FALSE;
|
||||||
ManualControlCommandSet(&cmd);
|
ManualControlCommandSet(&cmd);
|
||||||
|
|
||||||
|
// Need to do this here since we don't process armed status. Since this shouldn't happen in flight (changed config)
|
||||||
|
// immediately disarm
|
||||||
|
setArmedIfChanged(FLIGHTSTATUS_ARMED_DISARMED);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// decide if we have valid manual input or not
|
// decide if we have valid manual input or not
|
||||||
bool valid_input_detected = validInputRange(settings.ChannelMin[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE], settings.ChannelMax[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE], cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE]) &&
|
valid_input_detected &= validInputRange(settings.ChannelMin[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE], settings.ChannelMax[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE], cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE]) &&
|
||||||
validInputRange(settings.ChannelMin[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL], settings.ChannelMax[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL], cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL]) &&
|
validInputRange(settings.ChannelMin[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL], settings.ChannelMax[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL], cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL]) &&
|
||||||
validInputRange(settings.ChannelMin[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW], settings.ChannelMax[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW], cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW]) &&
|
validInputRange(settings.ChannelMin[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW], settings.ChannelMax[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW], cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW]) &&
|
||||||
validInputRange(settings.ChannelMin[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH], settings.ChannelMax[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH], cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH]);
|
validInputRange(settings.ChannelMin[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH], settings.ChannelMax[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH], cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH]);
|
||||||
@ -257,7 +282,30 @@ static void manualControlTask(void *parameters)
|
|||||||
// Important: Throttle < 0 will reset Stabilization coefficients among other things. Either change this,
|
// Important: Throttle < 0 will reset Stabilization coefficients among other things. Either change this,
|
||||||
// or leave throttle at IDLE speed or above when going into AUTO-failsafe.
|
// or leave throttle at IDLE speed or above when going into AUTO-failsafe.
|
||||||
AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_WARNING);
|
AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_WARNING);
|
||||||
ManualControlCommandSet(&cmd);
|
|
||||||
|
AccessoryDesiredData accessory;
|
||||||
|
// Set Accessory 0
|
||||||
|
if (settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_ACCESSORY0] !=
|
||||||
|
MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
|
||||||
|
accessory.AccessoryVal = 0;
|
||||||
|
if(AccessoryDesiredInstSet(0, &accessory) != 0)
|
||||||
|
AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_WARNING);
|
||||||
|
}
|
||||||
|
// Set Accessory 1
|
||||||
|
if (settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_ACCESSORY1] !=
|
||||||
|
MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
|
||||||
|
accessory.AccessoryVal = 0;
|
||||||
|
if(AccessoryDesiredInstSet(1, &accessory) != 0)
|
||||||
|
AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_WARNING);
|
||||||
|
}
|
||||||
|
// Set Accessory 2
|
||||||
|
if (settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_ACCESSORY2] !=
|
||||||
|
MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
|
||||||
|
accessory.AccessoryVal = 0;
|
||||||
|
if(AccessoryDesiredInstSet(2, &accessory) != 0)
|
||||||
|
AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_WARNING);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
AlarmsClear(SYSTEMALARMS_ALARM_MANUALCONTROL);
|
AlarmsClear(SYSTEMALARMS_ALARM_MANUALCONTROL);
|
||||||
|
|
||||||
@ -293,13 +341,15 @@ static void manualControlTask(void *parameters)
|
|||||||
|
|
||||||
|
|
||||||
processFlightMode(&settings, flightMode);
|
processFlightMode(&settings, flightMode);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process arming outside conditional so system will disarm when disconnected
|
||||||
processArm(&cmd, &settings);
|
processArm(&cmd, &settings);
|
||||||
|
|
||||||
// Update cmd object
|
// Update cmd object
|
||||||
ManualControlCommandSet(&cmd);
|
ManualControlCommandSet(&cmd);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ManualControlCommandGet(&cmd); /* Under GCS control */
|
ManualControlCommandGet(&cmd); /* Under GCS control */
|
||||||
}
|
}
|
||||||
@ -624,7 +674,7 @@ static void processArm(ManualControlCommandData * cmd, ManualControlSettingsData
|
|||||||
} else {
|
} else {
|
||||||
// Not really needed since this function not called when disconnected
|
// Not really needed since this function not called when disconnected
|
||||||
if (cmd->Connected == MANUALCONTROLCOMMAND_CONNECTED_FALSE)
|
if (cmd->Connected == MANUALCONTROLCOMMAND_CONNECTED_FALSE)
|
||||||
return;
|
lowThrottle = true;
|
||||||
|
|
||||||
// The throttle is not low, in case we where arming or disarming, abort
|
// The throttle is not low, in case we where arming or disarming, abort
|
||||||
if (!lowThrottle) {
|
if (!lowThrottle) {
|
||||||
|
@ -76,8 +76,20 @@ out_fail:
|
|||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads an input channel from the appropriate driver
|
||||||
|
* @param[in] rcvr_id driver to read from
|
||||||
|
* @param[in] channel channel to read
|
||||||
|
* @returns Unitless input value
|
||||||
|
* @retval PIOS_RCVR_TIMEOUT indicates a failsafe or timeout from that channel
|
||||||
|
* @retval PIOS_RCVR_INVALID invalid channel for this driver (usually out of range supported)
|
||||||
|
* @retval PIOS_RCVR_NODRIVER driver was not initialized
|
||||||
|
*/
|
||||||
int32_t PIOS_RCVR_Read(uint32_t rcvr_id, uint8_t channel)
|
int32_t PIOS_RCVR_Read(uint32_t rcvr_id, uint8_t channel)
|
||||||
{
|
{
|
||||||
|
if (rcvr_id == 0)
|
||||||
|
return PIOS_RCVR_NODRIVER;
|
||||||
|
|
||||||
struct pios_rcvr_dev * rcvr_dev = (struct pios_rcvr_dev *)rcvr_id;
|
struct pios_rcvr_dev * rcvr_dev = (struct pios_rcvr_dev *)rcvr_id;
|
||||||
|
|
||||||
if (!PIOS_RCVR_validate(rcvr_dev)) {
|
if (!PIOS_RCVR_validate(rcvr_dev)) {
|
||||||
|
@ -47,7 +47,6 @@ const struct pios_rcvr_driver pios_ppm_rcvr_driver = {
|
|||||||
#define PIOS_PPM_IN_MIN_SYNC_PULSE_US 3800 // microseconds
|
#define PIOS_PPM_IN_MIN_SYNC_PULSE_US 3800 // microseconds
|
||||||
#define PIOS_PPM_IN_MIN_CHANNEL_PULSE_US 750 // microseconds
|
#define PIOS_PPM_IN_MIN_CHANNEL_PULSE_US 750 // microseconds
|
||||||
#define PIOS_PPM_IN_MAX_CHANNEL_PULSE_US 2250 // microseconds
|
#define PIOS_PPM_IN_MAX_CHANNEL_PULSE_US 2250 // microseconds
|
||||||
#define PIOS_PPM_INPUT_INVALID 0
|
|
||||||
|
|
||||||
/* Local Variables */
|
/* Local Variables */
|
||||||
static TIM_ICInitTypeDef TIM_ICInitStructure;
|
static TIM_ICInitTypeDef TIM_ICInitStructure;
|
||||||
@ -212,12 +211,12 @@ static int32_t PIOS_PPM_Get(uint32_t rcvr_id, uint8_t channel)
|
|||||||
|
|
||||||
if (!PIOS_PPM_validate(ppm_dev)) {
|
if (!PIOS_PPM_validate(ppm_dev)) {
|
||||||
/* Invalid device specified */
|
/* Invalid device specified */
|
||||||
return -1;
|
return PIOS_RCVR_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel >= PIOS_PPM_IN_MAX_NUM_CHANNELS) {
|
if (channel >= PIOS_PPM_IN_MAX_NUM_CHANNELS) {
|
||||||
/* Channel out of range */
|
/* Channel out of range */
|
||||||
return -1;
|
return PIOS_RCVR_INVALID;
|
||||||
}
|
}
|
||||||
return ppm_dev->CaptureValue[channel];
|
return ppm_dev->CaptureValue[channel];
|
||||||
}
|
}
|
||||||
@ -290,7 +289,7 @@ static void PIOS_PPM_tim_edge_cb (uint32_t tim_id, uint32_t context, uint8_t cha
|
|||||||
}
|
}
|
||||||
for (uint32_t i = ppm_dev->NumChannels;
|
for (uint32_t i = ppm_dev->NumChannels;
|
||||||
i < PIOS_PPM_IN_MAX_NUM_CHANNELS; i++) {
|
i < PIOS_PPM_IN_MAX_NUM_CHANNELS; i++) {
|
||||||
ppm_dev->CaptureValue[i] = PIOS_PPM_INPUT_INVALID;
|
ppm_dev->CaptureValue[i] = PIOS_RCVR_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +313,7 @@ static void PIOS_PPM_tim_edge_cb (uint32_t tim_id, uint32_t context, uint8_t cha
|
|||||||
/* Not a valid pulse duration */
|
/* Not a valid pulse duration */
|
||||||
ppm_dev->Tracking = FALSE;
|
ppm_dev->Tracking = FALSE;
|
||||||
for (uint32_t i = 0; i < PIOS_PPM_IN_MAX_NUM_CHANNELS ; i++) {
|
for (uint32_t i = 0; i < PIOS_PPM_IN_MAX_NUM_CHANNELS ; i++) {
|
||||||
ppm_dev->CaptureValueNewFrame[i] = PIOS_PPM_INPUT_INVALID;
|
ppm_dev->CaptureValueNewFrame[i] = PIOS_RCVR_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -342,8 +341,8 @@ static void PIOS_PPM_Supervisor(uint32_t ppm_id) {
|
|||||||
ppm_dev->Tracking = FALSE;
|
ppm_dev->Tracking = FALSE;
|
||||||
|
|
||||||
for (int32_t i = 0; i < PIOS_PPM_IN_MAX_NUM_CHANNELS ; i++) {
|
for (int32_t i = 0; i < PIOS_PPM_IN_MAX_NUM_CHANNELS ; i++) {
|
||||||
ppm_dev->CaptureValue[i] = PIOS_PPM_INPUT_INVALID;
|
ppm_dev->CaptureValue[i] = PIOS_RCVR_TIMEOUT;
|
||||||
ppm_dev->CaptureValueNewFrame[i] = PIOS_PPM_INPUT_INVALID;
|
ppm_dev->CaptureValueNewFrame[i] = PIOS_RCVR_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,8 @@ const struct pios_rcvr_driver pios_pwm_rcvr_driver = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Local Variables */
|
/* Local Variables */
|
||||||
|
/* 100 ms timeout without updates on channels */
|
||||||
|
const static uint32_t PWM_SUPERVISOR_TIMEOUT = 100000;
|
||||||
|
|
||||||
enum pios_pwm_dev_magic {
|
enum pios_pwm_dev_magic {
|
||||||
PIOS_PWM_DEV_MAGIC = 0xab30293c,
|
PIOS_PWM_DEV_MAGIC = 0xab30293c,
|
||||||
@ -56,6 +58,7 @@ struct pios_pwm_dev {
|
|||||||
uint16_t FallValue[PIOS_PWM_NUM_INPUTS];
|
uint16_t FallValue[PIOS_PWM_NUM_INPUTS];
|
||||||
uint32_t CaptureValue[PIOS_PWM_NUM_INPUTS];
|
uint32_t CaptureValue[PIOS_PWM_NUM_INPUTS];
|
||||||
uint32_t CapCounter[PIOS_PWM_NUM_INPUTS];
|
uint32_t CapCounter[PIOS_PWM_NUM_INPUTS];
|
||||||
|
uint32_t us_since_update[PIOS_PWM_NUM_INPUTS];
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool PIOS_PWM_validate(struct pios_pwm_dev * pwm_dev)
|
static bool PIOS_PWM_validate(struct pios_pwm_dev * pwm_dev)
|
||||||
@ -120,7 +123,7 @@ int32_t PIOS_PWM_Init(uint32_t * pwm_id, const struct pios_pwm_cfg * cfg)
|
|||||||
pwm_dev->CaptureState[i] = 0;
|
pwm_dev->CaptureState[i] = 0;
|
||||||
pwm_dev->RiseValue[i] = 0;
|
pwm_dev->RiseValue[i] = 0;
|
||||||
pwm_dev->FallValue[i] = 0;
|
pwm_dev->FallValue[i] = 0;
|
||||||
pwm_dev->CaptureValue[i] = 0;
|
pwm_dev->CaptureValue[i] = PIOS_RCVR_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t tim_id;
|
uint32_t tim_id;
|
||||||
@ -152,6 +155,10 @@ int32_t PIOS_PWM_Init(uint32_t * pwm_id, const struct pios_pwm_cfg * cfg)
|
|||||||
TIM_ITConfig(chan->timer, TIM_IT_CC4, ENABLE);
|
TIM_ITConfig(chan->timer, TIM_IT_CC4, ENABLE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Need the update event for that timer to detect timeouts
|
||||||
|
TIM_ITConfig(chan->timer, TIM_IT_Update, ENABLE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*pwm_id = (uint32_t) pwm_dev;
|
*pwm_id = (uint32_t) pwm_dev;
|
||||||
@ -174,12 +181,12 @@ static int32_t PIOS_PWM_Get(uint32_t rcvr_id, uint8_t channel)
|
|||||||
|
|
||||||
if (!PIOS_PWM_validate(pwm_dev)) {
|
if (!PIOS_PWM_validate(pwm_dev)) {
|
||||||
/* Invalid device specified */
|
/* Invalid device specified */
|
||||||
return -1;
|
return PIOS_RCVR_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel >= PIOS_PWM_NUM_INPUTS) {
|
if (channel >= PIOS_PWM_NUM_INPUTS) {
|
||||||
/* Channel out of range */
|
/* Channel out of range */
|
||||||
return -1;
|
return PIOS_RCVR_INVALID;
|
||||||
}
|
}
|
||||||
return pwm_dev->CaptureValue[channel];
|
return pwm_dev->CaptureValue[channel];
|
||||||
}
|
}
|
||||||
@ -193,6 +200,20 @@ static void PIOS_PWM_tim_overflow_cb (uint32_t tim_id, uint32_t context, uint8_t
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (channel >= pwm_dev->cfg->num_channels) {
|
||||||
|
/* Channel out of range */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pwm_dev->us_since_update[channel] += count;
|
||||||
|
if(pwm_dev->us_since_update[channel] >= PWM_SUPERVISOR_TIMEOUT) {
|
||||||
|
pwm_dev->CaptureState[channel] = 0;
|
||||||
|
pwm_dev->RiseValue[channel] = 0;
|
||||||
|
pwm_dev->FallValue[channel] = 0;
|
||||||
|
pwm_dev->CaptureValue[channel] = PIOS_RCVR_TIMEOUT;
|
||||||
|
pwm_dev->us_since_update[channel] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,6 +236,7 @@ static void PIOS_PWM_tim_edge_cb (uint32_t tim_id, uint32_t context, uint8_t cha
|
|||||||
|
|
||||||
if (pwm_dev->CaptureState[chan_idx] == 0) {
|
if (pwm_dev->CaptureState[chan_idx] == 0) {
|
||||||
pwm_dev->RiseValue[chan_idx] = count;
|
pwm_dev->RiseValue[chan_idx] = count;
|
||||||
|
pwm_dev->us_since_update[chan_idx] = 0;
|
||||||
} else {
|
} else {
|
||||||
pwm_dev->FallValue[chan_idx] = count;
|
pwm_dev->FallValue[chan_idx] = count;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ static void PIOS_SBUS_Supervisor(uint32_t sbus_id);
|
|||||||
static void reset_channels(void)
|
static void reset_channels(void)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < SBUS_NUMBER_OF_CHANNELS; i++) {
|
for (int i = 0; i < SBUS_NUMBER_OF_CHANNELS; i++) {
|
||||||
channel_data[i] = 0;
|
channel_data[i] = PIOS_RCVR_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ static int32_t PIOS_SBUS_Get(uint32_t rcvr_id, uint8_t channel)
|
|||||||
{
|
{
|
||||||
/* return error if channel is not available */
|
/* return error if channel is not available */
|
||||||
if (channel >= SBUS_NUMBER_OF_CHANNELS) {
|
if (channel >= SBUS_NUMBER_OF_CHANNELS) {
|
||||||
return -1;
|
return PIOS_RCVR_INVALID;
|
||||||
}
|
}
|
||||||
return channel_data[channel];
|
return channel_data[channel];
|
||||||
}
|
}
|
||||||
|
@ -260,12 +260,12 @@ static int32_t PIOS_SPEKTRUM_Get(uint32_t rcvr_id, uint8_t channel)
|
|||||||
{
|
{
|
||||||
struct pios_spektrum_dev * spektrum_dev = (struct pios_spektrum_dev *)rcvr_id;
|
struct pios_spektrum_dev * spektrum_dev = (struct pios_spektrum_dev *)rcvr_id;
|
||||||
|
|
||||||
bool valid = PIOS_SPEKTRUM_validate(spektrum_dev);
|
if(!PIOS_SPEKTRUM_validate(spektrum_dev))
|
||||||
PIOS_Assert(valid);
|
return PIOS_RCVR_INVALID;
|
||||||
|
|
||||||
/* Return error if channel not available */
|
/* Return error if channel not available */
|
||||||
if (channel >= PIOS_SPEKTRUM_NUM_INPUTS) {
|
if (channel >= PIOS_SPEKTRUM_NUM_INPUTS) {
|
||||||
return -1;
|
return PIOS_RCVR_INVALID;
|
||||||
}
|
}
|
||||||
return spektrum_dev->fsm.CaptureValue[channel];
|
return spektrum_dev->fsm.CaptureValue[channel];
|
||||||
}
|
}
|
||||||
@ -334,8 +334,8 @@ static void PIOS_SPEKTRUM_Supervisor(uint32_t spektrum_id)
|
|||||||
/* signal lost */
|
/* signal lost */
|
||||||
fsm->sync_of = 0;
|
fsm->sync_of = 0;
|
||||||
for (int i = 0; i < PIOS_SPEKTRUM_NUM_INPUTS; i++) {
|
for (int i = 0; i < PIOS_SPEKTRUM_NUM_INPUTS; i++) {
|
||||||
fsm->CaptureValue[i] = 0;
|
fsm->CaptureValue[i] = PIOS_RCVR_TIMEOUT;
|
||||||
fsm->CaptureValueTemp[i] = 0;
|
fsm->CaptureValueTemp[i] = PIOS_RCVR_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spektrum_dev->supv_timer = 0;
|
spektrum_dev->supv_timer = 0;
|
||||||
|
@ -39,6 +39,16 @@ struct pios_rcvr_driver {
|
|||||||
/* Public Functions */
|
/* Public Functions */
|
||||||
extern int32_t PIOS_RCVR_Read(uint32_t rcvr_id, uint8_t channel);
|
extern int32_t PIOS_RCVR_Read(uint32_t rcvr_id, uint8_t channel);
|
||||||
|
|
||||||
|
/*! Define error codes for PIOS_RCVR_Get */
|
||||||
|
enum PIOS_RCVR_errors {
|
||||||
|
/*! Indicates that a failsafe condition or missing receiver detected for that channel */
|
||||||
|
PIOS_RCVR_TIMEOUT = 0,
|
||||||
|
/*! Channel is invalid for this driver (usually out of range supported) */
|
||||||
|
PIOS_RCVR_INVALID = -1,
|
||||||
|
/*! Indicates that the driver for this channel has not been initialized */
|
||||||
|
PIOS_RCVR_NODRIVER = -2
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* PIOS_RCVR_H */
|
#endif /* PIOS_RCVR_H */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,6 +91,14 @@
|
|||||||
65632DF51251650300469B77 /* pios_board.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_board.h; sourceTree = "<group>"; };
|
65632DF51251650300469B77 /* pios_board.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_board.h; sourceTree = "<group>"; };
|
||||||
65632DF61251650300469B77 /* STM32103CB_AHRS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STM32103CB_AHRS.h; sourceTree = "<group>"; };
|
65632DF61251650300469B77 /* STM32103CB_AHRS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STM32103CB_AHRS.h; sourceTree = "<group>"; };
|
||||||
65632DF71251650300469B77 /* STM3210E_OP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STM3210E_OP.h; sourceTree = "<group>"; };
|
65632DF71251650300469B77 /* STM3210E_OP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STM3210E_OP.h; sourceTree = "<group>"; };
|
||||||
|
65643CAB1413322000A32F59 /* pios_rcvr_priv.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_rcvr_priv.h; sourceTree = "<group>"; };
|
||||||
|
65643CAC1413322000A32F59 /* pios_rcvr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_rcvr.h; sourceTree = "<group>"; };
|
||||||
|
65643CAD1413322000A32F59 /* pios_rtc_priv.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_rtc_priv.h; sourceTree = "<group>"; };
|
||||||
|
65643CAE1413322000A32F59 /* pios_sbus_priv.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_sbus_priv.h; sourceTree = "<group>"; };
|
||||||
|
65643CAF1413322000A32F59 /* pios_sbus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_sbus.h; sourceTree = "<group>"; };
|
||||||
|
65643CB01413322000A32F59 /* pios_spektrum_priv.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_spektrum_priv.h; sourceTree = "<group>"; };
|
||||||
|
65643CB91413456D00A32F59 /* pios_tim.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_tim.c; sourceTree = "<group>"; };
|
||||||
|
65643CBA141350C200A32F59 /* pios_sbus.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_sbus.c; sourceTree = "<group>"; };
|
||||||
6572CB1613D0F2B200FC2972 /* link_STM32103CB_CC_Rev1_memory.ld */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = link_STM32103CB_CC_Rev1_memory.ld; path = ../../PiOS/STM32F10x/link_STM32103CB_CC_Rev1_memory.ld; sourceTree = SOURCE_ROOT; };
|
6572CB1613D0F2B200FC2972 /* link_STM32103CB_CC_Rev1_memory.ld */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = link_STM32103CB_CC_Rev1_memory.ld; path = ../../PiOS/STM32F10x/link_STM32103CB_CC_Rev1_memory.ld; sourceTree = SOURCE_ROOT; };
|
||||||
6572CB1713D0F2B200FC2972 /* link_STM32103CB_CC_Rev1_sections.ld */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = link_STM32103CB_CC_Rev1_sections.ld; path = ../../PiOS/STM32F10x/link_STM32103CB_CC_Rev1_sections.ld; sourceTree = SOURCE_ROOT; };
|
6572CB1713D0F2B200FC2972 /* link_STM32103CB_CC_Rev1_sections.ld */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = link_STM32103CB_CC_Rev1_sections.ld; path = ../../PiOS/STM32F10x/link_STM32103CB_CC_Rev1_sections.ld; sourceTree = SOURCE_ROOT; };
|
||||||
657CEEAD121DB6C8007A1FBE /* homelocation.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = homelocation.xml; sourceTree = "<group>"; };
|
657CEEAD121DB6C8007A1FBE /* homelocation.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = homelocation.xml; sourceTree = "<group>"; };
|
||||||
@ -7724,11 +7732,17 @@
|
|||||||
65E8F04811EFF25C00BBF654 /* pios_ppm.h */,
|
65E8F04811EFF25C00BBF654 /* pios_ppm.h */,
|
||||||
65E8F04911EFF25C00BBF654 /* pios_pwm.h */,
|
65E8F04911EFF25C00BBF654 /* pios_pwm.h */,
|
||||||
657FF86A12EA8BFB00801617 /* pios_pwm_priv.h */,
|
657FF86A12EA8BFB00801617 /* pios_pwm_priv.h */,
|
||||||
|
65643CAC1413322000A32F59 /* pios_rcvr.h */,
|
||||||
|
65643CAB1413322000A32F59 /* pios_rcvr_priv.h */,
|
||||||
6589A9E2131DF1C7006BD67C /* pios_rtc.h */,
|
6589A9E2131DF1C7006BD67C /* pios_rtc.h */,
|
||||||
|
65643CAD1413322000A32F59 /* pios_rtc_priv.h */,
|
||||||
|
65643CAE1413322000A32F59 /* pios_sbus_priv.h */,
|
||||||
|
65643CAF1413322000A32F59 /* pios_sbus.h */,
|
||||||
65E8F04A11EFF25C00BBF654 /* pios_sdcard.h */,
|
65E8F04A11EFF25C00BBF654 /* pios_sdcard.h */,
|
||||||
65E8F04B11EFF25C00BBF654 /* pios_servo.h */,
|
65E8F04B11EFF25C00BBF654 /* pios_servo.h */,
|
||||||
65FBE14412E7C98100176B5A /* pios_servo_priv.h */,
|
65FBE14412E7C98100176B5A /* pios_servo_priv.h */,
|
||||||
65E8F04C11EFF25C00BBF654 /* pios_spektrum.h */,
|
65E8F04C11EFF25C00BBF654 /* pios_spektrum.h */,
|
||||||
|
65643CB01413322000A32F59 /* pios_spektrum_priv.h */,
|
||||||
65E8F04D11EFF25C00BBF654 /* pios_spi.h */,
|
65E8F04D11EFF25C00BBF654 /* pios_spi.h */,
|
||||||
65E8F04E11EFF25C00BBF654 /* pios_spi_priv.h */,
|
65E8F04E11EFF25C00BBF654 /* pios_spi_priv.h */,
|
||||||
65E8F04F11EFF25C00BBF654 /* pios_stm32.h */,
|
65E8F04F11EFF25C00BBF654 /* pios_stm32.h */,
|
||||||
@ -7766,10 +7780,12 @@
|
|||||||
65E8F0E411EFF25C00BBF654 /* pios_ppm.c */,
|
65E8F0E411EFF25C00BBF654 /* pios_ppm.c */,
|
||||||
65E8F0E511EFF25C00BBF654 /* pios_pwm.c */,
|
65E8F0E511EFF25C00BBF654 /* pios_pwm.c */,
|
||||||
6589A9DB131DEE76006BD67C /* pios_rtc.c */,
|
6589A9DB131DEE76006BD67C /* pios_rtc.c */,
|
||||||
|
65643CBA141350C200A32F59 /* pios_sbus.c */,
|
||||||
65E8F0E611EFF25C00BBF654 /* pios_servo.c */,
|
65E8F0E611EFF25C00BBF654 /* pios_servo.c */,
|
||||||
65E8F0E711EFF25C00BBF654 /* pios_spektrum.c */,
|
65E8F0E711EFF25C00BBF654 /* pios_spektrum.c */,
|
||||||
65E8F0E811EFF25C00BBF654 /* pios_spi.c */,
|
65E8F0E811EFF25C00BBF654 /* pios_spi.c */,
|
||||||
65E8F0E911EFF25C00BBF654 /* pios_sys.c */,
|
65E8F0E911EFF25C00BBF654 /* pios_sys.c */,
|
||||||
|
65643CB91413456D00A32F59 /* pios_tim.c */,
|
||||||
65E8F0EA11EFF25C00BBF654 /* pios_usart.c */,
|
65E8F0EA11EFF25C00BBF654 /* pios_usart.c */,
|
||||||
65E8F0ED11EFF25C00BBF654 /* pios_usb_hid.c */,
|
65E8F0ED11EFF25C00BBF654 /* pios_usb_hid.c */,
|
||||||
651CF9E5120B5D8300EEFD70 /* pios_usb_hid_desc.c */,
|
651CF9E5120B5D8300EEFD70 /* pios_usb_hid_desc.c */,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user