Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bryantaylor 0:eafc3fd41f75 1 """
bryantaylor 0:eafc3fd41f75 2 mbed SDK
bryantaylor 0:eafc3fd41f75 3 Copyright (c) 2011-2016 ARM Limited
bryantaylor 0:eafc3fd41f75 4
bryantaylor 0:eafc3fd41f75 5 Licensed under the Apache License, Version 2.0 (the "License");
bryantaylor 0:eafc3fd41f75 6 you may not use this file except in compliance with the License.
bryantaylor 0:eafc3fd41f75 7 You may obtain a copy of the License at
bryantaylor 0:eafc3fd41f75 8
bryantaylor 0:eafc3fd41f75 9 http://www.apache.org/licenses/LICENSE-2.0
bryantaylor 0:eafc3fd41f75 10
bryantaylor 0:eafc3fd41f75 11 Unless required by applicable law or agreed to in writing, software
bryantaylor 0:eafc3fd41f75 12 distributed under the License is distributed on an "AS IS" BASIS,
bryantaylor 0:eafc3fd41f75 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
bryantaylor 0:eafc3fd41f75 14 See the License for the specific language governing permissions and
bryantaylor 0:eafc3fd41f75 15 limitations under the License.
bryantaylor 0:eafc3fd41f75 16 """
bryantaylor 0:eafc3fd41f75 17 import re
bryantaylor 0:eafc3fd41f75 18 import os
bryantaylor 0:eafc3fd41f75 19 from project_generator_definitions.definitions import ProGenDef
bryantaylor 0:eafc3fd41f75 20
bryantaylor 0:eafc3fd41f75 21 from tools.export.exporters import Exporter, ExporterTargetsProperty
bryantaylor 0:eafc3fd41f75 22 from tools.targets import TARGET_MAP, TARGET_NAMES
bryantaylor 0:eafc3fd41f75 23
bryantaylor 0:eafc3fd41f75 24 # If you wish to add a new target, add it to project_generator_definitions, and then
bryantaylor 0:eafc3fd41f75 25 # define progen_target name in the target class (`` self.progen_target = 'my_target_name' ``)
bryantaylor 0:eafc3fd41f75 26 class IAREmbeddedWorkbench(Exporter):
bryantaylor 0:eafc3fd41f75 27 """
bryantaylor 0:eafc3fd41f75 28 Exporter class for IAR Systems. This class uses project generator.
bryantaylor 0:eafc3fd41f75 29 """
bryantaylor 0:eafc3fd41f75 30 # These 2 are currently for exporters backward compatiblity
bryantaylor 0:eafc3fd41f75 31 NAME = 'iar_arm'
bryantaylor 0:eafc3fd41f75 32 TOOLCHAIN = 'IAR'
bryantaylor 0:eafc3fd41f75 33 # PROGEN_ACTIVE contains information for exporter scripts that this is using progen
bryantaylor 0:eafc3fd41f75 34 PROGEN_ACTIVE = True
bryantaylor 0:eafc3fd41f75 35
bryantaylor 0:eafc3fd41f75 36 MBED_CONFIG_HEADER_SUPPORTED = True
bryantaylor 0:eafc3fd41f75 37
bryantaylor 0:eafc3fd41f75 38 @ExporterTargetsProperty
bryantaylor 0:eafc3fd41f75 39 def TARGETS(cls):
bryantaylor 0:eafc3fd41f75 40 if not hasattr(cls, "_targets_supported"):
bryantaylor 0:eafc3fd41f75 41 cls._targets_supported = []
bryantaylor 0:eafc3fd41f75 42 progendef = ProGenDef('iar')
bryantaylor 0:eafc3fd41f75 43 for target in TARGET_NAMES:
bryantaylor 0:eafc3fd41f75 44 try:
bryantaylor 0:eafc3fd41f75 45 if (progendef.is_supported(str(TARGET_MAP[target])) or
bryantaylor 0:eafc3fd41f75 46 progendef.is_supported(TARGET_MAP[target].progen['target'])):
bryantaylor 0:eafc3fd41f75 47 cls._targets_supported.append(target)
bryantaylor 0:eafc3fd41f75 48 except AttributeError:
bryantaylor 0:eafc3fd41f75 49 # target is not supported yet
bryantaylor 0:eafc3fd41f75 50 continue
bryantaylor 0:eafc3fd41f75 51 return cls._targets_supported
bryantaylor 0:eafc3fd41f75 52
bryantaylor 0:eafc3fd41f75 53 def generate(self):
bryantaylor 0:eafc3fd41f75 54 """ Generates the project files """
bryantaylor 0:eafc3fd41f75 55 project_data = self.progen_get_project_data()
bryantaylor 0:eafc3fd41f75 56 try:
bryantaylor 0:eafc3fd41f75 57 if TARGET_MAP[self.target].progen['iar']['template']:
bryantaylor 0:eafc3fd41f75 58 project_data['template']=TARGET_MAP[self.target].progen['iar']['template']
bryantaylor 0:eafc3fd41f75 59 except KeyError:
bryantaylor 0:eafc3fd41f75 60 # use default template
bryantaylor 0:eafc3fd41f75 61 # by the mbed projects
bryantaylor 0:eafc3fd41f75 62 project_data['template']=[os.path.join(os.path.dirname(__file__), 'iar_template.ewp.tmpl')]
bryantaylor 0:eafc3fd41f75 63
bryantaylor 0:eafc3fd41f75 64 project_data['misc'] = self.flags
bryantaylor 0:eafc3fd41f75 65 # VLA is enabled via template IccAllowVLA
bryantaylor 0:eafc3fd41f75 66 project_data['misc']['c_flags'].remove("--vla")
bryantaylor 0:eafc3fd41f75 67 project_data['misc']['asm_flags'] = list(set(project_data['misc']['asm_flags']))
bryantaylor 0:eafc3fd41f75 68 project_data['build_dir'] = os.path.join(project_data['build_dir'], 'iar_arm')
bryantaylor 0:eafc3fd41f75 69 self.progen_gen_file(project_data)
bryantaylor 0:eafc3fd41f75 70
bryantaylor 0:eafc3fd41f75 71 # Currently not used, we should reuse folder_name to create virtual folders
bryantaylor 0:eafc3fd41f75 72 class IarFolder():
bryantaylor 0:eafc3fd41f75 73 """
bryantaylor 0:eafc3fd41f75 74 This is a recursive folder object.
bryantaylor 0:eafc3fd41f75 75 To present the folder structure in the IDE as it is presented on the disk.
bryantaylor 0:eafc3fd41f75 76 This can be used for uvision as well if you replace the __str__ method.
bryantaylor 0:eafc3fd41f75 77 Example:
bryantaylor 0:eafc3fd41f75 78 files: ./main.cpp, ./apis/I2C.h, ./mbed/common/I2C.cpp
bryantaylor 0:eafc3fd41f75 79 in the project this would look like:
bryantaylor 0:eafc3fd41f75 80 main.cpp
bryantaylor 0:eafc3fd41f75 81 common/I2C.cpp
bryantaylor 0:eafc3fd41f75 82 input:
bryantaylor 0:eafc3fd41f75 83 folder_level : folder path to current folder
bryantaylor 0:eafc3fd41f75 84 folder_name : name of current folder
bryantaylor 0:eafc3fd41f75 85 source_files : list of source_files (all must be in same directory)
bryantaylor 0:eafc3fd41f75 86 """
bryantaylor 0:eafc3fd41f75 87 def __init__(self, folder_level, folder_name, source_files):
bryantaylor 0:eafc3fd41f75 88 self.folder_level = folder_level
bryantaylor 0:eafc3fd41f75 89 self.folder_name = folder_name
bryantaylor 0:eafc3fd41f75 90 self.source_files = source_files
bryantaylor 0:eafc3fd41f75 91 self.sub_folders = {}
bryantaylor 0:eafc3fd41f75 92
bryantaylor 0:eafc3fd41f75 93 def __str__(self):
bryantaylor 0:eafc3fd41f75 94 """
bryantaylor 0:eafc3fd41f75 95 converts the folder structue to IAR project format.
bryantaylor 0:eafc3fd41f75 96 """
bryantaylor 0:eafc3fd41f75 97 group_start = ""
bryantaylor 0:eafc3fd41f75 98 group_end = ""
bryantaylor 0:eafc3fd41f75 99 if self.folder_name != "":
bryantaylor 0:eafc3fd41f75 100 group_start = "<group>\n<name>%s</name>\n" %(self.folder_name)
bryantaylor 0:eafc3fd41f75 101 group_end = "</group>\n"
bryantaylor 0:eafc3fd41f75 102
bryantaylor 0:eafc3fd41f75 103 str_content = group_start
bryantaylor 0:eafc3fd41f75 104 #Add files in current folder
bryantaylor 0:eafc3fd41f75 105 if self.source_files:
bryantaylor 0:eafc3fd41f75 106 for src in self.source_files:
bryantaylor 0:eafc3fd41f75 107 str_content += "<file>\n<name>$PROJ_DIR$/%s</name>\n</file>\n" % src
bryantaylor 0:eafc3fd41f75 108 #Add sub folders
bryantaylor 0:eafc3fd41f75 109 if self.sub_folders:
bryantaylor 0:eafc3fd41f75 110 for folder_name in self.sub_folders.iterkeys():
bryantaylor 0:eafc3fd41f75 111 str_content += self.sub_folders[folder_name].__str__()
bryantaylor 0:eafc3fd41f75 112
bryantaylor 0:eafc3fd41f75 113 str_content += group_end
bryantaylor 0:eafc3fd41f75 114 return str_content
bryantaylor 0:eafc3fd41f75 115
bryantaylor 0:eafc3fd41f75 116 def insert_file(self, source_input):
bryantaylor 0:eafc3fd41f75 117 """
bryantaylor 0:eafc3fd41f75 118 Inserts a source file into the folder tree
bryantaylor 0:eafc3fd41f75 119 """
bryantaylor 0:eafc3fd41f75 120 if self.source_files:
bryantaylor 0:eafc3fd41f75 121 #All source_files in a IarFolder must be in same directory.
bryantaylor 0:eafc3fd41f75 122 dir_sources = IarFolder.get_directory(self.source_files[0])
bryantaylor 0:eafc3fd41f75 123 #Check if sources are already at their deepest level.
bryantaylor 0:eafc3fd41f75 124 if not self.folder_level == dir_sources:
bryantaylor 0:eafc3fd41f75 125 _reg_exp = r"^" + re.escape(self.folder_level) + r"[/\\]?([^/\\]+)"
bryantaylor 0:eafc3fd41f75 126 folder_name = re.match(_reg_exp, dir_sources).group(1)
bryantaylor 0:eafc3fd41f75 127 self.sub_folders[folder_name] = IarFolder(os.path.join(self.folder_level, folder_name), folder_name, self.source_files)
bryantaylor 0:eafc3fd41f75 128 self.source_files = []
bryantaylor 0:eafc3fd41f75 129
bryantaylor 0:eafc3fd41f75 130 dir_input = IarFolder.get_directory(source_input)
bryantaylor 0:eafc3fd41f75 131 if dir_input == self.folder_level:
bryantaylor 0:eafc3fd41f75 132 self.source_files.append(source_input)
bryantaylor 0:eafc3fd41f75 133 else:
bryantaylor 0:eafc3fd41f75 134 _reg_exp = r"^" + re.escape(self.folder_level) + r"[/\\]?([^/\\]+)"
bryantaylor 0:eafc3fd41f75 135 folder_name = re.match(_reg_exp, dir_input).group(1)
bryantaylor 0:eafc3fd41f75 136 if self.sub_folders.has_key(folder_name):
bryantaylor 0:eafc3fd41f75 137 self.sub_folders[folder_name].insert_file(source_input)
bryantaylor 0:eafc3fd41f75 138 else:
bryantaylor 0:eafc3fd41f75 139 if self.folder_level == "":
bryantaylor 0:eafc3fd41f75 140 #Top level exception
bryantaylor 0:eafc3fd41f75 141 self.sub_folders[folder_name] = IarFolder(folder_name, folder_name, [source_input])
bryantaylor 0:eafc3fd41f75 142 else:
bryantaylor 0:eafc3fd41f75 143 self.sub_folders[folder_name] = IarFolder(os.path.join(self.folder_level, folder_name), folder_name, [source_input])
bryantaylor 0:eafc3fd41f75 144
bryantaylor 0:eafc3fd41f75 145 @staticmethod
bryantaylor 0:eafc3fd41f75 146 def get_directory(file_path):
bryantaylor 0:eafc3fd41f75 147 """
bryantaylor 0:eafc3fd41f75 148 Returns the directory of the file
bryantaylor 0:eafc3fd41f75 149 """
bryantaylor 0:eafc3fd41f75 150 return os.path.dirname(file_path)