Compare commits
3 commits
ccd911dc1e
...
4d07ec3fa1
Author | SHA1 | Date | |
---|---|---|---|
Xiretza | 4d07ec3fa1 | ||
Xiretza | 40caa85d92 | ||
Xiretza | 24e3b11588 |
144
vhdl/splink.vhdl
144
vhdl/splink.vhdl
|
@ -22,61 +22,125 @@ entity splink is
|
||||||
end entity;
|
end entity;
|
||||||
|
|
||||||
architecture a of splink is
|
architecture a of splink is
|
||||||
signal driver_out : std_logic;
|
|
||||||
|
|
||||||
constant BITS_PER_LED: natural := 24;
|
constant BITS_PER_LED: natural := 24;
|
||||||
subtype color_t is std_logic_vector(BITS_PER_LED-1 downto 0);
|
subtype color_t is std_logic_vector(BITS_PER_LED-1 downto 0);
|
||||||
type strand_store_t is array(0 to MAX_STRAND_LEN) of color_t;
|
|
||||||
signal strand_store: strand_store_t;
|
|
||||||
|
|
||||||
signal led_addr : std_logic_vector(7 downto 0);
|
type led_data_t is record
|
||||||
signal current_color : color_t;
|
addr : std_logic_vector(7 downto 0);
|
||||||
|
current_color : color_t;
|
||||||
|
|
||||||
|
was_written : std_logic;
|
||||||
|
end record;
|
||||||
|
|
||||||
|
type led_data_arr_t is array(0 to NUM_STRANDS-1) of led_data_t;
|
||||||
|
signal led_data_arr : led_data_arr_t;
|
||||||
|
|
||||||
|
signal active_strand: natural range 0 to NUM_STRANDS-1;
|
||||||
|
signal num_pixels: natural range 1 to MAX_STRAND_LEN;
|
||||||
|
signal frame_number: unsigned(31 downto 0);
|
||||||
|
signal pixels_received: natural range 0 to MAX_STRAND_LEN-1;
|
||||||
|
|
||||||
|
type receive_state_t is (FRAME_NUM, STRAND_NUM, DATA, DROP);
|
||||||
|
signal receive_state : receive_state_t;
|
||||||
begin
|
begin
|
||||||
ws2812_inst: entity work.ws2812
|
driver_gen: for i in 0 to NUM_STRANDS-1 generate
|
||||||
generic map (
|
ws2812_inst: entity work.ws2812
|
||||||
NUM_LEDS => MAX_STRAND_LEN,
|
generic map (
|
||||||
COLOR_ORDER => "GRB",
|
NUM_LEDS => MAX_STRAND_LEN,
|
||||||
T_CLK => 12.5 ns,
|
COLOR_ORDER => "GRB",
|
||||||
|
T_CLK => 12.5 ns,
|
||||||
|
|
||||||
T0H => 0.35 us,
|
T0H => 0.35 us,
|
||||||
T0L => 0.8 us,
|
T0L => 0.8 us,
|
||||||
T1H => 0.7 us,
|
T1H => 0.7 us,
|
||||||
T1L => 0.6 us,
|
T1L => 0.6 us,
|
||||||
|
|
||||||
T_RES => 80 us
|
T_RES => 80 us
|
||||||
)
|
)
|
||||||
port map (
|
port map (
|
||||||
n_reset => not reset,
|
n_reset => not reset,
|
||||||
clk => clk,
|
clk => clk,
|
||||||
|
|
||||||
led_addr => led_addr,
|
led_addr => led_data_arr(i).addr,
|
||||||
|
|
||||||
led_red => current_color(7 downto 0),
|
led_red => led_data_arr(i).current_color(23 downto 16),
|
||||||
led_green => current_color(15 downto 8),
|
led_green => led_data_arr(i).current_color(15 downto 8),
|
||||||
led_blue => current_color(23 downto 16),
|
led_blue => led_data_arr(i).current_color(7 downto 0),
|
||||||
|
|
||||||
dout => driver_out
|
dout => drivers(i)
|
||||||
);
|
);
|
||||||
|
|
||||||
-- https://github.com/YosysHQ/yosys/issues/3360
|
writer: process(clk)
|
||||||
drivers <= (19 => driver_out, others => '0');
|
type strand_store_t is array(0 to MAX_STRAND_LEN-1) of color_t;
|
||||||
|
variable strand_store: strand_store_t;
|
||||||
|
begin
|
||||||
|
if rising_edge(clk) then
|
||||||
|
led_data_arr(i).current_color <= strand_store(to_integer(unsigned(led_data_arr(i).addr)));
|
||||||
|
|
||||||
writer: process(clk)
|
if udp_valid = '1' and receive_state = DATA and active_strand = i then
|
||||||
variable store_counter: natural range 0 to MAX_STRAND_LEN-1;
|
strand_store(pixels_received) := udp_data(23 downto 0);
|
||||||
|
|
||||||
|
if pixels_received = num_pixels - 1 and udp_last = '1' then
|
||||||
|
led_data_arr(i).was_written <= '1';
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if frame_done then
|
||||||
|
led_data_arr(i).was_written <= '0';
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
end process;
|
||||||
|
end generate;
|
||||||
|
|
||||||
|
process(led_data_arr)
|
||||||
|
begin
|
||||||
|
frame_done <= '1';
|
||||||
|
|
||||||
|
for i in 0 to NUM_STRANDS-1 loop
|
||||||
|
if not led_data_arr(i).was_written then
|
||||||
|
frame_done <= '0';
|
||||||
|
end if;
|
||||||
|
end loop;
|
||||||
|
end process;
|
||||||
|
|
||||||
|
fsm: process(clk)
|
||||||
begin
|
begin
|
||||||
if rising_edge(clk) then
|
if rising_edge(clk) then
|
||||||
frame_done <= '0';
|
if reset then
|
||||||
current_color <= strand_store(to_integer(unsigned(led_addr)));
|
receive_state <= STRAND_NUM;
|
||||||
|
elsif udp_valid then
|
||||||
if udp_valid then
|
|
||||||
strand_store(store_counter) <= udp_data(23 downto 0);
|
|
||||||
|
|
||||||
if udp_last then
|
if udp_last then
|
||||||
frame_done <= '1';
|
-- always resynchronize to start of packet
|
||||||
store_counter := 0;
|
receive_state <= STRAND_NUM;
|
||||||
elsif store_counter /= MAX_STRAND_LEN-1 then
|
|
||||||
store_counter := store_counter + 1;
|
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
|
case receive_state is
|
||||||
|
when STRAND_NUM =>
|
||||||
|
-- TODO udp_length, range check with MAX_STRAND_LEN
|
||||||
|
num_pixels <= MAX_STRAND_LEN;
|
||||||
|
|
||||||
|
-- FIXME bounds check
|
||||||
|
active_strand <= to_integer(unsigned(udp_data));
|
||||||
|
|
||||||
|
receive_state <= FRAME_NUM;
|
||||||
|
|
||||||
|
when FRAME_NUM =>
|
||||||
|
frame_number <= unsigned(udp_data);
|
||||||
|
|
||||||
|
pixels_received <= 0;
|
||||||
|
receive_state <= DATA;
|
||||||
|
|
||||||
|
when DATA =>
|
||||||
|
if pixels_received /= num_pixels - 1 then
|
||||||
|
pixels_received <= pixels_received + 1;
|
||||||
|
elsif not udp_last then
|
||||||
|
-- packet too long
|
||||||
|
receive_state <= DROP;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
when DROP =>
|
||||||
|
-- wait until udp_last
|
||||||
|
end case;
|
||||||
end if;
|
end if;
|
||||||
end if;
|
end if;
|
||||||
end process;
|
end process;
|
||||||
|
|
Loading…
Reference in a new issue