Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of application access to the PX4IO relays. #123

Merged
merged 1 commit into from
Jan 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/drivers/drv_pwm_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ORB_DECLARE(output_pwm);
* Note that ioctls and ObjDev updates should not be mixed, as the
* behaviour of the system in this case is not defined.
*/
#define _PWM_SERVO_BASE 0x2700
#define _PWM_SERVO_BASE 0x2a00

/** arm all servo outputs handle by this driver */
#define PWM_SERVO_ARM _IOC(_PWM_SERVO_BASE, 0)
Expand Down
32 changes: 31 additions & 1 deletion apps/drivers/px4io/px4io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include <drivers/device/device.h>
#include <drivers/drv_rc_input.h>
#include <drivers/drv_pwm_output.h>
#include <drivers/drv_gpio.h>
#include <drivers/drv_hrt.h>
#include <drivers/drv_mixer.h>

Expand Down Expand Up @@ -114,6 +115,8 @@ class PX4IO : public device::CDev

bool _primary_pwm_device; ///< true if we are the default PWM output

uint32_t _relays; ///< state of the PX4IO relays, one bit per relay

volatile bool _switch_armed; ///< PX4IO switch armed state
// XXX how should this work?

Expand Down Expand Up @@ -185,6 +188,7 @@ PX4IO::PX4IO() :
_t_outputs(-1),
_mixers(nullptr),
_primary_pwm_device(false),
_relays(0),
_switch_armed(false),
_send_needed(false),
_config_needed(false)
Expand Down Expand Up @@ -497,7 +501,9 @@ PX4IO::io_send()
/* publish as we send */
orb_publish(ORB_ID_VEHICLE_CONTROLS, _t_outputs, &_outputs);

// XXX relays
/* update relays */
for (unsigned i = 0; i < PX4IO_RELAY_CHANNELS; i++)
cmd.relay_state[i] = (_relays & (1<< i)) ? true : false;

/* armed and not locked down */
cmd.arm_ok = (_armed.armed && !_armed.lockdown);
Expand Down Expand Up @@ -559,6 +565,30 @@ PX4IO::ioctl(file *filep, int cmd, unsigned long arg)
*(servo_position_t *)arg = _outputs.output[cmd - PWM_SERVO_GET(0)];
break;

case GPIO_RESET:
_relays = 0;
_send_needed = true;
break;

case GPIO_SET:
case GPIO_CLEAR:
/* make sure only valid bits are being set */
if ((arg & ((1UL << PX4IO_RELAY_CHANNELS) - 1)) != arg) {
ret = EINVAL;
break;
}
if (cmd == GPIO_SET) {
_relays |= arg;
} else {
_relays &= ~arg;
}
_send_needed = true;
break;

case GPIO_GET:
*(uint32_t *)arg = _relays;
break;

case MIXERIOCGETOUTPUTCOUNT:
*(unsigned *)arg = _max_actuators;
break;
Expand Down
25 changes: 21 additions & 4 deletions apps/px4io/comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ comms_handle_command(const void *buffer, size_t length)
system_state.fmu_channel_data[i] = cmd->servo_command[i];

/* if the IO is armed and the FMU gets disarmed, the IO must also disarm */
if(system_state.arm_ok && !cmd->arm_ok) {
if (system_state.arm_ok && !cmd->arm_ok) {
system_state.armed = false;
}

Expand All @@ -191,9 +191,26 @@ comms_handle_command(const void *buffer, size_t length)
// if (!system_state.arm_ok && system_state.armed)
// system_state.armed = false;

/* XXX do relay changes here */
for (unsigned i = 0; i < PX4IO_RELAY_CHANNELS; i++)
system_state.relays[i] = cmd->relay_state[i];
/* handle relay state changes here */
for (unsigned i = 0; i < PX4IO_RELAY_CHANNELS; i++) {
if (system_state.relays[i] != cmd->relay_state[i]) {
switch (i) {
case 0:
POWER_ACC1(cmd->relay_state[i]);
break;
case 1:
POWER_ACC2(cmd->relay_state[i]);
break;
case 2:
POWER_RELAY1(cmd->relay_state[i]);
break;
case 3:
POWER_RELAY2(cmd->relay_state[i]);
break;
}
}
system_state.relays[i] != cmd->relay_state[i]
}

irqrestore(flags);
}
Expand Down