Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for #[cfg] on #[monotonic] #664

Closed
ia0 opened this issue Nov 8, 2022 · 4 comments · Fixed by #691
Closed

Support for #[cfg] on #[monotonic] #664

ia0 opened this issue Nov 8, 2022 · 4 comments · Fixed by #691
Labels
#[cfg] Issues related to #[cfg] attributes

Comments

@ia0
Copy link

ia0 commented Nov 8, 2022

I would like to feature-gate the monotonic type to only have it in some builds and not others. I tried the following but it doesn't work:

    #[cfg(feature = "log")]
    #[monotonic(binds = SysTick, default = true)]
    type MonoSysTick = Systick<100>;

Then in init I have:

        (
            Shared { ... },
            Local { ... },
            #[cfg(not(feature = "log"))]
            init::Monotonics(),
            #[cfg(feature = "log")]
            init::Monotonics(systick),
        )

Here's what I get when building without the feature (it works with the feature):

error[E0412]: cannot find type `MonoSysTick` in module `super::super`
  --> src/main.rs:51:10
   |
51 |     type MonoSysTick = Systick<100>;
   |          ^^^^^^^^^^^ not found in `super::super`

error[E0412]: cannot find type `Systick` in this scope
  --> src/main.rs:51:24
   |
51 |     type MonoSysTick = Systick<100>;
   |                        ^^^^^^^ not found in this scope

error[E0061]: this struct takes 1 argument but 0 arguments were supplied
   --> src/main.rs:117:13
    |
117 |             init::Monotonics(),
    |             ^^^^^^^^^^^^^^^^-- an argument is missing
    |

Is this something that might eventually get support for?

@AfoHT AfoHT added the #[cfg] Issues related to #[cfg] attributes label Nov 16, 2022
@David-OConnor
Copy link

Scope goes beyond Monotonic. Also applies to Shared and Local. I also would like this.

@korken89
Copy link
Collaborator

korken89 commented Jan 22, 2023

Hi,

The cfg support in RTIC 1 is broken and on the path of wont-fix.
This usr case is already supported in (under development) RTIC 2, so I think it's best to go for that

@korken89 korken89 reopened this Jan 22, 2023
@AfoHT
Copy link
Contributor

AfoHT commented Jan 22, 2023

As an experiment to see what can be done for RTIC 1 I've created #691

The obvious limitation, as shown in examples/cfg-monotonic, is that rtic-syntax does not know what is cfg-ed out, and thus "correctly" refuses code that uses the same type, or same interrupt. Might work for other cases, here I hope for your help to see how your usecases might be supported :)

From the example, showing the rtic-syntax errors

    // A monotonic timer to enable scheduling in RTIC
    #[cfg(feature = "killmono")]
    #[monotonic(binds = SysTick, default = true)]
    type MyMono = Systick<100>; // 100 Hz / 10 ms granularity

    // Not allowed by current rtic-syntax:
    // error: `#[monotonic(...)]` on a specific type must appear at most once
    //   --> examples/cfg-monotonic.rs:23:10
    //    |
    // 23 |     type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
    //    |          ^^^^^^
    // #[monotonic(binds = SysTick, default = true)]
    // type MyMono = Systick<100>; // 100 Hz / 10 ms granularity

    // Not allowed by current rtic-syntax:
    // error: this interrupt is already bound
    //   --> examples/cfg-monotonic.rs:31:25
    //    |
    // 31 |     #[monotonic(binds = SysTick, default = true)]
    //    |                         ^^^^^^^
    // #[monotonic(binds = SysTick, default = true)]
    // type MyMono2 = DwtSystick<100>; // 100 Hz / 10 ms granularity

@ia0
Copy link
Author

ia0 commented Jan 22, 2023

here I hope for your help to see how your usecases might be supported

As original author of this issue, my usecase doesn't exist anymore (I moved out of RTIC for different reasons). But for reference, my original usecase was: Use monotonic for defmt::timestamp! and thus only use it when logging is enabled. The cfg would have been something like #[cfg(feature = "defmt")]. And in the init task I would call defmt::timestamp! on monotonics::now(), gated by feature = "defmt".

@bors bors bot closed this as completed in a601c6e Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#[cfg] Issues related to #[cfg] attributes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants