Skip to content

Commit

Permalink
Merge branch 'dev_zynqmon_path' of github.com:apollo-lhc/cm_mcu into …
Browse files Browse the repository at this point in the history
…dev_zynqmon_path
  • Loading branch information
pkotamnives committed Nov 1, 2023
2 parents ff48a06 + ad6d5aa commit 77ff48f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ c_cpp_properties.json
.cache
/.metadata/
projects/cm_mcu/ZynqMon_addresses.c
projects/cm_mcu/ZynqMon_addresses.h
17 changes: 10 additions & 7 deletions projects/cm_mcu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ all: ${COMPILER}/cm_mcu.axf
# The rule to clean out all the build products.
#
clean:
@rm -rf ${COMPILER} ${wildcard *~} ZynqMon_addresses.c
@rm -rf ${COMPILER} ${wildcard *~} ZynqMon_addresses.c ZynqMon_addresses.h

#
# The rule to create the target directory.
Expand All @@ -91,13 +91,16 @@ ${COMPILER}:
@mkdir -p ${COMPILER}


## Zynq address table
## Zynq address table -- MCU code
YAML_FILES=$(wildcard ${ROOT}/sm_cm_config/data/*.yml)
ZynqMon_addresses.c: ${YAML_FILES}
python ${ROOT}/sm_cm_config/src/mcu_generate.py -v -o $@ ${YAML_FILES}
#python ${ROOT}/sm_cm_config/src/xml_generate.py
ZynqMon_addresses.c ZynqMon_addresses.h &: ${YAML_FILES}
python ${ROOT}/sm_cm_config/src/mcu_generate.py -o $@ ${YAML_FILES}

ZynqMon_addresses.o: ZynqMon_addresses.c
# these rules are required to force the generation of the ZynqMon_addresses.c
# and .h file. The second one depends on the .h file only, but putting that
# in as a target causes the rule above to be called 2x. So we lie to make.
${COMPILER}/ZynqMon_addresses.o: ZynqMon_addresses.c
${COMPILER}/ZynqMonTask.o: ZynqMon_addresses.c
#
# Rules for building the project
#
Expand Down Expand Up @@ -131,8 +134,8 @@ ${COMPILER}/cm_mcu.axf: ${COMPILER}/GenericAlarmTask.o
${COMPILER}/cm_mcu.axf: ${COMPILER}/AlarmUtilities.o
${COMPILER}/cm_mcu.axf: ${COMPILER}/LedTask.o
${COMPILER}/cm_mcu.axf: ${COMPILER}/microrl.o
${COMPILER}/cm_mcu.axf: ${COMPILER}/ZynqMonTask.o
${COMPILER}/cm_mcu.axf: ${COMPILER}/ZynqMon_addresses.o
${COMPILER}/cm_mcu.axf: ${COMPILER}/ZynqMonTask.o
${COMPILER}/cm_mcu.axf: ${COMPILER}/InterruptHandlers.o
${COMPILER}/cm_mcu.axf: ${COMPILER}/InitTask.o
${COMPILER}/cm_mcu.axf: ${COMPILER}/WatchdogTask.o
Expand Down
8 changes: 2 additions & 6 deletions projects/cm_mcu/ZynqMonTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "clocksynth.h"
#include "common/log.h"

#include "ZynqMon_addresses.h"

// Rev 2
// this needs to be split into a SoftUART version (Rev1) and a hard UART version (Rev2)

Expand Down Expand Up @@ -519,12 +521,6 @@ void zm_set_fpga(struct zynqmon_data_t data[], int start)
}
}

#ifdef REV1
#define ZMON_VALID_ENTRIES 126
#elif defined REV2
#define ZMON_VALID_ENTRIES 233
#endif

void zm_send_data(struct zynqmon_data_t data[])
{
// https://docs.google.com/spreadsheets/d/1E-JD7sRUnkbXNqfgCUgriTZWfCXark6IN9ir_9b362M/edit#gid=0
Expand Down
66 changes: 52 additions & 14 deletions sm_cm_config/src/mcu_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
import sys
import argparse
import subprocess

import yaml

parser = argparse.ArgumentParser(description='Process YAML for MCU.')
Expand All @@ -18,14 +20,19 @@
if args.output:
print('Output file name:', args.output)

#sort the input file names.Default appears to be random(or order in the filesystem)
# sort the input file names.Default appears to be random(or order in the filesystem)
args.input_files.sort()

if args.verbose:
#pretty - print list of input files
# pretty - print list of input files
print('Input file names:', *args.input_files, sep=', ', end='\n')

#open output text file for writing
# header output file -- same as output file with .h extension
header_fname = args.output.replace('.c', '.h')

ZMON_VALID_ENTRIES=[]

# open output c source file for writing
with open(args.output, 'w', encoding="ascii") as fout:
print(r"// This file is generated by mcu_generate.py", file=fout)
print(r"// Do not edit this file directly", file=fout)
Expand All @@ -36,8 +43,10 @@
print(r"// and the C calls to initialize the zynqmon data", file=fout)
print(r"//", file=fout)
print("#include \"Tasks.h\"", file=fout)
# include the header file we will write later
print(f"#include \"{header_fname}\"", file=fout)

#first set the #ifdef for REV1
# first set the #ifdef for REV1
print(r"#ifdef REV1", file=fout)
for idx, fname in enumerate(args.input_files):
if args.verbose:
Expand All @@ -49,7 +58,7 @@
print(f"#elif defined(REV{ver}) // REV{ver}", file=fout)
print("void zm_fill_structs(void) \n{", file=fout)

#print the names of the variables
# print the names of the variables
if args.verbose:
print(f"dump variables for iteration {idx}")
config = data['config']
Expand All @@ -60,7 +69,7 @@
pairs = []
size = 0
for c in config:
#generate C call
# generate C call
expected_length = len(c['names'])
if 'postfixes' in c:
expected_length *= len(c['postfixes'])
Expand All @@ -74,7 +83,7 @@
print(f"// mismatch: {expected_length}, size {c['count']}", file=fout)
print(f"Mismatch in size for {c['name']}, file {fname}")
print(f"Mismatch: expected: {expected_length}, size {c['count']}")
#close and delete the output file before exiting
# close and delete the output file before exiting
fout.close()
os.remove(args.output)
sys.exit(1)
Expand All @@ -87,8 +96,8 @@
size += int(expected_length)
pairs.append((c['start'], c['start'] + int(expected_length)-1))

#check to ensure that none of the tuples in pairs overlap
#this is a sanity check to ensure that the yaml file is correct
# check to ensure that none of the tuples in pairs overlap
# this is a sanity check to ensure that the yaml file is correct
errors=False
for a, b in zip(pairs, pairs[1:]):
if a[0] <= b[0] and a[1] >= b[0] or a[0] <= b[1] and a[1] >= b[1]:
Expand All @@ -97,13 +106,42 @@
if errors:
print("ERRORS FOUND")
sys.exit(1)
#close input yaml file
# close input yaml file
f.close()
print("}", file=fout)
print(f"#define ZMON_VALID_ENTRIES {size}", file=fout)
#close output text file
ZMON_VALID_ENTRIES.append(size)
# end of loop over input files
print(r"#else // REV1", file=fout)
#error if no revision is defined
# error if no revision is defined
print(r"#error No revision defined", file=fout)
print(r"#endif // REV1", file=fout)
fout.close()

# reformat the c file using clang-format
# -style=file:$HOME/src/apollo_cm_mcu/.clang-format
r = subprocess.run(["clang-format", "-i", args.output], check=False)
if r.returncode != 0:
print('clang-format failed')
sys.exit(1)
if args.verbose:
print('clang-format complete')

# open output header file for writing.
# first chekc that ZM_VALID_ENTRIES has exactly two entries
if len(ZMON_VALID_ENTRIES) != 2:
print(f"ERROR: ZM_VALID_ENTRIES has the wrong number of entries: {len(ZMON_VALID_ENTRIES)}")
sys.exit(1)

with open(header_fname, encoding="ascii", mode='w') as fheader:
print(r"// This file is generated by mcu_generate.py", file=fheader)
print(r"// Do not edit this file directly", file=fheader)
print(r"// Edit the yaml files in the data directory and run mcu_generate.py", file=fheader)
print(r"// to generate this file", file=fheader)
print(r"//", file=fheader)
print("#ifndef ZYNQMON_ADDRESSES_H", file=fheader)
print("#define ZYNQMON_ADDRESSES_H", file=fheader)
print("#ifdef REV1", file=fheader)
print(f"#define ZMON_VALID_ENTRIES {ZMON_VALID_ENTRIES[0]}", file=fheader)
print("#elif defined(REV2)", file=fheader)
print(f"#define ZMON_VALID_ENTRIES {ZMON_VALID_ENTRIES[1]}", file=fheader)
print("#endif // REV1", file=fheader)
print("#endif // ZYNQMON_ADDRESSES_H", file=fheader)

0 comments on commit 77ff48f

Please sign in to comment.