📄 p_altst.vhd
字号:
-----------------------------------------------------------------------
--
-- Original Code Copyright (c) 1999 by Esperan. All rights reserved.
-- www.esperan.com
--
-- This source file may be used and distributed without restriction
-- provided that this copyright statement is not removed from the file
-- and that any derivative work contains this copyright notice.
--
-- Esperan VHDL Alarm Clock Lab Exercise Design V5.0
--
-- P_altst.vhd
-- Package defining procedures used in the testbench for the
-- Alarm Clock Controller block (T_a_fsm.vhd)
--
----------------------------------------------------
Library IEEE;
use IEEE.Std_Logic_1164.all;
use std.textio.all;
------------------------------------------------------------------------
-- Package Declaration
------------------------------------------------------------------------
package P_ALARM_TEST is
-- Constant for the clock period we will use
constant PERIOD : time := 20 ns;
-- Constants to determine time for a keypress
-- and time between keypresses
constant KEYPRESS : time := 2 * PERIOD;
constant KEYOFF : time := 5 * PERIOD;
-- This function converts std_logic to character so the standard
-- write routine for character can be used
function STDU2CHAR ( -- complete function declaration
------------------------------------------------------------------------
-- The following procedures perform the actions required of the commands
-- SHALM, SETAL, SETTI, COUNT and KTOUT
------------------------------------------------------------------------
procedure DO_SHALM( ); -- fill in procedure declaration
procedure DO_SETAL(SETTING: in string(1 to 4);
signal KEY : out std_logic_vector(3 downto 0);
signal ALARM_BUTTON: out std_logic);
procedure DO_SETTI( ); -- fill in procedure declaration
procedure DO_COUNT(CYCLES: in character);
procedure DO_KTOUT( ); -- fill in procedure declaration
end P_ALARM_TEST;
------------------------------------------------------------------------
-- Package Body Declaration
------------------------------------------------------------------------
package body P_ALARM_TEST is
------------------------------------------------------------------------
-- STDU2CHAR type conversion function
------------------------------------------------------------------------
function STDU2CHAR ( -- complete function declaration
-- Write a function to convert the values 1 and 0 of
-- type std_logic to the equivalent character values
-- If std_logic input is not 1 or 0 then output "-"
end STDU2CHAR;
------------------------------------------------------------------------
-- CHAR2INT type conversion function
--
-- Define this function in package body but not in package - only visible
-- to definitions within package body
------------------------------------------------------------------------
function CHAR2INT (CHAR : character) return integer is
variable INT : integer range 0 to 10;
begin
case CHAR is
when '0' => INT := 0;
when '1' => INT := 1;
when '2' => INT := 2;
when '3' => INT := 3;
when '4' => INT := 4;
when '5' => INT := 5;
when '6' => INT := 6;
when '7' => INT := 7;
when '8' => INT := 8;
when '9' => INT := 9;
when others =>
end case;
return INT;
end CHAR2INT;
function CHAR2VEC (CHAR : character) return std_logic_vector is
variable VEC : std_logic_vector(3 downto 0);
begin
case CHAR is
when '0' => VEC := "0000";
when '1' => VEC := "0001";
when '2' => VEC := "0010";
when '3' => VEC := "0011";
when '4' => VEC := "0100";
when '5' => VEC := "0101";
when '6' => VEC := "0110";
when '7' => VEC := "0111";
when '8' => VEC := "1000";
when '9' => VEC := "1001";
when others =>
end case;
return VEC;
end CHAR2VEC;
------------------------------------------------------------------------
-- SHALM command
------------------------------------------------------------------------
procedure DO_SHALM( -- fill in the procedure declaration
) is
begin
-- Write a procedure to simulate pressing down the alarm button.
-- Hold the alarm down for the KEYPRESS time period and
-- then release it for the KEYOFF time period
end DO_SHALM;
------------------------------------------------------------------------
-- SETAL command
------------------------------------------------------------------------
procedure DO_SETAL(SETTING: in string(1 to 4);
signal KEY : out std_logic_vector(3 downto 0);
signal ALARM_BUTTON: out std_logic) is
begin
for I in 1 to 4 loop
KEY <= CHAR2VEC(SETTING(I));
wait for KEYPRESS;
KEY <= "1010";
wait for KEYOFF;
end loop;
ALARM_BUTTON <= '1';
wait for KEYPRESS;
ALARM_BUTTON <= '0';
wait for KEYOFF;
end DO_SETAL;
------------------------------------------------------------------------
-- SETTI command
------------------------------------------------------------------------
procedure DO_SETTI(( -- fill in procedure declaration
) is
begin
-- Write a procedure to simulate entering the SETTING value;
-- hold each KEY value for the KEYPRESS interval then release
-- (KEY="1010") for the KEYOFF interval before entering the next value.
-- When SETTING value is entered, press time button for
-- the KEYPRESS interval and then release for the KEYOFF interval
end DO_SETTI;
------------------------------------------------------------------------
-- COUNT command
------------------------------------------------------------------------
procedure DO_COUNT(CYCLES: in character) is
begin
wait for (CHAR2INT(CYCLES))*PERIOD;
end DO_COUNT;
------------------------------------------------------------------------
-- KTOUT command
------------------------------------------------------------------------
procedure DO_KTOUT( -- fill in procedure declaration
) is
begin
-- Write a procedure to simulate holding a key down the
-- KEYPRESS interval then releasing it and waiting for
-- 15 KEYOFF intervals.
end DO_KTOUT;
end P_ALARM_TEST;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -