Skip to content

Commit

Permalink
Merge pull request #9 from mbedmicro/master
Browse files Browse the repository at this point in the history
Synd with master (15 May 2015)
  • Loading branch information
PrzemekWirkus committed May 16, 2015
2 parents 1de9187 + 4d310b7 commit 0441994
Show file tree
Hide file tree
Showing 728 changed files with 220,536 additions and 21,313 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ Nordic:
Renesas:
* [RZ-A1H](http://developer.mbed.org/platforms/Renesas-GR-PEACH/) (Cortex-A9)

Silicon Labs:
* [EFM32 Zero Gecko] (https://developer.mbed.org/platforms/EFM32-Zero-Gecko/) (Cortex-M0+)
* [EFM32 Happy Gecko] (https://developer.mbed.org/platforms/EFM32-Happy-Gecko/) (Cortex-M0+)
* [EFM32 Leopard Gecko] (https://developer.mbed.org/platforms/EFM32-Leopard-Gecko/) (Cortex-M3)
* [EFM32 Giant Gecko] (https://developer.mbed.org/platforms/EFM32-Giant-Gecko/) (Cortex-M3)
* [EFM32 Wonder Gecko] (https://developer.mbed.org/platforms/EFM32-Wonder-Gecko/) (Cortex-M4)


Supported Toolchains and IDEs
-----------------------------
Expand Down
10 changes: 5 additions & 5 deletions docs/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ Build successes:
Above command will build mbed SDK for [LPC1768](http://developer.mbed.org/platforms/mbed-LPC1768/) platform using ARM compiler.

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.
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.
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.
```
$ tree ./mbed/build/
Folder PATH listing
Expand Down Expand Up @@ -406,14 +406,14 @@ C:\Work\mbed\libraries\mbed\targets\cmsis\TARGET_NXP\TARGET_LPC176X\TOOLCHAIN_GC
...
```

## CppUCheck analysis
## CppCheck analysis
[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).

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

```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.
```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.

* 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.

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

# make.py script
```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```.
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.
```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```.
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.

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

Expand Down
6 changes: 6 additions & 0 deletions libraries/USBDevice/USBDevice/USBHAL_STM32F4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,13 @@ void USBHAL::_usbisr(void) {


void USBHAL::usbisr(void) {
if (OTG_FS->GREGS.GINTSTS & (1 << 11)) { // USB Suspend
suspendStateChanged(1);
};

if (OTG_FS->GREGS.GINTSTS & (1 << 12)) { // USB Reset
suspendStateChanged(0);

// Set SNAK bits
OTG_FS->OUTEP_REGS[0].DOEPCTL |= (1 << 27);
OTG_FS->OUTEP_REGS[1].DOEPCTL |= (1 << 27);
Expand Down
202 changes: 202 additions & 0 deletions libraries/mbed/api/CThunk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/* General C++ Object Thunking class
*
* - allows direct callbacks to non-static C++ class functions
* - keeps track for the corresponding class instance
* - supports an optional context parameter for the called function
* - ideally suited for class object receiving interrupts (NVIC_SetVector)
*
* Copyright (c) 2014-2015 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.
*/
#ifndef __CTHUNK_H__
#define __CTHUNK_H__

#define CTHUNK_ADDRESS 1

#if defined(__CORTEX_M3) || defined(__CORTEX_M4) || defined(__thumb2__)
#define CTHUNK_VARIABLES volatile uint32_t code[1]
/**
* CTHUNK disassembly for Cortex-M3/M4 (thumb2):
* * ldm.w pc,{r0,r1,r2,pc}
*
* This instruction loads the arguments for the static thunking function to r0-r2, and
* branches to that function by loading its address into PC.
*
* This is safe for both regular calling and interrupt calling, since it only touches scratch registers
* which should be saved by the caller, and are automatically saved as part of the IRQ context switch.
*/
#define CTHUNK_ASSIGMENT m_thunk.code[0] = 0x8007E89F

#elif defined(__CORTEX_M0PLUS) || defined(__CORTEX_M0)
/*
* CTHUNK disassembly for Cortex M0 (thumb):
* * push {r0,r1,r2,r3,r4,lr} save touched registers and return address
* * movs r4,#4 set up address to load arguments from (immediately following this code block) (1)
* * add r4,pc set up address to load arguments from (immediately following this code block) (2)
* * ldm r4!,{r0,r1,r2,r3} load arguments for static thunk function
* * blx r3 call static thunk function
* * pop {r0,r1,r2,r3,r4,pc} restore scratch registers and return from function
*/
#define CTHUNK_VARIABLES volatile uint32_t code[3]
#define CTHUNK_ASSIGMENT do { \
m_thunk.code[0] = 0x2404B51F; \
m_thunk.code[1] = 0xCC0F447C; \
m_thunk.code[2] = 0xBD1F4798; \
} while (0)

#else
#error "Target is not currently suported."
#endif

/* IRQ/Exception compatible thunk entry function */
typedef void (*CThunkEntry)(void);

template<class T>
class CThunk
{
public:
typedef void (T::*CCallbackSimple)(void);
typedef void (T::*CCallback)(void* context);

inline CThunk(T *instance)
{
init(instance, NULL, NULL);
}

inline CThunk(T *instance, CCallback callback)
{
init(instance, callback, NULL);
}

~CThunk() {

}

inline CThunk(T *instance, CCallbackSimple callback)
{
init(instance, (CCallback)callback, NULL);
}

inline CThunk(T &instance, CCallback callback)
{
init(instance, callback, NULL);
}

inline CThunk(T &instance, CCallbackSimple callback)
{
init(instance, (CCallback)callback, NULL);
}

inline CThunk(T &instance, CCallback callback, void* context)
{
init(instance, callback, context);
}

inline void callback(CCallback callback)
{
m_callback = callback;
}

inline void callback(CCallbackSimple callback)
{
m_callback = (CCallback)callback;
}

inline void context(void* context)
{
m_thunk.context = (uint32_t)context;
}

inline void context(uint32_t context)
{
m_thunk.context = context;
}

inline uint32_t entry(void)
{
return (((uint32_t)&m_thunk)|CTHUNK_ADDRESS);
}

/* get thunk entry point for connecting rhunk to an IRQ table */
inline operator CThunkEntry(void)
{
return (CThunkEntry)entry();
}

/* get thunk entry point for connecting rhunk to an IRQ table */
inline operator uint32_t(void)
{
return entry();
}

/* simple test function */
inline void call(void)
{
(((CThunkEntry)(entry()))());
}

private:
T* m_instance;
volatile CCallback m_callback;

// TODO: this needs proper fix, to refactor toolchain header file and all its use
// PACKED there is not defined properly for IAR
#if defined (__ICCARM__)
typedef __packed struct
{
CTHUNK_VARIABLES;
volatile uint32_t instance;
volatile uint32_t context;
volatile uint32_t callback;
volatile uint32_t trampoline;
} CThunkTrampoline;
#else
typedef struct
{
CTHUNK_VARIABLES;
volatile uint32_t instance;
volatile uint32_t context;
volatile uint32_t callback;
volatile uint32_t trampoline;
} __attribute__((__packed__)) CThunkTrampoline;
#endif

static void trampoline(T* instance, void* context, CCallback* callback)
{
if(instance && *callback) {
(static_cast<T*>(instance)->**callback)(context);
}
}

volatile CThunkTrampoline m_thunk;

inline void init(T *instance, CCallback callback, void* context)
{
/* remember callback - need to add this level of redirection
as pointer size for member functions differs between platforms */
m_callback = callback;

/* populate thunking trampoline */
CTHUNK_ASSIGMENT;
m_thunk.context = (uint32_t)context;
m_thunk.instance = (uint32_t)instance;
m_thunk.callback = (uint32_t)&m_callback;
m_thunk.trampoline = (uint32_t)&trampoline;

__ISB();
__DSB();
}
};

#endif/*__CTHUNK_H__*/
98 changes: 98 additions & 0 deletions libraries/mbed/api/CircularBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* mbed Microcontroller Library
* Copyright (c) 2015 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.
*/
#ifndef MBED_CIRCULARBUFFER_H
#define MBED_CIRCULARBUFFER_H

namespace mbed {

/** Templated Circular buffer class
*/
template<typename T, uint32_t BufferSize, typename CounterType = uint32_t>
class CircularBuffer {
public:
CircularBuffer() : _head(0), _tail(0), _full(false) {
}

~CircularBuffer() {
}

/** Push the transaction to the buffer. This overwrites the buffer if it's
* full
*
* @param data Data to be pushed to the buffer
*/
void push(const T& data) {
if (full()) {
_tail++;
_tail %= BufferSize;
}
_pool[_head++] = data;
_head %= BufferSize;
if (_head == _tail) {
_full = true;
}
}

/** Pop the transaction from the buffer
*
* @param data Data to be pushed to the buffer
* @return True if the buffer is not empty and data contains a transaction, false otherwise
*/
bool pop(T& data) {
if (!empty()) {
data = _pool[_tail++];
_tail %= BufferSize;
_full = false;
return true;
}
return false;
}

/** Check if the buffer is empty
*
* @return True if the buffer is empty, false if not
*/
bool empty() {
return (_head == _tail) && !_full;
}

/** Check if the buffer is full
*
* @return True if the buffer is full, false if not
*/
bool full() {
return _full;
}

/** Reset the buffer
*
*/
void reset() {
_head = 0;
_tail = 0;
_full = false;
}

private:
T _pool[BufferSize];
CounterType _head;
CounterType _tail;
bool _full;
};

}

#endif
Loading

0 comments on commit 0441994

Please sign in to comment.