Enum Types - 2025.2 English - UG901

Vivado Design Suite User Guide: Synthesis (UG901)

Document ID
UG901
Release Date
2025-12-05
Version
2025.2 English

Declare the Enumerated types in the following syntax:

enum [type] {enum_name1, enum_name2...enum_namex} identifier

The enum defaults to int if no type is specified. Following is an example:

enum {sun, mon, tues, wed, thurs, fri, sat} day_of_week;

This code generates an enum of int with seven values. These names receive values starting at 0 and incrementing, so sun = 0 and sat = 6.

To override the default values, use code as in the following example:

enum {sun=1, mon, tues, wed, thurs, fri, sat} day_of week;

In this case, sun is 1 and sat is 7.

The following is another example how to override defaults:

enum {sun, mon=3, tues, wed, thurs=10, fri=12, sat} day_of_week;

In this case, sun=0, mon=3, tues=4, wed=5, thurs=10, fri=12, and sat=13.

Typedef can also be used with enumerated types.

typedef enum {sun,mon,tues,wed,thurs,fri,sat} day_of_week; day_of_week my_day;

The preceding example defines a signal called my_day that is of type day_of_week. You can also specify a range of enums. For example, the preceding example can be specified as:

enum {day[7]} day_of_week;

This creates an enumerated type called day_of_week with seven elements as follows: day0, day1day6.

Following are other ways to use enumerated types:

enum {day[1:7]} day_of_week; // creates day1,day2...day7
enum {day[7] = 5} day_of_week; //creates day0=5, day1=6... day6=11