Compare commits
5 Commits
working
...
4518891301
| Author | SHA1 | Date | |
|---|---|---|---|
| 4518891301 | |||
| 57f461af59 | |||
| f9eb244c7f | |||
| 4019d21a98 | |||
| 75e2b3d035 |
37
labor_4/README.md
Normal file
37
labor_4/README.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Labor EDS: Labor 4
|
||||
|
||||
## Übung 6: SPI Master
|
||||
|
||||
### Vorbereitung 1
|
||||
|
||||
Aufgabenstellung aus der Email:
|
||||
|
||||
- Kapitel 6 durchlesen und Aufgaben 6.3 und 6.5 bearbeiten
|
||||
- Auf dem Dozentenlaufwerk und auf Teams liegt der Ordner 'spi_master' mit der Vorlage 'spi_master_template.v'
|
||||
- Vorlage kann mit 'sim_w_lib.do' kompiliert werden
|
||||
- SImulation anschauen und versuchen zu verstehen
|
||||
|
||||
- Aufgabe 6.3 ist eine Schaltung-zu-Code Übersetzung
|
||||
- das Modul 'sclk_gen' und eine Testbench dazu schreiben
|
||||
|
||||
- Aufgabe 6.5:
|
||||
- benötigt einen Zähler der statt einer festen Variable, eine von außen dynamisch vorgegebene Anzahl Schritte zählt
|
||||
- Zähler als Modul vorbereiten und dazu eine kleine Testbench
|
||||
- Zähler soll als Abwärtszähler arbeiten
|
||||
- Beim Erreichen des Wertes 0 soll im nächsten Takt der Wert am Eingang CLOCK_DIVIDER ins Zählerregister geladen werden
|
||||
- Wenn das Zählerregister 0 ist soll außerdem der Ausgang SYNC auf 1 gesetzt werden.
|
||||
|
||||
|
||||
**Eingänge:**
|
||||
|
||||
CLK: Taktsignal
|
||||
|
||||
RESETn: Asynchroner, 0-aktiver Reset, setzt alle Bits im Zählerregister auf 0
|
||||
|
||||
CLOCK_DIVIDER: Startwert für den Abwärtszähler
|
||||
|
||||
**Ausgänge:**
|
||||
|
||||
SYNC: 1 wenn alle Zählerregister 0, sonst 0
|
||||
|
||||
manuel.walz@advantest.com
|
||||
BIN
labor_4/res/spi_master/Schaltplaene_Erweiterungsboard.pdf
Normal file
BIN
labor_4/res/spi_master/Schaltplaene_Erweiterungsboard.pdf
Normal file
Binary file not shown.
41
labor_4/res/spi_master/quartus/led_chaser.sdc
Normal file
41
labor_4/res/spi_master/quartus/led_chaser.sdc
Normal file
@@ -0,0 +1,41 @@
|
||||
#************************************************************
|
||||
# THIS IS A WIZARD-GENERATED FILE.
|
||||
#
|
||||
# Version 12.1 Build 243 01/31/2013 Service Pack 1 SJ Web Edition
|
||||
#
|
||||
#************************************************************
|
||||
|
||||
# Copyright (C) 1991-2012 Altera Corporation
|
||||
# Your use of Altera Corporation's design tools, logic functions
|
||||
# and other software and tools, and its AMPP partner logic
|
||||
# functions, and any output files from any of the foregoing
|
||||
# (including device programming or simulation files), and any
|
||||
# associated documentation or information are expressly subject
|
||||
# to the terms and conditions of the Altera Program License
|
||||
# Subscription Agreement, Altera MegaCore Function License
|
||||
# Agreement, or other applicable license agreement, including,
|
||||
# without limitation, that your use is for the sole purpose of
|
||||
# programming logic devices manufactured by Altera and sold by
|
||||
# Altera or its authorized distributors. Please refer to the
|
||||
# applicable agreement for further details.
|
||||
|
||||
|
||||
|
||||
# Clock constraints
|
||||
|
||||
create_clock -name "CLOCK_50" -period 20.000ns [get_ports {CLOCK_50}] -waveform {0.000 10.000}
|
||||
|
||||
|
||||
# Automatically constrain PLL and other generated clocks
|
||||
derive_pll_clocks -create_base_clocks
|
||||
|
||||
# Automatically calculate clock uncertainty to jitter and other effects.
|
||||
#derive_clock_uncertainty
|
||||
# Not supported for family Cyclone II
|
||||
|
||||
# tsu/th constraints
|
||||
|
||||
# tco constraints
|
||||
|
||||
# tpd constraints
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
# Quartus II Version 5.1 Internal Build 160 09/19/2005 TO Full Version,
|
||||
# File: D:\de2_pins\de2_pins.csv,
|
||||
# Generated on: Wed Sep 28 09:40:34 2005,
|
||||
|
||||
# Note: The column header names should not be changed if you wish to import this .csv file into the Quartus II software.,
|
||||
|
||||
To,Location
|
||||
SW[0],PIN_N25
|
||||
SW[1],PIN_N26
|
||||
SW[2],PIN_P25
|
||||
SW[3],PIN_AE14
|
||||
SW[4],PIN_AF14
|
||||
SW[5],PIN_AD13
|
||||
SW[6],PIN_AC13
|
||||
SW[7],PIN_C13
|
||||
SW[8],PIN_B13
|
||||
SW[9],PIN_A13
|
||||
SW[10],PIN_N1
|
||||
SW[11],PIN_P1
|
||||
SW[12],PIN_P2
|
||||
SW[13],PIN_T7
|
||||
SW[14],PIN_U3
|
||||
SW[15],PIN_U4
|
||||
|
||||
LEDR[0],PIN_AE23
|
||||
LEDR[1],PIN_AF23
|
||||
LEDR[2],PIN_AB21
|
||||
LEDR[3],PIN_AC22
|
||||
LEDR[4],PIN_AD22
|
||||
LEDR[5],PIN_AD23
|
||||
LEDR[6],PIN_AD21
|
||||
LEDR[7],PIN_AC21
|
||||
LEDR[8],PIN_AA14
|
||||
LEDR[9],PIN_Y13
|
||||
LEDR[10],PIN_AA13
|
||||
LEDR[11],PIN_AC14
|
||||
LEDR[12],PIN_AD15
|
||||
LEDR[13],PIN_AE15
|
||||
LEDR[14],PIN_AF13
|
||||
LEDR[15],PIN_AE13
|
||||
|
||||
LEDG[0],PIN_AE22
|
||||
LEDG[1],PIN_AF22
|
||||
LEDG[2],PIN_W19
|
||||
LEDG[3],PIN_V18
|
||||
LEDG[4],PIN_U18
|
||||
LEDG[5],PIN_U17
|
||||
LEDG[6],PIN_AA20
|
||||
LEDG[7],PIN_Y18
|
||||
CLOCK_50,PIN_N2
|
||||
|
||||
SSn_A[0],PIN_D25
|
||||
SSn_A[1],PIN_J22
|
||||
SSn_A[2],PIN_E26
|
||||
SSn_A[3],PIN_E25
|
||||
MOSI_A,PIN_F24
|
||||
SCLK_A,PIN_F23
|
||||
MISO_A1,PIN_J21
|
||||
MISO_A2,PIN_J20
|
||||
SSn_D[0],PIN_F25
|
||||
SSn_D[1],PIN_F26
|
||||
SSn_D[2],PIN_N18
|
||||
SSn_D[3],PIN_P18
|
||||
MOSI_D,PIN_G23
|
||||
SCLK_D,PIN_G24
|
||||
MISO_D,PIN_K22
|
||||
PWM_OUT_A,PIN_G25
|
||||
PWM_OUT_B,PIN_H23
|
||||
PWM_IN_A,PIN_H24
|
||||
PWM_IN_B,PIN_J23
|
||||
|
||||
MOSI_SCOPE,PIN_W23
|
||||
SCLK_SCOPE,PIN_V23
|
||||
MISO_SCOPE,PIN_W25
|
||||
|
||||
LCD_RW,PIN_K4
|
||||
LCD_EN,PIN_K3
|
||||
LCD_RS,PIN_K1
|
||||
LCD_DATA[0],PIN_J1
|
||||
LCD_DATA[1],PIN_J2
|
||||
LCD_DATA[2],PIN_H1
|
||||
LCD_DATA[3],PIN_H2
|
||||
LCD_DATA[4],PIN_J4
|
||||
LCD_DATA[5],PIN_J3
|
||||
LCD_DATA[6],PIN_H4
|
||||
LCD_DATA[7],PIN_H3
|
||||
LCD_ON,PIN_L4
|
||||
LCD_BLON,PIN_K2
|
||||
|
||||
KEY[0],PIN_G26
|
||||
KEY[1],PIN_N23
|
||||
KEY[2],PIN_P23
|
||||
KEY[3],PIN_W26
|
||||
|
BIN
labor_4/res/spi_master/quartus/output_files/led_chaser.sof
Normal file
BIN
labor_4/res/spi_master/quartus/output_files/led_chaser.sof
Normal file
Binary file not shown.
21
labor_4/res/spi_master/sim/libs/spi_master/_info
Normal file
21
labor_4/res/spi_master/sim/libs/spi_master/_info
Normal file
@@ -0,0 +1,21 @@
|
||||
m255
|
||||
K3
|
||||
13
|
||||
cModel Technology
|
||||
dC:\digitale_systeme\spi_master\sim
|
||||
vspi_master
|
||||
!s100 PDm=HJzS7gNQJSYmeO1UX1
|
||||
IN33U<eK;gRE;z6ImB8iaH3
|
||||
VVAEF_7[2`JEP650]dTjC60
|
||||
d.
|
||||
Fnofile
|
||||
L0 4
|
||||
OV;L;10.1b;51
|
||||
r1
|
||||
!s85 0
|
||||
31
|
||||
!s108 1521123190.954000
|
||||
!s107 ../src/spi_master.v|
|
||||
!s90 -reportprogress|300|-quiet|-nodebug|-work|spi_master|../src/spi_master.v|
|
||||
!s101 -O0
|
||||
o-quiet -nodebug -nodebug -work spi_master -O0
|
||||
3
labor_4/res/spi_master/sim/libs/spi_master/_vmake
Normal file
3
labor_4/res/spi_master/sim/libs/spi_master/_vmake
Normal file
@@ -0,0 +1,3 @@
|
||||
m255
|
||||
K3
|
||||
cModel Technology
|
||||
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
library verilog;
|
||||
use verilog.vl_types.all;
|
||||
entity spi_master is
|
||||
port(
|
||||
RESETn : in vl_logic;
|
||||
CLK : in vl_logic;
|
||||
CLK_DIVIDER : in vl_logic_vector(7 downto 0);
|
||||
SLAVE_SELECT : in vl_logic_vector(7 downto 0);
|
||||
DATA_LENGTH : in vl_logic_vector(1 downto 0);
|
||||
MODE : in vl_logic_vector(1 downto 0);
|
||||
MISO : in vl_logic;
|
||||
TX : in vl_logic_vector(31 downto 0);
|
||||
RUN : in vl_logic;
|
||||
RX : out vl_logic_vector(31 downto 0);
|
||||
SCLK : out vl_logic;
|
||||
MOSI : out vl_logic;
|
||||
SSn : out vl_logic_vector(7 downto 0);
|
||||
BUSY : out vl_logic;
|
||||
SYNC_TEST : out vl_logic;
|
||||
STATE_TEST : out vl_logic_vector(2 downto 0);
|
||||
ENA_TEST : out vl_logic
|
||||
);
|
||||
end spi_master;
|
||||
Binary file not shown.
Binary file not shown.
19
labor_4/res/spi_master/sim/sim.do
Normal file
19
labor_4/res/spi_master/sim/sim.do
Normal file
@@ -0,0 +1,19 @@
|
||||
#remove working directory
|
||||
file delete -force work
|
||||
|
||||
#Creating the work lib
|
||||
vlib work
|
||||
vmap work work
|
||||
|
||||
|
||||
#Top level testbench
|
||||
vlog spi_master_tb.v \
|
||||
../src/spi_master.v
|
||||
|
||||
#Simulate
|
||||
vsim -c -t ps spi_master_tb
|
||||
|
||||
#get wave
|
||||
do wave.do
|
||||
|
||||
run 25 us
|
||||
19
labor_4/res/spi_master/sim/sim_w_lib.do
Normal file
19
labor_4/res/spi_master/sim/sim_w_lib.do
Normal file
@@ -0,0 +1,19 @@
|
||||
#remove working directory
|
||||
file delete -force work
|
||||
|
||||
#Creating the work lib
|
||||
vlib work
|
||||
vmap work work
|
||||
vlib "libs/spi_master"
|
||||
vmap spi_master "libs/spi_master"
|
||||
|
||||
#Top level testbench
|
||||
vlog spi_master_tb.v
|
||||
|
||||
#Simulate
|
||||
vsim -c -t ps -L spi_master spi_master_tb
|
||||
|
||||
#get wave
|
||||
do wave.do
|
||||
|
||||
run 25 us
|
||||
96
labor_4/res/spi_master/sim/spi_master_tb.v
Normal file
96
labor_4/res/spi_master/sim/spi_master_tb.v
Normal file
@@ -0,0 +1,96 @@
|
||||
`timescale 1ns/1ps
|
||||
|
||||
module spi_master_tb;
|
||||
// top level testbench, no inputs or outputs
|
||||
|
||||
reg RESETn_TB, RUN_TB, CLOCK_50_TB;
|
||||
reg [7:0] CLK_DIVIDER_TB, SLAVE_SELECT_TB;
|
||||
reg [1:0] DATA_LENGTH_TB, MODE_TB;
|
||||
reg [31:0] TX_TB;
|
||||
|
||||
//DUT module outputs
|
||||
wire [31:0] RX_TB;
|
||||
wire [7:0] SSn_TB;
|
||||
wire SCLK_TB, MOSI_TB, BUSY_TB, MISO_TB;
|
||||
|
||||
//DUT test signals
|
||||
wire [2:0] STATE_TEST_TB;
|
||||
wire SYNC_TEST_TB, ENA_TEST_TB;
|
||||
|
||||
assign MISO_TB = 1'b0;
|
||||
|
||||
initial begin
|
||||
// Reset
|
||||
CLOCK_50_TB <= 1'b0;
|
||||
RESETn_TB <= 1'b1;
|
||||
|
||||
TX_TB <= 32'h0;
|
||||
CLK_DIVIDER_TB <= 8'h0;
|
||||
SLAVE_SELECT_TB <= 8'h0;
|
||||
DATA_LENGTH_TB <= 2'b00;
|
||||
MODE_TB <= 2'b00;
|
||||
RUN_TB <= 1'b0;
|
||||
|
||||
#20 RESETn_TB <= 1'b0;
|
||||
#80 RESETn_TB <= 1'b1;
|
||||
|
||||
// spi_master setup: 8 Bit Daten, Mode 0
|
||||
|
||||
TX_TB <= 32'h000000AA;
|
||||
CLK_DIVIDER_TB <= 8'h1;
|
||||
SLAVE_SELECT_TB <= 8'h1;
|
||||
DATA_LENGTH_TB <= 2'b00;
|
||||
MODE_TB <= 2'b00;
|
||||
|
||||
#100 RUN_TB <= 1'b1;
|
||||
#100 RUN_TB <= 1'b0;
|
||||
|
||||
#5000
|
||||
|
||||
// spi_master setup: 16 Bit Daten, Mode 3
|
||||
TX_TB <= 32'h000084A8;
|
||||
CLK_DIVIDER_TB <= 8'h4;
|
||||
SLAVE_SELECT_TB <= 8'h1;
|
||||
DATA_LENGTH_TB <= 2'b01;
|
||||
MODE_TB <= 2'b11;
|
||||
|
||||
#100 RUN_TB <= 1'b1;
|
||||
#100 RUN_TB <= 1'b0;
|
||||
|
||||
#7000
|
||||
|
||||
// spi_master setup: 8 Bit Daten, Mode 2
|
||||
TX_TB <= 32'h000084A8;
|
||||
CLK_DIVIDER_TB <= 8'h4;
|
||||
SLAVE_SELECT_TB <= 8'h2;
|
||||
DATA_LENGTH_TB <= 2'b00;
|
||||
MODE_TB <= 2'b10;
|
||||
|
||||
#100 RUN_TB <= 1'b1;
|
||||
#100 RUN_TB <= 1'b0;
|
||||
|
||||
end
|
||||
|
||||
always begin
|
||||
#10 CLOCK_50_TB <= ~CLOCK_50_TB;
|
||||
end
|
||||
|
||||
spi_master spi_master_test(
|
||||
.RESETn(RESETn_TB),
|
||||
.CLK(CLOCK_50_TB),
|
||||
.RUN(RUN_TB),
|
||||
.MODE(MODE_TB),
|
||||
.DATA_LENGTH(DATA_LENGTH_TB),
|
||||
.CLK_DIVIDER(CLK_DIVIDER_TB),
|
||||
.SLAVE_SELECT(SLAVE_SELECT_TB),
|
||||
.TX(TX_TB),
|
||||
.SCLK(SCLK_TB),
|
||||
.MISO(MISO_TB),
|
||||
.MOSI(MOSI_TB),
|
||||
.SSn(SSn_TB),
|
||||
.RX(RX_TB),
|
||||
.BUSY(BUSY_TB),
|
||||
.SYNC_TEST(SYNC_TEST_TB),
|
||||
.STATE_TEST(STATE_TEST_TB),
|
||||
.ENA_TEST(ENA_TEST_TB));
|
||||
endmodule
|
||||
43
labor_4/res/spi_master/sim/wave.do
Normal file
43
labor_4/res/spi_master/sim/wave.do
Normal file
@@ -0,0 +1,43 @@
|
||||
onerror {resume}
|
||||
quietly WaveActivateNextPane {} 0
|
||||
add wave -noupdate /spi_master_tb/RESETn_TB
|
||||
add wave -noupdate /spi_master_tb/RUN_TB
|
||||
add wave -noupdate /spi_master_tb/CLOCK_50_TB
|
||||
add wave -noupdate -radix unsigned /spi_master_tb/CLK_DIVIDER_TB
|
||||
add wave -noupdate /spi_master_tb/SLAVE_SELECT_TB
|
||||
add wave -noupdate /spi_master_tb/DATA_LENGTH_TB
|
||||
add wave -noupdate -radix unsigned /spi_master_tb/MODE_TB
|
||||
add wave -noupdate -radix hexadecimal /spi_master_tb/TX_TB
|
||||
add wave -noupdate -radix hexadecimal /spi_master_tb/RX_TB
|
||||
add wave -noupdate -divider {SPI Interface}
|
||||
add wave -noupdate /spi_master_tb/SSn_TB
|
||||
add wave -noupdate /spi_master_tb/SCLK_TB
|
||||
add wave -noupdate /spi_master_tb/MOSI_TB
|
||||
add wave -noupdate /spi_master_tb/BUSY_TB
|
||||
add wave -noupdate /spi_master_tb/MISO_TB
|
||||
add wave -noupdate -divider {SPI Master intern}
|
||||
add wave -noupdate /spi_master_tb/SYNC_TEST_TB
|
||||
add wave -noupdate -radix unsigned -childformat {{{/spi_master_tb/STATE_TEST_TB[2]} -radix unsigned} {{/spi_master_tb/STATE_TEST_TB[1]} -radix unsigned} {{/spi_master_tb/STATE_TEST_TB[0]} -radix unsigned}} -subitemconfig {{/spi_master_tb/STATE_TEST_TB[2]} {-radix unsigned} {/spi_master_tb/STATE_TEST_TB[1]} {-radix unsigned} {/spi_master_tb/STATE_TEST_TB[0]} {-radix unsigned}} /spi_master_tb/STATE_TEST_TB
|
||||
add wave -noupdate /spi_master_tb/ENA_TEST_TB
|
||||
add wave -noupdate /spi_master_tb/spi_master_test/BUSY
|
||||
add wave -noupdate -radix hexadecimal /spi_master_tb/spi_master_test/TX_SR
|
||||
add wave -noupdate -radix hexadecimal /spi_master_tb/spi_master_test/RX_SR
|
||||
add wave -noupdate -radix unsigned /spi_master_tb/spi_master_test/CYCLE_CTR
|
||||
TreeUpdate [SetDefaultTree]
|
||||
WaveRestoreCursors {{Cursor 1} {0 ps} 0}
|
||||
quietly wave cursor active 0
|
||||
configure wave -namecolwidth 232
|
||||
configure wave -valuecolwidth 100
|
||||
configure wave -justifyvalue left
|
||||
configure wave -signalnamewidth 0
|
||||
configure wave -snapdistance 10
|
||||
configure wave -datasetprefix 0
|
||||
configure wave -rowmargin 4
|
||||
configure wave -childrowmargin 2
|
||||
configure wave -gridoffset 0
|
||||
configure wave -gridperiod 1
|
||||
configure wave -griddelta 40
|
||||
configure wave -timeline 0
|
||||
configure wave -timelineunits ns
|
||||
update
|
||||
WaveRestoreZoom {0 ps} {1640626 ps}
|
||||
93
labor_4/res/spi_master/src/led_chaser.v
Normal file
93
labor_4/res/spi_master/src/led_chaser.v
Normal file
@@ -0,0 +1,93 @@
|
||||
module led_chaser(
|
||||
// module inputs
|
||||
CLOCK_50,
|
||||
KEY,
|
||||
SW,
|
||||
// module outputs
|
||||
SSn_D,
|
||||
MOSI_D,
|
||||
SCLK_D,
|
||||
LEDR
|
||||
);
|
||||
|
||||
input [3:0] KEY;
|
||||
input CLOCK_50;
|
||||
input [15:0] SW;
|
||||
output [3:0] SSn_D;
|
||||
output MOSI_D, SCLK_D;
|
||||
output [15:0] LEDR;
|
||||
|
||||
assign LEDR = LEDS;
|
||||
|
||||
// Reset wire
|
||||
wire RESETn;
|
||||
assign RESETn = KEY[0];
|
||||
|
||||
wire [15:0] LEDS;
|
||||
reg [9:0] CLKDIV0, CLKDIV1, CLKDIV2;
|
||||
|
||||
`define DIVVAL0 1000-1
|
||||
`define DIVVAL1 1000-1
|
||||
`define DIVVAL2 50-1
|
||||
|
||||
// Clock Divider
|
||||
always @(posedge CLOCK_50 or negedge RESETn)
|
||||
if (~RESETn) CLKDIV0 <=`DIVVAL0;
|
||||
else if (CLKDIV0 > 10'b0)
|
||||
CLKDIV0[9:0] <= CLKDIV0[9:0] - 1'b1;
|
||||
else
|
||||
CLKDIV0[9:0] <= `DIVVAL0;
|
||||
|
||||
always @(posedge CLOCK_50 or negedge RESETn)
|
||||
if (~RESETn) CLKDIV1 <=`DIVVAL1;
|
||||
else if (CLKDIV0[9:0] == 10'b0)
|
||||
begin
|
||||
if (CLKDIV1 > 10'b0)
|
||||
CLKDIV1[9:0] <= CLKDIV1[9:0] - 1'b1;
|
||||
else
|
||||
CLKDIV1[9:0] <= `DIVVAL1;
|
||||
end
|
||||
|
||||
always @(posedge CLOCK_50 or negedge RESETn)
|
||||
if (~RESETn) CLKDIV2<=`DIVVAL2;
|
||||
else if ((CLKDIV1[9:0] == 10'b0) & (CLKDIV0[9:0] == 10'b0))
|
||||
begin
|
||||
if (CLKDIV2 > 10'b0)
|
||||
CLKDIV2[9:0] <= CLKDIV2[9:0] - 1'b1;
|
||||
else
|
||||
CLKDIV2[9:0] <= `DIVVAL2;
|
||||
end
|
||||
|
||||
// ring_sr
|
||||
|
||||
ring_sr ring_shift_reg(
|
||||
.CLK(CLOCK_50),
|
||||
.RSTn(RESETn),
|
||||
.ENA((CLKDIV0[9:0] == 10'b0) & (CLKDIV1[9:0] == 10'b0) & (CLKDIV2[9:0] == 10'b0)),
|
||||
.PATTERN(SW),
|
||||
.Q(LEDS[15:0]));
|
||||
|
||||
// SPI-Master
|
||||
spi_master spimaster(
|
||||
.RESETn(RESETn),
|
||||
.CLK(CLOCK_50),
|
||||
.CLK_DIVIDER(8'd10),
|
||||
.SLAVE_SELECT(8'h1),
|
||||
.DATA_LENGTH(2'd1),
|
||||
.MODE(2'd1),
|
||||
.MISO(1'b1),
|
||||
.TX({16'h0,LEDS}),
|
||||
.RUN((CLKDIV0[9:0] == 10'b0) & (CLKDIV1[9:0] == 10'b0) & (CLKDIV2[9:0] == 10'b0)),
|
||||
//module outputs
|
||||
.RX(),
|
||||
.SCLK(SCLK_D),
|
||||
.MOSI(MOSI_D),
|
||||
.SSn(SSn_D),
|
||||
.BUSY(),
|
||||
// module test outputs
|
||||
.SYNC_TEST(),
|
||||
.STATE_TEST(),
|
||||
.ENA_TEST()
|
||||
);
|
||||
|
||||
endmodule
|
||||
23
labor_4/res/spi_master/src/ring_sr.v
Normal file
23
labor_4/res/spi_master/src/ring_sr.v
Normal file
@@ -0,0 +1,23 @@
|
||||
module ring_sr(
|
||||
//inputs
|
||||
PATTERN,
|
||||
CLK,
|
||||
RSTn,
|
||||
ENA,
|
||||
//outputs
|
||||
Q);
|
||||
|
||||
input [15:0] PATTERN;
|
||||
input CLK,RSTn,ENA;
|
||||
output reg [15:0] Q;
|
||||
|
||||
always @(posedge CLK)
|
||||
if(~RSTn) Q <= PATTERN;
|
||||
|
||||
else if (ENA)
|
||||
begin
|
||||
Q[15:1] <= Q[14:0];
|
||||
Q[0] <= Q[15];
|
||||
end
|
||||
|
||||
endmodule // ring_sr
|
||||
86
labor_4/res/spi_master/src/spi_master_template.v
Normal file
86
labor_4/res/spi_master/src/spi_master_template.v
Normal file
@@ -0,0 +1,86 @@
|
||||
// module spi_master
|
||||
// Author: M. Walz
|
||||
|
||||
module spi_master(
|
||||
//module inputs
|
||||
// --- Definition of control inputs ---
|
||||
input wire RESETn,
|
||||
input wire CLK,
|
||||
input wire [7:0] CLK_DIVIDER,
|
||||
input wire [7:0] SLAVE_SELECT,
|
||||
input wire [1:0] DATA_LENGTH,
|
||||
input wire [1:0] MODE,
|
||||
input wire MISO,
|
||||
input wire [31:0] TX,
|
||||
input wire RUN,
|
||||
//module outputs
|
||||
output reg [31:0] RX,
|
||||
output SCLK,
|
||||
output reg MOSI,
|
||||
output reg [7:0] SSn,
|
||||
output reg BUSY,
|
||||
// module test outputs
|
||||
output wire SYNC_TEST,
|
||||
output wire [2:0] STATE_TEST,
|
||||
output wire ENA_TEST
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
// --- Definition of internal varibles ---
|
||||
reg [31:0]TX_SR, RX_SR;
|
||||
reg [7:0] CLK_DIVIDER_REG;
|
||||
reg [5:0] CYCLE_CTR;
|
||||
reg [2:0] STATE;
|
||||
reg ENA; // Enables operation of SCLK generator
|
||||
reg T1, Q1; // Used for SLCK generation
|
||||
wire CPOL, CPHA; // SPI Mode
|
||||
wire SYNC; // SYNC Signal
|
||||
|
||||
// --- Implementation ---
|
||||
|
||||
// assignments of test signals
|
||||
assign STATE_TEST = STATE;
|
||||
assign ENA_TEST = ENA;
|
||||
assign SYNC_TEST = SYNC;
|
||||
|
||||
// assignments MODE to control wires
|
||||
assign CPOL = MODE [1];
|
||||
assign CPHA = MODE [0];
|
||||
|
||||
// Clockdivider for generation of SYNC signal
|
||||
|
||||
always @ (posedge CLK or negedge RESETn) begin
|
||||
end
|
||||
|
||||
// SPI-interface control logic
|
||||
|
||||
always @ (posedge CLK or negedge RESETn) begin
|
||||
if (~RESETn) begin
|
||||
end
|
||||
else case (STATE)
|
||||
// STATE: Wait
|
||||
|
||||
// STATE: Initialize
|
||||
|
||||
// STATE: Shift
|
||||
|
||||
// STATE: Latch
|
||||
|
||||
// STATE:
|
||||
|
||||
// When transfering data from RX to RX_SR, ignore previously received bytes
|
||||
case (DATA_LENGTH[1:0])
|
||||
2'h0 : RX[31:0] <= {24'h0, RX_SR[ 7:0]}; // 1 Byte received
|
||||
2'h1 : // 2 Bytes received
|
||||
2'h2 : // 3 Bytes received
|
||||
2'h3 : // 4 Bytes received
|
||||
endcase
|
||||
|
||||
endcase
|
||||
end
|
||||
|
||||
// SPI SCLK generation
|
||||
|
||||
endmodule
|
||||
Reference in New Issue
Block a user