test
Dependents: Telemetria_RX_SD_GPS_copy Telemetria_RX_SD_GPS Telemetria_TX Telemetria_TX ... more
Arduino-mbed-APIs/arduino-mbed.cpp@80:62f0b027efff, 2017-08-03 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Thu Aug 03 13:43:35 2017 +0200
- Revision:
- 80:62f0b027efff
- Parent:
- 79:8ae448a3c1fd
- Child:
- 84:3428e25c7157
Added proper wait_ms function which uses our timers
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut Tschemernjak | 46:e78a1d0391ac | 1 | /* |
Helmut Tschemernjak | 65:b2d98328fcba | 2 | * The file is Licensed under the Apache License, Version 2.0 |
Helmut Tschemernjak | 46:e78a1d0391ac | 3 | * (c) 2017 Helmut Tschemernjak |
Helmut Tschemernjak | 46:e78a1d0391ac | 4 | * 30826 Garbsen (Hannover) Germany |
Helmut Tschemernjak | 46:e78a1d0391ac | 5 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 6 | |
Helmut Tschemernjak | 65:b2d98328fcba | 7 | #ifdef ARDUINO |
Helmut Tschemernjak | 65:b2d98328fcba | 8 | |
Helmut Tschemernjak | 65:b2d98328fcba | 9 | using namespace std; |
Helmut Tschemernjak | 65:b2d98328fcba | 10 | |
Helmut Tschemernjak | 65:b2d98328fcba | 11 | #include "arduino-mbed.h" |
Helmut Tschemernjak | 75:7330dd86cdea | 12 | #include "arduino-util.h" |
Helmut Tschemernjak | 65:b2d98328fcba | 13 | |
Helmut Tschemernjak | 75:7330dd86cdea | 14 | Stream *ser; |
Helmut Tschemernjak | 75:7330dd86cdea | 15 | void InitSerial(Stream *serial) { |
Helmut Tschemernjak | 75:7330dd86cdea | 16 | ser = serial; |
Helmut Tschemernjak | 75:7330dd86cdea | 17 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 18 | |
Helmut Tschemernjak | 65:b2d98328fcba | 19 | static void pinInt00(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 20 | static void pinInt01(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 21 | static void pinInt02(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 22 | static void pinInt03(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 23 | static void pinInt04(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 24 | static void pinInt05(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 25 | static void pinInt06(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 26 | static void pinInt07(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 27 | static void pinInt08(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 28 | static void pinInt09(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 29 | static void pinInt10(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 30 | static void pinInt11(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 31 | static void pinInt12(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 32 | static void pinInt13(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 33 | static void pinInt14(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 34 | static void pinInt15(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 35 | static void pinInt16(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 36 | static void pinInt17(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 37 | static void pinInt18(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 38 | static void pinInt19(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 39 | static void pinInt20(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 40 | static void pinInt21(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 41 | static void pinInt22(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 42 | static void pinInt23(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 43 | static void pinInt24(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 44 | static void pinInt25(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 45 | static void pinInt26(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 46 | static void pinInt27(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 47 | static void pinInt28(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 48 | static void pinInt29(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 49 | static void pinInt30(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 50 | static void pinInt31(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 51 | static void pinInt32(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 52 | static void pinInt33(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 53 | static void pinInt34(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 54 | static void pinInt35(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 55 | static void pinInt36(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 56 | static void pinInt37(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 57 | static void pinInt38(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 58 | static void pinInt39(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 59 | static void pinInt40(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 60 | static void pinInt41(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 61 | static void pinInt42(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 62 | static void pinInt43(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 63 | static void pinInt44(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 64 | static void pinInt45(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 65 | static void pinInt46(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 66 | static void pinInt47(void); |
Helmut Tschemernjak | 46:e78a1d0391ac | 67 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 68 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 69 | |
Helmut Tschemernjak | 65:b2d98328fcba | 70 | #define MAX_MCU_PINS 48 |
Helmut Tschemernjak | 65:b2d98328fcba | 71 | class InterruptIn; |
Helmut Tschemernjak | 65:b2d98328fcba | 72 | struct intPtrTable { |
Helmut Tschemernjak | 65:b2d98328fcba | 73 | void (*func)(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 74 | InterruptIn *context; |
Helmut Tschemernjak | 65:b2d98328fcba | 75 | } intPtrTable[MAX_MCU_PINS] = { |
Helmut Tschemernjak | 65:b2d98328fcba | 76 | { pinInt00, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 77 | { pinInt01, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 78 | { pinInt02, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 79 | { pinInt03, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 80 | { pinInt04, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 81 | { pinInt05, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 82 | { pinInt06, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 83 | { pinInt07, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 84 | { pinInt08, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 85 | { pinInt09, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 86 | { pinInt10, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 87 | { pinInt11, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 88 | { pinInt12, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 89 | { pinInt13, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 90 | { pinInt14, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 91 | { pinInt15, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 92 | { pinInt16, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 93 | { pinInt17, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 94 | { pinInt18, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 95 | { pinInt19, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 96 | { pinInt20, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 97 | { pinInt21, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 98 | { pinInt22, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 99 | { pinInt23, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 100 | { pinInt24, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 101 | { pinInt25, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 102 | { pinInt26, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 103 | { pinInt27, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 104 | { pinInt28, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 105 | { pinInt29, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 106 | { pinInt30, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 107 | { pinInt31, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 108 | { pinInt32, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 109 | { pinInt33, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 110 | { pinInt34, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 111 | { pinInt35, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 112 | { pinInt36, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 113 | { pinInt37, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 114 | { pinInt38, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 115 | { pinInt39, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 116 | { pinInt40, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 117 | { pinInt41, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 118 | { pinInt42, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 119 | { pinInt43, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 120 | { pinInt44, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 121 | { pinInt45, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 122 | { pinInt46, NULL }, |
Helmut Tschemernjak | 65:b2d98328fcba | 123 | { pinInt47, NULL } |
Helmut Tschemernjak | 65:b2d98328fcba | 124 | }; // our max MCUs pins |
Helmut Tschemernjak | 46:e78a1d0391ac | 125 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 126 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 127 | |
Helmut Tschemernjak | 65:b2d98328fcba | 128 | static void pinInt00(void) { InterruptIn::_irq_handler(intPtrTable[0].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 129 | static void pinInt01(void) { InterruptIn::_irq_handler(intPtrTable[1].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 130 | static void pinInt02(void) { InterruptIn::_irq_handler(intPtrTable[2].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 131 | static void pinInt03(void) { InterruptIn::_irq_handler(intPtrTable[3].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 132 | static void pinInt04(void) { InterruptIn::_irq_handler(intPtrTable[4].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 133 | static void pinInt05(void) { InterruptIn::_irq_handler(intPtrTable[5].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 134 | static void pinInt06(void) { InterruptIn::_irq_handler(intPtrTable[6].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 135 | static void pinInt07(void) { InterruptIn::_irq_handler(intPtrTable[7].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 136 | static void pinInt08(void) { InterruptIn::_irq_handler(intPtrTable[8].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 137 | static void pinInt09(void) { InterruptIn::_irq_handler(intPtrTable[9].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 138 | static void pinInt10(void) { InterruptIn::_irq_handler(intPtrTable[10].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 139 | static void pinInt11(void) { InterruptIn::_irq_handler(intPtrTable[11].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 140 | static void pinInt12(void) { InterruptIn::_irq_handler(intPtrTable[12].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 141 | static void pinInt13(void) { InterruptIn::_irq_handler(intPtrTable[13].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 142 | static void pinInt14(void) { InterruptIn::_irq_handler(intPtrTable[14].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 143 | static void pinInt15(void) { InterruptIn::_irq_handler(intPtrTable[15].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 144 | static void pinInt16(void) { InterruptIn::_irq_handler(intPtrTable[16].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 145 | static void pinInt17(void) { InterruptIn::_irq_handler(intPtrTable[17].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 146 | static void pinInt18(void) { InterruptIn::_irq_handler(intPtrTable[18].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 147 | static void pinInt19(void) { InterruptIn::_irq_handler(intPtrTable[19].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 148 | static void pinInt20(void) { InterruptIn::_irq_handler(intPtrTable[20].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 149 | static void pinInt21(void) { InterruptIn::_irq_handler(intPtrTable[21].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 150 | static void pinInt22(void) { InterruptIn::_irq_handler(intPtrTable[22].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 151 | static void pinInt23(void) { InterruptIn::_irq_handler(intPtrTable[23].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 152 | static void pinInt24(void) { InterruptIn::_irq_handler(intPtrTable[24].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 153 | static void pinInt25(void) { InterruptIn::_irq_handler(intPtrTable[25].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 154 | static void pinInt26(void) { InterruptIn::_irq_handler(intPtrTable[26].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 155 | static void pinInt27(void) { InterruptIn::_irq_handler(intPtrTable[27].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 156 | static void pinInt28(void) { InterruptIn::_irq_handler(intPtrTable[28].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 157 | static void pinInt29(void) { InterruptIn::_irq_handler(intPtrTable[29].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 158 | static void pinInt30(void) { InterruptIn::_irq_handler(intPtrTable[30].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 159 | static void pinInt31(void) { InterruptIn::_irq_handler(intPtrTable[31].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 160 | static void pinInt32(void) { InterruptIn::_irq_handler(intPtrTable[32].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 161 | static void pinInt33(void) { InterruptIn::_irq_handler(intPtrTable[33].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 162 | static void pinInt34(void) { InterruptIn::_irq_handler(intPtrTable[34].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 163 | static void pinInt35(void) { InterruptIn::_irq_handler(intPtrTable[35].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 164 | static void pinInt36(void) { InterruptIn::_irq_handler(intPtrTable[36].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 165 | static void pinInt37(void) { InterruptIn::_irq_handler(intPtrTable[37].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 166 | static void pinInt38(void) { InterruptIn::_irq_handler(intPtrTable[38].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 167 | static void pinInt39(void) { InterruptIn::_irq_handler(intPtrTable[39].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 168 | static void pinInt40(void) { InterruptIn::_irq_handler(intPtrTable[40].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 169 | static void pinInt41(void) { InterruptIn::_irq_handler(intPtrTable[41].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 170 | static void pinInt42(void) { InterruptIn::_irq_handler(intPtrTable[42].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 171 | static void pinInt43(void) { InterruptIn::_irq_handler(intPtrTable[43].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 172 | static void pinInt44(void) { InterruptIn::_irq_handler(intPtrTable[44].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 173 | static void pinInt45(void) { InterruptIn::_irq_handler(intPtrTable[45].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 174 | static void pinInt46(void) { InterruptIn::_irq_handler(intPtrTable[46].context); } |
Helmut Tschemernjak | 65:b2d98328fcba | 175 | static void pinInt47(void) { InterruptIn::_irq_handler(intPtrTable[47].context); } |
Helmut Tschemernjak | 46:e78a1d0391ac | 176 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 177 | |
Helmut Tschemernjak | 80:62f0b027efff | 178 | void wait_ms(uint32_t ms) |
Helmut Tschemernjak | 80:62f0b027efff | 179 | { |
Helmut Tschemernjak | 80:62f0b027efff | 180 | uint32_t start = ms_getTicker(); |
Helmut Tschemernjak | 80:62f0b027efff | 181 | |
Helmut Tschemernjak | 80:62f0b027efff | 182 | while (true) { |
Helmut Tschemernjak | 80:62f0b027efff | 183 | uint32_t t = ms_getTicker(); |
Helmut Tschemernjak | 80:62f0b027efff | 184 | if (t < start) // warp. |
Helmut Tschemernjak | 80:62f0b027efff | 185 | start = 0; |
Helmut Tschemernjak | 80:62f0b027efff | 186 | if (t > (start + ms)) |
Helmut Tschemernjak | 80:62f0b027efff | 187 | break; |
Helmut Tschemernjak | 80:62f0b027efff | 188 | } |
Helmut Tschemernjak | 80:62f0b027efff | 189 | } |
Helmut Tschemernjak | 80:62f0b027efff | 190 | |
Helmut Tschemernjak | 77:7f227a4dffe6 | 191 | struct TimeoutVector TimeOuts[MAX_TIMEOUTS]; |
Helmut Tschemernjak | 46:e78a1d0391ac | 192 | |
Helmut Tschemernjak | 65:b2d98328fcba | 193 | void |
Helmut Tschemernjak | 65:b2d98328fcba | 194 | InterruptIn::rise(Callback<void()> func) { |
Helmut Tschemernjak | 65:b2d98328fcba | 195 | if (_gpioPin >= MAX_MCU_PINS-1) |
Helmut Tschemernjak | 65:b2d98328fcba | 196 | return; |
Helmut Tschemernjak | 65:b2d98328fcba | 197 | if (func) { |
Helmut Tschemernjak | 65:b2d98328fcba | 198 | _func = func; |
Helmut Tschemernjak | 65:b2d98328fcba | 199 | intPtrTable[_gpioPin].context = this; |
Helmut Tschemernjak | 69:d440a5b04708 | 200 | attachInterrupt(MYdigitalPinToInterrupt(_gpioPin), intPtrTable[_gpioPin].func, RISING); |
Helmut Tschemernjak | 65:b2d98328fcba | 201 | } else { |
Helmut Tschemernjak | 65:b2d98328fcba | 202 | _func = InterruptIn::donothing; |
Helmut Tschemernjak | 65:b2d98328fcba | 203 | intPtrTable[_gpioPin].context = NULL; |
Helmut Tschemernjak | 65:b2d98328fcba | 204 | detachInterrupt(_gpioPin); |
Helmut Tschemernjak | 46:e78a1d0391ac | 205 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 206 | }; |
Helmut Tschemernjak | 46:e78a1d0391ac | 207 | |
Helmut Tschemernjak | 65:b2d98328fcba | 208 | void |
Helmut Tschemernjak | 65:b2d98328fcba | 209 | InterruptIn::fall(Callback<void()> func) { |
Helmut Tschemernjak | 65:b2d98328fcba | 210 | if (func) { |
Helmut Tschemernjak | 65:b2d98328fcba | 211 | _func = func; |
Helmut Tschemernjak | 65:b2d98328fcba | 212 | intPtrTable[_gpioPin].context = this; |
Helmut Tschemernjak | 69:d440a5b04708 | 213 | attachInterrupt(MYdigitalPinToInterrupt(_gpioPin), intPtrTable[_gpioPin].func, FALLING); |
Helmut Tschemernjak | 65:b2d98328fcba | 214 | } else { |
Helmut Tschemernjak | 65:b2d98328fcba | 215 | _func = InterruptIn::donothing; |
Helmut Tschemernjak | 65:b2d98328fcba | 216 | intPtrTable[_gpioPin].context = NULL; |
Helmut Tschemernjak | 65:b2d98328fcba | 217 | detachInterrupt(_gpioPin); |
Helmut Tschemernjak | 46:e78a1d0391ac | 218 | } |
Helmut Tschemernjak | 46:e78a1d0391ac | 219 | } |
Helmut Tschemernjak | 46:e78a1d0391ac | 220 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 221 | |
Helmut Tschemernjak | 70:1d496aae2819 | 222 | uint32_t s_getTicker(void) |
Helmut Tschemernjak | 70:1d496aae2819 | 223 | { |
Helmut Tschemernjak | 70:1d496aae2819 | 224 | long long ns = ns_getTicker(); |
Helmut Tschemernjak | 70:1d496aae2819 | 225 | ns /= (long long)1000000000; // to secs |
Helmut Tschemernjak | 70:1d496aae2819 | 226 | |
Helmut Tschemernjak | 70:1d496aae2819 | 227 | int secs = ns; |
Helmut Tschemernjak | 70:1d496aae2819 | 228 | return secs; |
Helmut Tschemernjak | 70:1d496aae2819 | 229 | } |
Helmut Tschemernjak | 70:1d496aae2819 | 230 | |
Helmut Tschemernjak | 70:1d496aae2819 | 231 | |
Helmut Tschemernjak | 67:d3afd803f40d | 232 | uint32_t ms_getTicker(void) |
Helmut Tschemernjak | 67:d3afd803f40d | 233 | { |
Helmut Tschemernjak | 67:d3afd803f40d | 234 | uint32_t us = us_getTicker(); |
Helmut Tschemernjak | 67:d3afd803f40d | 235 | |
Helmut Tschemernjak | 67:d3afd803f40d | 236 | us /= 1000; // to ms |
Helmut Tschemernjak | 67:d3afd803f40d | 237 | return us; |
Helmut Tschemernjak | 67:d3afd803f40d | 238 | } |
Helmut Tschemernjak | 67:d3afd803f40d | 239 | |
Helmut Tschemernjak | 67:d3afd803f40d | 240 | uint32_t us_getTicker(void) |
Helmut Tschemernjak | 67:d3afd803f40d | 241 | { |
Helmut Tschemernjak | 67:d3afd803f40d | 242 | long long ns = ns_getTicker(); |
Helmut Tschemernjak | 67:d3afd803f40d | 243 | |
Helmut Tschemernjak | 67:d3afd803f40d | 244 | ns /= (long long)1000; // to us |
Helmut Tschemernjak | 67:d3afd803f40d | 245 | uint32_t us = ns & 0xffffffff; |
Helmut Tschemernjak | 67:d3afd803f40d | 246 | |
Helmut Tschemernjak | 67:d3afd803f40d | 247 | return us; |
Helmut Tschemernjak | 67:d3afd803f40d | 248 | } |
Helmut Tschemernjak | 67:d3afd803f40d | 249 | |
Helmut Tschemernjak | 67:d3afd803f40d | 250 | |
Helmut Tschemernjak | 65:b2d98328fcba | 251 | void |
Helmut Tschemernjak | 65:b2d98328fcba | 252 | Timeout::insert(void) |
Helmut Tschemernjak | 65:b2d98328fcba | 253 | { |
Helmut Tschemernjak | 65:b2d98328fcba | 254 | noInterrupts(); |
Helmut Tschemernjak | 65:b2d98328fcba | 255 | for (int i = 0; i < MAX_TIMEOUTS-1; i++) { |
Helmut Tschemernjak | 65:b2d98328fcba | 256 | struct TimeoutVector *tvp = &TimeOuts[i]; |
Helmut Tschemernjak | 79:8ae448a3c1fd | 257 | if (tvp->timer == this) // already here, timer has been restartet. |
Helmut Tschemernjak | 79:8ae448a3c1fd | 258 | break; |
Helmut Tschemernjak | 65:b2d98328fcba | 259 | if (tvp->timer == NULL) { |
Helmut Tschemernjak | 65:b2d98328fcba | 260 | tvp->timer = this; |
Helmut Tschemernjak | 65:b2d98328fcba | 261 | break; |
Helmut Tschemernjak | 65:b2d98328fcba | 262 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 263 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 264 | interrupts(); |
Helmut Tschemernjak | 65:b2d98328fcba | 265 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 266 | |
Helmut Tschemernjak | 65:b2d98328fcba | 267 | void |
Helmut Tschemernjak | 65:b2d98328fcba | 268 | Timeout::remove(void) |
Helmut Tschemernjak | 65:b2d98328fcba | 269 | { |
Helmut Tschemernjak | 65:b2d98328fcba | 270 | noInterrupts(); |
Helmut Tschemernjak | 65:b2d98328fcba | 271 | for (int i = 0; i < MAX_TIMEOUTS-1; i++) { |
Helmut Tschemernjak | 65:b2d98328fcba | 272 | struct TimeoutVector *tvp = &TimeOuts[i]; |
Helmut Tschemernjak | 65:b2d98328fcba | 273 | if (tvp->timer == this) { |
Helmut Tschemernjak | 65:b2d98328fcba | 274 | tvp->timer = NULL; |
Helmut Tschemernjak | 65:b2d98328fcba | 275 | break; |
Helmut Tschemernjak | 65:b2d98328fcba | 276 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 277 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 278 | interrupts(); |
Helmut Tschemernjak | 65:b2d98328fcba | 279 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 280 | |
Helmut Tschemernjak | 65:b2d98328fcba | 281 | |
Helmut Tschemernjak | 65:b2d98328fcba | 282 | void |
Helmut Tschemernjak | 67:d3afd803f40d | 283 | Timeout::restart() |
Helmut Tschemernjak | 65:b2d98328fcba | 284 | { |
Helmut Tschemernjak | 77:7f227a4dffe6 | 285 | Tcc *t = getTimeout_tcc(); |
Helmut Tschemernjak | 67:d3afd803f40d | 286 | uint64_t timeout = ~0; |
Helmut Tschemernjak | 65:b2d98328fcba | 287 | |
Helmut Tschemernjak | 65:b2d98328fcba | 288 | /* |
Helmut Tschemernjak | 65:b2d98328fcba | 289 | * find the lowest timeout value which is our the next timeout |
Helmut Tschemernjak | 65:b2d98328fcba | 290 | * zero means stop the timer. |
Helmut Tschemernjak | 65:b2d98328fcba | 291 | */ |
Helmut Tschemernjak | 65:b2d98328fcba | 292 | noInterrupts(); |
Helmut Tschemernjak | 65:b2d98328fcba | 293 | for (int i = 0; i < MAX_TIMEOUTS-1; i++) { |
Helmut Tschemernjak | 65:b2d98328fcba | 294 | struct TimeoutVector *tvp = &TimeOuts[i]; |
Helmut Tschemernjak | 67:d3afd803f40d | 295 | if (tvp->timer) { |
Helmut Tschemernjak | 67:d3afd803f40d | 296 | if (tvp->timer->_timeout < timeout) { |
Helmut Tschemernjak | 67:d3afd803f40d | 297 | timeout = tvp->timer->_timeout; |
Helmut Tschemernjak | 65:b2d98328fcba | 298 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 299 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 300 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 301 | interrupts(); |
Helmut Tschemernjak | 65:b2d98328fcba | 302 | |
Helmut Tschemernjak | 67:d3afd803f40d | 303 | if (timeout == (uint64_t)~0) { |
Helmut Tschemernjak | 67:d3afd803f40d | 304 | stopTimer(t); |
Helmut Tschemernjak | 65:b2d98328fcba | 305 | return; |
Helmut Tschemernjak | 65:b2d98328fcba | 306 | } |
Helmut Tschemernjak | 67:d3afd803f40d | 307 | |
Helmut Tschemernjak | 67:d3afd803f40d | 308 | uint64_t nsecs = ns_getTicker(); |
Helmut Tschemernjak | 65:b2d98328fcba | 309 | |
Helmut Tschemernjak | 67:d3afd803f40d | 310 | if (timeout > nsecs) { |
Helmut Tschemernjak | 67:d3afd803f40d | 311 | startTimer(t, (uint64_t)timeout - (uint64_t)nsecs); |
Helmut Tschemernjak | 65:b2d98328fcba | 312 | return; |
Helmut Tschemernjak | 65:b2d98328fcba | 313 | } else { |
Helmut Tschemernjak | 67:d3afd803f40d | 314 | startTimer(t, (uint64_t)1); // just one nsec to trigger interrrupt |
Helmut Tschemernjak | 65:b2d98328fcba | 315 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 316 | } |
Helmut Tschemernjak | 67:d3afd803f40d | 317 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 318 | #endif // ARDUINO |