From 9bae034f9db66b8cd31ab5ce788ffaeb8bc8e2dc Mon Sep 17 00:00:00 2001 From: bjoernQ Date: Thu, 6 Oct 2022 08:22:06 +0200 Subject: [PATCH] Adapt to the changed trap frame for ESP32-C3 --- Cargo.toml | 5 +++-- examples/ble.rs | 3 +-- examples/coex.rs | 5 ++--- src/preempt/preempt_riscv.rs | 19 ++++++++++--------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2e73cfeb..1ee3ca42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,5 +70,6 @@ ble = [] # currently published versions don't contain all relevant adjustments - using git dependencies for now [patch.crates-io] -esp32s3-hal = { git = "https://github.com/esp-rs/esp-hal/", package = "esp32s3-hal", rev = "b1d5e37f36508ccfa835b236b2d30c3115bd3f72" } -esp32s2-hal = { git = "https://github.com/esp-rs/esp-hal/", package = "esp32s2-hal", rev = "b1d5e37f36508ccfa835b236b2d30c3115bd3f72" } +esp32s3-hal = { git = "https://github.com/esp-rs/esp-hal/", package = "esp32s3-hal", rev = "af745ac7b0799752260e13573895b97153d85639" } +esp32s2-hal = { git = "https://github.com/esp-rs/esp-hal/", package = "esp32s2-hal", rev = "af745ac7b0799752260e13573895b97153d85639" } +esp32c3-hal = { git = "https://github.com/esp-rs/esp-hal/", package = "esp32c3-hal", rev = "af745ac7b0799752260e13573895b97153d85639" } diff --git a/examples/ble.rs b/examples/ble.rs index 04923e94..9d9402de 100644 --- a/examples/ble.rs +++ b/examples/ble.rs @@ -104,8 +104,7 @@ fn main() -> ! { let mut wf2 = |_data| {}; - gatt!([ - service { + gatt!([service { uuid: "937312e0-2354-11eb-9f10-fbc30a62cf38", characteristics: [ characteristic { diff --git a/examples/coex.rs b/examples/coex.rs index c678581e..71909fad 100644 --- a/examples/coex.rs +++ b/examples/coex.rs @@ -12,10 +12,9 @@ use bleps::{ ad_structure::{ create_advertising_data, AdStructure, BR_EDR_NOT_SUPPORTED, LE_GENERAL_DISCOVERABLE, }, - attribute_server::{AttributeServer, WorkResult}, - Ble, Data, HciConnection, HciConnector, att::Uuid, + att::Uuid, + Ble, HciConnector, }; -use bleps_macros::gatt; use esp_wifi::{ble::controller::BleConnector, current_millis, wifi_interface::Network}; diff --git a/src/preempt/preempt_riscv.rs b/src/preempt/preempt_riscv.rs index 757311ec..e8e195f5 100644 --- a/src/preempt/preempt_riscv.rs +++ b/src/preempt/preempt_riscv.rs @@ -4,7 +4,6 @@ use esp32c3_hal::interrupt::TrapFrame; #[derive(Debug, Default, Clone, Copy)] pub struct Context { trap_frame: TrapFrame, - pc: usize, _running: bool, } @@ -57,8 +56,11 @@ static mut CTX_TASKS: [Context; MAX_TASK] = [Context { gp: 0, tp: 0, sp: 0, + pc: 0, + mstatus: 0, + mcause: 0, + mtval: 0, }, - pc: 0, _running: false, }; MAX_TASK]; @@ -66,7 +68,7 @@ pub fn task_create(task: extern "C" fn()) -> usize { unsafe { let i = TASK_TOP; TASK_TOP += 1; - CTX_TASKS[i].pc = task as usize; + CTX_TASKS[i].trap_frame.pc = task as usize; // stack must be aligned by 16 let task_stack_ptr = &TASK_STACK as *const _ as usize @@ -85,7 +87,7 @@ fn task_create_from_mepc(mepc: usize) -> usize { unsafe { let i = TASK_TOP; TASK_TOP += 1; - CTX_TASKS[i].pc = mepc; + CTX_TASKS[i].trap_frame.pc = mepc; CTX_NOW = i; i } @@ -125,7 +127,7 @@ pub fn task_to_trap_frame(id: usize, trap_frame: &mut TrapFrame) -> usize { trap_frame.gp = CTX_TASKS[id].trap_frame.gp; trap_frame.tp = CTX_TASKS[id].trap_frame.tp; - CTX_TASKS[id].pc + CTX_TASKS[id].trap_frame.pc } } @@ -163,7 +165,7 @@ pub fn trap_frame_to_task(id: usize, pc: usize, trap_frame: &TrapFrame) { CTX_TASKS[id].trap_frame.gp = trap_frame.gp; CTX_TASKS[id].trap_frame.tp = trap_frame.tp; - CTX_TASKS[id].pc = pc; + CTX_TASKS[id].trap_frame.pc = pc; } } @@ -175,7 +177,7 @@ pub fn next_task() { pub fn task_switch(trap_frame: &mut TrapFrame) { unsafe { - let old_mepc = riscv::register::mepc::read(); + let old_mepc = trap_frame.pc; if FIRST_SWITCH.load(Ordering::Relaxed) { FIRST_SWITCH.store(false, Ordering::Relaxed); @@ -188,8 +190,7 @@ pub fn task_switch(trap_frame: &mut TrapFrame) { next_task(); let new_pc = task_to_trap_frame(CTX_NOW, trap_frame); - - riscv::register::mepc::write(new_pc); + trap_frame.pc = new_pc; // debug aid! remove when not needed anymore!!!!! // static mut CNT: u32 = 0;