Also init calibration variables in the calibration init function
Change-Id: I777590427fb4e15c7a61f45313f120c089c28315
This commit is contained in:
parent
abc94d70d2
commit
dce0d1910b
powertrain_build/zone_controller
test_data/zone_controller/test_composition_yaml
tests/zone_controller
@ -10,6 +10,7 @@ from powertrain_build.problem_logger import ProblemLogger
|
||||
class ZoneControllerCalibration(ProblemLogger):
|
||||
"""Class for handling ZoneController calibration."""
|
||||
|
||||
calibration_function_init_template = '{swc_name}_ZcCalibrationInit'
|
||||
calibration_function_step_template = '{swc_name}_ZcCalibrationStep'
|
||||
trigger_read_rte_cdata_signal = {
|
||||
'name_template': 'c{swc_name}_TriggerReadRteCData',
|
||||
@ -44,6 +45,62 @@ class ZoneControllerCalibration(ProblemLogger):
|
||||
header_guard_tmp = Path(self.calibration_interface_header).stem
|
||||
return header_guard_tmp.upper() + '_H'
|
||||
|
||||
def _get_calibration_variables_write_string_list(self, indent=4):
|
||||
write_string_list = []
|
||||
for signal_name, signal_data in self.calibration_variables.items():
|
||||
rte_call = f'Rte_CData_{self.swc_name}_{signal_name}()'
|
||||
if isinstance(signal_data["width"], list):
|
||||
write_string_list.append(f'{"":{indent}}memcpy({signal_name}, {rte_call}, sizeof({signal_name}));\n')
|
||||
else:
|
||||
write_string_list.append(f'{"":{indent}}{signal_name} = {rte_call};\n')
|
||||
return write_string_list
|
||||
|
||||
def _get_source_file_init_content(self):
|
||||
header = [
|
||||
f'#define {self.swc_name}_START_SEC_CODE\n',
|
||||
f'#include "{self.swc_name}_MemMap.h"\n',
|
||||
]
|
||||
|
||||
body = [
|
||||
f'void {self.calibration_function_init_template.format(swc_name=self.swc_name)}(void)\n',
|
||||
'{\n',
|
||||
]
|
||||
body.extend(self._get_calibration_variables_write_string_list())
|
||||
body.append('}\n')
|
||||
|
||||
footer = [
|
||||
f'#define {self.swc_name}_STOP_SEC_CODE\n',
|
||||
f'#include "{self.swc_name}_MemMap.h"\n',
|
||||
'\n'
|
||||
]
|
||||
|
||||
return header + body + footer
|
||||
|
||||
def _get_source_file_step_content(self):
|
||||
trigger_read_calibration_function = f'Rte_CData_{self.swc_name}_{self.trigger_read_rte_cdata_signal_name}()'
|
||||
|
||||
header = [
|
||||
f'#define {self.swc_name}_START_SEC_CODE\n',
|
||||
f'#include "{self.swc_name}_MemMap.h"\n'
|
||||
]
|
||||
|
||||
body = [
|
||||
f'void {self.calibration_function_step_template.format(swc_name=self.swc_name)}(void)\n',
|
||||
'{\n',
|
||||
f' if ({self.trigger_read_rte_cdata_signal_name} != {trigger_read_calibration_function})\n'
|
||||
]
|
||||
body.append(' {\n')
|
||||
body.extend(self._get_calibration_variables_write_string_list(indent=8))
|
||||
body.append(' }\n')
|
||||
body.append('}\n')
|
||||
|
||||
footer = [
|
||||
f'#define {self.swc_name}_STOP_SEC_CODE\n',
|
||||
f'#include "{self.swc_name}_MemMap.h"\n'
|
||||
]
|
||||
|
||||
return header + body + footer
|
||||
|
||||
def get_header_file_content(self):
|
||||
"""Get content for the calibration header file.
|
||||
|
||||
@ -98,6 +155,7 @@ class ZoneControllerCalibration(ProblemLogger):
|
||||
|
||||
lines_to_write.extend([
|
||||
'\n',
|
||||
f'void {self.calibration_function_init_template.format(swc_name=self.swc_name)}(void);\n',
|
||||
f'void {self.calibration_function_step_template.format(swc_name=self.swc_name)}(void);\n'
|
||||
])
|
||||
|
||||
@ -109,8 +167,6 @@ class ZoneControllerCalibration(ProblemLogger):
|
||||
Returns:
|
||||
(list(str)): List of lines to write to calibration source file.
|
||||
"""
|
||||
trigger_read_calibration_function = f'Rte_CData_{self.swc_name}_{self.trigger_read_rte_cdata_signal_name}()'
|
||||
|
||||
header = [
|
||||
f'#include "{self.calibration_interface_header}"\n',
|
||||
'\n',
|
||||
@ -121,28 +177,12 @@ class ZoneControllerCalibration(ProblemLogger):
|
||||
f'#define {self.swc_name}_STOP_SEC_VCC_CAL\n',
|
||||
f'#include "{self.swc_name}_MemMap.h"\n',
|
||||
'\n',
|
||||
f'#define {self.swc_name}_START_SEC_CODE\n',
|
||||
f'#include "{self.swc_name}_MemMap.h"\n',
|
||||
f'void {self.calibration_function_step_template.format(swc_name=self.swc_name)}(void)\n{{\n'
|
||||
]
|
||||
|
||||
body = [f' if ({self.trigger_read_rte_cdata_signal_name} != {trigger_read_calibration_function})\n']
|
||||
body.append(' {\n')
|
||||
for signal_name, signal_data in self.calibration_variables.items():
|
||||
if isinstance(signal_data["width"], list):
|
||||
rte_call = f'Rte_CData_{self.swc_name}_{signal_name}()'
|
||||
body.append(f' memcpy({signal_name}, {rte_call}, sizeof({signal_name}));\n')
|
||||
else:
|
||||
body.append(f' {signal_name} = Rte_CData_{self.swc_name}_{signal_name}();\n')
|
||||
body.append(' }\n')
|
||||
body = self._get_source_file_init_content()
|
||||
body.extend(self._get_source_file_step_content())
|
||||
|
||||
footer = [
|
||||
'}\n',
|
||||
f'#define {self.swc_name}_STOP_SEC_CODE\n',
|
||||
f'#include "{self.swc_name}_MemMap.h"\n'
|
||||
]
|
||||
|
||||
return header + body + footer
|
||||
return header + body
|
||||
|
||||
def generate_calibration_interface_files(self):
|
||||
"""Generate calibration interface files."""
|
||||
|
@ -476,12 +476,10 @@ class CompositionYaml(ProblemLogger):
|
||||
swc_content = {init_function: {"type": "INIT", "accesses": calibration_variables}}
|
||||
|
||||
if self.build_cfg.get_code_generation_config(item="generateCalibrationInterfaceFiles"):
|
||||
cal_init_function = autosar_prefix + ZCC.calibration_function_init_template.format(swc_name=swc_name)
|
||||
cal_step_function = autosar_prefix + ZCC.calibration_function_step_template.format(swc_name=swc_name)
|
||||
swc_content[cal_step_function] = {
|
||||
"type": "PERIODIC",
|
||||
"period": 0.1,
|
||||
"accesses": calibration_variables,
|
||||
}
|
||||
swc_content[cal_init_function] = {"type": "INIT", "accesses": calibration_variables}
|
||||
swc_content[cal_step_function] = {"type": "PERIODIC", "period": 0.1, "accesses": calibration_variables}
|
||||
|
||||
if len(runnables) == 1 and custom_step_function is not None:
|
||||
swc_content[custom_step_function] = {
|
||||
|
@ -81,6 +81,10 @@ expected_cal_result = {
|
||||
"type": "INIT",
|
||||
"accesses": composition_yaml_setup.cal_accesses
|
||||
},
|
||||
"AR_testName_SC_ZcCalibrationInit": {
|
||||
"type": "INIT",
|
||||
"accesses": composition_yaml_setup.cal_accesses
|
||||
},
|
||||
"AR_prefix_testRunnable": {
|
||||
"period": 10,
|
||||
"type": "PERIODIC",
|
||||
|
@ -11,8 +11,6 @@ from powertrain_build.zone_controller.calibration import ZoneControllerCalibrati
|
||||
class TestZoneControllerCalibration(TestCase):
|
||||
"""Test case for testing composition_yaml."""
|
||||
|
||||
maxDiff = None
|
||||
|
||||
def setUp(self):
|
||||
"""Set-up common data structures for all tests in the test case."""
|
||||
build_cfg = MagicMock()
|
||||
@ -69,6 +67,7 @@ class TestZoneControllerCalibration(TestCase):
|
||||
"extern const UInt8* Rte_CData_testName_SC_dummy_four(void);\n",
|
||||
"extern Float32 Rte_CData_testName_SC_ctestName_SC_TriggerReadRteCData(void);\n",
|
||||
"\n",
|
||||
"void testName_SC_ZcCalibrationInit(void);\n",
|
||||
"void testName_SC_ZcCalibrationStep(void);\n",
|
||||
"\n",
|
||||
"#endif /* CALIBRATION_INTERFACE_H */\n"
|
||||
@ -89,7 +88,21 @@ class TestZoneControllerCalibration(TestCase):
|
||||
"\n",
|
||||
"#define testName_SC_START_SEC_CODE\n",
|
||||
'#include "testName_SC_MemMap.h"\n',
|
||||
"void testName_SC_ZcCalibrationStep(void)\n{\n",
|
||||
"void testName_SC_ZcCalibrationInit(void)\n",
|
||||
"{\n",
|
||||
" dummy_one = Rte_CData_testName_SC_dummy_one();\n",
|
||||
" dummy_two = Rte_CData_testName_SC_dummy_two();\n",
|
||||
" memcpy(dummy_three, Rte_CData_testName_SC_dummy_three(), sizeof(dummy_three));\n",
|
||||
" memcpy(dummy_four, Rte_CData_testName_SC_dummy_four(), sizeof(dummy_four));\n",
|
||||
" ctestName_SC_TriggerReadRteCData = Rte_CData_testName_SC_ctestName_SC_TriggerReadRteCData();\n",
|
||||
"}\n",
|
||||
"#define testName_SC_STOP_SEC_CODE\n",
|
||||
'#include "testName_SC_MemMap.h"\n',
|
||||
"\n",
|
||||
"#define testName_SC_START_SEC_CODE\n",
|
||||
'#include "testName_SC_MemMap.h"\n',
|
||||
"void testName_SC_ZcCalibrationStep(void)\n",
|
||||
"{\n",
|
||||
" if (ctestName_SC_TriggerReadRteCData != Rte_CData_testName_SC_ctestName_SC_TriggerReadRteCData())\n",
|
||||
" {\n",
|
||||
" dummy_one = Rte_CData_testName_SC_dummy_one();\n",
|
||||
|
Loading…
x
Reference in New Issue
Block a user