Alessandro Angelino / mbed-tools

Fork of mbed-tools by Morpheus

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers simplicityv3.py Source File

simplicityv3.py

00001 """
00002 mbed SDK
00003 Copyright (c) 2014 ARM Limited
00004 
00005 Licensed under the Apache License, Version 2.0 (the "License");
00006 you may not use this file except in compliance with the License.
00007 You may obtain a copy of the License at
00008 
00009     http://www.apache.org/licenses/LICENSE-2.0
00010 
00011 Unless required by applicable law or agreed to in writing, software
00012 distributed under the License is distributed on an "AS IS" BASIS,
00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 See the License for the specific language governing permissions and
00015 limitations under the License.
00016 """
00017 from exporters import Exporter
00018 from os.path import split,splitext, basename
00019 
00020 class Folder:
00021     def __init__(self, name):
00022         self.name = name
00023         self.children = []
00024 
00025     def contains(self, folderName):
00026         for child in self.children:
00027             if child.name == folderName:
00028                 return True
00029         return False
00030 
00031     def __str__(self):
00032         retval = self.name + " "
00033         if len(self.children) > 0:
00034             retval += "[ "
00035             for child in self.children:
00036                 retval += child.__str__()
00037             retval += " ]"
00038 
00039         return retval
00040 
00041     def findChild(self, folderName):
00042         for child in self.children:
00043             if child.name == folderName:
00044                 return child
00045         return None
00046 
00047     def addChild(self, folderName):
00048         if folderName == '':
00049             return None
00050 
00051         if not self.contains(folderName):
00052             self.children.append(Folder(folderName))
00053 
00054         return self.findChild(folderName)
00055 
00056 class SimplicityV3(Exporter):
00057     NAME = 'SimplicityV3'
00058     TOOLCHAIN = 'GCC_ARM'
00059 
00060     TARGETS = [
00061         'EFM32GG_STK3700',
00062         'EFM32ZG_STK3200',
00063         'EFM32LG_STK3600',
00064         'EFM32WG_STK3800',
00065         'EFM32HG_STK3400',
00066         'EFM32PG_STK3401'
00067     ]
00068 
00069     PARTS = {
00070         'EFM32GG_STK3700': 'com.silabs.mcu.si32.efm32.efm32gg.efm32gg990f1024',
00071         'EFM32ZG_STK3200': 'com.silabs.mcu.si32.efm32.efm32zg.efm32zg222f32',
00072         'EFM32LG_STK3600': 'com.silabs.mcu.si32.efm32.efm32lg.efm32lg990f256',
00073         'EFM32WG_STK3800': 'com.silabs.mcu.si32.efm32.efm32wg.efm32wg990f256',
00074         'EFM32HG_STK3400': 'com.silabs.mcu.si32.efm32.efm32hg.efm32hg322f64',
00075         'EFM32PG_STK3401': 'com.silabs.mcu.si32.efm32.efm32pg1b.efm32pg1b200f256gm48'
00076     }
00077 
00078     KITS = {
00079         'EFM32GG_STK3700': 'com.silabs.kit.si32.efm32.efm32gg.stk3700',
00080         'EFM32ZG_STK3200': 'com.silabs.kit.si32.efm32.efm32zg.stk3200',
00081         'EFM32LG_STK3600': 'com.silabs.kit.si32.efm32.efm32lg.stk3600',
00082         'EFM32WG_STK3800': 'com.silabs.kit.si32.efm32.efm32wg.stk3800',
00083         'EFM32HG_STK3400': 'com.silabs.kit.si32.efm32.efm32hg.slstk3400a',
00084         'EFM32PG_STK3401': 'com.silabs.kit.si32.efm32.efm32pg.slstk3401a'
00085     }
00086 
00087     FILE_TYPES = {
00088         'c_sources':'1',
00089         'cpp_sources':'1',
00090         's_sources':'1'
00091     }
00092 
00093     EXCLUDED_LIBS = [
00094         'm',
00095         'c',
00096         'gcc',
00097         'nosys',
00098         'supc++',
00099         'stdc++'
00100     ]
00101 
00102     DOT_IN_RELATIVE_PATH = False
00103 
00104     orderedPaths = Folder("Root")
00105 
00106     def check_and_add_path(self, path):
00107         levels = path.split('/')
00108         base = self.orderedPaths
00109         for level in levels:
00110             if base.contains(level):
00111                 base = base.findChild(level)
00112             else:
00113                 base.addChild(level)
00114                 base = base.findChild(level)
00115 
00116 
00117     def generate(self):
00118         # "make" wants Unix paths
00119         self.resources.win_to_unix()
00120 
00121         main_files = []
00122 
00123         EXCLUDED_LIBS = [
00124             'm',
00125             'c',
00126             'gcc',
00127             'nosys',
00128             'supc++',
00129             'stdc++'
00130         ]
00131 
00132         for r_type in ['s_sources', 'c_sources', 'cpp_sources']:
00133             r = getattr(self.resources, r_type)
00134             if r:
00135                 for source in r:
00136                     self.check_and_add_path(split(source)[0])
00137 
00138                     if not ('/' in source):
00139                         main_files.append(source)
00140 
00141         libraries = []
00142         for lib in self.resources.libraries:
00143             l, _ = splitext(basename(lib))
00144             if l[3:] not in EXCLUDED_LIBS:
00145                 libraries.append(l[3:])
00146 
00147         defines = []
00148         for define in self.get_symbols():
00149             if '=' in define:
00150                 keyval = define.split('=')
00151                 defines.append( (keyval[0], keyval[1]) )
00152             else:
00153                 defines.append( (define, '') )
00154 
00155         self.check_and_add_path(split(self.resources.linker_script)[0])
00156 
00157         ctx = {
00158             'name': self.program_name,
00159             'main_files': main_files,
00160             'recursiveFolders': self.orderedPaths,
00161             'object_files': self.resources.objects,
00162             'include_paths': self.resources.inc_dirs,
00163             'library_paths': self.resources.lib_dirs,
00164             'linker_script': self.resources.linker_script,
00165             'libraries': libraries,
00166             'symbols': self.get_symbols(),
00167             'defines': defines,
00168             'part': self.PARTS[self.target],
00169             'kit': self.KITS[self.target],
00170             'loopcount': 0
00171         }
00172 
00173         ## Strip main folder from include paths because ssproj is not capable of handling it
00174         if '.' in ctx['include_paths']:
00175             ctx['include_paths'].remove('.')
00176 
00177         '''
00178         Suppress print statements
00179         print('\n')
00180         print(self.target)
00181         print('\n')
00182         print(ctx)
00183         print('\n')
00184         print(self.orderedPaths)
00185         for path in self.orderedPaths.children:
00186             print(path.name + "\n")
00187             for bpath in path.children:
00188                 print("\t" + bpath.name + "\n")
00189         '''
00190 
00191         self.gen_file('simplicityv3_slsproj.tmpl', ctx, '%s.slsproj' % self.program_name)