Make timer target value configurable

This commit is contained in:
2022-11-06 20:11:01 +01:00
parent c35376833f
commit 85112d9938
3 changed files with 24 additions and 8 deletions

View File

@@ -21,7 +21,7 @@ timer_status_addr: .word 0x000F000C
dmem_start_addr: .word 0x00000400 dmem_start_addr: .word 0x00000400
dmem_end_addr: .word 0x000004FC dmem_end_addr: .word 0x000004FC
priority_mask: .word 0xFFFFFF03 priority_mask: .word 0xFFFFFF03
xor_mask: .word 0xFFFFFFFF timer_target_value: .word 127 // change for simulation / real board
main: main:
// Initialize stack pointer to the end of the data memory // Initialize stack pointer to the end of the data memory
@@ -33,6 +33,7 @@ main:
ldr r0,>led_addr // LED addr ldr r0,>led_addr // LED addr
ldr r1,>timer_status_addr // Timer addr ldr r1,>timer_status_addr // Timer addr
ldr r3,>timer_counter_addr // Timer addr
// Init // Init
clr r9 // 0 if we are currently filling, 1 if we are currently flushing clr r9 // 0 if we are currently filling, 1 if we are currently flushing
@@ -42,6 +43,9 @@ main:
addi r4, 10 addi r4, 10
// Enable the timer... // Enable the timer...
ldr r2, >timer_target_value // target value
st32 r3, r2
clr r2 clr r2
addi r2, 0x3 // enable and repeat bit set addi r2, 0x3 // enable and repeat bit set
st32 r1, r2 st32 r1, r2

View File

@@ -3,6 +3,7 @@
library ieee; library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_1164.all;
use ieee.numeric_std.all; use ieee.numeric_std.all;
use ieee.math_real.all;
use work.lt16x32_global.all; use work.lt16x32_global.all;
use work.wishbone.all; use work.wishbone.all;
use work.config.all; use work.config.all;
@@ -23,11 +24,12 @@ entity wb_timer is
end wb_timer; end wb_timer;
architecture Behavioral of wb_timer is architecture Behavioral of wb_timer is
constant COUNT_MAX : integer := 128 - 1; constant TARGET_COUNT_DEFAULT : integer := 32 - 1;
signal ack : std_logic; signal ack : std_logic;
signal counter : integer range 0 to COUNT_MAX; signal counter : integer range 0 to 65535;
signal counter_target_value : integer range 0 to 65535;
signal enable : std_logic; signal enable : std_logic;
signal repeat : std_logic; signal repeat : std_logic;
@@ -51,7 +53,7 @@ begin
counter <= 0; counter <= 0;
else else
if enable = '1' then if enable = '1' then
if counter = COUNT_MAX then if counter = counter_target_value then
counter <= 0; counter <= 0;
else else
counter <= counter + 1; counter <= counter + 1;
@@ -79,7 +81,7 @@ begin
end if; end if;
-- Reset enable bit -- Reset enable bit
if counter = COUNT_MAX and repeat = '0' then if counter = counter_target_value and repeat = '0' then
enable <= '0'; enable <= '0';
end if; end if;
end if; end if;
@@ -93,6 +95,7 @@ begin
ack <= '0'; ack <= '0';
data_in <= (others => '0'); data_in <= (others => '0');
data_in_changed <= '0'; data_in_changed <= '0';
counter_target_value <= TARGET_COUNT_DEFAULT;
else else
data_in <= (others => '0'); data_in <= (others => '0');
data_in_changed <= '0'; data_in_changed <= '0';
@@ -102,6 +105,10 @@ begin
data_in <= dec_wb_dat(wslvi.sel,wslvi.dat)(2 downto 0); data_in <= dec_wb_dat(wslvi.sel,wslvi.dat)(2 downto 0);
data_in_changed <= '1'; data_in_changed <= '1';
end if; end if;
if wslvi.we='1' and wslvi.adr(2) = '0' then
counter_target_value <= to_integer(unsigned(dec_wb_dat(wslvi.sel,wslvi.dat)));
end if;
if ack = '0' then if ack = '0' then
ack <= '1'; ack <= '1';
@@ -115,7 +122,7 @@ begin
end if; end if;
end process; end process;
counter_vector <= std_logic_vector(to_unsigned(counter, counter_vector'length)); counter_vector <= std_logic_vector(to_unsigned(counter_target_value, counter_vector'length));
status_register(0) <= enable; -- enable status_register(0) <= enable; -- enable
status_register(1) <= repeat; -- repeat status_register(1) <= repeat; -- repeat
@@ -125,7 +132,7 @@ begin
else status_register when wslvi.adr(2) = '1' else status_register when wslvi.adr(2) = '1'
else (others => '0'); else (others => '0');
interrupt <= '1' when counter = COUNT_MAX else '0'; interrupt <= '1' when counter = counter_target_value else '0';
wslvo.ack <= ack; wslvo.ack <= ack;
wslvo.wbcfg <= wb_membar(memaddr, addrmask); wslvo.wbcfg <= wb_membar(memaddr, addrmask);

View File

@@ -86,11 +86,16 @@ BEGIN
wait for CLK_PERIOD*20; wait for CLK_PERIOD*20;
-- Change target value
data <= std_logic_vector(to_unsigned(1024, data'length));
generate_sync_wb_single_write(slvi,slvo,clk,data);
-- Read status register -- Read status register
data <= (others => '0'); data <= (others => '0');
generate_sync_wb_single_read(slvi,slvo,clk,data, ADR_OFFSET => 4); generate_sync_wb_single_read(slvi,slvo,clk,data, ADR_OFFSET => 4);
wait for CLK_PERIOD * 2; wait until interrupt = '1';
wait for CLK_PERIOD * 5;
assert false report "Simulation terminated!" severity failure; assert false report "Simulation terminated!" severity failure;
wait; wait;