Skip to content

Commit e46b659

Browse files
committed
Merge branch 'master' of https://github.com/mbedmicro/mbed into nrf51_port
2 parents c854d01 + d1ec4be commit e46b659

File tree

574 files changed

+151262
-110006
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

574 files changed

+151262
-110006
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ MANIFEST
1010
private_settings.py
1111

1212
# Default Build Directory
13-
build/
13+
.build/
1414
venv/
1515

1616
# Eclipse Project Files

.travis.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
---
21
python:
32
- "2.7"
3+
44
script: "python workspace_tools/build_travis.py"
5+
before_install:
6+
- sudo add-apt-repository -y ppa:terry.guo/gcc-arm-embedded
7+
- sudo apt-get update -qq
8+
- sudo apt-get install -qq gcc-arm-none-eabi --force-yes
9+
# Print versions we use
10+
- arm-none-eabi-gcc --version
11+
- python --version
512
install:
6-
- "sudo $TRAVIS_BUILD_DIR/travis/install_dependencies.sh > /dev/null"
713
- sudo pip install colorama
814
- sudo pip install prettytable
915
- sudo pip install jinja2

docs/mbed_targets.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Adding and configuring mbed targets
2+
3+
mbed uses JSON as a description language for its build targets. The JSON description of mbed targets can be found in `workspace_tools/targets.json`. To better understand how a target is defined, we'll use this example (taken from `targets.json`):
4+
5+
```
6+
"TEENSY3_1": {
7+
"inherits": ["Target"],
8+
"core": "Cortex-M4",
9+
"extra_labels": ["Freescale", "K20XX", "K20DX256"],
10+
"OUTPUT_EXT": "hex",
11+
"is_disk_virtual": true,
12+
"supported_toolchains": ["GCC_ARM", "ARM"],
13+
"post_binary_hook": {
14+
"function": "TEENSY3_1Code.binary_hook",
15+
"toolchains": ["ARM_STD", "ARM_MICRO", "GCC_ARM"]
16+
},
17+
"progen": {"target": "teensy-31"},
18+
"detect_code": ["0230"]
19+
```
20+
21+
The definition of the target called **TEENSY3_1** is a JSON object. The properties in the object are either "standard" (understood by the mbed build system) or specific to the target.
22+
23+
# Standard properties
24+
25+
This section lists all the properties that are known to the mbed build system. Unless specified otherwise, all properties are optional.
26+
27+
## inherits
28+
29+
The description of a mbed target can "inherit" from one of more descriptions of other targets. When a target **A** inherits from another target **B** (**A** is the _child_ of **B** and **B** is the _parent_ of **A**), it automatically "borrows" all the definitions of properties from **B** and can modify them as needed (if you're familiar with Python, this is very similar with how class inheritance works in Python). In our example above, `TEENSY3_1` inherits from `Target` (most mbed targets inherit from `Target`). This is how `Target` is defined:
30+
31+
```
32+
"Target": {
33+
"core": null,
34+
"default_toolchain": "ARM",
35+
"supported_toolchains": null,
36+
"extra_labels": [],
37+
"is_disk_virtual": false,
38+
"macros": [],
39+
"detect_code": [],
40+
"public": false
41+
}
42+
```
43+
44+
Since `TEENSY3_1` inherits from `Target`:
45+
46+
- `core` is a property defined both in `TEENSY3_1` and `Target`. Since `TEENSY3_1` redefines it, the value of `core` for `TEENSY3_1` will be `Cortex-M4`.
47+
- `default_toolchain` is not defined in `TEENSY3_1`, but since it is defined in `Target`, `TEENSY3_1` borrows it, so the value of `default_toolchain` for `TEENSY3_1` will be `ARM`.
48+
49+
A target can add properties that don't exist in its parent(s). For example, `OUTPUT_EXT` is defined in `TEENSY3_1`, but doesn't exist in `Target`.
50+
51+
It's possible to inherit from more than one target. For example:
52+
53+
```
54+
"ImaginaryTarget": {
55+
"inherits": ["Target", "TEENSY3_1"]
56+
}
57+
```
58+
59+
In this case, `ImaginaryTarget` inherits the properties of both `Target` and `TEENSY3_1`, so:
60+
61+
- the value of `ImaginaryTarget.default_toolchain` will be `ARM` (from `Target`)
62+
- the value of `ImaginaryTarget.OUTPUT_EXT` will be `hex` (from `TEENSY3_1`).
63+
- the value of `ImaginaryTarget.core` will be `null` (from `Target`, since that's the first parent of `ImaginaryTarget` that defines `core`).
64+
65+
Avoid using multiple inheritance for your targets if possible, since it can get pretty tricky to figure out how a property is inherited if multiple inheritance is used. If you have to use multiple inheritance, keep in mind that the mbed target description mechanism uses the old (pre 2.3) Python mechanism for finding the method resolution order:
66+
67+
- look for the property in the current target.
68+
- if not found, look for the property in the first target's parent, then in the parent of the parent and so on.
69+
- if not found, look for the property in the rest of the target's parents, relative to the current inheritance level.
70+
71+
For more details about the Python method resolution order, check for example [this link](http://makina-corpus.com/blog/metier/2014/python-tutorial-understanding-python-mro-class-search-path).
72+
73+
## core
74+
75+
The name of the ARM core used by the target.
76+
77+
Possible values: `"Cortex-M0"`, `"Cortex-M0+"`, `"Cortex-M1"`, `"Cortex-M3"`, `"Cortex-M4"`, `"Cortex-M4F"`, `"Cortex-M7"`, `"Cortex-M7F"`, `"Cortex-A9"`
78+
79+
## public
80+
81+
Some mbed targets might be defined solely for the purpose of serving as an inheritance base for other targets (as opposed to being used to build mbed code). When such a target is defined, its description must have the `public` property set to `false` to prevent the mbed build system from considering it as a build target. An example is the `Target` target shown in a previous paragraph.
82+
83+
If `public` is not defined for a target, it defaults to `true`.
84+
85+
Note that unlike other target properties, **the value of `public` is not inherited from a parent to its children**.
86+
87+
## macros, macros_add, macros_remove
88+
89+
The macros in this list will be defined when compiling mbed code. The macros can be defined with or without a value. For example, the declaration `"macros": ["NO_VALUE", "VALUE=10"]` will add these definitions to the compiler's command line: `-DNO_VALUE -DVALUE=10`.
90+
91+
When target inheritance is used, it's possible to alter the values of `macros` in inherited targets without re-defining `macros` completely:
92+
93+
- an inherited target can use `macros_add` to add its own macros.
94+
- an inherited target can use `macros_remove` to remove macros defined by its parents.
95+
96+
For example, in this configuration:
97+
98+
```
99+
"TargetA": {
100+
"macros": ["PARENT_MACRO1", "PARENT_MACRO2"]
101+
},
102+
"TargetB": {
103+
"inherits": ["TargetA"],
104+
"macros_add": ["CHILD_MACRO1"],
105+
"macros_remove": ["PARENT_MACRO2"]
106+
}
107+
```
108+
109+
the value of `TargetB.macros` will be `["PARENT_MACRO1", "CHILD_MACRO1"]`.
110+
111+
## extra_labels, extra_labels_add, extra_labels_remove
112+
113+
The list of **labels** defines how the build system looks for sources, libraries, include directories and any other additional files that are needed at compile time. `extra_labels` can be used to make the build system aware of additional directories that must be scanned for such files.
114+
115+
If target inheritance is used, it's possible to alter the values of `extra_labels` using `extra_labels_add` and `extra_labels_remove`. This is similar to the `macros_add` and `macros_remove` mechanism described in the previous paragraph.
116+
117+
## features, features_add, features_remove
118+
119+
The list of **features** defines what hardware a device has.
120+
This allows allowing mbed, libraries, or application source code to select between different implementations of drivers based on hardware availability, to selectively compile drivers for only the hardware that exists, or to test only the tests that apply to a particular platform.
121+
122+
If target inheritance is used, it's possible to alter the values of `features` using `features_add` and `features_remove`. This is similar to the `macros_add` and `macros_remove` mechanism described in the previous two paragraphs.
123+
124+
## supported_toolchains
125+
126+
This is the list of toolchains that can be used to compile code for the target. The known toolchains are `ARM`, `uARM`, `GCC_ARM`, `GCC_CR`, `IAR`.
127+
128+
## default_toolchain
129+
130+
The name of the toolchain that will be used by default to compile this target (if another toolchain is not specified). Possible values are `ARM` or `uARM`.
131+
132+
## post_binary_hook
133+
134+
Some mbed targets require specific actions for generating a binary image that can be flashed to the target. If that's the case, these specific actions can be specified using the `post_binary_hook` property and custom Python code. For the `TEENSY3_1` target above, the definition of `post_binary_hook` looks like this:
135+
136+
```
137+
"post_binary_hook": {
138+
"function": "TEENSY3_1Code.binary_hook",
139+
"toolchains": ["ARM_STD", "ARM_MICRO", "GCC_ARM"]
140+
}
141+
```
142+
143+
Following this definition, the build system will call the function `binary_hook` in the `TEENSY3_1Code` class after the initial binary image for the target is generated. The definition of the `TEENSY3_1Code` class **must** exist in the *targets.py* file. Since `toolchains` is also specified, `binary_hook` will only be called if the toolchain used for compiling the code is either `ARM_STD`, `ARM_MICRO` or `GCC_ARM`. Note that specifying `toolchains` is optional: if it's not specified, the hook will be called no matter what toolchain is used.
144+
145+
As for the `binary_hook` code, this is how it looks in *targets.py*:
146+
147+
```
148+
class TEENSY3_1Code:
149+
@staticmethod
150+
def binary_hook(t_self, resources, elf, binf):
151+
from intelhex import IntelHex
152+
binh = IntelHex()
153+
binh.loadbin(binf, offset = 0)
154+
155+
with open(binf.replace(".bin", ".hex"), "w") as f:
156+
binh.tofile(f, format='hex')
157+
```
158+
159+
In this case, it converts the output file (`binf`) from binary format to Intel HEX format.
160+
161+
The hook code can look quite different between different targets. Take a look at the other classes in *targets.py* for more examples of hook code.
162+
163+
## progen
164+
165+
This property is used to pass additional data to the project generator (used to export the mbed code to various 3rd party tools and IDEs). A definition for `progen` looks like this:
166+
167+
```
168+
"progen": {
169+
"target": "lpc11u35_401",
170+
"uvision": {
171+
"template": ["uvision_microlib.uvproj.tmpl"]
172+
}
173+
```
174+
175+
The `target` property of `progen` specifies the target name that must be used for the exporter (if different than the mbed target name).
176+
For each exporter, a template for exporting can also be specified. In this example, the template used for generating a uVision project file is in a file called `uvision_microlib.uvproj.tmpl`. It is assumed that all the templates are located in `workspace_tools/export`.

hal/api/CAN.h

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "can_api.h"
2424
#include "can_helper.h"
25-
#include "FunctionPointer.h"
25+
#include "Callback.h"
2626

2727
namespace mbed {
2828

@@ -206,34 +206,40 @@ class CAN {
206206
/** Attach a function to call whenever a CAN frame received interrupt is
207207
* generated.
208208
*
209-
* @param fptr A pointer to a void function, or 0 to set as none
209+
* @param func A pointer to a void function, or 0 to set as none
210210
* @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, CAN::TxIrq for transmitted or aborted, CAN::EwIrq for error warning, CAN::DoIrq for data overrun, CAN::WuIrq for wake-up, CAN::EpIrq for error passive, CAN::AlIrq for arbitration lost, CAN::BeIrq for bus error)
211211
*/
212-
void attach(void (*fptr)(void), IrqType type=RxIrq);
212+
void attach(Callback<void()> func, IrqType type=RxIrq);
213213

214214
/** Attach a member function to call whenever a CAN frame received interrupt
215215
* is generated.
216216
*
217-
* @param tptr pointer to the object to call the member function on
218-
* @param mptr pointer to the member function to be called
217+
* @param obj pointer to the object to call the member function on
218+
* @param method pointer to the member function to be called
219219
* @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error)
220220
*/
221-
template<typename T>
222-
void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
223-
if((mptr != NULL) && (tptr != NULL)) {
224-
_irq[type].attach(tptr, mptr);
225-
can_irq_set(&_can, (CanIrqType)type, 1);
226-
}
227-
else {
228-
can_irq_set(&_can, (CanIrqType)type, 0);
229-
}
221+
template<typename T>
222+
void attach(T* obj, void (T::*method)(), IrqType type=RxIrq) {
223+
attach(Callback<void()>(obj, method), type);
224+
}
225+
226+
/** Attach a member function to call whenever a CAN frame received interrupt
227+
* is generated.
228+
*
229+
* @param obj pointer to the object to call the member function on
230+
* @param method pointer to the member function to be called
231+
* @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error)
232+
*/
233+
template<typename T>
234+
void attach(T* obj, void (*method)(T*), IrqType type=RxIrq) {
235+
attach(Callback<void()>(obj, method), type);
230236
}
231237

232238
static void _irq_handler(uint32_t id, CanIrqType type);
233239

234240
protected:
235-
can_t _can;
236-
FunctionPointer _irq[9];
241+
can_t _can;
242+
Callback<void()> _irq[9];
237243
};
238244

239245
} // namespace mbed

hal/api/CThunk.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
* See the License for the specific language governing permissions and
2020
* limitations under the License.
2121
*/
22+
23+
/* General C++ Object Thunking class
24+
*
25+
* - allows direct callbacks to non-static C++ class functions
26+
* - keeps track for the corresponding class instance
27+
* - supports an optional context parameter for the called function
28+
* - ideally suited for class object receiving interrupts (NVIC_SetVector)
29+
*/
30+
2231
#ifndef __CTHUNK_H__
2332
#define __CTHUNK_H__
2433

hal/api/CallChain.h

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#ifndef MBED_CALLCHAIN_H
1717
#define MBED_CALLCHAIN_H
1818

19-
#include "FunctionPointer.h"
19+
#include "Callback.h"
2020
#include <string.h>
2121

2222
namespace mbed {
@@ -57,7 +57,7 @@ namespace mbed {
5757
* @endcode
5858
*/
5959

60-
typedef FunctionPointer* pFunctionPointer_t;
60+
typedef Callback<void()> *pFunctionPointer_t;
6161

6262
class CallChain {
6363
public:
@@ -70,34 +70,34 @@ class CallChain {
7070

7171
/** Add a function at the end of the chain
7272
*
73-
* @param function A pointer to a void function
73+
* @param func A pointer to a void function
7474
*
7575
* @returns
76-
* The function object created for 'function'
76+
* The function object created for 'func'
7777
*/
78-
pFunctionPointer_t add(void (*function)(void));
78+
pFunctionPointer_t add(Callback<void()> func);
7979

8080
/** Add a function at the end of the chain
8181
*
82-
* @param tptr pointer to the object to call the member function on
83-
* @param mptr pointer to the member function to be called
82+
* @param obj pointer to the object to call the member function on
83+
* @param method pointer to the member function to be called
8484
*
8585
* @returns
86-
* The function object created for 'tptr' and 'mptr'
86+
* The function object created for 'obj' and 'method'
8787
*/
88-
template<typename T>
89-
pFunctionPointer_t add(T *tptr, void (T::*mptr)(void)) {
90-
return common_add(new FunctionPointer(tptr, mptr));
88+
template<typename T, typename M>
89+
pFunctionPointer_t add(T *obj, M method) {
90+
return add(Callback<void()>(obj, method));
9191
}
9292

9393
/** Add a function at the beginning of the chain
9494
*
95-
* @param function A pointer to a void function
95+
* @param func A pointer to a void function
9696
*
9797
* @returns
98-
* The function object created for 'function'
98+
* The function object created for 'func'
9999
*/
100-
pFunctionPointer_t add_front(void (*function)(void));
100+
pFunctionPointer_t add_front(Callback<void()> func);
101101

102102
/** Add a function at the beginning of the chain
103103
*
@@ -107,9 +107,9 @@ class CallChain {
107107
* @returns
108108
* The function object created for 'tptr' and 'mptr'
109109
*/
110-
template<typename T>
111-
pFunctionPointer_t add_front(T *tptr, void (T::*mptr)(void)) {
112-
return common_add_front(new FunctionPointer(tptr, mptr));
110+
template<typename T, typename M>
111+
pFunctionPointer_t add_front(T *obj, M method) {
112+
return add_front(Callback<void()>(obj, method));
113113
}
114114

115115
/** Get the number of functions in the chain
@@ -162,8 +162,6 @@ class CallChain {
162162

163163
private:
164164
void _check_size();
165-
pFunctionPointer_t common_add(pFunctionPointer_t pf);
166-
pFunctionPointer_t common_add_front(pFunctionPointer_t pf);
167165

168166
pFunctionPointer_t* _chain;
169167
int _size;

0 commit comments

Comments
 (0)