-
Notifications
You must be signed in to change notification settings - Fork 24
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
RFC: improving the generated output, to create structs ? #7
Comments
Take a look at #4 which I think is the same as this proposal except that the structs aren't extern. For accessing memory locations, that is how I am doing it in my repo zig-cortex as the amount of work to hand roll the structs is relatively small, but for this one I wasn't sure if it would be worth the effort until the proposal to deprecate the volatile keyword is resolved. Andrew said that the issue wouldn't be resolved or decided on until the next release cycle. Until then, I don't want to put in the effort since this repo was just to get another project of mine off the ground. Just the svd parsing needs a lot of work as the other vendor's file formats have many currently unsupported svd fields. I will spiff this whole thing up once the language stabilizes a little bit more. I would gladly accept a pull request implementing the struct representation, however. |
My 2 cents on this: I found both this project and https://github.com/lynaghk/svd2zig while I was trying having a go at Zig for the first time trying to use it to blink an LED on an STM32 board. I liked the packed struct approach (there's also a blogpost about it) but the "other" So I tried to make this repo's const std = @import("std");
const assert = std.debug.assert;
/// ACR
const ACR_val = packed struct {
/// LATENCY [0:2]
/// Latency
LATENCY: u3 = 0,
_unused3: u5 = 0,
/// PRFTEN [8:8]
/// Prefetch enable
PRFTEN: u1 = 0,
/// ICEN [9:9]
/// Instruction cache enable
ICEN: u1 = 0,
/// DCEN [10:10]
/// Data cache enable
DCEN: u1 = 0,
/// ICRST [11:11]
/// Instruction cache reset
ICRST: u1 = 0,
/// DCRST [12:12]
/// Data cache reset
DCRST: u1 = 0,
_unused13: u19 = 0,
};
test "correct size" {
assert(@sizeOf(ACR_val) == 4);
} The packed struct sums to 32 bits hence should have a size of 4, but it actually returns 5. So I think that packed struct have to be fixed in the compiler before they can be used reliably for MMIO. When it does I'd be happy to merge my branch and/or use it as a base for some different kind of output. |
@rbino I'm pretty sure you can't use |
@N00byEdge the I've actually spent some more time on the struct output stuff and I think I've found a workaround for the packed structs bug (namely, splitting the unused chunks at 8 bit boundaries). The result is here, since the new format is a major breaking change I created a fork but if @justinbalexander is ok with it I can open a pull request to upstream those changes. |
@rbino Oh okay, didn't read your blog post, just the code you posted here. Looks neat! |
@N00byEdge the blogpost is not mine actually, I just took that idea and used it to make |
@rbino Very cool that you got that to work. I am actually not as much of a fan of that API, personally but I'm glad it is working for you. I am used to C and like that Vim's autocompletion works on just text. I have started using zls, though and so maybe I will change my mind. I actually got tired of working on my main project in Zig because of the bugs and switched back to C. Looks like you are carrying the torch now! Maybe when the self-hosted compiler is up and running I will take a look at this again and setup more configuration options where you can select the API you desire. For now I will consider yours to the be the "most official repo". Thanks again for the pull requests and good luck! P.S. Are you sure all your bugs are ironed out? These "simple" bugs finally broke my will... |
struct is a first class citizen in zig, from looking other repos, the natural way to expose the mappings, seems, using const packed structs :
https://github.com/tralamazza/embedded_zig/blob/master/core_cm3.zig
or
https://github.com/tralamazza/embedded_zig/blob/master/stm32f10.zig
this probably will need to leverage the XML parsing.
The text was updated successfully, but these errors were encountered: