data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v
1: b'%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:29: Cannot find include file: sys.h\n`include "sys.h" // system level definition file which contains the  \n         ^~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/458737381/src/verilog-parser/tests,data/full_repos/permissive/458737381/sys.h\n             data/full_repos/permissive/458737381/src/verilog-parser/tests,data/full_repos/permissive/458737381/sys.h.v\n             data/full_repos/permissive/458737381/src/verilog-parser/tests,data/full_repos/permissive/458737381/sys.h.sv\n             sys.h\n             sys.h.v\n             sys.h.sv\n             obj_dir/sys.h\n             obj_dir/sys.h.v\n             obj_dir/sys.h.sv\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:31: Cannot find include file: iop.h\n`include        "iop.h" \n                ^~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:63: Define or directive not defined: \'`IOB_CPU_WIDTH\'\n   input [`IOB_CPU_WIDTH-1:0]     cpx_iob_grant_cx2;\n          ^~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:67: Define or directive not defined: \'`IOB_CPU_WIDTH\'\n   input [`IOB_CPU_WIDTH-1:0]     int_buf_cpx_req;\n          ^~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:68: Define or directive not defined: \'`IOB_CPU_WIDTH\'\n   input [`IOB_CPU_WIDTH-1:0]     io_buf_cpx_req;\n          ^~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:69: Define or directive not defined: \'`IOB_CPU_WIDTH\'\n   input [`IOB_CPU_WIDTH-1:0]     iob_cpx_req_next;\n          ^~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:86: Define or directive not defined: \'`IOB_IO_BUF_INDEX\'\n   input [`IOB_IO_BUF_INDEX:0]     io_buf_tail_s;\n          ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:86: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\n   input [`IOB_IO_BUF_INDEX:0]     io_buf_tail_s;\n                           ^\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:87: Define or directive not defined: \'`IOB_IO_BUF_INDEX\'\n   output [`IOB_IO_BUF_INDEX:0]    io_buf_head_f;\n           ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:87: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\n   output [`IOB_IO_BUF_INDEX:0]    io_buf_head_f;\n                            ^\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:92: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n   output [`IOB_INT_BUF_INDEX-1:0] int_buf_tail_ptr;\n           ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:93: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n   output [`IOB_INT_BUF_INDEX-1:0] int_buf_head_ptr;\n           ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:97: Define or directive not defined: \'`IOB_IO_BUF_INDEX\'\n   output [`IOB_IO_BUF_INDEX-1:0]  io_buf_head_ptr;\n           ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:101: Define or directive not defined: \'`IOB_CPU_WIDTH\'\n   wire [`IOB_CPU_WIDTH-1:0]     cpx_buf_full;\n         ^~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:102: Define or directive not defined: \'`IOB_CPU_WIDTH\'\n   wire [`IOB_CPU_WIDTH-1:0]     cpx_iob_grant;\n         ^~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:104: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n   wire [`IOB_INT_BUF_INDEX:0]     int_buf_tail;\n         ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:104: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\n   wire [`IOB_INT_BUF_INDEX:0]     int_buf_tail;\n                           ^\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:105: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n   wire [`IOB_INT_BUF_INDEX:0]     int_buf_tail_plus;\n         ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:105: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\n   wire [`IOB_INT_BUF_INDEX:0]     int_buf_tail_plus;\n                           ^\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:106: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n   wire [`IOB_INT_BUF_INDEX:0]     int_buf_tail_plus10;\n         ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:106: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\n   wire [`IOB_INT_BUF_INDEX:0]     int_buf_tail_plus10;\n                           ^\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:108: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n   wire [`IOB_INT_BUF_INDEX:0]     int_buf_head;\n         ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:108: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\n   wire [`IOB_INT_BUF_INDEX:0]     int_buf_head;\n                           ^\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:109: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n   wire [`IOB_INT_BUF_INDEX:0]     int_buf_head_prev;\n         ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:109: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\n   wire [`IOB_INT_BUF_INDEX:0]     int_buf_head_prev;\n                           ^\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:110: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n   wire [`IOB_INT_BUF_INDEX:0]     int_buf_head_plus1;\n         ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:110: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\n   wire [`IOB_INT_BUF_INDEX:0]     int_buf_head_plus1;\n                           ^\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:117: Define or directive not defined: \'`IOB_IO_BUF_INDEX\'\n   wire [`IOB_IO_BUF_INDEX:0]     io_buf_head;\n         ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:117: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\n   wire [`IOB_IO_BUF_INDEX:0]     io_buf_head;\n                          ^\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:118: Define or directive not defined: \'`IOB_IO_BUF_INDEX\'\n   wire [`IOB_IO_BUF_INDEX:0]     io_buf_head_prev;\n         ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:118: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\n   wire [`IOB_IO_BUF_INDEX:0]     io_buf_head_prev;\n                          ^\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:119: Define or directive not defined: \'`IOB_IO_BUF_INDEX\'\n   wire [`IOB_IO_BUF_INDEX:0]     io_buf_head_plus1;\n         ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:119: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\n   wire [`IOB_IO_BUF_INDEX:0]     io_buf_head_plus1;\n                          ^\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:121: Define or directive not defined: \'`IOB_IO_BUF_INDEX\'\n   wire [`IOB_IO_BUF_INDEX:0]     io_buf_tail;\n         ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:121: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\n   wire [`IOB_IO_BUF_INDEX:0]     io_buf_tail;\n                          ^\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:145: Define or directive not defined: \'`IOB_CPU_WIDTH\'\n   dffrl_ns #(`IOB_CPU_WIDTH) cpx_iob_grant_ff (.din(cpx_iob_grant_cx2),\n              ^~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:249: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n   dffrle_ns #(`IOB_INT_BUF_INDEX+1) int_buf_tail_ff (.din(int_buf_tail_plus),\n               ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:256: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n   assign  int_buf_tail_ptr = int_buf_tail[`IOB_INT_BUF_INDEX-1:0];\n                                           ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:259: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n   assign       int_buf_hit_hwm = ((int_buf_tail_plus10[`IOB_INT_BUF_INDEX] != int_buf_head[`IOB_INT_BUF_INDEX]) &\n                                                        ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:259: syntax error, unexpected \']\', expecting TYPE-IDENTIFIER\n   assign       int_buf_hit_hwm = ((int_buf_tail_plus10[`IOB_INT_BUF_INDEX] != int_buf_head[`IOB_INT_BUF_INDEX]) &\n                                                                          ^\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:259: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n   assign       int_buf_hit_hwm = ((int_buf_tail_plus10[`IOB_INT_BUF_INDEX] != int_buf_head[`IOB_INT_BUF_INDEX]) &\n                                                                                            ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:260: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n                                   (int_buf_tail_plus10[`IOB_INT_BUF_INDEX-1:0] >= int_buf_head[`IOB_INT_BUF_INDEX-1:0])) |\n                                                        ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:260: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n                                   (int_buf_tail_plus10[`IOB_INT_BUF_INDEX-1:0] >= int_buf_head[`IOB_INT_BUF_INDEX-1:0])) |\n                                                                                                ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:261: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n                                  ((int_buf_tail_plus10[`IOB_INT_BUF_INDEX] == int_buf_head[`IOB_INT_BUF_INDEX]) &\n                                                        ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:261: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n                                  ((int_buf_tail_plus10[`IOB_INT_BUF_INDEX] == int_buf_head[`IOB_INT_BUF_INDEX]) &\n                                                                                            ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:262: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n                                   (int_buf_tail_plus10[`IOB_INT_BUF_INDEX-1:0] <= int_buf_head[`IOB_INT_BUF_INDEX-1:0]));\n                                                        ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:262: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n                                   (int_buf_tail_plus10[`IOB_INT_BUF_INDEX-1:0] <= int_buf_head[`IOB_INT_BUF_INDEX-1:0]));\n                                                                                                ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:266: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n   dffrl_ns #(`IOB_INT_BUF_INDEX+1) int_buf_head_prev_ff (.din(int_buf_head),\n              ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:273: Define or directive not defined: \'`IOB_INT_BUF_INDEX\'\n   assign     int_buf_head_ptr = int_buf_head[`IOB_INT_BUF_INDEX-1:0];\n                                              ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/458737381/src/verilog-parser/tests/i2c_fctrl.v:300: Define or directive not defined: \'`IOB_IO_BUF_INDEX\'\n   dffrl_ns #(`IOB_IO_BUF_INDEX+1) io_buf_head_prev_ff (.din(io_buf_head),\n              ^~~~~~~~~~~~~~~~~\n%Error: Exiting due to too many errors encountered; --error-limit=50\n'
module i2c_fctrl (

   int_buf_sel_next, io_buf_sel_next, int_buf_rd, io_buf_rd, 
   int_buf_hit_hwm, io_buf_head_f, int_buf_wr, int_buf_tail_ptr, 
   int_buf_head_ptr, io_buf_head_ptr, 

   cpu_rst_l, cpu_clk, tx_sync, rx_sync, cpx_iob_grant_cx2, 
   int_buf_cpx_req, io_buf_cpx_req, iob_cpx_req_next, 
   cpu_mondo_rd_d2, cpu_mondo_wr_d2, io_buf_tail_s
   );
   




   input                           cpu_rst_l;
   input 			   cpu_clk;
   input 			   tx_sync;
   input 			   rx_sync;

   

   input [`IOB_CPU_WIDTH-1:0] 	   cpx_iob_grant_cx2;
   
    

   input [`IOB_CPU_WIDTH-1:0] 	   int_buf_cpx_req;
   input [`IOB_CPU_WIDTH-1:0] 	   io_buf_cpx_req;
   input [`IOB_CPU_WIDTH-1:0] 	   iob_cpx_req_next;
   
   output 			   int_buf_sel_next;
   output 			   io_buf_sel_next;
   
   output 			   int_buf_rd;
   output 			   io_buf_rd;

   

   input 			   cpu_mondo_rd_d2;
   input 			   cpu_mondo_wr_d2;
   
   output 			   int_buf_hit_hwm;

   

   input [`IOB_IO_BUF_INDEX:0] 	   io_buf_tail_s;
   output [`IOB_IO_BUF_INDEX:0]    io_buf_head_f;

   

   output 			   int_buf_wr;
   output [`IOB_INT_BUF_INDEX-1:0] int_buf_tail_ptr;
   output [`IOB_INT_BUF_INDEX-1:0] int_buf_head_ptr;

   

   output [`IOB_IO_BUF_INDEX-1:0]  io_buf_head_ptr;

   

   wire [`IOB_CPU_WIDTH-1:0] 	   cpx_buf_full;
   wire [`IOB_CPU_WIDTH-1:0] 	   cpx_iob_grant;
   wire 			   cpu_mondo_rdwr_d2;
   wire [`IOB_INT_BUF_INDEX:0] 	   int_buf_tail;
   wire [`IOB_INT_BUF_INDEX:0] 	   int_buf_tail_plus;
   wire [`IOB_INT_BUF_INDEX:0] 	   int_buf_tail_plus10;
   
   wire [`IOB_INT_BUF_INDEX:0] 	   int_buf_head;
   wire [`IOB_INT_BUF_INDEX:0] 	   int_buf_head_prev;
   wire [`IOB_INT_BUF_INDEX:0] 	   int_buf_head_plus1;
   wire 			   int_buf_head_inc;
   wire 			   int_buf_empty;
   wire 			   int_buf_empty_prev;
   wire 			   int_buf_vld;
   wire 			   int_buf_vld_next;

   wire [`IOB_IO_BUF_INDEX:0] 	   io_buf_head;
   wire [`IOB_IO_BUF_INDEX:0] 	   io_buf_head_prev;
   wire [`IOB_IO_BUF_INDEX:0] 	   io_buf_head_plus1;
   wire 			   io_buf_head_inc;
   wire [`IOB_IO_BUF_INDEX:0] 	   io_buf_tail;
   wire 			   io_buf_empty;
   wire 			   io_buf_empty_prev;
   wire 			   io_buf_vld;
   wire 			   io_buf_vld_next;
   
   





   assign 	int_buf_sel_next = ~|(cpx_buf_full & ~cpx_iob_grant & int_buf_cpx_req) &
		                   int_buf_vld;
   
   assign 	io_buf_sel_next = ~|(cpx_buf_full & ~cpx_iob_grant & io_buf_cpx_req) &
		                  ~int_buf_sel_next & io_buf_vld;

   

   dffrl_ns #(`IOB_CPU_WIDTH) cpx_iob_grant_ff (.din(cpx_iob_grant_cx2),
					       	.clk(cpu_clk),
					       	.rst_l(cpu_rst_l),
					       	.q(cpx_iob_grant));
   



   i2c_cpx_cnt count0 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[0]),
		       .cpx_iob_grant(cpx_iob_grant[0]),
		       .cpx_buf_full(cpx_buf_full[0]));
   

   i2c_cpx_cnt count1 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[1]),
		       .cpx_iob_grant(cpx_iob_grant[1]),
		       .cpx_buf_full(cpx_buf_full[1]));
   

   i2c_cpx_cnt count2 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[2]),
		       .cpx_iob_grant(cpx_iob_grant[2]),
		       .cpx_buf_full(cpx_buf_full[2]));
   

   i2c_cpx_cnt count3 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[3]),
		       .cpx_iob_grant(cpx_iob_grant[3]),
		       .cpx_buf_full(cpx_buf_full[3]));
   

   i2c_cpx_cnt count4 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[4]),
		       .cpx_iob_grant(cpx_iob_grant[4]),
		       .cpx_buf_full(cpx_buf_full[4]));
   

   i2c_cpx_cnt count5 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[5]),
		       .cpx_iob_grant(cpx_iob_grant[5]),
		       .cpx_buf_full(cpx_buf_full[5]));
   

   i2c_cpx_cnt count6 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[6]),
		       .cpx_iob_grant(cpx_iob_grant[6]),
		       .cpx_buf_full(cpx_buf_full[6]));
   

   i2c_cpx_cnt count7 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[7]),
		       .cpx_iob_grant(cpx_iob_grant[7]),
		       .cpx_buf_full(cpx_buf_full[7]));
   
   

   assign 	cpu_mondo_rdwr_d2 = cpu_mondo_rd_d2 | cpu_mondo_wr_d2;
   assign 	int_buf_wr = cpu_mondo_rdwr_d2;
   

   dffrle_ns #(`IOB_INT_BUF_INDEX+1) int_buf_tail_ff (.din(int_buf_tail_plus),
						     .rst_l(cpu_rst_l),
						     .en(int_buf_wr),
						     .clk(cpu_clk),
						     .q(int_buf_tail));
   
   assign 	int_buf_tail_plus = int_buf_tail + 5'b1;
   assign 	int_buf_tail_ptr = int_buf_tail[`IOB_INT_BUF_INDEX-1:0];
   
   assign 	int_buf_tail_plus10 = int_buf_tail + 5'b01010;
   assign       int_buf_hit_hwm = ((int_buf_tail_plus10[`IOB_INT_BUF_INDEX] != int_buf_head[`IOB_INT_BUF_INDEX]) &
                                   (int_buf_tail_plus10[`IOB_INT_BUF_INDEX-1:0] >= int_buf_head[`IOB_INT_BUF_INDEX-1:0])) |
                                  ((int_buf_tail_plus10[`IOB_INT_BUF_INDEX] == int_buf_head[`IOB_INT_BUF_INDEX]) &
                                   (int_buf_tail_plus10[`IOB_INT_BUF_INDEX-1:0] <= int_buf_head[`IOB_INT_BUF_INDEX-1:0]));
   
   

   dffrl_ns #(`IOB_INT_BUF_INDEX+1) int_buf_head_prev_ff (.din(int_buf_head),
							  .clk(cpu_clk),
							  .rst_l(cpu_rst_l),
							  .q(int_buf_head_prev));
   assign     int_buf_head_plus1 = int_buf_head_prev + 4'b1;
   assign     int_buf_head = int_buf_head_inc ? int_buf_head_plus1 :
                                                int_buf_head_prev;
   assign     int_buf_head_ptr = int_buf_head[`IOB_INT_BUF_INDEX-1:0];
   

   assign     int_buf_empty = (int_buf_head == int_buf_tail);
   dff_ns #(1) int_buf_empty_prev_ff (.din(int_buf_empty|~cpu_rst_l),
				      .clk(cpu_clk),
                                      .q(int_buf_empty_prev));
   
   assign     int_buf_head_inc = ~int_buf_empty_prev &
                                 ((int_buf_vld & int_buf_sel_next) |
                                  ~int_buf_vld);


   assign     int_buf_rd = int_buf_head_inc;

   assign     int_buf_vld_next = int_buf_rd |
	                         (int_buf_vld & ~int_buf_sel_next);
   dffrl_ns #(1) int_buf_vld_ff (.din(int_buf_vld_next),
				 .clk(cpu_clk),
				 .rst_l(cpu_rst_l),
				 .q(int_buf_vld));

	  


   dffrl_ns #(`IOB_IO_BUF_INDEX+1) io_buf_head_prev_ff (.din(io_buf_head),
							.clk(cpu_clk),
							.rst_l(cpu_rst_l),
							.q(io_buf_head_prev));
   assign     io_buf_head_plus1 = io_buf_head_prev + 5'b1;
   assign     io_buf_head = io_buf_head_inc ? io_buf_head_plus1 :
                                              io_buf_head_prev;
   assign     io_buf_head_ptr = io_buf_head[`IOB_IO_BUF_INDEX-1:0];

   dffrle_ns #(`IOB_IO_BUF_INDEX+1) io_buf_head_f_ff (.din(io_buf_head),
						      .rst_l(cpu_rst_l),
						      .en(tx_sync),
						      .clk(cpu_clk),
						      .q(io_buf_head_f));
   
   

   dffrle_ns #(`IOB_IO_BUF_INDEX+1) io_buf_tail_ff (.din(io_buf_tail_s),
						    .rst_l(cpu_rst_l),
						    .en(rx_sync),
						    .clk(cpu_clk),
						    .q(io_buf_tail));



   assign     io_buf_empty = (io_buf_head == io_buf_tail);
   dff_ns #(1) io_buf_empty_prev_ff (.din(io_buf_empty|~cpu_rst_l),
				     .clk(cpu_clk),
                                     .q(io_buf_empty_prev));
   
   assign     io_buf_head_inc = ~io_buf_empty_prev &
                                ((io_buf_vld & io_buf_sel_next) |
                                 ~io_buf_vld);


   assign     io_buf_rd = io_buf_head_inc;

   assign     io_buf_vld_next = io_buf_rd |
	                        (io_buf_vld & ~io_buf_sel_next);
   dffrl_ns #(1) io_buf_vld_ff (.din(io_buf_vld_next),
				.clk(cpu_clk),
				.rst_l(cpu_rst_l),
				.q(io_buf_vld));

   
endmodule
module i2c_fctrl (

   int_buf_sel_next, io_buf_sel_next, int_buf_rd, io_buf_rd, 
   int_buf_hit_hwm, io_buf_head_f, int_buf_wr, int_buf_tail_ptr, 
   int_buf_head_ptr, io_buf_head_ptr, 

   cpu_rst_l, cpu_clk, tx_sync, rx_sync, cpx_iob_grant_cx2, 
   int_buf_cpx_req, io_buf_cpx_req, iob_cpx_req_next, 
   cpu_mondo_rd_d2, cpu_mondo_wr_d2, io_buf_tail_s
   );

   




   input                           cpu_rst_l;
   input 			   cpu_clk;
   input 			   tx_sync;
   input 			   rx_sync;

   

   input [`IOB_CPU_WIDTH-1:0] 	   cpx_iob_grant_cx2;
   
    

   input [`IOB_CPU_WIDTH-1:0] 	   int_buf_cpx_req;
   input [`IOB_CPU_WIDTH-1:0] 	   io_buf_cpx_req;
   input [`IOB_CPU_WIDTH-1:0] 	   iob_cpx_req_next;
   
   output 			   int_buf_sel_next;
   output 			   io_buf_sel_next;
   
   output 			   int_buf_rd;
   output 			   io_buf_rd;

   

   input 			   cpu_mondo_rd_d2;
   input 			   cpu_mondo_wr_d2;
   
   output 			   int_buf_hit_hwm;

   

   input [`IOB_IO_BUF_INDEX:0] 	   io_buf_tail_s;
   output [`IOB_IO_BUF_INDEX:0]    io_buf_head_f;

   

   output 			   int_buf_wr;
   output [`IOB_INT_BUF_INDEX-1:0] int_buf_tail_ptr;
   output [`IOB_INT_BUF_INDEX-1:0] int_buf_head_ptr;

   

   output [`IOB_IO_BUF_INDEX-1:0]  io_buf_head_ptr;

   

   wire [`IOB_CPU_WIDTH-1:0] 	   cpx_buf_full;
   wire [`IOB_CPU_WIDTH-1:0] 	   cpx_iob_grant;
   wire 			   cpu_mondo_rdwr_d2;
   wire [`IOB_INT_BUF_INDEX:0] 	   int_buf_tail;
   wire [`IOB_INT_BUF_INDEX:0] 	   int_buf_tail_plus;
   wire [`IOB_INT_BUF_INDEX:0] 	   int_buf_tail_plus10;
   
   wire [`IOB_INT_BUF_INDEX:0] 	   int_buf_head;
   wire [`IOB_INT_BUF_INDEX:0] 	   int_buf_head_prev;
   wire [`IOB_INT_BUF_INDEX:0] 	   int_buf_head_plus1;
   wire 			   int_buf_head_inc;
   wire 			   int_buf_empty;
   wire 			   int_buf_empty_prev;
   wire 			   int_buf_vld;
   wire 			   int_buf_vld_next;

   wire [`IOB_IO_BUF_INDEX:0] 	   io_buf_head;
   wire [`IOB_IO_BUF_INDEX:0] 	   io_buf_head_prev;
   wire [`IOB_IO_BUF_INDEX:0] 	   io_buf_head_plus1;
   wire 			   io_buf_head_inc;
   wire [`IOB_IO_BUF_INDEX:0] 	   io_buf_tail;
   wire 			   io_buf_empty;
   wire 			   io_buf_empty_prev;
   wire 			   io_buf_vld;
   wire 			   io_buf_vld_next;
   
   





   assign 	int_buf_sel_next = ~|(cpx_buf_full & ~cpx_iob_grant & int_buf_cpx_req) &
		                   int_buf_vld;
   
   assign 	io_buf_sel_next = ~|(cpx_buf_full & ~cpx_iob_grant & io_buf_cpx_req) &
		                  ~int_buf_sel_next & io_buf_vld;

   

   dffrl_ns #(`IOB_CPU_WIDTH) cpx_iob_grant_ff (.din(cpx_iob_grant_cx2),
					       	.clk(cpu_clk),
					       	.rst_l(cpu_rst_l),
					       	.q(cpx_iob_grant));
   



   i2c_cpx_cnt count0 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[0]),
		       .cpx_iob_grant(cpx_iob_grant[0]),
		       .cpx_buf_full(cpx_buf_full[0]));
   

   i2c_cpx_cnt count1 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[1]),
		       .cpx_iob_grant(cpx_iob_grant[1]),
		       .cpx_buf_full(cpx_buf_full[1]));
   

   i2c_cpx_cnt count2 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[2]),
		       .cpx_iob_grant(cpx_iob_grant[2]),
		       .cpx_buf_full(cpx_buf_full[2]));
   

   i2c_cpx_cnt count3 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[3]),
		       .cpx_iob_grant(cpx_iob_grant[3]),
		       .cpx_buf_full(cpx_buf_full[3]));
   

   i2c_cpx_cnt count4 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[4]),
		       .cpx_iob_grant(cpx_iob_grant[4]),
		       .cpx_buf_full(cpx_buf_full[4]));
   

   i2c_cpx_cnt count5 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[5]),
		       .cpx_iob_grant(cpx_iob_grant[5]),
		       .cpx_buf_full(cpx_buf_full[5]));
   

   i2c_cpx_cnt count6 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[6]),
		       .cpx_iob_grant(cpx_iob_grant[6]),
		       .cpx_buf_full(cpx_buf_full[6]));
   

   i2c_cpx_cnt count7 (.rst_l(cpu_rst_l),
		       .clk(cpu_clk),
		       .iob_cpx_req_next(iob_cpx_req_next[7]),
		       .cpx_iob_grant(cpx_iob_grant[7]),
		       .cpx_buf_full(cpx_buf_full[7]));
   
   

   assign 	cpu_mondo_rdwr_d2 = cpu_mondo_rd_d2 | cpu_mondo_wr_d2;
   assign 	int_buf_wr = cpu_mondo_rdwr_d2;
   

   dffrle_ns #(`IOB_INT_BUF_INDEX+1) int_buf_tail_ff (.din(int_buf_tail_plus),
						     .rst_l(cpu_rst_l),
						     .en(int_buf_wr),
						     .clk(cpu_clk),
						     .q(int_buf_tail));
   
   assign 	int_buf_tail_plus = int_buf_tail + 5'b1;
   assign 	int_buf_tail_ptr = int_buf_tail[`IOB_INT_BUF_INDEX-1:0];
   
   assign 	int_buf_tail_plus10 = int_buf_tail + 5'b01010;
   assign       int_buf_hit_hwm = ((int_buf_tail_plus10[`IOB_INT_BUF_INDEX] != int_buf_head[`IOB_INT_BUF_INDEX]) &
                                   (int_buf_tail_plus10[`IOB_INT_BUF_INDEX-1:0] >= int_buf_head[`IOB_INT_BUF_INDEX-1:0])) |
                                  ((int_buf_tail_plus10[`IOB_INT_BUF_INDEX] == int_buf_head[`IOB_INT_BUF_INDEX]) &
                                   (int_buf_tail_plus10[`IOB_INT_BUF_INDEX-1:0] <= int_buf_head[`IOB_INT_BUF_INDEX-1:0]));
   
   

   dffrl_ns #(`IOB_INT_BUF_INDEX+1) int_buf_head_prev_ff (.din(int_buf_head),
							  .clk(cpu_clk),
							  .rst_l(cpu_rst_l),
							  .q(int_buf_head_prev));
   assign     int_buf_head_plus1 = int_buf_head_prev + 4'b1;
   assign     int_buf_head = int_buf_head_inc ? int_buf_head_plus1 :
                                                int_buf_head_prev;
   assign     int_buf_head_ptr = int_buf_head[`IOB_INT_BUF_INDEX-1:0];
   

   assign     int_buf_empty = (int_buf_head == int_buf_tail);
   dff_ns #(1) int_buf_empty_prev_ff (.din(int_buf_empty|~cpu_rst_l),
				      .clk(cpu_clk),
                                      .q(int_buf_empty_prev));
   
   assign     int_buf_head_inc = ~int_buf_empty_prev &
                                 ((int_buf_vld & int_buf_sel_next) |
                                  ~int_buf_vld);


   assign     int_buf_rd = int_buf_head_inc;

   assign     int_buf_vld_next = int_buf_rd |
	                         (int_buf_vld & ~int_buf_sel_next);
   dffrl_ns #(1) int_buf_vld_ff (.din(int_buf_vld_next),
				 .clk(cpu_clk),
				 .rst_l(cpu_rst_l),
				 .q(int_buf_vld));

	  


   dffrl_ns #(`IOB_IO_BUF_INDEX+1) io_buf_head_prev_ff (.din(io_buf_head),
							.clk(cpu_clk),
							.rst_l(cpu_rst_l),
							.q(io_buf_head_prev));
   assign     io_buf_head_plus1 = io_buf_head_prev + 5'b1;
   assign     io_buf_head = io_buf_head_inc ? io_buf_head_plus1 :
                                              io_buf_head_prev;
   assign     io_buf_head_ptr = io_buf_head[`IOB_IO_BUF_INDEX-1:0];

   dffrle_ns #(`IOB_IO_BUF_INDEX+1) io_buf_head_f_ff (.din(io_buf_head),
						      .rst_l(cpu_rst_l),
						      .en(tx_sync),
						      .clk(cpu_clk),
						      .q(io_buf_head_f));
   
   

   dffrle_ns #(`IOB_IO_BUF_INDEX+1) io_buf_tail_ff (.din(io_buf_tail_s),
						    .rst_l(cpu_rst_l),
						    .en(rx_sync),
						    .clk(cpu_clk),
						    .q(io_buf_tail));



   assign     io_buf_empty = (io_buf_head == io_buf_tail);
   dff_ns #(1) io_buf_empty_prev_ff (.din(io_buf_empty|~cpu_rst_l),
				     .clk(cpu_clk),
                                     .q(io_buf_empty_prev));
   
   assign     io_buf_head_inc = ~io_buf_empty_prev &
                                ((io_buf_vld & io_buf_sel_next) |
                                 ~io_buf_vld);


   assign     io_buf_rd = io_buf_head_inc;

   assign     io_buf_vld_next = io_buf_rd |
	                        (io_buf_vld & ~io_buf_sel_next);
   dffrl_ns #(1) io_buf_vld_ff (.din(io_buf_vld_next),
				.clk(cpu_clk),
				.rst_l(cpu_rst_l),
				.q(io_buf_vld));

   
endmodule