Skip to content

Commit 0441994

Browse files
committed
Merge pull request #9 from mbedmicro/master
Synd with master (15 May 2015)
2 parents 1de9187 + 4d310b7 commit 0441994

File tree

728 files changed

+220536
-21313
lines changed

Some content is hidden

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

728 files changed

+220536
-21313
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ Nordic:
8585
Renesas:
8686
* [RZ-A1H](http://developer.mbed.org/platforms/Renesas-GR-PEACH/) (Cortex-A9)
8787

88+
Silicon Labs:
89+
* [EFM32 Zero Gecko] (https://developer.mbed.org/platforms/EFM32-Zero-Gecko/) (Cortex-M0+)
90+
* [EFM32 Happy Gecko] (https://developer.mbed.org/platforms/EFM32-Happy-Gecko/) (Cortex-M0+)
91+
* [EFM32 Leopard Gecko] (https://developer.mbed.org/platforms/EFM32-Leopard-Gecko/) (Cortex-M3)
92+
* [EFM32 Giant Gecko] (https://developer.mbed.org/platforms/EFM32-Giant-Gecko/) (Cortex-M3)
93+
* [EFM32 Wonder Gecko] (https://developer.mbed.org/platforms/EFM32-Wonder-Gecko/) (Cortex-M4)
94+
8895

8996
Supported Toolchains and IDEs
9097
-----------------------------

docs/BUILDING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ Build successes:
236236
Above command will build mbed SDK for [LPC1768](http://developer.mbed.org/platforms/mbed-LPC1768/) platform using ARM compiler.
237237

238238
Let's have a look at directory structure under ```mbed/build/```. We can see for ```LPC1768``` new directory ```TARGET_LPC1768``` was created. This directory contains all build primitives.
239-
Directory ```mbed/TARGET_LPC1768/TOOLCHAIN_ARM_STD/``` conteins mbed SDK library ```mbed.ar```. This directory structure also stores all needed headers which you should use with ```mbed.ar``` when building your own software.
239+
Directory ```mbed/TARGET_LPC1768/TOOLCHAIN_ARM_STD/``` contains mbed SDK library ```mbed.ar```. This directory structure also stores all needed headers which you should use with ```mbed.ar``` when building your own software.
240240
```
241241
$ tree ./mbed/build/
242242
Folder PATH listing
@@ -406,14 +406,14 @@ C:\Work\mbed\libraries\mbed\targets\cmsis\TARGET_NXP\TARGET_LPC176X\TOOLCHAIN_GC
406406
...
407407
```
408408

409-
## CppUCheck analysis
409+
## CppCheck analysis
410410
[Cppcheck](http://cppcheck.sourceforge.net/) is a static analysis tool for C/C++ code. Unlike C/C++ compilers and many other analysis tools it does not detect syntax errors in the code. Cppcheck primarily detects the types of bugs that the compilers normally do not detect. The goal is to detect only real errors in the code (i.e. have zero false positives).
411411

412412
Prerequisites:
413413
* Please install ```CppCheck``` on your system before you want to use it with build scripts.
414414
* You should also add Cppcheck to your system path.
415415

416-
```build.py``` script supports switching between compilation and building and just static code analysis testing. You can use switch ```--cppcheck``` to perform CppCheck static code analysis.
416+
```build.py``` script supports switching between compilation, building and just static code analysis testing. You can use switch ```--cppcheck``` to perform CppCheck static code analysis.
417417

418418
* When you are using --cppcheck switch all macros, toolchain dependencies etc. are preserved so you are sure you are checking exactly the same code you would compile for your application.
419419

@@ -427,8 +427,8 @@ $ python build.py -t uARM -m NUCLEO_F334R8 --cppcheck
427427
```
428428

429429
# make.py script
430-
```make.pt``` is a ```mbed/workspace_tools/``` script used to build tests (we call them sometimes 'programs') one by one manually. Script allows you to flash board with test and execute it. This is deprecated functionality and will not be described here. Instead please use ```singletest.py``` file to build mbed SDK, tests and run automation for test cases included in ```mbedmicro/mbed```.
431-
Note: ```make.py``` script depends on existing already built mked SDK and library sources so you need to pre-build mbed SDK and for example RTOS library to link 'program' (test) with mebd SDK and RTOS library. To pre-build mbed SDK please use ```build.py``` script.
430+
```make.py``` is a ```mbed/workspace_tools/``` script used to build tests (we call them sometimes 'programs') one by one manually. This script allows you to flash board, execute and test it. However, this script is deprecated and will not be described here. Instead please use ```singletest.py``` file to build mbed SDK, tests and run automation for test cases included in ```mbedmicro/mbed```.
431+
Note: ```make.py``` script depends on existing already built mbed SDK and library sources so you need to pre-build mbed SDK and other libraries (such as RTOS library) to link 'program' (test) with mbed SDK and RTOS library. To pre-build mbed SDK please use ```build.py``` script.
432432

433433
Just for sake of example please see few ways to use ```make.py``` together with Freedom K64F board.
434434

libraries/USBDevice/USBDevice/USBHAL_STM32F4.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,13 @@ void USBHAL::_usbisr(void) {
307307

308308

309309
void USBHAL::usbisr(void) {
310+
if (OTG_FS->GREGS.GINTSTS & (1 << 11)) { // USB Suspend
311+
suspendStateChanged(1);
312+
};
313+
310314
if (OTG_FS->GREGS.GINTSTS & (1 << 12)) { // USB Reset
315+
suspendStateChanged(0);
316+
311317
// Set SNAK bits
312318
OTG_FS->OUTEP_REGS[0].DOEPCTL |= (1 << 27);
313319
OTG_FS->OUTEP_REGS[1].DOEPCTL |= (1 << 27);

libraries/mbed/api/CThunk.h

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/* General C++ Object Thunking class
2+
*
3+
* - allows direct callbacks to non-static C++ class functions
4+
* - keeps track for the corresponding class instance
5+
* - supports an optional context parameter for the called function
6+
* - ideally suited for class object receiving interrupts (NVIC_SetVector)
7+
*
8+
* Copyright (c) 2014-2015 ARM Limited
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
#ifndef __CTHUNK_H__
23+
#define __CTHUNK_H__
24+
25+
#define CTHUNK_ADDRESS 1
26+
27+
#if defined(__CORTEX_M3) || defined(__CORTEX_M4) || defined(__thumb2__)
28+
#define CTHUNK_VARIABLES volatile uint32_t code[1]
29+
/**
30+
* CTHUNK disassembly for Cortex-M3/M4 (thumb2):
31+
* * ldm.w pc,{r0,r1,r2,pc}
32+
*
33+
* This instruction loads the arguments for the static thunking function to r0-r2, and
34+
* branches to that function by loading its address into PC.
35+
*
36+
* This is safe for both regular calling and interrupt calling, since it only touches scratch registers
37+
* which should be saved by the caller, and are automatically saved as part of the IRQ context switch.
38+
*/
39+
#define CTHUNK_ASSIGMENT m_thunk.code[0] = 0x8007E89F
40+
41+
#elif defined(__CORTEX_M0PLUS) || defined(__CORTEX_M0)
42+
/*
43+
* CTHUNK disassembly for Cortex M0 (thumb):
44+
* * push {r0,r1,r2,r3,r4,lr} save touched registers and return address
45+
* * movs r4,#4 set up address to load arguments from (immediately following this code block) (1)
46+
* * add r4,pc set up address to load arguments from (immediately following this code block) (2)
47+
* * ldm r4!,{r0,r1,r2,r3} load arguments for static thunk function
48+
* * blx r3 call static thunk function
49+
* * pop {r0,r1,r2,r3,r4,pc} restore scratch registers and return from function
50+
*/
51+
#define CTHUNK_VARIABLES volatile uint32_t code[3]
52+
#define CTHUNK_ASSIGMENT do { \
53+
m_thunk.code[0] = 0x2404B51F; \
54+
m_thunk.code[1] = 0xCC0F447C; \
55+
m_thunk.code[2] = 0xBD1F4798; \
56+
} while (0)
57+
58+
#else
59+
#error "Target is not currently suported."
60+
#endif
61+
62+
/* IRQ/Exception compatible thunk entry function */
63+
typedef void (*CThunkEntry)(void);
64+
65+
template<class T>
66+
class CThunk
67+
{
68+
public:
69+
typedef void (T::*CCallbackSimple)(void);
70+
typedef void (T::*CCallback)(void* context);
71+
72+
inline CThunk(T *instance)
73+
{
74+
init(instance, NULL, NULL);
75+
}
76+
77+
inline CThunk(T *instance, CCallback callback)
78+
{
79+
init(instance, callback, NULL);
80+
}
81+
82+
~CThunk() {
83+
84+
}
85+
86+
inline CThunk(T *instance, CCallbackSimple callback)
87+
{
88+
init(instance, (CCallback)callback, NULL);
89+
}
90+
91+
inline CThunk(T &instance, CCallback callback)
92+
{
93+
init(instance, callback, NULL);
94+
}
95+
96+
inline CThunk(T &instance, CCallbackSimple callback)
97+
{
98+
init(instance, (CCallback)callback, NULL);
99+
}
100+
101+
inline CThunk(T &instance, CCallback callback, void* context)
102+
{
103+
init(instance, callback, context);
104+
}
105+
106+
inline void callback(CCallback callback)
107+
{
108+
m_callback = callback;
109+
}
110+
111+
inline void callback(CCallbackSimple callback)
112+
{
113+
m_callback = (CCallback)callback;
114+
}
115+
116+
inline void context(void* context)
117+
{
118+
m_thunk.context = (uint32_t)context;
119+
}
120+
121+
inline void context(uint32_t context)
122+
{
123+
m_thunk.context = context;
124+
}
125+
126+
inline uint32_t entry(void)
127+
{
128+
return (((uint32_t)&m_thunk)|CTHUNK_ADDRESS);
129+
}
130+
131+
/* get thunk entry point for connecting rhunk to an IRQ table */
132+
inline operator CThunkEntry(void)
133+
{
134+
return (CThunkEntry)entry();
135+
}
136+
137+
/* get thunk entry point for connecting rhunk to an IRQ table */
138+
inline operator uint32_t(void)
139+
{
140+
return entry();
141+
}
142+
143+
/* simple test function */
144+
inline void call(void)
145+
{
146+
(((CThunkEntry)(entry()))());
147+
}
148+
149+
private:
150+
T* m_instance;
151+
volatile CCallback m_callback;
152+
153+
// TODO: this needs proper fix, to refactor toolchain header file and all its use
154+
// PACKED there is not defined properly for IAR
155+
#if defined (__ICCARM__)
156+
typedef __packed struct
157+
{
158+
CTHUNK_VARIABLES;
159+
volatile uint32_t instance;
160+
volatile uint32_t context;
161+
volatile uint32_t callback;
162+
volatile uint32_t trampoline;
163+
} CThunkTrampoline;
164+
#else
165+
typedef struct
166+
{
167+
CTHUNK_VARIABLES;
168+
volatile uint32_t instance;
169+
volatile uint32_t context;
170+
volatile uint32_t callback;
171+
volatile uint32_t trampoline;
172+
} __attribute__((__packed__)) CThunkTrampoline;
173+
#endif
174+
175+
static void trampoline(T* instance, void* context, CCallback* callback)
176+
{
177+
if(instance && *callback) {
178+
(static_cast<T*>(instance)->**callback)(context);
179+
}
180+
}
181+
182+
volatile CThunkTrampoline m_thunk;
183+
184+
inline void init(T *instance, CCallback callback, void* context)
185+
{
186+
/* remember callback - need to add this level of redirection
187+
as pointer size for member functions differs between platforms */
188+
m_callback = callback;
189+
190+
/* populate thunking trampoline */
191+
CTHUNK_ASSIGMENT;
192+
m_thunk.context = (uint32_t)context;
193+
m_thunk.instance = (uint32_t)instance;
194+
m_thunk.callback = (uint32_t)&m_callback;
195+
m_thunk.trampoline = (uint32_t)&trampoline;
196+
197+
__ISB();
198+
__DSB();
199+
}
200+
};
201+
202+
#endif/*__CTHUNK_H__*/

libraries/mbed/api/CircularBuffer.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2015 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#ifndef MBED_CIRCULARBUFFER_H
17+
#define MBED_CIRCULARBUFFER_H
18+
19+
namespace mbed {
20+
21+
/** Templated Circular buffer class
22+
*/
23+
template<typename T, uint32_t BufferSize, typename CounterType = uint32_t>
24+
class CircularBuffer {
25+
public:
26+
CircularBuffer() : _head(0), _tail(0), _full(false) {
27+
}
28+
29+
~CircularBuffer() {
30+
}
31+
32+
/** Push the transaction to the buffer. This overwrites the buffer if it's
33+
* full
34+
*
35+
* @param data Data to be pushed to the buffer
36+
*/
37+
void push(const T& data) {
38+
if (full()) {
39+
_tail++;
40+
_tail %= BufferSize;
41+
}
42+
_pool[_head++] = data;
43+
_head %= BufferSize;
44+
if (_head == _tail) {
45+
_full = true;
46+
}
47+
}
48+
49+
/** Pop the transaction from the buffer
50+
*
51+
* @param data Data to be pushed to the buffer
52+
* @return True if the buffer is not empty and data contains a transaction, false otherwise
53+
*/
54+
bool pop(T& data) {
55+
if (!empty()) {
56+
data = _pool[_tail++];
57+
_tail %= BufferSize;
58+
_full = false;
59+
return true;
60+
}
61+
return false;
62+
}
63+
64+
/** Check if the buffer is empty
65+
*
66+
* @return True if the buffer is empty, false if not
67+
*/
68+
bool empty() {
69+
return (_head == _tail) && !_full;
70+
}
71+
72+
/** Check if the buffer is full
73+
*
74+
* @return True if the buffer is full, false if not
75+
*/
76+
bool full() {
77+
return _full;
78+
}
79+
80+
/** Reset the buffer
81+
*
82+
*/
83+
void reset() {
84+
_head = 0;
85+
_tail = 0;
86+
_full = false;
87+
}
88+
89+
private:
90+
T _pool[BufferSize];
91+
CounterType _head;
92+
CounterType _tail;
93+
bool _full;
94+
};
95+
96+
}
97+
98+
#endif

0 commit comments

Comments
 (0)