avr-atomic 1.0.0

Fast atomic load/store without IRQ-disable for AVR
Documentation
  • Coverage
  • 100%
    11 out of 11 items documented1 out of 11 items with examples
  • Size
  • Source code size: 40.07 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.55 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • mbuesch/avr-atomic
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mbuesch

Fast atomic load/store without IRQ-disable for AVR

A fast atomic type for 8-bit values on AVR microcontrollers. It is designed to be efficient by avoiding IRQ-disable/restore overhead.

This crate provides a simple and fast way to perform atomic load and store operations on 8-bit values: u8, i8, bool and any other user defined type that can be converted to and from u8.

Usage

Add this to your Cargo.toml:

[dependencies]
avr-atomic = "1"

Example: Basic types u8, i8, bool

use avr_atomic::AvrAtomic;

static VALUE_U8: AvrAtomic<u8> = AvrAtomic::new();
static VALUE_I8: AvrAtomic<i8> = AvrAtomic::new();
static VALUE_BOOL: AvrAtomic<bool> = AvrAtomic::new();

fn foo() {
    VALUE_U8.store(0x42);
    let value = VALUE_U8.load();

    VALUE_I8.store(-42);
    let value = VALUE_I8.load();

    VALUE_BOOL.store(true);
    let value = VALUE_BOOL.load();
}

Example: User defined type

use avr_atomic::{AvrAtomic, AvrAtomicConvert};

#[derive(Copy, Clone)]
struct MyFoo {
    inner: u8,
}

impl AvrAtomicConvert for MyFoo {
    fn from_u8(value: u8) -> Self {
        Self { inner: value }
    }

    fn to_u8(self) -> u8 {
        self.inner
    }
}

static VALUE: AvrAtomic<MyFoo> = AvrAtomic::new();

fn foo() {
    VALUE.store(MyFoo { inner: 2 } );

    let value = VALUE.load();
    assert_eq!(value.inner, 2);
}

License

This project is licensed under either of the following, at your option: