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

regz outputs padding instead of enum #402

Closed
oliverpool opened this issue Mar 6, 2025 · 1 comment · Fixed by #404
Closed

regz outputs padding instead of enum #402

oliverpool opened this issue Mar 6, 2025 · 1 comment · Fixed by #404

Comments

@oliverpool
Copy link
Contributor

oliverpool commented Mar 6, 2025

Reproducible example

When running the following command inside tools/regz:

zig build run -- --format atdf ../../port/microchip/avr/src/chips/ATmega328P.atdf

The end of the generated file looks like this:

                /// USART Control and Status Register C
                UCSR0C: mmio.Mmio(packed struct(u8) {
                    /// Clock Polarity
                    UCPOL0: u1,
                    /// Character Size - together with UCSZ2 in UCSR0B
                    UCSZ0: u2,
                    padding: u5,
                }),

Expected output

Whereas I believe it should be:

            /// USART Control and Status Register C
            UCSR0C: mmio.Mmio(packed struct(u8) {
                /// Clock Polarity
                UCPOL0: u1,
                /// Character Size - together with UCSZ2 in UCSR0B
                UCSZ0: u2,
                /// Stop Bit Select
                USBS0: COMM_STOP_BIT_SEL,
                /// Parity Mode Bits
                UPM0: COMM_UPM_PARITY_MODE,
                /// USART Mode Select
                UMSEL0: COMM_USART_MODE_2BIT,
            }),

Note that the padding is replaced by enums.

The enum cannot be found because the register-group has a different struct-id than the enum (due to having a different name).

Possible workarounds / fixes

change the name of the register-group to match the name of the module (drop the 0)

<register-group caption="USART" name="USART0">

It works because the following line reuses the struct-id

// special case but the most common, if there is only one register

pass parent_struct_id in the "child" case

Changing

try load_register_group_children(ctx, node, struct_id);

to

try load_register_group_children(ctx, node, parent_struct_id); // the enums are attached to the parent

works as well (but breaks the tests)


Since I just got started with microzig, I have no Idea what the proper solution should be and would appreciate any pointers!

@oliverpool
Copy link
Contributor Author

3rd fix: see the PR #404 (lookup among the parents)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant