#frequency #run-time #cpu #clock #avr #retrieving #details

avr-config

An AVR foundational crate for retrieving details, such as the CPU clock frequency, at runtime

3 stable releases

2.0.1 Feb 1, 2021
1.0.0 Jul 25, 2020

#1787 in Embedded development

Download history 42/week @ 2023-12-07 52/week @ 2023-12-14 54/week @ 2023-12-21 24/week @ 2023-12-28 39/week @ 2024-01-04 53/week @ 2024-01-11 54/week @ 2024-01-18 38/week @ 2024-01-25 35/week @ 2024-02-01 44/week @ 2024-02-08 73/week @ 2024-02-15 87/week @ 2024-02-22 63/week @ 2024-02-29 83/week @ 2024-03-07 66/week @ 2024-03-14 70/week @ 2024-03-21

294 downloads per month
Used in 2 crates

MIT license

6KB

avr-config

Crates.io MIT licensed

A foundational crate for retrieving details, such as the CPU clock frequency, at runtime.

API Documentation

Usage

Add this to your Cargo.toml

avr-config = "1.0"

Features

Retrieving the CPU clock frequency

The CPU_FREQUENCY_HZ constant can be used to fetch the target clock frequency of the AVR. This corresponds to the $AVR_CPU_FREQUENCY_HZ environment variable that must be set when compiling this crate and crates that use it for AVR.

fn main() {
    let prescaler = avr_config::CPU_FREQUENCY_HZ / 16;
}

No part of the compiler toolchain itself understands or knows about the CPU frequency of the target device - this is a user-level concern that only affects user code (such as a busy wait delay loop for timed sleeping).

This crate is not strictly required for retrieving the clock frequency - any logic or environment variable will do. However, setting up the required clock frequency environment variables for all your dependent crates could be problematic if there are multiple ways of doing it, increasing the chance of forgetting one or getting into the situation where the frequencies are inconsistent and dependent crates execute at different speeds.

This crate aims to provide the boilerplate for getting the CPU frequency as an integer at runtime, as well as establishes a convention that $AVR_CPU_FREQUENCY_HZ is used to pass the target frequency to all AVR crates, if they opt-in to it.

Dependencies

~1.5MB
~34K SLoC