fft

Dependencies:   BSP_DISCO_F746NG SDFileSystem_Warning_Fixed

Committer:
aria19970520
Date:
Fri Mar 06 06:52:14 2020 +0000
Revision:
3:6f7e05dd8d15
Parent:
0:3e46577dc273
fft

Who changed what in which revision?

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