mbed os with nrf51 internal bandgap enabled to read battery level

Dependents:   BLE_file_test BLE_Blink ExternalEncoder

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

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