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 """ import and bulid a bunch of example programs """
elessair 0:f269e3021894 2
elessair 0:f269e3021894 3 from argparse import ArgumentParser
elessair 0:f269e3021894 4 import os
elessair 0:f269e3021894 5 from os.path import dirname, abspath, basename
elessair 0:f269e3021894 6 import os.path
elessair 0:f269e3021894 7 import sys
elessair 0:f269e3021894 8 import subprocess
elessair 0:f269e3021894 9 import json
elessair 0:f269e3021894 10
elessair 0:f269e3021894 11 ROOT = abspath(dirname(dirname(dirname(dirname(__file__)))))
elessair 0:f269e3021894 12 sys.path.insert(0, ROOT)
elessair 0:f269e3021894 13
elessair 0:f269e3021894 14 from tools.build_api import get_mbed_official_release
elessair 0:f269e3021894 15 from tools.targets import TARGET_MAP
elessair 0:f269e3021894 16 from tools.utils import argparse_force_uppercase_type
elessair 0:f269e3021894 17
elessair 0:f269e3021894 18
elessair 0:f269e3021894 19 EXAMPLES = json.load(open(os.path.join(os.path.dirname(__file__),
elessair 0:f269e3021894 20 "examples.json")))
elessair 0:f269e3021894 21
elessair 0:f269e3021894 22 def print_stuff(name, lst):
elessair 0:f269e3021894 23 if lst:
elessair 0:f269e3021894 24 print("#"*80)
elessair 0:f269e3021894 25 print("# {} example combinations".format(name))
elessair 0:f269e3021894 26 print("#")
elessair 0:f269e3021894 27 for thing in lst:
elessair 0:f269e3021894 28 print(thing)
elessair 0:f269e3021894 29
elessair 0:f269e3021894 30
elessair 0:f269e3021894 31 SUPPORTED_TOOLCHAINS = ["ARM", "IAR", "GCC_ARM"]
elessair 0:f269e3021894 32
elessair 0:f269e3021894 33
elessair 0:f269e3021894 34 def target_cross_toolchain(allowed_toolchains,
elessair 0:f269e3021894 35 features=[], targets=TARGET_MAP.keys(),
elessair 0:f269e3021894 36 toolchains=SUPPORTED_TOOLCHAINS):
elessair 0:f269e3021894 37 """Generate pairs of target and toolchains
elessair 0:f269e3021894 38
elessair 0:f269e3021894 39 Args:
elessair 0:f269e3021894 40 allowed_toolchains - a list of all possible toolchains
elessair 0:f269e3021894 41
elessair 0:f269e3021894 42 Kwargs:
elessair 0:f269e3021894 43 features - the features that must be in the features array of a
elessair 0:f269e3021894 44 target
elessair 0:f269e3021894 45 targets - a list of available targets
elessair 0:f269e3021894 46 toolchains - a list of available toolchains
elessair 0:f269e3021894 47 """
elessair 0:f269e3021894 48 for release_target, release_toolchains in get_mbed_official_release("5"):
elessair 0:f269e3021894 49 for toolchain in release_toolchains:
elessair 0:f269e3021894 50 if (toolchain in allowed_toolchains and
elessair 0:f269e3021894 51 toolchain in toolchains and
elessair 0:f269e3021894 52 release_target in targets and
elessair 0:f269e3021894 53 all(feature in TARGET_MAP[release_target].features
elessair 0:f269e3021894 54 for feature in features)):
elessair 0:f269e3021894 55 yield release_target, toolchain
elessair 0:f269e3021894 56
elessair 0:f269e3021894 57
elessair 0:f269e3021894 58 def main():
elessair 0:f269e3021894 59 """Entry point"""
elessair 0:f269e3021894 60 parser = ArgumentParser()
elessair 0:f269e3021894 61 subparsers = parser.add_subparsers()
elessair 0:f269e3021894 62 import_cmd = subparsers.add_parser("import")
elessair 0:f269e3021894 63 import_cmd.set_defaults(fn=do_import)
elessair 0:f269e3021894 64 compile_cmd = subparsers.add_parser("compile")
elessair 0:f269e3021894 65 compile_cmd.set_defaults(fn=do_compile)
elessair 0:f269e3021894 66 compile_cmd.add_argument(
elessair 0:f269e3021894 67 "toolchains", nargs="*", default=SUPPORTED_TOOLCHAINS,
elessair 0:f269e3021894 68 type=argparse_force_uppercase_type(SUPPORTED_TOOLCHAINS,
elessair 0:f269e3021894 69 "toolchain"))
elessair 0:f269e3021894 70 args = parser.parse_args()
elessair 0:f269e3021894 71 return args.fn(args)
elessair 0:f269e3021894 72
elessair 0:f269e3021894 73
elessair 0:f269e3021894 74 def do_import(_):
elessair 0:f269e3021894 75 """Do the import step of this process"""
elessair 0:f269e3021894 76 for example, _ in EXAMPLES.iteritems():
elessair 0:f269e3021894 77 subprocess.call(["mbed-cli", "import", example])
elessair 0:f269e3021894 78 return 0
elessair 0:f269e3021894 79
elessair 0:f269e3021894 80
elessair 0:f269e3021894 81 def do_compile(args):
elessair 0:f269e3021894 82 """Do the compile step"""
elessair 0:f269e3021894 83 failures = []
elessair 0:f269e3021894 84 sucesses = []
elessair 0:f269e3021894 85 for example, requirements in EXAMPLES.iteritems():
elessair 0:f269e3021894 86 os.chdir(basename(example))
elessair 0:f269e3021894 87 for target, toolchain in target_cross_toolchain(args.toolchains,
elessair 0:f269e3021894 88 **requirements):
elessair 0:f269e3021894 89 proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain,
elessair 0:f269e3021894 90 "-m", target, "--silent"])
elessair 0:f269e3021894 91 proc.wait()
elessair 0:f269e3021894 92 example_name = "{} {} {}".format(basename(example), target,
elessair 0:f269e3021894 93 toolchain)
elessair 0:f269e3021894 94 if proc.returncode:
elessair 0:f269e3021894 95 failures.append(example_name)
elessair 0:f269e3021894 96 else:
elessair 0:f269e3021894 97 sucesses.append(example_name)
elessair 0:f269e3021894 98 os.chdir("..")
elessair 0:f269e3021894 99
elessair 0:f269e3021894 100 print_stuff("Passed", sucesses)
elessair 0:f269e3021894 101 print_stuff("Failed", failures)
elessair 0:f269e3021894 102 return len(failures)
elessair 0:f269e3021894 103
elessair 0:f269e3021894 104 if __name__ == "__main__":
elessair 0:f269e3021894 105 sys.exit(main())