Skip to content

Commit

Permalink
Compile time assert FORCE_COPY_BUFFER_SIZE <= EASY_DMA_SIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrik Alsér committed Jun 30, 2020
1 parent 45d9201 commit edc316d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions nrf-hal-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion nrf-hal-common/src/twim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit edc316d

Please sign in to comment.