mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +01:00
rtic-macros: fix #[cfg] for hardware and software tasks
Disabling hardware and software tasks via `#[cfg]` flags was broken. Added test case to verify, and fixed codegen to output missing cfgs.
This commit is contained in:
parent
fa2a5b449f
commit
a330dedf37
8 changed files with 61 additions and 9 deletions
0
ci/expected/lm3s6965/t-cfg-tasks.run
Normal file
0
ci/expected/lm3s6965/t-cfg-tasks.run
Normal file
2
examples/lm3s6965/Cargo.lock
generated
2
examples/lm3s6965/Cargo.lock
generated
|
@ -354,7 +354,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rtic"
|
||||
version = "2.1.0"
|
||||
version = "2.1.1"
|
||||
dependencies = [
|
||||
"atomic-polyfill",
|
||||
"bare-metal 1.0.0",
|
||||
|
|
35
examples/lm3s6965/examples/t-cfg-tasks.rs
Normal file
35
examples/lm3s6965/examples/t-cfg-tasks.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
//! [compile-pass] check that `#[cfg]` attributes applied on tasks work
|
||||
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::debug;
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local) {
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
(Shared {}, Local {})
|
||||
}
|
||||
|
||||
#[cfg(feature = "feature_x")]
|
||||
#[task]
|
||||
async fn opt_sw_task(cx: opt_sw_task::Context) {}
|
||||
|
||||
#[cfg(feature = "feature_x")]
|
||||
#[task(binds = UART0)]
|
||||
fn opt_hw_task(cx: opt_hw_task::Context) {}
|
||||
}
|
|
@ -7,6 +7,10 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `#[cfg]` tags on hardware and software tasks.
|
||||
|
||||
## [v2.1.0] - 2024-02-27
|
||||
|
||||
### Added
|
||||
|
|
|
@ -16,10 +16,12 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
|
|||
let interrupts = &analysis.interrupts;
|
||||
|
||||
// Generate executor definition and priority in global scope
|
||||
for (name, _) in app.software_tasks.iter() {
|
||||
for (name, task) in app.software_tasks.iter() {
|
||||
let exec_name = util::internal_task_ident(name, "EXEC");
|
||||
let cfgs = &task.cfgs;
|
||||
|
||||
items.push(quote!(
|
||||
#(#cfgs)*
|
||||
#[allow(non_upper_case_globals)]
|
||||
static #exec_name: rtic::export::executor::AsyncTaskExecutorPtr =
|
||||
rtic::export::executor::AsyncTaskExecutorPtr::new();
|
||||
|
@ -46,15 +48,15 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
|
|||
|
||||
for name in channel.tasks.iter() {
|
||||
let exec_name = util::internal_task_ident(name, "EXEC");
|
||||
let task = &app.software_tasks[name];
|
||||
let cfgs = &task.cfgs;
|
||||
let from_ptr_n_args =
|
||||
util::from_ptr_n_args_ident(app.software_tasks[name].inputs.len());
|
||||
|
||||
// TODO: Fix cfg
|
||||
// let task = &app.software_tasks[name];
|
||||
// let cfgs = &task.cfgs;
|
||||
|
||||
stmts.push(quote!(
|
||||
#(#cfgs)*
|
||||
let exec = rtic::export::executor::AsyncTaskExecutor::#from_ptr_n_args(#name, &#exec_name);
|
||||
#(#cfgs)*
|
||||
exec.poll(|| {
|
||||
let exec = rtic::export::executor::AsyncTaskExecutor::#from_ptr_n_args(#name, &#exec_name);
|
||||
exec.set_pending();
|
||||
|
|
|
@ -73,10 +73,12 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
|
|||
|
||||
if !task.is_extern {
|
||||
let attrs = &task.attrs;
|
||||
let cfgs = &task.cfgs;
|
||||
let context = &task.context;
|
||||
let stmts = &task.stmts;
|
||||
user_tasks.push(quote!(
|
||||
#(#attrs)*
|
||||
#(#cfgs)*
|
||||
#[allow(non_snake_case)]
|
||||
fn #name(#context: #name::Context) {
|
||||
use rtic::Mutex as _;
|
||||
|
|
|
@ -30,14 +30,19 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
|
|||
|
||||
let mut executor_allocations = Vec::new();
|
||||
|
||||
for (name, _) in app.software_tasks.iter() {
|
||||
for (name, task) in app.software_tasks.iter() {
|
||||
let exec_name = util::internal_task_ident(name, "EXEC");
|
||||
let new_n_args = util::new_n_args_ident(app.software_tasks[name].inputs.len());
|
||||
let cfgs = &task.cfgs;
|
||||
|
||||
executor_allocations.push(quote!(
|
||||
#(#cfgs)*
|
||||
let executor = ::core::mem::ManuallyDrop::new(rtic::export::executor::AsyncTaskExecutor::#new_n_args(#name));
|
||||
executors_size += ::core::mem::size_of_val(&executor);
|
||||
#exec_name.set_in_main(&executor);
|
||||
#(#cfgs)*
|
||||
{
|
||||
executors_size += ::core::mem::size_of_val(&executor);
|
||||
#exec_name.set_in_main(&executor);
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,10 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `#[cfg]` tags on hardware and software tasks.
|
||||
|
||||
## [v2.1.1] - 2024-03-13
|
||||
|
||||
### Fixed
|
||||
|
|
Loading…
Reference in a new issue