61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
import sys
|
||
|
import struct
|
||
|
|
||
|
import yaml
|
||
|
from intelhex import IntelHex
|
||
|
|
||
|
|
||
|
def as_fxp(v):
|
||
|
return int(v * 2**16 + 0.5)
|
||
|
|
||
|
BASE_ADDR = 0x08080000
|
||
|
|
||
|
FLAG_NAME_TO_BIT_INDEX = {
|
||
|
'USE_DCDC_CONTROL': 0
|
||
|
}
|
||
|
|
||
|
CONFIG_KEY_TO_OFFSET = {
|
||
|
# note: flags are at 0x0000, but not listed here due to special handling.
|
||
|
'CORRIDOR_MIN_TEMPERATURE': 0x0004,
|
||
|
'CORRIDOR_MAX_TEMPERATURE': 0x0008,
|
||
|
'FAN_START_TEMPERATURE': 0x000C,
|
||
|
'FAN_OFF_TEMPERATURE': 0x0010,
|
||
|
'EMERGENCY_TEMPERATURE': 0x0014,
|
||
|
'DUTY_CYCLE_MIN': 0x0018,
|
||
|
'DUTY_CYCLE_MAX': 0x001C,
|
||
|
'DUTY_CYCLE_START': 0x0020,
|
||
|
'GAIN_T_HIGH_P': 0x0024,
|
||
|
'GAIN_T_HIGH_I': 0x0028,
|
||
|
'GAIN_T_LOW_P': 0x002C,
|
||
|
'GAIN_T_LOW_I': 0x0030,
|
||
|
}
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
output = IntelHex()
|
||
|
|
||
|
if len(sys.argv) < 3:
|
||
|
print(f"usage: {sys.argv[0]} <yaml-config> <output-hex>")
|
||
|
sys.exit(1)
|
||
|
|
||
|
with open(sys.argv[1], 'r') as configfile:
|
||
|
config = yaml.safe_load(configfile)
|
||
|
|
||
|
flags = 0
|
||
|
for key, bitidx in FLAG_NAME_TO_BIT_INDEX.items():
|
||
|
if config['flags'][key]:
|
||
|
flags |= (1 << bitidx)
|
||
|
|
||
|
|
||
|
enc_bytes = struct.pack('<I', flags)
|
||
|
output.puts(BASE_ADDR + 0x0000, enc_bytes)
|
||
|
|
||
|
for key, offset in CONFIG_KEY_TO_OFFSET.items():
|
||
|
value = as_fxp(config['config'][key])
|
||
|
enc_bytes = struct.pack('<i', value)
|
||
|
output.puts(BASE_ADDR + offset, enc_bytes)
|
||
|
|
||
|
output.write_hex_file(sys.argv[2])
|