2017-02-26 01:54:16 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
comps = []
|
|
|
|
|
2017-02-26 20:41:24 +00:00
|
|
|
header = open(sys.argv[1] + '/inc/hal_tbl.h', 'w')
|
|
|
|
code = open(sys.argv[1] + '/src/hal_tbl.c', 'w')
|
2017-02-26 04:21:48 +00:00
|
|
|
|
|
|
|
for infile in sys.argv[2:]:
|
2017-02-26 01:54:16 +00:00
|
|
|
with open(infile) as f:
|
|
|
|
pins = []
|
|
|
|
compname = ''
|
|
|
|
for line in f:
|
2017-04-12 02:05:46 +00:00
|
|
|
comp = re.search('COMP\((\w*)\);', line)
|
2017-02-26 01:54:16 +00:00
|
|
|
if comp:
|
|
|
|
compname = comp.groups()[0]
|
2017-04-12 02:05:46 +00:00
|
|
|
pin = re.search('HAL_PIN\((\w*)\)', line)
|
2017-02-26 01:54:16 +00:00
|
|
|
if pin:
|
2017-03-06 02:14:56 +00:00
|
|
|
pins.append((pin.groups()[0], int(1)))
|
2017-04-12 02:05:46 +00:00
|
|
|
pin = re.search('HAL_PINA\((\w*),\s*(\d*)\)', line)
|
2017-03-06 02:14:56 +00:00
|
|
|
if pin:
|
|
|
|
pins.append((pin.groups()[0], int(pin.groups()[1])))
|
2017-04-12 02:05:46 +00:00
|
|
|
comps.append((compname, pins, infile))
|
2017-02-26 01:54:16 +00:00
|
|
|
|
2017-02-26 04:21:48 +00:00
|
|
|
header.write("#pragma once\n")
|
2017-02-26 20:41:24 +00:00
|
|
|
header.write("//generated by " + sys.argv[0] + " DO NOT EDIT\n\n")
|
2017-02-26 01:54:16 +00:00
|
|
|
|
2017-04-20 00:31:36 +00:00
|
|
|
header.write("struct pin_ctx_t{\n")
|
|
|
|
header.write(" hal_pin_inst_t rt_prio;\n")
|
|
|
|
header.write(" hal_pin_inst_t frt_prio;\n")
|
2017-06-03 00:33:52 +00:00
|
|
|
# header.write(" hal_pin_inst_t rt_calc_time;\n")
|
|
|
|
# header.write(" hal_pin_inst_t rt_start_time;\n")
|
|
|
|
# header.write(" hal_pin_inst_t frt_calc_time;\n")
|
|
|
|
# header.write(" hal_pin_inst_t frt_start_time;\n")
|
|
|
|
# header.write(" hal_pin_inst_t nrt_calc_time;\n")
|
|
|
|
# header.write(" hal_pin_inst_t nrt_start_time;\n")
|
2017-06-02 18:44:50 +00:00
|
|
|
|
2017-04-20 00:31:36 +00:00
|
|
|
header.write("};\n\n")
|
|
|
|
|
2017-04-12 02:05:46 +00:00
|
|
|
for comp_name, pins, file_name in comps:
|
|
|
|
header.write("struct " + comp_name + "_pin_ctx_t{ // found in " + file_name + "\n")
|
2017-03-06 02:14:56 +00:00
|
|
|
header.write(" hal_pin_inst_t rt_prio;\n")
|
|
|
|
header.write(" hal_pin_inst_t frt_prio;\n")
|
2017-06-03 00:33:52 +00:00
|
|
|
# header.write(" hal_pin_inst_t rt_calc_time;\n")
|
|
|
|
# header.write(" hal_pin_inst_t rt_start_time;\n")
|
|
|
|
# header.write(" hal_pin_inst_t frt_calc_time;\n")
|
|
|
|
# header.write(" hal_pin_inst_t frt_start_time;\n")
|
|
|
|
# header.write(" hal_pin_inst_t nrt_calc_time;\n")
|
|
|
|
# header.write(" hal_pin_inst_t nrt_start_time;\n")
|
2017-04-20 00:31:36 +00:00
|
|
|
|
|
|
|
for (p, i) in pins:
|
|
|
|
if i > 1:
|
|
|
|
header.write(" hal_pin_inst_t " + p + "[" + str(i) + "]" + ";\n")
|
|
|
|
else:
|
|
|
|
header.write(" hal_pin_inst_t " + p + ";\n")
|
2017-02-26 20:41:24 +00:00
|
|
|
header.write("};\n\n")
|
2017-04-20 00:31:36 +00:00
|
|
|
|
2017-04-12 02:05:46 +00:00
|
|
|
header.write("extern const hal_comp_t * comps[];\n")
|
|
|
|
header.write("extern const pin_t pins[];\n")
|
2017-02-26 20:41:24 +00:00
|
|
|
header.write("extern const uint32_t comp_count;\n")
|
|
|
|
header.write("extern const uint32_t pin_count;\n\n")
|
2017-02-26 01:54:16 +00:00
|
|
|
|
2017-04-12 02:05:46 +00:00
|
|
|
for comp_name, pins, file_name in comps:
|
|
|
|
header.write("extern const hal_comp_t " + comp_name + "_comp_struct; // found in " + file_name + "\n")
|
2017-02-26 20:41:24 +00:00
|
|
|
|
2017-02-26 04:21:48 +00:00
|
|
|
|
2017-04-12 02:05:46 +00:00
|
|
|
code.write("#include \"hal.h\"\n")
|
2017-02-26 20:41:24 +00:00
|
|
|
code.write("//generated by " + sys.argv[0] + " DO NOT EDIT\n\n")
|
2017-04-12 02:05:46 +00:00
|
|
|
code.write("const hal_comp_t * comps[] = {\n")
|
|
|
|
for comp_name, pins, file_name in comps:
|
|
|
|
code.write(" &" + comp_name + "_comp_struct, // found in " + file_name + "\n")
|
2017-02-26 20:41:24 +00:00
|
|
|
code.write("};\n\n")
|
2017-02-26 04:21:48 +00:00
|
|
|
code.write("const uint32_t comp_count = sizeof(comps) / sizeof(comps[0]);\n\n")
|
2017-02-26 01:54:16 +00:00
|
|
|
|
2017-04-12 02:05:46 +00:00
|
|
|
code.write("const pin_t pins[] = {\n")
|
|
|
|
for comp_name, pins, file_name in comps:
|
|
|
|
code.write(" // pins for comp " + comp_name + " found in " + file_name + "\n")
|
2017-04-20 00:31:36 +00:00
|
|
|
code.write(" \"rt_prio\",\n")
|
|
|
|
code.write(" \"frt_prio\",\n")
|
2017-06-03 00:33:52 +00:00
|
|
|
# code.write(" \"rt_calc_time\",\n")
|
|
|
|
# code.write(" \"rt_start_time\",\n")
|
|
|
|
# code.write(" \"frt_calc_time\",\n")
|
|
|
|
# code.write(" \"frt_start_time\",\n")
|
|
|
|
# code.write(" \"nrt_calc_time\",\n")
|
|
|
|
# code.write(" \"nrt_start_time\",\n")
|
2017-04-20 00:31:36 +00:00
|
|
|
|
2017-04-12 02:05:46 +00:00
|
|
|
for (p, i) in pins:
|
2017-03-06 02:14:56 +00:00
|
|
|
if i > 1:
|
|
|
|
for j in range(i):
|
|
|
|
code.write(" \"" + p + str(j) + "\",\n")
|
|
|
|
else:
|
|
|
|
code.write(" \"" + p + "\",\n")
|
2017-04-20 00:31:36 +00:00
|
|
|
|
2017-02-26 20:41:24 +00:00
|
|
|
code.write("};\n\n")
|
2017-02-26 04:21:48 +00:00
|
|
|
code.write("const uint32_t pin_count = sizeof(pins) / sizeof(pins[0]);\n\n")
|
2017-02-26 01:54:16 +00:00
|
|
|
|
2017-02-26 04:21:48 +00:00
|
|
|
header.close()
|
2017-02-26 20:41:24 +00:00
|
|
|
code.close()
|