summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-05-13 15:48:10 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2019-05-13 15:48:10 +0200
commit29094b709088d5c997425580dc15e22b555dbf59 (patch)
treea4d1e3122e854a51a2f824f19ff1fae0f03236b3 /lib
parent349e9f1984584197be379b0033260632ea1c26d4 (diff)
cycles_to_energy: Add energy per cycle and ATMega328 class
Diffstat (limited to 'lib')
-rw-r--r--lib/cycles_to_energy.py54
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 = {