diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-10-18 07:34:17 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-10-18 07:34:17 +0200 |
commit | 41f6b6d6f31f5617810c752fd15015549d78cdc3 (patch) | |
tree | 4f0764da4b466e84bfd5057661400dd1eedd9725 | |
parent | 20037a10ca63e05f3b785e98ebf3747a4b811848 (diff) |
MSP430: Show calculated real timer frequency on 'info"
-rw-r--r-- | src/arch/msp430fr5969lp/Makefile.inc | 2 | ||||
-rwxr-xr-x | src/arch/msp430fr5969lp/model.py | 48 |
2 files changed, 49 insertions, 1 deletions
diff --git a/src/arch/msp430fr5969lp/Makefile.inc b/src/arch/msp430fr5969lp/Makefile.inc index 2eb9dc9..d639a9d 100644 --- a/src/arch/msp430fr5969lp/Makefile.inc +++ b/src/arch/msp430fr5969lp/Makefile.inc @@ -86,7 +86,7 @@ arch_help: arch_info: @echo "CPU Freq: ${cpu_freq} Hz" - @echo "Timer Freq: ${timer_freq} Hz" + @echo "Timer Freq: ${timer_freq} Hz -> $(shell src/arch/msp430fr5969lp/model.py f_timer "${cpu_freq}" "${timer_freq}")" @echo "I2C Freq: ${i2c_freq} Hz" .PHONY: arch_clean arch_help arch_info monitor program diff --git a/src/arch/msp430fr5969lp/model.py b/src/arch/msp430fr5969lp/model.py new file mode 100755 index 0000000..4747b68 --- /dev/null +++ b/src/arch/msp430fr5969lp/model.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 + +import numpy as np +import sys + +# include/arch/msp430fr5969lp/driver/timer.h +def get_timer_frequency(f_cpu, f_timer): + if f_cpu == 16000000: + ta0_main_div = 8 + elif f_cpu == 8000000: + ta0_main_div = 4 + elif f_cpu == 4000000: + ta0_main_div = 2 + elif f_cpu == 1000000: + ta0_main_div = 1 + else: + raise ValueError("Invalid f_cpu") + + if f_cpu == 1000000: + if f_timer >= 1000: + divisor = 1 + counter = 1000 / (f_timer / 1000) + elif f_timer >= 20: + divisor = 1 + counter = 1000000 / f_timer + else: + divisor = 8 * 2 + counter = 62500 / f_timer + else: + if f_timer >= 1000: + divisor = ta0_main_div * 1 + counter = 2000 / (f_timer / 1000) + else: + divisor = ta0_main_div * 1 + counter = 2000000 / f_timer + + return f_cpu / divisor / int(counter) + +module = sys.argv[1] + +if module == 'f_timer' and len(sys.argv) == 4: + try: + f_cpu = int(sys.argv[2]) + f_timer = int(sys.argv[3]) + except: + sys.exit(0) + if f_cpu != 0 and f_timer != 0: + print('{:.2f}'.format(get_timer_frequency(f_cpu, f_timer))) |