А как вам такое решение?
Я создал двухмерный массив
Код
type packet_t is array (12 downto 0) of std_logic_vector(7 downto 0);
type packet_fifo_t is array (31 downto 0) of packet_t;
signal tx_mailbox_fifo : packet_fifo_t;
shared variable g_fifo_head_idx : integer range 0 to 255 := 0;
shared variable g_fifo_tail_idx : integer range 0 to 255 := 0;
В одном процесе я загружаю байты в очередную ячейку из РАМ
Код
when ST_RAM_TO_TX_BUF_3 =>
if (idx2 < 13) then
tx_mailbox_fifo(g_fifo_head_idx)(idx2) <= slave_data_out2;
idx2 := idx2 + 1;
else
--get ready the next fifo slot
g_fifo_head_idx := g_fifo_head_idx + 1;
if (g_fifo_head_idx > 31) then
g_fifo_head_idx := 0;
end if;
RamState_b <= ST_RAMB_IDLE;
end if;
В другом слежу за индексом
Код
TX_MAILBOX_FIFO_MANAGER: process (REG_CLK)
begin
if (rising_edge(REG_CLK)) then
--send previous message - g_fifo_head_idx incremeted by 1 in other process
if (g_fifo_tail_idx < g_fifo_head_idx) then
tx_buf_ready <= '1';
end if;
if (update_tail_idx = '1') then
tx_buf_ready <= '0';
g_fifo_tail_idx := g_fifo_tail_idx + 1;
if (g_fifo_tail_idx > 31) then
g_fifo_tail_idx := 0;
end if;
end if;
end if;
end process TX_MAILBOX_FIFO_MANAGER;
И есть процесс посылки
Код
when ST_TX_DATA => --send 13 byte of data
if (tx_byte_idx < 13) then
MSPI_WR_DATA <= X"00" & tx_mailbox_fifo(g_fifo_tail_idx)(tx_byte_idx);
MSPI_WR_START_TRIG <= '1'; --send a byte
tx_byte_idx := tx_byte_idx + 1;
NextState <= ST_TX_DATA;
McpState <= ST_WAIT_DONE;
else
MSPI_CS <= '1'; --chip select high
update_tail_idx <= '1';
NextState <= ST_MCP_IDLE;
McpState <= ST_REQ_TO_SEND0;
end if;