enum.sv 701 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
`default_nettype none

// Technically the value assignment could be anything, but most tools default to a 32-bit logic assigning MODE_A = 0 and MODE_B = 1
typedef enum {MODE_A, MODE_B} Mode_t;

typedef enum logic [1:0] {READ=2'd1, WRITE=2'd2, NONE=2'd0} Operation_t;

module Example(
    input logic rawMode,
    output logic [1:0] rawOperation
);

    Mode_t mode;
    Operation_t operation;

    // cast into a strongly typed variant
    assign mode = Mode_t'(rawMode);
    assign rawOperation = operation;

    always_comb begin
        case(mode)
            MODE_A: operation = READ;
            MODE_B: operation = WRITE;
            default: operation = NONE;
        endcase
    end

endmodule