test
Dependents: Telemetria_RX_SD_GPS_copy Telemetria_RX_SD_GPS Telemetria_TX Telemetria_TX ... more
Arduino-mbed-APIs/arduino-mbed.cpp@77:7f227a4dffe6, 2017-07-31 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Mon Jul 31 16:11:17 2017 +0200
- Revision:
- 77:7f227a4dffe6
- Parent:
- 76:79f8ca9c8025
- Child:
- 79:8ae448a3c1fd
Moved SAMD timer and sleep code into new file arduino-d21.cpp
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 | 77:7f227a4dffe6 | 178 | struct TimeoutVector TimeOuts[MAX_TIMEOUTS]; |
Helmut Tschemernjak | 46:e78a1d0391ac | 179 | |
Helmut Tschemernjak | 65:b2d98328fcba | 180 | void |
Helmut Tschemernjak | 65:b2d98328fcba | 181 | InterruptIn::rise(Callback<void()> func) { |
Helmut Tschemernjak | 65:b2d98328fcba | 182 | if (_gpioPin >= MAX_MCU_PINS-1) |
Helmut Tschemernjak | 65:b2d98328fcba | 183 | return; |
Helmut Tschemernjak | 65:b2d98328fcba | 184 | if (func) { |
Helmut Tschemernjak | 65:b2d98328fcba | 185 | _func = func; |
Helmut Tschemernjak | 65:b2d98328fcba | 186 | intPtrTable[_gpioPin].context = this; |
Helmut Tschemernjak | 69:d440a5b04708 | 187 | attachInterrupt(MYdigitalPinToInterrupt(_gpioPin), intPtrTable[_gpioPin].func, RISING); |
Helmut Tschemernjak | 65:b2d98328fcba | 188 | } else { |
Helmut Tschemernjak | 65:b2d98328fcba | 189 | _func = InterruptIn::donothing; |
Helmut Tschemernjak | 65:b2d98328fcba | 190 | intPtrTable[_gpioPin].context = NULL; |
Helmut Tschemernjak | 65:b2d98328fcba | 191 | detachInterrupt(_gpioPin); |
Helmut Tschemernjak | 46:e78a1d0391ac | 192 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 193 | }; |
Helmut Tschemernjak | 46:e78a1d0391ac | 194 | |
Helmut Tschemernjak | 65:b2d98328fcba | 195 | void |
Helmut Tschemernjak | 65:b2d98328fcba | 196 | InterruptIn::fall(Callback<void()> func) { |
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, FALLING); |
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 | 46:e78a1d0391ac | 206 | } |
Helmut Tschemernjak | 46:e78a1d0391ac | 207 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 208 | |
Helmut Tschemernjak | 70:1d496aae2819 | 209 | uint32_t s_getTicker(void) |
Helmut Tschemernjak | 70:1d496aae2819 | 210 | { |
Helmut Tschemernjak | 70:1d496aae2819 | 211 | long long ns = ns_getTicker(); |
Helmut Tschemernjak | 70:1d496aae2819 | 212 | ns /= (long long)1000000000; // to secs |
Helmut Tschemernjak | 70:1d496aae2819 | 213 | |
Helmut Tschemernjak | 70:1d496aae2819 | 214 | int secs = ns; |
Helmut Tschemernjak | 70:1d496aae2819 | 215 | return secs; |
Helmut Tschemernjak | 70:1d496aae2819 | 216 | } |
Helmut Tschemernjak | 70:1d496aae2819 | 217 | |
Helmut Tschemernjak | 70:1d496aae2819 | 218 | |
Helmut Tschemernjak | 67:d3afd803f40d | 219 | uint32_t ms_getTicker(void) |
Helmut Tschemernjak | 67:d3afd803f40d | 220 | { |
Helmut Tschemernjak | 67:d3afd803f40d | 221 | uint32_t us = us_getTicker(); |
Helmut Tschemernjak | 67:d3afd803f40d | 222 | |
Helmut Tschemernjak | 67:d3afd803f40d | 223 | us /= 1000; // to ms |
Helmut Tschemernjak | 67:d3afd803f40d | 224 | return us; |
Helmut Tschemernjak | 67:d3afd803f40d | 225 | } |
Helmut Tschemernjak | 67:d3afd803f40d | 226 | |
Helmut Tschemernjak | 67:d3afd803f40d | 227 | uint32_t us_getTicker(void) |
Helmut Tschemernjak | 67:d3afd803f40d | 228 | { |
Helmut Tschemernjak | 67:d3afd803f40d | 229 | long long ns = ns_getTicker(); |
Helmut Tschemernjak | 67:d3afd803f40d | 230 | |
Helmut Tschemernjak | 67:d3afd803f40d | 231 | ns /= (long long)1000; // to us |
Helmut Tschemernjak | 67:d3afd803f40d | 232 | uint32_t us = ns & 0xffffffff; |
Helmut Tschemernjak | 67:d3afd803f40d | 233 | |
Helmut Tschemernjak | 67:d3afd803f40d | 234 | return us; |
Helmut Tschemernjak | 67:d3afd803f40d | 235 | } |
Helmut Tschemernjak | 67:d3afd803f40d | 236 | |
Helmut Tschemernjak | 67:d3afd803f40d | 237 | |
Helmut Tschemernjak | 65:b2d98328fcba | 238 | void |
Helmut Tschemernjak | 65:b2d98328fcba | 239 | Timeout::insert(void) |
Helmut Tschemernjak | 65:b2d98328fcba | 240 | { |
Helmut Tschemernjak | 65:b2d98328fcba | 241 | noInterrupts(); |
Helmut Tschemernjak | 65:b2d98328fcba | 242 | for (int i = 0; i < MAX_TIMEOUTS-1; i++) { |
Helmut Tschemernjak | 65:b2d98328fcba | 243 | struct TimeoutVector *tvp = &TimeOuts[i]; |
Helmut Tschemernjak | 65:b2d98328fcba | 244 | if (tvp->timer == NULL) { |
Helmut Tschemernjak | 65:b2d98328fcba | 245 | tvp->timer = this; |
Helmut Tschemernjak | 65:b2d98328fcba | 246 | break; |
Helmut Tschemernjak | 65:b2d98328fcba | 247 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 248 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 249 | interrupts(); |
Helmut Tschemernjak | 65:b2d98328fcba | 250 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 251 | |
Helmut Tschemernjak | 65:b2d98328fcba | 252 | void |
Helmut Tschemernjak | 65:b2d98328fcba | 253 | Timeout::remove(void) |
Helmut Tschemernjak | 65:b2d98328fcba | 254 | { |
Helmut Tschemernjak | 65:b2d98328fcba | 255 | noInterrupts(); |
Helmut Tschemernjak | 65:b2d98328fcba | 256 | for (int i = 0; i < MAX_TIMEOUTS-1; i++) { |
Helmut Tschemernjak | 65:b2d98328fcba | 257 | struct TimeoutVector *tvp = &TimeOuts[i]; |
Helmut Tschemernjak | 65:b2d98328fcba | 258 | if (tvp->timer == this) { |
Helmut Tschemernjak | 65:b2d98328fcba | 259 | tvp->timer = NULL; |
Helmut Tschemernjak | 65:b2d98328fcba | 260 | break; |
Helmut Tschemernjak | 65:b2d98328fcba | 261 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 262 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 263 | interrupts(); |
Helmut Tschemernjak | 65:b2d98328fcba | 264 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 265 | |
Helmut Tschemernjak | 65:b2d98328fcba | 266 | |
Helmut Tschemernjak | 65:b2d98328fcba | 267 | void |
Helmut Tschemernjak | 67:d3afd803f40d | 268 | Timeout::restart() |
Helmut Tschemernjak | 65:b2d98328fcba | 269 | { |
Helmut Tschemernjak | 77:7f227a4dffe6 | 270 | Tcc *t = getTimeout_tcc(); |
Helmut Tschemernjak | 67:d3afd803f40d | 271 | uint64_t timeout = ~0; |
Helmut Tschemernjak | 65:b2d98328fcba | 272 | |
Helmut Tschemernjak | 65:b2d98328fcba | 273 | /* |
Helmut Tschemernjak | 65:b2d98328fcba | 274 | * find the lowest timeout value which is our the next timeout |
Helmut Tschemernjak | 65:b2d98328fcba | 275 | * zero means stop the timer. |
Helmut Tschemernjak | 65:b2d98328fcba | 276 | */ |
Helmut Tschemernjak | 65:b2d98328fcba | 277 | noInterrupts(); |
Helmut Tschemernjak | 65:b2d98328fcba | 278 | for (int i = 0; i < MAX_TIMEOUTS-1; i++) { |
Helmut Tschemernjak | 65:b2d98328fcba | 279 | struct TimeoutVector *tvp = &TimeOuts[i]; |
Helmut Tschemernjak | 67:d3afd803f40d | 280 | if (tvp->timer) { |
Helmut Tschemernjak | 67:d3afd803f40d | 281 | if (tvp->timer->_timeout < timeout) { |
Helmut Tschemernjak | 67:d3afd803f40d | 282 | timeout = tvp->timer->_timeout; |
Helmut Tschemernjak | 65:b2d98328fcba | 283 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 284 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 285 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 286 | interrupts(); |
Helmut Tschemernjak | 65:b2d98328fcba | 287 | |
Helmut Tschemernjak | 67:d3afd803f40d | 288 | if (timeout == (uint64_t)~0) { |
Helmut Tschemernjak | 67:d3afd803f40d | 289 | stopTimer(t); |
Helmut Tschemernjak | 65:b2d98328fcba | 290 | return; |
Helmut Tschemernjak | 65:b2d98328fcba | 291 | } |
Helmut Tschemernjak | 67:d3afd803f40d | 292 | |
Helmut Tschemernjak | 67:d3afd803f40d | 293 | uint64_t nsecs = ns_getTicker(); |
Helmut Tschemernjak | 65:b2d98328fcba | 294 | |
Helmut Tschemernjak | 67:d3afd803f40d | 295 | if (timeout > nsecs) { |
Helmut Tschemernjak | 67:d3afd803f40d | 296 | startTimer(t, (uint64_t)timeout - (uint64_t)nsecs); |
Helmut Tschemernjak | 65:b2d98328fcba | 297 | return; |
Helmut Tschemernjak | 65:b2d98328fcba | 298 | } else { |
Helmut Tschemernjak | 67:d3afd803f40d | 299 | startTimer(t, (uint64_t)1); // just one nsec to trigger interrrupt |
Helmut Tschemernjak | 65:b2d98328fcba | 300 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 301 | } |
Helmut Tschemernjak | 67:d3afd803f40d | 302 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 303 | #endif // ARDUINO |