Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spi cpol0 cpha0 #85

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/view.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

gtkwave -a $OH_HOME/common/dv/oh.gtkw waveform.vcd
gtkwave -a $OH_HOME/src/common/dv/oh.gtkw waveform.vcd

6 changes: 5 additions & 1 deletion src/common/hdl/oh_fifo_async.v
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ module oh_fifo_async # (parameter DW = 104, //FIFO width
.din (din[DW-1:0]),
.rd_en (rd_en));
end // if ((DW==104) & (DEPTH==32))
end // block: xilinx
else
_INVALID_PARAMETERS_ invalid_parameters();
end // block: xilinx
else
_INVALID_TARGET_ invalid_target();
endgenerate

endmodule // oh_fifo_async
Expand Down
8 changes: 5 additions & 3 deletions src/common/hdl/oh_par2ser.v
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module oh_par2ser #(parameter PW = 64, // parallel packet width
//transfer counter
always @ (posedge clk or negedge nreset)
if(!nreset)
count[CW-1:0] <= 'b0;
count[CW-1:0] <= {(CW){1'b0}};
else if(start_transfer)
count[CW-1:0] <= datasize[CW-1:0]; //one "SW sized" transfers
else if(shift & busy)
Expand All @@ -51,8 +51,10 @@ module oh_par2ser #(parameter PW = 64, // parallel packet width
assign wait_out = wait_in | busy;

// shift register
always @ (posedge clk)
if(start_transfer)
always @ (posedge clk or negedge nreset)
if(!nreset)
shiftreg[PW-1:0] = {(PW){1'b0}};
else if(start_transfer)
shiftreg[PW-1:0] = din[PW-1:0];
else if(shift & lsbfirst)
shiftreg[PW-1:0] = {{(SW){fill}}, shiftreg[PW-1:SW]};
Expand Down
8 changes: 5 additions & 3 deletions src/common/hdl/oh_ser2par.v
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ module oh_ser2par #(parameter PW = 64, // parallel packet width

parameter CW = $clog2(PW/SW); // serialization factor (for counter)

reg [PW-1:0] dout;
reg [PW-1:0] dout_reg;
reg [CW-1:0] count;
wire [PW-1:0] shiftdata;

assign dout = dout_reg;

always @ (posedge clk)
if(shift & lsbfirst)
dout[PW-1:0] <= {din[SW-1:0],dout[PW-1:SW]};
dout_reg[PW-1:0] <= {din[SW-1:0],dout_reg[PW-1:SW]};
else if(shift)
dout[PW-1:0] <= {dout[PW-SW-1:0],din[SW-1:0]};
dout_reg[PW-1:0] <= {dout_reg[PW-SW-1:0],din[SW-1:0]};

endmodule // oh_ser2par
14 changes: 8 additions & 6 deletions src/parallella/hdl/pgpio.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ module pgpio(/*AUTOARG*/
ps_gpio_o, ps_gpio_t
);

parameter NGPIO = 24; // 12 or 24
parameter NPS = 64; // signals for PS
parameter DIFF = 0; // 0= single ended
// 1= differential
parameter NGPIO = 24; // 12 or 24
parameter NPS = 64; // signals for PS
parameter DIFF = 0; // 0= single ended
// 1= differential
parameter SLEW = "SLOW"; // "SLOW" or "FAST", only applicable to
// single ended.

inout [NGPIO-1:0] gpio_p;
inout [NGPIO-1:0] gpio_n;
Expand Down Expand Up @@ -74,7 +76,7 @@ module pgpio(/*AUTOARG*/
.DRIVE(8), // Specify the output drive strength
.IBUF_LOW_PWR("TRUE"), // Low Power - "TRUE", High Performance = "FALSE"
.IOSTANDARD("LVCMOS25"), // Specify the I/O standard
.SLEW("SLOW") // Specify the output slew rate
.SLEW(SLEW) // Specify the output slew rate
)
i_iocmos_n [NGPIO-1:0]
(
Expand All @@ -89,7 +91,7 @@ module pgpio(/*AUTOARG*/
.DRIVE(8), // Specify the output drive strength
.IBUF_LOW_PWR("TRUE"), // Low Power - "TRUE", High Performance = "FALSE"
.IOSTANDARD("LVCMOS25"), // Specify the I/O standard
.SLEW("SLOW") // Specify the output slew rate
.SLEW(SLEW) // Specify the output slew rate
)
i_iocmos_p [NGPIO-1:0]
(
Expand Down
18 changes: 18 additions & 0 deletions src/spi/dv/tests/test_high_bits.emf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
DEADBEEF_00000003_00000002_01_0020 //CLKDIV (BAUDRATE, DIVIDE by 8)
DEADBEEF_00000020_00000008_01_0000 //TX DATA (command=write addr=spi_user0)
DEADBEEF_000000FE_00000008_01_0000 //TX DATA (data)
DEADBEEF_000000DC_00000008_01_0000 //TX DATA (data)
DEADBEEF_000000BA_00000008_01_0000 //TX DATA (data)
DEADBEEF_00000098_00000008_01_0000 //TX DATA (data)
DEADBEEF_00000076_00000008_01_0000 //TX DATA (data)
DEADBEEF_00000054_00000008_01_0000 //TX DATA (data)
DEADBEEF_00000032_00000008_01_0100 //TX DATA (data)
DEADBEEF_000000A0_00000008_01_0000 //TX DATA (command=read addr=spi_user0)
DEADBEEF_00000000_00000008_01_0000 //TX DATA (read)
DEADBEEF_00000000_00000008_01_0000 //TX DATA (read)
DEADBEEF_00000000_00000008_01_0000 //TX DATA (read)
DEADBEEF_00000000_00000008_01_0000 //TX DATA (read)
DEADBEEF_00000000_00000008_01_0000 //TX DATA (read)
DEADBEEF_00000000_00000008_01_0000 //TX DATA (read)
DEADBEEF_00000000_00000008_01_0400 //TX DATA (read)
DEADBEEF_00000000_00000010_04_0400 // Read local RX0
33 changes: 31 additions & 2 deletions src/spi/fpga/axi_spi_timing.xdc
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# SPI slave clock
create_clock -name spi_s_sclk -period 10 [get_ports spi_s_sclk]
# Use numbers from here:
# https://en.wikipedia.org/wiki/Propagation_delay
# Assume wires are shorter than < 30cm (12")

# slave
create_clock -period 30.000 -name spi_s_sclk -waveform {0.000 15.000} [get_ports {gpio_p[3]}]
# assign spi_s_mosi = gpio_in[8];
set_input_delay -clock spi_s_sclk -max 2.000 [get_ports {gpio_n[4]}]
# assign spi_s_miso = gpio_out[9];
set_output_delay -clock spi_s_sclk -max -add_delay 2.000 [get_ports {gpio_n[5]}]
# assign spi_s_ss = gpio_in[10];
set_input_delay -clock spi_s_sclk -max 2.000 [get_ports {gpio_p[4]}]

#master
# assign spi_m_sclk = gpio_out[3];
# just misses timing for 100 MHz
create_clock -period 20.000 -name spi_m_sclk -waveform {0.000 10.000} [get_ports {gpio_p[1]}]
# assign spi_m_mosi = gpio_out[4];
set_output_delay -clock spi_m_sclk -max -add_delay 2.000 [get_ports {gpio_n[2]}]
# assign spi_m_miso = gpio_in[5];
set_input_delay -clock spi_m_sclk -max 2.000 [get_ports {gpio_n[3]}]
# assign spi_m_ss = gpio_out[6];
set_output_delay -clock spi_m_sclk -max -add_delay 2.000 [get_ports {gpio_p[2]}]

set_false_path -from [get_clocks clk_fpga_0] -to [get_clocks spi_m_sclk]

# pgpio.v pin mapping
# for(m=0; m<NGPIO; m=m+2) begin : assign_se_sigs
# assign ps_gpio_i[2*m] = gpio_i_n[m];
# assign ps_gpio_i[2*m+1] = gpio_i_n[m+1];
# assign ps_gpio_i[2*m+2] = gpio_i_p[m];
# assign ps_gpio_i[2*m+3] = gpio_i_p[m+1];
4 changes: 3 additions & 1 deletion src/spi/fpga/ip_params.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ set hdl_files [list \
$root/parallella/hdl \
]

set ip_files []
set ip_files [list \
$root/xilibs/ip/fifo_async_104x32.xci \
]

set constraints_files []

4 changes: 3 additions & 1 deletion src/spi/fpga/system_params.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ set hdl_files [list \
$root/parallella/hdl \
]

set ip_files []
set ip_files [list \
$root/xilibs/ip/fifo_async_104x32.xci \
]

set constraints_files [list \
../../parallella/fpga/parallella_io.xdc \
Expand Down
3 changes: 2 additions & 1 deletion src/spi/hdl/axi_spi.v
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module axi_spi(/*AUTOARG*/
parameter PW = 2*AW+40; // packet width
parameter ID = 12'h810; // addr[31:20] id
parameter S_IDW = 12; // ID width for S_AXI
parameter TARGET = "GENERIC"; // XILINX,ALTERA,GENERIC,ASIC

//clk, reset
input sys_nreset; // active low async reset
Expand Down Expand Up @@ -122,7 +123,7 @@ module axi_spi(/*AUTOARG*/
wire spi_wait_in;

/* spi AUTO_TEMPLATE (.\([sm]_.*\) (spi_\1[]),); */
spi #(.AW(AW))
spi #(.AW(AW),.TARGET(TARGET))
spi (
//Outputs
.hw_en (1'b1),
Expand Down
7 changes: 4 additions & 3 deletions src/spi/hdl/parallella_spi.v
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module parallella_spi(/*AUTOARG*/
parameter ID = 12'h7fe; // addr[31:20] id
parameter S_IDW = 12; // ID width for S_AXI
parameter NGPIO = 24; // number of gpio pins
parameter TARGET = "XILINX"; // XILINX,ALTERA,GENERIC,ASIC

// constants
input constant_zero; // Always 0
Expand Down Expand Up @@ -124,12 +125,12 @@ module parallella_spi(/*AUTOARG*/
assign spi_m_sclk = gpio_out[3];

/* NOTE: 0 = in, 1 = out */
assign gpio_dir[NGPIO-1:0] = {{(NGPIO-8){1'b0}}, 8'b01001011};
assign gpio_dir[NGPIO-1:0] = {{(NGPIO-11){1'b0}}, 8'b01001011, 3'b000};

assign constant_zero = 1'b0;
assign constant_one = 1'b1;

pgpio #(.NGPIO(NGPIO),.NPS(NGPIO))
pgpio #(.NGPIO(NGPIO),.NPS(NGPIO),.SLEW("FAST"))
pgpio (.ps_gpio_i (gpio_in[NGPIO-1:0]),
.ps_gpio_o (gpio_out[NGPIO-1:0]),
.ps_gpio_t (~gpio_dir[NGPIO-1:0]),
Expand All @@ -139,7 +140,7 @@ module parallella_spi(/*AUTOARG*/
.gpio_n (gpio_n[NGPIO-1:0]));


axi_spi #(.S_IDW(S_IDW),.AW(AW),.ID(ID))
axi_spi #(.S_IDW(S_IDW),.AW(AW),.ID(ID),.TARGET(TARGET))
axi_spi (// Outputs
.spi_irq (spi_irq),
.spi_m_mosi (spi_m_mosi),
Expand Down
6 changes: 4 additions & 2 deletions src/spi/hdl/spi.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

module spi #( parameter AW = 32, // address width
parameter PW = 104, // packet size
parameter UREGS = 13 // number of user slave regs
parameter UREGS = 13, // number of user slave regs
parameter TARGET = "GENERIC" // XILINX,ALTERA,GENERIC,ASIC
)
(//clk, reset, irq
input nreset, // asynch active low reset
Expand Down Expand Up @@ -63,7 +64,8 @@ module spi #( parameter AW = 32, // address width
*/

spi_master #(.AW(AW),
.PW(PW))
.PW(PW),
.TARGET(TARGET))
spi_master (/*AUTOINST*/
// Outputs
.sclk (m_sclk), // Templated
Expand Down
12 changes: 7 additions & 5 deletions src/spi/hdl/spi_master.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
module spi_master # ( parameter DEPTH = 32, // fifo depth
parameter REGS = 16, // total # of regs
parameter AW = 32, // addresss width
parameter PW = 104 // packet width
parameter PW = 104, // packet width
parameter TARGET = "GENERIC" // XILINX,ALTERA,GENERIC,ASIC
)
(
//clk,reset, cfg
Expand Down Expand Up @@ -50,7 +51,7 @@ module spi_master # ( parameter DEPTH = 32, // fifo depth
wire rx_access; // From spi_master_io of spi_master_io.v
wire [63:0] rx_data; // From spi_master_io of spi_master_io.v
wire spi_en; // From spi_master_regs of spi_master_regs.v
wire [1:0] spi_state; // From spi_master_io of spi_master_io.v
wire [2:0] spi_state; // From spi_master_io of spi_master_io.v
// End of automatics

//#####################################################
Expand All @@ -75,7 +76,7 @@ module spi_master # ( parameter DEPTH = 32, // fifo depth
.hw_en (hw_en),
.rx_data (rx_data[63:0]),
.rx_access (rx_access),
.spi_state (spi_state[1:0]),
.spi_state (spi_state[2:0]),
.fifo_prog_full (fifo_prog_full),
.fifo_wait (fifo_wait),
.access_in (access_in),
Expand All @@ -93,7 +94,8 @@ module spi_master # ( parameter DEPTH = 32, // fifo depth

spi_master_fifo #(.AW(AW),
.PW(PW),
.DEPTH(DEPTH))
.DEPTH(DEPTH),
.TARGET(TARGET))
spi_master_fifo(
/*AUTOINST*/
// Outputs
Expand All @@ -116,7 +118,7 @@ module spi_master # ( parameter DEPTH = 32, // fifo depth
spi_master_io
spi_master_io (/*AUTOINST*/
// Outputs
.spi_state (spi_state[1:0]),
.spi_state (spi_state[2:0]),
.fifo_read (fifo_read),
.rx_data (rx_data[63:0]),
.rx_access (rx_access),
Expand Down
70 changes: 53 additions & 17 deletions src/spi/hdl/spi_master_fifo.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module spi_master_fifo #( parameter DEPTH = 16, // fifo entries
parameter PW = 104, // input packet width
parameter SW = 8, // io packet width
parameter FAW = $clog2(DEPTH), // fifo address width
parameter SRW = $clog2(PW/SW) // serialization factor
parameter SRW = $clog2(PW/SW), // serialization factor
parameter TARGET = "GENERIC" // XILINX,ALTERA,GENERIC,ASIC
)
(
//clk,reset, cfg
Expand Down Expand Up @@ -69,7 +70,8 @@ module spi_master_fifo #( parameter DEPTH = 16, // fifo entries
access_in &
~fifo_wait &
(dstaddr_in[5:0]==`SPI_TX);


wire fifo_wait;
assign wait_out = fifo_wait; // & tx_write;

//epiphany mode works in msb or lsb mode
Expand All @@ -79,7 +81,7 @@ module spi_master_fifo #( parameter DEPTH = 16, // fifo entries
assign tx_data[PW-1:0] = {{(40){1'b0}},
srcaddr_in[AW-1:0],
data_in[AW-1:0]};

//##################################
//# FIFO PACKET WRITE
//##################################
Expand All @@ -106,20 +108,54 @@ module spi_master_fifo #( parameter DEPTH = 16, // fifo entries
//# FIFO
//###################################

oh_fifo_sync #(.DEPTH(DEPTH),
.DW(SW))
fifo(// Outputs
.dout (fifo_dout[7:0]),
.full (fifo_full),
.prog_full (fifo_prog_full),
.empty (fifo_empty),
.rd_count (),
// Inputs
.clk (clk),
.nreset (nreset),
.din (fifo_din[7:0]),
.wr_en (fifo_wr),
.rd_en (fifo_read));
// HACK: oh_fifo_sync is broken for XILINX target.
generate
if(TARGET=="XILINX") begin : gen_xilinx_fifo
// HACK: Hardcoded DW/DEPTH to please XILINX target
wire [103:0] fifo_dout_full;
assign fifo_dout[SW-1:0] = fifo_dout_full[SW-1:0];

wire [103:0] packet_in_full;
assign packet_in_full[103:0] = {{(104-SW){1'b0}},fifo_din[SW-1:0]};

// oh_fifo_cdc #(.DW(SW),
// .DEPTH(DEPTH),
// .TARGET(TARGET))
oh_fifo_cdc #(.DW(104),
.DEPTH(32),
.TARGET(TARGET))
fifo (// Outputs
.wait_out (),
.access_out (),
.packet_out (fifo_dout_full[103:0]),
.prog_full (fifo_prog_full),
.full (fifo_full),
.empty (fifo_empty),
// Inputs
.nreset (nreset),
.clk_in (clk),
.packet_in (packet_in_full[103:0]),
.clk_out (clk),
.access_in (fifo_wr),
.wait_in (~fifo_read));
end // TARGET == "XILINX"
else begin : gen_generic_fifo
oh_fifo_sync #(.DEPTH(DEPTH),
.DW(SW))
fifo(// Outputs
.dout (fifo_dout[7:0]),
.full (fifo_full),
.prog_full (fifo_prog_full),
.empty (fifo_empty),
.rd_count (),
// Inputs
.clk (clk),
.nreset (nreset),
.din (fifo_din[7:0]),
.wr_en (fifo_wr),
.rd_en (fifo_read));
end // TARGET != "XILINX"
endgenerate

endmodule // spi_master_fifo

Expand Down
Loading