1

Can I have groups inside a struct?

pseudo-code:

typedef struct {
     input_group {
             logic a;
     }
     output_group {
             logic b;
     }
} my_signals_list
user2692669
  • 461
  • 8
  • 23

1 Answers1

3

Short answer: no.

If you want to have signals grouped like this, why not create a struct for the input group and a struct for your output group?

typedef struct {
  logic a;
} input_group_s;

typedef struct {
  logic b;
} output_group_s;

typedef struct {
  input_group_s input_group;
  output_group_s output_group;
} my_signals_list;

As Greg points out in the comments, you can also have nested struct definitions inside the main struct:

typedef struct {
  struct { logic a; } input_group;
  struct { logic b; } output_group;
} my_signals_list;

If you want to specify signals for a module in a nice encapsulated fashion, I would suggest using an interface, though.

Tudor Timi
  • 7,453
  • 1
  • 24
  • 53
  • I was thinking about the AXI specification: the signals are grouped instead of input/output seperate logic. – user2692669 Oct 09 '14 at 11:47
  • 2
    FYI: Nested structs are allowed: `typedef struct { struct { logic a; } input_group; struct { logic b; } output_group; } my_signals_list;` – Greg Oct 09 '14 at 14:49
  • @user2692669 You can have an individual interface for each AXI channel and then have those as members/ports of a bigger AXI interface. It seems a bit overkill, though, since you're probably always going to be connecting full interfaces, not just individual channels. – Tudor Timi Oct 09 '14 at 15:51
  • @Tudor can you update your answer with Greg's comment so it gets accepted? – user2692669 Oct 09 '14 at 17:07