module hostcmd(input commclk
,input ready
,output [7:0] word_in
,output tx_frame_complete
,output word_available
,input word_read
);
function integer clog2;
	input integer value;
	begin
		value = value-1;
		for (clog2=0; value>0; clog2=clog2+1)
			value = value>>1;
	end
endfunction
parameter CMDWIDTH=64;
parameter CMDLENGTH=18;
localparam ADDRWIDTH=clog2(CMDLENGTH*CMDWIDTH/8);

reg [CMDWIDTH-1:0] hostcmds[CMDLENGTH-1:0];
reg [ADDRWIDTH:0] bytecnt=0;
wire word_available=ready&(bytecnt[ADDRWIDTH:3]<=CMDLENGTH-1);
wire tx_frame_complete=~word_available;

wire word_read;
always @(posedge commclk) begin
	bytecnt <= bytecnt+(ready&word_read);
end
assign word_in=bytecnt[2:0]==0 ? hostcmds[bytecnt[ADDRWIDTH-1:3]][7*8+7:7*8]
: bytecnt[2:0]==1 ? hostcmds[bytecnt[ADDRWIDTH-1:3]][6*8+7:6*8]
: bytecnt[2:0]==2 ? hostcmds[bytecnt[ADDRWIDTH-1:3]][5*8+7:5*8]
: bytecnt[2:0]==3 ? hostcmds[bytecnt[ADDRWIDTH-1:3]][4*8+7:4*8]
: bytecnt[2:0]==4 ? hostcmds[bytecnt[ADDRWIDTH-1:3]][3*8+7:3*8]
: bytecnt[2:0]==5 ? hostcmds[bytecnt[ADDRWIDTH-1:3]][2*8+7:2*8]
: bytecnt[2:0]==6 ? hostcmds[bytecnt[ADDRWIDTH-1:3]][1*8+7:1*8]
: bytecnt[2:0]==7 ? hostcmds[bytecnt[ADDRWIDTH-1:3]][0*8+7:0*8]
: 0;

initial begin
	hostcmds[0]={8'h0,24'h0,32'h0};
	hostcmds[1]={8'h0,24'h0,32'h0};
hostcmds[2]={8'h0,24'h3b,32'h1}; // mmcm_reset
hostcmds[3]={8'h0,24'h3b,32'h0}; // mmcm_reset
hostcmds[4]={8'h0,24'h31,32'h1}; // U2_iserdes_reset_r
hostcmds[5]={8'h0,24'h32,32'h1}; // U3_iserdes_reset_r
hostcmds[6]={8'h0,24'h31,32'h0}; // U2_iserdes_reset_r
hostcmds[7]={8'h0,24'h32,32'h0}; // U3_iserdes_reset_r
hostcmds[8]={8'h0,24'h30,32'h1}; // idelayctrl_reset
hostcmds[9]={8'h0,24'h30,32'h0}; // idelayctrl_reset
hostcmds[10]={8'h0,24'h43,32'h0}; // rf_go
hostcmds[11]={8'h0,24'h43,32'h1}; // rf_go
hostcmds[12]={8'h0,24'h7,32'h0}; // trace_reset
hostcmds[13]={8'h0,24'h2,32'h1}; // banyan_reset
hostcmds[14]={8'h0,24'h1,32'hf0}; // banyan_mask
hostcmds[15]={8'h0,24'h2,32'h0}; // banyan_reset
hostcmds[16]={8'h1,24'h20000,32'h0}; // trace_data
hostcmds[17]={8'h1,24'h20001,32'h0}; // 
//hostcmds[64]={8'h1,24'h20002,32'h0}; // 
//hostcmds[16]={8'h1,24'h10001,32'h0}; // 
//hostcmds[17]={8'h1,24'h10002,32'h0}; // 
//hostcmds[18]={8'h1,24'h10007,32'h0}; // 
//hostcmds[19]={8'h1,24'h10008,32'h0}; // 
//hostcmds[20]={8'h0,24'h11,32'h101}; // 
//hostcmds[21]={8'h0,24'h11,32'h48}; // 
//hostcmds[22]={8'h0,24'h11,32'h43}; // 
//hostcmds[23]={8'h0,24'h11,32'hf0}; // 
//hostcmds[24]={8'h0,24'h11,32'h0}; // 
//hostcmds[25]={8'h0,24'h11,32'h100}; // 
//hostcmds[26]={8'h1,24'h10007,32'h0}; // 
//hostcmds[27]={8'h1,24'h10008,32'h0}; // 
//hostcmds[28]={8'h0,24'h11,32'h101}; // 
//hostcmds[29]={8'h0,24'h11,32'h48}; // 
//hostcmds[30]={8'h0,24'h11,32'h43}; // 
//hostcmds[31]={8'h0,24'h11,32'hf0}; // 
//hostcmds[32]={8'h0,24'h11,32'h0}; // 
//hostcmds[33]={8'h0,24'h11,32'h100}; // 
//hostcmds[34]={8'h0,24'h11,32'h102}; // 
//hostcmds[35]={8'h0,24'h11,32'h80}; // 
//hostcmds[36]={8'h0,24'h11,32'h0}; // 
//hostcmds[37]={8'h0,24'h11,32'h192}; // 
//hostcmds[38]={8'h0,24'h11,32'hff}; // 
//hostcmds[39]={8'h0,24'h11,32'h100}; // 
//hostcmds[40]={8'h1,24'h14,32'hff}; // llspi_result
//hostcmds[41]={8'h0,24'h7,32'h0}; // trace_reset
//hostcmds[42]={8'h0,24'h23,32'hff}; // U18_spi_addr
//hostcmds[43]={8'h0,24'h29,32'hfffffff}; // U18_spi_data
//hostcmds[44]={8'h0,24'h21,32'h1}; // U18_spi_start
//hostcmds[45]={8'h0,24'h21,32'h0}; // U18_spi_start
//hostcmds[46]={8'h0,24'h34,32'h1}; // scanner_scan_trigger
//hostcmds[47]={8'h0,24'h34,32'h0}; // scanner_scan_trigger
//hostcmds[48]={8'h0,24'h2,32'h1}; // banyan_reset
//hostcmds[49]={8'h0,24'h1,32'hf0}; // banyan_mask
//hostcmds[50]={8'h0,24'h2,32'h0}; // banyan_reset
//hostcmds[51]={8'h0,24'h40001,32'h13}; // 
//hostcmds[52]={8'h0,24'h40002,32'h1c}; // 
//hostcmds[53]={8'h1,24'h16,32'h0}; // frequency_4xout
//hostcmds[54]={8'h1,24'h30001,32'h0}; // 
//hostcmds[55]={8'h1,24'h30002,32'h0}; // 
//hostcmds[56]={8'h1,24'h20001,32'h0}; // 
//hostcmds[57]={8'h1,24'h20002,32'h0}; // 
//hostcmds[58]={8'h1,24'h20003,32'h0}; // 
//hostcmds[59]={8'h1,24'h20004,32'h0}; // 
//hostcmds[60]={8'h0,24'h6,32'h1}; // llspi
//hostcmds[61]={8'h0,24'h6,32'h1}; // llspi
//hostcmds[62]={8'h1,24'h20000,32'h0}; // trace_data
//hostcmds[63]={8'h1,24'h20001,32'h0}; // 
//hostcmds[64]={8'h1,24'h20002,32'h0}; // 
//hostcmds[65]={8'h1,24'h20003,32'h0}; // 
//hostcmds[66]={8'h1,24'h20004,32'h0}; // 
//hostcmds[67]={8'h1,24'h20005,32'h0}; // 
//hostcmds[68]={8'h1,24'h20006,32'h0}; // 
//hostcmds[69]={8'h1,24'h20007,32'h0}; // 
//hostcmds[70]={8'h1,24'h20008,32'h0}; // 
//hostcmds[71]={8'h1,24'h20009,32'h0}; // 
//hostcmds[72]={8'h1,24'h2000a,32'h0}; // 
//hostcmds[73]={8'h1,24'h2000b,32'h0}; // 
//hostcmds[74]={8'h1,24'h2000c,32'h0}; // 
//hostcmds[75]={8'h1,24'h2000d,32'h0}; // 
//hostcmds[76]={8'h1,24'h2000e,32'h0}; // 
//hostcmds[77]={8'h1,24'h2000f,32'h0}; // 
//hostcmds[78]={8'h0,24'h6,32'hf}; // llspi
//hostcmds[79]={8'h0,24'h6,32'hf}; // llspi
//hostcmds[80]={8'h1,24'h20000,32'h0}; // trace_data
//hostcmds[81]={8'h1,24'h20001,32'h0}; // 
//hostcmds[82]={8'h1,24'h20002,32'h0}; // 
//hostcmds[83]={8'h1,24'h20003,32'h0}; // 
//hostcmds[84]={8'h1,24'h20004,32'h0}; // 
//hostcmds[85]={8'h1,24'h20005,32'h0}; // 
//hostcmds[86]={8'h1,24'h20006,32'h0}; // 
//hostcmds[87]={8'h1,24'h20007,32'h0}; // 
//hostcmds[88]={8'h1,24'h20008,32'h0}; // 
//hostcmds[89]={8'h1,24'h20009,32'h0}; // 
//hostcmds[90]={8'h1,24'h2000a,32'h0}; // 
//hostcmds[91]={8'h1,24'h2000b,32'h0}; // 
//hostcmds[92]={8'h1,24'h2000c,32'h0}; // 
//hostcmds[93]={8'h1,24'h2000d,32'h0}; // 
//hostcmds[94]={8'h1,24'h2000e,32'h0}; // 
//hostcmds[95]={8'h1,24'h2000f,32'h0}; // 
//hostcmds[96]={8'h0,24'h6,32'hf0}; // llspi
//hostcmds[97]={8'h0,24'h6,32'hf0}; // llspi
//hostcmds[98]={8'h1,24'h20000,32'h0}; // trace_data
//hostcmds[99]={8'h1,24'h20001,32'h0}; // 
//hostcmds[100]={8'h1,24'h20002,32'h0}; // 
//hostcmds[101]={8'h1,24'h20003,32'h0}; // 
//hostcmds[102]={8'h1,24'h20004,32'h0}; // 
//hostcmds[103]={8'h1,24'h20005,32'h0}; // 
//hostcmds[104]={8'h1,24'h20006,32'h0}; // 
//hostcmds[105]={8'h1,24'h20007,32'h0}; // 
//hostcmds[106]={8'h1,24'h20008,32'h0}; // 
//hostcmds[107]={8'h1,24'h20009,32'h0}; // 
//hostcmds[108]={8'h1,24'h2000a,32'h0}; // 
//hostcmds[109]={8'h1,24'h2000b,32'h0}; // 
//hostcmds[110]={8'h1,24'h2000c,32'h0}; // 
//hostcmds[111]={8'h1,24'h2000d,32'h0}; // 
//hostcmds[112]={8'h1,24'h2000e,32'h0}; // 
//hostcmds[113]={8'h1,24'h2000f,32'h0}; // 
//hostcmds[114]={8'h0,24'h6,32'hff}; // llspi
//hostcmds[115]={8'h0,24'h6,32'hff}; // llspi
//hostcmds[116]={8'h1,24'h20000,32'h0}; // trace_data
//hostcmds[117]={8'h1,24'h20001,32'h0}; // 
//hostcmds[118]={8'h1,24'h20002,32'h0}; // 
//hostcmds[119]={8'h1,24'h20003,32'h0}; // 
//hostcmds[120]={8'h1,24'h20004,32'h0}; // 
//hostcmds[121]={8'h1,24'h20005,32'h0}; // 
//hostcmds[122]={8'h1,24'h20006,32'h0}; // 
//hostcmds[123]={8'h1,24'h20007,32'h0}; // 
//hostcmds[124]={8'h1,24'h20008,32'h0}; // 
//hostcmds[125]={8'h1,24'h20009,32'h0}; // 
//hostcmds[126]={8'h1,24'h2000a,32'h0}; // 
//hostcmds[127]={8'h1,24'h2000b,32'h0}; // 
//hostcmds[128]={8'h1,24'h2000c,32'h0}; // 
//hostcmds[129]={8'h1,24'h2000d,32'h0}; // 
//hostcmds[130]={8'h1,24'h2000e,32'h0}; // 
//hostcmds[131]={8'h1,24'h2000f,32'h0}; // 
//hostcmds[132]={8'h0,24'h6,32'hf000}; // llspi
//hostcmds[133]={8'h0,24'h6,32'hf000}; // llspi
//hostcmds[134]={8'h1,24'h20000,32'h0}; // trace_data
//hostcmds[135]={8'h1,24'h20001,32'h0}; // 
//hostcmds[136]={8'h1,24'h20002,32'h0}; // 
//hostcmds[137]={8'h1,24'h20003,32'h0}; // 
//hostcmds[138]={8'h1,24'h20004,32'h0}; // 
//hostcmds[139]={8'h1,24'h20005,32'h0}; // 
//hostcmds[140]={8'h1,24'h20006,32'h0}; // 
//hostcmds[141]={8'h1,24'h20007,32'h0}; // 
//hostcmds[142]={8'h1,24'h20008,32'h0}; // 
//hostcmds[143]={8'h1,24'h20009,32'h0}; // 
//hostcmds[144]={8'h1,24'h2000a,32'h0}; // 
//hostcmds[145]={8'h1,24'h2000b,32'h0}; // 
//hostcmds[146]={8'h1,24'h2000c,32'h0}; // 
//hostcmds[147]={8'h1,24'h2000d,32'h0}; // 
//hostcmds[148]={8'h1,24'h2000e,32'h0}; // 
//hostcmds[149]={8'h1,24'h2000f,32'h0}; // 
//hostcmds[150]={8'h0,24'h6,32'h1}; // llspi
//hostcmds[151]={8'h0,24'h6,32'h1}; // llspi
//hostcmds[152]={8'h1,24'h20000,32'h0}; // trace_data
//hostcmds[153]={8'h1,24'h20001,32'h0}; // 
//hostcmds[154]={8'h1,24'h20002,32'h0}; // 
//hostcmds[155]={8'h1,24'h20003,32'h0}; // 
//hostcmds[156]={8'h1,24'h20004,32'h0}; // 
//hostcmds[157]={8'h1,24'h20005,32'h0}; // 
//hostcmds[158]={8'h1,24'h20006,32'h0}; // 
//hostcmds[159]={8'h1,24'h20007,32'h0}; // 
//hostcmds[160]={8'h1,24'h20008,32'h0}; // 
//hostcmds[161]={8'h1,24'h20009,32'h0}; // 
//hostcmds[162]={8'h1,24'h2000a,32'h0}; // 
//hostcmds[163]={8'h1,24'h2000b,32'h0}; // 
//hostcmds[164]={8'h1,24'h2000c,32'h0}; // 
//hostcmds[165]={8'h1,24'h2000d,32'h0}; // 
//hostcmds[166]={8'h1,24'h2000e,32'h0}; // 
//hostcmds[167]={8'h1,24'h2000f,32'h0}; // 
end
endmodule
