Compare commits

...

5 Commits

Author SHA1 Message Date
ee5da6812c implemented 2018-04-13 21:35:44 +02:00
763edd1900 read in type field 2018-04-13 21:28:02 +02:00
9558851e8b adopted to longer LED strip 2018-04-13 21:14:18 +02:00
69d26c3a46 add power on delay 2018-04-07 19:44:34 +02:00
0425710537 reset-sync 2018-04-07 19:12:55 +02:00
2 changed files with 128 additions and 306 deletions

255
c/prog.c
View File

@@ -24,7 +24,8 @@
#define MY_DEST_MAC5 0x00
#define DEFAULT_IF "enp5s0"
#define BUF_SIZ 1024
#define BUF_SIZ 1500
#define LED_CNT 360
int main(int argc, char *argv[])
{
@@ -84,240 +85,28 @@ int main(int argc, char *argv[])
/* Packet data */
if (mode == 0) {
for (i = 0; i < LED_CNT; i++) {
switch (i%3) {
case 0:
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
break;
case 1:
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
break;
case 2:
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
break;
}
}
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0x00;
sendbuf[tx_len++] = 0xff;
} else if (mode > 0 && mode < 4) {
for (i = 0; i< 60; i++) {
for (i = 0; i< LED_CNT; i++) {
switch (mode) {
case 1:
sendbuf[tx_len++] = 0xff;
@@ -337,13 +126,13 @@ int main(int argc, char *argv[])
}
}
} else if (mode == 4) {
for (i = 0; i< 3*60; i++) {
for (i = 0; i< 3*LED_CNT; i++) {
sendbuf[tx_len++] = 0x00;
}
} else if (mode == 5) {
for (i = 0; i< 3*60; i++) {
for (i = 0; i< 3*LED_CNT; i++) {
sendbuf[tx_len++] = 0xff;
}
} else if (mode == 6) {
@@ -351,7 +140,7 @@ sendbuf[tx_len++] = 0xff;
r = (unsigned char) atoi(argv[2]);
g = (unsigned char) atoi(argv[3]);
b = (unsigned char) atoi(argv[4]);
for (i = 0; i< 60; i++) {
for (i = 0; i< LED_CNT; i++) {
sendbuf[tx_len++] = r;
sendbuf[tx_len++] = g;
sendbuf[tx_len++] = b;

179
top.vhd
View File

@@ -6,7 +6,7 @@
-- Author : Mario Hüttel <mario.huettel@gmx.net>
-- Company :
-- Created : 2018-04-05
-- Last update: 2018-04-07
-- Last update: 2018-04-13
-- Platform :
-- Standard : VHDL'93/02
-------------------------------------------------------------------------------
@@ -36,59 +36,72 @@ entity top is
end entity top;
architecture RTL of top is
constant DELAYCNTVAL : integer := 100000; -- set to low value for
-- simulation
constant DEFMAC : std_logic_vector(47 downto 0) := x"00DEADBEEF00";
constant DELAYCNTVAL : integer := 100000; -- set to low value for
-- simulation
constant STARTUPDELAY : integer := 50000000;
constant DEFMAC : std_logic_vector(47 downto 0) := x"00DEADBEEF00";
constant PIPE_PKG : std_logic_vector(15 downto 0) := x"AA00";
constant FIN_PKG : std_logic_vector(15 downto 0) := x"55AA";
type smi_state_t is (IDLE, STROBE);
type smi_init_state_t is (SMI_POR, RESET, INIT, DELAY, INIT_COMPLETE);
type smi_init_state_t is (SMI_POR, SMI_PORDELAY, RESET, INIT, DELAY, INIT_COMPLETE);
type ws_send_t is (WS_READY, WS_SYNC, WS_RED, WS_GREEN, WS_BLUE, WS_PIPE, WS_POST);
type receive_t is (PRE, DESTMAC, HEADER, RECV, WAITFORACK);
type receive_t is (PRE, DESTMAC, SRCMAC, TYPEFIELD, RECV, WAITFORACK);
signal rst : std_logic;
signal dat_cnt_s : unsigned(3 downto 0);
signal sendstate : smi_state_t;
signal initstate : smi_init_state_t := SMI_POR;
signal after_delay_state : smi_init_state_t := RESET;
signal rst_rxtx : std_logic;
signal delaycounter : unsigned(19 downto 0);
signal smi_reg : std_logic_vector(4 downto 0);
signal smi_dat : std_logic_vector(15 downto 0);
signal smi_strb : std_logic;
signal smi_busy : std_logic;
signal sendstate : smi_state_t;
signal initstate : smi_init_state_t := SMI_POR;
signal rst_rxtx : std_logic;
signal delaycounter : unsigned(26 downto 0);
signal smi_reg : std_logic_vector(4 downto 0);
signal smi_dat : std_logic_vector(15 downto 0);
signal smi_strb : std_logic;
signal smi_busy : std_logic;
---
signal sof : std_logic;
signal eof : std_logic;
signal eth_dat : std_logic_vector(7 downto 0);
signal eth_strb : std_logic;
signal crc_valid : std_logic;
signal sof : std_logic;
signal eof : std_logic;
signal eth_dat : std_logic_vector(7 downto 0);
signal eth_strb : std_logic;
signal crc_valid : std_logic;
--
signal fifo_in : std_logic_vector(7 downto 0);
signal fifo_out : std_logic_vector(7 downto 0);
signal fifo_wr : std_logic;
signal fifo_rd : std_logic;
signal fifo_rst : std_logic;
signal fifo_full : std_logic;
signal fifo_empty : std_logic;
signal fifo_in : std_logic_vector(7 downto 0);
signal fifo_out : std_logic_vector(7 downto 0);
signal fifo_wr : std_logic;
signal fifo_rd : std_logic;
signal fifo_rst : std_logic;
signal fifo_full : std_logic;
signal fifo_empty : std_logic;
--
signal fifo_data_avail : std_logic;
signal fifo_data_ack : std_logic;
signal recv_state : receive_t;
signal mac : std_logic_vector(47 downto 0);
signal recv_cnt : integer range 0 to 15;
signal fifo_data_avail : std_logic;
signal fifo_data_ack : std_logic;
signal recv_state : receive_t;
signal mac : std_logic_vector(47 downto 0);
signal recv_cnt : integer range 0 to 15;
signal pkg_type : std_logic_vector(15 downto 0);
--
signal ws_busy : std_logic;
signal ws_strb : std_logic;
signal red : unsigned(7 downto 0);
signal green : unsigned(7 downto 0);
signal blue : unsigned(7 downto 0);
signal ws_busy : std_logic;
signal ws_strb : std_logic;
signal red : unsigned(7 downto 0);
signal green : unsigned(7 downto 0);
signal blue : unsigned(7 downto 0);
--
signal ws_state : ws_send_t;
signal ws_state : ws_send_t;
begin -- architecture RTL
rst <= not rst_hw;
reset_sync : process(clk, rst_hw) is
begin
if rst_hw = '0' then
rst <= '1';
elsif rising_edge(clk) then
if rst_hw = '1' then
rst <= '0';
end if;
end if;
end process reset_sync;
smi_1 : entity work.smi
generic map (
@@ -136,7 +149,7 @@ begin -- architecture RTL
STD_FIFO_1 : entity work.STD_FIFO
generic map (
DATA_WIDTH => 8,
FIFO_DEPTH => 256)
FIFO_DEPTH => 360*3)
port map (
CLK => clk,
RST => fifo_rst,
@@ -184,37 +197,41 @@ begin -- architecture RTL
begin
if rst = '1' then
smi_reg <= (others => '0');
smi_dat <= (others => '0');
smi_strb <= '0';
rst_rxtx <= '1';
initstate <= SMI_POR;
sendstate <= IDLE;
after_delay_state <= RESET;
delaycounter <= (others => '0');
smi_reg <= (others => '0');
smi_dat <= (others => '0');
smi_strb <= '0';
rst_rxtx <= '1';
initstate <= SMI_POR;
sendstate <= IDLE;
delaycounter <= (others => '0');
elsif rising_edge(clk) then
smi_strb <= '0';
rst_rxtx <= '1';
case initstate is
when SMI_POR =>
after_delay_state <= RESET;
delaycounter <= (others => '0');
initstate <= DELAY;
initstate <= SMI_PORDELAY;
when SMI_PORDELAY =>
delaycounter <= delaycounter + 1;
if delaycounter = STARTUPDELAY then
initstate <= RESET;
end if;
when RESET =>
after_delay_state <= INIT;
delaycounter <= (others => '0');
sendsmi((others => '0'), x"8000", DELAY);
sendsmi((others => '0'), x"8000", DELAY);
when DELAY =>
delaycounter <= delaycounter + 1;
if delaycounter = DELAYCNTVAL then -- Set to 100000
initstate <= after_delay_state;
initstate <= INIT;
end if;
when INIT =>
sendsmi((others => '0'), "00" & '1' & '1' & "000" & '1' & "00000000", INIT_COMPLETE);
when INIT_COMPLETE =>
initstate <= INIT_COMPLETE;
rst_rxtx <= '0';
if smi_busy = '0' then
rst_rxtx <= '0';
end if;
end case;
end if;
end process initphy;
@@ -232,6 +249,7 @@ begin -- architecture RTL
led1 <= '1';
led2 <= '1';
recv_cnt <= 0;
pkg_type <= (others => '0');
mac <= (others => '0');
elsif rising_edge(clk) then -- rising clock edge
fifo_rst <= '0';
@@ -240,6 +258,7 @@ begin -- architecture RTL
when PRE =>
if sof = '1' then
recv_cnt <= 0;
pkg_type <= (others => '0');
mac <= (others => '0');
recv_state <= DESTMAC;
led1 <= '1';
@@ -252,28 +271,35 @@ begin -- architecture RTL
elsif eth_strb = '1' then
recv_cnt <= recv_cnt + 1;
mac <= mac(39 downto 0) & eth_dat;
if recv_cnt = 5 then
if recv_cnt = 5 and (mac(39 downto 0) & eth_dat) = DEFMAC then
recv_cnt <= 0;
recv_state <= HEADER;
recv_state <= SRCMAC;
end if;
end if;
when HEADER =>
led1 <= '0';
when SRCMAC =>
if eof = '1' then
recv_state <= PRE;
elsif eth_strb = '1' then
recv_cnt <= recv_cnt + 1;
if recv_cnt = 7 then
if mac = DEFMAC then
recv_state <= RECV;
dat_cnt_s <= (others => '0');
else
recv_state <= PRE;
end if;
if recv_cnt 5 then -- SRC_MAC received
recv_state <= TYPEFIELD
recv_cnt <= 0;
end if;
end if;
when TYPEFIELD =>
if eof = '1' then
recv_state <= PRE;
elsif eth_strb = '1' then
recv_cnt <= recv_cnt + 1;
pkg_type <= pkg_type(7 downto 0) & eth_dat;
if recv_cnt = 1 then -- Type received
recv_cnt <= 0;
recv_state <= RECV;
end if;
end if;
when RECV =>
led2 <= '0';
if eth_strb = '1' and fifo_full /= '1' then
@@ -282,12 +308,19 @@ begin -- architecture RTL
dat_cnt_s <= dat_cnt_s +1;
end if;
if eof = '1' then
if crc_valid = '1' then -- or crc_valid = '0' then
recv_state <= WAITFORACK;
fifo_data_avail <= '1';
--led2 <= '0';
else
--led2 <= '1';
if crc_valid = '1' then
if pkg_type = PIPE_PKG then
-- Wait for further frames
-- This is also called with any
-- undefined TYPEFIELD
recv_state <= PRE;
elsif pkg_type = FIN_PKG then
fifo_data_avail <= '1';
recv_state <= WAITFORACK;
else
recv_state <= PRE;
end if;
else -- Eth Frame invalid. Discard
fifo_rst <= '1';
recv_state <= PRE;
end if;