-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the
clock
module, provide ROM functions via linker scripts (…
…#353) * Refactor `clock` and `clocks_ll` into a common module * Add a ROM function linker script to each HAL and provide some functions * Use the provided ROM functions instead of transmuting addresses * Fix CI workflow for ESP32-S2
- Loading branch information
1 parent
1ec6f98
commit 832f9ef
Showing
27 changed files
with
110 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,9 +113,6 @@ jobs: | |
esp32s2-hal: | ||
runs-on: ubuntu-latest | ||
|
||
env: | ||
RUSTFLAGS: '--cfg target_has_atomic="8" --cfg target_has_atomic="16" --cfg target_has_atomic="32" --cfg target_has_atomic="ptr"' | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: esp-rs/[email protected] | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,147 +1,43 @@ | ||
pub use paste::paste; | ||
|
||
/// Pauses execution for us microseconds | ||
#[inline(always)] | ||
pub unsafe fn esp_rom_delay_us(us: u32) { | ||
#[cfg(esp32)] | ||
const ESP_ROM_DELAY_US: u32 = 0x4000_8534; | ||
#[cfg(esp32c2)] | ||
const ESP_ROM_DELAY_US: u32 = 0x4000_0044; | ||
#[cfg(esp32c3)] | ||
const ESP_ROM_DELAY_US: u32 = 0x4000_0050; | ||
#[cfg(esp32s2)] | ||
const ESP_ROM_DELAY_US: u32 = 0x4000_d888; | ||
#[cfg(esp32s3)] | ||
const ESP_ROM_DELAY_US: u32 = 0x4000_0600; | ||
#[allow(unused)] | ||
extern "C" { | ||
pub(crate) fn rom_i2c_writeReg(block: u32, block_hostid: u32, reg_add: u32, indata: u32); | ||
|
||
// cast to usize is just needed because of the way we run clippy in CI | ||
let fn_esp_rom_delay_us: fn(us: u32) = core::mem::transmute(ESP_ROM_DELAY_US as usize); | ||
|
||
fn_esp_rom_delay_us(us); | ||
} | ||
|
||
#[inline(always)] | ||
/// Set the real CPU ticks per us to the ets, so that ets_delay_us | ||
/// will be accurate. Call this function when CPU frequency is changed. | ||
pub unsafe fn ets_update_cpu_frequency(ticks_per_us: u32) { | ||
#[cfg(esp32)] | ||
const ETS_UPDATE_CPU_FREQUENCY: u32 = 0x4000_8550; | ||
#[cfg(esp32c2)] | ||
const ETS_UPDATE_CPU_FREQUENCY: u32 = 0x4000_0774; | ||
#[cfg(esp32c3)] | ||
const ETS_UPDATE_CPU_FREQUENCY: u32 = 0x4000_0588; | ||
#[cfg(esp32s2)] | ||
const ETS_UPDATE_CPU_FREQUENCY: u32 = 0x4000_d8a4; | ||
#[cfg(esp32s3)] | ||
const ETS_UPDATE_CPU_FREQUENCY: u32 = 0x4004_3164; | ||
|
||
// cast to usize is just needed because of the way we run clippy in CI | ||
let rom_ets_update_cpu_frequency: fn(ticks_per_us: u32) = | ||
core::mem::transmute(ETS_UPDATE_CPU_FREQUENCY as usize); | ||
|
||
rom_ets_update_cpu_frequency(ticks_per_us); | ||
} | ||
|
||
#[inline(always)] | ||
pub unsafe fn regi2c_ctrl_write_reg(block: u32, block_hostid: u32, reg_add: u32, indata: u32) { | ||
#[cfg(esp32)] | ||
const ROM_I2C_WRITEREG: u32 = 0x4000_41a4; | ||
#[cfg(esp32c2)] | ||
const ROM_I2C_WRITEREG: u32 = 0x4000_22f4; | ||
#[cfg(esp32c3)] | ||
const ROM_I2C_WRITEREG: u32 = 0x4000_195c; | ||
#[cfg(esp32s2)] | ||
const ROM_I2C_WRITEREG: u32 = 0x4000_a9a8; | ||
#[cfg(esp32s3)] | ||
const ROM_I2C_WRITEREG: u32 = 0x4000_5d60; | ||
|
||
// cast to usize is just needed because of the way we run clippy in CI | ||
let i2c_write_reg_raw: fn(block: u32, block_hostid: u32, reg_add: u32, indata: u32) -> i32 = | ||
core::mem::transmute(ROM_I2C_WRITEREG as usize); | ||
|
||
i2c_write_reg_raw(block, block_hostid, reg_add, indata); | ||
pub(crate) fn rom_i2c_writeReg_Mask( | ||
block: u32, | ||
block_hostid: u32, | ||
reg_add: u32, | ||
reg_add_msb: u32, | ||
reg_add_lsb: u32, | ||
indata: u32, | ||
); | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! regi2c_write { | ||
( $block: ident, $reg_add: ident, $indata: expr ) => { | ||
paste! { | ||
regi2c_ctrl_write_reg($block, | ||
rom_i2c_writeReg($block, | ||
[<$block _HOSTID>], | ||
$reg_add, | ||
$indata); | ||
$indata | ||
); | ||
} | ||
}; | ||
} | ||
|
||
#[inline(always)] | ||
pub unsafe fn regi2c_ctrl_write_reg_mask( | ||
block: u32, | ||
block_hostid: u32, | ||
reg_add: u32, | ||
reg_add_msb: u32, | ||
reg_add_lsb: u32, | ||
indata: u32, | ||
) { | ||
#[cfg(esp32)] | ||
const ROM_I2C_WRITEREG_MASK: u32 = 0x4000_41fc; | ||
#[cfg(esp32c2)] | ||
const ROM_I2C_WRITEREG_MASK: u32 = 0x4000_22fc; | ||
#[cfg(esp32c3)] | ||
const ROM_I2C_WRITEREG_MASK: u32 = 0x4000_1960; | ||
#[cfg(esp32s2)] | ||
const ROM_I2C_WRITEREG_MASK: u32 = 0x4000_aa00; | ||
#[cfg(esp32s3)] | ||
const ROM_I2C_WRITEREG_MASK: u32 = 0x4000_5d6c; | ||
|
||
// cast to usize is just needed because of the way we run clippy in CI | ||
let i2c_write_reg_mask_raw: fn( | ||
block: u32, | ||
block_hostid: u32, | ||
reg_add: u32, | ||
reg_add_msb: u32, | ||
reg_add_lsb: u32, | ||
indata: u32, | ||
) -> i32 = core::mem::transmute(ROM_I2C_WRITEREG_MASK as usize); | ||
|
||
i2c_write_reg_mask_raw( | ||
block, | ||
block_hostid, | ||
reg_add, | ||
reg_add_msb, | ||
reg_add_lsb, | ||
indata, | ||
); | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! regi2c_write_mask { | ||
( $block: ident, $reg_add: ident, $indata: expr ) => { | ||
paste! { | ||
regi2c_ctrl_write_reg_mask($block, | ||
rom_i2c_writeReg_Mask($block, | ||
[<$block _HOSTID>], | ||
$reg_add, | ||
[<$reg_add _MSB>], | ||
[<$reg_add _LSB>], | ||
$indata); | ||
$indata | ||
); | ||
} | ||
}; | ||
} | ||
|
||
/// Determine the reason that the specified CPU reset | ||
pub unsafe fn rtc_get_reset_reason(cpu_num: u32) -> u32 { | ||
#[cfg(esp32)] | ||
const RTC_GET_RESET_REASON: u32 = 0x4000_81d4; | ||
#[cfg(esp32c2)] | ||
const RTC_GET_RESET_REASON: u32 = 0x4000_0018; | ||
#[cfg(esp32c3)] | ||
const RTC_GET_RESET_REASON: u32 = 0x4000_0018; | ||
#[cfg(esp32s2)] | ||
const RTC_GET_RESET_REASON: u32 = 0x4000_ff58; | ||
#[cfg(esp32s3)] | ||
const RTC_GET_RESET_REASON: u32 = 0x4000_057c; | ||
|
||
let get_reason: fn(u32) -> u32 = core::mem::transmute(RTC_GET_RESET_REASON as usize); | ||
|
||
get_reason(cpu_num) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
INCLUDE "link-esp32.x" | ||
INCLUDE "hal-defaults.x" | ||
INCLUDE "rom-functions.x" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
PROVIDE(ets_delay_us = 0x40008534); | ||
PROVIDE(ets_update_cpu_frequency_rom = 0x40008550); | ||
PROVIDE(rom_i2c_writeReg = 0x400041a4); | ||
PROVIDE(rom_i2c_writeReg_Mask = 0x400041fc); | ||
PROVIDE(rtc_get_reset_reason = 0x400081d4); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
INCLUDE "memory.x" | ||
INCLUDE "bl-riscv-link.x" | ||
INCLUDE "hal-defaults.x" | ||
INCLUDE "rom-functions.x" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
INCLUDE "esp32c2-link.x" | ||
INCLUDE "hal-defaults.x" | ||
INCLUDE "rom-functions.x" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
PROVIDE(ets_delay_us = 0x40000044); | ||
PROVIDE(ets_update_cpu_frequency_rom = 0x40008550); | ||
PROVIDE(rom_i2c_writeReg = 0x400022f4); | ||
PROVIDE(rom_i2c_writeReg_Mask = 0x400022fc); | ||
PROVIDE(rtc_get_reset_reason = 0x40000018); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
INCLUDE "memory.x" | ||
INCLUDE "bl-riscv-link.x" | ||
INCLUDE "hal-defaults.x" | ||
INCLUDE "rom-functions.x" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
INCLUDE "esp32c3-link.x" | ||
INCLUDE "hal-defaults.x" | ||
INCLUDE "hal-defaults.x" | ||
INCLUDE "rom-functions.x" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
INCLUDE "link-esp32s2.x" | ||
INCLUDE "hal-defaults.x" | ||
INCLUDE "rom-functions.x" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
PROVIDE(ets_delay_us = 0x4000d888); | ||
PROVIDE(ets_update_cpu_frequency_rom = 0x4000d8a4); | ||
PROVIDE(rom_i2c_writeReg = 0x4000a9a8); | ||
PROVIDE(rom_i2c_writeReg_Mask = 0x4000aa00); | ||
PROVIDE(rtc_get_reset_reason = 0x4000ff58); |
Oops, something went wrong.