Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcozecchini 0:9fca2b23d0ba 1 #! /usr/bin/env python2
marcozecchini 0:9fca2b23d0ba 2 """
marcozecchini 0:9fca2b23d0ba 3 mbed SDK
marcozecchini 0:9fca2b23d0ba 4 Copyright (c) 2011-2013 ARM Limited
marcozecchini 0:9fca2b23d0ba 5
marcozecchini 0:9fca2b23d0ba 6 Licensed under the Apache License, Version 2.0 (the "License");
marcozecchini 0:9fca2b23d0ba 7 you may not use this file except in compliance with the License.
marcozecchini 0:9fca2b23d0ba 8 You may obtain a copy of the License at
marcozecchini 0:9fca2b23d0ba 9
marcozecchini 0:9fca2b23d0ba 10 http://www.apache.org/licenses/LICENSE-2.0
marcozecchini 0:9fca2b23d0ba 11
marcozecchini 0:9fca2b23d0ba 12 Unless required by applicable law or agreed to in writing, software
marcozecchini 0:9fca2b23d0ba 13 distributed under the License is distributed on an "AS IS" BASIS,
marcozecchini 0:9fca2b23d0ba 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
marcozecchini 0:9fca2b23d0ba 15 See the License for the specific language governing permissions and
marcozecchini 0:9fca2b23d0ba 16 limitations under the License.
marcozecchini 0:9fca2b23d0ba 17 """
marcozecchini 0:9fca2b23d0ba 18 import sys
marcozecchini 0:9fca2b23d0ba 19 import os
marcozecchini 0:9fca2b23d0ba 20 import re
marcozecchini 0:9fca2b23d0ba 21
marcozecchini 0:9fca2b23d0ba 22 ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
marcozecchini 0:9fca2b23d0ba 23 sys.path.insert(0, ROOT)
marcozecchini 0:9fca2b23d0ba 24
marcozecchini 0:9fca2b23d0ba 25 from tools.options import get_default_options_parser
marcozecchini 0:9fca2b23d0ba 26
marcozecchini 0:9fca2b23d0ba 27 # Check: Extra modules which are required by core test suite
marcozecchini 0:9fca2b23d0ba 28 from tools.utils import check_required_modules
marcozecchini 0:9fca2b23d0ba 29 check_required_modules(['prettytable'])
marcozecchini 0:9fca2b23d0ba 30
marcozecchini 0:9fca2b23d0ba 31 # Imports related to mbed build api
marcozecchini 0:9fca2b23d0ba 32 from tools.build_api import mcu_toolchain_matrix
marcozecchini 0:9fca2b23d0ba 33 from tools.test_api import get_autodetected_MUTS_list
marcozecchini 0:9fca2b23d0ba 34 from tools.test_api import get_module_avail
marcozecchini 0:9fca2b23d0ba 35 from argparse import ArgumentParser
marcozecchini 0:9fca2b23d0ba 36
marcozecchini 0:9fca2b23d0ba 37 try:
marcozecchini 0:9fca2b23d0ba 38 import mbed_lstools
marcozecchini 0:9fca2b23d0ba 39 except:
marcozecchini 0:9fca2b23d0ba 40 pass
marcozecchini 0:9fca2b23d0ba 41
marcozecchini 0:9fca2b23d0ba 42 def main():
marcozecchini 0:9fca2b23d0ba 43 """Entry Point"""
marcozecchini 0:9fca2b23d0ba 44 try:
marcozecchini 0:9fca2b23d0ba 45 # Parse Options
marcozecchini 0:9fca2b23d0ba 46 parser = ArgumentParser()
marcozecchini 0:9fca2b23d0ba 47
marcozecchini 0:9fca2b23d0ba 48 parser.add_argument("-S", "--supported-toolchains",
marcozecchini 0:9fca2b23d0ba 49 action="store_true",
marcozecchini 0:9fca2b23d0ba 50 dest="supported_toolchains",
marcozecchini 0:9fca2b23d0ba 51 default=False,
marcozecchini 0:9fca2b23d0ba 52 help="Displays supported matrix of"
marcozecchini 0:9fca2b23d0ba 53 " targets and toolchains")
marcozecchini 0:9fca2b23d0ba 54
marcozecchini 0:9fca2b23d0ba 55 parser.add_argument('-f', '--filter',
marcozecchini 0:9fca2b23d0ba 56 dest='general_filter_regex',
marcozecchini 0:9fca2b23d0ba 57 default=None,
marcozecchini 0:9fca2b23d0ba 58 help='Filter targets')
marcozecchini 0:9fca2b23d0ba 59
marcozecchini 0:9fca2b23d0ba 60 parser.add_argument("-v", "--verbose",
marcozecchini 0:9fca2b23d0ba 61 action="store_true",
marcozecchini 0:9fca2b23d0ba 62 dest="verbose",
marcozecchini 0:9fca2b23d0ba 63 default=False,
marcozecchini 0:9fca2b23d0ba 64 help="Verbose diagnostic output")
marcozecchini 0:9fca2b23d0ba 65
marcozecchini 0:9fca2b23d0ba 66 options = parser.parse_args()
marcozecchini 0:9fca2b23d0ba 67
marcozecchini 0:9fca2b23d0ba 68 # Only prints matrix of supported toolchains
marcozecchini 0:9fca2b23d0ba 69 if options.supported_toolchains:
marcozecchini 0:9fca2b23d0ba 70 print mcu_toolchain_matrix(
marcozecchini 0:9fca2b23d0ba 71 platform_filter=options.general_filter_regex)
marcozecchini 0:9fca2b23d0ba 72 exit(0)
marcozecchini 0:9fca2b23d0ba 73
marcozecchini 0:9fca2b23d0ba 74 # If auto_detect attribute is present, we assume other auto-detection
marcozecchini 0:9fca2b23d0ba 75 # parameters like 'toolchains_filter' are also set.
marcozecchini 0:9fca2b23d0ba 76 muts = get_autodetected_MUTS_list()
marcozecchini 0:9fca2b23d0ba 77
marcozecchini 0:9fca2b23d0ba 78 mcu_filter = options.general_filter_regex or ".*"
marcozecchini 0:9fca2b23d0ba 79
marcozecchini 0:9fca2b23d0ba 80 count = 0
marcozecchini 0:9fca2b23d0ba 81 for mut in muts.values():
marcozecchini 0:9fca2b23d0ba 82 if re.match(mcu_filter, mut['mcu']):
marcozecchini 0:9fca2b23d0ba 83 interface_version = get_interface_version(mut['disk'])
marcozecchini 0:9fca2b23d0ba 84 print ""
marcozecchini 0:9fca2b23d0ba 85 print "[mbed] Detected %s, port %s, mounted %s, interface version %s:" % \
marcozecchini 0:9fca2b23d0ba 86 (mut['mcu'], mut['port'], mut['disk'], interface_version)
marcozecchini 0:9fca2b23d0ba 87
marcozecchini 0:9fca2b23d0ba 88 print "[mbed] Supported toolchains for %s" % mut['mcu']
marcozecchini 0:9fca2b23d0ba 89 print mcu_toolchain_matrix(platform_filter=mut['mcu'])
marcozecchini 0:9fca2b23d0ba 90 count += 1
marcozecchini 0:9fca2b23d0ba 91
marcozecchini 0:9fca2b23d0ba 92 if count == 0:
marcozecchini 0:9fca2b23d0ba 93 print "[mbed] No mbed targets were detected on your system."
marcozecchini 0:9fca2b23d0ba 94
marcozecchini 0:9fca2b23d0ba 95 except KeyboardInterrupt:
marcozecchini 0:9fca2b23d0ba 96 print "\n[CTRL+c] exit"
marcozecchini 0:9fca2b23d0ba 97 except Exception as exc:
marcozecchini 0:9fca2b23d0ba 98 import traceback
marcozecchini 0:9fca2b23d0ba 99 traceback.print_exc(file=sys.stdout)
marcozecchini 0:9fca2b23d0ba 100 print "[ERROR] %s" % str(exc)
marcozecchini 0:9fca2b23d0ba 101 sys.exit(1)
marcozecchini 0:9fca2b23d0ba 102
marcozecchini 0:9fca2b23d0ba 103 def get_interface_version(mount_point):
marcozecchini 0:9fca2b23d0ba 104 """ Function returns interface version from the target mounted on the specified mount point
marcozecchini 0:9fca2b23d0ba 105
marcozecchini 0:9fca2b23d0ba 106 mount_point can be acquired via the following:
marcozecchini 0:9fca2b23d0ba 107 muts = get_autodetected_MUTS_list()
marcozecchini 0:9fca2b23d0ba 108 for mut in muts.values():
marcozecchini 0:9fca2b23d0ba 109 mount_point = mut['disk']
marcozecchini 0:9fca2b23d0ba 110
marcozecchini 0:9fca2b23d0ba 111 @param mount_point Name of disk where platform is connected to host machine.
marcozecchini 0:9fca2b23d0ba 112 """
marcozecchini 0:9fca2b23d0ba 113 if get_module_avail('mbed_lstools'):
marcozecchini 0:9fca2b23d0ba 114 try :
marcozecchini 0:9fca2b23d0ba 115 mbeds = mbed_lstools.create()
marcozecchini 0:9fca2b23d0ba 116 details_txt = mbeds.get_details_txt(mount_point)
marcozecchini 0:9fca2b23d0ba 117
marcozecchini 0:9fca2b23d0ba 118 if 'Interface Version' in details_txt:
marcozecchini 0:9fca2b23d0ba 119 return details_txt['Interface Version']
marcozecchini 0:9fca2b23d0ba 120
marcozecchini 0:9fca2b23d0ba 121 elif 'Version' in details_txt:
marcozecchini 0:9fca2b23d0ba 122 return details_txt['Version']
marcozecchini 0:9fca2b23d0ba 123
marcozecchini 0:9fca2b23d0ba 124 except :
marcozecchini 0:9fca2b23d0ba 125 return 'unknown'
marcozecchini 0:9fca2b23d0ba 126
marcozecchini 0:9fca2b23d0ba 127 return 'unknown'
marcozecchini 0:9fca2b23d0ba 128
marcozecchini 0:9fca2b23d0ba 129 if __name__ == '__main__':
marcozecchini 0:9fca2b23d0ba 130 main()