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 """
marcozecchini 0:9fca2b23d0ba 2 mbed SDK
marcozecchini 0:9fca2b23d0ba 3 Copyright (c) 2011-2013 ARM Limited
marcozecchini 0:9fca2b23d0ba 4
marcozecchini 0:9fca2b23d0ba 5 Licensed under the Apache License, Version 2.0 (the "License");
marcozecchini 0:9fca2b23d0ba 6 you may not use this file except in compliance with the License.
marcozecchini 0:9fca2b23d0ba 7 You may obtain a copy of the License at
marcozecchini 0:9fca2b23d0ba 8
marcozecchini 0:9fca2b23d0ba 9 http://www.apache.org/licenses/LICENSE-2.0
marcozecchini 0:9fca2b23d0ba 10
marcozecchini 0:9fca2b23d0ba 11 Unless required by applicable law or agreed to in writing, software
marcozecchini 0:9fca2b23d0ba 12 distributed under the License is distributed on an "AS IS" BASIS,
marcozecchini 0:9fca2b23d0ba 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
marcozecchini 0:9fca2b23d0ba 14 See the License for the specific language governing permissions and
marcozecchini 0:9fca2b23d0ba 15 limitations under the License.
marcozecchini 0:9fca2b23d0ba 16 """
marcozecchini 0:9fca2b23d0ba 17 from json import load
marcozecchini 0:9fca2b23d0ba 18 from os.path import join, dirname
marcozecchini 0:9fca2b23d0ba 19 from os import listdir
marcozecchini 0:9fca2b23d0ba 20 from argparse import ArgumentParser, ArgumentTypeError
marcozecchini 0:9fca2b23d0ba 21 from tools.toolchains import TOOLCHAINS
marcozecchini 0:9fca2b23d0ba 22 from tools.targets import TARGET_NAMES, Target, update_target_data
marcozecchini 0:9fca2b23d0ba 23 from tools.utils import argparse_force_uppercase_type, \
marcozecchini 0:9fca2b23d0ba 24 argparse_lowercase_hyphen_type, argparse_many, \
marcozecchini 0:9fca2b23d0ba 25 argparse_filestring_type, args_error, argparse_profile_filestring_type,\
marcozecchini 0:9fca2b23d0ba 26 argparse_deprecate
marcozecchini 0:9fca2b23d0ba 27
marcozecchini 0:9fca2b23d0ba 28 FLAGS_DEPRECATION_MESSAGE = "Please use the --profile argument instead.\n"\
marcozecchini 0:9fca2b23d0ba 29 "Documentation may be found in "\
marcozecchini 0:9fca2b23d0ba 30 "docs/Toolchain_Profiles.md"
marcozecchini 0:9fca2b23d0ba 31
marcozecchini 0:9fca2b23d0ba 32 def get_default_options_parser(add_clean=True, add_options=True,
marcozecchini 0:9fca2b23d0ba 33 add_app_config=False):
marcozecchini 0:9fca2b23d0ba 34 """Create a new options parser with the default compiler options added
marcozecchini 0:9fca2b23d0ba 35
marcozecchini 0:9fca2b23d0ba 36 Keyword arguments:
marcozecchini 0:9fca2b23d0ba 37 add_clean - add the clean argument?
marcozecchini 0:9fca2b23d0ba 38 add_options - add the options argument?
marcozecchini 0:9fca2b23d0ba 39 """
marcozecchini 0:9fca2b23d0ba 40 parser = ArgumentParser()
marcozecchini 0:9fca2b23d0ba 41
marcozecchini 0:9fca2b23d0ba 42 targetnames = TARGET_NAMES
marcozecchini 0:9fca2b23d0ba 43 targetnames.sort()
marcozecchini 0:9fca2b23d0ba 44 toolchainlist = list(TOOLCHAINS)
marcozecchini 0:9fca2b23d0ba 45 toolchainlist.sort()
marcozecchini 0:9fca2b23d0ba 46
marcozecchini 0:9fca2b23d0ba 47 parser.add_argument("-m", "--mcu",
marcozecchini 0:9fca2b23d0ba 48 help=("build for the given MCU (%s)" %
marcozecchini 0:9fca2b23d0ba 49 ', '.join(targetnames)),
marcozecchini 0:9fca2b23d0ba 50 metavar="MCU")
marcozecchini 0:9fca2b23d0ba 51
marcozecchini 0:9fca2b23d0ba 52 parser.add_argument("-t", "--tool",
marcozecchini 0:9fca2b23d0ba 53 help=("build using the given TOOLCHAIN (%s)" %
marcozecchini 0:9fca2b23d0ba 54 ', '.join(toolchainlist)),
marcozecchini 0:9fca2b23d0ba 55 metavar="TOOLCHAIN",
marcozecchini 0:9fca2b23d0ba 56 type=argparse_many(
marcozecchini 0:9fca2b23d0ba 57 argparse_force_uppercase_type(
marcozecchini 0:9fca2b23d0ba 58 toolchainlist, "toolchain")))
marcozecchini 0:9fca2b23d0ba 59
marcozecchini 0:9fca2b23d0ba 60 parser.add_argument("--color",
marcozecchini 0:9fca2b23d0ba 61 help="print Warnings, and Errors in color",
marcozecchini 0:9fca2b23d0ba 62 action="store_true", default=False)
marcozecchini 0:9fca2b23d0ba 63
marcozecchini 0:9fca2b23d0ba 64 parser.add_argument("--cflags",
marcozecchini 0:9fca2b23d0ba 65 type=argparse_deprecate(FLAGS_DEPRECATION_MESSAGE),
marcozecchini 0:9fca2b23d0ba 66 help="Deprecated. " + FLAGS_DEPRECATION_MESSAGE)
marcozecchini 0:9fca2b23d0ba 67
marcozecchini 0:9fca2b23d0ba 68 parser.add_argument("--asmflags",
marcozecchini 0:9fca2b23d0ba 69 type=argparse_deprecate(FLAGS_DEPRECATION_MESSAGE),
marcozecchini 0:9fca2b23d0ba 70 help="Deprecated. " + FLAGS_DEPRECATION_MESSAGE)
marcozecchini 0:9fca2b23d0ba 71
marcozecchini 0:9fca2b23d0ba 72 parser.add_argument("--ldflags",
marcozecchini 0:9fca2b23d0ba 73 type=argparse_deprecate(FLAGS_DEPRECATION_MESSAGE),
marcozecchini 0:9fca2b23d0ba 74 help="Deprecated. " + FLAGS_DEPRECATION_MESSAGE)
marcozecchini 0:9fca2b23d0ba 75
marcozecchini 0:9fca2b23d0ba 76 if add_clean:
marcozecchini 0:9fca2b23d0ba 77 parser.add_argument("-c", "--clean", action="store_true", default=False,
marcozecchini 0:9fca2b23d0ba 78 help="clean the build directory")
marcozecchini 0:9fca2b23d0ba 79
marcozecchini 0:9fca2b23d0ba 80 if add_options:
marcozecchini 0:9fca2b23d0ba 81 parser.add_argument("--profile", dest="profile", action="append",
marcozecchini 0:9fca2b23d0ba 82 type=argparse_profile_filestring_type,
marcozecchini 0:9fca2b23d0ba 83 help="Build profile to use. Can be either path to json" \
marcozecchini 0:9fca2b23d0ba 84 "file or one of the default one ({})".format(", ".join(list_profiles())),
marcozecchini 0:9fca2b23d0ba 85 default=[])
marcozecchini 0:9fca2b23d0ba 86 if add_app_config:
marcozecchini 0:9fca2b23d0ba 87 parser.add_argument("--app-config", default=None, dest="app_config",
marcozecchini 0:9fca2b23d0ba 88 type=argparse_filestring_type,
marcozecchini 0:9fca2b23d0ba 89 help="Path of an app configuration file (Default is to look for 'mbed_app.json')")
marcozecchini 0:9fca2b23d0ba 90
marcozecchini 0:9fca2b23d0ba 91 return parser
marcozecchini 0:9fca2b23d0ba 92
marcozecchini 0:9fca2b23d0ba 93 def list_profiles():
marcozecchini 0:9fca2b23d0ba 94 """Lists available build profiles
marcozecchini 0:9fca2b23d0ba 95
marcozecchini 0:9fca2b23d0ba 96 Checks default profile directory (mbed-os/tools/profiles/) for all the json files and return list of names only
marcozecchini 0:9fca2b23d0ba 97 """
marcozecchini 0:9fca2b23d0ba 98 return [fn.replace(".json", "") for fn in listdir(join(dirname(__file__), "profiles")) if fn.endswith(".json")]
marcozecchini 0:9fca2b23d0ba 99
marcozecchini 0:9fca2b23d0ba 100 def extract_profile(parser, options, toolchain, fallback="develop"):
marcozecchini 0:9fca2b23d0ba 101 """Extract a Toolchain profile from parsed options
marcozecchini 0:9fca2b23d0ba 102
marcozecchini 0:9fca2b23d0ba 103 Positional arguments:
marcozecchini 0:9fca2b23d0ba 104 parser - parser used to parse the command line arguments
marcozecchini 0:9fca2b23d0ba 105 options - The parsed command line arguments
marcozecchini 0:9fca2b23d0ba 106 toolchain - the toolchain that the profile should be extracted for
marcozecchini 0:9fca2b23d0ba 107 """
marcozecchini 0:9fca2b23d0ba 108 profiles = []
marcozecchini 0:9fca2b23d0ba 109 filenames = options.profile or [join(dirname(__file__), "profiles",
marcozecchini 0:9fca2b23d0ba 110 fallback + ".json")]
marcozecchini 0:9fca2b23d0ba 111 for filename in filenames:
marcozecchini 0:9fca2b23d0ba 112 contents = load(open(filename))
marcozecchini 0:9fca2b23d0ba 113 if toolchain not in contents:
marcozecchini 0:9fca2b23d0ba 114 args_error(parser, ("argument --profile: toolchain {} is not"
marcozecchini 0:9fca2b23d0ba 115 " supported by profile {}").format(toolchain,
marcozecchini 0:9fca2b23d0ba 116 filename))
marcozecchini 0:9fca2b23d0ba 117 profiles.append(contents)
marcozecchini 0:9fca2b23d0ba 118
marcozecchini 0:9fca2b23d0ba 119 return profiles
marcozecchini 0:9fca2b23d0ba 120
marcozecchini 0:9fca2b23d0ba 121 def mcu_is_enabled(parser, mcu):
marcozecchini 0:9fca2b23d0ba 122 if "Cortex-A" in TARGET_MAP[mcu].core:
marcozecchini 0:9fca2b23d0ba 123 args_error(
marcozecchini 0:9fca2b23d0ba 124 parser,
marcozecchini 0:9fca2b23d0ba 125 ("%s Will be supported in mbed OS 5.6. "
marcozecchini 0:9fca2b23d0ba 126 "To use the %s, please checkout the mbed OS 5.4 release branch. "
marcozecchini 0:9fca2b23d0ba 127 "See https://developer.mbed.org/platforms/Renesas-GR-PEACH/#important-notice "
marcozecchini 0:9fca2b23d0ba 128 "for more information") % (mcu, mcu))
marcozecchini 0:9fca2b23d0ba 129 return True
marcozecchini 0:9fca2b23d0ba 130
marcozecchini 0:9fca2b23d0ba 131 def extract_mcus(parser, options):
marcozecchini 0:9fca2b23d0ba 132 try:
marcozecchini 0:9fca2b23d0ba 133 if options.source_dir:
marcozecchini 0:9fca2b23d0ba 134 for source_dir in options.source_dir:
marcozecchini 0:9fca2b23d0ba 135 Target.add_extra_targets(source_dir)
marcozecchini 0:9fca2b23d0ba 136 update_target_data()
marcozecchini 0:9fca2b23d0ba 137 except KeyError:
marcozecchini 0:9fca2b23d0ba 138 pass
marcozecchini 0:9fca2b23d0ba 139 targetnames = TARGET_NAMES
marcozecchini 0:9fca2b23d0ba 140 targetnames.sort()
marcozecchini 0:9fca2b23d0ba 141 try:
marcozecchini 0:9fca2b23d0ba 142 return argparse_many(argparse_force_uppercase_type(targetnames, "MCU"))(options.mcu)
marcozecchini 0:9fca2b23d0ba 143 except ArgumentTypeError as exc:
marcozecchini 0:9fca2b23d0ba 144 args_error(parser, "argument -m/--mcu: {}".format(str(exc)))
marcozecchini 0:9fca2b23d0ba 145