Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions adapter/cmsis/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ build_rust("adapter_validation") {
":cmsis_adapter",
":validation_cases",
"//external/vendor/semihosting-0.1.20:semihosting",
"//kernel/arch:bluekernel_arch",
"//kernel/kconfig:generate_rustflags_file",

# in fact, validation_cases need an c library
Expand Down
37 changes: 10 additions & 27 deletions adapter/cmsis/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,51 +105,34 @@ mod tests {
0
}

use cortex_m::interrupt::InterruptNumber;

// copy from kernel/src/arch/arm/irq.rs
// used for rv2 ISR context api tests
#[derive(Debug, Copy, Clone)]
#[repr(transparent)]
pub struct IrqNumber(u16);
impl IrqNumber {
#[inline]
pub const fn new(number: u16) -> Self {
Self(number)
}
}
// SAFETY: get the number of the interrupt is safe
unsafe impl InterruptNumber for IrqNumber {
#[inline]
fn number(self) -> u16 {
self.0
}
}
use bluekernel_arch::cortex_m::nvic;

#[no_mangle]
pub unsafe extern "C" fn NVIC_SetPriority(irq: u16, priority: u8) {
cortex_m::Peripherals::steal()
.NVIC
.set_priority(IrqNumber::new(irq), priority);
// Keep the CMSIS validation shim on the same in-tree architecture
// boundary as the kernel. `bluekernel_arch` owns the NVIC MMIO access
// now, so the adapter test should not pull in a second architecture
// abstraction just to drive validation interrupts.
unsafe { nvic::set_priority(irq, priority) };
}
#[no_mangle]
pub unsafe extern "C" fn NVIC_EnableIRQ(irq: u16) {
cortex_m::peripheral::NVIC::unmask(IrqNumber::new(irq));
unsafe { nvic::enable(irq) };
}

#[no_mangle]
pub unsafe extern "C" fn NVIC_DisableIRQ(irq: u16) {
cortex_m::peripheral::NVIC::mask(IrqNumber::new(irq));
unsafe { nvic::disable(irq) };
}

#[no_mangle]
pub unsafe extern "C" fn NVIC_GetPendingIRQ(irq: u16) -> bool {
cortex_m::peripheral::NVIC::is_pending(IrqNumber::new(irq))
unsafe { nvic::is_pending(irq) }
}

#[no_mangle]
pub unsafe extern "C" fn NVIC_SetPendingIRQ(irq: u16) {
cortex_m::peripheral::NVIC::pend(IrqNumber::new(irq));
unsafe { nvic::pend(irq) };
}

#[no_mangle]
Expand Down
29 changes: 29 additions & 0 deletions arch/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2025 vivo Mobile Communication Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build/templates/build_template.gni")
import("//build/toolchain/blueos.gni")

build_rust("bluekernel_arch") {
crate_type = "rlib"
sources = [ "src/lib.rs" ]
edition = "2021"
deps = [
"//external/vendor/tock-registers-0.9.0:tock_registers",
"//kernel/hal:blueos_hal",
"//kernel/kconfig:blueos_kconfig",
"//kernel/kconfig:generate_rustflags_file",
]
configs += [ "//kernel/kconfig:kconfigs" ]
}
Loading