summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6ed3436)
raw | patch | inline | side by side (parent: 6ed3436)
author | Brad Griffis <bgriffis@ti.com> | |
Fri, 16 Aug 2019 03:42:09 +0000 (22:42 -0500) | ||
committer | Brad Griffis <bgriffis@ti.com> | |
Fri, 16 Aug 2019 03:42:09 +0000 (22:42 -0500) |
padconf/am65xx-padconf-decoder.py | [new file with mode: 0755] | patch | blob |
diff --git a/padconf/am65xx-padconf-decoder.py b/padconf/am65xx-padconf-decoder.py
--- /dev/null
@@ -0,0 +1,133 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2019, Texas Instruments Incorporated
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# * Neither the name of Texas Instruments Incorporated nor the names of
+# its contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+import xml.etree.ElementTree as ET
+import re
+import sys
+
+if len(sys.argv) != 2:
+ print # Empty line
+ print sys.argv[0], "help:\n"
+ print "Please pass the rd1 file to this script, e.g.:"
+ print "", sys.argv[0], "am65xx-padconf_yyyy-mm-dd_hhmmss.rd1\n"
+ print("Output file will have same base name as input, "
+ "but csv file type.\n")
+ sys.exit(1)
+
+try:
+ rd1 = open(sys.argv[1], "rt")
+except IOError:
+ print "Error: input file", sys.argv[1], "not accessible."
+ sys.exit(1)
+
+try:
+ csv_filename = sys.argv[1]
+ csv_filename = csv_filename.replace(".rd1", ".csv")
+ csv = open(csv_filename, "w+")
+except IOError:
+ print "Error creating file", csv_filename
+ sys.exit(1)
+
+# CSV files must use \r\n for all line endings
+# Create header row
+csv.write("Reg Name, Reg Address, Reg Value, Mux Mode\r\n")
+csv_string = "%s, 0x%08X, 0x%08X, %s\r\n"
+# csv.write("Reg Name, Reg Address, Reg Value, LOCK, WKUP_EVT, WKUP_EN, "
+ # "DS0 Pull, DS0 Output, ISO_BYP, ISO_OVR, TX_DIS, "
+ # "SLEWRATE, RXACTIVE, Pull, FORCE_DS_EN, MUXMODE, Comments\r\n")
+# csv_string = "%s, 0x%08X, 0x%08X, %s, %s, %s, "
+ # "%s, %s, %d, %s, %s, "
+ # "%s, %s, %s, %s, %s, %s\r\n"
+
+# Determine device family based on header
+header = rd1.readline()
+m = re.match(r'.*AM(65)xx.*', header, 0)
+if m:
+ family = int(m.group(1))
+else:
+ print "Unrecognized device family in header:"
+ print header
+ sys.exit(1)
+
+if family == 65:
+ tree = ET.parse('AM654x_Pin_Mux.xml')
+else:
+ print "Didn't recognize device family AM%d" % family
+ print header
+ sys.exit(1)
+
+root = tree.getroot()
+
+mySearchExpression = "./register[@offset=\'0x%X\']"
+mySearchExpression2 = "./bitenum[@value=\'%d\']"
+
+for lines in rd1:
+ # Use regular expression to extract address and data from rd1
+ m = re.match(r'(0x[0-9a-fA-F]{8})\s+(0x[0-9a-fA-F]{8})', lines, 0)
+ if m:
+ alphanum1 = m.group(1) # address (string)
+ alphanum2 = m.group(2) # data (string)
+ address = int(alphanum1, 16) # convert from string to number
+ register_value = int(alphanum2, 16) # convert from string
+ comments = "" # Start new for each line
+
+ # Derive Register Name
+ if ((address & 0xFFFF0000) == 0x43010000):
+ myregister_name = "CTRLMMR_WKUP_PADCONFIG"
+ register_number = (address - 0x4301C000) >> 2
+ myregister_name += "%d" % register_number
+ elif ((address & 0xFFFF0000) == 0x00110000):
+ myregister_name = "CTRLMMR_PADCONFIG"
+ register_number = (address - 0x0011C000) >> 2
+ myregister_name += "%d" % register_number
+ else:
+ print "Unexpected device address: 0x%08X" % address
+ sys.exit(1)
+
+ muxmode = register_value & 0xF
+ for clockNode_node in root.findall("./clockNode"):
+ register_text = clockNode_node.find("./type/pad/confregisters/regbit/register").text
+ if (register_text == myregister_name):
+ for muxmode_node in clockNode_node.findall("./type/pad/muxmode"):
+ muxmode_text = muxmode_node.find("./mode").text
+ if (muxmode_text != "Bootstrap"):
+ muxmode_int = int(muxmode_text)
+ if (muxmode_int == muxmode):
+ mux_mode_descr = muxmode_node.find("./signal").text
+
+ # Write a line of the CSV file
+ csv.write(csv_string % (myregister_name, address,
+ register_value, mux_mode_descr))
+
+rd1.close()
+csv.close()