-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Debouncer_files * debouncer_de10files * Update README.md * Criado endereço para o gpio_deb --------- Co-authored-by: Renan Augusto Starke <[email protected]>
- Loading branch information
Showing
9 changed files
with
889 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
------------------------------------------------------- | ||
--! @file | ||
--! @brief RISCV Simple GPIO module | ||
-- RAM mapped general purpose I/O | ||
|
||
--! @Todo: Module should mask bytes (Word, half word and byte access) | ||
-- Daddress shoud be unsgined | ||
-- | ||
------------------------------------------------------- | ||
|
||
library ieee; | ||
use ieee.std_logic_1164.all; | ||
use ieee.numeric_std.all; | ||
|
||
entity debouncer is | ||
|
||
generic ( | ||
--! Chip selec | ||
SYS_FREQ : integer := 1; -- em megahertz | ||
COUNTT : integer := 5 -- | ||
); | ||
|
||
port( | ||
clk : in std_logic; | ||
rst : in std_logic; | ||
|
||
-- hardware input/output signals | ||
input : in std_logic; | ||
output : out std_logic | ||
|
||
); | ||
|
||
|
||
end entity debouncer; | ||
|
||
architecture RTL_gpio of debouncer is | ||
signal max_v : unsigned(31 downto 0); | ||
begin | ||
debouncer: process(clk, rst) | ||
variable count: unsigned(31 downto 0); | ||
begin | ||
if rst = '1' then | ||
--output <= '0'; | ||
--max_v <= to_unsigned(SYS_FREQ*COUNT, max_v'length); | ||
else | ||
if rising_edge(clk) then | ||
if (input = '1') then | ||
if max_v = "00000000000000000000000000000000" then | ||
--output <= '1'; | ||
else | ||
max_v <= max_v - 1; | ||
end if; | ||
else | ||
--max_v <= to_unsigned(SYS_FREQ*COUNT, max_v'length); | ||
--output <= '0'; | ||
end if; | ||
end if; | ||
end if; | ||
end process; | ||
debouncer2: process(clk, rst) | ||
variable count: unsigned(2 downto 0); | ||
variable vetor: unsigned(7 downto 0); | ||
begin | ||
if rst = '1' then | ||
output <= '0'; | ||
count := to_unsigned(0, count'length); | ||
vetor := to_unsigned(0, vetor'length); | ||
else | ||
if rising_edge(clk) then | ||
vetor(to_integer(count)) := input; | ||
count:= count +1; | ||
if ((vetor = "11111111") or (vetor = "00000000")) then -- se os ultimos 12 sao iguais | ||
output <= input; | ||
end if; | ||
end if; | ||
end if; | ||
end process; | ||
|
||
end architecture RTL_gpio; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
------------------------------------------------------- | ||
--! @file | ||
--! @brief RISCV Simple GPIO module | ||
-- RAM mapped general purpose I/O | ||
|
||
--! @Todo: Module should mask bytes (Word, half word and byte access) | ||
-- Daddress shoud be unsgined | ||
-- | ||
------------------------------------------------------- | ||
|
||
library ieee; | ||
use ieee.std_logic_1164.all; | ||
use ieee.numeric_std.all; | ||
|
||
entity debouncer is | ||
|
||
generic ( | ||
--! Chip selec | ||
SYS_FREQ : integer := 1; -- em megahertz | ||
COUNT : integer := 5 -- | ||
); | ||
|
||
port( | ||
clk : in std_logic; | ||
rst : in std_logic; | ||
|
||
-- hardware input/output signals | ||
input : in std_logic; | ||
output : out std_logic | ||
|
||
); | ||
|
||
|
||
end entity debouncer; | ||
|
||
architecture RTL_gpio of debouncer is | ||
signal max_v : unsigned(31 downto 0); | ||
begin | ||
debouncer: process(clk, rst) | ||
variable count: unsigned(31 downto 0); | ||
begin | ||
if rst = '1' then | ||
output <= '0'; | ||
--max_v <= to_unsigned(SYS_FREQ*COUNT, max_v'length); | ||
else | ||
if rising_edge(clk) then | ||
if (input = '1') then | ||
if max_v = "00000000000000000000000000000000" then | ||
--output <= '1'; | ||
else | ||
max_v <= max_v - 1; | ||
end if; | ||
else | ||
--max_v <= to_unsigned(SYS_FREQ*COUNT, max_v'length); | ||
--output <= '0'; | ||
end if; | ||
end if; | ||
end if; | ||
end process; | ||
debouncer2: process(clk, rst) | ||
variable count: unsigned(11 downto 0); | ||
variable vetor: unsigned(11 downto 0); | ||
begin | ||
if rst = '1' then | ||
output <= '0'; | ||
count := to_unsigned(0, count'length); | ||
else | ||
if rising_edge(clk) then | ||
count := count sll 1; | ||
vetor := (vetor and (not count)); | ||
if input = '1' then | ||
vetor := vetor or count; | ||
end if; | ||
if ((vetor = "111111111111") or (vetor = "000000000000")) then -- se os ultimos 12 sao iguais | ||
output <= input; | ||
end if; | ||
end if; | ||
end if; | ||
end process; | ||
|
||
end architecture RTL_gpio; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
------------------------------------------------------- | ||
--! @file | ||
--! @brief RISCV Simple GPIO module | ||
-- RAM mapped general purpose I/O | ||
|
||
--! @Todo: Module should mask bytes (Word, half word and byte access) | ||
-- Daddress shoud be unsgined | ||
-- | ||
------------------------------------------------------- | ||
|
||
library ieee; | ||
use ieee.std_logic_1164.all; | ||
use ieee.numeric_std.all; | ||
|
||
entity gpio_deb is | ||
generic ( | ||
--! Chip selec | ||
MY_CHIPSELECT : std_logic_vector(1 downto 0) := "10"; | ||
MY_WORD_ADDRESS : unsigned(15 downto 0) := x"0120" | ||
); | ||
|
||
port( | ||
clk : in std_logic; | ||
rst : in std_logic; | ||
|
||
-- Core data bus signals | ||
-- ToDo: daddress shoud be unsgined | ||
daddress : in unsigned(31 downto 0); | ||
ddata_w : in std_logic_vector(31 downto 0); | ||
ddata_r : out std_logic_vector(31 downto 0); | ||
d_we : in std_logic; | ||
d_rd : in std_logic; | ||
dcsel : in std_logic_vector(1 downto 0); --! Chip select | ||
-- ToDo: Module should mask bytes (Word, half word and byte access) | ||
dmask : in std_logic_vector(3 downto 0); --! Byte enable mask | ||
|
||
-- hardware input/output signals | ||
input : in std_logic_vector(31 downto 0); | ||
output : out std_logic_vector(31 downto 0) | ||
); | ||
end entity gpio_deb; | ||
|
||
architecture RTL of gpio_deb is | ||
signal result : std_logic_vector(31 downto 0); | ||
|
||
begin | ||
-- Input register | ||
process(clk, rst) | ||
begin | ||
if rst = '1' then | ||
ddata_r <= (others => '0'); | ||
else | ||
if rising_edge(clk) then | ||
if (d_rd = '1') and (dcsel = MY_CHIPSELECT) then | ||
if daddress(15 downto 0) =(MY_WORD_ADDRESS) then -- GPIO_ADDRESS | ||
ddata_r <= result; | ||
end if; | ||
end if; | ||
end if; | ||
end if; | ||
end process; | ||
|
||
-- Output register | ||
process(clk, rst) | ||
begin | ||
if rst = '1' then | ||
output <= (others => '0'); | ||
else | ||
if rising_edge(clk) then | ||
if (d_we = '1') and (dcsel = MY_CHIPSELECT)then | ||
--if daddress(15 downto 0) =(TIMER_BASE_ADDRESS + x"0000") then -- TIMER_ADDRESS | ||
if daddress(15 downto 0) =(MY_WORD_ADDRESS+x"01") then -- GPIO_ADDRESS | ||
-- ToDo: Simplify comparators | ||
-- ToDo: Maybe use byte addressing? | ||
-- x"01" (word addressing) is x"04" (byte addressing) | ||
-- Address comparator when more than one word is mapped here | ||
--if to_unsigned(daddress, 32)(8 downto 0) = MY_WORD_ADDRESS then | ||
--end if; | ||
output <= ddata_w; | ||
end if; | ||
end if; | ||
end if; | ||
end if; | ||
end process; | ||
|
||
deb2: entity work.debouncer | ||
generic map( | ||
SYS_FREQ => 1, | ||
COUNTT => 5 | ||
) | ||
port map( | ||
clk => clk, | ||
rst => rst, | ||
input => input(0), | ||
output => result(0) | ||
); | ||
|
||
|
||
|
||
|
||
-- debouncer: for i in 0 to 31 generate | ||
-- regs: entity work.debouncer | ||
-- generic map( | ||
-- SYS_FREQ => 1, | ||
-- COUNT => 5 | ||
-- ) | ||
-- port map( | ||
-- clk => clk, | ||
-- rst => rst, | ||
-- input => input(i), | ||
-- output => result(i) | ||
-- --input => input | ||
-- --output => result | ||
-- ); | ||
-- end generate; | ||
--debouncer2: | ||
|
||
end architecture RTL; |
Oops, something went wrong.