Changed line endings to LF, removed non-ASCII chars from sources

pull/23/head
Bogdan Marinescu 2013-08-08 12:58:34 +03:00
parent 3f703f1bf0
commit 3b465de3aa
16 changed files with 12242 additions and 12242 deletions

View File

@ -1,94 +1,94 @@
/* mbed Microcontroller Library /* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited * Copyright (c) 2006-2013 ARM Limited
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifndef MBED_FUNCTIONPOINTER_H #ifndef MBED_FUNCTIONPOINTER_H
#define MBED_FUNCTIONPOINTER_H #define MBED_FUNCTIONPOINTER_H
#include <string.h> #include <string.h>
namespace mbed { namespace mbed {
typedef void (*pvoidf_t)(void); typedef void (*pvoidf_t)(void);
/** A class for storing and calling a pointer to a static or member void function /** A class for storing and calling a pointer to a static or member void function
*/ */
class FunctionPointer { class FunctionPointer {
public: public:
/** Create a FunctionPointer, attaching a static function /** Create a FunctionPointer, attaching a static function
* *
* @param function The void static function to attach (default is none) * @param function The void static function to attach (default is none)
*/ */
FunctionPointer(void (*function)(void) = 0); FunctionPointer(void (*function)(void) = 0);
/** Create a FunctionPointer, attaching a member function /** Create a FunctionPointer, attaching a member function
* *
* @param object The object pointer to invoke the member function on (i.e. the this pointer) * @param object The object pointer to invoke the member function on (i.e. the this pointer)
* @param function The address of the void member function to attach * @param function The address of the void member function to attach
*/ */
template<typename T> template<typename T>
FunctionPointer(T *object, void (T::*member)(void)) { FunctionPointer(T *object, void (T::*member)(void)) {
attach(object, member); attach(object, member);
} }
/** Attach a static function /** Attach a static function
* *
* @param function The void static function to attach (default is none) * @param function The void static function to attach (default is none)
*/ */
void attach(void (*function)(void) = 0); void attach(void (*function)(void) = 0);
/** Attach a member function /** Attach a member function
* *
* @param object The object pointer to invoke the member function on (i.e. the this pointer) * @param object The object pointer to invoke the member function on (i.e. the this pointer)
* @param function The address of the void member function to attach * @param function The address of the void member function to attach
*/ */
template<typename T> template<typename T>
void attach(T *object, void (T::*member)(void)) { void attach(T *object, void (T::*member)(void)) {
_object = static_cast<void*>(object); _object = static_cast<void*>(object);
memcpy(_member, (char*)&member, sizeof(member)); memcpy(_member, (char*)&member, sizeof(member));
_membercaller = &FunctionPointer::membercaller<T>; _membercaller = &FunctionPointer::membercaller<T>;
_function = 0; _function = 0;
} }
/** Call the attached static or member function /** Call the attached static or member function
*/ */
void call(); void call();
pvoidf_t get_function() const { pvoidf_t get_function() const {
return (pvoidf_t)_function; return (pvoidf_t)_function;
} }
#ifdef MBED_OPERATORS #ifdef MBED_OPERATORS
void operator ()(void); void operator ()(void);
#endif #endif
private: private:
template<typename T> template<typename T>
static void membercaller(void *object, char *member) { static void membercaller(void *object, char *member) {
T* o = static_cast<T*>(object); T* o = static_cast<T*>(object);
void (T::*m)(void); void (T::*m)(void);
memcpy((char*)&m, member, sizeof(m)); memcpy((char*)&m, member, sizeof(m));
(o->*m)(); (o->*m)();
} }
void (*_function)(void); // static function pointer - 0 if none attached void (*_function)(void); // static function pointer - 0 if none attached
void *_object; // object this pointer - 0 if none attached void *_object; // object this pointer - 0 if none attached
char _member[16]; // raw member function pointer storage - converted back by registered _membercaller char _member[16]; // raw member function pointer storage - converted back by registered _membercaller
void (*_membercaller)(void*, char*); // registered membercaller function to convert back and call _member on _object void (*_membercaller)(void*, char*); // registered membercaller function to convert back and call _member on _object
}; };
} // namespace mbed } // namespace mbed
#endif #endif

View File

@ -1,273 +1,273 @@
/* mbed Microcontroller Library /* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited * Copyright (c) 2006-2013 ARM Limited
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifndef MBED_INTERRUPTIN_H #ifndef MBED_INTERRUPTIN_H
#define MBED_INTERRUPTIN_H #define MBED_INTERRUPTIN_H
#include "platform.h" #include "platform.h"
#if DEVICE_INTERRUPTIN #if DEVICE_INTERRUPTIN
#include "gpio_api.h" #include "gpio_api.h"
#include "gpio_irq_api.h" #include "gpio_irq_api.h"
#include "FunctionPointer.h" #include "FunctionPointer.h"
#include "CallChain.h" #include "CallChain.h"
namespace mbed { namespace mbed {
/** A digital interrupt input, used to call a function on a rising or falling edge /** A digital interrupt input, used to call a function on a rising or falling edge
* *
* Example: * Example:
* @code * @code
* // Flash an LED while waiting for events * // Flash an LED while waiting for events
* *
* #include "mbed.h" * #include "mbed.h"
* *
* InterruptIn event(p16); * InterruptIn event(p16);
* DigitalOut led(LED1); * DigitalOut led(LED1);
* *
* void trigger() { * void trigger() {
* printf("triggered!\n"); * printf("triggered!\n");
* } * }
* *
* int main() { * int main() {
* event.rise(&trigger); * event.rise(&trigger);
* while(1) { * while(1) {
* led = !led; * led = !led;
* wait(0.25); * wait(0.25);
* } * }
* } * }
* @endcode * @endcode
*/ */
class InterruptIn { class InterruptIn {
public: public:
/** Create an InterruptIn connected to the specified pin /** Create an InterruptIn connected to the specified pin
* *
* @param pin InterruptIn pin to connect to * @param pin InterruptIn pin to connect to
* @param name (optional) A string to identify the object * @param name (optional) A string to identify the object
*/ */
InterruptIn(PinName pin); InterruptIn(PinName pin);
virtual ~InterruptIn(); virtual ~InterruptIn();
int read(); int read();
#ifdef MBED_OPERATORS #ifdef MBED_OPERATORS
operator int(); operator int();
#endif #endif
/** Attach a function to call when a rising edge occurs on the input /** Attach a function to call when a rising edge occurs on the input
* *
* @param fptr A pointer to a void function, or 0 to set as none * @param fptr A pointer to a void function, or 0 to set as none
* *
* @returns * @returns
* The function object created for 'fptr' * The function object created for 'fptr'
*/ */
pFunctionPointer_t rise(void (*fptr)(void)); pFunctionPointer_t rise(void (*fptr)(void));
/** Add a function to be called when a rising edge occurs at the end of the call chain /** Add a function to be called when a rising edge occurs at the end of the call chain
* *
* @param fptr the function to add * @param fptr the function to add
* *
* @returns * @returns
* The function object created for 'fptr' * The function object created for 'fptr'
*/ */
pFunctionPointer_t rise_add(void (*fptr)(void)) { pFunctionPointer_t rise_add(void (*fptr)(void)) {
return rise_add_common(fptr); return rise_add_common(fptr);
} }
/** Add a function to be called when a rising edge occurs at the beginning of the call chain /** Add a function to be called when a rising edge occurs at the beginning of the call chain
* *
* @param fptr the function to add * @param fptr the function to add
* *
* @returns * @returns
* The function object created for 'fptr' * The function object created for 'fptr'
*/ */
pFunctionPointer_t rise_add_front(void (*fptr)(void)) { pFunctionPointer_t rise_add_front(void (*fptr)(void)) {
return rise_add_common(fptr, true); return rise_add_common(fptr, true);
} }
/** Attach a member function to call when a rising edge occurs on the input /** Attach a member function to call when a rising edge occurs on the input
* *
* @param tptr pointer to the object to call the member function on * @param tptr pointer to the object to call the member function on
* @param mptr pointer to the member function to be called * @param mptr pointer to the member function to be called
* *
* @returns * @returns
* The function object created for 'tptr' and 'mptr' * The function object created for 'tptr' and 'mptr'
*/ */
template<typename T> template<typename T>
pFunctionPointer_t rise(T* tptr, void (T::*mptr)(void)) { pFunctionPointer_t rise(T* tptr, void (T::*mptr)(void)) {
_rise.clear(); _rise.clear();
pFunctionPointer_t pf = _rise.add(tptr, mptr); pFunctionPointer_t pf = _rise.add(tptr, mptr);
gpio_irq_set(&gpio_irq, IRQ_RISE, 1); gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
return pf; return pf;
} }
/** Add a function to be called when a rising edge occurs at the end of the call chain /** Add a function to be called when a rising edge occurs at the end of the call chain
* *
* @param tptr pointer to the object to call the member function on * @param tptr pointer to the object to call the member function on
* @param mptr pointer to the member function to be called * @param mptr pointer to the member function to be called
* *
* @returns * @returns
* The function object created for 'tptr' and 'mptr' * The function object created for 'tptr' and 'mptr'
*/ */
template<typename T> template<typename T>
pFunctionPointer_t rise_add(T* tptr, void (T::*mptr)(void)) { pFunctionPointer_t rise_add(T* tptr, void (T::*mptr)(void)) {
return rise_add_common(tptr, mptr); return rise_add_common(tptr, mptr);
} }
/** Add a function to be called when a rising edge occurs at the beginning of the call chain /** Add a function to be called when a rising edge occurs at the beginning of the call chain
* *
* @param tptr pointer to the object to call the member function on * @param tptr pointer to the object to call the member function on
* @param mptr pointer to the member function to be called * @param mptr pointer to the member function to be called
* *
* @returns * @returns
* The function object created for 'tptr' and 'mptr' * The function object created for 'tptr' and 'mptr'
*/ */
template<typename T> template<typename T>
pFunctionPointer_t rise_add_front(T* tptr, void (T::*mptr)(void)) { pFunctionPointer_t rise_add_front(T* tptr, void (T::*mptr)(void)) {
return rise_add_common(tptr, mptr, true); return rise_add_common(tptr, mptr, true);
} }
/** Remove a function from the list of functions to be called when a rising edge occurs /** Remove a function from the list of functions to be called when a rising edge occurs
* *
* @param pf the function object to remove * @param pf the function object to remove
* *
* @returns * @returns
* true if the function was found and removed, false otherwise * true if the function was found and removed, false otherwise
*/ */
bool rise_remove(pFunctionPointer_t pf); bool rise_remove(pFunctionPointer_t pf);
/** Attach a function to call when a falling edge occurs on the input /** Attach a function to call when a falling edge occurs on the input
* *
* @param fptr A pointer to a void function, or 0 to set as none * @param fptr A pointer to a void function, or 0 to set as none
* *
* @returns * @returns
* The function object created for 'fptr' * The function object created for 'fptr'
*/ */
pFunctionPointer_t fall(void (*fptr)(void)); pFunctionPointer_t fall(void (*fptr)(void));
/** Add a function to be called when a falling edge occurs at the end of the call chain /** Add a function to be called when a falling edge occurs at the end of the call chain
* *
* @param fptr the function to add * @param fptr the function to add
* *
* @returns * @returns
* The function object created for 'fptr' * The function object created for 'fptr'
*/ */
pFunctionPointer_t fall_add(void (*fptr)(void)) { pFunctionPointer_t fall_add(void (*fptr)(void)) {
return fall_add_common(fptr); return fall_add_common(fptr);
} }
/** Add a function to be called when a falling edge occurs at the beginning of the call chain /** Add a function to be called when a falling edge occurs at the beginning of the call chain
* *
* @param fptr the function to add * @param fptr the function to add
* *
* @returns * @returns
* The function object created for 'fptr' * The function object created for 'fptr'
*/ */
pFunctionPointer_t fall_add_front(void (*fptr)(void)) { pFunctionPointer_t fall_add_front(void (*fptr)(void)) {
return fall_add_common(fptr, true); return fall_add_common(fptr, true);
} }
/** Attach a member function to call when a falling edge occurs on the input /** Attach a member function to call when a falling edge occurs on the input
* *
* @param tptr pointer to the object to call the member function on * @param tptr pointer to the object to call the member function on
* @param mptr pointer to the member function to be called * @param mptr pointer to the member function to be called
* *
* @returns * @returns
* The function object created for 'tptr' and 'mptr' * The function object created for 'tptr' and 'mptr'
*/ */
template<typename T> template<typename T>
pFunctionPointer_t fall(T* tptr, void (T::*mptr)(void)) { pFunctionPointer_t fall(T* tptr, void (T::*mptr)(void)) {
_fall.clear(); _fall.clear();
pFunctionPointer_t pf = _fall.add(tptr, mptr); pFunctionPointer_t pf = _fall.add(tptr, mptr);
gpio_irq_set(&gpio_irq, IRQ_FALL, 1); gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
return pf; return pf;
} }
/** Add a function to be called when a falling edge occurs at the end of the call chain /** Add a function to be called when a falling edge occurs at the end of the call chain
* *
* @param tptr pointer to the object to call the member function on * @param tptr pointer to the object to call the member function on
* @param mptr pointer to the member function to be called * @param mptr pointer to the member function to be called
* *
* @returns * @returns
* The function object created for 'tptr' and 'mptr' * The function object created for 'tptr' and 'mptr'
*/ */
template<typename T> template<typename T>
pFunctionPointer_t fall_add(T* tptr, void (T::*mptr)(void)) { pFunctionPointer_t fall_add(T* tptr, void (T::*mptr)(void)) {
return fall_add_common(tptr, mptr); return fall_add_common(tptr, mptr);
} }
/** Add a function to be called when a falling edge occurs at the beginning of the call chain /** Add a function to be called when a falling edge occurs at the beginning of the call chain
* *
* @param tptr pointer to the object to call the member function on * @param tptr pointer to the object to call the member function on
* @param mptr pointer to the member function to be called * @param mptr pointer to the member function to be called
* *
* @returns * @returns
* The function object created for 'tptr' and 'mptr' * The function object created for 'tptr' and 'mptr'
*/ */
template<typename T> template<typename T>
pFunctionPointer_t fall_add_front(T* tptr, void (T::*mptr)(void)) { pFunctionPointer_t fall_add_front(T* tptr, void (T::*mptr)(void)) {
return fall_add_common(tptr, mptr, true); return fall_add_common(tptr, mptr, true);
} }
/** Remove a function from the list of functions to be called when a falling edge occurs /** Remove a function from the list of functions to be called when a falling edge occurs
* *
* @param pf the function object to remove * @param pf the function object to remove
* *
* @returns * @returns
* true if the function was found and removed, false otherwise * true if the function was found and removed, false otherwise
*/ */
bool fall_remove(pFunctionPointer_t pf); bool fall_remove(pFunctionPointer_t pf);
/** Set the input pin mode /** Set the input pin mode
* *
* @param mode PullUp, PullDown, PullNone * @param mode PullUp, PullDown, PullNone
*/ */
void mode(PinMode pull); void mode(PinMode pull);
static void _irq_handler(uint32_t id, gpio_irq_event event); static void _irq_handler(uint32_t id, gpio_irq_event event);
protected: protected:
pFunctionPointer_t rise_add_common(void (*fptr)(void), bool front=false); pFunctionPointer_t rise_add_common(void (*fptr)(void), bool front=false);
pFunctionPointer_t fall_add_common(void (*fptr)(void), bool front=false); pFunctionPointer_t fall_add_common(void (*fptr)(void), bool front=false);
template<typename T> template<typename T>
pFunctionPointer_t rise_add_common(T* tptr, void (T::*mptr)(void), bool front=false) { pFunctionPointer_t rise_add_common(T* tptr, void (T::*mptr)(void), bool front=false) {
pFunctionPointer_t pf = front ? _rise.add_front(tptr, mptr) : _rise.add(tptr, mptr); pFunctionPointer_t pf = front ? _rise.add_front(tptr, mptr) : _rise.add(tptr, mptr);
gpio_irq_set(&gpio_irq, IRQ_RISE, 1); gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
return pf; return pf;
} }
template<typename T> template<typename T>
pFunctionPointer_t fall_add_common(T* tptr, void (T::*mptr)(void), bool front=false) { pFunctionPointer_t fall_add_common(T* tptr, void (T::*mptr)(void), bool front=false) {
pFunctionPointer_t pf = front ? _fall.add_front(tptr, mptr) : _fall.add(tptr, mptr); pFunctionPointer_t pf = front ? _fall.add_front(tptr, mptr) : _fall.add(tptr, mptr);
gpio_irq_set(&gpio_irq, IRQ_FALL, 1); gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
return pf; return pf;
} }
gpio_t gpio; gpio_t gpio;
gpio_irq_t gpio_irq; gpio_irq_t gpio_irq;
CallChain _rise; CallChain _rise;
CallChain _fall; CallChain _fall;
}; };
} // namespace mbed } // namespace mbed
#endif #endif
#endif #endif

View File

@ -1,202 +1,202 @@
/* mbed Microcontroller Library /* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited * Copyright (c) 2006-2013 ARM Limited
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifndef MBED_TICKER_H #ifndef MBED_TICKER_H
#define MBED_TICKER_H #define MBED_TICKER_H
#include "TimerEvent.h" #include "TimerEvent.h"
#include "FunctionPointer.h" #include "FunctionPointer.h"
#include "CallChain.h" #include "CallChain.h"
namespace mbed { namespace mbed {
/** A Ticker is used to call a function at a recurring interval /** A Ticker is used to call a function at a recurring interval
* *
* You can use as many seperate Ticker objects as you require. * You can use as many seperate Ticker objects as you require.
* *
* Example: * Example:
* @code * @code
* // Toggle the blinking led after 5 seconds * // Toggle the blinking led after 5 seconds
* *
* #include "mbed.h" * #include "mbed.h"
* *
* Ticker timer; * Ticker timer;
* DigitalOut led1(LED1); * DigitalOut led1(LED1);
* DigitalOut led2(LED2); * DigitalOut led2(LED2);
* *
* int flip = 0; * int flip = 0;
* *
* void attime() { * void attime() {
* flip = !flip; * flip = !flip;
* } * }
* *
* int main() { * int main() {
* timer.attach(&attime, 5); * timer.attach(&attime, 5);
* while(1) { * while(1) {
* if(flip == 0) { * if(flip == 0) {
* led1 = !led1; * led1 = !led1;
* } else { * } else {
* led2 = !led2; * led2 = !led2;
* } * }
* wait(0.2); * wait(0.2);
* } * }
* } * }
* @endcode * @endcode
*/ */
class Ticker : public TimerEvent { class Ticker : public TimerEvent {
public: public:
/** Attach a function to be called by the Ticker, specifiying the interval in seconds /** Attach a function to be called by the Ticker, specifiying the interval in seconds
* *
* @param fptr pointer to the function to be called * @param fptr pointer to the function to be called
* @param t the time between calls in seconds * @param t the time between calls in seconds
* *
* @returns * @returns
* The function object created for 'fptr' * The function object created for 'fptr'
*/ */
pFunctionPointer_t attach(void (*fptr)(void), float t) { pFunctionPointer_t attach(void (*fptr)(void), float t) {
return attach_us(fptr, t * 1000000.0f); return attach_us(fptr, t * 1000000.0f);
} }
/** Add a function to be called by the Ticker at the end of the call chain /** Add a function to be called by the Ticker at the end of the call chain
* *
* @param fptr the function to add * @param fptr the function to add
* *
* @returns * @returns
* The function object created for 'fptr' * The function object created for 'fptr'
*/ */
pFunctionPointer_t add_function(void (*fptr)(void)) { pFunctionPointer_t add_function(void (*fptr)(void)) {
return add_function_helper(fptr); return add_function_helper(fptr);
} }
/** Add a function to be called by the Ticker at the beginning of the call chain /** Add a function to be called by the Ticker at the beginning of the call chain
* *
* @param fptr the function to add * @param fptr the function to add
* *
* @returns * @returns
* The function object created for 'fptr' * The function object created for 'fptr'
*/ */
pFunctionPointer_t add_function_front(void (*fptr)(void)) { pFunctionPointer_t add_function_front(void (*fptr)(void)) {
return add_function_helper(fptr, true); return add_function_helper(fptr, true);
} }
/** Attach a member function to be called by the Ticker, specifiying the interval in seconds /** Attach a member function to be called by the Ticker, specifiying the interval in seconds
* *
* @param tptr pointer to the object to call the member function on * @param tptr pointer to the object to call the member function on
* @param mptr pointer to the member function to be called * @param mptr pointer to the member function to be called
* @param t the time between calls in seconds * @param t the time between calls in seconds
* *
* @returns * @returns
* The function object created for 'tptr' and 'mptr' * The function object created for 'tptr' and 'mptr'
*/ */
template<typename T> template<typename T>
pFunctionPointer_t attach(T* tptr, void (T::*mptr)(void), float t) { pFunctionPointer_t attach(T* tptr, void (T::*mptr)(void), float t) {
return attach_us(tptr, mptr, t * 1000000.0f); return attach_us(tptr, mptr, t * 1000000.0f);
} }
/** Add a function to be called by the Ticker at the end of the call chain /** Add a function to be called by the Ticker at the end of the call chain
* *
* @param tptr pointer to the object to call the member function on * @param tptr pointer to the object to call the member function on
* @param mptr pointer to the member function to be called * @param mptr pointer to the member function to be called
* *
* @returns * @returns
* The function object created for 'tptr' and 'mptr' * The function object created for 'tptr' and 'mptr'
*/ */
template<typename T> template<typename T>
pFunctionPointer_t add_function(T* tptr, void (T::*mptr)(void)) { pFunctionPointer_t add_function(T* tptr, void (T::*mptr)(void)) {
return add_function_helper(tptr, mptr); return add_function_helper(tptr, mptr);
} }
/** Add a function to be called by the Ticker at the beginning of the call chain /** Add a function to be called by the Ticker at the beginning of the call chain
* *
* @param tptr pointer to the object to call the member function on * @param tptr pointer to the object to call the member function on
* @param mptr pointer to the member function to be called * @param mptr pointer to the member function to be called
* *
* @returns * @returns
* The function object created for 'tptr' and 'mptr' * The function object created for 'tptr' and 'mptr'
*/ */
template<typename T> template<typename T>
pFunctionPointer_t add_function_front(T* tptr, void (T::*mptr)(void)) { pFunctionPointer_t add_function_front(T* tptr, void (T::*mptr)(void)) {
return add_function_helper(tptr, mptr, true); return add_function_helper(tptr, mptr, true);
} }
/** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds /** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
* *
* @param fptr pointer to the function to be called * @param fptr pointer to the function to be called
* @param t the time between calls in micro-seconds * @param t the time between calls in micro-seconds
* *
* @returns * @returns
* The function object created for 'fptr' * The function object created for 'fptr'
*/ */
pFunctionPointer_t attach_us(void (*fptr)(void), unsigned int t) { pFunctionPointer_t attach_us(void (*fptr)(void), unsigned int t) {
pFunctionPointer_t pf = _chain.add(fptr); pFunctionPointer_t pf = _chain.add(fptr);
setup(t); setup(t);
return pf; return pf;
} }
/** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
* *
* @param tptr pointer to the object to call the member function on * @param tptr pointer to the object to call the member function on
* @param mptr pointer to the member function to be called * @param mptr pointer to the member function to be called
* @param t the time between calls in micro-seconds * @param t the time between calls in micro-seconds
* *
* @returns * @returns
* The function object created for 'tptr' and 'mptr' * The function object created for 'tptr' and 'mptr'
*/ */
template<typename T> template<typename T>
pFunctionPointer_t attach_us(T* tptr, void (T::*mptr)(void), unsigned int t) { pFunctionPointer_t attach_us(T* tptr, void (T::*mptr)(void), unsigned int t) {
pFunctionPointer_t pf = _chain.add(mptr, tptr); pFunctionPointer_t pf = _chain.add(mptr, tptr);
setup(t); setup(t);
return pf; return pf;
} }
/** Detach the function /** Detach the function
*/ */
void detach(); void detach();
/** Remove a function from the Ticker's call chain /** Remove a function from the Ticker's call chain
* *
* @param pf the function object to remove * @param pf the function object to remove
* *
* @returns * @returns
* true if the function was found and removed, false otherwise * true if the function was found and removed, false otherwise
*/ */
bool remove_function(pFunctionPointer_t pf) { bool remove_function(pFunctionPointer_t pf) {
bool res = _chain.remove(pf); bool res = _chain.remove(pf);
if (res && _chain.size() == 0) if (res && _chain.size() == 0)
detach(); detach();
return res; return res;
} }
protected: protected:
void setup(unsigned int t); void setup(unsigned int t);
pFunctionPointer_t add_function_helper(void (*fptr)(void), bool front=false); pFunctionPointer_t add_function_helper(void (*fptr)(void), bool front=false);
virtual void handler(); virtual void handler();
template<typename T> template<typename T>
pFunctionPointer_t add_function_helper(T* tptr, void (T::*mptr)(void), bool front=false) { pFunctionPointer_t add_function_helper(T* tptr, void (T::*mptr)(void), bool front=false) {
if (_chain.size() == 0) if (_chain.size() == 0)
return NULL; return NULL;
return front ? _chain.add_front(tptr, mptr) : _chain.add(tptr, mptr); return front ? _chain.add_front(tptr, mptr) : _chain.add(tptr, mptr);
} }
unsigned int _delay; unsigned int _delay;
CallChain _chain; CallChain _chain;
}; };
} // namespace mbed } // namespace mbed
#endif #endif

View File

@ -1,43 +1,43 @@
/* mbed Microcontroller Library /* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited * Copyright (c) 2006-2013 ARM Limited
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "FunctionPointer.h" #include "FunctionPointer.h"
namespace mbed { namespace mbed {
FunctionPointer::FunctionPointer(void (*function)(void)) { FunctionPointer::FunctionPointer(void (*function)(void)) {
attach(function); attach(function);
} }
void FunctionPointer::attach(void (*function)(void)) { void FunctionPointer::attach(void (*function)(void)) {
_function = function; _function = function;
_object = 0; _object = 0;
} }
void FunctionPointer::call(void) { void FunctionPointer::call(void) {
if (_function) { if (_function) {
_function(); _function();
} else if (_object) { } else if (_object) {
_membercaller(_object, _member); _membercaller(_object, _member);
} }
} }
#ifdef MBED_OPERATORS #ifdef MBED_OPERATORS
void FunctionPointer::operator ()(void) { void FunctionPointer::operator ()(void) {
call(); call();
} }
#endif #endif
} // namespace mbed } // namespace mbed

View File

@ -1,110 +1,110 @@
/* mbed Microcontroller Library /* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited * Copyright (c) 2006-2013 ARM Limited
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "InterruptIn.h" #include "InterruptIn.h"
#if DEVICE_INTERRUPTIN #if DEVICE_INTERRUPTIN
namespace mbed { namespace mbed {
InterruptIn::InterruptIn(PinName pin) { InterruptIn::InterruptIn(PinName pin) {
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this); gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
gpio_init(&gpio, pin, PIN_INPUT); gpio_init(&gpio, pin, PIN_INPUT);
} }
InterruptIn::~InterruptIn() { InterruptIn::~InterruptIn() {
gpio_irq_free(&gpio_irq); gpio_irq_free(&gpio_irq);
} }
int InterruptIn::read() { int InterruptIn::read() {
return gpio_read(&gpio); return gpio_read(&gpio);
} }
void InterruptIn::mode(PinMode pull) { void InterruptIn::mode(PinMode pull) {
gpio_mode(&gpio, pull); gpio_mode(&gpio, pull);
} }
pFunctionPointer_t InterruptIn::rise(void (*fptr)(void)) { pFunctionPointer_t InterruptIn::rise(void (*fptr)(void)) {
pFunctionPointer_t pf = NULL; pFunctionPointer_t pf = NULL;
_rise.clear(); _rise.clear();
if (fptr) { if (fptr) {
pf = _rise.add(fptr); pf = _rise.add(fptr);
gpio_irq_set(&gpio_irq, IRQ_RISE, 1); gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
} else { } else {
gpio_irq_set(&gpio_irq, IRQ_RISE, 0); gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
} }
return pf; return pf;
} }
pFunctionPointer_t InterruptIn::rise_add_common(void (*fptr)(void), bool front) { pFunctionPointer_t InterruptIn::rise_add_common(void (*fptr)(void), bool front) {
if (NULL == fptr) if (NULL == fptr)
return NULL; return NULL;
pFunctionPointer_t pf = front ? _rise.add_front(fptr) : _rise.add(fptr); pFunctionPointer_t pf = front ? _rise.add_front(fptr) : _rise.add(fptr);
gpio_irq_set(&gpio_irq, IRQ_RISE, 1); gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
return pf; return pf;
} }
bool InterruptIn::rise_remove(pFunctionPointer_t pf) { bool InterruptIn::rise_remove(pFunctionPointer_t pf) {
bool res = _rise.remove(pf); bool res = _rise.remove(pf);
if (res && _rise.size() == 0) if (res && _rise.size() == 0)
gpio_irq_set(&gpio_irq, IRQ_RISE, 0); gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
return res; return res;
} }
pFunctionPointer_t InterruptIn::fall(void (*fptr)(void)) { pFunctionPointer_t InterruptIn::fall(void (*fptr)(void)) {
pFunctionPointer_t pf = NULL; pFunctionPointer_t pf = NULL;
_fall.clear(); _fall.clear();
if (fptr) { if (fptr) {
pf = _fall.add(fptr); pf = _fall.add(fptr);
gpio_irq_set(&gpio_irq, IRQ_FALL, 1); gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
} else { } else {
gpio_irq_set(&gpio_irq, IRQ_FALL, 0); gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
} }
return pf; return pf;
} }
pFunctionPointer_t InterruptIn::fall_add_common(void (*fptr)(void), bool front) { pFunctionPointer_t InterruptIn::fall_add_common(void (*fptr)(void), bool front) {
if (NULL == fptr) if (NULL == fptr)
return NULL; return NULL;
pFunctionPointer_t pf = front ? _fall.add_front(fptr) : _fall.add(fptr); pFunctionPointer_t pf = front ? _fall.add_front(fptr) : _fall.add(fptr);
gpio_irq_set(&gpio_irq, IRQ_FALL, 1); gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
return pf; return pf;
} }
bool InterruptIn::fall_remove(pFunctionPointer_t pf) { bool InterruptIn::fall_remove(pFunctionPointer_t pf) {
bool res = _fall.remove(pf); bool res = _fall.remove(pf);
if (res && _fall.size() == 0) if (res && _fall.size() == 0)
gpio_irq_set(&gpio_irq, IRQ_FALL, 0); gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
return res; return res;
} }
void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) { void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
InterruptIn *handler = (InterruptIn*)id; InterruptIn *handler = (InterruptIn*)id;
switch (event) { switch (event) {
case IRQ_RISE: handler->_rise.call(); break; case IRQ_RISE: handler->_rise.call(); break;
case IRQ_FALL: handler->_fall.call(); break; case IRQ_FALL: handler->_fall.call(); break;
case IRQ_NONE: break; case IRQ_NONE: break;
} }
} }
#ifdef MBED_OPERATORS #ifdef MBED_OPERATORS
InterruptIn::operator int() { InterruptIn::operator int() {
return read(); return read();
} }
#endif #endif
} // namespace mbed } // namespace mbed
#endif #endif

View File

@ -1,45 +1,45 @@
/* mbed Microcontroller Library /* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited * Copyright (c) 2006-2013 ARM Limited
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "Ticker.h" #include "Ticker.h"
#include "TimerEvent.h" #include "TimerEvent.h"
#include "FunctionPointer.h" #include "FunctionPointer.h"
namespace mbed { namespace mbed {
void Ticker::detach() { void Ticker::detach() {
remove(); remove();
_chain.clear(); _chain.clear();
} }
void Ticker::setup(unsigned int t) { void Ticker::setup(unsigned int t) {
remove(); remove();
_delay = t; _delay = t;
insert(_delay + us_ticker_read()); insert(_delay + us_ticker_read());
} }
void Ticker::handler() { void Ticker::handler() {
insert(event.timestamp + _delay); insert(event.timestamp + _delay);
_chain.call(); _chain.call();
} }
pFunctionPointer_t Ticker::add_function_helper(void (*fptr)(void), bool front) { pFunctionPointer_t Ticker::add_function_helper(void (*fptr)(void), bool front) {
if (_chain.size() == 0) if (_chain.size() == 0)
return NULL; return NULL;
return front ? _chain.add_front(fptr) : _chain.add(fptr); return front ? _chain.add_front(fptr) : _chain.add(fptr);
} }
} // namespace mbed } // namespace mbed

View File

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

View File

@ -45,7 +45,7 @@
// //
// <h> Watchdog Oscillator Control Register (WDTOSCCTRL) // <h> Watchdog Oscillator Control Register (WDTOSCCTRL)
// <o2.0..4> DIVSEL: Select Divider for Fclkana // <o2.0..4> DIVSEL: Select Divider for Fclkana
// <i> wdt_osc_clk = Fclkana/ (2 × (1 + DIVSEL)) // <i> wdt_osc_clk = Fclkana/ (2 * (1 + DIVSEL))
// <0-31> // <0-31>
// <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana) // <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana)
// <0=> Undefined // <0=> Undefined

View File

@ -45,7 +45,7 @@
// //
// <h> Watchdog Oscillator Control Register (WDTOSCCTRL) // <h> Watchdog Oscillator Control Register (WDTOSCCTRL)
// <o2.0..4> DIVSEL: Select Divider for Fclkana // <o2.0..4> DIVSEL: Select Divider for Fclkana
// <i> wdt_osc_clk = Fclkana/ (2 × (1 + DIVSEL)) // <i> wdt_osc_clk = Fclkana/ (2 * (1 + DIVSEL))
// <0-31> // <0-31>
// <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana) // <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana)
// <0=> Undefined // <0=> Undefined

View File

@ -45,7 +45,7 @@
// //
// <h> Watchdog Oscillator Control Register (WDTOSCCTRL) // <h> Watchdog Oscillator Control Register (WDTOSCCTRL)
// <o2.0..4> DIVSEL: Select Divider for Fclkana // <o2.0..4> DIVSEL: Select Divider for Fclkana
// <i> wdt_osc_clk = Fclkana/ (2 × (1 + DIVSEL)) // <i> wdt_osc_clk = Fclkana/ (2 * (1 + DIVSEL))
// <0-31> // <0-31>
// <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana) // <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana)
// <0=> Undefined // <0=> Undefined

View File

@ -45,7 +45,7 @@
// //
// <h> Watchdog Oscillator Control Register (WDTOSCCTRL) // <h> Watchdog Oscillator Control Register (WDTOSCCTRL)
// <o2.0..4> DIVSEL: Select Divider for Fclkana // <o2.0..4> DIVSEL: Select Divider for Fclkana
// <i> wdt_osc_clk = Fclkana/ (2 × (1 + DIVSEL)) // <i> wdt_osc_clk = Fclkana/ (2 * (1 + DIVSEL))
// <0-31> // <0-31>
// <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana) // <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana)
// <0=> Undefined // <0=> Undefined

View File

@ -41,7 +41,7 @@
// //
// <h> Watchdog Oscillator Control Register (WDTOSCCTRL) // <h> Watchdog Oscillator Control Register (WDTOSCCTRL)
// <o2.0..4> DIVSEL: Select Divider for Fclkana // <o2.0..4> DIVSEL: Select Divider for Fclkana
// <i> wdt_osc_clk = Fclkana/ (2 × (1 + DIVSEL)) // <i> wdt_osc_clk = Fclkana/ (2 * (1 + DIVSEL))
// <0-31> // <0-31>
// <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana) // <o2.5..8> FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana)
// <0=> Undefined // <0=> Undefined

View File

@ -1,105 +1,105 @@
/** /**
****************************************************************************** ******************************************************************************
* @file system_stm32f4xx.h * @file system_stm32f4xx.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.1.0
* @date 11-January-2013 * @date 11-January-2013
* @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
* You may obtain a copy of the License at: * You may obtain a copy of the License at:
* *
* http://www.st.com/software_license_agreement_liberty_v2 * http://www.st.com/software_license_agreement_liberty_v2
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
****************************************************************************** ******************************************************************************
*/ */
/** @addtogroup CMSIS /** @addtogroup CMSIS
* @{ * @{
*/ */
/** @addtogroup stm32f4xx_system /** @addtogroup stm32f4xx_system
* @{ * @{
*/ */
/** /**
* @brief Define to prevent recursive inclusion * @brief Define to prevent recursive inclusion
*/ */
#ifndef __SYSTEM_STM32F4XX_H #ifndef __SYSTEM_STM32F4XX_H
#define __SYSTEM_STM32F4XX_H #define __SYSTEM_STM32F4XX_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/** @addtogroup STM32F4xx_System_Includes /** @addtogroup STM32F4xx_System_Includes
* @{ * @{
*/ */
/** /**
* @} * @}
*/ */
/** @addtogroup STM32F4xx_System_Exported_types /** @addtogroup STM32F4xx_System_Exported_types
* @{ * @{
*/ */
extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
/** /**
* @} * @}
*/ */
/** @addtogroup STM32F4xx_System_Exported_Constants /** @addtogroup STM32F4xx_System_Exported_Constants
* @{ * @{
*/ */
/** /**
* @} * @}
*/ */
/** @addtogroup STM32F4xx_System_Exported_Macros /** @addtogroup STM32F4xx_System_Exported_Macros
* @{ * @{
*/ */
/** /**
* @} * @}
*/ */
/** @addtogroup STM32F4xx_System_Exported_Functions /** @addtogroup STM32F4xx_System_Exported_Functions
* @{ * @{
*/ */
extern void SystemInit(void); extern void SystemInit(void);
extern void SystemCoreClockUpdate(void); extern void SystemCoreClockUpdate(void);
/** /**
* @} * @}
*/ */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*__SYSTEM_STM32F4XX_H */ #endif /*__SYSTEM_STM32F4XX_H */
/** /**
* @} * @}
*/ */
/** /**
* @} * @}
*/ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/