]> jspc29.x-matter.uni-frankfurt.de Git - trbnet.git/commitdiff
SPI master multi-write mode, JM
authorhadeshyp <hadeshyp>
Thu, 3 Jan 2013 17:23:57 +0000 (17:23 +0000)
committerhadeshyp <hadeshyp>
Thu, 3 Jan 2013 17:23:57 +0000 (17:23 +0000)
gbe2_ecp3/trb_net16_ipu2gbe.vhd
special/spi_ltc2600.vhd

index 0f220a37b96456cce1107fd8af11d8ff0853a3e4..133789751b1208d14a5fe9dec1fdf157ab6aa0bc 100755 (executable)
@@ -433,6 +433,7 @@ begin
                -- gk 06.11.2012
                when RESET_FIFO =>
                        saveNextState <= SIDLE;
+                       state <= x"E";
                -- gk 29.03.10 new states during which the subsub bytes are saved
                when ADD_SUBSUB1 =>
                        state <= x"6";
index 57c3f70064b517c077b00d3c7ed32d7c5edbceaa..4d2d2b35f2897b8b301b97cfc58e6d0ac16d4fb7 100644 (file)
@@ -29,7 +29,7 @@ architecture spi_ltc2600_arch of spi_ltc2600 is
   type ram_t is array(0 to 15) of std_logic_vector(31 downto 0);
   signal ram : ram_t;
   
-  signal ram_addr : integer range 0 to 15;
+  signal ram_addr : integer range 0 to 31;
   signal ram_data : std_logic_vector(31 downto 0);
   signal ctrl_reg : std_logic_vector(31 downto 0);
   signal start    : std_logic;
@@ -44,7 +44,7 @@ architecture spi_ltc2600_arch of spi_ltc2600 is
   signal time_count : integer range 0 to 7;
   signal readback   : std_logic_vector(31 downto 0);
   
-  type fsm_t is (IDLE, WAIT_STATE, SET, FINISH);
+  type fsm_t is (IDLE, WAIT_STATE, SET, TOGGLE_CS, TOGGLE_CS_0, TOGGLE_CS_1, TOGGLE_CS_2,  FINISH);
   signal fsm_state : fsm_t;
   
 begin
@@ -60,20 +60,18 @@ begin
       start        <= '0';
       
       if BUS_WRITE_IN = '1' then
-        if BUS_ADDR_IN(4) = '0' then
-          ram(addr) <= BUS_DATA_IN;
+        if fsm_state = IDLE then
           BUS_ACK_OUT <= '1';
-        elsif BUS_ADDR_IN(0) = '1' then
-          if fsm_state = IDLE then
+          if BUS_ADDR_IN(4) = '0' then
+            ram(addr) <= BUS_DATA_IN;
+          elsif BUS_ADDR_IN(0) = '1' then
             ctrl_reg    <= BUS_DATA_IN;
-            BUS_ACK_OUT <= '1';
             start       <= '1';
-          else
-            BUS_BUSY_OUT <= '1';
+          else --if BUS_ADDR_IN(0) = '0' then
+            chipselect_reg <= BUS_DATA_IN(15 downto 0);
           end if;
-        else --if BUS_ADDR_IN(1) = '0' then
-          chipselect_reg <= BUS_DATA_IN(15 downto 0);
-          BUS_ACK_OUT <= '1';
+        else
+          BUS_BUSY_OUT <= '1';
         end if;
       end if;
 
@@ -105,7 +103,7 @@ begin
       
         if start = '1' then
           ram_addr   <= 0;
-          word_count <= to_integer(unsigned(ctrl_reg(3 downto 0)));
+          word_count <= to_integer(unsigned(ctrl_reg(4 downto 0)));
           bit_count  <= 31;
           time_count <= 7;
           fsm_state  <= WAIT_STATE;
@@ -135,7 +133,11 @@ begin
             ram_addr  <= ram_addr + 1;
             bit_count <= 31;
             if ram_addr /= word_count -1 then
-              fsm_state <= WAIT_STATE;
+              if ctrl_reg(7) = '0' then --one CS phase
+                fsm_state <= WAIT_STATE;
+              else                      --one CS per word
+                fsm_state <= TOGGLE_CS; 
+              end if;
             else
               fsm_state <= FINISH;
             end if;
@@ -144,6 +146,38 @@ begin
           fsm_state  <= WAIT_STATE;
           readback   <= readback(30 downto 0) & SPI_SDI_IN;          
         end if;
+      when TOGGLE_CS =>
+        if time_count = 0 and spi_sck = '0' then
+          time_count <= 7;
+          spi_sck    <= not spi_sck;
+          readback   <= readback(30 downto 0) & SPI_SDI_IN;          
+        elsif time_count = 0 and spi_sck = '1' then
+          fsm_state  <= TOGGLE_CS_0;
+        else
+          time_count   <= time_count - 1;
+        end if;
+      when TOGGLE_CS_0 =>
+         time_count <= time_count - 1;
+         if time_count = 0 then
+           spi_cs     <= x"ffff";
+           fsm_state  <= TOGGLE_CS_1;
+           time_count <= 7;
+         end if;  
+      when TOGGLE_CS_1 =>
+         time_count <= time_count - 1;
+         if time_count = 0 then
+           spi_cs  <= not chipselect_reg;
+           bit_count <= 31;
+           fsm_state <= WAIT_STATE;
+           time_count <= 7;
+         end if;  
+      when TOGGLE_CS_2 =>           
+         time_count <= time_count - 1;
+         if time_count = 0 then
+           spi_sck <= not spi_sck;
+           fsm_state <= WAIT_STATE;
+           time_count <= 7;
+         end if;
       when FINISH =>
         if time_count = 0 and spi_sck = '0' then
           time_count <= 7;