This repo contains the libraries of Mbed for LPC1549 with following changes: - IAP commands. - EEPROM write and read. - UART write and read (public) - CAN can_s -> LPC_C_CAN0_Type *can
mbed/Ticker.h@0:820a69dfd200, 2015-04-14 (annotated)
- Committer:
- gmatarrubia
- Date:
- Tue Apr 14 15:00:13 2015 +0200
- Revision:
- 0:820a69dfd200
Initial repo. IAP commands, EEPROM write/read, UART write/read, CAN
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gmatarrubia |
0:820a69dfd200 | 1 | /* mbed Microcontroller Library |
gmatarrubia |
0:820a69dfd200 | 2 | * Copyright (c) 2006-2013 ARM Limited |
gmatarrubia |
0:820a69dfd200 | 3 | * |
gmatarrubia |
0:820a69dfd200 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
gmatarrubia |
0:820a69dfd200 | 5 | * you may not use this file except in compliance with the License. |
gmatarrubia |
0:820a69dfd200 | 6 | * You may obtain a copy of the License at |
gmatarrubia |
0:820a69dfd200 | 7 | * |
gmatarrubia |
0:820a69dfd200 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
gmatarrubia |
0:820a69dfd200 | 9 | * |
gmatarrubia |
0:820a69dfd200 | 10 | * Unless required by applicable law or agreed to in writing, software |
gmatarrubia |
0:820a69dfd200 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
gmatarrubia |
0:820a69dfd200 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
gmatarrubia |
0:820a69dfd200 | 13 | * See the License for the specific language governing permissions and |
gmatarrubia |
0:820a69dfd200 | 14 | * limitations under the License. |
gmatarrubia |
0:820a69dfd200 | 15 | */ |
gmatarrubia |
0:820a69dfd200 | 16 | #ifndef MBED_TICKER_H |
gmatarrubia |
0:820a69dfd200 | 17 | #define MBED_TICKER_H |
gmatarrubia |
0:820a69dfd200 | 18 | |
gmatarrubia |
0:820a69dfd200 | 19 | #include "TimerEvent.h" |
gmatarrubia |
0:820a69dfd200 | 20 | #include "FunctionPointer.h" |
gmatarrubia |
0:820a69dfd200 | 21 | |
gmatarrubia |
0:820a69dfd200 | 22 | namespace mbed { |
gmatarrubia |
0:820a69dfd200 | 23 | |
gmatarrubia |
0:820a69dfd200 | 24 | /** A Ticker is used to call a function at a recurring interval |
gmatarrubia |
0:820a69dfd200 | 25 | * |
gmatarrubia |
0:820a69dfd200 | 26 | * You can use as many seperate Ticker objects as you require. |
gmatarrubia |
0:820a69dfd200 | 27 | * |
gmatarrubia |
0:820a69dfd200 | 28 | * Example: |
gmatarrubia |
0:820a69dfd200 | 29 | * @code |
gmatarrubia |
0:820a69dfd200 | 30 | * // Toggle the blinking led after 5 seconds |
gmatarrubia |
0:820a69dfd200 | 31 | * |
gmatarrubia |
0:820a69dfd200 | 32 | * #include "mbed.h" |
gmatarrubia |
0:820a69dfd200 | 33 | * |
gmatarrubia |
0:820a69dfd200 | 34 | * Ticker timer; |
gmatarrubia |
0:820a69dfd200 | 35 | * DigitalOut led1(LED1); |
gmatarrubia |
0:820a69dfd200 | 36 | * DigitalOut led2(LED2); |
gmatarrubia |
0:820a69dfd200 | 37 | * |
gmatarrubia |
0:820a69dfd200 | 38 | * int flip = 0; |
gmatarrubia |
0:820a69dfd200 | 39 | * |
gmatarrubia |
0:820a69dfd200 | 40 | * void attime() { |
gmatarrubia |
0:820a69dfd200 | 41 | * flip = !flip; |
gmatarrubia |
0:820a69dfd200 | 42 | * } |
gmatarrubia |
0:820a69dfd200 | 43 | * |
gmatarrubia |
0:820a69dfd200 | 44 | * int main() { |
gmatarrubia |
0:820a69dfd200 | 45 | * timer.attach(&attime, 5); |
gmatarrubia |
0:820a69dfd200 | 46 | * while(1) { |
gmatarrubia |
0:820a69dfd200 | 47 | * if(flip == 0) { |
gmatarrubia |
0:820a69dfd200 | 48 | * led1 = !led1; |
gmatarrubia |
0:820a69dfd200 | 49 | * } else { |
gmatarrubia |
0:820a69dfd200 | 50 | * led2 = !led2; |
gmatarrubia |
0:820a69dfd200 | 51 | * } |
gmatarrubia |
0:820a69dfd200 | 52 | * wait(0.2); |
gmatarrubia |
0:820a69dfd200 | 53 | * } |
gmatarrubia |
0:820a69dfd200 | 54 | * } |
gmatarrubia |
0:820a69dfd200 | 55 | * @endcode |
gmatarrubia |
0:820a69dfd200 | 56 | */ |
gmatarrubia |
0:820a69dfd200 | 57 | class Ticker : public TimerEvent { |
gmatarrubia |
0:820a69dfd200 | 58 | |
gmatarrubia |
0:820a69dfd200 | 59 | public: |
gmatarrubia |
0:820a69dfd200 | 60 | |
gmatarrubia |
0:820a69dfd200 | 61 | /** Attach a function to be called by the Ticker, specifiying the interval in seconds |
gmatarrubia |
0:820a69dfd200 | 62 | * |
gmatarrubia |
0:820a69dfd200 | 63 | * @param fptr pointer to the function to be called |
gmatarrubia |
0:820a69dfd200 | 64 | * @param t the time between calls in seconds |
gmatarrubia |
0:820a69dfd200 | 65 | */ |
gmatarrubia |
0:820a69dfd200 | 66 | void attach(void (*fptr)(void), float t) { |
gmatarrubia |
0:820a69dfd200 | 67 | attach_us(fptr, t * 1000000.0f); |
gmatarrubia |
0:820a69dfd200 | 68 | } |
gmatarrubia |
0:820a69dfd200 | 69 | |
gmatarrubia |
0:820a69dfd200 | 70 | /** Attach a member function to be called by the Ticker, specifiying the interval in seconds |
gmatarrubia |
0:820a69dfd200 | 71 | * |
gmatarrubia |
0:820a69dfd200 | 72 | * @param tptr pointer to the object to call the member function on |
gmatarrubia |
0:820a69dfd200 | 73 | * @param mptr pointer to the member function to be called |
gmatarrubia |
0:820a69dfd200 | 74 | * @param t the time between calls in seconds |
gmatarrubia |
0:820a69dfd200 | 75 | */ |
gmatarrubia |
0:820a69dfd200 | 76 | template<typename T> |
gmatarrubia |
0:820a69dfd200 | 77 | void attach(T* tptr, void (T::*mptr)(void), float t) { |
gmatarrubia |
0:820a69dfd200 | 78 | attach_us(tptr, mptr, t * 1000000.0f); |
gmatarrubia |
0:820a69dfd200 | 79 | } |
gmatarrubia |
0:820a69dfd200 | 80 | |
gmatarrubia |
0:820a69dfd200 | 81 | /** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds |
gmatarrubia |
0:820a69dfd200 | 82 | * |
gmatarrubia |
0:820a69dfd200 | 83 | * @param fptr pointer to the function to be called |
gmatarrubia |
0:820a69dfd200 | 84 | * @param t the time between calls in micro-seconds |
gmatarrubia |
0:820a69dfd200 | 85 | */ |
gmatarrubia |
0:820a69dfd200 | 86 | void attach_us(void (*fptr)(void), timestamp_t t) { |
gmatarrubia |
0:820a69dfd200 | 87 | _function.attach(fptr); |
gmatarrubia |
0:820a69dfd200 | 88 | setup(t); |
gmatarrubia |
0:820a69dfd200 | 89 | } |
gmatarrubia |
0:820a69dfd200 | 90 | |
gmatarrubia |
0:820a69dfd200 | 91 | /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds |
gmatarrubia |
0:820a69dfd200 | 92 | * |
gmatarrubia |
0:820a69dfd200 | 93 | * @param tptr pointer to the object to call the member function on |
gmatarrubia |
0:820a69dfd200 | 94 | * @param mptr pointer to the member function to be called |
gmatarrubia |
0:820a69dfd200 | 95 | * @param t the time between calls in micro-seconds |
gmatarrubia |
0:820a69dfd200 | 96 | */ |
gmatarrubia |
0:820a69dfd200 | 97 | template<typename T> |
gmatarrubia |
0:820a69dfd200 | 98 | void attach_us(T* tptr, void (T::*mptr)(void), timestamp_t t) { |
gmatarrubia |
0:820a69dfd200 | 99 | _function.attach(tptr, mptr); |
gmatarrubia |
0:820a69dfd200 | 100 | setup(t); |
gmatarrubia |
0:820a69dfd200 | 101 | } |
gmatarrubia |
0:820a69dfd200 | 102 | |
gmatarrubia |
0:820a69dfd200 | 103 | virtual ~Ticker() { |
gmatarrubia |
0:820a69dfd200 | 104 | detach(); |
gmatarrubia |
0:820a69dfd200 | 105 | } |
gmatarrubia |
0:820a69dfd200 | 106 | |
gmatarrubia |
0:820a69dfd200 | 107 | /** Detach the function |
gmatarrubia |
0:820a69dfd200 | 108 | */ |
gmatarrubia |
0:820a69dfd200 | 109 | void detach(); |
gmatarrubia |
0:820a69dfd200 | 110 | |
gmatarrubia |
0:820a69dfd200 | 111 | protected: |
gmatarrubia |
0:820a69dfd200 | 112 | void setup(timestamp_t t); |
gmatarrubia |
0:820a69dfd200 | 113 | virtual void handler(); |
gmatarrubia |
0:820a69dfd200 | 114 | |
gmatarrubia |
0:820a69dfd200 | 115 | protected: |
gmatarrubia |
0:820a69dfd200 | 116 | timestamp_t _delay; /**< Time delay (in microseconds) for re-setting the multi-shot callback. */ |
gmatarrubia |
0:820a69dfd200 | 117 | FunctionPointer _function; /**< Callback. */ |
gmatarrubia |
0:820a69dfd200 | 118 | }; |
gmatarrubia |
0:820a69dfd200 | 119 | |
gmatarrubia |
0:820a69dfd200 | 120 | } // namespace mbed |
gmatarrubia |
0:820a69dfd200 | 121 | |
gmatarrubia |
0:820a69dfd200 | 122 | #endif |