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
Create crate for Tock Registers #984
Conversation
Awesome, thanks a lot for the effort. Unfortunately, currently not much free time for hobby projects on my side, but I will definitely check this out once time permits. |
pub mod regs; | ||
|
||
#[macro_use] | ||
pub mod macros; |
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.
So the only thing I would want is to export the structs directly here by:
pub use regs::{ReadOny, WriteOnly, LocalRegisterCopy, Field, FieldValue}
Then if I use this crate it's enough to
extern crate tock_regs;
use tock_regs::ReadWrite;
Instead of
extern crate tock_regs;
use tock_regs::regs::ReadWrite;
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.
That seems like a good suggestion. I will do that.
@@ -293,8 +290,8 @@ impl<R: RegisterLongName> From<LocalRegisterCopy<u32, R>> for u32 { | |||
/// Specific section of a register. | |||
#[derive(Copy, Clone)] | |||
pub struct Field<T: IntLike, R: RegisterLongName> { | |||
mask: T, | |||
shift: u32, | |||
pub mask: T, |
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.
Why are these fields made pub
?
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.
So that other users can extend the register system. For example: https://github.com/brghena/tock-register-example/blob/master/src/cpu_regs.rs#L16
It is annoying that they have to public though. Do you have any suggestions on a better way to do this?
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.
Ok, I see. I don't think it possible to leak private items without getters
.
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.
Looks good 👍
arch/cortex-m3/src/systick.rs
Outdated
use kernel::common::StaticRef; | ||
use tock_regs::regs::{ReadOnly, ReadWrite}; |
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 it would be better to have the kernel crate depend on the new tock_regs crate, and re-export the regs they way they are now so we don't need all of these changes.
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.
What's the rationale for re-exporting them through the kernel? I'm happy to make the change, but I'm not sure why it would be preferable compared to directly referencing the tock_regs crate. Do we expect all libraries to be re-exported through the kernel in Tock?
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.
It would mean not having to change all these files every time we do this (since there is a motion to move the cells too), and it seems like all of these helper functions should come from the same place (and I think it makes sense to stick with them coming from the kernel trait).
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.
Do you mean that only the kernel imports the crate(tock_regs) and then exports as pub?
For example in lib.rs
:
extern crate tock_regs;
pub use tock_regs;
Then others just use use kernel::tock_regs::ReadOnly
?!
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.
No, the kernel lib.rs does whatever it has to so that chips use kernel::common::regs::ReadOnly
as they do now.
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 agree with Brad that centralizing the dependencies within Tock (by re-exporting through the kernel crate) is a good idea.
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.
Ah, makes sense!
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.
Idea: export tock_regs through the kernel.
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 agree with @bradjc suggestion to re-export.
d3509fa
to
b4b210c
Compare
Better @phil-levis and @bradjc? Now none of the crates have changed at all, except |
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.
Looks good
This looks good to me. Thanks so much for making those changes Amit!! |
The only real changes here are making the tock-register-interface crate, and the `Cargo.toml` and `lib.rs` file connections to it in `arch/` and `chips/`. Tested on Hail, where the Hail app still Hails.
2bfcb3e
to
9294bad
Compare
(rebased on master again since we had all the pulls today) |
#![no_std] | ||
|
||
extern crate tock_regs; | ||
|
||
pub use tock_regs::{register_bitfields, register_bitmasks}; |
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.
Is it really worth introducing another unstable
feature just for using extern macros
over #[macro_use(register_bitfields, register_bitmasks)]
?
OT: I don´t like this syntax for using macros confuses me with ordinary imports
but but .........
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.
Ok, grumble on using #![feature(use_extern_macros)]
because we are not consistent through the codebase. In all other places, we are using #[macro_use]
Don't they serve different purposes? I thought |
Yes, you right never mind (clearly haven´t done my homework) |
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.
My one comment is that if it isn't already there, putting Shane's name somewhere in the documentation would be useful. This was less important when it was internal but if the goal is for other people to use it too giving credit in the files is good.
da8cfca
Thanks for carving this out! Any plans to upload it to crates.io with a license? Would make it a bit easier to include it and reuse some snippets where needed in one's own crates :) |
Would pulling it from the gihub repo in cargo.toml not work for now? I'm not sure how everyone feels but I don't think we are ready to support that as a component on crates.io. |
Not at all, that is perfectly fine. The question was more towards the licensing. But I overlooked the license files in the tock root, and thought the project is unlicensed. My bad, nevermind 😅. |
Pull Request Overview
This PR creates a separate crate for the Tock register interface (named
tock-regs
) and moves the code totools/tock-register-interface/
. While this change affects many files throughout Tock, almost all of them are just changes to the import statement. Additionally,Cargo.toml
files have changed to reference the new crate, and documentation has been updated.The driver for this change is to allow other projects to use or extend Tock registers. In order to support this, the
mask
andshift
fields ofField
as well as themask
andvalue
fields ofFieldValue
are made public.An example of using this crate in an external project can be found here based off of examples from @niklasad1 and @andre-richter. This example both uses Tock registers and extends them with additional functionality. Unfortunately, the first build of this example repo takes a considerable amount of time (several minutes) because using the Tock registers crate requires a clone of the entire Tock repo. Subsequent builds are quick, however.
Closes #930.
Testing Strategy
Compiling all boards.
TODO or Help Wanted
None
Documentation Updated
/docs
, or no updates are required.Userland: Added/updated the application README, if needed.Formatting
make formatall
.