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

Add common enumeration types #5

Open
Paebbels opened this issue Jan 20, 2022 · 2 comments
Open

Add common enumeration types #5

Paebbels opened this issue Jan 20, 2022 · 2 comments

Comments

@Paebbels
Copy link
Member

Paebbels commented Jan 20, 2022

For verification components, common enumeration types should be upstreamed from specific VCs like SPI to the common package, so multiple VCs can reuse these types.

Proposed Additions

1. Common Enumeration Types:

type ClockPolarity is (HIGH_ACTIVE, LOW_ACTIVE);
type ClockPhase    is (RISING_EDGE, FALLING_EDGE);
type BitOrder      is (LSB_FIRST, MSB_FIRST);

2. Overloaded Operators:

function "xor" (Left : std_logic; Right: SpiClockPolarity) return std_logic;

Bodies:

 function "xor" (Left : std_logic; Right: SpiClockPolarity) return std_logic is
begin
  if Right = LOW_ACTIVE then
    return not Left; 
  else
    return Left;
  end if;
end function;  

3. Helper Functions and Converters:

function position(iterator: natural; length: natural; bitOrder : SpiBitOrder) return natural;
function to_sl(ClockPhase    : SpiClockPhase) return std_logic;
function to_sl(ClockPolarity : SpiClockPolarity) return std_logic;

Bodies:

function position(iterator: natural; length: natural; bitOrder : SpiBitOrder) return natural is
begin
  if bitOrder = LSB_FIRST then
    return iterator;              -- filling from left to right in a downto vector
  else
    return length - iterator - 1; -- filling from right to left in a downto vector
  end if;
end function;

function to_sl(ClockPhase : SpiClockPhase) return std_logic is
begin
  if ClockPhase = FALLING_EDGE then
    return '0';
  else
    return '1';
  end if;
end function;

function to_sl(ClockPolarity : SpiClockPolarity) return std_logic is
begin
  if ClockPolarity = LOW_ACTIVE then
    return '0';
  else
    return '1';
  end if;
end function;

Usecases

XOR Operator

SCLK <= SpiClock xor ClockPolarity;

Position Function

MOSI <= TransmitStim.Data(position(i, TransmitStim.Data'length, BitOrder)) after tpd_Clk_MOSI;

to_sl(..) Conversion

wait until SCLK = to_sl(ClockPhase);

Further Improvements

If OSVVM has a boolean to std_ulogic conversion, then some of the if..else-statements could be replaced by a function call.


/cc @Asif71

@JimLewis
Copy link
Member

Are these intended to be relative to TbUtilPkg in the OSVVM library? Maybe we should move them there.

@Paebbels
Copy link
Member Author

The idea is that these get a central place so VC don't define them per VC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants