1
0
Fork 0

Squashed 'tmk_core/' changes from 7967731..b9e0ea0

b9e0ea0 Merge commit '7fa9d8bdea3773d1195b04d98fcf27cf48ddd81d' as 'tool/mbed/mbed-sdk'
7fa9d8b Squashed 'tool/mbed/mbed-sdk/' content from commit 7c21ce5

git-subtree-dir: tmk_core
git-subtree-split: b9e0ea08cb940de20b3610ecdda18e9d8cd7c552
This commit is contained in:
Jun Wako 2015-04-24 16:26:14 +09:00
parent a20ef7052c
commit 1fe4406f37
4198 changed files with 2016457 additions and 0 deletions

View file

@ -0,0 +1,16 @@
"""
mbed SDK
Copyright (c) 2011-2013 ARM Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View file

@ -0,0 +1,89 @@
"""
mbed SDK
Copyright (c) 2011-2013 ARM Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from numpy import sin, arange, pi
from scipy.signal import lfilter, firwin
from pylab import figure, plot, grid, show
#------------------------------------------------
# Create a signal for demonstration.
#------------------------------------------------
# 320 samples of (1000Hz + 15000 Hz) at 48 kHz
sample_rate = 48000.
nsamples = 320
F_1KHz = 1000.
A_1KHz = 1.0
F_15KHz = 15000.
A_15KHz = 0.5
t = arange(nsamples) / sample_rate
signal = A_1KHz * sin(2*pi*F_1KHz*t) + A_15KHz*sin(2*pi*F_15KHz*t)
#------------------------------------------------
# Create a FIR filter and apply it to signal.
#------------------------------------------------
# The Nyquist rate of the signal.
nyq_rate = sample_rate / 2.
# The cutoff frequency of the filter: 6KHz
cutoff_hz = 6000.0
# Length of the filter (number of coefficients, i.e. the filter order + 1)
numtaps = 29
# Use firwin to create a lowpass FIR filter
fir_coeff = firwin(numtaps, cutoff_hz/nyq_rate)
# Use lfilter to filter the signal with the FIR filter
filtered_signal = lfilter(fir_coeff, 1.0, signal)
#------------------------------------------------
# Plot the original and filtered signals.
#------------------------------------------------
# The first N-1 samples are "corrupted" by the initial conditions
warmup = numtaps - 1
# The phase delay of the filtered signal
delay = (warmup / 2) / sample_rate
figure(1)
# Plot the original signal
plot(t, signal)
# Plot the filtered signal, shifted to compensate for the phase delay
plot(t-delay, filtered_signal, 'r-')
# Plot just the "good" part of the filtered signal. The first N-1
# samples are "corrupted" by the initial conditions.
plot(t[warmup:]-delay, filtered_signal[warmup:], 'g', linewidth=4)
grid(True)
show()
#------------------------------------------------
# Print values
#------------------------------------------------
def print_values(label, values):
var = "float32_t %s[%d]" % (label, len(values))
print "%-30s = {%s}" % (var, ', '.join(["%+.10f" % x for x in values]))
print_values('signal', signal)
print_values('fir_coeff', fir_coeff)
print_values('filtered_signal', filtered_signal)

View file

@ -0,0 +1,31 @@
from intelhex import IntelHex
from cStringIO import StringIO
def sections(h):
start, last_address = None, None
for a in h.addresses():
if last_address is None:
start, last_address = a, a
continue
if a > last_address + 1:
yield (start, last_address)
start = a
last_address = a
if start:
yield (start, last_address)
def print_sections(h):
for s in sections(h):
print "[0x%08X - 0x%08X]" % s
def decode(record):
h = IntelHex()
f = StringIO(record)
h.loadhex(f)
h.dump()

View file

@ -0,0 +1,190 @@
"""
mbed SDK
Copyright (c) 2011-2013 ARM Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from os.path import join
from jinja2 import Template
from workspace_tools.paths import TOOLS_DATA, MBED_RPC
RPC_TEMPLATES_PATH = join(TOOLS_DATA, "rpc")
RPC_TEMPLATE = "RPCClasses.h"
CLASS_TEMPLATE = "class.cpp"
RPC_CLASSES_PATH = join(MBED_RPC, RPC_TEMPLATE)
def get_template(name):
return Template(open(join(RPC_TEMPLATES_PATH, name)).read())
def write_rpc_classes(classes):
template = get_template(RPC_TEMPLATE)
open(RPC_CLASSES_PATH, "w").write(template.render({"classes":classes}))
RPC_CLASSES = (
{
"name": "DigitalOut",
"cons_args": ["PinName"],
"methods": [
(None , "write", ["int"]),
("int", "read" , []),
]
},
{
"name": "DigitalIn",
"cons_args": ["PinName"],
"methods": [
("int", "read" , []),
]
},
{
"name": "DigitalInOut",
"cons_args": ["PinName"],
"methods": [
("int", "read" , []),
(None , "write" , ["int"]),
(None , "input" , []),
(None , "output", []),
]
},
{
"name": "AnalogIn",
"required": "ANALOGIN",
"cons_args": ["PinName"],
"methods": [
("float" , "read" , []),
("unsigned short", "read_u16", []),
]
},
{
"name": "AnalogOut",
"required": "ANALOGOUT",
"cons_args": ["PinName"],
"methods": [
("float", "read" , []),
(None , "write" , ["float"]),
(None , "write_u16", ["unsigned short"]),
]
},
{
"name": "PwmOut",
"required": "PWMOUT",
"cons_args": ["PinName"],
"methods": [
("float", "read" , []),
(None , "write" , ["float"]),
(None , "period" , ["float"]),
(None , "period_ms" , ["int"]),
(None , "pulsewidth" , ["float"]),
(None , "pulsewidth_ms", ["int"]),
]
},
{
"name": "SPI",
"required": "SPI",
"cons_args": ["PinName", "PinName", "PinName"],
"methods": [
(None , "format" , ["int", "int"]),
(None , "frequency", ["int"]),
("int", "write" , ["int"]),
]
},
{
"name": "Serial",
"required": "SERIAL",
"cons_args": ["PinName", "PinName"],
"methods": [
(None , "baud" , ["int"]),
("int", "readable" , []),
("int", "writeable", []),
("int", "putc" , ["int"]),
("int", "getc" , []),
("int", "puts" , ["const char *"]),
]
},
{
"name": "Timer",
"cons_args": [],
"methods": [
(None , "start" , []),
(None , "stop" , []),
(None , "reset" , []),
("float", "read" , []),
("int" , "read_ms", []),
("int" , "read_us", []),
]
}
)
def get_args_proto(args_types, extra=None):
args = ["%s a%d" % (s, n) for n, s in enumerate(args_types)]
if extra:
args.extend(extra)
return ', '.join(args)
def get_args_call(args):
return ', '.join(["a%d" % (n) for n in range(len(args))])
classes = []
class_template = get_template(CLASS_TEMPLATE)
for c in RPC_CLASSES:
c_args = c['cons_args']
data = {
'name': c['name'],
'cons_type': ', '.join(c_args + ['const char*']),
"cons_proto": get_args_proto(c_args, ["const char *name=NULL"]),
"cons_call": get_args_call(c_args)
}
c_name = "Rpc" + c['name']
methods = []
rpc_methods = []
for r, m, a in c['methods']:
ret_proto = r if r else "void"
args_proto = "void"
ret_defin = "return " if r else ""
args_defin = ""
if a:
args_proto = get_args_proto(a)
args_defin = get_args_call(a)
proto = "%s %s(%s)" % (ret_proto, m, args_proto)
defin = "{%so.%s(%s);}" % (ret_defin, m, args_defin)
methods.append("%s %s" % (proto, defin))
rpc_method_type = [r] if r else []
rpc_method_type.append(c_name)
rpc_method_type.extend(a)
rpc_methods.append('{"%s", rpc_method_caller<%s, &%s::%s>}' % (m, ', '.join(rpc_method_type), c_name, m))
data['methods'] = "\n ".join(methods)
data['rpc_methods'] = ",\n ".join(rpc_methods)
class_decl = class_template.render(data)
if 'required' in c:
class_decl = "#if DEVICE_%s\n%s\n#endif" % (c['required'], class_decl)
classes.append(class_decl)
write_rpc_classes('\n\n'.join(classes))

View file

@ -0,0 +1,75 @@
"""
mbed SDK
Copyright (c) 2011-2013 ARM Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Utility to find which libraries could define a given symbol
"""
from argparse import ArgumentParser
from os.path import join, splitext
from os import walk
from subprocess import Popen, PIPE
OBJ_EXT = ['.o', '.a', '.ar']
def find_sym_in_lib(sym, obj_path):
contain_symbol = False
out = Popen(["nm", "-C", obj_path], stdout=PIPE, stderr=PIPE).communicate()[0]
for line in out.splitlines():
tokens = line.split()
n = len(tokens)
if n == 2:
sym_type = tokens[0]
sym_name = tokens[1]
elif n == 3:
sym_type = tokens[1]
sym_name = tokens[2]
else:
continue
if sym_type == "U":
# This object is using this symbol, not defining it
continue
if sym_name == sym:
contain_symbol = True
return contain_symbol
def find_sym_in_path(sym, dir_path):
for root, _, files in walk(dir_path):
for file in files:
_, ext = splitext(file)
if ext not in OBJ_EXT: continue
path = join(root, file)
if find_sym_in_lib(sym, path):
print path
if __name__ == '__main__':
parser = ArgumentParser(description='Find Symbol')
parser.add_argument('-s', '--sym', required=True,
help='The symbol to be searched')
parser.add_argument('-p', '--path', required=True,
help='The path where to search')
args = parser.parse_args()
find_sym_in_path(args.sym, args.path)