User Tools

Site Tools


Sidebar

GitHub

CoreLib

Sponsors

This website is sponsored by

Notes

This wiki uses icons from icons8.com licensed under CC BY-ND 3.0.

proposals:helper:physical
Author Patrick Lehmann
Last Update 13.09.2016
Related Proposals

Physical Types and Operators

Add some text here…

package physical is
  type FREQ is range 0 to integer'high units
    Hz;
    kHz = 1000 Hz;
    MHz = 1000 kHz;
    GHz = 1000 MHz;
  end units;
 
  type BAUD is range 0 to integer'high units
    Bd;
    kBd = 1000 Bd;
    MBd = 1000 kBd;
    GBd = 1000 MBd;
  end units;
 
  type MEMORY is range 0 to integer'high units
    Byte;
    KiB = 1024 Byte;
    MiB = 1024 KiB;
    GiB = 1024 MiB;
  end units;
 
  -- vector data types
  type T_TIMEVEC is array(natural range <>) of time;
  type T_FREQVEC is array(natural range <>) of FREQ;
  type T_BAUDVEC is array(natural range <>) of BAUD;
  type T_MEMVEC  is array(natural range <>) of MEMORY;
 
  -- if true: TimingToCycles reports difference between expected and actual result
  constant C_PHYSICAL_REPORT_TIMING_DEVIATION    : boolean    := TRUE;
 
  -- conversion functions
  function to_time(f : FREQ)  return time;
  function to_freq(p : time)  return FREQ;
  function to_freq(br : BAUD)  return FREQ;
  function to_baud(str : string)  return BAUD;
 
  -- if-then-else
  function ite(cond : boolean; value1 : time;  value2 : time)    return time;
  function ite(cond : boolean; value1 : FREQ;  value2 : FREQ)    return FREQ;
  function ite(cond : boolean; value1 : BAUD;  value2 : BAUD)    return BAUD;
  function ite(cond : boolean; value1 : MEMORY; value2 : MEMORY) return MEMORY;
 
  -- min/ max for 2 arguments
  function tmin(arg1 : time; arg2 : time) return time;        -- Calculates: min(arg1, arg2) for times
  function fmin(arg1 : FREQ; arg2 : FREQ) return FREQ;        -- Calculates: min(arg1, arg2) for frequencies
  function bmin(arg1 : BAUD; arg2 : BAUD) return BAUD;        -- Calculates: min(arg1, arg2) for symbols per second
  function mmin(arg1 : MEMORY; arg2 : MEMORY) return MEMORY;  -- Calculates: min(arg1, arg2) for memory
 
  function tmax(arg1 : time; arg2 : time) return time;        -- Calculates: max(arg1, arg2) for times
  function fmax(arg1 : FREQ; arg2 : FREQ) return FREQ;        -- Calculates: max(arg1, arg2) for frequencies
  function bmax(arg1 : BAUD; arg2 : BAUD) return BAUD;        -- Calculates: max(arg1, arg2) for symbols per second
  function mmax(arg1 : MEMORY; arg2 : MEMORY) return MEMORY;  -- Calculates: max(arg1, arg2) for memory
 
  -- min/max/sum as vector aggregation
  function tmin(vec : T_TIMEVEC) return time;                -- Calculates: min(vec) for a time vector
  function fmin(vec : T_FREQVEC) return FREQ;                -- Calculates: min(vec) for a frequency vector
  function bmin(vec : T_BAUDVEC) return BAUD;                -- Calculates: min(vec) for a baud vector
  function mmin(vec : T_MEMVEC)  return MEMORY;              -- Calculates: min(vec) for a memory vector
 
  function tmax(vec : T_TIMEVEC) return time;                -- Calculates: max(vec) for a time vector
  function fmax(vec : T_FREQVEC) return FREQ;                -- Calculates: max(vec) for a frequency vector
  function bmax(vec : T_BAUDVEC) return BAUD;                -- Calculates: max(vec) for a baud vector
  function mmax(vec : T_MEMVEC)  return MEMORY;              -- Calculates: max(vec) for a memory vector
 
  function tsum(vec : T_TIMEVEC) return time;                -- Calculates: sum(vec) for a time vector
  function fsum(vec : T_FREQVEC) return FREQ;                -- Calculates: sum(vec) for a frequency vector
  function bsum(vec : T_BAUDVEC) return BAUD;                -- Calculates: sum(vec) for a baud vector
  function msum(vec : T_MEMVEC)  return MEMORY;              -- Calculates: sum(vec) for a memory vector
 
  -- convert standard types (NATURAL, REAL) to time (TIME)
  function fs2Time(t_fs : integer)    return time;
  function ps2Time(t_ps : integer)    return time;
  function ns2Time(t_ns : integer)    return time;
  function us2Time(t_us : integer)    return time;
  function ms2Time(t_ms : integer)    return time;
  function sec2Time(t_sec : integer)  return time;
 
  function fs2Time(t_fs : REAL)       return time;
  function ps2Time(t_ps : REAL)       return time;
  function ns2Time(t_ns : REAL)       return time;
  function us2Time(t_us : REAL)       return time;
  function ms2Time(t_ms : REAL)       return time;
  function sec2Time(t_sec : REAL)     return time;
 
  -- convert standard types (NATURAL, REAL) to period (TIME)
  function Hz2Time(f_Hz : natural)    return time;
  function kHz2Time(f_kHz : natural)  return time;
  function MHz2Time(f_MHz : natural)  return time;
  function GHz2Time(f_GHz : natural)  return time;
 
  function Hz2Time(f_Hz : REAL)       return time;
  function kHz2Time(f_kHz : REAL)     return time;
  function MHz2Time(f_MHz : REAL)     return time;
  function GHz2Time(f_GHz : REAL)     return time;
 
  -- convert standard types (NATURAL, REAL) to frequency (FREQ)
  function Hz2Freq(f_Hz : natural)    return FREQ;
  function kHz2Freq(f_kHz : natural)  return FREQ;
  function MHz2Freq(f_MHz : natural)  return FREQ;
  function GHz2Freq(f_GHz : natural)  return FREQ;
 
  function Hz2Freq(f_Hz : REAL)       return FREQ;
  function kHz2Freq(f_kHz : REAL)     return FREQ;
  function MHz2Freq(f_MHz : REAL)     return FREQ;
  function GHz2Freq(f_GHz : REAL)     return FREQ;
 
  -- convert physical types to standard type (REAL)
  function to_real(t : time;     scale : time)   return REAL;
  function to_real(f : FREQ;     scale : FREQ)   return REAL;
  function to_real(br : BAUD;    scale : BAUD)   return REAL;
  function to_real(mem : MEMORY; scale : MEMORY) return REAL;
 
  -- convert physical types to standard type (INTEGER)
  function to_int(t : time;     scale : time;   RoundingStyle : T_ROUNDING_STYLE := ROUND_TO_NEAREST) return integer;
  function to_int(f : FREQ;     scale : FREQ;   RoundingStyle : T_ROUNDING_STYLE := ROUND_TO_NEAREST) return integer;
  function to_int(br : BAUD;    scale : BAUD;   RoundingStyle : T_ROUNDING_STYLE := ROUND_TO_NEAREST) return integer;
  function to_int(mem : MEMORY; scale : MEMORY; RoundingStyle : T_ROUNDING_STYLE := ROUND_UP)         return integer;
 
  -- calculate needed counter cycles to achieve a given 1. timing/delay and 2. frequency/period
  function TimingToCycles(Timing : time; Clock_Period    : time; RoundingStyle : T_ROUNDING_STYLE := ROUND_UP) return natural;
  function TimingToCycles(Timing : time; Clock_Frequency : FREQ; RoundingStyle : T_ROUNDING_STYLE := ROUND_UP) return natural;
 
  function CyclesToDelay(Cycles : natural; Clock_Period    : time) return time;
  function CyclesToDelay(Cycles : natural; Clock_Frequency : FREQ) return time;
 
  -- convert and format physical types to STRING
  function to_string(t : time; precision : natural)     return string;
  function to_string(f : FREQ; precision : natural)     return string;
  function to_string(br : BAUD; precision : natural)    return string;
  function to_string(mem : MEMORY; precision : natural) return string;
end package;

Source: PoC.physical

General Comments

Supporters

proposals/helper/physical.txt · Last modified: 13.09.2016 19:47 by paebbels