5.2.1 - Updated I2C files

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Committer:
group-onsemi
Date:
Wed Jan 25 20:34:15 2017 +0000
Revision:
0:098463de4c5d
Initial commit

Who changed what in which revision?

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