Skip to content

Commit

Permalink
Adapt to the changed trap frame for ESP32-C3 (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernQ authored Oct 6, 2022
1 parent e8adb31 commit 3f21a58
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
3 changes: 1 addition & 2 deletions examples/ble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ fn main() -> ! {

let mut wf2 = |_data| {};

gatt!([
service {
gatt!([service {
uuid: "937312e0-2354-11eb-9f10-fbc30a62cf38",
characteristics: [
characteristic {
Expand Down
5 changes: 2 additions & 3 deletions examples/coex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
19 changes: 10 additions & 9 deletions src/preempt/preempt_riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use esp32c3_hal::interrupt::TrapFrame;
#[derive(Debug, Default, Clone, Copy)]
pub struct Context {
trap_frame: TrapFrame,
pc: usize,
_running: bool,
}

Expand Down Expand Up @@ -57,16 +56,19 @@ 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];

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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 3f21a58

Please sign in to comment.