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 """
marcozecchini 0:9fca2b23d0ba 19 import sys
marcozecchini 0:9fca2b23d0ba 20 from os.path import isdir, abspath, dirname, join
marcozecchini 0:9fca2b23d0ba 21 from os import _exit
marcozecchini 0:9fca2b23d0ba 22
marcozecchini 0:9fca2b23d0ba 23 # Be sure that the tools directory is in the search path
marcozecchini 0:9fca2b23d0ba 24 ROOT = abspath(join(dirname(__file__), ".."))
marcozecchini 0:9fca2b23d0ba 25 sys.path.insert(0, ROOT)
marcozecchini 0:9fca2b23d0ba 26
marcozecchini 0:9fca2b23d0ba 27 from tools.utils import args_error
marcozecchini 0:9fca2b23d0ba 28 from tools.options import get_default_options_parser
marcozecchini 0:9fca2b23d0ba 29 from tools.options import extract_mcus
marcozecchini 0:9fca2b23d0ba 30 from tools.build_api import get_config
marcozecchini 0:9fca2b23d0ba 31 from config import Config
marcozecchini 0:9fca2b23d0ba 32 from utils import argparse_filestring_type
marcozecchini 0:9fca2b23d0ba 33 try:
marcozecchini 0:9fca2b23d0ba 34 import tools.private_settings as ps
marcozecchini 0:9fca2b23d0ba 35 except:
marcozecchini 0:9fca2b23d0ba 36 ps = object()
marcozecchini 0:9fca2b23d0ba 37
marcozecchini 0:9fca2b23d0ba 38 if __name__ == '__main__':
marcozecchini 0:9fca2b23d0ba 39 # Parse Options
marcozecchini 0:9fca2b23d0ba 40 parser = get_default_options_parser(add_clean=False, add_options=False)
marcozecchini 0:9fca2b23d0ba 41 parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, required=True,
marcozecchini 0:9fca2b23d0ba 42 default=[], help="The source (input) directory", action="append")
marcozecchini 0:9fca2b23d0ba 43 parser.add_argument("--prefix", dest="prefix", action="append",
marcozecchini 0:9fca2b23d0ba 44 default=[], help="Restrict listing to parameters that have this prefix")
marcozecchini 0:9fca2b23d0ba 45 parser.add_argument("-v", "--verbose", action="store_true", dest="verbose",
marcozecchini 0:9fca2b23d0ba 46 default=False, help="Verbose diagnostic output")
marcozecchini 0:9fca2b23d0ba 47
marcozecchini 0:9fca2b23d0ba 48 options = parser.parse_args()
marcozecchini 0:9fca2b23d0ba 49
marcozecchini 0:9fca2b23d0ba 50 # Target
marcozecchini 0:9fca2b23d0ba 51 if options.mcu is None :
marcozecchini 0:9fca2b23d0ba 52 args_error(parser, "argument -m/--mcu is required")
marcozecchini 0:9fca2b23d0ba 53 target = extract_mcus(parser, options)[0]
marcozecchini 0:9fca2b23d0ba 54
marcozecchini 0:9fca2b23d0ba 55 # Toolchain
marcozecchini 0:9fca2b23d0ba 56 if options.tool is None:
marcozecchini 0:9fca2b23d0ba 57 args_error(parser, "argument -t/--toolchain is required")
marcozecchini 0:9fca2b23d0ba 58 toolchain = options.tool[0]
marcozecchini 0:9fca2b23d0ba 59
marcozecchini 0:9fca2b23d0ba 60 options.prefix = options.prefix or [""]
marcozecchini 0:9fca2b23d0ba 61
marcozecchini 0:9fca2b23d0ba 62 try:
marcozecchini 0:9fca2b23d0ba 63 params, macros, features = get_config(options.source_dir, target, toolchain)
marcozecchini 0:9fca2b23d0ba 64 if not params and not macros:
marcozecchini 0:9fca2b23d0ba 65 print "No configuration data available."
marcozecchini 0:9fca2b23d0ba 66 _exit(0)
marcozecchini 0:9fca2b23d0ba 67 if params:
marcozecchini 0:9fca2b23d0ba 68 print "Configuration parameters"
marcozecchini 0:9fca2b23d0ba 69 print "------------------------"
marcozecchini 0:9fca2b23d0ba 70 for p in sorted(params):
marcozecchini 0:9fca2b23d0ba 71 for s in options.prefix:
marcozecchini 0:9fca2b23d0ba 72 if p.startswith(s):
marcozecchini 0:9fca2b23d0ba 73 print(str(params[p]) if not options.verbose else params[p].get_verbose_description())
marcozecchini 0:9fca2b23d0ba 74 break
marcozecchini 0:9fca2b23d0ba 75 print ""
marcozecchini 0:9fca2b23d0ba 76
marcozecchini 0:9fca2b23d0ba 77 print "Macros"
marcozecchini 0:9fca2b23d0ba 78 print "------"
marcozecchini 0:9fca2b23d0ba 79 if macros:
marcozecchini 0:9fca2b23d0ba 80 print 'Defined with "macros":', Config.config_macros_to_macros(macros)
marcozecchini 0:9fca2b23d0ba 81 print "Generated from configuration parameters:", Config.parameters_to_macros(params)
marcozecchini 0:9fca2b23d0ba 82
marcozecchini 0:9fca2b23d0ba 83 except KeyboardInterrupt, e:
marcozecchini 0:9fca2b23d0ba 84 print "\n[CTRL+c] exit"
marcozecchini 0:9fca2b23d0ba 85 except Exception,e:
marcozecchini 0:9fca2b23d0ba 86 if options.verbose:
marcozecchini 0:9fca2b23d0ba 87 import traceback
marcozecchini 0:9fca2b23d0ba 88 traceback.print_exc(file=sys.stdout)
marcozecchini 0:9fca2b23d0ba 89 else:
marcozecchini 0:9fca2b23d0ba 90 print "[ERROR] %s" % str(e)
marcozecchini 0:9fca2b23d0ba 91
marcozecchini 0:9fca2b23d0ba 92 sys.exit(1)