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

External register packed struct bit-order is incorrect #111

Closed
benoitdenkinger opened this issue May 23, 2024 · 3 comments
Closed

External register packed struct bit-order is incorrect #111

benoitdenkinger opened this issue May 23, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@benoitdenkinger
Copy link

Hello,

I'm using external register in SystemRDL. The regblock plugin generates packed structure for external registers. For example:

From SystemRDL description:

    reg {
        desc = "UART live status register";
        field {
            desc = "TX buffer is full";
            sw = r;
            hw = rw;
            we = true;
        } txfull[0:0] = 0x0;
        field {
            desc = "RX buffer is full";
            sw = r;
            hw = rw;
            we = true;
        } rxfull[1:1] = 0x0;
        field {
            desc = "TX FIFO is empty";
            sw = r;
            hw = rw;
            we = true;
        } txempty[2:2] = 0x1;
        field {
            desc = "TX FIFO is empty and all bits have been transmitted";
            sw = r;
            hw = rw;
            we = true;
        } txidle[3:3] = 0x1;
        field {
            desc = "RX is idle";
            sw = r;
            hw = rw;
            we = true;
        } rxidle[4:4] = 0x1;
        field {
            desc = "RX FIFO is empty";
            sw = r;
            hw = rw;
            we = true;
        } rxempty[5:5] = 0x1;
    } external status @ 0x10;

I get in the regblock package:

    typedef struct packed {
        logic txfull;
        logic rxfull;
        logic txempty;
        logic txidle;
        logic rxidle;
        logic rxempty;
        logic [25:0] _reserved_31_6;
    } uart_INTF_d878ad62__status__external__fields__in_t;

I have problem with this because I believe the bit order of the status register is not the one I expect. txfull is placed at the MSB in a packed array struct, but from my SystemRDL code I'm expecting it to be at the LSB. The generated code is also misleading as there is a reserved space _reserved_31_6 but it does not correspond to the 6 to 31 bit range when assigning the struct to a logic 32 bits variable.

Am I missing something or is there indeed a problem here?

@benoitdenkinger
Copy link
Author

If I revert the packed structure order I indeed get the behavior I expect:

    typedef struct packed {
        logic [25:0] _reserved_31_6;
        logic rxempty;
        logic rxidle;
        logic txidle;
        logic txempty;
        logic rxfull;
        logic txfull;
    } uart_INTF_d878ad62__status__external__fields__in_t;

I'll implement this in my fork, let me know if this aligns with your vision and I'll propose a PR.

@amykyta3 amykyta3 added the bug Something isn't working label Dec 13, 2024
@amykyta3 amykyta3 changed the title External registers packed struct External register packed struct bit-order is incorrect Dec 20, 2024
@amykyta3
Copy link
Member

Thanks for pointing this out! Will be fixed in the upcoming release.

@amykyta3
Copy link
Member

Implemented in v0.23.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants