Skip to content

Commit

Permalink
sensor: remove noop 1 Hz timer
Browse files Browse the repository at this point in the history
task/sensor was configuring a timer to wake it every 1 Hz. Each time it
woke up, it would snooze its alarm clock and go back to sleep.

While I definitely sympathize with that desire, this is essentially dead
code that looks like a bug, so this commit removes it. I'm not sure what
the history here is.

In addition to removing noise from the code, this knocks 114 bytes off
the sensor task text size.
  • Loading branch information
cbiffle committed Apr 2, 2024
1 parent c361359 commit 36aaed8
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 21 deletions.
1 change: 0 additions & 1 deletion app/gimlet/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ priority = 4
max-sizes = {flash = 16384, ram = 8192 }
stacksize = 1024
start = true
notifications = ["timer"]

[tasks.host_sp_comms]
name = "task-host-sp-comms"
Expand Down
1 change: 0 additions & 1 deletion app/gimletlet/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ priority = 5
max-sizes = {flash = 16384, ram = 2048 }
stacksize = 1024
start = true
notifications = ["timer"]

[tasks.dump_agent]
name = "task-dump-agent"
Expand Down
1 change: 0 additions & 1 deletion app/psc/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ priority = 3
max-sizes = {flash = 16384, ram = 8192 }
stacksize = 1024
start = true
notifications = ["timer"]

[tasks.sensor_polling]
name = "task-sensor-polling"
Expand Down
1 change: 0 additions & 1 deletion app/sidecar/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ priority = 4
max-sizes = {flash = 16384, ram = 8192 }
stacksize = 1024
start = true
notifications = ["timer"]

[tasks.ecp5_mainboard]
name = "drv-fpga-server"
Expand Down
1 change: 0 additions & 1 deletion task/sensor/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
build_util::expose_target_board();
build_util::build_notifications()?;
idol::Generator::new()
.with_counters(
idol::CounterSettings::default().with_server_counters(false),
Expand Down
22 changes: 6 additions & 16 deletions task/sensor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ struct ServerImpl {
err_time: SensorArray<u64>,

nerrors: SensorArray<u32>,
deadline: u64,
}

const TIMER_INTERVAL: u64 = 1000;

impl idl::InOrderSensorImpl for ServerImpl {
fn get(
&mut self,
Expand Down Expand Up @@ -243,24 +240,20 @@ impl ServerImpl {

impl NotificationHandler for ServerImpl {
fn current_notification_mask(&self) -> u32 {
notifications::TIMER_MASK
// We don't use notifications, don't listen for any.
0
}

fn handle_notification(&mut self, _bits: u32) {
self.deadline = self.deadline.wrapping_add(TIMER_INTERVAL);
sys_set_timer(Some(self.deadline), notifications::TIMER_MASK);
unreachable!()
}
}

#[export_name = "main"]
fn main() -> ! {
let deadline = sys_get_timer().now;

//
// This will put our timer in the past, and should immediately kick us.
//
sys_set_timer(Some(deadline), notifications::TIMER_MASK);

// N.B. if you are staring at this macro thinking that it looks like it
// doesn't do anything and might be obsolescent, the key is the :upper. This
// macro exists exclusively to uppercase the field names below.
macro_rules! declare_server {
($($name:ident: $t:ty = $n:expr;)*) => {{
paste::paste! {
Expand All @@ -271,7 +264,6 @@ fn main() -> ! {
};
let ($($name),*) = ($(SensorArray($name)),*);
ServerImpl {
deadline,
$($name),*
}
}}
Expand Down Expand Up @@ -308,5 +300,3 @@ mod idl {

include!(concat!(env!("OUT_DIR"), "/server_stub.rs"));
}

include!(concat!(env!("OUT_DIR"), "/notifications.rs"));

0 comments on commit 36aaed8

Please sign in to comment.