Line 45... |
Line 45... |
//
|
//
|
//
|
//
|
module spiarbiter(i_clk,
|
module spiarbiter(i_clk,
|
i_cs_a_n, i_ck_a, i_mosi_a,
|
i_cs_a_n, i_ck_a, i_mosi_a,
|
i_cs_b_n, i_ck_b, i_mosi_b,
|
i_cs_b_n, i_ck_b, i_mosi_b,
|
o_cs_a_n, o_cs_b_n, o_ck, o_mosi); // , i_en, o_err
|
o_cs_a_n, o_cs_b_n, o_ck, o_mosi,
|
|
o_grant);
|
input i_clk;
|
input i_clk;
|
input i_cs_a_n, i_ck_a, i_mosi_a;
|
input i_cs_a_n, i_ck_a, i_mosi_a;
|
// output wire o_grant_a;
|
// output wire o_grant_a;
|
input i_cs_b_n, i_ck_b, i_mosi_b;
|
input i_cs_b_n, i_ck_b, i_mosi_b;
|
// output wire o_grant_b;
|
// output wire o_grant_b;
|
output wire o_cs_a_n, o_cs_b_n, o_ck, o_mosi;
|
output wire o_cs_a_n, o_cs_b_n, o_ck, o_mosi;
|
|
//
|
|
output wire o_grant; // == o_grant_a = ~o_grant_b
|
|
|
reg a_owner;
|
reg a_owner;
|
initial a_owner = 1'b1;
|
initial a_owner = 1'b1;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if ((i_cs_a_n)&&(i_cs_b_n))
|
if ((i_cs_a_n)&&(i_cs_b_n))
|
a_owner <= 1'b1; // Keep control
|
a_owner <= 1'b1; // Keep control
|
else if ((i_cs_a_n)&&(~i_cs_b_n))
|
else if ((i_cs_a_n)&&(~i_cs_b_n))
|
a_owner <= 1'b0; // Give up control
|
a_owner <= 1'b0; // Give up control
|
|
else if ((~i_cs_a_n)&&(i_cs_b_n))
|
|
a_owner <= 1'b1; // Take control
|
|
|
// assign o_grant_a = a_owner;
|
// assign o_grant_a = a_owner;
|
// assign o_grant_b = (~a_owner);
|
// assign o_grant_b = (~a_owner);
|
|
|
assign o_cs_a_n = (~a_owner)||(~i_cs_a_n);
|
assign o_cs_a_n = (~a_owner)||(i_cs_a_n);
|
assign o_cs_b_n = ( a_owner)||(~i_cs_b_n);
|
assign o_cs_b_n = ( a_owner)||(i_cs_b_n);
|
assign o_ck = ( a_owner)?i_ck_a : i_ck_b;
|
assign o_ck = ( a_owner)?i_ck_a : i_ck_b;
|
assign o_mosi = ( a_owner)?i_mosi_a : i_mosi_b;
|
assign o_mosi = ( a_owner)?i_mosi_a : i_mosi_b;
|
|
|
|
assign o_grant = ~a_owner;
|
|
|
endmodule
|
endmodule
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|