persistent-buff

Crates.iopersistent-buff
lib.rspersistent-buff
version0.2.6
sourcesrc
created_at2022-10-27 21:02:17.029379
updated_at2023-01-27 13:55:44.15614
descriptionA buffer that stays persistent in ram between boots
homepagehttps://github.com/xgroleau/persistent-buff
repositoryhttps://github.com/xgroleau/persistent-buff
max_upload_size
id699778
size32,671
Xavier Groleau (xgroleau)

documentation

https://docs.rs/persistent-buff

README

persistent-buff

crates.io documentation

A buffer that persists between boot. Inspired by panic-persist

A region in RAM is reseved for this buffer. Your linker script should make sure the start and end of the buffer are outside of other sections

Usage

Linker script

You need to create a new reserved section for the buffer and make sure it's outside of other sections to avoid zero initializations.

Example

memory.x file before modification:

MEMORY
{
  /* NOTE 1 K = 1 KiBi = 1024 bytes */
  FLASH : ORIGIN = 0x00000000, LENGTH = 1024K
  RAM : ORIGIN = 0x20000000, LENGTH = 128K
}

memory.x file after modification to hold a 1K region:

MEMORY
{
  /* NOTE 1 K = 1 KiBi = 1024 bytes */
  FLASH : ORIGIN = 0x00000000, LENGTH = 1024K
  RAM : ORIGIN = 0x20000000, LENGTH = 128K - 1K
  PERSISTENT_BUFF: ORIGIN = ORIGIN(RAM) + LENGTH(RAM), LENGTH = 1K
}
_persistent_buff_start = ORIGIN(PERSISTENT_BUFF);
_persistent_buff_end   = ORIGIN(PERSISTENT_BUFF) + LENGTH(PERSISTENT_BUFF);

Program

#![no_std]

#[entry]
fn main() -> ! {
   let mut pbuff = persistent_buff::PersistentBuff::take_managed().unwrap();

   // Trivial way to initialize is to fill it with 0
   let buff = pbuff.validate(|b| b.fill(0));

   buff[0] = (buff[0] % 255) + 1;
   info!("Value is now {}", buff[0]);
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 31

cargo fmt