- put general helper functions to utils_pkg
Committed on the Free edition of March Hare Software CVSNT Server. Upgrade to CVS Suite for more features and support: http://march-hare.com/cvsnt/ git-svn-id: http://moon:8086/svn/vhdl/trunk@580 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
@@ -123,14 +123,6 @@ package vga_types is
|
||||
);
|
||||
|
||||
-- Functions
|
||||
function NextPowerOfTwo(x : natural) return natural;
|
||||
function NextExpBaseTwo(x : natural) return natural;
|
||||
function GCD(a, b : natural) return natural;
|
||||
function LCM(a, b : natural) return natural;
|
||||
function DCM_PERIOD(f_sys_hz : natural) return real;
|
||||
function DCM_FREQ_M(f_sys_hz, f_vga_hz : natural) return natural;
|
||||
function DCM_FREQ_D(f_sys_hz, f_vga_hz : natural) return natural;
|
||||
|
||||
function to_color_t(x : unsigned) return color_t;
|
||||
function to_unsigned(x : color_t) return unsigned;
|
||||
|
||||
@@ -139,81 +131,6 @@ end vga_types;
|
||||
|
||||
package body vga_types is
|
||||
|
||||
function NextExpBaseTwo(x : natural) return natural is
|
||||
begin
|
||||
return natural(ceil(log2(real(x))));
|
||||
end NextExpBaseTwo;
|
||||
|
||||
function NextPowerOfTwo(x : natural) return natural is
|
||||
begin
|
||||
|
||||
return 2**NextExpBaseTwo(x);
|
||||
end NextPowerOfTwo;
|
||||
|
||||
function GCD(a, b : natural) return natural is
|
||||
variable aa : natural;
|
||||
variable bb : natural;
|
||||
begin
|
||||
aa := a;
|
||||
bb := b;
|
||||
while bb /= 0 loop
|
||||
if aa > bb then
|
||||
aa := aa - bb;
|
||||
else
|
||||
bb := bb - aa;
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
return aa;
|
||||
|
||||
end GCD;
|
||||
|
||||
function LCM(a, b : natural) return natural is
|
||||
begin
|
||||
|
||||
return (a * b)/GCD(a, b);
|
||||
|
||||
end LCM;
|
||||
|
||||
function DCM_FREQ_M(f_sys_hz, f_vga_hz : natural) return natural is
|
||||
variable f_sys_mhz : natural;
|
||||
variable f_vga_mhz : natural;
|
||||
variable m : natural;
|
||||
begin
|
||||
f_sys_mhz := f_sys_hz/1E6;
|
||||
f_vga_mhz := f_vga_hz/1E6;
|
||||
m := f_vga_mhz/GCD(f_sys_mhz, f_vga_mhz);
|
||||
|
||||
if m = 1 then
|
||||
m := 2;
|
||||
end if;
|
||||
|
||||
return m;
|
||||
|
||||
end DCM_FREQ_M;
|
||||
|
||||
function DCM_FREQ_D(f_sys_hz, f_vga_hz : natural) return natural is
|
||||
variable f_sys_mhz : natural;
|
||||
variable f_vga_mhz : natural;
|
||||
variable m : natural;
|
||||
variable d : natural;
|
||||
begin
|
||||
m := DCM_FREQ_M(f_sys_hz, f_vga_hz);
|
||||
f_sys_mhz := f_sys_hz/1E6;
|
||||
f_vga_mhz := f_vga_hz/1E6;
|
||||
d := m*f_sys_mhz/f_vga_mhz;
|
||||
|
||||
return d;
|
||||
|
||||
end DCM_FREQ_D;
|
||||
|
||||
function DCM_PERIOD(f_sys_hz : natural) return real is
|
||||
begin
|
||||
|
||||
return 1.0E9/real(f_sys_hz);
|
||||
|
||||
end DCM_PERIOD;
|
||||
|
||||
function to_color_t(x : unsigned) return color_t is
|
||||
variable result : color_t;
|
||||
begin
|
||||
|
||||
Reference in New Issue
Block a user