Skip to content
This repository was archived by the owner on Aug 9, 2022. It is now read-only.

Commit 2dc64df

Browse files
authored
Merge pull request #49 from esp-rs/xtensa-rt-alloc-fixes
xtensa-lx changes, alloc fixes and clean up
2 parents 92a4de0 + d9f7c98 commit 2dc64df

File tree

19 files changed

+60
-67
lines changed

19 files changed

+60
-67
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"rust-analyzer.cargo.target": "x86_64-unknown-linux-gnu"
3+
}

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ alloc = ["linked_list_allocator"]
3232
mem = []
3333

3434
# Enable the `rt` feature of the `esp32` crate.
35-
rt = ["esp32/rt", "xtensa-lx6-rt"]
35+
rt = ["esp32/rt", "xtensa-lx-rt"]
3636

3737

3838
[dependencies]
39-
esp32-hal-proc-macros = { version = "=0.1.0", path = "procmacros" }
39+
esp32-hal-proc-macros = { version = "=0.2.0", path = "procmacros" }
4040

41-
xtensa-lx6-rt = { version = "0.4.0", optional = true }
42-
xtensa-lx6 = "0.2.0"
43-
esp32 = { version = "0.7.0", default-features = false }
41+
xtensa-lx-rt = { version = "0.5.0", optional = true, features = ["lx6"] }
42+
xtensa-lx = { version = "0.3.0", features = ["lx6"]}
43+
esp32 = "0.10.0"
4444
bare-metal = "0.2"
4545
nb = "0.1.2"
4646
embedded-hal = { version = "0.2.3", features = ["unproven"] }
47-
linked_list_allocator = { version = "=0.8.4", optional = true, default-features = false, features = ["alloc_ref"] }
47+
linked_list_allocator = { version = "0.8.5", optional = true, default-features = false, features = ["alloc_ref"] }
4848
void = { version = "1.0.2", default-features = false }
4949

5050
[dev-dependencies]

examples/blinky.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
#![no_std]
22
#![no_main]
33

4-
extern crate esp32_hal as hal;
5-
extern crate panic_halt;
6-
extern crate xtensa_lx6_rt;
7-
84
use esp32_hal::target;
95
use hal::prelude::*;
10-
use xtensa_lx6::timer::get_cycle_count;
6+
use xtensa_lx::timer::get_cycle_count;
7+
use panic_halt as _;
8+
use esp32_hal as hal;
119

1210
/// The default clock source is the onboard crystal
1311
/// In most cases 40mhz (but can be as low as 2mhz depending on the board)
1412
const CORE_HZ: u32 = 40_000_000;
1513

1614
const WDT_WKEY_VALUE: u32 = 0x50D83AA1;
1715

18-
#[no_mangle]
16+
#[entry]
1917
fn main() -> ! {
2018
let dp = target::Peripherals::take().expect("Failed to obtain Peripherals");
2119

examples/exception.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use esp32_hal::Core::PRO;
1919
// !!! Cannot use CriticalSectionSpinLockMutex here, because an NMI is fires from within a locked
2020
// section which leads to a deadlock in the NMI interrupt handler. This is not a problem in this
2121
// case as this is a single threaded example. !!!
22-
static TX: xtensa_lx6::mutex::CriticalSectionMutex<Option<esp32_hal::serial::Tx<esp32::UART0>>> =
23-
xtensa_lx6::mutex::CriticalSectionMutex::new(None);
22+
static TX: xtensa_lx::mutex::CriticalSectionMutex<Option<esp32_hal::serial::Tx<esp32::UART0>>> =
23+
xtensa_lx::mutex::CriticalSectionMutex::new(None);
2424

2525
fn locked_print(str: &str) {
2626
(&TX).lock(|tx| {
@@ -30,7 +30,7 @@ fn locked_print(str: &str) {
3030
tx,
3131
" {}, Level: {}",
3232
str,
33-
xtensa_lx6::interrupt::get_level()
33+
xtensa_lx::interrupt::get_level()
3434
)
3535
.unwrap();
3636
});
@@ -78,8 +78,8 @@ fn random_name() {
7878
#[exception]
7979
#[ram]
8080
fn other_exception(
81-
cause: xtensa_lx6_rt::exception::ExceptionCause,
82-
frame: xtensa_lx6_rt::exception::Context,
81+
cause: xtensa_lx_rt::exception::ExceptionCause,
82+
frame: xtensa_lx_rt::exception::Context,
8383
) {
8484
(&TX).lock(|tx| {
8585
let tx = tx.as_mut().unwrap();

examples/gpio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn handle_gpio_interrupt() {
122122
writeln!(
123123
serial,
124124
" Interrupt level: {}, pin state: {}",
125-
xtensa_lx6::interrupt::get_level(),
125+
xtensa_lx::interrupt::get_level(),
126126
gpio.is_high().unwrap()
127127
)
128128
.unwrap();

examples/mem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use esp32_hal::mem::{memcmp, memcpy, memcpy_reverse, memset};
1717
use esp32_hal::serial::{config::Config, Serial};
1818
use esp32_hal::target;
1919

20-
use xtensa_lx6::timer::get_cycle_count;
20+
use xtensa_lx::timer::get_cycle_count;
2121

2222
#[macro_use]
2323
extern crate alloc;

examples/multicore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use esp32_hal::dprintln;
1212
use esp32_hal::serial::{config::Config, Serial};
1313
use esp32_hal::target;
1414

15-
use xtensa_lx6::{get_stack_pointer, timer::get_cycle_count};
15+
use xtensa_lx::{get_stack_pointer, timer::get_cycle_count};
1616

1717
const BLINK_HZ: Hertz = Hertz(1);
1818

examples/ram.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use esp32_hal::dprintln;
1212
use esp32_hal::serial::{config::Config, Serial};
1313
use esp32_hal::target;
1414

15-
use xtensa_lx6::get_program_counter;
15+
use xtensa_lx::get_program_counter;
1616

1717
#[entry]
1818
fn main() -> ! {

examples/rtccntl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn main() -> ! {
128128

129129
x = x.wrapping_add(1);
130130

131-
let ccount = xtensa_lx6::timer::get_cycle_count();
131+
let ccount = xtensa_lx::timer::get_cycle_count();
132132
let ccount_diff = ccount.wrapping_sub(prev_ccount);
133133

134134
writeln!(

examples/timer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn main() -> ! {
161161
timer0.get_value(),
162162
timer1.get_value(),
163163
timer2.get_value(),
164-
xtensa_lx6::timer::get_cycle_count()
164+
xtensa_lx::timer::get_cycle_count()
165165
)
166166
.unwrap();
167167
if let Ok(_) = timer1.wait() {

procmacros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ keywords = ["esp32", "esp32-hal", "runtime", "startup"]
77
license = "MIT OR Apache-2.0"
88
name = "esp32-hal-proc-macros"
99
repository = "https://github.com/esp-rs/xtensa-lx6-rt"
10-
version = "0.1.0"
10+
version = "0.2.0"
1111
edition = "2018"
1212

1313
[lib]

src/alloc.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,26 +149,17 @@ unsafe impl GlobalAlloc for Allocator {
149149
}
150150

151151
extern crate alloc;
152-
use alloc::alloc::{AllocErr, AllocInit, AllocRef, MemoryBlock};
152+
use alloc::alloc::{AllocErr, AllocRef};
153153

154154
unsafe impl AllocRef for Allocator {
155-
fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocErr> {
155+
fn alloc(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
156156
if layout.size() == 0 {
157-
return Ok(MemoryBlock {
158-
ptr: layout.dangling(),
159-
size: 0,
160-
});
157+
return Ok(NonNull::slice_from_raw_parts(layout.dangling(), 0));
161158
}
162159
let ptr = unsafe { GlobalAlloc::alloc(self, layout) };
163-
if ptr != 0 as *mut u8 {
164-
let block = MemoryBlock {
165-
ptr: NonNull::new(ptr).ok_or(AllocErr)?,
166-
size: layout.size(),
167-
};
168-
unsafe { init.init(block) };
169-
Ok(block)
170-
} else {
171-
Err(AllocErr)
160+
match NonNull::new(ptr) {
161+
Some(ptr) => Ok(NonNull::slice_from_raw_parts(ptr, layout.size())),
162+
None => Err(AllocErr)
172163
}
173164
}
174165
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {

src/clock_control/cpu.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use super::Error;
55
use crate::target;
66
use crate::Core::{self, APP, PRO};
7-
use xtensa_lx6::set_stack_pointer;
7+
use xtensa_lx::set_stack_pointer;
88

99
static mut START_CORE1_FUNCTION: Option<fn() -> !> = None;
1010

@@ -119,12 +119,12 @@ impl super::ClockControl {
119119
}
120120

121121
// disables interrupts
122-
xtensa_lx6::interrupt::set_mask(0);
122+
xtensa_lx::interrupt::set_mask(0);
123123

124124
// reset cycle compare registers
125-
xtensa_lx6::timer::set_ccompare0(0);
126-
xtensa_lx6::timer::set_ccompare1(0);
127-
xtensa_lx6::timer::set_ccompare2(0);
125+
xtensa_lx::timer::set_ccompare0(0);
126+
xtensa_lx::timer::set_ccompare1(0);
127+
xtensa_lx::timer::set_ccompare2(0);
128128

129129
// set stack pointer to end of memory: no need to retain stack up to this point
130130
set_stack_pointer(&mut _stack_end_cpu1);
@@ -136,7 +136,7 @@ impl super::ClockControl {
136136
///
137137
/// The second core will start running with the function `entry`.
138138
pub fn start_app_core(&mut self, entry: fn() -> !) -> Result<(), Error> {
139-
if !xtensa_lx6::is_debugger_attached()
139+
if !xtensa_lx::is_debugger_attached()
140140
&& self
141141
.dport_control
142142
.appcpu_ctrl_b()

src/clock_control/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::target::rtccntl::clk_conf::*;
2323
use crate::target::rtccntl::cntl::*;
2424
use crate::target::{APB_CTRL, RTCCNTL, TIMG0};
2525
use core::fmt;
26-
use xtensa_lx6::timer::{delay, get_cycle_count};
26+
use xtensa_lx::timer::{delay, get_cycle_count};
2727

2828
pub mod config;
2929
pub mod cpu;

src/dport.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
//! Registers needed in other blocks can be split off.
55
//!
66
use crate::target::{dport, DPORT};
7-
use xtensa_lx6::mutex::mutex_trait::Mutex;
8-
use xtensa_lx6::mutex::CriticalSectionSpinLockMutex;
7+
use xtensa_lx::mutex::mutex_trait::Mutex;
8+
use xtensa_lx::mutex::CriticalSectionSpinLockMutex;
99

1010
/// Cpu Period Configuration Register
1111
pub struct ClockControl {}

src/external_ram.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(super) unsafe fn init() {
3838
if &_external_heap_start as *const u32 > (&_external_ram_start as *const u32).add(get_size()) {
3939
panic!("External RAM too small for data");
4040
}
41-
xtensa_lx6_rt::zero_bss(&mut _external_bss_start, &mut _external_bss_end);
41+
xtensa_lx_rt::zero_bss(&mut _external_bss_start, &mut _external_bss_end);
4242
}
4343

4444
/// Calculate the size of external RAM by reading and writing at defined intervals while

src/interrupt.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
//! This module redirects the cpu interrupts handler to registered peripheral interrupt handlers.
55
//!
66
//! Interrupt handlers are defined using the [Interrupt](attr.interrupt.html) attribute.
7-
//! (Note that this is a distinct attribute from the one in the [xtensa_lx6_rt](xtensa_lx6_rt)
7+
//! (Note that this is a distinct attribute from the one in the [xtensa_lx_rt](xtensa_lx_rt)
88
//! crate.)
99
//!
1010
//! To enable the interrupt and assign to a specific interrupt level use
1111
//! the [enable] or [enable_with_priority] functions. (This is in addition to enabling the
1212
//! interrupt in the respective peripherals.)
1313
//!
1414
//! To have lowest latency possible you can use the
15-
//! [Interrupt](../../xtensa_lx6_rt/attr.interrupt.html) attribute from the xtensa_lx6_rt crate
15+
//! [Interrupt](../../xtensa_lx_rt/attr.interrupt.html) attribute from the xtensa_lx_rt crate
1616
//! to define low level/naked interrupt handlers. (This will override the interrupt
1717
//! handling offered by this crate for that specific interrupt level. This should especially be
1818
//! considered when using Level 7 = Non Maskable Interrupt level as these will not be turned off
@@ -38,7 +38,7 @@ pub use crate::target::{
3838
use crate::Core::{self, APP, PRO};
3939
use bare_metal::Nr;
4040
pub use proc_macros::interrupt;
41-
pub use xtensa_lx6::interrupt::{self, free};
41+
pub use xtensa_lx::interrupt::{self, free};
4242

4343
/// Interrupt errors
4444
#[derive(Debug)]
@@ -213,43 +213,43 @@ static mut INTERRUPT_LEVELS: [u128; 8] = [0u128; 8];
213213
static INTERRUPT_LEVELS_MUTEX: CriticalSectionSpinLockMutex<bool> =
214214
CriticalSectionSpinLockMutex::new(false);
215215

216-
#[xtensa_lx6_rt::interrupt(1)]
216+
#[xtensa_lx_rt::interrupt(1)]
217217
#[ram]
218218
unsafe fn level_1_handler(level: u32) {
219219
handle_interrupts(level)
220220
}
221221

222-
#[xtensa_lx6_rt::interrupt(2)]
222+
#[xtensa_lx_rt::interrupt(2)]
223223
#[ram]
224224
unsafe fn level_2_handler(level: u32) {
225225
handle_interrupts(level)
226226
}
227227

228-
#[xtensa_lx6_rt::interrupt(3)]
228+
#[xtensa_lx_rt::interrupt(3)]
229229
#[ram]
230230
unsafe fn level_3_handler(level: u32) {
231231
handle_interrupts(level)
232232
}
233233

234-
#[xtensa_lx6_rt::interrupt(4)]
234+
#[xtensa_lx_rt::interrupt(4)]
235235
#[ram]
236236
unsafe fn level_4_handler(level: u32) {
237237
handle_interrupts(level)
238238
}
239239

240-
#[xtensa_lx6_rt::interrupt(5)]
240+
#[xtensa_lx_rt::interrupt(5)]
241241
#[ram]
242242
unsafe fn level_5_handler(level: u32) {
243243
handle_interrupts(level)
244244
}
245245

246-
#[xtensa_lx6_rt::interrupt(6)]
246+
#[xtensa_lx_rt::interrupt(6)]
247247
#[ram]
248248
unsafe fn level_6_handler(level: u32) {
249249
handle_interrupts(level)
250250
}
251251

252-
#[xtensa_lx6_rt::interrupt(7)]
252+
#[xtensa_lx_rt::interrupt(7)]
253253
#[ram]
254254
unsafe fn level_7_handler(level: u32) {
255255
handle_interrupts(level)

src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#![feature(const_fn)]
1919
#![cfg_attr(feature = "alloc", feature(allocator_api))]
2020
#![cfg_attr(feature = "alloc", feature(alloc_layout_extra))]
21+
#![cfg_attr(feature = "alloc", feature(nonnull_slice_from_raw_parts))]
2122

2223
pub use embedded_hal as hal;
2324
pub use esp32 as target;
@@ -76,17 +77,17 @@ pub unsafe extern "C" fn ESP32Reset() -> ! {
7677
// initialization to zero needs to be done by the application
7778

7879
// Initialize RTC RAM
79-
xtensa_lx6_rt::zero_bss(&mut _rtc_fast_bss_start, &mut _rtc_fast_bss_end);
80-
xtensa_lx6_rt::zero_bss(&mut _rtc_slow_bss_start, &mut _rtc_slow_bss_end);
80+
xtensa_lx_rt::zero_bss(&mut _rtc_fast_bss_start, &mut _rtc_fast_bss_end);
81+
xtensa_lx_rt::zero_bss(&mut _rtc_slow_bss_start, &mut _rtc_slow_bss_end);
8182

8283
#[cfg(feature = "external_ram")]
8384
external_ram::init();
8485

8586
// set stack pointer to end of memory: no need to retain stack up to this point
86-
xtensa_lx6::set_stack_pointer(&mut _stack_end_cpu0);
87+
xtensa_lx::set_stack_pointer(&mut _stack_end_cpu0);
8788

8889
// continue with default reset handler
89-
xtensa_lx6_rt::Reset();
90+
xtensa_lx_rt::Reset();
9091
}
9192

9293
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
@@ -96,7 +97,7 @@ pub enum Core {
9697
}
9798

9899
pub fn get_core() -> Core {
99-
match ((xtensa_lx6::get_processor_id() >> 13) & 1) != 0 {
100+
match ((xtensa_lx::get_processor_id() >> 13) & 1) != 0 {
100101
false => Core::PRO,
101102
true => Core::APP,
102103
}

src/prelude.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! This can be imported as use `esp32_hal::prelude::*`.
88
99
#[cfg(feature = "rt")]
10-
pub use xtensa_lx6_rt::{entry, exception};
10+
pub use xtensa_lx_rt::{entry, exception};
1111

1212
pub use crate::analog::SensExt;
1313
pub use crate::dport::{self, Peripheral};
@@ -23,5 +23,5 @@ pub use embedded_hal::digital::v2::ToggleableOutputPin as _;
2323
pub use embedded_hal::prelude::*;
2424
pub use embedded_hal::timer::{Cancel, CountDown, Periodic};
2525

26-
pub use xtensa_lx6::mutex::mutex_trait::prelude::*;
27-
pub use xtensa_lx6::mutex::CriticalSectionSpinLockMutex;
26+
pub use xtensa_lx::mutex::mutex_trait::prelude::*;
27+
pub use xtensa_lx::mutex::CriticalSectionSpinLockMutex;

0 commit comments

Comments
 (0)