diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-02-10 22:47:17 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-02-10 23:03:16 +0100 |
| commit | 4c4e923e057cc376ae3ebc2c2f7a01ed4723d308 (patch) | |
| tree | 695f8780f7a3d71eece68991d869e5f7f191537e /embassy-nrf/src/qspi.rs | |
| parent | 023b0d5b2270f31aa69e54aa3d43416e16c33966 (diff) | |
nrf/qspi: do not panic when canceling futures.
Diffstat (limited to 'embassy-nrf/src/qspi.rs')
| -rw-r--r-- | embassy-nrf/src/qspi.rs | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index 07a970018..d434327fc 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs | |||
| @@ -6,7 +6,7 @@ use core::future::poll_fn; | |||
| 6 | use core::ptr; | 6 | use core::ptr; |
| 7 | use core::task::Poll; | 7 | use core::task::Poll; |
| 8 | 8 | ||
| 9 | use embassy_hal_common::drop::DropBomb; | 9 | use embassy_hal_common::drop::OnDrop; |
| 10 | use embassy_hal_common::{into_ref, PeripheralRef}; | 10 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 11 | 11 | ||
| 12 | use crate::gpio::{self, Pin as GpioPin}; | 12 | use crate::gpio::{self, Pin as GpioPin}; |
| @@ -190,7 +190,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { | |||
| 190 | // Enable it | 190 | // Enable it |
| 191 | r.enable.write(|w| w.enable().enabled()); | 191 | r.enable.write(|w| w.enable().enabled()); |
| 192 | 192 | ||
| 193 | let mut res = Self { | 193 | let res = Self { |
| 194 | dpm_enabled: config.deep_power_down.is_some(), | 194 | dpm_enabled: config.deep_power_down.is_some(), |
| 195 | irq, | 195 | irq, |
| 196 | }; | 196 | }; |
| @@ -200,7 +200,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { | |||
| 200 | 200 | ||
| 201 | r.tasks_activate.write(|w| w.tasks_activate().bit(true)); | 201 | r.tasks_activate.write(|w| w.tasks_activate().bit(true)); |
| 202 | 202 | ||
| 203 | res.blocking_wait_ready(); | 203 | Self::blocking_wait_ready(); |
| 204 | 204 | ||
| 205 | res | 205 | res |
| 206 | } | 206 | } |
| @@ -217,7 +217,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { | |||
| 217 | 217 | ||
| 218 | /// Do a custom QSPI instruction. | 218 | /// Do a custom QSPI instruction. |
| 219 | pub async fn custom_instruction(&mut self, opcode: u8, req: &[u8], resp: &mut [u8]) -> Result<(), Error> { | 219 | pub async fn custom_instruction(&mut self, opcode: u8, req: &[u8], resp: &mut [u8]) -> Result<(), Error> { |
| 220 | let bomb = DropBomb::new(); | 220 | let ondrop = OnDrop::new(Self::blocking_wait_ready); |
| 221 | 221 | ||
| 222 | let len = core::cmp::max(req.len(), resp.len()) as u8; | 222 | let len = core::cmp::max(req.len(), resp.len()) as u8; |
| 223 | self.custom_instruction_start(opcode, req, len)?; | 223 | self.custom_instruction_start(opcode, req, len)?; |
| @@ -226,7 +226,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { | |||
| 226 | 226 | ||
| 227 | self.custom_instruction_finish(resp)?; | 227 | self.custom_instruction_finish(resp)?; |
| 228 | 228 | ||
| 229 | bomb.defuse(); | 229 | ondrop.defuse(); |
| 230 | 230 | ||
| 231 | Ok(()) | 231 | Ok(()) |
| 232 | } | 232 | } |
| @@ -236,7 +236,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { | |||
| 236 | let len = core::cmp::max(req.len(), resp.len()) as u8; | 236 | let len = core::cmp::max(req.len(), resp.len()) as u8; |
| 237 | self.custom_instruction_start(opcode, req, len)?; | 237 | self.custom_instruction_start(opcode, req, len)?; |
| 238 | 238 | ||
| 239 | self.blocking_wait_ready(); | 239 | Self::blocking_wait_ready(); |
| 240 | 240 | ||
| 241 | self.custom_instruction_finish(resp)?; | 241 | self.custom_instruction_finish(resp)?; |
| 242 | 242 | ||
| @@ -312,7 +312,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { | |||
| 312 | .await | 312 | .await |
| 313 | } | 313 | } |
| 314 | 314 | ||
| 315 | fn blocking_wait_ready(&mut self) { | 315 | fn blocking_wait_ready() { |
| 316 | loop { | 316 | loop { |
| 317 | let r = T::regs(); | 317 | let r = T::regs(); |
| 318 | if r.events_ready.read().bits() != 0 { | 318 | if r.events_ready.read().bits() != 0 { |
| @@ -382,36 +382,36 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { | |||
| 382 | 382 | ||
| 383 | /// Read data from the flash memory. | 383 | /// Read data from the flash memory. |
| 384 | pub async fn read(&mut self, address: usize, data: &mut [u8]) -> Result<(), Error> { | 384 | pub async fn read(&mut self, address: usize, data: &mut [u8]) -> Result<(), Error> { |
| 385 | let bomb = DropBomb::new(); | 385 | let ondrop = OnDrop::new(Self::blocking_wait_ready); |
| 386 | 386 | ||
| 387 | self.start_read(address, data)?; | 387 | self.start_read(address, data)?; |
| 388 | self.wait_ready().await; | 388 | self.wait_ready().await; |
| 389 | 389 | ||
| 390 | bomb.defuse(); | 390 | ondrop.defuse(); |
| 391 | 391 | ||
| 392 | Ok(()) | 392 | Ok(()) |
| 393 | } | 393 | } |
| 394 | 394 | ||
| 395 | /// Write data to the flash memory. | 395 | /// Write data to the flash memory. |
| 396 | pub async fn write(&mut self, address: usize, data: &[u8]) -> Result<(), Error> { | 396 | pub async fn write(&mut self, address: usize, data: &[u8]) -> Result<(), Error> { |
| 397 | let bomb = DropBomb::new(); | 397 | let ondrop = OnDrop::new(Self::blocking_wait_ready); |
| 398 | 398 | ||
| 399 | self.start_write(address, data)?; | 399 | self.start_write(address, data)?; |
| 400 | self.wait_ready().await; | 400 | self.wait_ready().await; |
| 401 | 401 | ||
| 402 | bomb.defuse(); | 402 | ondrop.defuse(); |
| 403 | 403 | ||
| 404 | Ok(()) | 404 | Ok(()) |
| 405 | } | 405 | } |
| 406 | 406 | ||
| 407 | /// Erase a sector on the flash memory. | 407 | /// Erase a sector on the flash memory. |
| 408 | pub async fn erase(&mut self, address: usize) -> Result<(), Error> { | 408 | pub async fn erase(&mut self, address: usize) -> Result<(), Error> { |
| 409 | let bomb = DropBomb::new(); | 409 | let ondrop = OnDrop::new(Self::blocking_wait_ready); |
| 410 | 410 | ||
| 411 | self.start_erase(address)?; | 411 | self.start_erase(address)?; |
| 412 | self.wait_ready().await; | 412 | self.wait_ready().await; |
| 413 | 413 | ||
| 414 | bomb.defuse(); | 414 | ondrop.defuse(); |
| 415 | 415 | ||
| 416 | Ok(()) | 416 | Ok(()) |
| 417 | } | 417 | } |
| @@ -419,21 +419,21 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { | |||
| 419 | /// Read data from the flash memory, blocking version. | 419 | /// Read data from the flash memory, blocking version. |
| 420 | pub fn blocking_read(&mut self, address: usize, data: &mut [u8]) -> Result<(), Error> { | 420 | pub fn blocking_read(&mut self, address: usize, data: &mut [u8]) -> Result<(), Error> { |
| 421 | self.start_read(address, data)?; | 421 | self.start_read(address, data)?; |
| 422 | self.blocking_wait_ready(); | 422 | Self::blocking_wait_ready(); |
| 423 | Ok(()) | 423 | Ok(()) |
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | /// Write data to the flash memory, blocking version. | 426 | /// Write data to the flash memory, blocking version. |
| 427 | pub fn blocking_write(&mut self, address: usize, data: &[u8]) -> Result<(), Error> { | 427 | pub fn blocking_write(&mut self, address: usize, data: &[u8]) -> Result<(), Error> { |
| 428 | self.start_write(address, data)?; | 428 | self.start_write(address, data)?; |
| 429 | self.blocking_wait_ready(); | 429 | Self::blocking_wait_ready(); |
| 430 | Ok(()) | 430 | Ok(()) |
| 431 | } | 431 | } |
| 432 | 432 | ||
| 433 | /// Erase a sector on the flash memory, blocking version. | 433 | /// Erase a sector on the flash memory, blocking version. |
| 434 | pub fn blocking_erase(&mut self, address: usize) -> Result<(), Error> { | 434 | pub fn blocking_erase(&mut self, address: usize) -> Result<(), Error> { |
| 435 | self.start_erase(address)?; | 435 | self.start_erase(address)?; |
| 436 | self.blocking_wait_ready(); | 436 | Self::blocking_wait_ready(); |
| 437 | Ok(()) | 437 | Ok(()) |
| 438 | } | 438 | } |
| 439 | } | 439 | } |
