mbed os with nrf51 internal bandgap enabled to read battery level

Dependents:   BLE_file_test BLE_Blink ExternalEncoder

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 """
elessair 0:f269e3021894 2 mbed SDK
elessair 0:f269e3021894 3 Copyright (c) 2011-2013 ARM Limited
elessair 0:f269e3021894 4
elessair 0:f269e3021894 5 Licensed under the Apache License, Version 2.0 (the "License");
elessair 0:f269e3021894 6 you may not use this file except in compliance with the License.
elessair 0:f269e3021894 7 You may obtain a copy of the License at
elessair 0:f269e3021894 8
elessair 0:f269e3021894 9 http://www.apache.org/licenses/LICENSE-2.0
elessair 0:f269e3021894 10
elessair 0:f269e3021894 11 Unless required by applicable law or agreed to in writing, software
elessair 0:f269e3021894 12 distributed under the License is distributed on an "AS IS" BASIS,
elessair 0:f269e3021894 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
elessair 0:f269e3021894 14 See the License for the specific language governing permissions and
elessair 0:f269e3021894 15 limitations under the License.
elessair 0:f269e3021894 16 """
elessair 0:f269e3021894 17 import sys
elessair 0:f269e3021894 18 from os.path import join, abspath, dirname, exists, splitext
elessair 0:f269e3021894 19 from subprocess import Popen, PIPE
elessair 0:f269e3021894 20 import csv
elessair 0:f269e3021894 21 from collections import defaultdict
elessair 0:f269e3021894 22
elessair 0:f269e3021894 23 ROOT = abspath(join(dirname(__file__), ".."))
elessair 0:f269e3021894 24 sys.path.insert(0, ROOT)
elessair 0:f269e3021894 25
elessair 0:f269e3021894 26 from tools.paths import BUILD_DIR, TOOLS_DATA
elessair 0:f269e3021894 27 from tools.settings import GCC_ARM_PATH
elessair 0:f269e3021894 28 from tools.tests import TEST_MAP
elessair 0:f269e3021894 29 from tools.build_api import build_mbed_libs, build_project
elessair 0:f269e3021894 30
elessair 0:f269e3021894 31 SIZE = join(GCC_ARM_PATH, 'arm-none-eabi-size')
elessair 0:f269e3021894 32
elessair 0:f269e3021894 33 def get_size(path):
elessair 0:f269e3021894 34 out = Popen([SIZE, path], stdout=PIPE).communicate()[0]
elessair 0:f269e3021894 35 return map(int, out.splitlines()[1].split()[:4])
elessair 0:f269e3021894 36
elessair 0:f269e3021894 37 def get_percentage(before, after):
elessair 0:f269e3021894 38 if before == 0:
elessair 0:f269e3021894 39 return 0 if after == 0 else 100.0
elessair 0:f269e3021894 40 return float(after - before) / float(before) * 100.0
elessair 0:f269e3021894 41
elessair 0:f269e3021894 42 def human_size(val):
elessair 0:f269e3021894 43 if val>1024:
elessair 0:f269e3021894 44 return "%.0fKb" % (float(val)/1024.0)
elessair 0:f269e3021894 45 return "%d" % val
elessair 0:f269e3021894 46
elessair 0:f269e3021894 47 def print_diff(name, before, after):
elessair 0:f269e3021894 48 print "%s: (%s -> %s) %.2f%%" % (name, human_size(before) , human_size(after) , get_percentage(before , after))
elessair 0:f269e3021894 49
elessair 0:f269e3021894 50 BENCHMARKS = [
elessair 0:f269e3021894 51 ("BENCHMARK_1", "CENV"),
elessair 0:f269e3021894 52 ("BENCHMARK_2", "PRINTF"),
elessair 0:f269e3021894 53 ("BENCHMARK_3", "FP"),
elessair 0:f269e3021894 54 ("BENCHMARK_4", "MBED"),
elessair 0:f269e3021894 55 ("BENCHMARK_5", "ALL"),
elessair 0:f269e3021894 56 ]
elessair 0:f269e3021894 57 BENCHMARK_DATA_PATH = join(TOOLS_DATA, 'benchmarks.csv')
elessair 0:f269e3021894 58
elessair 0:f269e3021894 59
elessair 0:f269e3021894 60 def benchmarks():
elessair 0:f269e3021894 61 # CSV Data
elessair 0:f269e3021894 62 csv_data = csv.writer(open(BENCHMARK_DATA_PATH, 'wb'))
elessair 0:f269e3021894 63 csv_data.writerow(['Toolchain', "Target", "Benchmark", "code", "data", "bss", "flash"])
elessair 0:f269e3021894 64
elessair 0:f269e3021894 65 # Build
elessair 0:f269e3021894 66 for toolchain in ['ARM', 'uARM', 'GCC_CR', 'GCC_ARM']:
elessair 0:f269e3021894 67 for mcu in ["LPC1768", "LPC11U24"]:
elessair 0:f269e3021894 68 # Build Libraries
elessair 0:f269e3021894 69 build_mbed_libs(mcu, toolchain)
elessair 0:f269e3021894 70
elessair 0:f269e3021894 71 # Build benchmarks
elessair 0:f269e3021894 72 build_dir = join(BUILD_DIR, "benchmarks", mcu, toolchain)
elessair 0:f269e3021894 73 for test_id, title in BENCHMARKS:
elessair 0:f269e3021894 74 # Build Benchmark
elessair 0:f269e3021894 75 try:
elessair 0:f269e3021894 76 test = TEST_MAP[test_id]
elessair 0:f269e3021894 77 path = build_project(test.source_dir, join(build_dir, test_id),
elessair 0:f269e3021894 78 mcu, toolchain, test.dependencies)
elessair 0:f269e3021894 79 base, ext = splitext(path)
elessair 0:f269e3021894 80 # Check Size
elessair 0:f269e3021894 81 code, data, bss, flash = get_size(base+'.elf')
elessair 0:f269e3021894 82 csv_data.writerow([toolchain, mcu, title, code, data, bss, flash])
elessair 0:f269e3021894 83 except Exception, e:
elessair 0:f269e3021894 84 print "Unable to build %s for toolchain %s targeting %s" % (test_id, toolchain, mcu)
elessair 0:f269e3021894 85 print e
elessair 0:f269e3021894 86
elessair 0:f269e3021894 87
elessair 0:f269e3021894 88 def compare(t1, t2, target):
elessair 0:f269e3021894 89 if not exists(BENCHMARK_DATA_PATH):
elessair 0:f269e3021894 90 benchmarks()
elessair 0:f269e3021894 91 else:
elessair 0:f269e3021894 92 print "Loading: %s" % BENCHMARK_DATA_PATH
elessair 0:f269e3021894 93
elessair 0:f269e3021894 94 data = csv.reader(open(BENCHMARK_DATA_PATH, 'rb'))
elessair 0:f269e3021894 95
elessair 0:f269e3021894 96 benchmarks_data = defaultdict(dict)
elessair 0:f269e3021894 97 for (toolchain, mcu, name, code, data, bss, flash) in data:
elessair 0:f269e3021894 98 if target == mcu:
elessair 0:f269e3021894 99 for t in [t1, t2]:
elessair 0:f269e3021894 100 if toolchain == t:
elessair 0:f269e3021894 101 benchmarks_data[name][t] = map(int, (code, data, bss, flash))
elessair 0:f269e3021894 102
elessair 0:f269e3021894 103 print "%s vs %s for %s" % (t1, t2, target)
elessair 0:f269e3021894 104 for name, data in benchmarks_data.iteritems():
elessair 0:f269e3021894 105 try:
elessair 0:f269e3021894 106 # Check Size
elessair 0:f269e3021894 107 code_a, data_a, bss_a, flash_a = data[t1]
elessair 0:f269e3021894 108 code_u, data_u, bss_u, flash_u = data[t2]
elessair 0:f269e3021894 109
elessair 0:f269e3021894 110 print "\n=== %s ===" % name
elessair 0:f269e3021894 111 print_diff("code", code_a , code_u)
elessair 0:f269e3021894 112 print_diff("data", data_a , data_u)
elessair 0:f269e3021894 113 print_diff("bss", bss_a , bss_u)
elessair 0:f269e3021894 114 print_diff("flash", flash_a , flash_u)
elessair 0:f269e3021894 115 except Exception, e:
elessair 0:f269e3021894 116 print "No data for benchmark %s" % (name)
elessair 0:f269e3021894 117 print e
elessair 0:f269e3021894 118
elessair 0:f269e3021894 119
elessair 0:f269e3021894 120 if __name__ == '__main__':
elessair 0:f269e3021894 121 compare("GCC_CR", "LPC1768")