-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for buffered uart #314
Open
huseinmsft
wants to merge
1
commit into
OpenDevicePartnership:main
Choose a base branch
from
huseinmsft:buffered_uart
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,24 +124,6 @@ impl<'d> Channel<'d> { | |
let xfercount = (mem_len / xferwidth) - 1; | ||
let channel = self.info.ch_num; | ||
|
||
// Configure the channel descriptor | ||
// NOTE: the DMA controller expects the memory buffer end address but peripheral address is actual | ||
// SAFETY: unsafe due to use of a mutable static (DESCRIPTORS.list) | ||
unsafe { | ||
DESCRIPTORS.list[channel].reserved = 0; | ||
if dir == Direction::MemoryToPeripheral { | ||
DESCRIPTORS.list[channel].dst_data_end_addr = dstbase as u32; | ||
} else { | ||
DESCRIPTORS.list[channel].dst_data_end_addr = dstbase as u32 + (xfercount * xferwidth) as u32; | ||
} | ||
if dir == Direction::PeripheralToMemory { | ||
DESCRIPTORS.list[channel].src_data_end_addr = srcbase as u32; | ||
} else { | ||
DESCRIPTORS.list[channel].src_data_end_addr = srcbase as u32 + (xfercount * xferwidth) as u32; | ||
} | ||
DESCRIPTORS.list[channel].nxt_desc_link_addr = 0; | ||
} | ||
|
||
// Configure for transfer type, no hardware triggering (we'll trigger via software), high priority | ||
// SAFETY: unsafe due to .bits usage | ||
self.info.regs.channel(channel).cfg().write(|w| unsafe { | ||
|
@@ -164,8 +146,19 @@ impl<'d> Channel<'d> { | |
// SAFETY: unsafe due to .bits usage | ||
self.info.regs.channel(channel).xfercfg().write(|w| unsafe { | ||
w.cfgvalid().set_bit(); | ||
w.clrtrig().set_bit(); | ||
w.reload().clear_bit(); | ||
|
||
if options.is_continuous { | ||
w.reload().enabled(); | ||
w.clrtrig().clear_bit(); | ||
} else { | ||
w.reload().disabled(); | ||
w.clrtrig().set_bit(); | ||
} | ||
if options.is_sw_trig { | ||
w.swtrig().set_bit(); | ||
} else { | ||
w.swtrig().clear_bit(); | ||
} | ||
Comment on lines
+150
to
+161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about using w.reload().variant(options.is_continuous).
clrtrig().variant(!options.is_continuous).
swtrig().variant(options.is_sw_trig) |
||
w.setinta().set_bit(); | ||
w.width().bits(options.width.into()); | ||
if dir == Direction::PeripheralToMemory { | ||
|
@@ -180,6 +173,35 @@ impl<'d> Channel<'d> { | |
} | ||
w.xfercount().bits(xfercount as u16) | ||
}); | ||
|
||
// Configure the channel descriptor | ||
// NOTE: the DMA controller expects the memory buffer end address but peripheral address is actual | ||
// SAFETY: unsafe due to use of a mutable static (DESCRIPTORS.list) | ||
unsafe { | ||
if options.is_continuous { | ||
let xfer_cfg = self.info.regs.channel(channel).xfercfg().read(); | ||
DESCRIPTORS.list[channel].reserved_reloadcfg = xfer_cfg.bits(); | ||
} else { | ||
DESCRIPTORS.list[channel].reserved_reloadcfg = 0; | ||
} | ||
|
||
if dir == Direction::MemoryToPeripheral { | ||
DESCRIPTORS.list[channel].dst_data_end_addr = dstbase as u32; | ||
} else { | ||
DESCRIPTORS.list[channel].dst_data_end_addr = dstbase as u32 + (xfercount * xferwidth) as u32; | ||
} | ||
|
||
if dir == Direction::PeripheralToMemory { | ||
DESCRIPTORS.list[channel].src_data_end_addr = srcbase as u32; | ||
} else { | ||
DESCRIPTORS.list[channel].src_data_end_addr = srcbase as u32 + (xfercount * xferwidth) as u32; | ||
} | ||
if options.is_continuous { | ||
DESCRIPTORS.list[channel].nxt_desc_link_addr = &DESCRIPTORS.list[channel] as *const _ as u32; | ||
} else { | ||
DESCRIPTORS.list[channel].nxt_desc_link_addr = 0; | ||
} | ||
} | ||
} | ||
|
||
/// Enable the DMA channel (only after configuring) | ||
|
@@ -192,6 +214,40 @@ impl<'d> Channel<'d> { | |
.modify(|_, w| unsafe { w.ena().bits(1 << channel) }); | ||
} | ||
|
||
#[cfg(feature = "defmt")] | ||
/// Log the DMA channel transfer configuration | ||
pub fn log_channel(&self) { | ||
// Log DMA Channel Config Register | ||
let channel = self.info.ch_num; | ||
let dma_channel_cfg = self.info.regs.channel(channel).cfg().read(); | ||
defmt::info!( | ||
"DMA Channel {} Config Register: 0x{=u32:x}", | ||
channel, | ||
dma_channel_cfg.bits() | ||
); | ||
// Log Interrupt Enable Set Register | ||
let intenset0 = self.info.regs.intenset0().read(); | ||
defmt::info!("Interrupt Enable Set Register: 0x{=u32:x}", intenset0.bits()); | ||
|
||
// Log DMA Xfer Config Register | ||
let xfer_cfg = self.info.regs.channel(channel).xfercfg().read(); | ||
defmt::info!( | ||
"DMA Channel {} Xfer Config Register: 0x{=u32:x}", | ||
channel, | ||
xfer_cfg.bits() | ||
); | ||
// Log DMA Enable Set Register after enabling | ||
let enableset0 = self.info.regs.enableset0().read(); | ||
defmt::info!("DMA Enable Set Register:0x{=u32:x}", enableset0.bits()); | ||
// Log DMA Xfer Config Register after triggering | ||
let xfer_cfg_after = self.info.regs.channel(channel).xfercfg().read(); | ||
defmt::info!( | ||
"DMA Channel {} Xfer Config Register (After Trigger): 0x{=u32:x}", | ||
channel, | ||
xfer_cfg_after.bits() | ||
); | ||
} | ||
|
||
/// Disable the DMA channel | ||
pub fn disable_channel(&self) { | ||
let channel = self.info.ch_num; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,21 @@ pub struct TransferOptions { | |
|
||
/// Transfer priority level | ||
pub priority: Priority, | ||
|
||
/// Transfer is intended to be done continuously, such as for a circular buffer | ||
pub is_continuous: bool, | ||
|
||
/// Transfer is software triggerred | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: typo, triggered* |
||
pub is_sw_trig: bool, | ||
} | ||
|
||
impl Default for TransferOptions { | ||
fn default() -> Self { | ||
Self { | ||
width: Width::Bit8, | ||
priority: Priority::Priority0, | ||
is_continuous: false, | ||
is_sw_trig: false, | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be part of its own commit. Why is this needed?