/* * _xc_test_Toroid_2.xc * * Created on: 7. mars 2021 * Author: teig * * https://patorjk.com/software/taag/#p=display&f=Big&t=TOP_21 * _ _ _ _ _ ___ * | | | | | | (_) | | |__ \ * __ _____ | |_ ___ ___| |_ | |_ ___ _ __ ___ _ __| | ) | __ _____ * \ \/ / __| | __/ _ \/ __| __| | __/ _ \| '__/ _ \| |/ _` | / / \ \/ / __| * > < (__ | || __/\__ \ |_ | || (_) | | | (_) | | (_| | / /_ _ > < (__ * /_/\_\___| \__\___||___/\__| \__\___/|_| \___/|_|\__,_| |____(_)_/\_\___| */ #include // core #include // printf (sprintf because if lib_logging and floats) #include // delay_milliseconds(..), XS1_TIMER_HZ etc #include // readability #include // uint32_t #include // memcpy #include // xScope logging #include "xassert.h" // assert and fail #include "_globals.h" #include "_version.h" // GENERAL PRINTING #define DO_DEBUG_PRINT 1 // Here and in "makefile" // IN-FUNCTION PRINING CONTROL #define DO_PRINT_INIT_TEMP 0 #define DO_PRINT_INIT_WT 0 #define DO_PRINT_CALC_TEMP 0 #define DO_PRINT_VALUES 1 #define DO_PRINT_PROGESS 0 #define DO_PRINT_SYNCH 0 #define DO_PRINT_RX_TX 0 #define DO_PRINT_FIX_SYNCH 1 #define DO_PRINT_VALUES_EVERY_CYCLE_CNT 1 // 1=every time, 1000=every thousands // Not used if DO_PRINT_RANGE==1 #define DO_PRINT_RANGE 0 // DO_PRINT_VALUES must be 1 #define DO_PRINT_RANGE_CYCLE_CNT_LOW 990 #define DO_PRINT_RANGE_CYCLE_CNT_HIGH 1010 #define DO_XSCOPE 0 /* _____ _ __ _ / ____| | | / _(_) | | ___ _ __ ___ _ __ ___ ___ _ __ __| | ___| |_ _ _ __ ___ ___ | | / _ \| '_ ` _ \| '_ ` _ \ / _ \| '_ \ / _` |/ _ \ _| | '_ \ / _ \/ __| | |___| (_) | | | | | | | | | | | (_) | | | | | (_| | __/ | | | | | | __/\__ \ \_____\___/|_| |_| |_|_| |_| |_|\___/|_| |_| \__,_|\___|_| |_|_| |_|\___||___/ */ // ===================================== // XSCOPE IS THE SCOPE IN xTIMEcomposer // ===================================== #if (DO_XSCOPE == 0) #define XSCOPE_INT(name,val) #elif (DO_XSCOPE==1) // This takes about 0.2 us, but ROOT_DELAY_UNTIL_NEXT_ROUND_US must have some real // temp_degC for data to be corrected (XScope would say "missing data" if it's too fast) #define XSCOPE_INT(name,val) xscope_int(name,val) // In "config.xscope" DISCRETE, which must be handled in offline mode, see // "xTIMEcomposer User Guide for tools version 14.0.x" page 133: // "Only continous probes can be displayed real-time." // If DECRETE not used here, temps_degC are interpolated (saw tooth curve is not of much temp_degC) // Log file is generated as "xscope.xmt" and opens on after I stop the RUN // // xScope scaling, if not top and bottom is not seen: #define XSCOPE_SCALE_MAX 1100 #define XSCOPE_VALUE_TRUE 1000 #define XSCOPE_VALUE_FALSE 100 #define XSCOPE_SCALE_MIN 0 #endif #define IS_2_BY_2 22 #define IS_4_BY_4 44 #define IS_8_BY_8 88 typedef float basic_data_type_t; typedef basic_data_type_t temp_degC_t; // DegC typedef basic_data_type_t si_unit_t; typedef basic_data_type_t joule_t; // temp_degC_t * heatcap_vals (J/K) typedef basic_data_type_t time_sec_t; typedef unsigned iof_pos_t; /* _______ _ _ _ |__ __| | | | | | | | | ___ _ __ | | ___ __ _ _ _ ___ ___| | ___ ___| |_ | |/ _ \| '_ \| |/ _ \ / _` | | | | / __|/ _ \ |/ _ \/ __| __| | | (_) | |_) | | (_) | (_| | |_| | \__ \ __/ | __/ (__| |_ |_|\___/| .__/|_|\___/ \__, |\__, | |___/\___|_|\___|\___|\__| | | __/ | __/ | |_| |___/ |___/ */ // ---- NEVER CHANGE: HARD CODED! ---------- #define NUM_CONNS_PER_NODE 3 // Physical #define NUM_NODES_PER_PAIR 2 // Every other #define SMALLEST_NUM_COLS NUM_NODES_PER_PAIR // LEGEND of config name, rather informally listed // '1_TILE' : 1 tile // '016_NODE' : 16 nodes (tasks) altogether // 'T0' : tile[0], then a list // 'T1' : tile[1], then a list // '2N' : 2 nodes on 2 cores, configured as normal task types // '2CN' : 2 combined nodes on 1 core // '4P' : 4 pairs of client and server // 'CC' : special config combined client and client on 1 core // 'CS' : special config combined client and server on 1 core // 'BY3SUB' : Each node task has 3 subtasks // #define TOP_20_HAS_2_TILE_004_T0_2N_BY3SUB_T1_2N_BY3SUB_RUNS_FAIR 20 // 2*2 chans as occam: works nicely #define TOP_21_HAS_1_TILE_004_T0_4N_RUNS_FAIR 21 // 2*2 interface: works nicely #define TOP_22_HAS_2_TILE_004_T0_2N_BY2SUB_T1_2N_BY2SUB_VIOLATES_PARALLEL_USAGE_RULES 22 // 4*4 interface: chanends overrun #define TOP_23_HAS_2_TILE_004_T0_8N_T1_8N_CHANENDS_OVERRUN 23 // 2*2 chans: wrongly used #define TOP_24_HAS_1_TILE_004_T0_2N_2CN_ETC_MAYBE_CONVERGING 24 // 2*2 interface with synch phase 24 // 2*2 interface with synch phase #define TOP_25_HAS_1_TILE_016_T0_2N_14CN_NOT_CONVERGING 25 // 4*4 interface with synch phase #define TOP_26_TESTING_SYNCH_PHASE 26 // 4*4 interface with synch phase // #define TOPOLOGY TOP_20_HAS_2_TILE_004_T0_2N_BY3SUB_T1_2N_BY3SUB_RUNS_FAIR // #define TOPOLOGY TOP_21_HAS_1_TILE_004_T0_4N_RUNS_FAIR // #define TOPOLOGY TOP_22_HAS_2_TILE_004_T0_2N_BY2SUB_T1_2N_BY2SUB_VIOLATES_PARALLEL_USAGE_RULES // #define TOPOLOGY TOP_23_HAS_2_TILE_004_T0_8N_T1_8N_CHANENDS_OVERRUN // #define TOPOLOGY TOP_24_HAS_1_TILE_004_T0_2N_2CN_ETC_MAYBE_CONVERGING // #define TOPOLOGY TOP_25_HAS_1_TILE_016_T0_2N_14CN_NOT_CONVERGING #define TOPOLOGY TOP_26_TESTING_SYNCH_PHASE #if (TOPOLOGY == TOP_20_HAS_2_TILE_004_T0_2N_BY3SUB_T1_2N_BY3SUB_RUNS_FAIR) #define NUM_ROWS 2 #define NUM_COLS 2 #define TOP_STR "Top_20 occam'ish runs fair" #define ROOT_DELAY_UNTIL_NEXT_ROUND_US 100000 // (0 allowed) Anything below round trip 1.25 us will be 1.25 us. // If 0 then DO_DEBUG_PRINT must be 0 // ROOT_DELAY_UNTIL_NEXT_ROUND_US, CLIENT_DELAY_UNTIL_NEXT_THIRD_US = 100000 See "2021 03 17 TOP_20 11.25 fair synchronized full.txt" #elif (TOPOLOGY == TOP_21_HAS_1_TILE_004_T0_4N_RUNS_FAIR) #define NUM_ROWS 2 #define NUM_COLS 2 #define TOP_STR "Top_21 runs fair (but not combinable)" #define ROOT_DELAY_UNTIL_NEXT_ROUND_US 100000 // If 0 then DO_DEBUG_PRINT must be 0 // ROOT_DELAY_UNTIL_NEXT_ROUND_US, CLIENT_DELAY_UNTIL_NEXT_THIRD_US = 100000 See "2021 03 17 TOP_21 11.31 fair synchronized full.txt" #elif (TOPOLOGY == TOP_22_HAS_2_TILE_004_T0_2N_BY2SUB_T1_2N_BY2SUB_VIOLATES_PARALLEL_USAGE_RULES) #define NUM_ROWS 2 #define NUM_COLS 2 #define TOP_STR "Top_22 occam'ish does not compile" #define ROOT_DELAY_UNTIL_NEXT_ROUND_US 100000 // If 0 then DO_DEBUG_PRINT must be 0 #elif (TOPOLOGY == TOP_23_HAS_2_TILE_004_T0_8N_T1_8N_CHANENDS_OVERRUN) #define NUM_ROWS 4 #define NUM_COLS 4 #define TOP_STR "Top_23 does not compile" #define ROOT_DELAY_UNTIL_NEXT_ROUND_US 100000 // If 0 then DO_DEBUG_PRINT must be 0 #elif (TOPOLOGY == TOP_24_HAS_1_TILE_004_T0_2N_2CN_ETC_MAYBE_CONVERGING) #define NUM_ROWS 2 #define NUM_COLS 2 #define ROOT_DELAY_UNTIL_NEXT_ROUND_US 100000 // If 0 then DO_DEBUG_PRINT must be 0 // If 0 and 1 below, round trip is some 45-60 us #define TOP_STR "Top_24 interface" // See this at https://www.xcore.com/viewtopic.php?f=26&t=8098 "Is it possible to get a race condition in clean XC on XCore?" #define TOP_24_AS_PARTLY_COMBINED 2 // 0 works. // // 1 builds code for (1 1) wrongly XMOS (added as comment to XMOS ticket #84030 13Mar2021) // // 2 builds code for (1 1) correctly, but discrepancy for 12.5 value XMOS if delays not set accordingly #if (TOP_24_AS_PARTLY_COMBINED == 0) #define CLIENT_DELAY_UNTIL_NEXT_THIRD_US 100 #if (ROOT_DELAY_UNTIL_NEXT_ROUND_US==0) #define CLIENT_DELAY_UNTIL_NEXT_SYNCH_POLL_US 1 // 0 not possible, plus makes little sense #else #define CLIENT_DELAY_UNTIL_NEXT_SYNCH_POLL_US (ROOT_DELAY_UNTIL_NEXT_ROUND_US/10) // high-speed poll is not very interesting #endif // ROOT_DELAY_UNTIL_NEXT_ROUND_US 100000 See "2021 03 17 TOP_24 11.44 not combined synchronized fair.txt" #elif (TOP_24_AS_PARTLY_COMBINED == 1) // Not important, won't build correctly anyhow. // Typically sequence number shows wrong number, and it's NOT the printing. XMOS comment to #84030 // (1 1):S(1036831949) [0.0000] from [0.0000][0.0000][0.0000] #define CLIENT_DELAY_UNTIL_NEXT_THIRD_US 1000 #if (ROOT_DELAY_UNTIL_NEXT_ROUND_US==0) #define CLIENT_DELAY_UNTIL_NEXT_SYNCH_POLL_US 1 // 0 not possible, plus makes little sense #else #define CLIENT_DELAY_UNTIL_NEXT_SYNCH_POLL_US (ROOT_DELAY_UNTIL_NEXT_ROUND_US/10) // high-speed poll is not very interesting #endif #elif (TOP_24_AS_PARTLY_COMBINED == 2) #define CLIENT_DELAY_UNTIL_NEXT_THIRD_US 100 #if (ROOT_DELAY_UNTIL_NEXT_ROUND_US==0) #define CLIENT_DELAY_UNTIL_NEXT_SYNCH_POLL_US 1 // 0 not possible, plus makes little sense #else #define CLIENT_DELAY_UNTIL_NEXT_SYNCH_POLL_US (ROOT_DELAY_UNTIL_NEXT_ROUND_US/10) // high-speed poll is not very interesting #endif #endif #elif (TOPOLOGY == TOP_25_HAS_1_TILE_016_T0_2N_14CN_NOT_CONVERGING) #define NUM_ROWS 4 #define NUM_COLS 4 // CONVERGING_VALUE [5.3273] at (2000) #define ROOT_DELAY_UNTIL_NEXT_ROUND_US 100000 // If 0 then DO_DEBUG_PRINT must be 0 // If 0 and 1 below, round trip is some 45-60 us #define CLIENT_DELAY_UNTIL_NEXT_THIRD_US 10000 #if (ROOT_DELAY_UNTIL_NEXT_ROUND_US==0) #define CLIENT_DELAY_UNTIL_NEXT_SYNCH_POLL_US 1 // 0 not possible, plus makes little sense #else #define CLIENT_DELAY_UNTIL_NEXT_SYNCH_POLL_US (ROOT_DELAY_UNTIL_NEXT_ROUND_US/10) // high-speed poll is not very interesting #endif #define TOP_STR "Top_25" #elif (TOPOLOGY == TOP_26_TESTING_SYNCH_PHASE) #define TOP_26_CONFIG IS_8_BY_8 // IS_2_BY_2, IS_4_BY_4 or IS_8_BY_8 #define TOP_STR "Top_26 4*4" #if (TOP_26_CONFIG == IS_2_BY_2) #define NUM_ROWS 2 #define NUM_COLS 2 #define TOP_26_AS_PARTLY_COMBINED 0 #elif (TOP_26_CONFIG == IS_4_BY_4) #define NUM_ROWS 4 #define NUM_COLS 4 #define TOP_26_AS_PARTLY_COMBINED 1 #elif (TOP_26_CONFIG == IS_8_BY_8) #define NUM_ROWS 8 #define NUM_COLS 8 #define TRANSFORM_ROW_COL 1 #define INIT_NUM_ROWS 4 #define INIT_NUM_COLS 4 #define TOP_26_AS_PARTLY_DISTRUBUTED 1 // 0 or 1, both work. 1 is shown in the Fringe #endif #define ROOT_DELAY_UNTIL_NEXT_ROUND_US 500000 // 0 If 0 then DO_DEBUG_PRINT must be 0 // If 0 and 1 below, round trip is some 38 us #define CLIENT_DELAY_UNTIL_NEXT_THIRD_US 1000 // 0 possible #if (ROOT_DELAY_UNTIL_NEXT_ROUND_US==0) #define CLIENT_DELAY_UNTIL_NEXT_SYNCH_POLL_US 1 // 0 not possible, plus makes little sense #else #define CLIENT_DELAY_UNTIL_NEXT_SYNCH_POLL_US (ROOT_DELAY_UNTIL_NEXT_ROUND_US/10) // high-speed poll is not very interesting #endif // ROOT_DELAY_UNTIL_NEXT_ROUND_US CLIENT_DELAY_UNTIL_NEXT_THIRD_US // 4*4 COMBINED 0 0 Makes 5 equal pulses of 50 ms for 500 ms then stops // 4*4 COMBINED 10 1 Does not run // 4*4 COMBINED 100 1,10,100 Does not run // 4*4 COMBINED 300 0 Stops after some rounds // 4*4 COMBINED 300 1 Runs T=710 us no jitter, but longer than this: // 4*4 COMBINED 300 50 Runs T=616 us no jitter! // 4*4 COMBINED 400 50 Runs T=680 us jitter. same as this: // 4*4 COMBINED 500 50 Runs T=680 us jitter // 4*4 COMBINED 500 100 Runs T=740 us jitter // 4*4 COMBINED 500 100 Runs T=800 us jitter // 4*4 COMBINED 1000 100 Runs T=1.34 ms // 4*4 2*8 0 0 Runs T=28us // 4*4 2*8 1 1 Runs T=30us // 4*4 2*8 10 1 Runs T=47us #else #error Topology not implemented #endif #ifndef TRANSFORM_ROW_COL #define TRANSFORM_ROW_COL 0 #endif /* _______ _ |__ __| | | | | ___ _ __ ___ | | ___ __ _ _ _ ___ ___ _ __ ___ _ __ ___ ___ _ __ | |/ _ \| '_ \ / _ \| |/ _ \ / _` | | | | / __/ _ \| '_ ` _ \| '_ ` _ \ / _ \| '_ \ | | (_) | |_) | (_) | | (_) | (_| | |_| | | (_| (_) | | | | | | | | | | | (_) | | | | |_|\___/| .__/ \___/|_|\___/ \__, |\__, | \___\___/|_| |_| |_|_| |_| |_|\___/|_| |_| | | __/ | __/ | |_| |___/ |___/ */ #if (NUM_COLS < SMALLEST_NUM_COLS) #error #endif #define NUM_PAIRS_PER_ROW (NUM_COLS / NUM_NODES_PER_PAIR) // NUM_ROWS = 1st parameter and 1st component of multi-dim array [rows][][] // NUM_COLS = 2nd parameter and 2nd component of multi-dim array [][cols][] #define DPT_VAL 1.00f // Delta time [sec] // Heat conductance [W/K] = [J/(K*sec)] as conduvert_vals [INIT_NUM_ROWS][INIT_NUM_COLS/2] #define CONDUVERT_VALS_11 { 0.1f} #define CONDUVERT_VALS_12 { 0.1f, 0.2f} #define CONDUVERT_VALS_21 { 0.1f}, { 0.1f} #define CONDUVERT_VALS_22 { 0.1f, 0.2f}, { 0.1f, 0.2f} #define CONDUVERT_VALS_32 { 0.1f, 0.2f}, { 0.1f, 0.2f}, { 0.1f, 0.2f} #define CONDUVERT_VALS_42 { 0.1f, 0.2f}, { 0.1f, 0.2f}, { 0.1f, 0.2f}, { 0.1f, 0.2f} #define CONDUVERT_VALS_82 CONDUVERT_VALS_42,CONDUVERT_VALS_42 // Heat conductance [W/K] = [J/(K*sec)] as condu_vals [INIT_NUM_ROWS][INIT_NUM_COLS]; // New version 11Mar2021 (0.04f to 0.3f) #define CONDU_VALS_12 { 0.2f, 0.3f} #define CONDU_VALS_14 { 0.2f, 0.3f, 0.1f, 0.3f} #define CONDU_VALS_22 { 0.2f, 0.3f}, { 0.2f, 0.3f} #define CONDU_VALS_24 { 0.2f, 0.3f, 0.1f, 0.3f}, { 0.2f, 0.3f, 0.1f, 0.3f} #define CONDU_VALS_34 { 0.2f, 0.3f, 0.1f, 0.3f}, { 0.2f, 0.3f, 0.1f, 0.3f}, { 0.2f, 0.3f, 0.1f, 0.3f} #define CONDU_VALS_44 { 0.2f, 0.3f, 0.1f, 0.3f}, { 0.2f, 0.3f, 0.1f, 0.3f}, { 0.2f, 0.3f, 0.1f, 0.3f}, { 0.2f, 0.3f, 0.1f, 0.3f} #define CONDU_VALS_84 CONDU_VALS_44,CONDU_VALS_44 // Heat capacity [J/K] as heatcap_vals [INIT_NUM_ROWS][INIT_NUM_COLS] #define HEATCAP_VALS_12 {25.0f, 4.0f} #define HEATCAP_VALS_14 {25.0f, 4.0f, 2.0f, 6.25f} #define HEATCAP_VALS_22 {25.0f, 4.0f}, { 5.0f, 4.0f} #define HEATCAP_VALS_24 {25.0f, 4.0f, 2.0f, 6.25f}, { 5.0f, 4.0f, 2.0f, 6.25f} #define HEATCAP_VALS_34 {25.0f, 4.0f, 2.0f, 6.25f}, { 5.0f, 4.0f, 2.0f, 6.25f}, { 5.0f, 4.0f, 2.0f, 6.25f} #define HEATCAP_VALS_44 {25.0f, 4.0f, 2.0f, 6.25f}, { 5.0f, 4.0f, 2.0f, 6.25f}, { 5.0f, 4.0f, 2.0f, 6.25f}, { 5.0f, 4.0f, 2.0f, 6.25f} // HEATCAP_VALS_44 SUM IS 89. CONVERGING_VALUE (19.0*25.0) / 89.0 = 5.337079 degC [5.3371] #define HEATCAP_VALS_84 HEATCAP_VALS_44,HEATCAP_VALS_44 // Temperature [degC] as tempinit_vals [INIT_NUM_ROWS][INIT_NUM_COLS] #define TEMPINIT_VALS_12 {19.0f, 0.0f} #define TEMPINIT_VALS_14 {19.0f, 0.0f, 0.0f, 0.0f} #define TEMPINIT_VALS_22 {19.0f, 0.0f}, { 0.0f, 0.0f} #define TEMPINIT_VALS_24 {19.0f, 0.0f, 0.0f, 0.0f}, { 0.0f, 0.0f, 0.0f, 0.0f} #define TEMPINIT_VALS_34 {19.0f, 0.0f, 0.0f, 0.0f}, { 0.0f, 0.0f, 0.0f, 0.0f}, { 0.0f, 0.0f, 0.0f, 0.0f} #define TEMPINIT_VALS_44 {19.0f, 0.0f, 0.0f, 0.0f}, { 0.0f, 0.0f, 0.0f, 0.0f}, { 0.0f, 0.0f, 0.0f, 0.0f}, { 0.0f, 0.0f, 0.0f, 0.0f} #define TEMPINIT_VALS_84 TEMPINIT_VALS_44,TEMPINIT_VALS_44 #define CALCULATE_WITH_NAIVE_FORMULA 1 // 1 is just summing up values, for testing, no decimals #if ((NUM_ROWS == 1) and (NUM_COLS == 2)) #define CONDUVERT_VALS CONDUVERT_VALS_11 #define CONDU_VALS CONDU_VALS_12 #define HEATCAP_VALS HEATCAP_VALS_12 #define TEMPINIT_VALS TEMPINIT_VALS_12 #elif ((NUM_ROWS == 1) and (NUM_COLS == 4)) #define CONDUVERT_VALS CONDUVERT_VALS_12 #define CONDU_VALS CONDU_VALS_14 #define HEATCAP_VALS HEATCAP_VALS_14 #define TEMPINIT_VALS TEMPINIT_VALS_14 #elif ((NUM_ROWS == 2) and (NUM_COLS == 2)) #define CONDUVERT_VALS CONDUVERT_VALS_21 #define CONDU_VALS CONDU_VALS_22 #define HEATCAP_VALS HEATCAP_VALS_22 #define TEMPINIT_VALS TEMPINIT_VALS_22 #elif ((NUM_ROWS == 2) and (NUM_COLS == 4)) #define CONDUVERT_VALS CONDUVERT_VALS_22 #define CONDU_VALS CONDU_VALS_24 #define HEATCAP_VALS HEATCAP_VALS_24 #define TEMPINIT_VALS TEMPINIT_VALS_24 #elif ((NUM_ROWS == 3) and (NUM_COLS == 4)) #define CONDUVERT_VALS CONDUVERT_VALS_32 #define CONDU_VALS CONDU_VALS_34 #define HEATCAP_VALS HEATCAP_VALS_34 #define TEMPINIT_VALS TEMPINIT_VALS_34 #elif ((NUM_ROWS == 4) and (NUM_COLS == 4)) #define CONDUVERT_VALS CONDUVERT_VALS_42 #define CONDU_VALS CONDU_VALS_44 #define HEATCAP_VALS HEATCAP_VALS_44 #define TEMPINIT_VALS TEMPINIT_VALS_44 #elif ((NUM_ROWS == 8) and (NUM_COLS == 4)) #error not coded #define CONDUVERT_VALS CONDUVERT_VALS_82 #define CONDU_VALS CONDU_VALS_84 #define HEATCAP_VALS HEATCAP_VALS_84 #define TEMPINIT_VALS TEMPINIT_VALS_84 #elif ((NUM_ROWS == 8) and (NUM_COLS == 8)) #define CONDUVERT_VALS CONDUVERT_VALS_42 #define CONDU_VALS CONDU_VALS_44 #define HEATCAP_VALS HEATCAP_VALS_44 #define TEMPINIT_VALS TEMPINIT_VALS_44 #else #error No config data defined #endif #ifndef INIT_NUM_ROWS #define INIT_NUM_ROWS NUM_ROWS #endif #ifndef INIT_NUM_COLS #define INIT_NUM_COLS NUM_COLS #endif /* _____ __ _ _ / ____| / _| | | (_) | | ___ _ __ ___ _ __ ___ ___ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___ | | / _ \| '_ ` _ \| '_ ` _ \ / _ \| '_ \ | _| | | | '_ \ / __| __| |/ _ \| '_ \/ __| | |___| (_) | | | | | | | | | | | (_) | | | | | | | |_| | | | | (__| |_| | (_) | | | \__ \ \_____\___/|_| |_| |_|_| |_| |_|\___/|_| |_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/ */ typedef struct params_t { si_unit_t conduvert_vals [INIT_NUM_ROWS][INIT_NUM_COLS/2]; // For vertical links si_unit_t condu_vals [INIT_NUM_ROWS][INIT_NUM_COLS]; // For links left and right si_unit_t heatcap_vals [INIT_NUM_ROWS][INIT_NUM_COLS]; temp_degC_t tempinit_vals [INIT_NUM_ROWS][INIT_NUM_COLS]; // temp_degC_t dpt_val; } params_t; #if (IS_MYTARGET == IS_MYTARGET_XCORE_200_EXPLORER) #define BOARD_LEDS_INIT 0x00 #define BOARD_LED_MASK_GREEN_ONLY 0x01 // BIT0 J1.7 #define BOARD_LED_MASK_RGB_BLUE 0x02 // BIT1 J1.5 #define BOARD_LED_MASK_RGB_GREEN 0x04 // BIT2 J1.3 #define BOARD_LED_MASK_RGB_RED 0x08 // BIT3 J1.1 #define BOARD_LED_MASK_RGB_ALL (BOARD_LED_MASK_RGB_BLUE bitor BOARD_LED_MASK_RGB_GREEN bitor BOARD_LED_MASK_RGB_RED) #else #error No LED configured #endif #ifndef ROOT_DELAY_UNTIL_NEXT_ROUND_US #define ROOT_DELAY_UNTIL_NEXT_ROUND_US 1000 // Default for all except TOP_08_HAS_1_TILE_016_NODE_T0_2N_AS_CC_6CN_8CN_RUNS #endif #define ROOT_WAIT_FOR_NEXT_ROUND_US (ROOT_DELAY_UNTIL_NEXT_ROUND_US * XS1_TIMER_MHZ) typedef bool all_clients_synched_t; typedef unsigned cycle_cnt_t; typedef struct node_context_t { unsigned iof_row; unsigned iof_col; unsigned my_number; temp_degC_t temps_degC[NUM_CONNS_PER_NODE]; temp_degC_t wt [NUM_CONNS_PER_NODE]; // delta time * heat conductance * thermal inertia. (thermal inertia = 1/heat capacity) (*1) cycle_cnt_t cycle_cnt; } node_context_t; #include "_print_macros_xc.h" unsigned row_col_to_number ( const unsigned iof_row, const unsigned iof_col) { return (1 + ((iof_row * NUM_COLS) + iof_col)); } // =============== // SOME FUNCTIONS // =============== bool is_float_around_12p5 (const float value) { return (value < 12.6f) and (value > 12.4f); } bool is_root ( const unsigned iof_row, const unsigned iof_col) { return ((iof_row==0) and (iof_col==0)); } void init_context ( const unsigned iof_row, const unsigned iof_col, node_context_t &context) { context.iof_row = iof_row; context.iof_col = iof_col; context.cycle_cnt = 0; context.my_number = row_col_to_number (iof_row, iof_col); for (unsigned ix = 0; ix>1]) / params.heatcap_vals[iof_row][iof_col]; PRINT_INIT_WT1_ODD; } else { // even horizontal, base on bottom wt[1] = (params.dpt_val * params.conduvert_vals[(iof_row+INIT_NUM_ROWS-1) % INIT_NUM_ROWS][iof_col>>1]) / params.heatcap_vals[iof_row][iof_col]; PRINT_INIT_WT1_EVEN; } wt[2] = (params.dpt_val * params.condu_vals[iof_row][iof_col]) / params.heatcap_vals[iof_row][iof_col]; // right side is iof_col PRINT_INIT_WT2; PRINT_INIT_WT_SUMMARY; } // init_wt temp_degC_t init_temp ( const iof_pos_t iof_row_, const iof_pos_t iof_col_, const params_t params) { // Read only iof_pos_t iof_row; iof_pos_t iof_col; {iof_row, iof_col} = transform_row_col (iof_row_, iof_col_); #if (CALCULATE_WITH_NAIVE_FORMULA==0) const temp_degC_t return_temp = params.tempinit_vals[iof_row][iof_col]; #elif (CALCULATE_WITH_NAIVE_FORMULA==1) const temp_degC_t return_temp = (temp_degC_t) 1 + (temp_degC_t)((iof_row * NUM_COLS) + iof_col); // For 4*4 -> [1..16] #endif PRINT_INIT_TEMP; return (return_temp); } // init_temp // FUNCTION calculate_new_temp_from_flow // Hard coded based on NUM_CONNS_PER_NODE being 3 // temp_degC_t calculate_new_temp_from_flow ( const node_context_t context, // const and no '&' here, so read only const temp_degC_t tempold) { #if (CALCULATE_WITH_NAIVE_FORMULA==0) const temp_degC_t term1 = context.wt[0] * (context.temps_degC[0]-tempold); const temp_degC_t term2 = context.wt[1] * (context.temps_degC[1]-tempold); const temp_degC_t term3 = context.wt[2] * (context.temps_degC[2]-tempold); const temp_degC_t temp_return = tempold + term1 + term2 + term3; #elif (CALCULATE_WITH_NAIVE_FORMULA==1) // NAIVE SUMMING, JUST FOR TESTING temp_degC_t my_number = (temp_degC_t) 1 + (temp_degC_t)((context.iof_row * NUM_COLS) + context.iof_col); // as init_temp 4*4 -> [1..16] const temp_degC_t term1 = context.temps_degC[0]; const temp_degC_t term2 = context.temps_degC[1]; const temp_degC_t term3 = context.temps_degC[2]; // temp_degC_t temp_formula = my_number + term1 + term2 + term3; // Not using tempold, but too many equal values at the start temp_degC_t temp_formula = term1 + term2 + term3; // Not using tempold, only ading terms if (temp_formula > (temp_degC_t) 99999) { temp_formula = my_number; } else {} const temp_degC_t temp_return = temp_formula; #endif PRINT_CALC_TEMP; return (temp_return); } // calculate_new_temp_from_flow // FUNCTION calculate_new_temp_from_flow // Hard coded based on NUM_CONNS_PER_NODE being 3 // temp_degC_t calculate_temp_times ( const node_context_t context, // const and no '&' here, so read only const temp_degC_t tempold) { #if (CALCULATE_WITH_NAIVE_FORMULA==0) // USED THIS const temp_degC_t term1 = context.wt[0] * (context.temps_degC[0]-tempold); const temp_degC_t term2 = context.wt[1] * (context.temps_degC[1]-tempold); const temp_degC_t term3 = context.wt[2] * (context.temps_degC[2]-tempold); const temp_degC_t temp_return = tempold + term1 + term2 + term3; #elif (CALCULATE_WITH_NAIVE_FORMULA==1) // NAIVE SUMMING, JUST FOR TESTING const temp_degC_t term1 = context.temps_degC[0]; const temp_degC_t term2 = context.temps_degC[1]; const temp_degC_t term3 = context.temps_degC[2]; temp_degC_t temp_formula = tempold + term1 + term2 + term3; if (temp_formula > 99999.0f) { temp_formula = 1.0f + (float)((context.iof_row * NUM_COLS) + context.iof_col); // as init_temp } else {} const temp_degC_t temp_return = temp_formula; #endif PRINT_CALC_TEMP; return (temp_return); } // calculate_new_temp_from_flow #if (IS_MYTARGET == IS_MYTARGET_XCORE_200_EXPLORER) out buffered port:4 outP4_leds = on tile[0]: XS1_PORT_4F; // xCORE-200 explorerKIT GPIO J1 P5, P3, P1. HIGH IS ON // Not used in buffered port:1 inP_button_left = on tile[0]: XS1_PORT_1M; // (*3) GPIO-J1.PIN63 (B1) in buffered port:1 inP_button_center = on tile[0]: XS1_PORT_1N; // (*3) GPIO-J1.PIN61 (B3) in buffered port:1 inP_button_right = on tile[0]: XS1_PORT_1O; // GPIO-J1.PIN59 (B2) #else #error No LED configured #endif #if (TOPOLOGY == TOP_20_HAS_2_TILE_004_T0_2N_BY3SUB_T1_2N_BY3SUB_RUNS_FAIR) // 2*2 chans as occam: works nicely /* _______ ____ _____ ___ ___ |__ __/ __ \| __ \ |__ \ / _ \ | | | | | | |__) | ) | | | | | | | | | | ___/ / /| | | | | | | |__| | | / /_| |_| | |_| \____/|_| |____|\___/ */ #include "top_20_occam_like_xc.h" #elif ((TOPOLOGY == TOP_21_HAS_1_TILE_004_T0_4N_RUNS_FAIR) or /* 2*2 interface: works nicely */ \ (TOPOLOGY == TOP_23_HAS_2_TILE_004_T0_8N_T1_8N_CHANENDS_OVERRUN)) /* 4*4 interface: chanends overrun */ /* _______ ____ _____ ___ __ _ _______ ____ _____ ___ ____ |__ __/ __ \| __ \ |__ \/_ | | | |__ __/ __ \| __ \ |__ \|___ \ | | | | | | |__) | ) || | __ _ _ __ __| | | | | | | | |__) | ) | __) | | | | | | | ___/ / / | | / _` | '_ \ / _` | | | | | | | ___/ / / |__ < | | | |__| | | / /_ | | | (_| | | | | (_| | | | | |__| | | / /_ ___) | |_| \____/|_| |____||_| \__,_|_| |_|\__,_| |_| \____/|_| |____|____/ */ #include "top_21_23_xc.h" #elif (TOPOLOGY == TOP_22_HAS_2_TILE_004_T0_2N_BY2SUB_T1_2N_BY2SUB_VIOLATES_PARALLEL_USAGE_RULES) // 2*2 chans: wrongly used /* _______ ____ _____ ___ ___ |__ __/ __ \| __ \ |__ \|__ \ | | | | | | |__) | ) | ) | | | | | | | ___/ / / / / | | | |__| | | / /_ / /_ |_| \____/|_| |____|____| */ #include "top_22_xc.h" #elif ((TOPOLOGY == TOP_24_HAS_1_TILE_004_T0_2N_2CN_ETC_MAYBE_CONVERGING) or (TOPOLOGY == TOP_25_HAS_1_TILE_016_T0_2N_14CN_NOT_CONVERGING)) // 2*2 interface with synch phase /* _______ ____ _____ ___ _ _ ___ _____ |__ __/ __ \| __ \ |__ \| || | |__ \| ____| | | | | | | |__) | ) | || |_ ) | |__ | | | | | | ___/ / /|__ _| / /|___ \ | | | |__| | | / /_ | | / /_ ___) | |_| \____/|_| |____| |_| |____|____/ */ #include "top_24_25_xc.h" #elif (TOPOLOGY == TOP_26_TESTING_SYNCH_PHASE) /* _______ ____ _____ ___ __ |__ __/ __ \| __ \ |__ \ / / | | | | | | |__) | ) / /_ | | | | | | ___/ / / '_ \ | | | |__| | | / /| (_) | |_| \____/|_| |____\___/ */ #include "top_26_xc.h" #else #if (TOP_WARNINGS==1) // From "makefile" #error CODE MISSING #endif #endif