Compare commits
11 Commits
33b87af4ee
...
ac601d06cc
Author | SHA1 | Date | |
---|---|---|---|
ac601d06cc | |||
daa181d1de | |||
46937f5bf9 | |||
1b313d21c4 | |||
1cc8645781 | |||
d7b01c12a4 | |||
e8a18548b0 | |||
ac015d1473 | |||
c53702ee74 | |||
bc0b18ab7c | |||
78b4bbcd49 |
@ -3,7 +3,7 @@
|
||||
Vorago VA416xx Rust Support
|
||||
=========
|
||||
|
||||
This crate collection provides support to write Rust applications for the VA416XX family
|
||||
This crate collection provided support to write Rust applications for the VA416XX family
|
||||
of devices.
|
||||
|
||||
## List of crates
|
||||
|
@ -25,8 +25,7 @@ static DMA_ACTIVE_FLAG: Mutex<Cell<bool>> = Mutex::new(Cell::new(false));
|
||||
#[link_section = ".sram1"]
|
||||
static mut DMA_CTRL_BLOCK: DmaCtrlBlock = DmaCtrlBlock::new();
|
||||
|
||||
// We can use statically allocated buffers for DMA transfers as well, and we can also place
|
||||
// those into SRAM1.
|
||||
// We can use statically allocated buffers for DMA transfers as well.
|
||||
#[link_section = ".sram1"]
|
||||
static mut DMA_SRC_BUF: [u16; 36] = [0; 36];
|
||||
#[link_section = ".sram1"]
|
||||
@ -136,11 +135,10 @@ fn transfer_example_8_bit(
|
||||
}
|
||||
|
||||
fn transfer_example_16_bit(dma0: &mut DmaChannel, delay_ms: &mut CountdownTimer<pac::Tim0>) {
|
||||
let dest_buf_ref = unsafe { &mut *core::ptr::addr_of_mut!(DMA_DEST_BUF[0..33]) };
|
||||
unsafe {
|
||||
// Set values scaled from 0 to 65535 to verify this is really a 16-bit transfer.
|
||||
(0..32).for_each(|i| {
|
||||
DMA_SRC_BUF[i] = (i as u32 * u16::MAX as u32 / (dest_buf_ref.len() as u32 - 1)) as u16;
|
||||
DMA_SRC_BUF[i] = (i as u32 * u16::MAX as u32 / (DMA_SRC_BUF.len() - 1) as u32) as u16;
|
||||
});
|
||||
}
|
||||
cortex_m::interrupt::free(|cs| {
|
||||
@ -149,11 +147,12 @@ fn transfer_example_16_bit(dma0: &mut DmaChannel, delay_ms: &mut CountdownTimer<
|
||||
cortex_m::interrupt::free(|cs| {
|
||||
DMA_ACTIVE_FLAG.borrow(cs).set(false);
|
||||
});
|
||||
let dest_buf_ref = unsafe { &mut *core::ptr::addr_of_mut!(DMA_DEST_BUF[0..32]) };
|
||||
// Safety: The source and destination buffer are valid for the duration of the DMA transfer.
|
||||
unsafe {
|
||||
dma0.prepare_mem_to_mem_transfer_16_bit(
|
||||
&*core::ptr::addr_of!(DMA_SRC_BUF[0..32]),
|
||||
&mut dest_buf_ref[0..32],
|
||||
dest_buf_ref,
|
||||
)
|
||||
.expect("error preparing transfer");
|
||||
}
|
||||
@ -188,7 +187,7 @@ fn transfer_example_16_bit(dma0: &mut DmaChannel, delay_ms: &mut CountdownTimer<
|
||||
(0..32).for_each(|i| {
|
||||
assert_eq!(
|
||||
dest_buf_ref[i],
|
||||
(i as u32 * u16::MAX as u32 / (dest_buf_ref.len() as u32 - 1)) as u16
|
||||
(i as u32 * u16::MAX as u32 / (dest_buf_ref.len() - 1) as u32) as u16
|
||||
);
|
||||
});
|
||||
// Sentinel value, should be 0.
|
||||
|
Loading…
x
Reference in New Issue
Block a user