cortexm/thread_id.rs
1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2025.
4
5//! Basic implementation of a thread ID provider for Cortex-M.
6
7use kernel::platform::chip::ThreadIdProvider;
8
9/// Implement the [`ThreadIdProvider`] trait for Cortex-M platforms.
10///
11/// We assign thread IDs this way:
12///
13/// - 0: Main thread
14/// - 1: Any interrupt service routine
15pub enum CortexMThreadIdProvider {}
16
17// # Safety
18//
19// By implementing [`ThreadIdProvider`] we are guaranteeing that we correctly
20// return the thread ID. On single-core platforms the thread ID only depends on
21// whether execution is in an interrupt service routine or not, which is what
22// this implementation checks for.
23unsafe impl ThreadIdProvider for CortexMThreadIdProvider {
24 fn running_thread_id() -> usize {
25 crate::support::is_interrupt_context() as usize
26 }
27}