WH-16 - Imported latest version of POF-Tx from the SMB (supporting the encoder multiplier), latest version of the POF-Rx (timing improvements)
This commit is contained in:
parent
9a8789b42b
commit
edca9fe387
10 changed files with 2081 additions and 1 deletions
3
generic_ip/pof_protocol/1/Readme.txt
Normal file
3
generic_ip/pof_protocol/1/Readme.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Golay Encoder/Decoder blocks included in the folder are not actually
|
||||
used in this version of the protocol, which is a simple extension of the
|
||||
original protocol.
|
||||
78
generic_ip/pof_protocol/1/sim/sim_pof_txrx.do
Normal file
78
generic_ip/pof_protocol/1/sim/sim_pof_txrx.do
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
# Simulation macro Net-Sync testbench
|
||||
|
||||
.main clear
|
||||
|
||||
# Cleanup libraries
|
||||
foreach lib [list work OSVVM] {
|
||||
file delete -force -- $lib
|
||||
vlib $lib
|
||||
}
|
||||
|
||||
set COMP_ONLY 0
|
||||
|
||||
set TB_PATH ./../src/test
|
||||
set COMMON_PATH ../../../common/0/src
|
||||
set OSVVM_PATH $COMMON_PATH/test/OSVVM
|
||||
|
||||
set WORKLIB work
|
||||
|
||||
vlib ./work
|
||||
vmap work ./work
|
||||
|
||||
if {$COMP_ONLY == 0} {
|
||||
# Compile the constrained random related packages
|
||||
vlib OSVVM
|
||||
vcom -2008 -work OSVVM \
|
||||
$OSVVM_PATH/RandomBasePkg.vhd \
|
||||
$OSVVM_PATH/SortListPkg_int.vhd \
|
||||
$OSVVM_PATH/RandomPkg.vhd \
|
||||
$OSVVM_PATH/NamePkg.vhd \
|
||||
$OSVVM_PATH/MessagePkg.vhd \
|
||||
$OSVVM_PATH/CoveragePkg.vhd
|
||||
}
|
||||
|
||||
# compile the UUTs:
|
||||
#vcom -2008 -work $WORKLIB $COMMON_PATH/pkg_functions.vhd
|
||||
vcom -2008 -work $WORKLIB $COMMON_PATH/common_pkg.vhd
|
||||
vcom -2008 -work $WORKLIB $COMMON_PATH/sync_wire.vhd
|
||||
vcom -2008 -work $WORKLIB $COMMON_PATH/sync_wire_redge.vhd
|
||||
--vcom -2008 -work $WORKLIB ../src/altera/fifo_16x8.vhd
|
||||
vcom -2008 -work $WORKLIB $COMMON_PATH/altera/sync_fifo.vhd
|
||||
vcom -2008 -work $WORKLIB ../src/uart_tx_1.vhd
|
||||
vcom -2008 -work $WORKLIB ../src/uart_rx_1.vhd
|
||||
vcom -2008 -work $WORKLIB ../src/pof_tx_1.vhd
|
||||
vcom -2008 -work $WORKLIB ../src//pof_rx_1.vhd
|
||||
|
||||
|
||||
# Compile the testbench and the other components supporting the test
|
||||
if {$COMP_ONLY == 0} {
|
||||
# Test support packages
|
||||
vcom -2008 -work $WORKLIB $COMMON_PATH/test/common_test_pkg.vhd
|
||||
vcom -2008 -work $WORKLIB $COMMON_PATH/test/log_pkg.vhd
|
||||
vcom -2008 -work $WORKLIB $COMMON_PATH/test/avalon_verify_pkg.vhd
|
||||
|
||||
# Testbench
|
||||
vcom -2008 -work $WORKLIB $TB_PATH/pof_tx_rx_1_tb.vhd
|
||||
|
||||
vsim -t ps work.pof_tx_rx_1_tb
|
||||
|
||||
|
||||
#add wave /pof_tx_rx_1_tb/*
|
||||
#add wave /pof_tx_rx_1_tb/iPOF_TX/*
|
||||
#add wave /pof_tx_rx_1_tb/iPOF_RX/*
|
||||
|
||||
# remove warnings from standard numeric/arithmetic packages (speed-up simulation)
|
||||
set StdArithNoWarnings 1
|
||||
set NumericStdNoWarnings 1
|
||||
|
||||
do wave_pof_txrx.do
|
||||
|
||||
when -label end_of_simulation {test_completed == true} {echo "Simulation Completed"; stop ;}
|
||||
run -all
|
||||
|
||||
#run 1 ms;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
238
generic_ip/pof_protocol/1/sim/wave_pof_txrx.do
Normal file
238
generic_ip/pof_protocol/1/sim/wave_pof_txrx.do
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
onerror {resume}
|
||||
quietly WaveActivateNextPane {} 0
|
||||
add wave -noupdate /pof_tx_rx_1_tb/clk
|
||||
add wave -noupdate /pof_tx_rx_1_tb/reset_n
|
||||
add wave -noupdate /pof_tx_rx_1_tb/avs_read
|
||||
add wave -noupdate /pof_tx_rx_1_tb/avs_write
|
||||
add wave -noupdate /pof_tx_rx_1_tb/sel_slave_0
|
||||
add wave -noupdate /pof_tx_rx_1_tb/sel_slave_1
|
||||
add wave -noupdate /pof_tx_rx_1_tb/avs_write_sl0
|
||||
add wave -noupdate /pof_tx_rx_1_tb/avs_read_sl0
|
||||
add wave -noupdate /pof_tx_rx_1_tb/avs_readdatavalid_sl0
|
||||
add wave -noupdate /pof_tx_rx_1_tb/avs_write_sl1
|
||||
add wave -noupdate /pof_tx_rx_1_tb/avs_read_sl1
|
||||
add wave -noupdate /pof_tx_rx_1_tb/avs_readdatavalid_sl1
|
||||
add wave -noupdate /pof_tx_rx_1_tb/init_tx
|
||||
add wave -noupdate /pof_tx_rx_1_tb/init_rx
|
||||
add wave -noupdate /pof_tx_rx_1_tb/dir_in
|
||||
add wave -noupdate /pof_tx_rx_1_tb/pd_in
|
||||
add wave -noupdate /pof_tx_rx_1_tb/inc_pos
|
||||
add wave -noupdate /pof_tx_rx_1_tb/dec_pos
|
||||
add wave -noupdate -radix decimal /pof_tx_rx_1_tb/abs_position
|
||||
add wave -noupdate /pof_tx_rx_1_tb/tx_data
|
||||
add wave -noupdate /pof_tx_rx_1_tb/rx_data
|
||||
add wave -noupdate /pof_tx_rx_1_tb/init_out
|
||||
add wave -noupdate /pof_tx_rx_1_tb/dir_out
|
||||
add wave -noupdate /pof_tx_rx_1_tb/enc_out
|
||||
add wave -noupdate /pof_tx_rx_1_tb/pd_out
|
||||
add wave -noupdate /pof_tx_rx_1_tb/inc_pos_out
|
||||
add wave -noupdate /pof_tx_rx_1_tb/dec_pos_out
|
||||
add wave -noupdate -radix decimal /pof_tx_rx_1_tb/abs_pos_out
|
||||
add wave -noupdate /pof_tx_rx_1_tb/test_completed
|
||||
add wave -noupdate /pof_tx_rx_1_tb/running
|
||||
add wave -noupdate /pof_tx_rx_1_tb/configuring
|
||||
add wave -noupdate /pof_tx_rx_1_tb/passed
|
||||
add wave -noupdate /pof_tx_rx_1_tb/failed
|
||||
add wave -noupdate /pof_tx_rx_1_tb/stimuli_completed
|
||||
add wave -noupdate /pof_tx_rx_1_tb/avs_address
|
||||
add wave -noupdate -radix hexadecimal /pof_tx_rx_1_tb/avs_writedata
|
||||
add wave -noupdate -radix hexadecimal /pof_tx_rx_1_tb/avs_readdata_sl0
|
||||
add wave -noupdate -radix hexadecimal /pof_tx_rx_1_tb/avs_readdata_sl1
|
||||
add wave -noupdate -radix decimal /pof_tx_rx_1_tb/abs_position_d
|
||||
add wave -noupdate -radix decimal /pof_tx_rx_1_tb/swathe_pos
|
||||
add wave -noupdate /pof_tx_rx_1_tb/swathe_cnt
|
||||
add wave -noupdate -radix hexadecimal /pof_tx_rx_1_tb/avs_m
|
||||
add wave -noupdate -radix hexadecimal /pof_tx_rx_1_tb/avs_s
|
||||
add wave -noupdate /pof_tx_rx_1_tb/detected_error
|
||||
add wave -noupdate /pof_tx_rx_1_tb/dir_discr_cnt
|
||||
add wave -noupdate /pof_tx_rx_1_tb/pd_discr_cnt
|
||||
add wave -noupdate /pof_tx_rx_1_tb/pd_in_cnt
|
||||
add wave -noupdate /pof_tx_rx_1_tb/pd_out_cnt
|
||||
add wave -noupdate -radix decimal /pof_tx_rx_1_tb/abs_position
|
||||
add wave -noupdate -radix decimal /pof_tx_rx_1_tb/abs_pos_out
|
||||
add wave -noupdate /pof_tx_rx_1_tb/pos_discr_cnt
|
||||
add wave -noupdate /pof_tx_rx_1_tb/end_of_swathe
|
||||
add wave -noupdate /pof_tx_rx_1_tb/enc_pulse_cnt
|
||||
add wave -noupdate /pof_tx_rx_1_tb/dir_err
|
||||
add wave -noupdate /pof_tx_rx_1_tb/pd_err
|
||||
add wave -noupdate /pof_tx_rx_1_tb/pos_err
|
||||
add wave -noupdate /pof_tx_rx_1_tb/enc_err
|
||||
add wave -noupdate /pof_tx_rx_1_tb/ovfl_err
|
||||
add wave -noupdate /pof_tx_rx_1_tb/injected_errors
|
||||
add wave -noupdate /pof_tx_rx_1_tb/max_pos
|
||||
add wave -noupdate /pof_tx_rx_1_tb/min_pos
|
||||
add wave -noupdate /pof_tx_rx_1_tb/exp_enc_pulse
|
||||
add wave -noupdate /pof_tx_rx_1_tb/enc_discr
|
||||
add wave -noupdate /pof_tx_rx_1_tb/exp_enc_cnt
|
||||
add wave -noupdate /pof_tx_rx_1_tb/error_rate_thres
|
||||
add wave -noupdate /pof_tx_rx_1_tb/one_pps
|
||||
add wave -noupdate /pof_tx_rx_1_tb/max_error_flag
|
||||
add wave -noupdate /pof_tx_rx_1_tb/rx_watchdog
|
||||
add wave -noupdate /pof_tx_rx_1_tb/rx_watchdog_en
|
||||
add wave -noupdate /pof_tx_rx_1_tb/rx_watchdog_clr
|
||||
add wave -noupdate -divider EMB2POF
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/reset_n
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/clk
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/init
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/pd_in
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/inc_pos
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/dec_pos
|
||||
add wave -noupdate -radix decimal /pof_tx_rx_1_tb/iPOF_TX/abs_position
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/tx_data
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/avs_address
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/avs_write
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/avs_writedata
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/avs_read
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/avs_readdatavalid
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/avs_readdata
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/rd_event
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/wr_event
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/empty
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/full
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/tx_ready
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/rd_event_d
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/wr_event_i
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/enable
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/toggle_sync
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/toggle_pd
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/add_keepalive
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/ovfl_err
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/init_d
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/init_gen
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/init_v
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/init_blocked
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/init_blk_cnt
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/parity_bit
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/inject_error
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/inject_error_req
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/pd_event
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/pd_event_d
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/pd_event_dd
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/gray
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/clear
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/pd_in_d
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/pd_gen
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/clk
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/symbol_valid
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/symbol
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/clr_fifo_lmax
|
||||
add wave -noupdate -radix unsigned /pof_tx_rx_1_tb/iPOF_TX/keepalive_period
|
||||
add wave -noupdate -radix unsigned /pof_tx_rx_1_tb/iPOF_TX/init_blocked_period
|
||||
add wave -noupdate -radix unsigned /pof_tx_rx_1_tb/iPOF_TX/fifo_level
|
||||
add wave -noupdate -radix unsigned /pof_tx_rx_1_tb/iPOF_TX/fifo_level_max
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/tx_data
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/event_in_i
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/event_in
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_TX/event_out
|
||||
add wave -noupdate -radix decimal /pof_tx_rx_1_tb/iPOF_TX/keepalive_cnt
|
||||
add wave -noupdate -divider POF2HMB
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/reset_n
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/clk
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/init
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/rx_clk
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/rx_data
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/init_out
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/enc_out
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/pd_out
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/inc_pos
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/dec_pos
|
||||
add wave -noupdate -radix decimal /pof_tx_rx_1_tb/iPOF_RX/abs_pos
|
||||
add wave -noupdate -radix unsigned /pof_tx_rx_1_tb/iPOF_RX/error_rate_thres
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/one_pps
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/max_error_flag
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/rx_watchdog
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/rx_watchdog_en
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/rx_watchdog_clr
|
||||
add wave -noupdate -radix unsigned /pof_tx_rx_1_tb/iPOF_RX/rx_wd_cnt
|
||||
add wave -noupdate -radix unsigned /pof_tx_rx_1_tb/iPOF_RX/error_rate_cnt
|
||||
add wave -noupdate -radix unsigned /pof_tx_rx_1_tb/iPOF_RX/error_rate
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/clear
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/clear_i
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/inc_pos_i
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/dec_pos_i
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/enable
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/sync_gen
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/pd_gen
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/symbol_error
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/rx_symbol_val
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/rx_symbol
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/rx_symbol_val_v
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/symbol_valid_i
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/symbol_valid_d
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/toggle_sync
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/sync_confirmed
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/sync_toggle_test
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/sync
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/toggle_pd
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/pd_confirmed
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/pd_toggle_test
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/pd
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/valid_pos
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/upd_pos
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/corr_done
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/corr_sign
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/skip_cnt
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/skip_pos
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/symbol_valid
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/symbol
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/apply_corr
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/clk_cnt
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/dist
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/abs_dist
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/next_pos_lsb
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/curr_pos_lsb
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/pos_corr
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/max_dist
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/gray_pos
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/symbol_i
|
||||
add wave -noupdate -radix unsigned /pof_tx_rx_1_tb/iPOF_RX/parity_err_cnt
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/enc_out
|
||||
add wave -noupdate -radix decimal /pof_tx_rx_1_tb/iPOF_RX/abs_pos_i
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/inc_pos_ii
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/dec_pos_ii
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/new_max
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/new_min
|
||||
add wave -noupdate -radix decimal /pof_tx_rx_1_tb/iPOF_RX/pos_max
|
||||
add wave -noupdate -radix decimal /pof_tx_rx_1_tb/iPOF_RX/pos_min
|
||||
add wave -noupdate -radix decimal /pof_tx_rx_1_tb/iPOF_RX/dist_pos
|
||||
add wave -noupdate -radix decimal /pof_tx_rx_1_tb/iPOF_RX/dist_neg
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/data_width
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/reset_n
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/clk
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/bit_div
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/init
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/data_out
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/data_out_valid
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/rx_data
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/fsm_state_curr
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/fsm_state_next
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/rx_data_i
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/shf_data
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/rst_bit_cnt
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/inc_bit_cnt
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/rst_clk_cnt
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/end_of_bit
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/end_of_rx
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/data_valid
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/stop_bit
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/data
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/clk_cnt
|
||||
add wave -noupdate /pof_tx_rx_1_tb/iPOF_RX/iRX_SYMBOL/bit_cnt
|
||||
TreeUpdate [SetDefaultTree]
|
||||
WaveRestoreCursors {{Cursor 1} {18949975000 ps} 0}
|
||||
quietly wave cursor active 1
|
||||
configure wave -namecolwidth 305
|
||||
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 ps
|
||||
update
|
||||
WaveRestoreZoom {0 ps} {12884901888 ps}
|
||||
358
generic_ip/pof_protocol/1/src/pof_rx_1.vhd
Normal file
358
generic_ip/pof_protocol/1/src/pof_rx_1.vhd
Normal file
|
|
@ -0,0 +1,358 @@
|
|||
-------------------------------------------------------------------------------
|
||||
-- Title : pof_rx
|
||||
-- Project : SMB
|
||||
-------------------------------------------------------------------------------
|
||||
-- File : pof_rx.vhd
|
||||
-- Author : Gianmarco Girau
|
||||
-- Company : Global Inkjet Systems
|
||||
-- Created : 2017-08-23
|
||||
-- Last update: 2019-09-20
|
||||
-- SVN ID : Git
|
||||
-- Standard : VHDL'08
|
||||
-------------------------------------------------------------------------------
|
||||
-- Description:
|
||||
-- Deserializes and decodes the EMS (SMB) output, received from the POF.
|
||||
-------------------------------------------------------------------------------
|
||||
-- altera vhdl_input_version vhdl_2008
|
||||
|
||||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
use ieee.numeric_std.all;
|
||||
|
||||
entity pof_rx_1 is
|
||||
port(
|
||||
reset_n : in std_logic;
|
||||
clk : in std_logic;
|
||||
--
|
||||
init : in std_logic;
|
||||
rx_clk : in std_logic;
|
||||
rx_data : in std_logic;
|
||||
init_out : out std_logic;
|
||||
dp_dir : in std_logic;
|
||||
enc_out : out std_logic;
|
||||
pd_out : out std_logic;
|
||||
inc_pos : out std_logic;
|
||||
dec_pos : out std_logic;
|
||||
abs_pos : out std_logic_vector(31 downto 0);
|
||||
-- C&S
|
||||
enable : in std_logic;
|
||||
bit_div : in std_logic_vector(3 downto 0);
|
||||
error_rate_thres : in std_logic_vector(7 downto 0);
|
||||
one_pps : in std_logic;
|
||||
upd_max_pos : in std_logic;
|
||||
upd_min_pos : in std_logic;
|
||||
max_error_flag : out std_logic;
|
||||
rx_watchdog : out std_logic;
|
||||
rx_watchdog_en : in std_logic;
|
||||
rx_watchdog_clr : in std_logic;
|
||||
parity_err_cnt : out std_logic_vector(15 downto 0);
|
||||
skip_pos_cnt : out std_logic_vector(15 downto 0));
|
||||
end entity pof_rx_1;
|
||||
|
||||
architecture rtl of pof_rx_1 is
|
||||
|
||||
-- check the parity bit (odd parity)
|
||||
function odd_parity_check(data : std_logic_vector) return std_logic is
|
||||
variable parity_bit : std_logic := '0';
|
||||
begin
|
||||
for n in 0 to data'length - 1 loop
|
||||
parity_bit := parity_bit xor data(n);
|
||||
end loop; -- n
|
||||
return parity_bit;
|
||||
end function odd_parity_check;
|
||||
|
||||
-- Gray-to-Binary coding
|
||||
function gray2bin(gray : std_logic_vector) return std_logic_vector is
|
||||
variable bin : std_logic_vector(gray'range);
|
||||
begin
|
||||
bin(gray'length - 1) := gray(gray'length - 1);
|
||||
for i in gray'length - 2 downto 0 loop
|
||||
bin(i) := bin(i + 1) xor gray(i);
|
||||
end loop; -- n
|
||||
return bin;
|
||||
end function gray2bin;
|
||||
|
||||
signal clear, symbol_ok, inc_pos_i, dec_pos_i : std_logic;
|
||||
signal sync_gen, pd_gen, symbol_error, sync_d : std_logic;
|
||||
signal symbol_valid, symbol_valid_i, symbol_valid_d : std_logic;
|
||||
signal toggle_sync, sync_confirmed, sync_toggle_test, sync : std_logic;
|
||||
signal toggle_pd, pd_confirmed, pd_toggle_test, pd : std_logic;
|
||||
signal valid_pos, upd_pos, corr_done, corr_sign : std_logic;
|
||||
signal skip_pos, apply_corr, inc_pos_ii, dec_pos_ii : std_logic;
|
||||
signal new_max, new_min, rx_error, rx_error_i : std_logic;
|
||||
signal rx_symbol_val, clear_i, skip_pos_d, pos_recovery : std_logic;
|
||||
signal dp_dir_d, dp_dir_change, max_error_flag_i : std_logic;
|
||||
--
|
||||
signal clk_cnt : std_logic_vector(1 downto 0);
|
||||
signal dist, abs_dist, skip_cnt : std_logic_vector(3 downto 0);
|
||||
signal next_pos_lsb, curr_pos_lsb : std_logic_vector(3 downto 0);
|
||||
signal pos_corr, max_dist, rx_error_v : std_logic_vector(3 downto 0);
|
||||
signal gray_pos, rx_symbol_val_v : std_logic_vector(3 downto 0);
|
||||
signal symbol, symbol_i, rx_symbol : std_logic_vector(7 downto 0);
|
||||
signal rx_wd_cnt : std_logic_vector(9 downto 0);
|
||||
signal parity_err_cnt_i, skip_pos_cnt_i : std_logic_vector(15 downto 0);
|
||||
signal error_rate_cnt, error_rate : std_logic_vector(15 downto 0);
|
||||
signal abs_pos_i, pos_max, pos_min : std_logic_vector(31 downto 0);
|
||||
signal dist_pos, dist_neg : std_logic_vector(31 downto 0);
|
||||
|
||||
begin
|
||||
|
||||
clear <= not enable or init;
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- De-serialize symbols (Serial clock at 300 MHz - typical)
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
iRX_SYMBOL : entity work.uart_rx_1
|
||||
generic map(
|
||||
data_width => 8)
|
||||
port map(
|
||||
reset_n => reset_n,
|
||||
clk => rx_clk,
|
||||
bit_div => bit_div,
|
||||
init => clear_i,
|
||||
data_out => rx_symbol,
|
||||
data_out_valid => rx_symbol_val,
|
||||
rx_error => rx_error,
|
||||
rx_data => rx_data);
|
||||
|
||||
-- Synchronize to the local clock
|
||||
pLATCH_RX_DATA : process(rx_clk)
|
||||
begin
|
||||
if (rx_clk = '1' and rx_clk'event) then
|
||||
if (rx_symbol_val = '1') then
|
||||
symbol <= rx_symbol;
|
||||
end if;
|
||||
if (rx_symbol_val = '1') then
|
||||
rx_symbol_val_v <= "1111";
|
||||
else
|
||||
rx_symbol_val_v <= '0' & rx_symbol_val_v(3 downto 1);
|
||||
end if;
|
||||
if (rx_error = '1') then
|
||||
rx_error_v <= "1111";
|
||||
else
|
||||
rx_error_v <= '0' & rx_error_v(3 downto 1);
|
||||
end if;
|
||||
end if;
|
||||
end process pLATCH_RX_DATA;
|
||||
|
||||
iSYNC_SYMBOL_VAL : entity work.sync_wire_rEdge
|
||||
generic map(rst_val => '0', sync_stages => 3)
|
||||
port map(rstN => reset_n, clk => clk, async_in => rx_symbol_val_v(0), sync_out => symbol_valid);
|
||||
|
||||
iSYNC_RX_ERROR : entity work.sync_wire_rEdge
|
||||
generic map(rst_val => '0', sync_stages => 3)
|
||||
port map(rstN => reset_n, clk => clk, async_in => rx_error_v(0), sync_out => rx_error_i);
|
||||
-- synchronize clear to tx_clk
|
||||
iSYNC_CLEAR : entity work.sync_wire
|
||||
generic map(rst_val => '1', sync_stages => 2)
|
||||
port map(
|
||||
rstN => reset_n, clk => rx_clk, async_in => clear, sync_out => clear_i);
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Toggle-Bits Decoding
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
pTOGGLE_DEC : process(clk)
|
||||
begin
|
||||
if (clk = '1' and clk'event) then
|
||||
-- Toggle Bits
|
||||
if (clear = '1') then
|
||||
toggle_sync <= '0';
|
||||
elsif (sync_confirmed = '1') then
|
||||
toggle_sync <= not toggle_sync;
|
||||
end if;
|
||||
if (clear = '1' or sync_confirmed = '1' or (symbol_valid_i = '1' and symbol_i(0) = toggle_sync)) then
|
||||
sync_toggle_test <= '0';
|
||||
elsif (sync_gen = '1') then
|
||||
sync_toggle_test <= '1';
|
||||
end if;
|
||||
sync <= sync_confirmed;
|
||||
sync_d <= sync;
|
||||
if (clear = '1') then
|
||||
toggle_pd <= '0';
|
||||
elsif (pd_confirmed = '1') then
|
||||
toggle_pd <= not toggle_pd;
|
||||
end if;
|
||||
if (clear = '1' or pd_confirmed = '1' or (symbol_valid_i = '1' and symbol_i(2) = toggle_pd)) then
|
||||
pd_toggle_test <= '0';
|
||||
elsif (pd_gen = '1') then
|
||||
pd_toggle_test <= '1';
|
||||
end if;
|
||||
pd <= pd_confirmed;
|
||||
--
|
||||
symbol_valid_i <= symbol_valid and symbol_ok;
|
||||
symbol_error <= symbol_valid and not symbol_ok;
|
||||
if (clear = '1') then
|
||||
parity_err_cnt_i <= (others => '0');
|
||||
elsif (symbol_error = '1') then
|
||||
parity_err_cnt_i <= std_logic_vector(unsigned(parity_err_cnt_i) + 1);
|
||||
end if;
|
||||
end if;
|
||||
end process pTOGGLE_DEC;
|
||||
|
||||
symbol_i <= symbol;
|
||||
|
||||
-- The received symbol is assumed to be vaild when there is not parity error
|
||||
-- and when the two bits with the PD-toggle bit are equal
|
||||
symbol_ok <= '1' when odd_parity_check(symbol) = '1' and (symbol(1) = symbol(2)) else '0';
|
||||
|
||||
sync_gen <= '1' when symbol_valid_i = '1' and symbol_i(0) /= toggle_sync else '0';
|
||||
pd_gen <= '1' when symbol_valid_i = '1' and symbol_i(2) /= toggle_pd else '0';
|
||||
--
|
||||
sync_confirmed <= sync_gen and sync_toggle_test;
|
||||
pd_confirmed <= pd_gen and pd_toggle_test;
|
||||
--
|
||||
init_out <= sync;
|
||||
pd_out <= pd;
|
||||
|
||||
parity_err_cnt <= parity_err_cnt_i;
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Position management & Error Recovery
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
gray_pos <= symbol_i(6 downto 3);
|
||||
next_pos_lsb <= gray2bin(gray_pos);
|
||||
curr_pos_lsb <= abs_pos_i(3 downto 0);
|
||||
|
||||
--dist <= std_logic_vector(signed(next_pos_lsb)-signed(curr_pos_lsb));
|
||||
abs_dist <= dist when dist(3) = '0' else std_logic_vector(unsigned(not dist) + 1);
|
||||
|
||||
pPOS_MNG : process(clk)
|
||||
begin
|
||||
if (clk = '1' and clk'event) then
|
||||
dist <= std_logic_vector(signed(next_pos_lsb) - signed(curr_pos_lsb));
|
||||
symbol_valid_d <= symbol_valid_i;
|
||||
if (clear = '1' or (symbol_valid_d = '1' and signed(dist) = 0) or pos_recovery = '1') then
|
||||
max_dist <= "0001";
|
||||
elsif (skip_pos = '1' or rx_error_i = '1') then
|
||||
max_dist <= std_logic_vector(unsigned(max_dist) + 1);
|
||||
end if;
|
||||
if (symbol_valid_d = '1' and valid_pos = '1') then
|
||||
pos_corr <= abs_dist;
|
||||
elsif (apply_corr = '1') then
|
||||
pos_corr <= std_logic_vector(unsigned(pos_corr) - 1);
|
||||
end if;
|
||||
if (clear = '1' or corr_done = '1') then
|
||||
upd_pos <= '0';
|
||||
elsif (symbol_valid_d = '1' and valid_pos = '1') then
|
||||
upd_pos <= '1';
|
||||
end if;
|
||||
if (upd_pos = '0' or unsigned(clk_cnt) = 2) then
|
||||
clk_cnt <= (others => '0');
|
||||
else
|
||||
clk_cnt <= std_logic_vector(unsigned(clk_cnt) + 1);
|
||||
end if;
|
||||
if (symbol_valid_d = '1' and valid_pos = '1') then
|
||||
corr_sign <= dist(3);
|
||||
end if;
|
||||
inc_pos_i <= inc_pos_ii;
|
||||
dec_pos_i <= dec_pos_ii;
|
||||
inc_pos <= inc_pos_i;
|
||||
dec_pos <= dec_pos_i;
|
||||
if (clear = '1' or sync = '1') then
|
||||
abs_pos_i <= (others => '0');
|
||||
elsif (inc_pos_ii = '1') then
|
||||
abs_pos_i <= std_logic_vector(signed(abs_pos_i) + 1);
|
||||
elsif (dec_pos_ii = '1') then
|
||||
abs_pos_i <= std_logic_vector(signed(abs_pos_i) - 1);
|
||||
end if;
|
||||
abs_pos <= abs_pos_i;
|
||||
skip_pos_d <= skip_pos;
|
||||
if (clear = '1' or (symbol_valid_d = '1' and valid_pos = '1')) then
|
||||
skip_cnt <= (others => '0');
|
||||
elsif (skip_pos = '1' and skip_pos_d = '0') then
|
||||
skip_cnt <= std_logic_vector(unsigned(skip_cnt) + 1);
|
||||
end if;
|
||||
if (clear = '1') then
|
||||
skip_pos_cnt_i <= (others => '0');
|
||||
elsif (skip_pos_d = '1') then
|
||||
skip_pos_cnt_i <= std_logic_vector(unsigned(skip_pos_cnt_i) + 1);
|
||||
end if;
|
||||
end if;
|
||||
end process pPOS_MNG;
|
||||
|
||||
skip_pos <= '1' when (symbol_valid = '1' and symbol_ok = '0') or (symbol_valid_d = '1' and valid_pos = '0') else '0';
|
||||
|
||||
pos_recovery <= '1' when unsigned(skip_cnt) >= 3 else '0';
|
||||
valid_pos <= '1' when unsigned(abs_dist) <= unsigned(max_dist) or pos_recovery = '1' else '0';
|
||||
|
||||
apply_corr <= '1' when upd_pos = '1' and clk_cnt = "01" else '0';
|
||||
corr_done <= '1' when signed(dist) = 0 else '0';
|
||||
|
||||
inc_pos_ii <= '1' when apply_corr = '1' and corr_sign = '0' else '0';
|
||||
dec_pos_ii <= '1' when apply_corr = '1' and corr_sign = '1' else '0';
|
||||
|
||||
skip_pos_cnt <= skip_pos_cnt_i;
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Additional logic for error reporting
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
pERROR_REPORTING : process(clk)
|
||||
begin
|
||||
if (clk = '1' and clk'event) then
|
||||
if (clear = '1' or one_pps = '1') then
|
||||
error_rate_cnt <= (others => '0');
|
||||
elsif (symbol_error = '1') then
|
||||
error_rate_cnt <= std_logic_vector(unsigned(error_rate_cnt) + 1);
|
||||
end if;
|
||||
if (clear = '1') then
|
||||
error_rate <= (others => '0');
|
||||
elsif (one_pps = '1') then
|
||||
error_rate <= error_rate_cnt;
|
||||
end if;
|
||||
max_error_flag <= not clear and max_error_flag_i;
|
||||
if (clear = '1' or symbol_valid_i = '1' or rx_watchdog_clr = '1') then
|
||||
rx_wd_cnt <= (others => '0');
|
||||
else
|
||||
rx_wd_cnt <= std_logic_vector(unsigned(rx_wd_cnt) + 1);
|
||||
end if;
|
||||
if (clear = '1' or rx_watchdog_clr = '1' or rx_watchdog_en = '0' or sync = '1') then
|
||||
rx_watchdog <= '0';
|
||||
elsif (unsigned(rx_wd_cnt) > 1000) then
|
||||
rx_watchdog <= '1';
|
||||
end if;
|
||||
end if;
|
||||
end process pERROR_REPORTING;
|
||||
|
||||
max_error_flag_i <= '1' when unsigned(error_rate) > unsigned(error_rate_thres) else '0';
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Encoder Pulse management
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-- Encoder pulses are generated only when there is an increment of the
|
||||
-- position in the intended direction, which exceeds the previous maximum.
|
||||
-- The value of the maximum is reset in the following situations:
|
||||
-- 1. After a Init/Sync pulse
|
||||
-- 2. After a direction change
|
||||
-- 3. When the distance between the current position and the previous maximum
|
||||
-- exceeds a programmable threshold, where the threshold is a 32 bit signed
|
||||
-- number. Only the 16 MSBs of this threshold can be configured. The threshold
|
||||
-- is set to the maximum value by default (e.g.: (2^23 = 8388608)
|
||||
|
||||
pENC_MNG : process(clk)
|
||||
begin
|
||||
if (clk = '1' and clk'event) then
|
||||
dp_dir_d <= dp_dir;
|
||||
if (sync_d = '1' or dp_dir_change = '1' or new_max = '1' or upd_max_pos = '1') then
|
||||
pos_max <= abs_pos_i;
|
||||
end if;
|
||||
if (sync_d = '1' or dp_dir_change = '1' or new_min = '1' or upd_min_pos = '1') then
|
||||
pos_min <= abs_pos_i;
|
||||
end if;
|
||||
enc_out <= new_min or new_max;
|
||||
end if;
|
||||
end process pENC_MNG;
|
||||
|
||||
dp_dir_change <= dp_dir xor dp_dir_d;
|
||||
|
||||
dist_pos <= std_logic_vector(signed(abs_pos_i) - signed(pos_max));
|
||||
dist_neg <= std_logic_vector(signed(pos_min) - signed(abs_pos_i));
|
||||
|
||||
new_max <= '1' when inc_pos_i = '1' and dp_dir = '0' and dist_pos(31) = '0' and unsigned(dist_pos(3 downto 0)) /= 0 else '0';
|
||||
new_min <= '1' when dec_pos_i = '1' and dp_dir = '1' and dist_neg(31) = '0' and unsigned(dist_neg(3 downto 0)) /= 0 else '0';
|
||||
|
||||
end architecture rtl;
|
||||
271
generic_ip/pof_protocol/1/src/pof_tx_1.vhd
Normal file
271
generic_ip/pof_protocol/1/src/pof_tx_1.vhd
Normal file
|
|
@ -0,0 +1,271 @@
|
|||
-------------------------------------------------------------------------------
|
||||
-- Title : pof_tx_1
|
||||
-- Project : SMB
|
||||
-------------------------------------------------------------------------------
|
||||
-- File : pof_tx_1.vhd
|
||||
-- Author : Gianmarco Girau
|
||||
-- Company : Global Inkjet Systems
|
||||
-- Created : 2017-08-22
|
||||
-- Last update: 2019-09-20
|
||||
-- SVN ID : Git
|
||||
-- Standard : VHDL'08
|
||||
-------------------------------------------------------------------------------
|
||||
-- Description:
|
||||
-- Encodes the EMS output into a serial format to be distributed over the POF
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
use ieee.numeric_std.all;
|
||||
|
||||
entity pof_tx_1 is
|
||||
port(
|
||||
reset_n : in std_logic;
|
||||
clk : in std_logic;
|
||||
init : in std_logic;
|
||||
pd_in : in std_logic;
|
||||
inc_pos : in std_logic;
|
||||
dec_pos : in std_logic;
|
||||
abs_position : in std_logic_vector(31 downto 0);
|
||||
tx_data : out std_logic;
|
||||
-- Avalon MM Interface
|
||||
avs_address : in std_logic_vector( 2 downto 0);
|
||||
avs_write : in std_logic;
|
||||
avs_writedata : in std_logic_vector(31 downto 0);
|
||||
avs_read : in std_logic;
|
||||
avs_readdatavalid : out std_logic;
|
||||
avs_readdata : out std_logic_vector(31 downto 0));
|
||||
end entity pof_tx_1;
|
||||
|
||||
architecture rtl of pof_tx_1 is
|
||||
|
||||
constant CSR : std_logic_vector( 2 downto 0) := b"000";
|
||||
constant ERROR_INJ_REG : std_logic_vector( 2 downto 0) := b"001";
|
||||
constant TIMING_REG : std_logic_vector( 2 downto 0) := b"010";
|
||||
constant FIFO_LEVEL_REG : std_logic_vector( 2 downto 0) := b"011";
|
||||
|
||||
constant KEEPALIVE_PERIOD_DEF : integer := 100;
|
||||
constant INIT_BLOCKED_PERIOD_DEF : integer := 200;
|
||||
|
||||
function odd_parity(data : std_logic_vector) return std_logic is
|
||||
variable parity_bit : std_logic := '1';
|
||||
begin
|
||||
for n in 0 to data'length-1 loop
|
||||
parity_bit := parity_bit xor data(n);
|
||||
end loop; -- n
|
||||
return parity_bit;
|
||||
end function odd_parity;
|
||||
|
||||
function bin2gray(bin : std_logic_vector) return std_logic_vector is
|
||||
variable gray : std_logic_vector(bin'range);
|
||||
begin
|
||||
gray := bin xor ('0' & bin(bin'length-1 downto 1));
|
||||
return gray;
|
||||
end function bin2gray;
|
||||
|
||||
signal rd_event, wr_event, empty, full, tx_ready : std_logic;
|
||||
signal rd_event_d, wr_event_i, symbol_valid : std_logic;
|
||||
signal enable, toggle_sync, toggle_pd : std_logic;
|
||||
signal add_keepalive, ovfl_err, init_d, init_gen : std_logic;
|
||||
signal clear, pd_in_d, pd_gen, parity_bit : std_logic;
|
||||
signal inject_error, inject_error_req : std_logic;
|
||||
signal pd_event, pd_event_d, pd_event_dd : std_logic;
|
||||
signal init_blocked, pd_event_ddd, delayed_pos : std_logic;
|
||||
signal clr_fifo_lmax : std_logic;
|
||||
--
|
||||
signal delayed_pos_v : std_logic_vector( 2 downto 0);
|
||||
signal init_v, gray, bit_div : std_logic_vector( 3 downto 0);
|
||||
signal latched_pos : std_logic_vector( 3 downto 0);
|
||||
signal event_in_i : std_logic_vector( 6 downto 0);
|
||||
signal event_in, event_out : std_logic_vector( 7 downto 0);
|
||||
signal symbol : std_logic_vector( 7 downto 0);
|
||||
signal init_blk_cnt : std_logic_vector( 9 downto 0) := (others => '0');
|
||||
signal keepalive_cnt : std_logic_vector( 9 downto 0);
|
||||
signal keepalive_period : std_logic_vector( 9 downto 0);
|
||||
signal init_blocked_period : std_logic_vector( 9 downto 0);
|
||||
signal fifo_level, fifo_level_max : std_logic_vector( 9 downto 0);
|
||||
|
||||
|
||||
begin
|
||||
|
||||
clear <= not enable or init_d;
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Encode events and queue these in a FIFO
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
pEVENT_GEN : process(clk)
|
||||
begin
|
||||
if(clk = '1' and clk'event) then
|
||||
init_d <= init;
|
||||
if(init = '1' and init_d = '0' and init_blocked = '0') then
|
||||
init_v <= "1100";
|
||||
else
|
||||
init_v <= '0' & init_v(3 downto 1);
|
||||
end if;
|
||||
if(enable = '0') then
|
||||
toggle_sync <= '0';
|
||||
elsif(init_d = '1' and init_blocked = '0') then
|
||||
toggle_sync <= not toggle_sync;
|
||||
end if;
|
||||
if(init_gen = '1') then
|
||||
init_blk_cnt <= init_blocked_period;
|
||||
elsif(init_blocked = '1') then
|
||||
init_blk_cnt <= std_logic_vector(unsigned(init_blk_cnt)-1);
|
||||
end if;
|
||||
pd_in_d <= pd_in;
|
||||
pd_event_d <= pd_event;
|
||||
pd_event_dd <= pd_event_d;
|
||||
pd_event_ddd <= pd_event_dd;
|
||||
if(pd_event = '1') then
|
||||
latched_pos <= abs_position(3 downto 0);
|
||||
end if;
|
||||
if((dec_pos = '1' or inc_pos = '1') and pd_gen = '1') then
|
||||
delayed_pos_v <= "111";
|
||||
else
|
||||
delayed_pos_v <= '0' & delayed_pos_v(2 downto 1);
|
||||
end if;
|
||||
if(enable = '0') then
|
||||
toggle_pd <= '0';
|
||||
elsif(pd_event = '1') then
|
||||
toggle_pd <= not toggle_pd;
|
||||
end if;
|
||||
wr_event <= wr_event_i or add_keepalive;
|
||||
event_in <= parity_bit & event_in_i;
|
||||
if(enable = '0' or wr_event_i = '1') then
|
||||
keepalive_cnt <= keepalive_period;
|
||||
else
|
||||
keepalive_cnt <= std_logic_vector(unsigned(keepalive_cnt)-1);
|
||||
end if;
|
||||
if(clear = '1') then
|
||||
ovfl_err <= '0';
|
||||
elsif(wr_event = '1' and full = '1') then
|
||||
ovfl_err <= '1';
|
||||
end if;
|
||||
if(clear = '1' or wr_event = '1') then
|
||||
inject_error <= '0';
|
||||
elsif(inject_error_req = '1') then
|
||||
inject_error <= '1';
|
||||
end if;
|
||||
if(init_gen = '1' or clr_fifo_lmax = '1') then
|
||||
fifo_level_max <= (others => '0');
|
||||
elsif(unsigned(fifo_level) > unsigned(fifo_level_max)) then
|
||||
fifo_level_max <= fifo_level;
|
||||
end if;
|
||||
end if;
|
||||
end process pEVENT_GEN;
|
||||
|
||||
init_gen <= init_v(0);
|
||||
|
||||
init_blocked <= '1' when unsigned(init_blk_cnt) /= 0 else '0';
|
||||
|
||||
pd_event <= pd_in and not pd_in_d;
|
||||
pd_gen <= pd_event or pd_event_d or pd_event_dd;
|
||||
|
||||
delayed_pos <= delayed_pos_v(0) and pd_event_ddd;
|
||||
|
||||
wr_event_i <= enable and (init_gen or pd_gen or dec_pos or inc_pos or delayed_pos);
|
||||
|
||||
add_keepalive <= '1' when wr_event_i = '0' and unsigned(keepalive_cnt) = 0 else '0';
|
||||
|
||||
gray <= bin2gray(latched_pos) when (pd_event_d = '1' or pd_event_dd = '1') else bin2gray(abs_position(3 downto 0));
|
||||
|
||||
-- toggle_pd is repeated twice in the tx word, to improve resiliance against
|
||||
-- double bit-flips errors
|
||||
event_in_i <= gray & toggle_pd & toggle_pd & toggle_sync;
|
||||
|
||||
parity_bit <= odd_parity(event_in_i) xor inject_error;
|
||||
|
||||
iQUEUE_EVENT : entity work.sync_fifo
|
||||
generic map (
|
||||
FIFO_WIDTH => 8,
|
||||
FIFO_DEPTH => 1024)
|
||||
port map (
|
||||
sclr => clear,
|
||||
clock => clk,
|
||||
data => event_in,
|
||||
rdreq => rd_event,
|
||||
wrreq => wr_event,
|
||||
empty => empty,
|
||||
full => full,
|
||||
q => event_out,
|
||||
usedw => fifo_level);
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Transmit symbols over serial link
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
pGET_EVENT : process(clk)
|
||||
begin
|
||||
if(clk = '1' and clk'event) then
|
||||
rd_event_d <= rd_event;
|
||||
symbol_valid <= rd_event_d;
|
||||
end if;
|
||||
end process pGET_EVENT;
|
||||
|
||||
rd_event <= '1' when tx_ready = '1' and empty = '0' and rd_event_d = '0' and symbol_valid = '0' else '0';
|
||||
|
||||
symbol <= event_out;
|
||||
|
||||
iTX_SYMBOL : entity work.uart_tx_1
|
||||
generic map (
|
||||
data_width => 8)
|
||||
port map (
|
||||
reset_n => reset_n,
|
||||
clk => clk,
|
||||
bit_div => bit_div,
|
||||
init => clear,
|
||||
ready => tx_ready,
|
||||
data_in => symbol,
|
||||
data_valid => symbol_valid,
|
||||
tx_data => tx_data);
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- C&S registers
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
pCTRL_STATUS : process(reset_n, clk)
|
||||
begin
|
||||
if(reset_n = '0') then
|
||||
avs_readdatavalid <= '0';
|
||||
enable <= '0';
|
||||
clr_fifo_lmax <= '0';
|
||||
bit_div <= "0010";
|
||||
keepalive_period <= std_logic_vector(to_unsigned(KEEPALIVE_PERIOD_DEF, 10));
|
||||
init_blocked_period <= std_logic_vector(to_unsigned(INIT_BLOCKED_PERIOD_DEF, 10));
|
||||
elsif(clk = '1' and clk'event) then
|
||||
inject_error_req <= '0';
|
||||
clr_fifo_lmax <= '0';
|
||||
-- CTRL registers
|
||||
if(avs_write = '1') then
|
||||
case avs_address is
|
||||
when CSR =>
|
||||
enable <= avs_writedata(0);
|
||||
clr_fifo_lmax <= avs_writedata(2);
|
||||
bit_div <= avs_writedata(7 downto 4);
|
||||
when ERROR_INJ_REG =>
|
||||
inject_error_req <= avs_writedata(0);
|
||||
when TIMING_REG =>
|
||||
keepalive_period <= avs_writedata( 9 downto 0);
|
||||
init_blocked_period <= avs_writedata(25 downto 16);
|
||||
when others => null;
|
||||
end case;
|
||||
end if;
|
||||
-- Read Ctrl & Status registers
|
||||
avs_readdatavalid <= avs_read;
|
||||
if(avs_read = '1') then
|
||||
case avs_address is
|
||||
when CSR =>
|
||||
avs_readdata <= X"000000" & bit_div & b"0" & clr_fifo_lmax & ovfl_err & enable;
|
||||
when TIMING_REG =>
|
||||
avs_readdata <= 6x"0" & init_blocked_period & 6x"0" & keepalive_period;
|
||||
when FIFO_LEVEL_REG =>
|
||||
avs_readdata <= 6x"0" & fifo_level_max & 6x"0" & fifo_level;
|
||||
when others =>
|
||||
avs_readdata <= X"BAD1BAD0";
|
||||
end case;
|
||||
end if;
|
||||
end if;
|
||||
end process pCTRL_STATUS;
|
||||
|
||||
end architecture rtl;
|
||||
623
generic_ip/pof_protocol/1/src/test/pof_tx_rx_1_tb.vhd
Normal file
623
generic_ip/pof_protocol/1/src/test/pof_tx_rx_1_tb.vhd
Normal file
|
|
@ -0,0 +1,623 @@
|
|||
-------------------------------------------------------------------------------
|
||||
-- Title : pof_tx_rx_tb
|
||||
-- Project : HMB daisy-chaining
|
||||
-------------------------------------------------------------------------------
|
||||
-- File : pof_tx_rx_tb.vhd
|
||||
-- Author : GMG
|
||||
-- Company : Global Inkjet Systems
|
||||
-- Created : 2017-08-29
|
||||
-- Last update: 2019-09-20
|
||||
-- SVN ID : Git
|
||||
-- Standard : VHDL'2008
|
||||
-------------------------------------------------------------------------------
|
||||
-- Description:
|
||||
-- Testbench for verifying the transmission over the POF with emb2poftx and
|
||||
-- pofrx2hmb blocks
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
use ieee.numeric_std.all;
|
||||
|
||||
library OSVVM;
|
||||
use OSVVM.RandomBasePkg.all;
|
||||
use OSVVM.RandomPkg.all;
|
||||
|
||||
use work.log_pkg.all;
|
||||
use work.avalon_verify_pkg.all;
|
||||
|
||||
use work.log_pkg.all;
|
||||
|
||||
entity pof_tx_rx_1_tb is
|
||||
-- ..
|
||||
end entity pof_tx_rx_1_tb;
|
||||
|
||||
architecture behav of pof_tx_rx_1_tb is
|
||||
|
||||
constant CLK_PERIOD : time := 10 ns; -- 100MHz
|
||||
constant RX_CLK_PERIOD : time := 3.333 ns; -- 300MHz
|
||||
|
||||
constant NUM_ITERATIONS : natural := 10;
|
||||
constant SWATHE_LEN : integer := 1000;
|
||||
constant START_DIR : std_logic := '0';
|
||||
constant INJECT_ERROR_PERC : natural := 3; -- percentage of injected errors
|
||||
constant DISCR_THRES : natural := 1000;
|
||||
constant TIME_INT : time := 800 ns;
|
||||
|
||||
constant UART_BIT_DIV : std_logic_vector(3 downto 0) := "0110"; -- divide by 6
|
||||
|
||||
-- Logging Verbosity Level
|
||||
constant VERBOSITY_LEVEL : verb_level_t := VMEDIUM;
|
||||
|
||||
signal clk, rx_clk, rx_clk_i, reset_n : std_logic := '0';
|
||||
signal avs_read, avs_write, sel_slave_0, sel_slave_1 : std_logic;
|
||||
signal avs_write_sl0, avs_read_sl0, avs_readdatavalid_sl0 : std_logic;
|
||||
signal avs_write_sl1, avs_read_sl1, avs_readdatavalid_sl1 : std_logic;
|
||||
signal init_tx, init_rx, dir_in, pd_in, inc_pos, dec_pos : std_logic;
|
||||
signal tx_data, rx_data, init_out, dir_out, enc_out : std_logic;
|
||||
signal pd_out, inc_pos_out, dec_pos_out, end_of_swathe : std_logic;
|
||||
--
|
||||
signal test_completed, running, configuring : boolean;
|
||||
signal passed, failed, stimuli_completed : boolean;
|
||||
signal detected_error : boolean := false;
|
||||
--
|
||||
signal avs_address : std_logic_vector(2 downto 0);
|
||||
signal avs_writedata : std_logic_vector(31 downto 0);
|
||||
signal avs_readdata_sl0, avs_readdata_sl1 : std_logic_vector(31 downto 0);
|
||||
signal abs_position, abs_position_d : std_logic_vector(31 downto 0);
|
||||
signal abs_pos_out : std_logic_vector(31 downto 0);
|
||||
--
|
||||
signal swathe_cnt, swathe_pos : integer;
|
||||
signal dir_discr_cnt, pd_discr_cnt : integer;
|
||||
signal pos_discr_cnt : integer;
|
||||
signal pd_in_cnt, pd_out_cnt : integer;
|
||||
signal enc_pulse_cnt : integer;
|
||||
signal dir_err, pd_err, ovfl_err : std_logic;
|
||||
signal pos_err, enc_err, dir_in_d : std_logic;
|
||||
signal injected_errors : integer;
|
||||
signal max_pos, min_pos : integer;
|
||||
signal max_pos_d, min_pos_d : integer;
|
||||
signal exp_enc_cnt : integer;
|
||||
signal exp_enc_pulse, enc_discr : std_logic;
|
||||
signal enc_out_d : std_logic;
|
||||
signal error_rate_thres : std_logic_vector(7 downto 0);
|
||||
signal one_pps : std_logic;
|
||||
signal max_error_flag : std_logic;
|
||||
signal rx_watchdog : std_logic;
|
||||
signal rx_watchdog_en : std_logic;
|
||||
signal rx_watchdog_clr : std_logic;
|
||||
--
|
||||
signal enable_rx : std_logic;
|
||||
signal parity_err_cnt : std_logic_vector(15 downto 0);
|
||||
signal skip_pos_cnt : std_logic_vector(15 downto 0);
|
||||
--
|
||||
signal avs_m : mm_m_rec_t;
|
||||
signal avs_s : mm_s_rec_t;
|
||||
|
||||
|
||||
begin -- architecture behav
|
||||
|
||||
clk <= not clk after 0.5 * CLK_PERIOD;
|
||||
|
||||
rx_clk_i <= not rx_clk_i after 0.5 * RX_CLK_PERIOD;
|
||||
rx_clk <= rx_clk_i after 1 ns;
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- UUTs
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
iPOF_TX : entity work.pof_tx_1
|
||||
port map(
|
||||
reset_n => reset_n,
|
||||
clk => clk,
|
||||
init => init_tx,
|
||||
pd_in => pd_in,
|
||||
inc_pos => inc_pos,
|
||||
dec_pos => dec_pos,
|
||||
abs_position => abs_position,
|
||||
tx_data => tx_data,
|
||||
avs_address => avs_address,
|
||||
avs_write => avs_write_sl0,
|
||||
avs_writedata => avs_writedata,
|
||||
avs_read => avs_read_sl0,
|
||||
avs_readdatavalid => avs_readdatavalid_sl0,
|
||||
avs_readdata => avs_readdata_sl0);
|
||||
|
||||
iPOF_RX : entity work.pof_rx_1
|
||||
port map(
|
||||
reset_n => reset_n,
|
||||
clk => clk,
|
||||
init => init_rx,
|
||||
rx_clk => rx_clk,
|
||||
rx_data => rx_data,
|
||||
init_out => init_out,
|
||||
dp_dir => dir_in,
|
||||
enc_out => enc_out,
|
||||
pd_out => pd_out,
|
||||
inc_pos => inc_pos_out,
|
||||
dec_pos => dec_pos_out,
|
||||
abs_pos => abs_pos_out,
|
||||
enable => enable_rx,
|
||||
bit_div => UART_BIT_DIV,
|
||||
error_rate_thres => error_rate_thres,
|
||||
one_pps => one_pps,
|
||||
upd_max_pos => '0',
|
||||
upd_min_pos => '0',
|
||||
max_error_flag => max_error_flag,
|
||||
rx_watchdog => rx_watchdog,
|
||||
rx_watchdog_en => rx_watchdog_en,
|
||||
rx_watchdog_clr => rx_watchdog_clr,
|
||||
parity_err_cnt => parity_err_cnt,
|
||||
skip_pos_cnt => skip_pos_cnt);
|
||||
|
||||
--rx_data <= tx_data after 40 ns;
|
||||
rx_data <= transport tx_data after 40 ns;
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- UUT configuration and control
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
clk_clk <= clk;
|
||||
reset_reset_n <= reset_n;
|
||||
|
||||
avs_s.mm_readdata <= avs_readdata_sl0 when sel_slave_0 = '1' else
|
||||
avs_readdata_sl1 when sel_slave_1 = '1' else (others => '0');
|
||||
|
||||
avs_readdata_sl1 <= (others => '0');
|
||||
|
||||
avs_s.mm_readdatavalid <= avs_readdatavalid_sl0 when sel_slave_0 = '1' else
|
||||
avs_readdatavalid_sl1 when sel_slave_1 = '1' else '0';
|
||||
|
||||
avs_readdatavalid_sl1 <= '0';
|
||||
|
||||
avs_s.mm_waitrequest <= '0';
|
||||
avs_s.use_readvalid <= true;
|
||||
|
||||
avs_address <= avs_m.mm_address(avs_address'range);
|
||||
avs_write <= avs_m.mm_write;
|
||||
avs_writedata <= avs_m.mm_writedata;
|
||||
avs_read <= avs_m.mm_read;
|
||||
--
|
||||
avs_write_sl0 <= avs_write and sel_slave_0;
|
||||
--avs_write_sl1 <= avs_write and sel_slave_1;
|
||||
avs_write_sl1 <= '0';
|
||||
--
|
||||
avs_read_sl0 <= avs_read and sel_slave_0;
|
||||
--avs_read_sl1 <= avs_read and sel_slave_1;
|
||||
avs_read_sl1 <= '0';
|
||||
|
||||
-- 1-PPS generation: make it faster than 1-PPS for simulation reasons
|
||||
pEMULATE_1PPS : process
|
||||
begin
|
||||
one_pps <= '0';
|
||||
for n in 1 to 99999 loop
|
||||
wait until clk = '1' and clk'event;
|
||||
end loop; -- 1 to 9999
|
||||
one_pps <= '1';
|
||||
wait until clk = '1' and clk'event;
|
||||
end process pEMULATE_1PPS;
|
||||
|
||||
pUUT_CTRL : process
|
||||
variable addr : std_logic_vector(31 downto 0) := (others => '0');
|
||||
variable data : std_logic_vector(31 downto 0) := (others => '0');
|
||||
variable init_done : boolean := false;
|
||||
variable fifo_level : integer;
|
||||
begin
|
||||
|
||||
enable_rx <= '0';
|
||||
--
|
||||
rx_watchdog_en <= '0';
|
||||
rx_watchdog_clr <= '0';
|
||||
error_rate_thres <= X"0A";
|
||||
|
||||
sel_slave_0 <= '0';
|
||||
sel_slave_1 <= '0';
|
||||
|
||||
configuring <= true;
|
||||
|
||||
-- initilialize the Avalon master-bus
|
||||
mm_m_init(avs_m);
|
||||
|
||||
if (reset_n = '0') then
|
||||
wait until reset_n = '1';
|
||||
wait for 100 ns;
|
||||
wait until clk = '1' and clk'event;
|
||||
end if;
|
||||
|
||||
log("Configuring EMB2POFTX ... ", VLOW, true);
|
||||
sel_slave_0 <= '1';
|
||||
-- Config netfork_rx control registers:
|
||||
-- disable the block
|
||||
addr := std_logic_vector(to_unsigned(0, 32));
|
||||
data := X"0000_0021";
|
||||
mm_32b_write(addr, data, avs_s, avs_m);
|
||||
|
||||
sel_slave_0 <= '0';
|
||||
sel_slave_1 <= '1';
|
||||
wait until clk = '1' and clk'event;
|
||||
|
||||
log("Configuring POFRX2HMB ... ", VLOW, true);
|
||||
-- Config netfork_rx control registers:
|
||||
-- disable the block
|
||||
addr := std_logic_vector(to_unsigned(0, 32));
|
||||
data := X"0000_0001";
|
||||
--mm_32b_write(addr, data, avs_s, avs_m);
|
||||
enable_rx <= '1';
|
||||
rx_watchdog_en <= '1';
|
||||
|
||||
log("Configuration completed.", VLOW, true);
|
||||
configuring <= false;
|
||||
|
||||
wait;
|
||||
|
||||
end process pUUT_CTRL;
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Stimuli Generation
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
pSTIMULI_REGs : process(clk)
|
||||
begin
|
||||
if (clk = '1' and clk'event) then
|
||||
abs_position_d <= abs_position;
|
||||
end if;
|
||||
end process pSTIMULI_REGs;
|
||||
|
||||
inc_pos <= '1' when signed(abs_position) = signed(abs_position_d) + 1 else '0';
|
||||
dec_pos <= '1' when signed(abs_position) = signed(abs_position_d) - 1 else '0';
|
||||
|
||||
pSTIMULI : process
|
||||
variable rv : RandomPType;
|
||||
variable tmp_int : integer;
|
||||
variable rand_time : time;
|
||||
variable end_of_stimuli : boolean;
|
||||
variable pd_dist : integer;
|
||||
begin
|
||||
|
||||
-- initialization
|
||||
init_rx <= '0';
|
||||
--
|
||||
init_tx <= '0';
|
||||
dir_in <= START_DIR;
|
||||
pd_in <= '0';
|
||||
abs_position <= (others => '0');
|
||||
swathe_pos <= 0;
|
||||
pd_dist := 0;
|
||||
--
|
||||
swathe_cnt <= 0;
|
||||
stimuli_completed <= false;
|
||||
end_of_swathe <= '0';
|
||||
|
||||
-- generating the stimulus
|
||||
wait until running = true;
|
||||
wait for 200 ns;
|
||||
-- Send a Init/Sync pulse
|
||||
wait until clk = '1' and clk'event;
|
||||
init_tx <= '1';
|
||||
wait until clk = '1' and clk'event;
|
||||
init_tx <= '0';
|
||||
wait for 500 ns;
|
||||
-- Send a second init pulse and verify that it is ignored (because too
|
||||
-- close to the previous)
|
||||
wait until clk = '1' and clk'event;
|
||||
init_tx <= '1';
|
||||
wait until clk = '1' and clk'event;
|
||||
init_tx <= '0';
|
||||
wait for 2500 ns;
|
||||
-- Send a third pulse (after a bigger interval from the previous).
|
||||
-- Verify that this time the pulse is accepted
|
||||
wait until clk = '1' and clk'event;
|
||||
init_tx <= '1';
|
||||
wait until clk = '1' and clk'event;
|
||||
init_tx <= '0';
|
||||
wait for 500 ns;
|
||||
wait until clk = '1' and clk'event;
|
||||
--
|
||||
-- generate the forward swathe
|
||||
end_of_stimuli := false;
|
||||
while end_of_stimuli = false loop
|
||||
swathe_pos <= 0;
|
||||
wait until clk = '1' and clk'event;
|
||||
while swathe_pos /= SWATHE_LEN loop
|
||||
-- generate a position increment
|
||||
tmp_int := rv.RandInt(1, 100);
|
||||
--tmp_int := 100;
|
||||
if (tmp_int < 20) then
|
||||
-- generate a position increment opposite to the swathe direction
|
||||
swathe_pos <= swathe_pos - 1;
|
||||
if (dir_in = '0') then
|
||||
abs_position <= std_logic_vector(signed(abs_position) - 1);
|
||||
else
|
||||
abs_position <= std_logic_vector(signed(abs_position) + 1);
|
||||
end if;
|
||||
else
|
||||
swathe_pos <= swathe_pos + 1;
|
||||
if (dir_in = '0') then
|
||||
abs_position <= std_logic_vector(signed(abs_position) + 1);
|
||||
else
|
||||
abs_position <= std_logic_vector(signed(abs_position) - 1);
|
||||
end if;
|
||||
end if;
|
||||
--
|
||||
tmp_int := rv.RandInt(1, 100);
|
||||
if (tmp_int <= 5 and pd_dist >= 10) then
|
||||
pd_dist := 0;
|
||||
-- generate a PD increment: the PD might be either concurren or not
|
||||
-- to the position increment
|
||||
tmp_int := rv.RandInt(1, 3);
|
||||
case tmp_int is
|
||||
when 2 =>
|
||||
-- wait less than the transmission time
|
||||
wait for 90 ns;
|
||||
wait until clk = '1' and clk'event;
|
||||
when 3 =>
|
||||
-- wait more than the transmission time
|
||||
wait for 290 ns;
|
||||
wait until clk = '1' and clk'event;
|
||||
when others => null;
|
||||
end case;
|
||||
pd_in <= '1';
|
||||
wait until clk = '1' and clk'event;
|
||||
pd_in <= '0';
|
||||
end if;
|
||||
pd_dist := pd_dist + 1;
|
||||
rand_time := rv.RandInt(-25, 25) * (10 ns);
|
||||
wait for TIME_INT + rand_time;
|
||||
end loop; -- swathe_pos /= SWATHE_LEN
|
||||
|
||||
wait for 25 us;
|
||||
end_of_swathe <= '1';
|
||||
wait until clk = '1' and clk'event;
|
||||
end_of_swathe <= '0';
|
||||
-- reverse direction
|
||||
if (dir_in /= START_DIR) then
|
||||
if (swathe_cnt = NUM_ITERATIONS) then
|
||||
end_of_stimuli := true;
|
||||
else
|
||||
swathe_cnt <= swathe_cnt + 1;
|
||||
end if;
|
||||
end if;
|
||||
if (end_of_stimuli = false) then
|
||||
wait until clk = '1' and clk'event;
|
||||
dir_in <= not dir_in;
|
||||
-- Wait some time to make sure the change of direction is transmitted.
|
||||
-- Note: if the position starts changing before the receiver was able to
|
||||
-- confirm the change of direction, then some encoder pulses may not be
|
||||
-- generated
|
||||
wait for 1 us;
|
||||
wait until clk = '1' and clk'event;
|
||||
end if;
|
||||
end loop; -- end_of_stimuli = false
|
||||
|
||||
stimuli_completed <= true;
|
||||
wait;
|
||||
|
||||
end process pSTIMULI;
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Error injection
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-- Randomly change the payload of the data transmitted over the UART.
|
||||
-- Insert 1, 2 or 3 errors per data word
|
||||
-- Note: an error on the start bit of the UART will can cause more than 3
|
||||
-- errors per data word, therefore this error injection method does not cover
|
||||
-- all the possible cases
|
||||
|
||||
pERROR_INJECTION : process
|
||||
--
|
||||
alias symbol_valid is <<signal iPOF_TX.symbol_valid : std_logic>>;
|
||||
alias symbol is <<signal iPOF_TX.symbol : std_logic_vector>>;
|
||||
--
|
||||
variable rv : RandomPType;
|
||||
variable flip_vect : std_logic_vector(7 downto 0);
|
||||
variable last_flip : std_logic_vector(7 downto 0);
|
||||
variable bit_flips : integer range 0 to 3;
|
||||
variable b0, b1, b2 : integer range 0 to 9;
|
||||
variable exclude_1 : integer_vector(0 downto 0);
|
||||
variable exclude_2 : integer_vector(1 downto 0);
|
||||
variable test : std_logic_vector(5 downto 0);
|
||||
begin
|
||||
|
||||
injected_errors <= 0;
|
||||
if (running /= true) then
|
||||
wait until running = true;
|
||||
end if;
|
||||
|
||||
while running loop
|
||||
wait until symbol_valid = '1' and symbol_valid'event;
|
||||
if (rv.RandInt(1, 100) < INJECT_ERROR_PERC) then
|
||||
-- Inject an error:
|
||||
-- Number of bits to flip in the tx word
|
||||
bit_flips := rv.RandInt(1, 3);
|
||||
--bit_flips := 2;
|
||||
b0 := rv.RandInt(0, 7);
|
||||
exclude_1(0) := b0;
|
||||
b1 := rv.RandInt(min => 0, max => 7, exclude => exclude_1);
|
||||
exclude_2 := (0 => b0, 1 => b1);
|
||||
b2 := rv.RandInt(min => 0, max => 7, exclude => exclude_2);
|
||||
flip_vect := (others => '0');
|
||||
flip_vect(b0) := '1';
|
||||
if (bit_flips >= 2) then
|
||||
flip_vect(b1) := '1';
|
||||
end if;
|
||||
if (bit_flips = 3) then
|
||||
flip_vect(b2) := '1';
|
||||
end if;
|
||||
-- Prevent situations with two consecutive bit flips on bit 0,1 and 2
|
||||
if ((flip_vect(0) = '1' and last_flip(0) = '1') or (flip_vect(1) = '1' and last_flip(1) = '1') or (flip_vect(2) = '1' and last_flip(2) = '1')) then
|
||||
flip_vect := (others => '0');
|
||||
end if;
|
||||
log("bit-flip = " & to_string(bit_flips) & ", flip_vect = " & to_string(flip_vect) & ".", VLOW);
|
||||
symbol <= force symbol xor flip_vect;
|
||||
injected_errors <= injected_errors + 1;
|
||||
wait until clk = '1' and clk'event;
|
||||
wait until clk = '1' and clk'event;
|
||||
symbol <= release;
|
||||
last_flip := flip_vect;
|
||||
else
|
||||
last_flip := (others => '0');
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
end process pERROR_INJECTION;
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Output Checking
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-- No more check on dir_out!!!
|
||||
dir_out <= dir_in;
|
||||
|
||||
pEVENT_MONITOR : process(clk)
|
||||
begin
|
||||
if (clk = '1' and clk'event) then
|
||||
if (reset_n = '0' or init_tx = '1' or running = false or dir_in = dir_out) then
|
||||
dir_discr_cnt <= 0;
|
||||
elsif (dir_in /= dir_out) then
|
||||
dir_discr_cnt <= dir_discr_cnt + 1;
|
||||
end if;
|
||||
if (reset_n = '0' or init_tx = '1' or running = false) then
|
||||
dir_err <= '0';
|
||||
elsif (dir_discr_cnt > DISCR_THRES) then
|
||||
dir_err <= '1';
|
||||
end if;
|
||||
if (reset_n = '0' or init_tx = '1' or running = false) then
|
||||
pd_in_cnt <= 0;
|
||||
elsif (pd_in = '1') then
|
||||
pd_in_cnt <= pd_in_cnt + 1;
|
||||
end if;
|
||||
if (reset_n = '0' or init_tx = '1' or running = false) then
|
||||
pd_out_cnt <= 0;
|
||||
elsif (pd_out = '1') then
|
||||
pd_out_cnt <= pd_out_cnt + 1;
|
||||
end if;
|
||||
if (reset_n = '0' or init_tx = '1' or running = false or pd_in_cnt = pd_out_cnt) then
|
||||
pd_discr_cnt <= 0;
|
||||
elsif (pd_in_cnt /= pd_out_cnt) then
|
||||
pd_discr_cnt <= pd_discr_cnt + 1;
|
||||
end if;
|
||||
if (reset_n = '0' or init_tx = '1' or running = false) then
|
||||
pd_err <= '0';
|
||||
elsif (pd_discr_cnt > DISCR_THRES) then
|
||||
pd_err <= '1';
|
||||
end if;
|
||||
if (reset_n = '0' or init_tx = '1' or running = false or signed(abs_position) = signed(abs_pos_out)) then
|
||||
pos_discr_cnt <= 0;
|
||||
elsif (signed(abs_position) /= signed(abs_pos_out)) then
|
||||
pos_discr_cnt <= pos_discr_cnt + 1;
|
||||
end if;
|
||||
if (reset_n = '0' or init_tx = '1' or running = false) then
|
||||
pos_err <= '0';
|
||||
elsif (pos_discr_cnt > DISCR_THRES) then
|
||||
pos_err <= '1';
|
||||
end if;
|
||||
dir_in_d <= dir_in;
|
||||
if (reset_n = '0' or init_tx = '1' or running = false or dir_in /= dir_in_d) then
|
||||
enc_pulse_cnt <= 0;
|
||||
elsif (enc_out = '1') then
|
||||
enc_pulse_cnt <= enc_pulse_cnt + 1;
|
||||
end if;
|
||||
if (reset_n = '0' or init_tx = '1' or running = false) then
|
||||
enc_err <= '0';
|
||||
elsif (end_of_swathe = '1' and enc_pulse_cnt /= SWATHE_LEN) then
|
||||
enc_err <= '1';
|
||||
end if;
|
||||
max_pos_d <= max_pos;
|
||||
min_pos_d <= min_pos;
|
||||
if ((dir_in = '0' and max_pos /= max_pos_d) or (dir_in = '1' and min_pos /= min_pos_d)) then
|
||||
exp_enc_pulse <= '1';
|
||||
else
|
||||
exp_enc_pulse <= '0';
|
||||
end if;
|
||||
enc_out_d <= enc_out;
|
||||
end if;
|
||||
end process pEVENT_MONITOR;
|
||||
|
||||
enc_discr <= enc_out_d xor exp_enc_pulse;
|
||||
|
||||
pMIN_MAX_POS : process(reset_n, end_of_swathe, abs_pos_out)
|
||||
begin
|
||||
if (reset_n = '0' or end_of_swathe = '1') then
|
||||
max_pos <= -SWATHE_LEN;
|
||||
elsif (signed(abs_pos_out) > max_pos) then
|
||||
max_pos <= to_integer(signed(abs_pos_out));
|
||||
end if;
|
||||
if (reset_n = '0' or end_of_swathe = '1') then
|
||||
min_pos <= SWATHE_LEN;
|
||||
elsif (signed(abs_pos_out) < min_pos) then
|
||||
min_pos <= to_integer(signed(abs_pos_out));
|
||||
end if;
|
||||
end process pMIN_MAX_POS;
|
||||
|
||||
exp_enc_cnt <= max_pos - min_pos;
|
||||
|
||||
ovfl_err <= <<signal iPOF_TX.ovfl_err : std_logic>>;
|
||||
|
||||
pERR_DETECT : process(reset_n, clk)
|
||||
begin
|
||||
if (reset_n = '0') then
|
||||
detected_error <= false;
|
||||
elsif (clk = '1' and clk'event) then
|
||||
--if(ovfl_err = '1' or dir_err = '1' or pd_err = '1' or pos_err = '1' or enc_err = '1') then
|
||||
if (ovfl_err = '1' or dir_err = '1' or pd_err = '1' or pos_err = '1') then
|
||||
detected_error <= true;
|
||||
end if;
|
||||
end if;
|
||||
end process pERR_DETECT;
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Testbench Control
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
pTB_CTRL : process
|
||||
begin
|
||||
|
||||
-- Set the verbosity level for logging
|
||||
set_log_verbosity(VERBOSITY_LEVEL);
|
||||
set_log_verbosity(VHIGH);
|
||||
|
||||
log_header("POF Transfer Tx/Rx verification:", VLOW);
|
||||
|
||||
test_completed <= false;
|
||||
running <= false;
|
||||
passed <= false;
|
||||
failed <= false;
|
||||
|
||||
-- Reset
|
||||
reset_n <= '0';
|
||||
wait for 100 ns;
|
||||
wait until clk = '1' and clk'event;
|
||||
reset_n <= '1';
|
||||
|
||||
if (configuring /= true) then
|
||||
wait until configuring = true;
|
||||
end if;
|
||||
wait until configuring = false;
|
||||
running <= true;
|
||||
|
||||
wait until stimuli_completed = true or detected_error = true;
|
||||
|
||||
if (stimuli_completed = true) then
|
||||
-- wait enough time to make sure that a max length package can be propagated
|
||||
wait for 20 us;
|
||||
end if;
|
||||
|
||||
if (detected_error = true) then
|
||||
failed <= true;
|
||||
log("FAILURE: test completed with errors.", VLOW);
|
||||
else
|
||||
passed <= true;
|
||||
log("SUCCESS: test successfully completed.", VLOW);
|
||||
end if;
|
||||
log_separator_line(VLOW);
|
||||
test_completed <= true;
|
||||
running <= false;
|
||||
|
||||
wait;
|
||||
|
||||
end process pTB_CTRL;
|
||||
|
||||
|
||||
end architecture behav;
|
||||
160
generic_ip/pof_protocol/1/src/uart_regen_1.vhd
Normal file
160
generic_ip/pof_protocol/1/src/uart_regen_1.vhd
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
-------------------------------------------------------------------------------
|
||||
-- Title : uart_regen
|
||||
-- Project : EMB-1
|
||||
-------------------------------------------------------------------------------
|
||||
-- File : uart_regen.vhd
|
||||
-- Author : Gianmarco Girau
|
||||
-- Company : Global Inkjet Systems
|
||||
-- Created : 2017-10-31
|
||||
-- Last update: 2017-10-31
|
||||
-- SVN ID : Git
|
||||
-- Standard : VHDL'08
|
||||
-------------------------------------------------------------------------------
|
||||
-- Description:
|
||||
-- Regenerate the UART signal
|
||||
-------------------------------------------------------------------------------
|
||||
-- altera vhdl_input_version vhdl_2008
|
||||
|
||||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
use ieee.numeric_std.all;
|
||||
|
||||
entity uart_regen_1 is
|
||||
generic(
|
||||
data_width : natural range 1 to 31);
|
||||
port(
|
||||
reset_n : in std_logic;
|
||||
clk : in std_logic;
|
||||
bit_div : in std_logic_vector(3 downto 0); -- number of clock cycles per tx bit
|
||||
enable : in std_logic;
|
||||
bypass_en : in std_logic;
|
||||
uart_rx : in std_logic;
|
||||
uart_tx : out std_logic);
|
||||
end entity uart_regen_1;
|
||||
|
||||
architecture rtl of uart_regen_1 is
|
||||
|
||||
type fsm_state_t is (s_init, s_idle, s_regen);
|
||||
|
||||
signal fsm_state_curr, fsm_state_next : fsm_state_t;
|
||||
--
|
||||
signal uart_rx_i, ld_data, rst_bit_cnt, inc_bit_cnt : std_logic;
|
||||
signal rst_clk_cnt, end_of_bit, end_of_rx : std_logic;
|
||||
signal uart_regen, uart_regen_i : std_logic;
|
||||
--
|
||||
signal clk_cnt : std_logic_vector(3 downto 0);
|
||||
signal bit_cnt : std_logic_vector(5 downto 0);
|
||||
|
||||
begin
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Input Synchronization
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
iSYNC_IN : entity work.sync_wire_1
|
||||
generic map(
|
||||
rst_val => '1',
|
||||
sync_stages => 3)
|
||||
port map(
|
||||
rstN => reset_n,
|
||||
clk => clk,
|
||||
async_in => uart_rx,
|
||||
sync_out => uart_rx_i);
|
||||
|
||||
-- NOTE : No NEED TO SYNCHRONIZE TO THE LOCAL CLOCK inputs enable, bypass_en
|
||||
-- and bit_biv BECAUSE THOSE SIGNALS ARE PREDOMINANTLY STATIC
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- UART registers and sequential logic
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
pREGs : process(clk)
|
||||
begin
|
||||
if (clk = '1' and clk'event) then
|
||||
if (rst_bit_cnt = '1') then
|
||||
bit_cnt <= (others => '0');
|
||||
elsif (inc_bit_cnt = '1') then
|
||||
bit_cnt <= std_logic_vector(unsigned(bit_cnt) + 1);
|
||||
end if;
|
||||
ld_data <= '0';
|
||||
if clk_cnt = ('0' & std_logic_vector(unsigned(bit_div(bit_div'high downto 1)) + 1)) then
|
||||
ld_data <= '1';
|
||||
end if;
|
||||
|
||||
if (rst_clk_cnt = '1' or end_of_bit = '1') then
|
||||
clk_cnt <= std_logic_vector(unsigned(bit_div) - 1);
|
||||
else
|
||||
clk_cnt <= std_logic_vector(unsigned(clk_cnt) - 1);
|
||||
end if;
|
||||
if (enable = '0') then
|
||||
uart_regen_i <= '1';
|
||||
elsif (ld_data = '1') then
|
||||
uart_regen_i <= uart_rx_i;
|
||||
end if;
|
||||
uart_regen <= uart_regen_i;
|
||||
end if;
|
||||
end process pREGs;
|
||||
|
||||
end_of_bit <= '1' when unsigned(clk_cnt) = 0 else '0';
|
||||
end_of_rx <= '1' when unsigned(bit_cnt) = data_width + 1 else '0';
|
||||
|
||||
-- output mux
|
||||
uart_tx <= uart_rx when bypass_en = '1' else uart_regen;
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- FSM
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-- FSM state register
|
||||
pFSM_SR : process(clk)
|
||||
begin
|
||||
if (clk = '1' and clk'event) then
|
||||
if (enable = '0' or bypass_en = '1') then
|
||||
fsm_state_curr <= s_init;
|
||||
else
|
||||
fsm_state_curr <= fsm_state_next;
|
||||
end if;
|
||||
end if;
|
||||
end process pFSM_SR;
|
||||
|
||||
-- FSM Combinational Logic
|
||||
pFSM_CL : process(fsm_state_curr, uart_rx_i, end_of_bit, end_of_rx, clk_cnt, bit_div)
|
||||
begin
|
||||
--default assignments
|
||||
rst_clk_cnt <= '0';
|
||||
rst_bit_cnt <= '0';
|
||||
inc_bit_cnt <= '0';
|
||||
--
|
||||
fsm_state_next <= fsm_state_curr;
|
||||
|
||||
case fsm_state_curr is
|
||||
when s_init =>
|
||||
if (uart_rx_i = '1') then
|
||||
fsm_state_next <= s_idle;
|
||||
end if;
|
||||
|
||||
when s_idle =>
|
||||
if (uart_rx_i = '0') then
|
||||
rst_clk_cnt <= '1';
|
||||
rst_bit_cnt <= '1';
|
||||
fsm_state_next <= s_regen;
|
||||
end if;
|
||||
|
||||
when s_regen =>
|
||||
|
||||
if (end_of_bit = '1') then
|
||||
inc_bit_cnt <= '1';
|
||||
if (end_of_rx = '1') then
|
||||
if (uart_rx_i = '1') then
|
||||
fsm_state_next <= s_idle;
|
||||
else
|
||||
fsm_state_next <= s_init;
|
||||
end if;
|
||||
end if;
|
||||
end if;
|
||||
|
||||
end case;
|
||||
end process pFSM_CL;
|
||||
|
||||
|
||||
end architecture rtl;
|
||||
186
generic_ip/pof_protocol/1/src/uart_rx_1.vhd
Normal file
186
generic_ip/pof_protocol/1/src/uart_rx_1.vhd
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
-------------------------------------------------------------------------------
|
||||
-- Title : uart_rx
|
||||
-- Project : EMB-1
|
||||
-------------------------------------------------------------------------------
|
||||
-- File : uart_rx.vhd
|
||||
-- Author : Gianmarco Girau
|
||||
-- Company : Global Inkjet Systems
|
||||
-- Created : 2016-10-24
|
||||
-- Last update: 2019-09-20
|
||||
-- SVN ID : Git
|
||||
-- Standard : VHDL'08
|
||||
-------------------------------------------------------------------------------
|
||||
-- Description:
|
||||
-- Simple UART receiver, used to receive data over the POF, 1 start, 1 stop
|
||||
-- bit, no parity
|
||||
-------------------------------------------------------------------------------
|
||||
-- altera vhdl_input_version vhdl_2008
|
||||
|
||||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
use ieee.numeric_std.all;
|
||||
|
||||
entity uart_rx_1 is
|
||||
generic(
|
||||
data_width : natural range 1 to 31);
|
||||
port(
|
||||
reset_n : in std_logic;
|
||||
clk : in std_logic;
|
||||
bit_div : in std_logic_vector(3 downto 0); -- number of clock cycles per tx bit
|
||||
init : in std_logic;
|
||||
data_out : out std_logic_vector(data_width - 1 downto 0);
|
||||
data_out_valid : out std_logic;
|
||||
rx_error : out std_logic;
|
||||
rx_data : in std_logic);
|
||||
end entity uart_rx_1;
|
||||
|
||||
architecture rtl of uart_rx_1 is
|
||||
|
||||
type fsm_state_t is (s_init, s_idle, s_get_start_bit, s_get_data, s_get_stop_bit);
|
||||
|
||||
signal fsm_state_curr, fsm_state_next : fsm_state_t;
|
||||
--
|
||||
signal rx_data_i, rst_bit_cnt, inc_bit_cnt : std_logic;
|
||||
signal rst_clk_cnt, end_of_rx, data_valid : std_logic;
|
||||
signal stop_bit, rx_error_i : std_logic;
|
||||
--
|
||||
signal data : std_logic_vector(data_width - 1 downto 0);
|
||||
signal bit_cnt : std_logic_vector(5 downto 0);
|
||||
|
||||
-- avoid maths with loadable shift registers
|
||||
-- bit_div will be used to set an indexed bit of the timer shift register
|
||||
-- the timers will shift down towards zeroth bit which will indicate timer has completed.
|
||||
-- this should be faster than using a decrementer and comparators
|
||||
signal uart_bit_timer, uart_bit_sample_timer : std_logic_vector(2**bit_div'length - 1 downto 0);
|
||||
signal uart_bit_timer_load_value, uart_bit_sample_timer_load_value : std_logic_vector(2**bit_div'length - 1 downto 0);
|
||||
|
||||
signal end_of_bit : std_logic;
|
||||
signal shf_data : std_logic;
|
||||
|
||||
begin
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Input Synchronization
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
iSYNC_IN : entity work.sync_wire
|
||||
generic map(
|
||||
rst_val => '1',
|
||||
sync_stages => 3)
|
||||
port map(
|
||||
rstN => reset_n,
|
||||
clk => clk,
|
||||
async_in => rx_data,
|
||||
sync_out => rx_data_i);
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- UART registers and sequential logic
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
pREGs : process(clk)
|
||||
begin
|
||||
if (clk = '1' and clk'event) then
|
||||
if (rst_bit_cnt = '1') then
|
||||
bit_cnt <= (others => '0');
|
||||
elsif (inc_bit_cnt = '1') then
|
||||
bit_cnt <= std_logic_vector(unsigned(bit_cnt) + 1);
|
||||
end if;
|
||||
if (rst_clk_cnt = '1' or end_of_bit = '1') then
|
||||
uart_bit_timer <= uart_bit_timer_load_value;
|
||||
uart_bit_sample_timer <= uart_bit_sample_timer_load_value;
|
||||
else
|
||||
uart_bit_timer <= '0' & uart_bit_timer(uart_bit_timer'high downto 1);
|
||||
uart_bit_sample_timer <= '0' & uart_bit_sample_timer(uart_bit_sample_timer'high downto 1);
|
||||
end if;
|
||||
if (shf_data = '1') then
|
||||
data <= rx_data_i & data(data'high downto 1);
|
||||
end if;
|
||||
data_out_valid <= data_valid;
|
||||
if (data_valid = '1') then
|
||||
data_out <= data;
|
||||
end if;
|
||||
rx_error <= rx_error_i;
|
||||
uart_bit_timer_load_value <= (others => '0');
|
||||
uart_bit_timer_load_value(to_integer(unsigned(bit_div) -1 )) <= '1';
|
||||
uart_bit_sample_timer_load_value <= (others => '0');
|
||||
uart_bit_sample_timer_load_value(to_integer( unsigned(bit_div(bit_div'high downto 1)) -1)) <= '1';
|
||||
end if;
|
||||
end process pREGs;
|
||||
|
||||
shf_data <= uart_bit_sample_timer(0) and not stop_bit;
|
||||
end_of_bit <= uart_bit_timer(0);
|
||||
end_of_rx <= '1' when unsigned(bit_cnt) = data_width else '0';
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- FSM
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-- FSM state register
|
||||
pFSM_SR : process(clk)
|
||||
begin
|
||||
if (clk = '1' and clk'event) then
|
||||
if (init = '1') then
|
||||
fsm_state_curr <= s_init;
|
||||
else
|
||||
fsm_state_curr <= fsm_state_next;
|
||||
end if;
|
||||
end if;
|
||||
end process pFSM_SR;
|
||||
|
||||
-- FSM Combinational Logic
|
||||
pFSM_CL : process(all)
|
||||
begin
|
||||
--default assignments
|
||||
rst_clk_cnt <= '0';
|
||||
rst_bit_cnt <= '0';
|
||||
inc_bit_cnt <= '0';
|
||||
data_valid <= '0';
|
||||
stop_bit <= '0';
|
||||
rx_error_i <= '0';
|
||||
--
|
||||
fsm_state_next <= fsm_state_curr;
|
||||
|
||||
case fsm_state_curr is
|
||||
when s_init =>
|
||||
if (rx_data_i = '1') then
|
||||
fsm_state_next <= s_idle;
|
||||
end if;
|
||||
|
||||
when s_idle =>
|
||||
if (rx_data_i = '0') then
|
||||
rst_clk_cnt <= '1';
|
||||
rst_bit_cnt <= '1';
|
||||
fsm_state_next <= s_get_start_bit;
|
||||
end if;
|
||||
|
||||
when s_get_start_bit =>
|
||||
if (end_of_bit = '1') then
|
||||
inc_bit_cnt <= '1';
|
||||
fsm_state_next <= s_get_data;
|
||||
end if;
|
||||
|
||||
when s_get_data =>
|
||||
if (end_of_bit = '1') then
|
||||
inc_bit_cnt <= '1';
|
||||
if (end_of_rx = '1') then
|
||||
fsm_state_next <= s_get_stop_bit;
|
||||
end if;
|
||||
end if;
|
||||
|
||||
when s_get_stop_bit =>
|
||||
stop_bit <= '1';
|
||||
if (end_of_bit = '1') then
|
||||
if (rx_data_i = '1') then
|
||||
data_valid <= '1';
|
||||
fsm_state_next <= s_idle;
|
||||
else
|
||||
rx_error_i <= '1';
|
||||
fsm_state_next <= s_init;
|
||||
end if;
|
||||
end if;
|
||||
|
||||
end case;
|
||||
end process pFSM_CL;
|
||||
|
||||
|
||||
end architecture rtl;
|
||||
163
generic_ip/pof_protocol/1/src/uart_tx_1.vhd
Normal file
163
generic_ip/pof_protocol/1/src/uart_tx_1.vhd
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
-------------------------------------------------------------------------------
|
||||
-- Title : uart_tx_1
|
||||
-- Project : EMB-1
|
||||
-------------------------------------------------------------------------------
|
||||
-- File : uart_tx_1.vhd
|
||||
-- Author : Gianmarco Girau
|
||||
-- Company : Global Inkjet Systems
|
||||
-- Created : 2016-10-24
|
||||
-- Last update: 2019-09-20
|
||||
-- SVN ID : Git
|
||||
-- Standard : VHDL'08
|
||||
-------------------------------------------------------------------------------
|
||||
-- Description:
|
||||
-- Simple UART trasmitter, used to trasmit data over the POF, 1 start, 1 stop
|
||||
-- bit, no parity
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
use ieee.numeric_std.all;
|
||||
|
||||
entity uart_tx_1 is
|
||||
generic(
|
||||
data_width : natural range 1 to 31);
|
||||
port(
|
||||
reset_n : in std_logic;
|
||||
clk : in std_logic;
|
||||
bit_div : in std_logic_vector(3 downto 0); -- number of clock cycles per tx bit
|
||||
init : in std_logic;
|
||||
ready : out std_logic;
|
||||
data_in : in std_logic_vector(data_width-1 downto 0);
|
||||
data_valid : in std_logic;
|
||||
tx_data : out std_logic);
|
||||
end entity uart_tx_1;
|
||||
|
||||
architecture rtl of uart_tx_1 is
|
||||
|
||||
type fsm_state_t is (idle, send_start_bit, send_data, send_stop_bit);
|
||||
|
||||
signal fsm_state_curr, fsm_state_next : fsm_state_t;
|
||||
--
|
||||
signal ld_data, shf_data, rst_bit_cnt, inc_bit_cnt : std_logic;
|
||||
signal rst_clk_cnt, end_of_bit, end_of_tx : std_logic;
|
||||
signal rst_tx_data, set_tx_data, ld_tx_data : std_logic;
|
||||
signal ready_i : std_logic;
|
||||
--
|
||||
signal data : std_logic_vector(data_width-1 downto 0);
|
||||
signal clk_cnt : std_logic_vector(3 downto 0);
|
||||
signal bit_cnt : std_logic_vector(5 downto 0);
|
||||
|
||||
begin
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- UART registers and sequential logic
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
pREGs : process(clk)
|
||||
begin
|
||||
if(clk ='1' and clk'event) then
|
||||
if(ld_data = '1') then
|
||||
data <= data_in;
|
||||
elsif(shf_data = '1') then
|
||||
data <= '0' & data(data'high downto 1);
|
||||
end if;
|
||||
if(rst_bit_cnt = '1') then
|
||||
bit_cnt <= (others => '0');
|
||||
elsif(inc_bit_cnt = '1') then
|
||||
bit_cnt <= std_logic_vector(unsigned(bit_cnt)+1);
|
||||
end if;
|
||||
if(rst_clk_cnt = '1' or end_of_bit = '1') then
|
||||
clk_cnt <= (others => '0');
|
||||
else
|
||||
clk_cnt <= std_logic_vector(unsigned(clk_cnt)+1);
|
||||
end if;
|
||||
if(rst_tx_data = '1') then
|
||||
tx_data <= '0';
|
||||
elsif(set_tx_data = '1') then
|
||||
tx_data <= '1';
|
||||
elsif(ld_tx_data = '1') then
|
||||
tx_data <= data(0);
|
||||
end if;
|
||||
end if;
|
||||
end process pREGs;
|
||||
|
||||
end_of_bit <= '1' when unsigned(clk_cnt) = (unsigned(bit_div)-1) else '0';
|
||||
end_of_tx <= '1' when unsigned(bit_cnt) = data_width else '0';
|
||||
|
||||
--shf_data <= inc_bit_cnt;
|
||||
shf_data <= ld_tx_data;
|
||||
inc_bit_cnt <= ld_tx_data;
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- FSM
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-- FSM state register
|
||||
pFSM_SR : process(reset_n, clk)
|
||||
begin
|
||||
if(reset_n = '0') then
|
||||
fsm_state_curr <= idle;
|
||||
elsif(clk = '1' and clk'event) then
|
||||
fsm_state_curr <= fsm_state_next;
|
||||
end if;
|
||||
end process pFSM_SR;
|
||||
|
||||
-- FSM Combinational Logic
|
||||
pFSM_CL : process(fsm_state_curr, init, data_valid, end_of_bit, end_of_tx)
|
||||
begin
|
||||
--default assignments
|
||||
ready_i <= '0';
|
||||
rst_clk_cnt <= '0';
|
||||
rst_tx_data <= '0';
|
||||
set_tx_data <= '0';
|
||||
ld_tx_data <= '0';
|
||||
rst_bit_cnt <= '0';
|
||||
ld_data <= '0';
|
||||
--
|
||||
fsm_state_next <= fsm_state_curr;
|
||||
|
||||
if(init = '1') then
|
||||
set_tx_data <= '1';
|
||||
fsm_state_next <= idle;
|
||||
else
|
||||
case fsm_state_curr is
|
||||
when idle =>
|
||||
ready_i <= '1';
|
||||
ld_data <= '1';
|
||||
rst_clk_cnt <= '1';
|
||||
rst_bit_cnt <= '1';
|
||||
set_tx_data <= '1';
|
||||
if(data_valid = '1') then
|
||||
rst_tx_data <= '1';
|
||||
fsm_state_next <= send_start_bit;
|
||||
end if;
|
||||
|
||||
when send_start_bit =>
|
||||
if(end_of_bit = '1') then
|
||||
ld_tx_data <= '1';
|
||||
fsm_state_next <= send_data;
|
||||
end if;
|
||||
|
||||
when send_data =>
|
||||
if(end_of_bit = '1') then
|
||||
ld_tx_data <= '1';
|
||||
if(end_of_tx = '1') then
|
||||
set_tx_data <= '1';
|
||||
fsm_state_next <= send_stop_bit;
|
||||
end if;
|
||||
end if;
|
||||
|
||||
when send_stop_bit =>
|
||||
if(end_of_bit = '1') then
|
||||
fsm_state_next <= idle;
|
||||
end if;
|
||||
|
||||
when others => null;
|
||||
end case;
|
||||
end if;
|
||||
end process pFSM_CL;
|
||||
|
||||
ready <= ready_i;
|
||||
|
||||
end architecture rtl;
|
||||
|
|
@ -1 +1 @@
|
|||
- Major Version 1: Modified POF Protocol, with Golay coding
|
||||
- Major Version 1: Modified POF Protocol, including Start/Stop Print bit for W&H
|
||||
Loading…
Add table
Add a link
Reference in a new issue