From edc316d545895f1e17b88856b0e1a2211ca313c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Alse=CC=81r?= <> Date: Tue, 30 Jun 2020 23:19:05 +0200 Subject: [PATCH] Compile time assert FORCE_COPY_BUFFER_SIZE <= EASY_DMA_SIZE --- nrf-hal-common/src/lib.rs | 4 ++++ nrf-hal-common/src/twim.rs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/nrf-hal-common/src/lib.rs b/nrf-hal-common/src/lib.rs index 0ad651b1..eda3fbbd 100644 --- a/nrf-hal-common/src/lib.rs +++ b/nrf-hal-common/src/lib.rs @@ -70,6 +70,8 @@ pub mod target_constants { pub const SRAM_LOWER: usize = 0x2000_0000; pub const SRAM_UPPER: usize = 0x3000_0000; pub const FORCE_COPY_BUFFER_SIZE: usize = 255; + const _CHECK_FORCE_COPY_BUFFER_SIZE: usize = EASY_DMA_SIZE - FORCE_COPY_BUFFER_SIZE; + // ERROR: FORCE_COPY_BUFFER_SIZE must be <= EASY_DMA_SIZE } #[cfg(any(feature = "52840", feature = "52833", feature = "9160"))] pub mod target_constants { @@ -79,6 +81,8 @@ pub mod target_constants { pub const SRAM_LOWER: usize = 0x2000_0000; pub const SRAM_UPPER: usize = 0x3000_0000; pub const FORCE_COPY_BUFFER_SIZE: usize = 1024; + const _CHECK_FORCE_COPY_BUFFER_SIZE: usize = EASY_DMA_SIZE - FORCE_COPY_BUFFER_SIZE; + // ERROR: FORCE_COPY_BUFFER_SIZE must be <= EASY_DMA_SIZE } /// Does this slice reside entirely within RAM? diff --git a/nrf-hal-common/src/twim.rs b/nrf-hal-common/src/twim.rs index 7f2ba5ad..7497b351 100644 --- a/nrf-hal-common/src/twim.rs +++ b/nrf-hal-common/src/twim.rs @@ -381,7 +381,7 @@ where // Chunk write data let wr_buffer = &mut [0; FORCE_COPY_BUFFER_SIZE][..]; - for chunk in tx_buffer.chunks(FORCE_COPY_BUFFER_SIZE.min(EASY_DMA_SIZE)) { + for chunk in tx_buffer.chunks(FORCE_COPY_BUFFER_SIZE) { // Copy chunk into RAM wr_buffer[..chunk.len()].copy_from_slice(chunk);