aboutsummaryrefslogtreecommitdiff
path: root/embassy-boot/nrf/src
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2023-08-02 22:57:42 +0200
committerUlf Lilleengen <[email protected]>2023-08-02 22:57:42 +0200
commitbcaef1de189732f1744804cd7c9c038fe79f0be9 (patch)
treedf81798e58cc599bb0a13399328da27e987e636c /embassy-boot/nrf/src
parent0d8a9b1e7a963fe1a1a3cf0e10c33314bba65e2d (diff)
feat: make nrf bootloader watchdog generic for any flash
Diffstat (limited to 'embassy-boot/nrf/src')
-rw-r--r--embassy-boot/nrf/src/lib.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/embassy-boot/nrf/src/lib.rs b/embassy-boot/nrf/src/lib.rs
index bb702073c..65f57fcd1 100644
--- a/embassy-boot/nrf/src/lib.rs
+++ b/embassy-boot/nrf/src/lib.rs
@@ -6,7 +6,7 @@ mod fmt;
6#[cfg(feature = "nightly")] 6#[cfg(feature = "nightly")]
7pub use embassy_boot::FirmwareUpdater; 7pub use embassy_boot::FirmwareUpdater;
8pub use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater, BootLoaderConfig, FirmwareUpdaterConfig}; 8pub use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater, BootLoaderConfig, FirmwareUpdaterConfig};
9use embassy_nrf::nvmc::{Nvmc, PAGE_SIZE}; 9use embassy_nrf::nvmc::PAGE_SIZE;
10use embassy_nrf::peripherals::WDT; 10use embassy_nrf::peripherals::WDT;
11use embassy_nrf::wdt; 11use embassy_nrf::wdt;
12use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash}; 12use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash};
@@ -104,15 +104,15 @@ impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>
104 } 104 }
105} 105}
106 106
107/// A flash implementation that wraps NVMC and will pet a watchdog when touching flash. 107/// A flash implementation that wraps any flash and will pet a watchdog when touching flash.
108pub struct WatchdogFlash<'d> { 108pub struct WatchdogFlash<FLASH> {
109 flash: Nvmc<'d>, 109 flash: FLASH,
110 wdt: wdt::WatchdogHandle, 110 wdt: wdt::WatchdogHandle,
111} 111}
112 112
113impl<'d> WatchdogFlash<'d> { 113impl<FLASH> WatchdogFlash<FLASH> {
114 /// Start a new watchdog with a given flash and WDT peripheral and a timeout 114 /// Start a new watchdog with a given flash and WDT peripheral and a timeout
115 pub fn start(flash: Nvmc<'d>, wdt: WDT, config: wdt::Config) -> Self { 115 pub fn start(flash: FLASH, wdt: WDT, config: wdt::Config) -> Self {
116 let (_wdt, [wdt]) = match wdt::Watchdog::try_new(wdt, config) { 116 let (_wdt, [wdt]) = match wdt::Watchdog::try_new(wdt, config) {
117 Ok(x) => x, 117 Ok(x) => x,
118 Err(_) => { 118 Err(_) => {
@@ -127,13 +127,13 @@ impl<'d> WatchdogFlash<'d> {
127 } 127 }
128} 128}
129 129
130impl<'d> ErrorType for WatchdogFlash<'d> { 130impl<FLASH: ErrorType> ErrorType for WatchdogFlash<FLASH> {
131 type Error = <Nvmc<'d> as ErrorType>::Error; 131 type Error = FLASH::Error;
132} 132}
133 133
134impl<'d> NorFlash for WatchdogFlash<'d> { 134impl<FLASH: NorFlash> NorFlash for WatchdogFlash<FLASH> {
135 const WRITE_SIZE: usize = <Nvmc<'d> as NorFlash>::WRITE_SIZE; 135 const WRITE_SIZE: usize = FLASH::WRITE_SIZE;
136 const ERASE_SIZE: usize = <Nvmc<'d> as NorFlash>::ERASE_SIZE; 136 const ERASE_SIZE: usize = FLASH::ERASE_SIZE;
137 137
138 fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { 138 fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> {
139 self.wdt.pet(); 139 self.wdt.pet();
@@ -145,8 +145,8 @@ impl<'d> NorFlash for WatchdogFlash<'d> {
145 } 145 }
146} 146}
147 147
148impl<'d> ReadNorFlash for WatchdogFlash<'d> { 148impl<FLASH: ReadNorFlash> ReadNorFlash for WatchdogFlash<FLASH> {
149 const READ_SIZE: usize = <Nvmc<'d> as ReadNorFlash>::READ_SIZE; 149 const READ_SIZE: usize = FLASH::READ_SIZE;
150 fn read(&mut self, offset: u32, data: &mut [u8]) -> Result<(), Self::Error> { 150 fn read(&mut self, offset: u32, data: &mut [u8]) -> Result<(), Self::Error> {
151 self.wdt.pet(); 151 self.wdt.pet();
152 self.flash.read(offset, data) 152 self.flash.read(offset, data)