drivers/tone_alarm and tune_control small improvements/cleanup

- drivers/tone_alarm: move to ModuleBase and purge CDev (/dev/tone_alarm0)
 - drivers/tone_alarm: only run on tune_control publication (or scheduled note) rather than continuously
 - drivers/tone_alarm: use HRT to schedule tone stop (prevents potential disruption)
 - msg/tune_control: add tune_id numbering
 - systemcmds/tune_control: add "error" special case tune_id
 - move all tune_control publication to new uORB::PublicationQueued<>
 - start tone_alarm immediately after board defaults are loaded to fix potential startup issues
 - for SITL (or other boards with no TONE output) print common messages (startup, error, etc)
This commit is contained in:
Daniel Agar
2020-10-05 21:39:26 -04:00
committed by GitHub
parent c7072b61a3
commit 08bf71b73d
39 changed files with 429 additions and 577 deletions
@@ -44,6 +44,8 @@ class ScheduledWorkItem : public WorkItem
{
public:
bool Scheduled() { return !hrt_called(&_call); }
/**
* Schedule next run with a delay in microseconds.
*
@@ -59,6 +61,13 @@ public:
*/
void ScheduleOnInterval(uint32_t interval_us, uint32_t delay_us = 0);
/**
* Schedule next run at a specific time.
*
* @param time_us The time in microseconds.
*/
void ScheduleAt(hrt_abstime time_us);
/**
* Clear any scheduled work.
*/
@@ -57,6 +57,11 @@ void ScheduledWorkItem::ScheduleOnInterval(uint32_t interval_us, uint32_t delay_
hrt_call_every(&_call, delay_us, interval_us, (hrt_callout)&ScheduledWorkItem::schedule_trampoline, this);
}
void ScheduledWorkItem::ScheduleAt(hrt_abstime time_us)
{
hrt_call_at(&_call, time_us, (hrt_callout)&ScheduledWorkItem::schedule_trampoline, this);
}
void ScheduledWorkItem::ScheduleClear()
{
// first clear any scheduled hrt call, then remove the item from the runnable queue
@@ -163,8 +163,9 @@ void init()
#endif /* TONE_ALARM_TIMER */
}
void start_note(unsigned frequency)
hrt_abstime start_note(unsigned frequency)
{
hrt_abstime time_started = 0;
#if defined(TONE_ALARM_TIMER)
float period = 0.5f / frequency;
@@ -182,8 +183,13 @@ void start_note(unsigned frequency)
rCR |= GPT_CR_EN;
// configure the GPIO to enable timer output
irqstate_t flags = enter_critical_section();
time_started = hrt_absolute_time();
px4_arch_configgpio(GPIO_TONE_ALARM);
leave_critical_section(flags);
#endif /* TONE_ALARM_TIMER */
return time_started;
}
void stop_note()
@@ -159,7 +159,7 @@ void init()
rMOD = 0; // Default the timer to a modulo value of 1; playing notes will change this.
}
void start_note(unsigned frequency)
hrt_abstime start_note(unsigned frequency)
{
// Calculate the signal switching period.
// (Signal switching period is one half of the frequency period).
@@ -173,7 +173,12 @@ void start_note(unsigned frequency)
rSC |= (TPM_SC_CMOD_LPTPM_CLK);
// Configure the GPIO to enable timer output.
irqstate_t flags = enter_critical_section();
const hrt_abstime time_started = hrt_absolute_time();
px4_arch_configgpio(GPIO_TONE_ALARM);
leave_critical_section(flags);
return time_started;
}
void stop_note()
@@ -159,7 +159,7 @@ void init()
rMOD = 0; // Default the timer to a modulo value of 1; playing notes will change this.
}
void start_note(unsigned frequency)
hrt_abstime start_note(unsigned frequency)
{
// Calculate the signal switching period.
// (Signal switching period is one half of the frequency period).
@@ -173,7 +173,12 @@ void start_note(unsigned frequency)
rSC |= (TPM_SC_CMOD_LPTPM_CLK);
// Configure the GPIO to enable timer output.
irqstate_t flags = enter_critical_section();
hrt_abstime time_started = hrt_absolute_time();
px4_arch_configgpio(GPIO_TONE_ALARM);
leave_critical_section(flags);
return time_started;
}
void stop_note()
@@ -44,9 +44,10 @@ void init()
px4_arch_configgpio(GPIO_TONE_ALARM_IDLE);
}
void start_note(unsigned frequency)
hrt_abstime start_note(unsigned frequency)
{
px4_arch_gpiowrite(GPIO_TONE_ALARM_GPIO, 1);
return hrt_absolute_time();
}
void stop_note()
@@ -299,7 +299,7 @@ void init()
rCR1 = GTIM_CR1_CEN; // Ensure the timer is running.
}
void start_note(unsigned frequency)
hrt_abstime start_note(unsigned frequency)
{
// Calculate the signal switching period.
// (Signal switching period is one half of the frequency period).
@@ -321,7 +321,12 @@ void start_note(unsigned frequency)
rCCER |= TONE_CCER; // Enable the output.
// Configure the GPIO to enable timer output.
hrt_abstime time_started = hrt_absolute_time();
irqstate_t flags = enter_critical_section();
px4_arch_configgpio(GPIO_TONE_ALARM);
leave_critical_section(flags);
return time_started;
}
void stop_note()
@@ -46,9 +46,10 @@ void init()
// Nothing to be done in simulation.
}
void start_note(unsigned frequency)
hrt_abstime start_note(unsigned frequency)
{
// Nothing to be done in simulation.
return 0;
}
void stop_note()