Compare commits
2 Commits
v0.5.1
...
0b4408cf8a
Author | SHA1 | Date | |
---|---|---|---|
0b4408cf8a | |||
b04159912f |
15
CHANGELOG.md
15
CHANGELOG.md
@@ -6,28 +6,13 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
## [v0.5.1]
|
|
||||||
|
|
||||||
### Changes
|
|
||||||
|
|
||||||
- Updated dependencies:
|
|
||||||
- `cortex-m-rtic` (dev-depencency) to 1.1.2
|
|
||||||
- `once_cell` to 1.12.0
|
|
||||||
- Other depencies: Only revision has changed
|
|
||||||
|
|
||||||
## [v0.5.0]
|
## [v0.5.0]
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- Reactored IRQ handling, so that `unmask` operations can be moved to HAL
|
- Reactored IRQ handling, so that `unmask` operations can be moved to HAL
|
||||||
- Added UART IRQ handler. Right now, can only perform reception, TX still needs to be done in
|
- Added UART IRQ handler. Right now, can only perform reception, TX still needs to be done in
|
||||||
a blocking manner
|
a blocking manner
|
||||||
- Added RTIC template and RTIC UART IRQ application
|
- Added RTIC template and RTIC UART IRQ application
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- Bugfix in UART code where RX and TX could not be enabled or disabled independently
|
|
||||||
|
|
||||||
## [v0.4.3]
|
## [v0.4.3]
|
||||||
|
|
||||||
- Various smaller fixes for READMEs, update of links in documentation
|
- Various smaller fixes for READMEs, update of links in documentation
|
||||||
|
35
Cargo.toml
35
Cargo.toml
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "va108xx-hal"
|
name = "va108xx-hal"
|
||||||
version = "0.5.1"
|
version = "0.5.0"
|
||||||
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
|
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "HAL for the Vorago VA108xx family of microcontrollers"
|
description = "HAL for the Vorago VA108xx family of microcontrollers"
|
||||||
@@ -8,43 +8,30 @@ homepage = "https://egit.irs.uni-stuttgart.de/rust/va108xx-hal"
|
|||||||
repository = "https://egit.irs.uni-stuttgart.de/rust/va108xx-hal"
|
repository = "https://egit.irs.uni-stuttgart.de/rust/va108xx-hal"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
keywords = ["no-std", "hal", "cortex-m", "vorago", "va108xx"]
|
keywords = ["no-std", "hal", "cortex-m", "vorago", "va108xx"]
|
||||||
categories = ["aerospace", "embedded", "no-std", "hardware-support"]
|
categories = ["embedded", "no-std", "hardware-support"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
va108xx = "0.2.4"
|
|
||||||
cortex-m = "0.7"
|
cortex-m = "0.7"
|
||||||
cortex-m-rt = "0.7"
|
cortex-m-rt = "0.7"
|
||||||
nb = "1"
|
nb = "1"
|
||||||
paste = "1.0"
|
paste = "1.0"
|
||||||
libm = "0.2.2"
|
embedded-hal = { features = ["unproven"], version = "0.2.6" }
|
||||||
|
void = { version = "1.0", default-features = false }
|
||||||
|
once_cell = { version = "1.8.0", default-features = false }
|
||||||
|
libm = "0.2.1"
|
||||||
|
|
||||||
[dependencies.embedded-hal]
|
[dependencies.va108xx]
|
||||||
version = "0.2.7"
|
version = "0.2.4"
|
||||||
features = ["unproven"]
|
|
||||||
|
|
||||||
[dependencies.void]
|
|
||||||
version = "1.0"
|
|
||||||
default-features = false
|
|
||||||
|
|
||||||
[dependencies.once_cell]
|
|
||||||
version = "1.12.0"
|
|
||||||
default-features = false
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
rt = ["va108xx/rt"]
|
rt = ["va108xx/rt"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
cortex-m-rtic = "1.1.2"
|
cortex-m-rtic = "0.6.0-rc.4"
|
||||||
|
panic-rtt-target = { version = "0.1", features = ["cortex-m"] }
|
||||||
|
rtt-target = { version = "0.3", features = ["cortex-m"] }
|
||||||
panic-halt = "0.2"
|
panic-halt = "0.2"
|
||||||
|
|
||||||
[dev-dependencies.rtt-target]
|
|
||||||
version = "0.3"
|
|
||||||
features = ["cortex-m"]
|
|
||||||
|
|
||||||
[dev-dependencies.panic-rtt-target]
|
|
||||||
version = "0.1"
|
|
||||||
features = ["cortex-m"]
|
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
debug = true
|
debug = true
|
||||||
lto = false
|
lto = false
|
||||||
|
@@ -1,12 +1,5 @@
|
|||||||
//! More complex UART application
|
//! UART example application. Sends a test string over a UART and then enters
|
||||||
//!
|
//! echo mode
|
||||||
//! Uses the IRQ capabilities of the VA10820 peripheral and the RTIC framework to poll the UART in
|
|
||||||
//! a non-blocking way. You can send variably sized strings to the VA10820 which will be echoed
|
|
||||||
//! back to the sender.
|
|
||||||
//!
|
|
||||||
//! This script was tested with an Arduino Due. You can find the test script in the
|
|
||||||
//! [`/test/DueSerialTest`](https://egit.irs.uni-stuttgart.de/rust/va108xx-hal/src/branch/main/test/DueSerialTest)
|
|
||||||
//! folder.
|
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
|
36
src/uart.rs
36
src/uart.rs
@@ -2,8 +2,7 @@
|
|||||||
//!
|
//!
|
||||||
//! ## Examples
|
//! ## Examples
|
||||||
//!
|
//!
|
||||||
//! - [UART simple example](https://egit.irs.uni-stuttgart.de/rust/va108xx-hal/src/branch/main/examples/uart.rs)
|
//! - [UART example](https://egit.irs.uni-stuttgart.de/rust/va108xx-hal/src/branch/main/examples/uart.rs)
|
||||||
//! - [UART with IRQ and RTIC](https://egit.irs.uni-stuttgart.de/rust/va108xx-hal/src/branch/main/examples/uart-irq-rtic.rs)
|
|
||||||
use core::{convert::Infallible, ptr};
|
use core::{convert::Infallible, ptr};
|
||||||
use core::{marker::PhantomData, ops::Deref};
|
use core::{marker::PhantomData, ops::Deref};
|
||||||
use libm::floorf;
|
use libm::floorf;
|
||||||
@@ -178,7 +177,7 @@ impl From<Bps> for Config {
|
|||||||
// IRQ Definitions
|
// IRQ Definitions
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
|
|
||||||
struct IrqInfo {
|
pub struct IrqInfo {
|
||||||
rx_len: usize,
|
rx_len: usize,
|
||||||
rx_idx: usize,
|
rx_idx: usize,
|
||||||
irq_cfg: IrqCfg,
|
irq_cfg: IrqCfg,
|
||||||
@@ -197,7 +196,6 @@ pub enum IrqResultMask {
|
|||||||
Unknown = 7,
|
Unknown = 7,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This struct is used to return the default IRQ handler result to the user
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct IrqResult {
|
pub struct IrqResult {
|
||||||
raw_res: u32,
|
raw_res: u32,
|
||||||
@@ -278,36 +276,32 @@ impl IrqResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
enum IrqReceptionMode {
|
pub enum IrqReceptionMode {
|
||||||
Idle,
|
Idle,
|
||||||
Pending,
|
FixedLen,
|
||||||
|
VarLen,
|
||||||
}
|
}
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
// UART implementation
|
// UART implementation
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
|
|
||||||
/// Type erased variant of a UART. Can be created with the [`Uart::downgrade`] function.
|
|
||||||
pub struct UartBase<UART> {
|
pub struct UartBase<UART> {
|
||||||
uart: UART,
|
uart: UART,
|
||||||
tx: Tx<UART>,
|
tx: Tx<UART>,
|
||||||
rx: Rx<UART>,
|
rx: Rx<UART>,
|
||||||
}
|
}
|
||||||
/// Serial abstraction. Entry point to create a new UART
|
/// Serial abstraction
|
||||||
pub struct Uart<UART, PINS> {
|
pub struct Uart<UART, PINS> {
|
||||||
uart_base: UartBase<UART>,
|
uart_base: UartBase<UART>,
|
||||||
pins: PINS,
|
pins: PINS,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// UART using the IRQ capabilities of the peripheral. Can be created with the
|
|
||||||
/// [`Uart::into_uart_with_irq`] function.
|
|
||||||
pub struct UartWithIrq<UART, PINS> {
|
pub struct UartWithIrq<UART, PINS> {
|
||||||
irq_base: UartWithIrqBase<UART>,
|
irq_base: UartWithIrqBase<UART>,
|
||||||
pins: PINS,
|
pins: PINS,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Type-erased UART using the IRQ capabilities of the peripheral. Can be created with the
|
|
||||||
/// [`UartWithIrq::downgrade`] function.
|
|
||||||
pub struct UartWithIrqBase<UART> {
|
pub struct UartWithIrqBase<UART> {
|
||||||
pub uart: UartBase<UART>,
|
pub uart: UartBase<UART>,
|
||||||
irq_info: IrqInfo,
|
irq_info: IrqInfo,
|
||||||
@@ -483,8 +477,6 @@ where
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If the IRQ capabilities of the peripheral are used, the UART needs to be converted
|
|
||||||
/// with this function
|
|
||||||
pub fn into_uart_with_irq(
|
pub fn into_uart_with_irq(
|
||||||
self,
|
self,
|
||||||
irq_cfg: IrqCfg,
|
irq_cfg: IrqCfg,
|
||||||
@@ -639,14 +631,6 @@ impl<UART: Instance> UartWithIrqBase<UART> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This initializes a non-blocking read transfer using the IRQ capabilities of the UART
|
|
||||||
/// peripheral.
|
|
||||||
///
|
|
||||||
/// The only required information is the maximum length for variable sized reception
|
|
||||||
/// or the expected length for fixed length reception. If variable sized packets are expected,
|
|
||||||
/// the timeout functionality of the IRQ should be enabled as well. After calling this function,
|
|
||||||
/// the [`irq_handler`](Self::irq_handler) function should be called in the user interrupt
|
|
||||||
/// handler to read the received packets and reinitiate another transfer if desired.
|
|
||||||
pub fn read_fixed_len_using_irq(
|
pub fn read_fixed_len_using_irq(
|
||||||
&mut self,
|
&mut self,
|
||||||
max_len: usize,
|
max_len: usize,
|
||||||
@@ -655,7 +639,6 @@ impl<UART: Instance> UartWithIrqBase<UART> {
|
|||||||
if self.irq_info.mode != IrqReceptionMode::Idle {
|
if self.irq_info.mode != IrqReceptionMode::Idle {
|
||||||
return Err(Error::TransferPending);
|
return Err(Error::TransferPending);
|
||||||
}
|
}
|
||||||
self.irq_info.mode = IrqReceptionMode::Pending;
|
|
||||||
self.irq_info.rx_idx = 0;
|
self.irq_info.rx_idx = 0;
|
||||||
self.irq_info.rx_len = max_len;
|
self.irq_info.rx_len = max_len;
|
||||||
self.uart.enable_rx();
|
self.uart.enable_rx();
|
||||||
@@ -706,10 +689,6 @@ impl<UART: Instance> UartWithIrqBase<UART> {
|
|||||||
self.irq_info.rx_len = 0;
|
self.irq_info.rx_len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Default IRQ handler which can be used to read the packets arriving on the UART peripheral.
|
|
||||||
///
|
|
||||||
/// If passed buffer is equal to or larger than the specified maximum length, an
|
|
||||||
/// [`Error::BufferTooShort`] will be returned
|
|
||||||
pub fn irq_handler(&mut self, res: &mut IrqResult, buf: &mut [u8]) -> Result<(), Error> {
|
pub fn irq_handler(&mut self, res: &mut IrqResult, buf: &mut [u8]) -> Result<(), Error> {
|
||||||
if buf.len() < self.irq_info.rx_len {
|
if buf.len() < self.irq_info.rx_len {
|
||||||
return Err(Error::BufferTooShort);
|
return Err(Error::BufferTooShort);
|
||||||
@@ -820,7 +799,6 @@ impl<UART: Instance> UartWithIrqBase<UART> {
|
|||||||
res.bytes_read = self.irq_info.rx_idx;
|
res.bytes_read = self.irq_info.rx_idx;
|
||||||
res.clear_result();
|
res.clear_result();
|
||||||
res.set_result(IrqResultMask::Complete);
|
res.set_result(IrqResultMask::Complete);
|
||||||
self.irq_info.mode = IrqReceptionMode::Idle;
|
|
||||||
self.irq_info.rx_idx = 0;
|
self.irq_info.rx_idx = 0;
|
||||||
self.irq_info.rx_len = 0;
|
self.irq_info.rx_len = 0;
|
||||||
}
|
}
|
||||||
@@ -831,7 +809,6 @@ impl<UART: Instance> UartWithIrqBase<UART> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<UART: Instance, PINS> UartWithIrq<UART, PINS> {
|
impl<UART: Instance, PINS> UartWithIrq<UART, PINS> {
|
||||||
/// See [`UartWithIrqBase::read_fixed_len_using_irq`] doc
|
|
||||||
pub fn read_fixed_len_using_irq(
|
pub fn read_fixed_len_using_irq(
|
||||||
&mut self,
|
&mut self,
|
||||||
max_len: usize,
|
max_len: usize,
|
||||||
@@ -845,7 +822,6 @@ impl<UART: Instance, PINS> UartWithIrq<UART, PINS> {
|
|||||||
self.irq_base.cancel_transfer()
|
self.irq_base.cancel_transfer()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See [`UartWithIrqBase::irq_handler`] doc
|
|
||||||
pub fn irq_handler(&mut self, res: &mut IrqResult, buf: &mut [u8]) -> Result<(), Error> {
|
pub fn irq_handler(&mut self, res: &mut IrqResult, buf: &mut [u8]) -> Result<(), Error> {
|
||||||
self.irq_base.irq_handler(res, buf)
|
self.irq_base.irq_handler(res, buf)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user