speck-core 0.2.0

Secure runtime package manager for MMU-less microcontrollers
Documentation
//! Wear leveling policies

use crate::flash::{Flash, PageId};

/// Policy for distributing writes across pages
#[derive(Clone, Debug)]
pub enum WearLevelingPolicy {
    /// No wear leveling (direct mapping)
    None,
    /// Simple rotation among pool
    RoundRobin,
    /// Always pick lowest erase count
    Greedy,
    /// Random selection with bias toward low-count pages
    Probabilistic,
}

impl WearLevelingPolicy {
    /// Select pages for allocation
    pub fn select_pages(&self, flash: &Flash, needed: usize) -> Vec<PageId> {
        match self {
            WearLevelingPolicy::None => {
                (0..needed).map(PageId).collect()
            }
            WearLevelingPolicy::Greedy => {
                flash.find_wear_leveled_pages(needed)
            }
            _ => flash.find_wear_leveled_pages(needed), // Default to greedy
        }
    }
}