diff --git a/src/CAN_Core/core_top.vhd b/src/CAN_Core/core_top.vhd index 87a8d48fc75efa86ec1cdea444d2c20a893c8702..571b4a269e5ae29627459b26873f03c4cfef59ac 100644 --- a/src/CAN_Core/core_top.vhd +++ b/src/CAN_Core/core_top.vhd @@ -902,8 +902,7 @@ begin sof_pulse <= sof_pulse_r; bus_off_start <= bus_off_start_int; - - -- Note TODO: signal for signalling the shifted bit Rate for interrupt + br_shifted <= br_shifted_int; ssp_reset <= ssp_reset_int; diff --git a/src/CAN_Core/protocolControl.vhd b/src/CAN_Core/protocolControl.vhd index 803d47262ae71b36b02178950fd17f8cdc9b2d00..4c621f8df402a3195836b93b54cbc366a7061cc2 100644 --- a/src/CAN_Core/protocolControl.vhd +++ b/src/CAN_Core/protocolControl.vhd @@ -2720,7 +2720,6 @@ begin PC_State <= overload; else PC_State <= sof; - -- TODO: is it really necessary to enable here? crc_enable_r <= '1'; end if; FSM_preset <= '1'; diff --git a/test/feature/arbitration_feature_tb.vhd b/test/feature/arbitration_feature_tb.vhd index 5d5909933e75143c1fd6b0ff9357aabb9e85d34c..b88a9413f35d3b408ffda0e3bcb191a914a46205 100644 --- a/test/feature/arbitration_feature_tb.vhd +++ b/test/feature/arbitration_feature_tb.vhd @@ -345,9 +345,6 @@ package body Arbitration_feature is read_alc(alc, ID_2, mem_bus(2)); end if; - -- TODO: Compare ALC value with expected value where node should - -- have lost arbitration! - ------------------------------------------------------------------------ -- If error frame is transmitted and collision not have appeared ------------------------------------------------------------------------ diff --git a/test/lib/CANtestLib.vhd b/test/lib/CANtestLib.vhd index 94d929a5b8e848047e5d4b3008c91d7620ac309f..e81107205824c15949b49ebe210f54a497680506 100644 --- a/test/lib/CANtestLib.vhd +++ b/test/lib/CANtestLib.vhd @@ -495,6 +495,20 @@ package CANtestLib is constant f100_MHZ : natural := 10000; + ---------------------------------------------------------------------------- + ---------------------------------------------------------------------------- + -- sanity test Stuff; must be in a package + ---------------------------------------------------------------------------- + ---------------------------------------------------------------------------- + constant NODE_COUNT : natural := 4; + type bus_matrix_type is array(1 to NODE_COUNT, 1 to NODE_COUNT) of real; + type anat_t is array (integer range <>) of natural; + subtype anat_nc_t is anat_t (1 to NODE_COUNT); + + subtype epsilon_type is anat_nc_t; + subtype trv_del_type is anat_nc_t; + subtype timing_config_t is anat_t(1 to 10); + ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- @@ -932,6 +946,31 @@ package CANtestLib is ); + ---------------------------------------------------------------------------- + -- Print Bus timing configuration of CTU CAN FD Core. + -- (duration of bit phases, synchronisation jump width, baud-rate prescaler) + -- + -- Arguments: + -- bus_timing Bus timing structure that will be printed in simulator. + -- ID Index of CTU CAN FD Core instance + -- mem_bus Avalon memory bus to execute the access on. + ---------------------------------------------------------------------------- + procedure CAN_print_timing( + constant bus_timing : in bit_time_config_type + ); + + + ---------------------------------------------------------------------------- + -- Print Bus matrix from sanity test configuration. + -- + -- Arguments: + -- bus_matrix Bus Matrix to be printed. + ---------------------------------------------------------------------------- + procedure CAN_print_bus_matrix( + constant bus_matrix : in bus_matrix_type + ); + + ---------------------------------------------------------------------------- -- Turn on/off CTU_CAN_FD Core. -- @@ -1565,23 +1604,6 @@ package CANtestLib is signal mem_bus : inout Avalon_mem_type ); - - - ---------------------------------------------------------------------------- - ---------------------------------------------------------------------------- - -- sanity test Stuff; must be in a package - ---------------------------------------------------------------------------- - ---------------------------------------------------------------------------- - constant NODE_COUNT : natural := 4; - type bus_matrix_type is array(1 to NODE_COUNT,1 to NODE_COUNT) of real; - type anat_t is array (integer range <>) of natural; - subtype anat_nc_t is anat_t (1 to NODE_COUNT); - - subtype epsilon_type is anat_nc_t; - subtype trv_del_type is anat_nc_t; - subtype timing_config_t is anat_t(1 to 10); - - ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- Component declarations @@ -1816,7 +1838,7 @@ package body CANtestLib is res_n <= '1'; status <= running; error_ctr <= 0; - wait for 250 ns; -- TODO: is it necessary? + wait for 250 ns; end procedure; @@ -2345,6 +2367,67 @@ package body CANtestLib is end procedure; + procedure CAN_print_timing( + constant bus_timing : in bit_time_config_type + )is + variable msg : line; + begin + write(msg, string'("Nominal Bit timing: ")); + + -- Baud Rate Prescaler + write(msg, string'("BRP: " & integer'image(bus_timing.tq_nbt) & " ")); + + -- Propagation segment + write(msg, string'("PROP: " & integer'image(bus_timing.prop_nbt) & " ")); + + -- Phase 1 segment + write(msg, string'("PH1: " & integer'image(bus_timing.ph1_nbt) & " ")); + + -- Phase 2 segment + write(msg, string'("PH2: " & integer'image(bus_timing.ph2_nbt) & " ")); + + -- SJW + write(msg, string'("SJW: " & integer'image(bus_timing.sjw_nbt) & " ")); + + write(msg, string'("Data Bit timing: ")); + + -- Baud Rate Prescaler - FD + write(msg, string'("BRP: " & integer'image(bus_timing.tq_dbt) & " ")); + + -- Propagation segment - FD + write(msg, string'("PROP: " & integer'image(bus_timing.prop_dbt) & " ")); + + -- Phase 1 segment - FD + write(msg, string'("PH1: " & integer'image(bus_timing.ph1_dbt) & " ")); + + -- Phase 2 segment - FD + write(msg, string'("PH2: " & integer'image(bus_timing.ph2_dbt) & " ")); + + -- SJW - FD + write(msg, string'("SJW: " & integer'image(bus_timing.sjw_dbt) & " ")); + + writeline(output, msg); + end procedure; + + + procedure CAN_print_bus_matrix( + constant bus_matrix : in bus_matrix_type + )is + variable msg : line; + begin + write(msg, string'("Bus matrix: ")); + writeline(output, msg); + + for i in 1 to NODE_COUNT loop + for j in 1 to NODE_COUNT loop + write(msg, string'(real'image(bus_matrix(i, j)) & " ")); + end loop; + writeline(output, msg); + end loop; + + end procedure; + + procedure CAN_turn_controller( constant turn_on : in boolean; constant ID : in natural range 0 to 15; diff --git a/test/lib/test_lib.tcl b/test/lib/test_lib.tcl index d3f858cd4d447b462708c5095b7ad15020f9e8de..44d85676cde9f15644702faae76b0e370d3713bb 100644 --- a/test/lib/test_lib.tcl +++ b/test/lib/test_lib.tcl @@ -118,73 +118,6 @@ proc run_simulation {} { run -all } -################################################################################ -# Obtains the test results from the simulator, by -# extracting the value of status signals into global variables TEST_RESULT -# and ERROR_COUNT -################################################################################ -proc get_test_results {} { - global TEST_RESULT - global ERROR_COUNT - global TCOMP - - set TEST_RESULT [exa {/can_test_wrapper/status}] - set ERROR_COUNT [exa {/can_test_wrapper/errors}] -} - -################################################################################ -# Obtains the test results from the simulator, by -# extracting the value of status signals into global variables -################################################################################ -proc get_test_results_feature {} { - global TEST_RESULT - global ERROR_COUNT - global TCOMP - - set TEST_RESULT [exa {/can_test_wrapper/status}] - set ERROR_COUNT [exa {/can_test_wrapper/error_ctr}] -} - -################################################################################ -# Prints help into command line -################################################################################ -proc print_help {} { - puts "CANTest framework has following commands available:" - puts " help to print this help menu" - puts " exit to exit the test framework" - puts " test to run the tests" - puts " " - - puts "CANTest framework contains following types of tests:" - puts " Unit tests" - puts " Feature tests" - puts " Sanity tests" - puts " " - - puts "Unit tests can be used via following commands:" - puts " test unit To execute unit test" - puts " test unit all TO execute all existing unit tests" - puts " " - - puts "Feature tests can be used via following commands:" - puts " test feature start To start test environment of feature test" - puts " test feature run To start feature test execution" - puts " test feature print_config To print configuration of feature test" - puts " " - - puts "Sanity tests can be used via following commands:" - puts " test sanity start To start test environment of sanity test" - puts " test sanity run To start sanity test execution" - puts " test sanity start silent To start sanity test with only basic waveform " - puts " This option is recomended to save harddisk space" - puts " when running long sanity simulations (e.g more than 5 hours)" - puts " " - - puts "Feature and sanity tests have separate configuration files (TCL) in " - puts "their corresponding directories. See the CAN FD IP Core documentation" - puts "to get the details about test configuration files" - puts " " -} ################################################################################ # Executes first TCL script it finds in given directory. @@ -251,274 +184,6 @@ proc exec_all_TCL_from_path {path} { -################################################################################ -################################################################################ -# Feature tests routines -################################################################################ -################################################################################ - -################################################################################ -# Starts simulation of feature test environment -################################################################################ -proc start_feature_FIFO {} { - global BASE_TEST - do "${BASE_TEST}/feature/feature_env_setup.tcl" -} - -################################################################################ -# Runs the feature test simulation. -# Feature config script is executed and FEATURE_FIFO is loaded. -# In loop each config is executed and FEATURE_FIFO is sliced until all tests -# are executed -################################################################################ -proc run_feature_FIFO {} { - global FEATURE_FIFO - global TCOMP - global TEST_RESULT - global ERROR_COUNT - global BASE_TEST - - set feat_res [] - - #Run the config script which sets up the feature list - #(ORIGINAL Feature FIFO) - do "${BASE_TEST}/feature/feature_config.tcl" - - #Iterate over FIFO entries - while { [llength $FEATURE_FIFO] > 0 } { - set actual [lindex $FEATURE_FIFO 0] - set act_name [lindex $actual 0] - set act_iter [lindex $actual 1] - - #Set the testbench stimulus - force $TCOMP/iterations $act_iter - set fmt_name [format "%20s" $act_name] - force $TCOMP/test_name "${fmt_name}" - - #Run the testbench and fetch results - run_simulation - get_test_results_feature - - #Erase the actual test from FIFO - set FEATURE_FIFO [lreplace $FEATURE_FIFO 0 0] - - #TODO: Here gather the result of the test! - lappend feat_res [list $act_name $act_iter $ERROR_COUNT $TEST_RESULT] - } - - puts "Feature test run results:" - foreach actual $feat_res { - puts $actual - } -} - -proc show_feature_FIFO {} { - global BASE_TEST - global FEATURE_FIFO - - do "${BASE_TEST}/feature/feature_config.tcl" - puts $FEATURE_FIFO -} - - -################################################################################ -################################################################################ -# Sanity test routines -################################################################################ -################################################################################ - -################################################################################ -# Set the bus_matrix signal of sanity test environment -################################################################################ -proc force_bm {a b c d e f g h i j k l m n o p} { - global TCOMP - - force $TCOMP/bus_matrix(1,1) $a - force $TCOMP/bus_matrix(1,2) $b - force $TCOMP/bus_matrix(1,3) $c - force $TCOMP/bus_matrix(1,4) $d - - force $TCOMP/bus_matrix(2,1) $e - force $TCOMP/bus_matrix(2,2) $f - force $TCOMP/bus_matrix(2,3) $g - force $TCOMP/bus_matrix(2,4) $h - - force $TCOMP/bus_matrix(3,1) $i - force $TCOMP/bus_matrix(3,2) $j - force $TCOMP/bus_matrix(3,3) $k - force $TCOMP/bus_matrix(3,4) $l - - force $TCOMP/bus_matrix(4,1) $m - force $TCOMP/bus_matrix(4,2) $n - force $TCOMP/bus_matrix(4,3) $o - force $TCOMP/bus_matrix(4,4) $p -} - -################################################################################ -# Start sanity test simulation -################################################################################ -proc start_sanity {} { - global BASE_TEST - do "${BASE_TEST}/sanity/sanity_env_setup.tcl" -} - -################################################################################ -# Run sanity test -# First SAN_CFG is loaded and each configuration is executed until all configs -# are exectued. -################################################################################ -proc run_sanity {} { - global SAN_CFG - global TCOMP - global TEST_RESULT - global ERROR_COUNT - global BASE_TEST - - set san_res [] - - #Run the config script which sets up the list with sanity - # configurations - do "${BASE_TEST}/sanity/sanity_config.tcl" - - #Iterate over the configurations - while { [llength $SAN_CFG] > 0 } { - set actual [lindex $SAN_CFG 0] - - ################################## - #Aliases for configuration values - ################################## - set topology [lindex $actual 0] - - #Bus lengths configuration - set l1 [lindex $actual 1] - set l2 [lindex $actual 2] - set l3 [lindex $actual 3] - set l4 [lindex $actual 4] - set l5 [lindex $actual 5] - set l6 [lindex $actual 6] - - #Transciever delay - set del [list [lindex $actual 7] [lindex $actual 8]\ - [lindex $actual 9] [lindex $actual 10]] - - #Oscillator tollerance - set osc [list [lindex $actual 11] [lindex $actual 12]\ - [lindex $actual 13] [lindex $actual 14]] - - #Noise parameters - set nw_mean [lindex $actual 15] - set nw_var [lindex $actual 16] - set ng_mean [lindex $actual 17] - set ng_var [lindex $actual 18] - - #Bit time config - set brp_nbt [lindex $actual 19] - set brp_dbt [lindex $actual 20] - set prop_nbt [lindex $actual 21] - set ph1_nbt [lindex $actual 22] - set ph2_nbt [lindex $actual 23] - set sjw_nbt [lindex $actual 24] - set prop_dbt [lindex $actual 25] - set ph1_dbt [lindex $actual 26] - set ph2_dbt [lindex $actual 27] - set sjw_dbt [lindex $actual 28] - - #Name and iterations amount - set act_name [lindex $actual 29] - set act_iter [lindex $actual 30] - - ################################## - # Now force the values to the test - ################################## - - #Bus matrix based on topology - if { $topology == "bus"} { - force_bm 0 $l1 [expr "${l1}+${l2}"] [expr "${l1}+${l2}+${l3}"]\ - $l1 0 $l2 [expr "${l2}+${l3}"]\ - [expr "${l1}+${l2}"] $l2 0 $l3\ - [expr "${l1}+${l2}+${l3}"] [expr "${l2}+${l3}"] $l3 0 - } elseif { $topology == "star" } { - force_bm 0 [expr "${l1}+${l2}"] [expr "${l1}+${l3}"] [expr "${l1}+${l4}"]\ - [expr "${l1}+${l2}"] 0 [expr "${l2}+${l3}"] [expr "${l2}+${l4}"]\ - [expr "${l1}+${l3}"] [expr "${l2}+${l3}"] 0 [expr "${l3}+${l4}"]\ - [expr "${l1}+${l4}"] [expr "${l2}+${l4}"] [expr "${l3}+${l4}"] 0 - } elseif { $topology == "tree" } { - force_bm 0 [expr "${l1}+${l2}"] [expr "${l1}+${l3}+${l5}"] [expr "${l1}+${l4}+${l5}"]\ - [expr "${l1}+${l2}"] 0 [expr "${l2}+${l3}+${l5}"] [expr "${l2}+${l4}+${l5}"]\ - [expr "${l1}+${l3}+${l5}"] [expr "${l2}+${l3}+${l5}"] 0 [expr "${l3}+${l4}"]\ - [expr "${l1}+${l4}+${l5}"] [expr "${l2}+${l4}+${l5}"] [expr "${l3}+${l4}"] 0 - } elseif { $topology == "ring" } { - # TODO: Ring topology with fucking min functions - } elseif { $topology == "custom" } { - force_bm 0 $l1 $l2 $l3 - $l1 0 $l4 $l5 - $l2 $l4 0 $l6 - $l3 $l6 $l6 0 - } else { - puts "Invalid bus topology! Assuming bus topology..." - force_bm 0 $l1 [expr "${l1}+${l2}"] [expr "${l1}+${l2}+${l3}"]\ - $l1 0 $l2 [expr "${l2}+${l3}"]\ - [expr "${l1}+${l2}"] $l2 0 $l3\ - [expr "${l1}+${l2}+${l3}"] [expr "${l2}+${l3}"] $l3 0 - } - - #Set the testbench stimulus - force $TCOMP/iterations $act_iter - set fmt_name [format "%-50s" $act_name] - force $TCOMP/i_st/test_desc "${fmt_name}" - - set fmt_topology [format "%-50s" $topology] - force $TCOMP/topology "${fmt_topology}" - - #Transciever delays - set index 0 - foreach elem $del { - incr index - force $TCOMP/trv_del_v($index) $elem - } - - #Oscilator tolerances - set index 0 - foreach elem $osc { - incr index - force $TCOMP/epsilon_v($index) $elem - } - - #Noise parameters - force $TCOMP/nw_mean $nw_mean - force $TCOMP/nw_var $nw_var - force $TCOMP/ng_mean $ng_mean - force $TCOMP/ng_var $ng_var - - #Bit time settings - force $TCOMP/timing_config.tq_nbt $brp_nbt - force $TCOMP/timing_config.tq_dbt $brp_dbt - force $TCOMP/timing_config.prop_nbt $prop_nbt - force $TCOMP/timing_config.ph1_nbt $ph1_nbt - force $TCOMP/timing_config.ph2_nbt $ph2_nbt - force $TCOMP/timing_config.sjw_nbt $sjw_nbt - force $TCOMP/timing_config.prop_dbt $prop_dbt - force $TCOMP/timing_config.ph1_dbt $ph1_dbt - force $TCOMP/timing_config.ph2_dbt $ph2_dbt - force $TCOMP/timing_config.sjw_dbt $sjw_dbt - - #Run the testbench and fetch results - run_simulation - get_test_results_feature - - #Erase the actual test from test config - set SAN_CFG [lreplace $SAN_CFG 0 0] - - #TODO: Here gather the result of the test! - lappend san_res [list $act_name "Iterations:" $act_iter "Errors:" $ERROR_COUNT "Result:" $TEST_RESULT] - } - - puts "Sanity test run results:" - foreach actual $san_res { - puts $actual - } -} - diff --git a/test/reference/reference_env_setup.tcl b/test/reference/reference_env_setup.tcl index c820cd82afd08b8d0d36bd1a73a526c50cd76866..39802c78b3cbf75b20bcfaaa76ab14a6f9e8a405 100644 --- a/test/reference/reference_env_setup.tcl +++ b/test/reference/reference_env_setup.tcl @@ -44,15 +44,8 @@ global TCOMP ################################################################################ #Add common waves for each test entity -#add_test_status_waves -#add_system_waves - -#TODO: Will be replace by calls above. So far disabled to allow manual debug! -add wave $TCOMP/run -add wave $TCOMP/loop_ctr -add wave $TCOMP/iterations -add wave $TCOMP/errors -add wave $TCOMP/status +add_test_status_waves +add_system_waves add wave -noupdate -divider -height 20 "System signals" add wave -label "Clock" $TCOMP/clk_sys diff --git a/test/sanity/sanity_test.vhd b/test/sanity/sanity_test.vhd index 828596cdafe691573669afd42706251b1b9432c3..a901a6a87909026b5f50856fed86c8e34b5cbc02 100644 --- a/test/sanity/sanity_test.vhd +++ b/test/sanity/sanity_test.vhd @@ -128,7 +128,6 @@ entity sanity_test is -- Amount of errors which appeared in the test signal errors :out natural - --TODO: Error log results ); end entity; @@ -825,8 +824,39 @@ begin variable step_done : boolean := false; begin print_test_info(iterations, log_level, error_beh, error_tol); - -- TODO: print sanity test params + + ------------------------------------------------------------------------ + -- Print Test configuration + ------------------------------------------------------------------------ + log("Sanity test configuration:", info_l, log_level); + log("Clock jitters (ppm): " + & integer'image(epsilon_v(1)) & " " + & integer'image(epsilon_v(2)) & " " + & integer'image(epsilon_v(3)) & " " + & integer'image(epsilon_v(4)) & " ", + info_l, log_level); + + log("Transceiver delays (ns): " + & integer'image(trv_del_v(1)) & " " + & integer'image(trv_del_v(2)) & " " + & integer'image(trv_del_v(3)) & " " + & integer'image(trv_del_v(4)) & " ", + info_l, log_level); + + log(" Noise width (mean): " & real'image(nw_mean) & + " Noise width (var): " & real'image(nw_var) & + " Noise gap (mean): " & real'image(ng_mean) & + " Noise gap (var): " & real'image(ng_var), + info_l, log_level); + + log ("Bus topology: " & topology, info_l, log_level); + + CAN_print_timing(timing_config); + CAN_print_bus_matrix(bus_matrix); + ------------------------------------------------------------------------ + -- Execute test reset + ------------------------------------------------------------------------ wait for 5 ns; do_restart_mem_if <= (OTHERS => false); wait for 5 ns; diff --git a/test/testfw/test_sanity.py b/test/testfw/test_sanity.py index 2860d99144c80415e6e7f473c3d3a1726cc60672..67f7c48dee0c111f0d7d81ee6083fa8fbbc7aa51 100644 --- a/test/testfw/test_sanity.py +++ b/test/testfw/test_sanity.py @@ -23,8 +23,10 @@ def len_to_matrix(topology, bus_len): [l[1]+l[3]+l[5], l[2]+l[3]+l[5], 0.0, l[3]+l[4]], [l[1]+l[4]+l[5], l[2]+l[4]+l[5], l[3]+l[4], 0.0]] elif topology == 'ring': - raise RuntimeError("Ring topology not implemented.") - # TODO: Ring topology with min functions + bm = [[0.0, min(l[1], l[2]+l[3]+l[4]), min(l[1]+l[2],l[3]+l[4]), min(l[4],l[1]+l[2]+l[3])], + [min(l[1], l[2]+l[3]+l[4]), 0.0, min(l[2], l[1]+l[3]+l[4]), min(l[2]+l[3],l[1]+l[4])], + [min(l[1]+l[2],l[3]+l[4]), min(l[2], l[1]+l[3]+l[4]), 0.0, min(l[3],l[1]+l[2]+l[4])], + [min(l[4],l[1]+l[2]+l[3]), min(l[2]+l[3],l[1]+l[4]), min(l[3],l[1]+l[2]+l[4]), 0.0]] elif topology == 'custom': bm = [[0.0, l[1], l[2], l[3]], [l[1], 0.0, l[4], l[5]],