MCU driver/HAL for the Picocell Gateway concentrator board. The firmware implements either a USB CDC protocol or a UART protocol to bridge commands coming from host to the SX1308 SPI interface.

Committer:
dgabino
Date:
Wed Apr 11 14:42:47 2018 +0000
Revision:
0:c76361bd82e8
Initial commit

Who changed what in which revision?

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