...

Dependents:   2doejemplo Labo_TRSE_Drone

Fork of mbed by mbed official

Committer:
emilmont
Date:
Wed Jan 16 12:56:34 2013 +0000
Revision:
55:d722ed6a4237
Parent:
54:71b101360fb9
Child:
59:0883845fe643
Include "sleep_api.h" in "mbed.h"
Add initial IAR toolchain support
LPC I2C: better handling of status
Add sleep mode support for the LPC1768
Correct GCC "__semihost" definition
Correct GCC "_isatty" retargeting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 44:24d45a770a51 1 /* mbed Microcontroller Library
emilmont 54:71b101360fb9 2 * Copyright (c) 2006-2013 ARM Limited
emilmont 44:24d45a770a51 3 *
emilmont 44:24d45a770a51 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
emilmont 44:24d45a770a51 5 * of this software and associated documentation files (the "Software"), to deal
emilmont 44:24d45a770a51 6 * in the Software without restriction, including without limitation the rights
emilmont 44:24d45a770a51 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
emilmont 44:24d45a770a51 8 * copies of the Software, and to permit persons to whom the Software is
emilmont 44:24d45a770a51 9 * furnished to do so, subject to the following conditions:
emilmont 44:24d45a770a51 10 *
emilmont 44:24d45a770a51 11 * The above copyright notice and this permission notice shall be included in
emilmont 44:24d45a770a51 12 * all copies or substantial portions of the Software.
emilmont 44:24d45a770a51 13 *
emilmont 44:24d45a770a51 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
emilmont 44:24d45a770a51 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
emilmont 44:24d45a770a51 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
emilmont 44:24d45a770a51 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
emilmont 44:24d45a770a51 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
emilmont 44:24d45a770a51 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
emilmont 44:24d45a770a51 20 * SOFTWARE.
emilmont 44:24d45a770a51 21 */
simon.ford@mbed.co.uk 9:cf0d45ce28a6 22 #ifndef MBED_TICKER_H
simon.ford@mbed.co.uk 9:cf0d45ce28a6 23 #define MBED_TICKER_H
simon.ford@mbed.co.uk 9:cf0d45ce28a6 24
simon.ford@mbed.co.uk 9:cf0d45ce28a6 25 #include "TimerEvent.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 26 #include "FunctionPointer.h"
simon.ford@mbed.co.uk 9:cf0d45ce28a6 27
simon.ford@mbed.co.uk 9:cf0d45ce28a6 28 namespace mbed {
simon.ford@mbed.co.uk 9:cf0d45ce28a6 29
emilmont 43:e2ed12d17f06 30 /** A Ticker is used to call a function at a recurring interval
simon.ford@mbed.co.uk 9:cf0d45ce28a6 31 *
emilmont 55:d722ed6a4237 32 * You can use as many seperate Ticker objects as you require.
rolf.meyer@arm.com 11:1c1ebd0324fa 33 *
rolf.meyer@arm.com 11:1c1ebd0324fa 34 * Example:
emilmont 43:e2ed12d17f06 35 * @code
emilmont 43:e2ed12d17f06 36 * // Toggle the blinking led after 5 seconds
rolf.meyer@arm.com 11:1c1ebd0324fa 37 *
emilmont 43:e2ed12d17f06 38 * #include "mbed.h"
emilmont 44:24d45a770a51 39 *
emilmont 43:e2ed12d17f06 40 * Ticker timer;
emilmont 43:e2ed12d17f06 41 * DigitalOut led1(LED1);
emilmont 43:e2ed12d17f06 42 * DigitalOut led2(LED2);
emilmont 55:d722ed6a4237 43 *
emilmont 43:e2ed12d17f06 44 * int flip = 0;
emilmont 55:d722ed6a4237 45 *
emilmont 43:e2ed12d17f06 46 * void attime() {
emilmont 43:e2ed12d17f06 47 * flip = !flip;
emilmont 43:e2ed12d17f06 48 * }
emilmont 43:e2ed12d17f06 49 *
emilmont 43:e2ed12d17f06 50 * int main() {
emilmont 43:e2ed12d17f06 51 * timer.attach(&attime, 5);
emilmont 43:e2ed12d17f06 52 * while(1) {
emilmont 43:e2ed12d17f06 53 * if(flip == 0) {
emilmont 43:e2ed12d17f06 54 * led1 = !led1;
emilmont 43:e2ed12d17f06 55 * } else {
emilmont 43:e2ed12d17f06 56 * led2 = !led2;
emilmont 43:e2ed12d17f06 57 * }
emilmont 43:e2ed12d17f06 58 * wait(0.2);
emilmont 43:e2ed12d17f06 59 * }
emilmont 43:e2ed12d17f06 60 * }
emilmont 43:e2ed12d17f06 61 * @endcode
simon.ford@mbed.co.uk 9:cf0d45ce28a6 62 */
simon.ford@mbed.co.uk 9:cf0d45ce28a6 63 class Ticker : public TimerEvent {
simon.ford@mbed.co.uk 9:cf0d45ce28a6 64
simon.ford@mbed.co.uk 9:cf0d45ce28a6 65 public:
simon.ford@mbed.co.uk 9:cf0d45ce28a6 66
emilmont 43:e2ed12d17f06 67 /** Attach a function to be called by the Ticker, specifiying the interval in seconds
emilmont 44:24d45a770a51 68 *
emilmont 43:e2ed12d17f06 69 * @param fptr pointer to the function to be called
emilmont 43:e2ed12d17f06 70 * @param t the time between calls in seconds
simon.ford@mbed.co.uk 9:cf0d45ce28a6 71 */
simon.ford@mbed.co.uk 9:cf0d45ce28a6 72 void attach(void (*fptr)(void), float t) {
simon.ford@mbed.co.uk 9:cf0d45ce28a6 73 attach_us(fptr, t * 1000000.0f);
simon.ford@mbed.co.uk 9:cf0d45ce28a6 74 }
emilmont 55:d722ed6a4237 75
emilmont 43:e2ed12d17f06 76 /** Attach a member function to be called by the Ticker, specifiying the interval in seconds
emilmont 44:24d45a770a51 77 *
emilmont 43:e2ed12d17f06 78 * @param tptr pointer to the object to call the member function on
emilmont 43:e2ed12d17f06 79 * @param mptr pointer to the member function to be called
emilmont 43:e2ed12d17f06 80 * @param t the time between calls in seconds
simon.ford@mbed.co.uk 9:cf0d45ce28a6 81 */
simon.ford@mbed.co.uk 9:cf0d45ce28a6 82 template<typename T>
simon.ford@mbed.co.uk 9:cf0d45ce28a6 83 void attach(T* tptr, void (T::*mptr)(void), float t) {
simon.ford@mbed.co.uk 9:cf0d45ce28a6 84 attach_us(tptr, mptr, t * 1000000.0f);
simon.ford@mbed.co.uk 9:cf0d45ce28a6 85 }
emilmont 55:d722ed6a4237 86
emilmont 43:e2ed12d17f06 87 /** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
emilmont 44:24d45a770a51 88 *
emilmont 43:e2ed12d17f06 89 * @param fptr pointer to the function to be called
emilmont 43:e2ed12d17f06 90 * @param t the time between calls in micro-seconds
simon.ford@mbed.co.uk 9:cf0d45ce28a6 91 */
simon.ford@mbed.co.uk 9:cf0d45ce28a6 92 void attach_us(void (*fptr)(void), unsigned int t) {
simon.ford@mbed.co.uk 9:cf0d45ce28a6 93 _function.attach(fptr);
simon.ford@mbed.co.uk 9:cf0d45ce28a6 94 setup(t);
simon.ford@mbed.co.uk 9:cf0d45ce28a6 95 }
simon.ford@mbed.co.uk 9:cf0d45ce28a6 96
emilmont 43:e2ed12d17f06 97 /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
emilmont 44:24d45a770a51 98 *
emilmont 43:e2ed12d17f06 99 * @param tptr pointer to the object to call the member function on
emilmont 43:e2ed12d17f06 100 * @param mptr pointer to the member function to be called
emilmont 43:e2ed12d17f06 101 * @param t the time between calls in micro-seconds
emilmont 55:d722ed6a4237 102 */
simon.ford@mbed.co.uk 9:cf0d45ce28a6 103 template<typename T>
simon.ford@mbed.co.uk 9:cf0d45ce28a6 104 void attach_us(T* tptr, void (T::*mptr)(void), unsigned int t) {
simon.ford@mbed.co.uk 9:cf0d45ce28a6 105 _function.attach(tptr, mptr);
simon.ford@mbed.co.uk 9:cf0d45ce28a6 106 setup(t);
simon.ford@mbed.co.uk 9:cf0d45ce28a6 107 }
emilmont 55:d722ed6a4237 108
emilmont 43:e2ed12d17f06 109 /** Detach the function
emilmont 44:24d45a770a51 110 */
simon.ford@mbed.co.uk 9:cf0d45ce28a6 111 void detach();
rolf.meyer@arm.com 11:1c1ebd0324fa 112
simon.ford@mbed.co.uk 9:cf0d45ce28a6 113 protected:
simon.ford@mbed.co.uk 9:cf0d45ce28a6 114 void setup(unsigned int t);
simon.ford@mbed.co.uk 9:cf0d45ce28a6 115 virtual void handler();
emilmont 55:d722ed6a4237 116
rolf.meyer@arm.com 11:1c1ebd0324fa 117 unsigned int _delay;
rolf.meyer@arm.com 11:1c1ebd0324fa 118 FunctionPointer _function;
rolf.meyer@arm.com 11:1c1ebd0324fa 119 };
simon.ford@mbed.co.uk 9:cf0d45ce28a6 120
rolf.meyer@arm.com 11:1c1ebd0324fa 121 } // namespace mbed
simon.ford@mbed.co.uk 9:cf0d45ce28a6 122
simon.ford@mbed.co.uk 9:cf0d45ce28a6 123 #endif