Skip to content
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

Various bug fixes (rebased) #5

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ license = "MIT"
maintenance = { status = "actively-developed" }

[dependencies]
bitflags = "1.2.1"
cortex-m = "0.6.2"
bitflags = "1.3.2"
cortex-m = "0.7.1"
smart-default = "0.6.0"
paste = "0.1.18"
typenum = { version = "1.12", features = ["no_std"] }
paste = "1.0.6"
typenum = { version = "1.14.0", features = ["no_std"] }

[dependencies.atsamd51j]
version = "0.8.0"
version = "0.11.0"
optional = true

[dependencies.atsamd51g]
version = "0.8.0"
version = "0.11.0"
optional = true

[dependencies.atsamd21g]
version = "0.8.0"
version = "0.11.0"
optional = true

[dependencies.atsamd21e]
version = "0.8.0"
version = "0.11.0"
optional = true

[dependencies.atsamd21j]
version = "0.8.0"
version = "0.11.0"
optional = true

[features]
Expand Down
10 changes: 6 additions & 4 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub struct Channel {
write_back: *mut TransferDescriptor,
}

unsafe impl Send for Channel {}

impl Channel {
pub(crate) fn new(id: u8, first_desc: *mut TransferDescriptor,
write_back: *mut TransferDescriptor) -> Channel
Expand Down Expand Up @@ -184,9 +186,9 @@ impl Channel {
Interrupts::from_bits_truncate(channel_reg!(chintflag, self.id).read().bits())
}

/// Reset the channel's interrupt flags.
pub fn clear_interrupt_flags(&mut self) {
channel_reg!(chintflag, self.id).reset();
/// Reset the specified interrupt flags for the channel.
pub fn clear_interrupt_flags(&mut self, flags: Interrupts) {
channel_reg!(chintflag, self.id).write(|w| unsafe { w.bits(flags.bits()) });
}

/// Enable interrupts for the channel. Any interrupts that are not set will be disabled.
Expand Down Expand Up @@ -303,7 +305,7 @@ impl Channel {
pub fn poll_status(&mut self) -> Result<WaitResult, TransactionError> {
let intflag = self.get_interrupt_flags();
let status = channel_reg!(chstatus, self.id).read();
self.clear_interrupt_flags();
self.clear_interrupt_flags(Interrupts::all());

if channel_reg!(chctrla, self.id).read().enable().bit_is_set() {
if intflag.intersects(Interrupts::TERR) {
Expand Down
35 changes: 15 additions & 20 deletions src/descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
BlockAction,
EventOutput,
};
use core::ptr::NonNull;

bitflags! {
#[repr(transparent)]
Expand Down Expand Up @@ -32,11 +33,13 @@ bitflags! {
pub struct TransferDescriptor {
btctrl: RawBlockTransferCtrl,
btcnt: u16,
srcaddr: Option<*const ()>,
dstaddr: Option<*const ()>,
descaddr: Option<*mut TransferDescriptor>,
srcaddr: Option<NonNull<()>>,
dstaddr: Option<NonNull<()>>,
descaddr: Option<NonNull<TransferDescriptor>>,
}

unsafe impl Send for TransferDescriptor {}

impl TransferDescriptor {
/// Create a new empty descriptor.
pub const fn new() -> TransferDescriptor {
Expand All @@ -50,36 +53,28 @@ impl TransferDescriptor {
}

/// Get the type-erased source address.
pub fn get_src_addr(&self) -> Option<*const ()> {
pub fn get_src_addr(&self) -> Option<NonNull<()>> {
self.srcaddr
}

/// Get the type-erased destination address.
pub fn get_dst_addr(&self) -> Option<*const ()> {
pub fn get_dst_addr(&self) -> Option<NonNull<()>> {
self.dstaddr
}

/// Get address for the next linked descriptor.
pub fn get_next_desc_addr(&self) -> Option<*mut TransferDescriptor> {
pub fn get_next_desc_addr(&self) -> Option<NonNull<TransferDescriptor>> {
self.descaddr
}

/// Set the source address of the descriptor. This is a type erased pointer.
pub fn set_src_addr(&mut self, addr: *const ()) {
self.srcaddr = if addr.is_null() {
None
} else {
Some(addr)
};
pub fn set_src_addr(&mut self, addr: *mut ()) {
self.srcaddr = NonNull::new(addr)
}

/// Set the destination address of the descriptor. This is a type erased pointer.
pub fn set_dst_addr(&mut self, addr: *const ()) {
self.dstaddr = if addr.is_null() {
None
} else {
Some(addr)
};
pub fn set_dst_addr(&mut self, addr: *mut ()) {
self.dstaddr = NonNull::new(addr)
}

/// Mark the descriptor as valid.
Expand Down Expand Up @@ -203,11 +198,11 @@ impl TransferDescriptor {

/// Link a transfer descriptor to execute AFTER this descriptor.
pub fn link_descriptor(&mut self, next: &mut TransferDescriptor) {
self.descaddr = Some(next);
self.descaddr = Some(next.into());
}

/// Unlink the next transfer descriptor, returning its address (which maybe null).
pub fn unlink_descriptor(&mut self) -> Option<*mut TransferDescriptor> {
pub fn unlink_descriptor(&mut self) -> Option<NonNull<TransferDescriptor>> {
self.descaddr.take()
}
}
Loading