mbed-os for GR-LYCHEE
Dependents: mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more
tools/export/simplicity/__init__.py@0:f782d9c66c49, 2018-02-02 (annotated)
- Committer:
- dkato
- Date:
- Fri Feb 02 05:42:23 2018 +0000
- Revision:
- 0:f782d9c66c49
mbed-os for GR-LYCHEE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 0:f782d9c66c49 | 1 | """ |
dkato | 0:f782d9c66c49 | 2 | mbed SDK |
dkato | 0:f782d9c66c49 | 3 | Copyright (c) 2014-2016 ARM Limited |
dkato | 0:f782d9c66c49 | 4 | |
dkato | 0:f782d9c66c49 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
dkato | 0:f782d9c66c49 | 6 | you may not use this file except in compliance with the License. |
dkato | 0:f782d9c66c49 | 7 | You may obtain a copy of the License at |
dkato | 0:f782d9c66c49 | 8 | |
dkato | 0:f782d9c66c49 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
dkato | 0:f782d9c66c49 | 10 | |
dkato | 0:f782d9c66c49 | 11 | Unless required by applicable law or agreed to in writing, software |
dkato | 0:f782d9c66c49 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
dkato | 0:f782d9c66c49 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
dkato | 0:f782d9c66c49 | 14 | See the License for the specific language governing permissions and |
dkato | 0:f782d9c66c49 | 15 | limitations under the License. |
dkato | 0:f782d9c66c49 | 16 | """ |
dkato | 0:f782d9c66c49 | 17 | from os.path import split,splitext, basename |
dkato | 0:f782d9c66c49 | 18 | |
dkato | 0:f782d9c66c49 | 19 | from tools.export.exporters import Exporter |
dkato | 0:f782d9c66c49 | 20 | |
dkato | 0:f782d9c66c49 | 21 | class Folder: |
dkato | 0:f782d9c66c49 | 22 | def __init__(self, name): |
dkato | 0:f782d9c66c49 | 23 | self.name = name |
dkato | 0:f782d9c66c49 | 24 | self.children = [] |
dkato | 0:f782d9c66c49 | 25 | |
dkato | 0:f782d9c66c49 | 26 | def contains(self, folderName): |
dkato | 0:f782d9c66c49 | 27 | for child in self.children: |
dkato | 0:f782d9c66c49 | 28 | if child.name == folderName: |
dkato | 0:f782d9c66c49 | 29 | return True |
dkato | 0:f782d9c66c49 | 30 | return False |
dkato | 0:f782d9c66c49 | 31 | |
dkato | 0:f782d9c66c49 | 32 | def __str__(self): |
dkato | 0:f782d9c66c49 | 33 | retval = self.name + " " |
dkato | 0:f782d9c66c49 | 34 | if len(self.children) > 0: |
dkato | 0:f782d9c66c49 | 35 | retval += "[ " |
dkato | 0:f782d9c66c49 | 36 | for child in self.children: |
dkato | 0:f782d9c66c49 | 37 | retval += child.__str__() |
dkato | 0:f782d9c66c49 | 38 | retval += " ]" |
dkato | 0:f782d9c66c49 | 39 | |
dkato | 0:f782d9c66c49 | 40 | return retval |
dkato | 0:f782d9c66c49 | 41 | |
dkato | 0:f782d9c66c49 | 42 | def findChild(self, folderName): |
dkato | 0:f782d9c66c49 | 43 | for child in self.children: |
dkato | 0:f782d9c66c49 | 44 | if child.name == folderName: |
dkato | 0:f782d9c66c49 | 45 | return child |
dkato | 0:f782d9c66c49 | 46 | return None |
dkato | 0:f782d9c66c49 | 47 | |
dkato | 0:f782d9c66c49 | 48 | def addChild(self, folderName): |
dkato | 0:f782d9c66c49 | 49 | if folderName == '': |
dkato | 0:f782d9c66c49 | 50 | return None |
dkato | 0:f782d9c66c49 | 51 | |
dkato | 0:f782d9c66c49 | 52 | if not self.contains(folderName): |
dkato | 0:f782d9c66c49 | 53 | self.children.append(Folder(folderName)) |
dkato | 0:f782d9c66c49 | 54 | |
dkato | 0:f782d9c66c49 | 55 | return self.findChild(folderName) |
dkato | 0:f782d9c66c49 | 56 | |
dkato | 0:f782d9c66c49 | 57 | class SimplicityV3(Exporter): |
dkato | 0:f782d9c66c49 | 58 | NAME = 'SimplicityV3' |
dkato | 0:f782d9c66c49 | 59 | TOOLCHAIN = 'GCC_ARM' |
dkato | 0:f782d9c66c49 | 60 | |
dkato | 0:f782d9c66c49 | 61 | TARGETS = [ |
dkato | 0:f782d9c66c49 | 62 | 'EFM32GG_STK3700', |
dkato | 0:f782d9c66c49 | 63 | 'EFM32ZG_STK3200', |
dkato | 0:f782d9c66c49 | 64 | 'EFM32LG_STK3600', |
dkato | 0:f782d9c66c49 | 65 | 'EFM32WG_STK3800', |
dkato | 0:f782d9c66c49 | 66 | 'EFM32HG_STK3400', |
dkato | 0:f782d9c66c49 | 67 | 'EFM32PG_STK3401' |
dkato | 0:f782d9c66c49 | 68 | ] |
dkato | 0:f782d9c66c49 | 69 | |
dkato | 0:f782d9c66c49 | 70 | PARTS = { |
dkato | 0:f782d9c66c49 | 71 | 'EFM32GG_STK3700': 'com.silabs.mcu.si32.efm32.efm32gg.efm32gg990f1024', |
dkato | 0:f782d9c66c49 | 72 | 'EFM32ZG_STK3200': 'com.silabs.mcu.si32.efm32.efm32zg.efm32zg222f32', |
dkato | 0:f782d9c66c49 | 73 | 'EFM32LG_STK3600': 'com.silabs.mcu.si32.efm32.efm32lg.efm32lg990f256', |
dkato | 0:f782d9c66c49 | 74 | 'EFM32WG_STK3800': 'com.silabs.mcu.si32.efm32.efm32wg.efm32wg990f256', |
dkato | 0:f782d9c66c49 | 75 | 'EFM32HG_STK3400': 'com.silabs.mcu.si32.efm32.efm32hg.efm32hg322f64', |
dkato | 0:f782d9c66c49 | 76 | 'EFM32PG_STK3401': 'com.silabs.mcu.si32.efm32.efm32pg1b.efm32pg1b200f256gm48' |
dkato | 0:f782d9c66c49 | 77 | } |
dkato | 0:f782d9c66c49 | 78 | |
dkato | 0:f782d9c66c49 | 79 | KITS = { |
dkato | 0:f782d9c66c49 | 80 | 'EFM32GG_STK3700': 'com.silabs.kit.si32.efm32.efm32gg.stk3700', |
dkato | 0:f782d9c66c49 | 81 | 'EFM32ZG_STK3200': 'com.silabs.kit.si32.efm32.efm32zg.stk3200', |
dkato | 0:f782d9c66c49 | 82 | 'EFM32LG_STK3600': 'com.silabs.kit.si32.efm32.efm32lg.stk3600', |
dkato | 0:f782d9c66c49 | 83 | 'EFM32WG_STK3800': 'com.silabs.kit.si32.efm32.efm32wg.stk3800', |
dkato | 0:f782d9c66c49 | 84 | 'EFM32HG_STK3400': 'com.silabs.kit.si32.efm32.efm32hg.slstk3400a', |
dkato | 0:f782d9c66c49 | 85 | 'EFM32PG_STK3401': 'com.silabs.kit.si32.efm32.efm32pg.slstk3401a' |
dkato | 0:f782d9c66c49 | 86 | } |
dkato | 0:f782d9c66c49 | 87 | |
dkato | 0:f782d9c66c49 | 88 | FILE_TYPES = { |
dkato | 0:f782d9c66c49 | 89 | 'c_sources':'1', |
dkato | 0:f782d9c66c49 | 90 | 'cpp_sources':'1', |
dkato | 0:f782d9c66c49 | 91 | 's_sources':'1' |
dkato | 0:f782d9c66c49 | 92 | } |
dkato | 0:f782d9c66c49 | 93 | |
dkato | 0:f782d9c66c49 | 94 | EXCLUDED_LIBS = [ |
dkato | 0:f782d9c66c49 | 95 | 'm', |
dkato | 0:f782d9c66c49 | 96 | 'c', |
dkato | 0:f782d9c66c49 | 97 | 'gcc', |
dkato | 0:f782d9c66c49 | 98 | 'nosys', |
dkato | 0:f782d9c66c49 | 99 | 'supc++', |
dkato | 0:f782d9c66c49 | 100 | 'stdc++' |
dkato | 0:f782d9c66c49 | 101 | ] |
dkato | 0:f782d9c66c49 | 102 | |
dkato | 0:f782d9c66c49 | 103 | DOT_IN_RELATIVE_PATH = False |
dkato | 0:f782d9c66c49 | 104 | |
dkato | 0:f782d9c66c49 | 105 | MBED_CONFIG_HEADER_SUPPORTED = True |
dkato | 0:f782d9c66c49 | 106 | |
dkato | 0:f782d9c66c49 | 107 | orderedPaths = Folder("Root") |
dkato | 0:f782d9c66c49 | 108 | |
dkato | 0:f782d9c66c49 | 109 | def check_and_add_path(self, path): |
dkato | 0:f782d9c66c49 | 110 | levels = path.split('/') |
dkato | 0:f782d9c66c49 | 111 | base = self.orderedPaths |
dkato | 0:f782d9c66c49 | 112 | for level in levels: |
dkato | 0:f782d9c66c49 | 113 | if base.contains(level): |
dkato | 0:f782d9c66c49 | 114 | base = base.findChild(level) |
dkato | 0:f782d9c66c49 | 115 | else: |
dkato | 0:f782d9c66c49 | 116 | base.addChild(level) |
dkato | 0:f782d9c66c49 | 117 | base = base.findChild(level) |
dkato | 0:f782d9c66c49 | 118 | |
dkato | 0:f782d9c66c49 | 119 | |
dkato | 0:f782d9c66c49 | 120 | def generate(self): |
dkato | 0:f782d9c66c49 | 121 | # "make" wants Unix paths |
dkato | 0:f782d9c66c49 | 122 | self.resources.win_to_unix() |
dkato | 0:f782d9c66c49 | 123 | |
dkato | 0:f782d9c66c49 | 124 | main_files = [] |
dkato | 0:f782d9c66c49 | 125 | |
dkato | 0:f782d9c66c49 | 126 | EXCLUDED_LIBS = [ |
dkato | 0:f782d9c66c49 | 127 | 'm', |
dkato | 0:f782d9c66c49 | 128 | 'c', |
dkato | 0:f782d9c66c49 | 129 | 'gcc', |
dkato | 0:f782d9c66c49 | 130 | 'nosys', |
dkato | 0:f782d9c66c49 | 131 | 'supc++', |
dkato | 0:f782d9c66c49 | 132 | 'stdc++' |
dkato | 0:f782d9c66c49 | 133 | ] |
dkato | 0:f782d9c66c49 | 134 | |
dkato | 0:f782d9c66c49 | 135 | for r_type in ['s_sources', 'c_sources', 'cpp_sources']: |
dkato | 0:f782d9c66c49 | 136 | r = getattr(self.resources, r_type) |
dkato | 0:f782d9c66c49 | 137 | if r: |
dkato | 0:f782d9c66c49 | 138 | for source in r: |
dkato | 0:f782d9c66c49 | 139 | self.check_and_add_path(split(source)[0]) |
dkato | 0:f782d9c66c49 | 140 | |
dkato | 0:f782d9c66c49 | 141 | if not ('/' in source): |
dkato | 0:f782d9c66c49 | 142 | main_files.append(source) |
dkato | 0:f782d9c66c49 | 143 | |
dkato | 0:f782d9c66c49 | 144 | libraries = [] |
dkato | 0:f782d9c66c49 | 145 | for lib in self.resources.libraries: |
dkato | 0:f782d9c66c49 | 146 | l, _ = splitext(basename(lib)) |
dkato | 0:f782d9c66c49 | 147 | if l[3:] not in EXCLUDED_LIBS: |
dkato | 0:f782d9c66c49 | 148 | libraries.append(l[3:]) |
dkato | 0:f782d9c66c49 | 149 | |
dkato | 0:f782d9c66c49 | 150 | defines = [] |
dkato | 0:f782d9c66c49 | 151 | for define in self.toolchain.get_symbols(): |
dkato | 0:f782d9c66c49 | 152 | if '=' in define: |
dkato | 0:f782d9c66c49 | 153 | keyval = define.split('=') |
dkato | 0:f782d9c66c49 | 154 | defines.append( (keyval[0], keyval[1]) ) |
dkato | 0:f782d9c66c49 | 155 | else: |
dkato | 0:f782d9c66c49 | 156 | defines.append( (define, '') ) |
dkato | 0:f782d9c66c49 | 157 | |
dkato | 0:f782d9c66c49 | 158 | self.check_and_add_path(split(self.resources.linker_script)[0]) |
dkato | 0:f782d9c66c49 | 159 | |
dkato | 0:f782d9c66c49 | 160 | ctx = { |
dkato | 0:f782d9c66c49 | 161 | 'name': self.project_name, |
dkato | 0:f782d9c66c49 | 162 | 'main_files': main_files, |
dkato | 0:f782d9c66c49 | 163 | 'recursiveFolders': self.orderedPaths, |
dkato | 0:f782d9c66c49 | 164 | 'object_files': self.resources.objects, |
dkato | 0:f782d9c66c49 | 165 | 'include_paths': self.resources.inc_dirs, |
dkato | 0:f782d9c66c49 | 166 | 'library_paths': self.resources.lib_dirs, |
dkato | 0:f782d9c66c49 | 167 | 'linker_script': self.resources.linker_script, |
dkato | 0:f782d9c66c49 | 168 | 'libraries': libraries, |
dkato | 0:f782d9c66c49 | 169 | 'defines': defines, |
dkato | 0:f782d9c66c49 | 170 | 'part': self.PARTS[self.target], |
dkato | 0:f782d9c66c49 | 171 | 'kit': self.KITS[self.target], |
dkato | 0:f782d9c66c49 | 172 | 'loopcount': 0 |
dkato | 0:f782d9c66c49 | 173 | } |
dkato | 0:f782d9c66c49 | 174 | ctx.update(self.flags) |
dkato | 0:f782d9c66c49 | 175 | |
dkato | 0:f782d9c66c49 | 176 | ## Strip main folder from include paths because ssproj is not capable of handling it |
dkato | 0:f782d9c66c49 | 177 | if '.' in ctx['include_paths']: |
dkato | 0:f782d9c66c49 | 178 | ctx['include_paths'].remove('.') |
dkato | 0:f782d9c66c49 | 179 | ctx['include_root'] = True |
dkato | 0:f782d9c66c49 | 180 | |
dkato | 0:f782d9c66c49 | 181 | ''' |
dkato | 0:f782d9c66c49 | 182 | Suppress print statements |
dkato | 0:f782d9c66c49 | 183 | print('\n') |
dkato | 0:f782d9c66c49 | 184 | print(self.target) |
dkato | 0:f782d9c66c49 | 185 | print('\n') |
dkato | 0:f782d9c66c49 | 186 | print(ctx) |
dkato | 0:f782d9c66c49 | 187 | print('\n') |
dkato | 0:f782d9c66c49 | 188 | print(self.orderedPaths) |
dkato | 0:f782d9c66c49 | 189 | for path in self.orderedPaths.children: |
dkato | 0:f782d9c66c49 | 190 | print(path.name + "\n") |
dkato | 0:f782d9c66c49 | 191 | for bpath in path.children: |
dkato | 0:f782d9c66c49 | 192 | print("\t" + bpath.name + "\n") |
dkato | 0:f782d9c66c49 | 193 | ''' |
dkato | 0:f782d9c66c49 | 194 | |
dkato | 0:f782d9c66c49 | 195 | self.gen_file('simplicity/slsproj.tmpl', ctx, '%s.slsproj' % self.project_name) |