Home / Learn Verilog / enum and typedef

enum and typedef

Named states and types.

In shortNamed states and types.

What's actually going on

enum FSMIDLERUNDONE
enum FSM

What it is

typedef enum logic [1:0] {IDLE, RUN, DONE} state_t; creates a named type whose values are named constants.

Why it matters

Readable FSMs and waveform names.

Mechanically speaking

Declare variables of the enum type.

Shows up in

  • Everyday RTL design
  • FPGA and ASIC projects
  • Testbenches and debugging

Try it

FSM with an enumVerilog: edit and run

Waveform viewers of full tools show the names.

Careful:This simulator runs the core of SystemVerilog (logic, always_ff, always_comb, enum, typedef, int, loops with int, break/continue, inside, immediate assert). Features shown only in the grey code box need a full simulator (Icarus -g2012, Verilator, Questa, VCS, Xcelium).

Check yourself

1. enum values are...