Skip to content

Add safe abstractions to CRC functions in ESP ROM#261

Merged
ivmarkov merged 3 commits into
esp-rs:masterfrom
jordanhalase:rom_crc
Jun 12, 2023
Merged

Add safe abstractions to CRC functions in ESP ROM#261
ivmarkov merged 3 commits into
esp-rs:masterfrom
jordanhalase:rom_crc

Conversation

@jordanhalase

@jordanhalase jordanhalase commented Jun 10, 2023

Copy link
Copy Markdown
Contributor

This is the safe CRC abstraction over the newly merged esp-rs/esp-idf-sys@4ffb883

I created the rom module to put commonly available ROM libraries, such as CRC. MD5 could be next. Since these libraries rely on the bindings provided by esp-idf-sys but are only on ESP32 chips they belong here in esp-idf-hal and not esp-idf-svc.

Test code is below or at my repository

use esp_idf_sys as _; // For binstart

use esp_idf_hal::rom::crc;

fn main() {
    esp_idf_sys::link_patches();

    let data = "123456789";

    loop {
        let crc_hdlc = crc::crc32_le(!0xffffffff, data.as_ref());
        let crc_bzip2 = crc::crc32_be(!0xffffffff, data.as_ref());
        let crc_mpeg2 = !crc::crc32_be(!0xffffffff, data.as_ref());
        let crc_cksum = crc::crc32_be(!0, data.as_ref());
        let crc_kermit = !crc::crc16_le(!0, data.as_ref());
        let crc_genibus = crc::crc16_be(!0xffff, data.as_ref());
        let crc_rohc = !crc::crc8_le(!0xff, data.as_ref());
        let crc_smbus = !crc::crc8_be(!0, data.as_ref());

        assert_eq!(crc_hdlc, 0xcbf43926);
        assert_eq!(crc_bzip2, 0xfc891918);
        assert_eq!(crc_mpeg2, 0x0376e6e7);
        assert_eq!(crc_cksum, 0x765e7680);
        assert_eq!(crc_kermit, 0x2189);
        assert_eq!(crc_genibus, 0xd64e);
        assert_eq!(crc_rohc, 0xd0);
        assert_eq!(crc_smbus, 0xf4);

        println!("{:08x} {:08x} {:08x} {:08x} {:04x} {:04x} {:02x} {:02x}",
            crc_hdlc, crc_bzip2, crc_mpeg2, crc_cksum, crc_kermit, crc_genibus, crc_rohc, crc_smbus);

        std::thread::sleep(std::time::Duration::from_millis(5000));
    }
}

@Vollbrecht Vollbrecht left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution ❤️

Comment thread src/lib.rs
Comment thread src/rom/mod.rs Outdated
@ivmarkov

Copy link
Copy Markdown
Collaborator

@jordanhalase Can you run cargo fmt on your PR and update? Also, please run cargo clippy as well, as that's the next step after fmt.

@jordanhalase

Copy link
Copy Markdown
Contributor Author

Ran cargo fmt and clippy :)

@ivmarkov
ivmarkov merged commit bf4a5af into esp-rs:master Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants