📄 uart_package.vhd
字号:
-- 库声明
library IEEE;
use IEEE.STD_LOGIC_1164.all;
-- 包声明
PACKAGE UART_PACKAGE IS
-- 信号监测器状态
type dt_state is
(
dt_unlock, -- 未锁定状态
dt_lock -- 锁定状态
);
-- UART状态
type UART_STATE is
(
UART_IDLE,
UART_LOAD,
UART_SEND,
UART_END_SEND,
UART_RECV,
UART_END_RECV
);
-- 计数器计数范围
type BD_COUNT is range 65535 downto 0;
-- 9600波特率对应参数
constant BD9600_FPC : BD_COUNT := 5208;
constant BD9600_HPC : BD_COUNT := 2604;
-- 波特率测试参数
constant BDTEST_FPC : BD_COUNT := 10;
constant BDTEST_HPC : BD_COUNT := 5;
-- 奇偶校验规则定义
type PARITY is
(
NONE, -- 无奇偶校验
ODD, -- 奇校验
EVEN -- 偶校验
);
-- 类型声明
type test_vectors is array (0 to 10) of std_logic;
-- 无奇偶校验测试序列
constant test_si_none : test_vectors :=
('0', '1', '0', '1', '0', '1', '0', '1', '0', others => '1');
-- 奇校验测试序列
constant test_si_odd : test_vectors :=
('0', '1', '0', '1', '0', '1', '1', '1', '0', '1', others => '1');
-- 偶校验测试序列
constant test_si_even : test_vectors :=
('0', '1', '0', '1', '0', '1', '0', '1', '0', '0', others => '1');
-- 函数声明
function MultiXOR(
din : in std_logic_vector )
return std_logic;
END UART_PACKAGE;
-- 包体
PACKAGE BODY UART_PACKAGE IS
-- 函数实现
function MultiXOR(
din : in std_logic_vector )
return std_logic is
variable check : std_logic;
begin
check := din(din'LOW);
for i in 1 to (din'HIGH) loop
check := check xor din(i);
end loop;
return check;
end MultiXOR;
END UART_PACKAGE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -