diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2019-05-13 15:48:10 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2019-05-13 15:48:10 +0200 |
commit | 29094b709088d5c997425580dc15e22b555dbf59 (patch) | |
tree | a4d1e3122e854a51a2f824f19ff1fae0f03236b3 /lib/cycles_to_energy.py | |
parent | 349e9f1984584197be379b0033260632ea1c26d4 (diff) |
cycles_to_energy: Add energy per cycle and ATMega328 class
Diffstat (limited to 'lib/cycles_to_energy.py')
-rw-r--r-- | lib/cycles_to_energy.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/cycles_to_energy.py b/lib/cycles_to_energy.py index 53b1e46..ec449ca 100644 --- a/lib/cycles_to_energy.py +++ b/lib/cycles_to_energy.py @@ -11,6 +11,8 @@ def get_class(cpu_name): return MSP430 if cpu_name == 'ATMega168': return ATMega168 + if cpu_name == 'ATMega328': + return ATMega328 if cpu_name == 'ATTiny88': return ATTiny88 @@ -56,6 +58,12 @@ class MSP430: return MSP430.get_current(params) * params['voltage'] + def get_energy_per_cycle(params): + if type(params) != dict: + return MSP430.get_energy(_param_list_to_dict(MSP430, params)) + + return MSP430.get_power(params) / params['cpu_freq'] + class ATMega168: name = 'ATMega168' parameters = { @@ -78,6 +86,52 @@ class ATMega168: return 12e-3 return None + def get_power(params): + if type(params) != dict: + return ATMega168.get_energy(_param_list_to_dict(ATMega168, params)) + + return ATMega168.get_current(params) * params['voltage'] + + def get_energy_per_cycle(params): + if type(params) != dict: + return ATMega168.get_energy(_param_list_to_dict(ATMega168, params)) + + return ATMega168.get_power(params) / params['cpu_freq'] + +class ATMega328: + name = 'ATMega328' + parameters = { + 'cpu_freq': [1e6, 4e6, 8e6], + 'voltage': [2, 3, 5] + } + default_params = { + 'cpu_freq': 4e6, + 'voltage': 3 + } + + def get_current(params): + if type(params) != dict: + return ATMega328.get_current(_param_list_to_dict(ATMega328, params)) + if params['cpu_freq'] == 1e6 and params['voltage'] <= 2: + return 0.5e-3 + if params['cpu_freq'] == 4e6 and params['voltage'] <= 3: + return 3.5e-3 + if params['cpu_freq'] == 8e6 and params['voltage'] <= 5: + return 12e-3 + return None + + def get_power(params): + if type(params) != dict: + return ATMega328.get_energy(_param_list_to_dict(ATMega328, params)) + + return ATMega328.get_current(params) * params['voltage'] + + def get_energy_per_cycle(params): + if type(params) != dict: + return ATMega328.get_energy(_param_list_to_dict(ATMega328, params)) + + return ATMega328.get_power(params) / params['cpu_freq'] + class ATTiny88: name = 'ATTiny88' parameters = { |