dhgdh

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by joey shelton

Committer:
cyberjoey
Date:
Sat Oct 22 01:31:58 2016 +0000
Revision:
9:6bb35cef007d
Parent:
1:55a6170b404f
WORKING

Who changed what in which revision?

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