Browse Source

IridiumSBD: Do not allow stopping the driver when the device is used to prevent hardfault

sbg
acfloria 7 years ago committed by Beat Küng
parent
commit
0e89a6b8bd
  1. 19
      src/drivers/telemetry/iridiumsbd/IridiumSBD.cpp
  2. 28
      src/drivers/telemetry/iridiumsbd/IridiumSBD.h

19
src/drivers/telemetry/iridiumsbd/IridiumSBD.cpp

@ -91,6 +91,11 @@ int IridiumSBD::stop() @@ -91,6 +91,11 @@ int IridiumSBD::stop()
return PX4_ERROR;
}
if (IridiumSBD::instance->cdev_used) {
PX4_WARN("device is used. Stop all users (MavLink)");
return PX4_ERROR;
}
PX4_WARN("stopping...");
IridiumSBD::instance->task_should_exit = true;
@ -922,6 +927,20 @@ void IridiumSBD::publish_telemetry_status() @@ -922,6 +927,20 @@ void IridiumSBD::publish_telemetry_status()
}
}
int IridiumSBD::open_first(struct file *filep)
{
cdev_used = true;
return CDev::open_first(filep);
}
int IridiumSBD::close_last(struct file *filep)
{
cdev_used = false;
return CDev::close_last(filep);
}
int iridiumsbd_main(int argc, char *argv[])
{
if (!strcmp(argv[1], "start")) {

28
src/drivers/telemetry/iridiumsbd/IridiumSBD.h

@ -261,6 +261,32 @@ private: @@ -261,6 +261,32 @@ private:
*/
void publish_telemetry_status(void);
/**
* Notification of the first open of CDev.
*
* This function is called when the device open count transitions from zero
* to one. The driver lock is held for the duration of the call.
*
* Notes that CDev is used and blocks stopping the driver.
*
* @param filep Pointer to the NuttX file structure.
* @return OK if the open should proceed, -errno otherwise.
*/
virtual int open_first(struct file *filep) override;
/**
* Notification of the last close of CDev.
*
* This function is called when the device open count transitions from
* one to zero. The driver lock is held for the duration of the call.
*
* Notes that CDev is not used anymore and allows stopping the driver.
*
* @param filep Pointer to the NuttX file structure.
* @return OK if the open should return OK, -errno otherwise.
*/
virtual int close_last(struct file *filep) override;
static IridiumSBD *instance;
static int task_handle;
bool task_should_exit = false;
@ -295,6 +321,8 @@ private: @@ -295,6 +321,8 @@ private:
bool rx_read_pending = false;
bool tx_session_pending = false;
bool cdev_used = false;
hrt_abstime last_write_time = 0;
hrt_abstime last_read_time = 0;
hrt_abstime last_heartbeat = 0;

Loading…
Cancel
Save