-
Notifications
You must be signed in to change notification settings - Fork 193
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
Allow initialization of resources in init
.
#43
Conversation
Hi Jonas
We are running on stm32f401re (uncleos), what exactly is the problem? (I mean the examples should be possible run with quite small modifications…)
Best
Per
On 03 Sep 2017, at 18:19, Jonas Schievink <notifications@github.com<mailto:notifications@github.com>> wrote:
Closes #37<https://github.com/japaric/cortex-m-rtfm/issues/37>
TODO:
* Open dependent PRs and get them merged
* Add an example (I cannot currently run any of the examples since I "only" have an stm32f401)
* Add a cfail test ensuring that init cannot access uninitialized resources (and possibly other tests)
* Figure out why I also cannot run these tests
* Simplify code, it's quite ugly
…________________________________
You can view, comment on, or merge this pull request online at:
https://github.com/japaric/cortex-m-rtfm/pull/43
Commit Summary
* Allow initialization of resources in `init`.
File Changes
* M Cargo.toml<https://github.com/japaric/cortex-m-rtfm/pull/43/files#diff-0> (9)
* M macros/Cargo.toml<https://github.com/japaric/cortex-m-rtfm/pull/43/files#diff-1> (3)
* M macros/src/trans.rs<https://github.com/japaric/cortex-m-rtfm/pull/43/files#diff-2> (105)
* M src/lib.rs<https://github.com/japaric/cortex-m-rtfm/pull/43/files#diff-3> (3)
Patch Links:
* https://github.com/japaric/cortex-m-rtfm/pull/43.patch
* https://github.com/japaric/cortex-m-rtfm/pull/43.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<https://github.com/japaric/cortex-m-rtfm/pull/43>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AD5naPSPE-aUa35p7YHswbqVc17TcD0Sks5setGSgaJpZM4PLOoU>.
{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/japaric/cortex-m-rtfm","title":"japaric/cortex-m-rtfm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/japaric/cortex-m-rtfm"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"[WIP] Allow initialization of resources in `init`. (#43)"}],"action":{"name":"View Pull Request","url":"https://github.com/japaric/cortex-m-rtfm/pull/43"}}}
|
I'm hitting #42, but managed to work around that by compiling in release mode (all examples compile, haven't run any yet). However, I still can't run the cfail tests on the host (x86-64 Linux) because there is still ARM inline assembly being used by
Travis seems to run these tests, too, so I don't understand why that works. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this, @jonas-schievink.
The implementation looks good to me but I left some nit comments. I agree that having a cfail test for this is a good idea.
macros/src/trans.rs
Outdated
let mut mod_items = vec![]; | ||
|
||
if !app.resources.is_empty() { | ||
// Write resources usable by `init`, if any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stray comment?
macros/src/trans.rs
Outdated
|
||
|
||
// Are there any resources that have an initializer? Those can be used by `init`. | ||
let has_initialized_resources = app.resources.iter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be expressed as app.resource.keys().any(|res| res.expr.is_some())
.
macros/src/trans.rs
Outdated
let mut fields = vec![]; | ||
let mut lifetime = None; | ||
let mut rexprs = vec![]; | ||
|
||
for (name, resource) in &app.resources { | ||
for (name, resource) in app.resources.iter() | ||
.filter(|&(_, res)| res.expr.is_some()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, I wonder if this would be more "correct" as app.resources.iter().filter_map(|(name, res)| res.map(|res| (name, rers)))
. It does look more complicated though. Basically what I'm trying to do is avoid having resource
be an "Option" that it's always Some. In any case, we won't unwrap the Option in this branch so maybe I'm just being pendantic ...
macros/src/trans.rs
Outdated
@@ -204,6 +213,46 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) { | |||
exprs.push(quote!(init::Resources::new())); | |||
} | |||
|
|||
let mut late_resources = vec![]; | |||
let has_late_resources = app.resources.iter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above: this could use any
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it just occurred to me that this could be done in a single pass over the resources by collecting the "early" resources and the "late" resources in vectors and then doing the appropriate codegen depending on whether the vector is empty or not.
Not sure which one would be easier to read.
macros/src/trans.rs
Outdated
}); | ||
|
||
late_resources.push(quote! { | ||
#_name = #krate::UntaggedOption { some: _late_resources.#name }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think UntaggedOption::some(..)
would be shorter. Would that require the const_fn
feature in user code though? Maybe it's already required by other generated code ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, #_name.some = _late_resources.#name
is even shorter. I'm not 100% if that has the exact semantics wrt to destructors. I think they are never run for any assignment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that require the const_fn feature in user code though?
Yes. That's the reason why I made those fields public in the first place.
Actually, #_name.some = _late_resources.#name is even shorter.
Yeah, I'll do this
I'm not 100% if that has the exact semantics wrt to destructors. I think they are never run for any assignment.
Running them would be unsafe (how does the drop glue know which variant was active before the assignment?), so it can't really happen automatically (dropping or assignment is always safe). At least that's how I understand it.
}, | ||
None => quote! { | ||
// Resource initialized in `init` | ||
static mut #_name: #krate::UntaggedOption<#ty> = #krate::UntaggedOption { none: () }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: as above this would be shorter as UntaggedOption::none()
src/lib.rs
Outdated
|
||
use core::u8; | ||
|
||
pub use rtfm_core::{Resource, Static, Threshold}; | ||
pub use cortex_m::asm::{bkpt, wfi}; | ||
pub use cortex_m_rtfm_macros::app; | ||
pub use untagged_option::UntaggedOption; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This re-export should be #[doc(hidden)]
as it is a not user facing implementation detail.
Fixes compilation on x86-64
The extended example tests that this actually works this time.
init
.init
.
Got rid of all iterators except a single call to |
I had forgotten about the @homunkulus r+ |
📌 Commit be1a27c has been approved by |
This needs a new release of rtfm-syntax before landing. I've redirected the dependency to my fork to work on this, the branch is now deleted. The other failures look like something else caught fire... |
💔 Test failed - status-travis |
Xargo v0.3.9 can't compile compiler-builtins. Could you pin the version to v0.3.8? That version works fine. |
rtfm-syntax v0.2.0 has been released |
@homunkulus r+ |
📌 Commit df85298 has been approved by |
💔 Test failed - status-travis |
The thumbv6m build failure is due to issue #42, which has already been fixed. We are seeing the issue here because we are cross compiling the stm32f103xx crate, which is a Cortex-M3 device crate, for thumbv6m. I guess we should use a Cortex-M0 device crate for the example when cross compiling to thumbv6m. I thought that As a horrible hack we could set the thumbv6m linker to the |
Horrible hack until we switch to a Cortex-M0 device crate that works with armv6.
I changed the linker to |
@homunkulus r+ |
📌 Commit a190da3 has been approved by |
☀️ Test successful - status-travis |
Zero cost stack overflow protection, take 2
this commit adds LLD support by removing all INFO sections. LLD kind of supports INFO in the form of NOLOAD but when the linker script contains NOLOAD sections LLD emits a binary with false `size` information: for example, it reported a fake increase of 20KB in .text and a fake increase of 1KB in .bss when compiling a program that only allocates a single Box. As the INFO sections are gone we can no longer support the stack overflow protection added in rtic-rs#43 so all the other related changes, like making _stack_start overridable, have been removed as well. If you want to continue using stack overflow protection you can stick to v0.3.x. As the .debug_gdb_scripts output section has been removed from the linker script these changes will only reliably support both LD and LLD if/when rust-lang/rust#49728 lands. closes rtic-rs#53
Closes #37
TODO:
(I cannot currently run any of the examples since I "only" have an stm32f401)init
cannot access uninitialized resources (and possibly other tests)