From 79061021f98ee01611e565a9edf89aa0dbf91bf6 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 9 Mar 2023 23:32:00 +0100 Subject: [PATCH] time: add power-of-2 kHz tick rates. Fixes #1269 --- embassy-time/Cargo.toml | 19 ++++++++++++++ embassy-time/gen_tick.py | 12 ++++++--- embassy-time/src/tick.rs | 57 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 4 deletions(-) diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml index 5701ab35..5b14814a 100644 --- a/embassy-time/Cargo.toml +++ b/embassy-time/Cargo.toml @@ -101,6 +101,25 @@ tick-hz-2_097_152 = [] tick-hz-4_194_304 = [] tick-hz-8_388_608 = [] tick-hz-16_777_216 = [] +tick-hz-2_000 = [] +tick-hz-4_000 = [] +tick-hz-8_000 = [] +tick-hz-16_000 = [] +tick-hz-32_000 = [] +tick-hz-64_000 = [] +tick-hz-128_000 = [] +tick-hz-256_000 = [] +tick-hz-512_000 = [] +tick-hz-1_024_000 = [] +tick-hz-2_048_000 = [] +tick-hz-4_096_000 = [] +tick-hz-8_192_000 = [] +tick-hz-16_384_000 = [] +tick-hz-32_768_000 = [] +tick-hz-65_536_000 = [] +tick-hz-131_072_000 = [] +tick-hz-262_144_000 = [] +tick-hz-524_288_000 = [] tick-hz-2_000_000 = [] tick-hz-3_000_000 = [] tick-hz-4_000_000 = [] diff --git a/embassy-time/gen_tick.py b/embassy-time/gen_tick.py index 651ebbd7..15e65187 100644 --- a/embassy-time/gen_tick.py +++ b/embassy-time/gen_tick.py @@ -11,6 +11,8 @@ for i in range(10): ticks.append(10**i) for i in range(1, 25): ticks.append(2**i) +for i in range(1, 20): + ticks.append(2**i * 1000) for i in range(1, 10): ticks.append(2**i * 1000000) ticks.append(2**i * 9 // 8 * 1000000) @@ -30,21 +32,23 @@ with open('Cargo.toml', 'r') as f: data = f.read() before, data = data.split(SEPARATOR_START, maxsplit=1) _, after = data.split(SEPARATOR_END, maxsplit=1) -data = before + SEPARATOR_START + HELP + toml.dumps(things) + SEPARATOR_END + after +data = before + SEPARATOR_START + HELP + \ + toml.dumps(things) + SEPARATOR_END + after with open('Cargo.toml', 'w') as f: f.write(data) # ========= Update src/tick.rs with open('src/tick.rs', 'w') as f: - + f.write('// Generated by gen_tick.py. DO NOT EDIT.\n\n') for hz in ticks: - f.write(f'#[cfg(feature = "tick-hz-{hz:_}")] pub const TICK_HZ: u64 = {hz:_};\n') + f.write( + f'#[cfg(feature = "tick-hz-{hz:_}")] pub const TICK_HZ: u64 = {hz:_};\n') f.write('#[cfg(not(any(\n') for hz in ticks: f.write(f'feature = "tick-hz-{hz:_}",\n') f.write(')))] pub const TICK_HZ: u64 = 1_000_000;') -os.system('rustfmt src/tick.rs') \ No newline at end of file +os.system('rustfmt src/tick.rs') diff --git a/embassy-time/src/tick.rs b/embassy-time/src/tick.rs index a7900650..608bc44f 100644 --- a/embassy-time/src/tick.rs +++ b/embassy-time/src/tick.rs @@ -68,6 +68,44 @@ pub const TICK_HZ: u64 = 4_194_304; pub const TICK_HZ: u64 = 8_388_608; #[cfg(feature = "tick-hz-16_777_216")] pub const TICK_HZ: u64 = 16_777_216; +#[cfg(feature = "tick-hz-2_000")] +pub const TICK_HZ: u64 = 2_000; +#[cfg(feature = "tick-hz-4_000")] +pub const TICK_HZ: u64 = 4_000; +#[cfg(feature = "tick-hz-8_000")] +pub const TICK_HZ: u64 = 8_000; +#[cfg(feature = "tick-hz-16_000")] +pub const TICK_HZ: u64 = 16_000; +#[cfg(feature = "tick-hz-32_000")] +pub const TICK_HZ: u64 = 32_000; +#[cfg(feature = "tick-hz-64_000")] +pub const TICK_HZ: u64 = 64_000; +#[cfg(feature = "tick-hz-128_000")] +pub const TICK_HZ: u64 = 128_000; +#[cfg(feature = "tick-hz-256_000")] +pub const TICK_HZ: u64 = 256_000; +#[cfg(feature = "tick-hz-512_000")] +pub const TICK_HZ: u64 = 512_000; +#[cfg(feature = "tick-hz-1_024_000")] +pub const TICK_HZ: u64 = 1_024_000; +#[cfg(feature = "tick-hz-2_048_000")] +pub const TICK_HZ: u64 = 2_048_000; +#[cfg(feature = "tick-hz-4_096_000")] +pub const TICK_HZ: u64 = 4_096_000; +#[cfg(feature = "tick-hz-8_192_000")] +pub const TICK_HZ: u64 = 8_192_000; +#[cfg(feature = "tick-hz-16_384_000")] +pub const TICK_HZ: u64 = 16_384_000; +#[cfg(feature = "tick-hz-32_768_000")] +pub const TICK_HZ: u64 = 32_768_000; +#[cfg(feature = "tick-hz-65_536_000")] +pub const TICK_HZ: u64 = 65_536_000; +#[cfg(feature = "tick-hz-131_072_000")] +pub const TICK_HZ: u64 = 131_072_000; +#[cfg(feature = "tick-hz-262_144_000")] +pub const TICK_HZ: u64 = 262_144_000; +#[cfg(feature = "tick-hz-524_288_000")] +pub const TICK_HZ: u64 = 524_288_000; #[cfg(feature = "tick-hz-2_000_000")] pub const TICK_HZ: u64 = 2_000_000; #[cfg(feature = "tick-hz-3_000_000")] @@ -153,6 +191,25 @@ pub const TICK_HZ: u64 = 768_000_000; feature = "tick-hz-4_194_304", feature = "tick-hz-8_388_608", feature = "tick-hz-16_777_216", + feature = "tick-hz-2_000", + feature = "tick-hz-4_000", + feature = "tick-hz-8_000", + feature = "tick-hz-16_000", + feature = "tick-hz-32_000", + feature = "tick-hz-64_000", + feature = "tick-hz-128_000", + feature = "tick-hz-256_000", + feature = "tick-hz-512_000", + feature = "tick-hz-1_024_000", + feature = "tick-hz-2_048_000", + feature = "tick-hz-4_096_000", + feature = "tick-hz-8_192_000", + feature = "tick-hz-16_384_000", + feature = "tick-hz-32_768_000", + feature = "tick-hz-65_536_000", + feature = "tick-hz-131_072_000", + feature = "tick-hz-262_144_000", + feature = "tick-hz-524_288_000", feature = "tick-hz-2_000_000", feature = "tick-hz-3_000_000", feature = "tick-hz-4_000_000",