Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ docs/help/vi/*
docs/help/zh_CN/*
configs/**/*.tbl.bak
configs/**/halshow.preferences
/tests/hm2-modbus/modbus-Params/*.mbccb
/tests/hm2-modbus/modbus-Params/halrun-stderr
/tests/hm2-modbus/modbus-Params/halrun-stdout
94 changes: 92 additions & 2 deletions src/hal/drivers/mesa-hostmot2/hm2_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,97 @@ int rtapi_app_main(void) {
break;
}

/*
7i96 configuration, enough to load pktUart driver.
Use script based on
mesaflash --addr 10.10.10.10 --device 7i96 --rpo 0x0100
to find the memory values.
*/
case 15: {
LL_PRINT("test pattern %d, llio and pattern copy\n", test_pattern);
static const char *hm2_7i96_pin_names[] = {
"TB3-01",
"TB3-02",
"TB3-03",
"TB3-04",
"TB3-05",
"TB3-06",
"TB3-07",
"TB3-08",
"TB3-09",
"TB3-10",
"TB3-11",
"TB3-13/TB3-14",
"TB3-15/TB3-16",
"TB3-17/TB3-18",
"TB3-19/TB3-20",
"TB3-21/TB3-22",
"TB3-23/TB3-24",

"TB1-02/TB1-03",
"TB1-04/TB1-05",
"TB1-08/TB1-09",
"TB1-10/TB1-11",
"TB1-14/TB1-15",
"TB1-16/TB1-17",
"TB1-20/TB1-21",
"TB1-22-TB1-23",

"TB2-02/TB2-03",
"TB2-04/TB2-05",
"TB2-07/TB2-08",
"TB2-10/TB2-11",
"TB2-13/TB2-14",
"TB2-16/TB2-17",
"TB2-18/TB2-19",

"internal", /* SSerial TXEN */
"internal", /* SSR AC Reference pin */

"P1-01/DB25-01", /* P1 parallel expansion */
"P1-02/DB25-14",
"P1-03/DB25-02",
"P1-04/DB25-15",
"P1-05/DB25-03",
"P1-06/DB25-16",
"P1-07/DB25-04",
"P1-08/DB25-17",
"P1-09/DB25-05",
"P1-11/DB25-06",
"P1-13/DB25-07",
"P1-15/DB25-08",
"P1-17/DB25-09",
"P1-19/DB25-10",
"P1-21/DB25-11",
"P1-23/DB25-12",
"P1-25/DB25-13",
};

/*
low level needs setup per board.
Copy this block from hm2_eth.c for your configuration.
*/
//memcpy(llio_name, "7i96", 4);
me->llio.num_ioport_connectors = 3;
me->llio.pins_per_connector = 17;
me->llio.io_connector_pin_names = (char**)hm2_7i96_pin_names;

me->llio.ioport_connector_name[0] = "P1"; // DB25, 17 pins used, IO 34 to IO 50
me->llio.ioport_connector_name[1] = "TB1"; // terminal block, 8 pins used, Step & Dir 0-3
me->llio.ioport_connector_name[2] = "TB2"; // terminal block, 7 pins used, Step & Dir 4, Enc A, B, Z, serial Rx/Tx
me->llio.ioport_connector_name[3] = "TB3"; // terminal block, 11 inputs, 6 SSR outputs

me->llio.fpga_part_number = "6slx9tqg144";
me->llio.num_leds = 4;

/*
Fill memory based on 7i96.
*/
size_t pattern_size = (sizeof(me->test_pattern) > sizeof(config_memory_dump)) ? sizeof(config_memory_dump) : sizeof(me->test_pattern);
(void)memcpy(me->test_pattern.tp8, config_memory_dump, pattern_size);
break;
}

default: {
LL_ERR("unknown test pattern %d", test_pattern);
return -ENODEV;
Expand Down Expand Up @@ -592,5 +683,4 @@ void rtapi_app_exit(void) {

LL_PRINT("driver unloaded\n");
hal_exit(comp_id);
}

}
783 changes: 783 additions & 0 deletions src/hal/drivers/mesa-hostmot2/hm2_test.h

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions tests/hm2-modbus/modbus-Params/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

This is a test of the hm2_modbus driver parameter settings.

Create a fake device using dump_config.sh.
40 changes: 40 additions & 0 deletions tests/hm2-modbus/modbus-Params/dump_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

#
# This script will dump the current configuration memory to the command line.
# Use ./dump_config.sh >> test_pattern15.h to capture your configuration to a file. Replace 7i96 with your firmware name.

# Want to use --rpo from 0x0000 - 0x6100.
#
ADDR=0
#END=0x6100 or decimal 24832

# format output in columns.
COLUMN=0

echo "/*"
echo " Header file containing configuration memory dump."
echo " You may use tests/hm-test/dump_config.sh to create this file."
echo "*/"
echo ""
echo "#pragma once"
echo ""
echo "const uint32_t config_memory_dump[] = {"

while [ $ADDR -lt 24832 ]
do
echo -n "0x"

mesaflash --addr 10.10.10.10 --device 7i96 --rpo $ADDR | tr "\n" ", "

if [ $COLUMN -lt 7 ]; then
COLUMN=$(( $COLUMN + 1 ))
else
COLUMN=0
echo ""
fi

ADDR=$(( $ADDR + 4 ))
done

echo "};"
40 changes: 40 additions & 0 deletions tests/hm2-modbus/modbus-Params/dump_config2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

#
# This script will dump the current configuration memory to the command line.
# Use ./dump_config.sh >> test_pattern15.h to capture your configuration to a file. Replace 7i96 with your firmware name.
# Use ./dump_config.sh >> test_pattern15.b to capture your configuration to a binary file.

# Want to use --rpo from 0x0000 - 0x6100.
#
ADDR=0
#END=0x6100 or decimal 24832

# format output in columns.
COLUMN=0

echo "/*"
echo " Header file containing configuration memory dump."
echo " You may use tests/hm-test/dump_config.sh to create this file."
echo "*/"
echo ""
echo "#pragma once"
echo ""
echo "const uint32_t config_memory_dump[] = {"


while [ $ADDR -lt 24832 ]
do
echo -n "0x"

v=$(mesaflash --addr 10.10.10.10 --device 7i96 --rpo $ADDR)

echo "mesaflash returns $v for $ADDR"
#var_value=$(echo "${arr[3]}" | sed 's/0x0\+//')

print "%u" $ADDR

ADDR=$(( $ADDR + 4 ))
done

echo "};"
17 changes: 17 additions & 0 deletions tests/hm2-modbus/modbus-Params/modbus_test.hal
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# HAL for modbus testing.
#
#loadrt hostmot2 debug_idrom=1 debug_pin_descriptors=1 debug_module_descriptors=1
loadrt hostmot2

#
# Load hm2_test that allows us to run test without physical mesa board or ethernet or RS485.
# TEST_PATTERN goes to the realtime hm2_test component.
#
loadrt hm2_test test_pattern=$(TEST_PATTERN)

#
# Now load the component with the configuration we want to test.
#
loadrt hm2_modbus ports=hm2_test.0.pktuart.0 mbccbs=$(TEST_MBCCB)
show param hm2_modbus.0
124 changes: 124 additions & 0 deletions tests/hm2-modbus/modbus-Params/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/bash

result=0

#
# Test pattern 15 uses a memory dump from a 7i96 as hostmod2 variables.
# This will get replaced using hm_test2_usr for any mesa firmware variables.
#
TEST_PATTERN=15
export TEST_PATTERN
#
# Convert each mbcc source file to binary.
#
for MBCCS in $(ls *.mbccs)
do
MBCCB=$(echo "$MBCCS" | sed 's/mbccs$/mbccb/')
mesambccc -o $MBCCB $MBCCS
done

# First test normal baudrates.
# test0 <mesamodbus baudrate="1200" parity="E" stopbits="1" drivedelay="2" duplex="half" suspend="false" >
# test1 <mesamodbus baudrate="19200" parity="O" stopbits="1" duplex="half" suspend="false" >
# test2 <mesamodbus baudrate="38400" parity="N" stopbits="2" duplex="half" suspend="false" >
# test3 <mesamodbus baudrate="115200" parity="E" stopbits="1" duplex="half" suspend="false" >
# test4 <mesamodbus baudrate="1000000" parity="E" stopbits="1" duplex="half" suspend="false" >
#
# Override icdelay.
#
# test5
#
echo "hm2_modbus delay test." >> halrun-stdout
#
# Run HAL with each test .mbccb
#
for MBCCB in $(ls *.mbccb)
do
echo
echo "Processing file: $MBCCB" > halrun-stdout
TEST_MBCCB=$MBCCB
export TEST_MBCCB

halrun -f modbus_test.hal >halrun-stdout 2>halrun-stderr

arr=($(grep "hm2_modbus.0.baudrate" halrun-stdout))
baudrate=$(echo "${arr[3]}" | sed 's/0x0\+/0/')
baudrate=$((16#$baudrate))
echo " baudrate = $baudrate"

arr=($(grep "hm2_modbus.0.drivedelay" halrun-stdout))
drivedelay=$(echo "${arr[3]}" | sed 's/0x0\+/0/')
drivedelay=$((16#$drivedelay))
echo " drivedelay = $drivedelay"

arr=($(grep "hm2_modbus.0.icdelay" halrun-stdout))
icdelay=$(echo "${arr[3]}" | sed 's/0x0\+/0/')
icdelay=$((16#$icdelay))
echo " icdelay = $icdelay"

arr=($(grep "hm2_modbus.0.parity" halrun-stdout))
parity=$(echo "${arr[3]}" | sed 's/0x0\+/0/')
parity=$((16#$parity))
echo " parity = $parity"

arr=($(grep "hm2_modbus.0.rxdelay" halrun-stdout))
rxdelay=$(echo "${arr[3]}" | sed 's/0x0\+/0/')
rxdelay=$((16#$rxdelay))
echo " rxdelay = $rxdelay"

arr=($(grep "hm2_modbus.0.stopbits" halrun-stdout))
stopbits=$(echo "${arr[3]}" | sed 's/0x0\+/0/')
stopbits=$((16#$stopbits))
echo " stopbits = $stopbits"

arr=($(grep "hm2_modbus.0.txdelay" halrun-stdout))
txdelay=$(echo "${arr[3]}" | sed 's/0x0\+/0/')
txdelay=$((16#$txdelay))
echo " txdelay = $txdelay"

#
# Now test values (alternate calculation as independent check).
#
if [ $baudrate -gt 19200 ]; then
#
# Calculate based on bits within 1750usec at this baudrate.
#
let "if_delay_predicted = ($baudrate * 7 + 3999)/4000"
# echo "1750usec worth of bits." > halrun-stdout
#
# hm2_modbus enforces obscure pktuart limitations inside the calc_if()
#
if [ $if_delay_predicted -gt 1120 ]; then
echo "Enforce pktuart limitation at the modbus level." > halrun-stdout
let "if_delay_predicted = 1020"
fi
else
#
# Calculate based on bpc.
#
if [ $parity -eq 0 ]; then
# Parity - None
let "bpc = (1 + 8) + $stopbits"
else
# Parity - Even or odd has one bit.
let "bpc = (1 + 8 + 1) + $stopbits"
fi
let "if_delay_predicted = (bpc * 7 + 1)/2"
# echo "3.5 chars worth of bits." > halrun-stdout
fi

let "delay_predicted = $if_delay_predicted - 1"
if [ $delay_predicted -ne $rxdelay ]; then
echo "ERROR rxdelay! predicted $delay_predicted vs $rxdelay"
let "result = $result + 1"
fi
let "delay_predicted = $if_delay_predicted + 1"
if [ $delay_predicted -ne $txdelay ]; then
echo "ERROR txdelay! predicted $delay_predicted vs $txdelay"
let "result = $result + 1"
fi
done

echo "Number of errors $result"

exit $result
20 changes: 20 additions & 0 deletions tests/hm2-modbus/modbus-Params/test0.mbccs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--
Use following line to compile this file:
mesambccc -o filename.mbccb filename.mbccs

This file is used for testing initialized hm2_modbus params.
-->

<mesamodbus baudrate="1200" parity="E" stopbits="1" drivedelay="2" duplex="half" suspend="false" >
<devices>
<device name="vfd" address="0x01"/>
</devices>

<initlist>
</initlist>

<commands>
<command device="vfd" address= "105" function="R_REGISTERS" name="max-set-speed" haltype="HAL_FLOAT" modbustype="U_AB" count="1" interval="once"/>
<command device="vfd" address= "117" function="W_REGISTERS" name="ref-coarse" haltype="HAL_FLOAT" modbustype="S_AB" count="1"/>
</commands>
</mesamodbus>
20 changes: 20 additions & 0 deletions tests/hm2-modbus/modbus-Params/test1.mbccs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--
Use following line to compile this file:
mesambccc -o filename.mbccb filename.mbccs

This file is used for testing initialized hm2_modbus params.
-->

<mesamodbus baudrate="19200" parity="O" stopbits="1" duplex="half" suspend="false" >
<devices>
<device name="vfd" address="0x01"/>
</devices>

<initlist>
</initlist>

<commands>
<command device="vfd" address= "105" function="R_REGISTERS" name="max-set-speed" haltype="HAL_FLOAT" modbustype="U_AB" count="1" interval="once"/>
<command device="vfd" address= "117" function="W_REGISTERS" name="ref-coarse" haltype="HAL_FLOAT" modbustype="S_AB" count="1"/>
</commands>
</mesamodbus>
Loading
Loading