An example project for the Heltec Turtle LoRa board (STM32L4 and SX1276 chips). The projects is only supported for the Nucleo-L432KC board platform in the mbed online and offline compiler environment. Visit www.radioshuttle.de (choose Turtle board) for instructions. Note that most source files and libraries are open source, however some files especially the RadioShuttle core protocol is copyrighted work. Check header for details.
Dependencies: mbed BufferedSerial SX1276GenericLib OLED_SSD1306 HELIOS_Si7021 NVProperty RadioShuttle-STM32L4 USBDeviceHT
utils.cpp@33:617765dcce6c, 2019-02-12 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Tue Feb 12 16:54:21 2019 +0100
- Revision:
- 33:617765dcce6c
- Parent:
- 30:8bc655c9b224
- Child:
- 37:77fa81e4ad79
Updated to work as well without FEATURE_USBSERIAL
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut64 | 0:3b6c2ce051a6 | 1 | /* |
Helmut Tschemernjak | 1:56fdc660a26a | 2 | * Copyright (c) 2019 Helmut Tschemernjak |
Helmut64 | 0:3b6c2ce051a6 | 3 | * 30826 Garbsen (Hannover) Germany |
Helmut64 | 0:3b6c2ce051a6 | 4 | */ |
Helmut Tschemernjak | 1:56fdc660a26a | 5 | #include "main.h" |
Helmut Tschemernjak | 5:c6a960febe80 | 6 | |
Helmut Tschemernjak | 5:c6a960febe80 | 7 | volatile uint32_t PendingInterrupts; // global interrupt mask of received interrupts |
Helmut Tschemernjak | 5:c6a960febe80 | 8 | |
Helmut64 | 0:3b6c2ce051a6 | 9 | time_t cvt_date(char const *date, char const *time); |
Helmut64 | 0:3b6c2ce051a6 | 10 | |
Helmut64 | 0:3b6c2ce051a6 | 11 | BufferedSerial *ser; |
Helmut64 | 0:3b6c2ce051a6 | 12 | #ifdef FEATURE_USBSERIAL |
Helmut64 | 0:3b6c2ce051a6 | 13 | USBSerialBuffered *usb; |
Helmut64 | 0:3b6c2ce051a6 | 14 | #endif |
Helmut64 | 0:3b6c2ce051a6 | 15 | bool _useDprintf; |
Helmut64 | 0:3b6c2ce051a6 | 16 | |
Helmut64 | 0:3b6c2ce051a6 | 17 | void InitSerial(int timeout, DigitalOut *led) |
Helmut64 | 0:3b6c2ce051a6 | 18 | { |
Helmut64 | 0:3b6c2ce051a6 | 19 | _useDprintf = true; |
Helmut Tschemernjak | 33:617765dcce6c | 20 | bool uartActive = true; |
Helmut Tschemernjak | 33:617765dcce6c | 21 | |
Helmut64 | 0:3b6c2ce051a6 | 22 | #ifdef FEATURE_USBSERIAL |
Helmut Tschemernjak | 33:617765dcce6c | 23 | DigitalOut rx(USBRX); // need to turn rx low to avoid floating signal |
Helmut Tschemernjak | 33:617765dcce6c | 24 | rx = 0; |
Helmut Tschemernjak | 33:617765dcce6c | 25 | DigitalIn uartRX(USBRX); |
Helmut Tschemernjak | 33:617765dcce6c | 26 | uartActive = uartRX.read(); |
Helmut64 | 0:3b6c2ce051a6 | 27 | if (!uartActive) { |
Helmut64 | 0:3b6c2ce051a6 | 28 | usb = new USBSerialBuffered(); |
Helmut64 | 0:3b6c2ce051a6 | 29 | Timer t; |
Helmut64 | 0:3b6c2ce051a6 | 30 | t.start(); |
Helmut64 | 0:3b6c2ce051a6 | 31 | while(!usb->connected()) { |
Helmut64 | 0:3b6c2ce051a6 | 32 | if (led) |
Helmut64 | 0:3b6c2ce051a6 | 33 | *led = !*led; |
Helmut64 | 0:3b6c2ce051a6 | 34 | wait_ms(100); |
Helmut64 | 0:3b6c2ce051a6 | 35 | if (timeout) { |
Helmut Tschemernjak | 5:c6a960febe80 | 36 | if (t.read_ms() >= timeout) { |
Helmut Tschemernjak | 5:c6a960febe80 | 37 | delete usb; |
Helmut Tschemernjak | 5:c6a960febe80 | 38 | usb = NULL; |
Helmut Tschemernjak | 5:c6a960febe80 | 39 | DigitalOut rx(USBRX); |
Helmut Tschemernjak | 5:c6a960febe80 | 40 | rx = 0; // need to turn tx low to avoid floating signal |
Helmut Tschemernjak | 5:c6a960febe80 | 41 | } |
Helmut Tschemernjak | 33:617765dcce6c | 42 | } |
Helmut Tschemernjak | 33:617765dcce6c | 43 | } |
Helmut Tschemernjak | 33:617765dcce6c | 44 | } |
Helmut64 | 0:3b6c2ce051a6 | 45 | #endif |
Helmut Tschemernjak | 33:617765dcce6c | 46 | if (uartActive) { |
Helmut64 | 0:3b6c2ce051a6 | 47 | ser = new BufferedSerial(USBTX, USBRX); |
Helmut64 | 0:3b6c2ce051a6 | 48 | ser->baud(230400); |
Helmut64 | 0:3b6c2ce051a6 | 49 | ser->format(8); |
Helmut64 | 0:3b6c2ce051a6 | 50 | } |
Helmut Tschemernjak | 33:617765dcce6c | 51 | |
Helmut64 | 0:3b6c2ce051a6 | 52 | time_t t = cvt_date(__DATE__, __TIME__); |
Helmut64 | 0:3b6c2ce051a6 | 53 | if (t > time(NULL)) { |
Helmut64 | 0:3b6c2ce051a6 | 54 | set_time(t); |
Helmut64 | 0:3b6c2ce051a6 | 55 | } |
Helmut64 | 0:3b6c2ce051a6 | 56 | } |
Helmut64 | 0:3b6c2ce051a6 | 57 | |
Helmut64 | 0:3b6c2ce051a6 | 58 | void printTimeStamp() |
Helmut64 | 0:3b6c2ce051a6 | 59 | { |
Helmut64 | 0:3b6c2ce051a6 | 60 | static LowPowerTimer *timer; |
Helmut64 | 0:3b6c2ce051a6 | 61 | if (!timer) { |
Helmut64 | 0:3b6c2ce051a6 | 62 | timer = new LowPowerTimer(); |
Helmut64 | 0:3b6c2ce051a6 | 63 | timer->start(); |
Helmut64 | 0:3b6c2ce051a6 | 64 | } |
Helmut64 | 0:3b6c2ce051a6 | 65 | time_t seconds = time(NULL); |
Helmut64 | 0:3b6c2ce051a6 | 66 | struct tm *tm = localtime(&seconds); |
Helmut64 | 0:3b6c2ce051a6 | 67 | int usecs = timer->read_us(); |
Helmut64 | 0:3b6c2ce051a6 | 68 | if (usecs < 0) { |
Helmut64 | 0:3b6c2ce051a6 | 69 | usecs = 0; |
Helmut64 | 0:3b6c2ce051a6 | 70 | timer->stop(); |
Helmut64 | 0:3b6c2ce051a6 | 71 | timer->reset(); |
Helmut64 | 0:3b6c2ce051a6 | 72 | timer->start(); |
Helmut64 | 0:3b6c2ce051a6 | 73 | } |
Helmut64 | 0:3b6c2ce051a6 | 74 | int msecs = usecs % 1000000; |
Helmut64 | 0:3b6c2ce051a6 | 75 | |
Helmut64 | 0:3b6c2ce051a6 | 76 | rprintf("%02d:%02d:%02d.%06d ", tm->tm_hour, tm->tm_min, tm->tm_sec, msecs); |
Helmut64 | 0:3b6c2ce051a6 | 77 | } |
Helmut64 | 0:3b6c2ce051a6 | 78 | |
Helmut64 | 0:3b6c2ce051a6 | 79 | void dprintf(const char *format, ...) |
Helmut64 | 0:3b6c2ce051a6 | 80 | { |
Helmut64 | 0:3b6c2ce051a6 | 81 | std::va_list arg; |
Helmut64 | 0:3b6c2ce051a6 | 82 | |
Helmut64 | 0:3b6c2ce051a6 | 83 | va_start(arg, format); |
Helmut64 | 0:3b6c2ce051a6 | 84 | VAprintf(true, true, _useDprintf, format, arg); |
Helmut64 | 0:3b6c2ce051a6 | 85 | va_end(arg); |
Helmut64 | 0:3b6c2ce051a6 | 86 | } |
Helmut64 | 0:3b6c2ce051a6 | 87 | |
Helmut64 | 0:3b6c2ce051a6 | 88 | void rprintf(const char *format, ...) |
Helmut64 | 0:3b6c2ce051a6 | 89 | { |
Helmut64 | 0:3b6c2ce051a6 | 90 | std::va_list arg; |
Helmut64 | 0:3b6c2ce051a6 | 91 | |
Helmut64 | 0:3b6c2ce051a6 | 92 | va_start(arg, format); |
Helmut64 | 0:3b6c2ce051a6 | 93 | VAprintf(false, false, _useDprintf, format, arg); |
Helmut64 | 0:3b6c2ce051a6 | 94 | va_end(arg); |
Helmut64 | 0:3b6c2ce051a6 | 95 | } |
Helmut64 | 0:3b6c2ce051a6 | 96 | |
Helmut64 | 0:3b6c2ce051a6 | 97 | void VAprintf(bool timstamp, bool newline, bool printEnabled, const char *format, va_list arg) |
Helmut64 | 0:3b6c2ce051a6 | 98 | { |
Helmut64 | 0:3b6c2ce051a6 | 99 | if (!printEnabled) |
Helmut64 | 0:3b6c2ce051a6 | 100 | return; |
Helmut64 | 0:3b6c2ce051a6 | 101 | |
Helmut64 | 0:3b6c2ce051a6 | 102 | if (timstamp) |
Helmut64 | 0:3b6c2ce051a6 | 103 | printTimeStamp(); |
Helmut64 | 0:3b6c2ce051a6 | 104 | #ifdef FEATURE_USBSERIAL |
Helmut64 | 0:3b6c2ce051a6 | 105 | if (usb) { |
Helmut64 | 0:3b6c2ce051a6 | 106 | usb->vprintf_irqsafe(format, arg); |
Helmut64 | 0:3b6c2ce051a6 | 107 | if (newline) |
Helmut64 | 0:3b6c2ce051a6 | 108 | usb->printf_irqsafe("\r\n"); |
Helmut Tschemernjak | 33:617765dcce6c | 109 | } |
Helmut64 | 0:3b6c2ce051a6 | 110 | #endif |
Helmut Tschemernjak | 33:617765dcce6c | 111 | if (ser) { |
Helmut64 | 0:3b6c2ce051a6 | 112 | // serial jas |
Helmut64 | 0:3b6c2ce051a6 | 113 | int r = 0; |
Helmut64 | 0:3b6c2ce051a6 | 114 | r = vsnprintf(NULL, 0, format, arg); |
Helmut64 | 0:3b6c2ce051a6 | 115 | if (r < 82) { |
Helmut64 | 0:3b6c2ce051a6 | 116 | char buffer[82+1]; |
Helmut64 | 0:3b6c2ce051a6 | 117 | |
Helmut64 | 0:3b6c2ce051a6 | 118 | vsnprintf(buffer, sizeof(buffer), format, arg); |
Helmut64 | 0:3b6c2ce051a6 | 119 | r = ser->write(buffer, r); |
Helmut64 | 0:3b6c2ce051a6 | 120 | } else { |
Helmut64 | 0:3b6c2ce051a6 | 121 | char *buffer = new char[r+1]; |
Helmut64 | 0:3b6c2ce051a6 | 122 | if (buffer) { |
Helmut64 | 0:3b6c2ce051a6 | 123 | vsnprintf(buffer, r+1, format, arg); |
Helmut64 | 0:3b6c2ce051a6 | 124 | r = ser->write(buffer, r); |
Helmut64 | 0:3b6c2ce051a6 | 125 | delete[] buffer; |
Helmut64 | 0:3b6c2ce051a6 | 126 | } else { |
Helmut64 | 0:3b6c2ce051a6 | 127 | error("%s %d cannot alloc memory (%d bytes)!\r\n", __FILE__, __LINE__, r+1); |
Helmut64 | 0:3b6c2ce051a6 | 128 | r = 0; |
Helmut64 | 0:3b6c2ce051a6 | 129 | } |
Helmut64 | 0:3b6c2ce051a6 | 130 | } |
Helmut64 | 0:3b6c2ce051a6 | 131 | if (newline) |
Helmut64 | 0:3b6c2ce051a6 | 132 | ser->write("\r\n", 2); |
Helmut64 | 0:3b6c2ce051a6 | 133 | } |
Helmut64 | 0:3b6c2ce051a6 | 134 | } |
Helmut64 | 0:3b6c2ce051a6 | 135 | |
Helmut Tschemernjak | 22:9cca40fcb25e | 136 | char *ConsoleReadline(char *buf, int buflen, bool echo, int timeout_ms) |
Helmut Tschemernjak | 14:d9340be18c3d | 137 | { |
Helmut Tschemernjak | 14:d9340be18c3d | 138 | int count = 0; |
Helmut Tschemernjak | 14:d9340be18c3d | 139 | memset(buf, 0, buflen); |
Helmut Tschemernjak | 14:d9340be18c3d | 140 | |
Helmut Tschemernjak | 33:617765dcce6c | 141 | #ifdef FEATURE_USBSERIAL |
Helmut Tschemernjak | 22:9cca40fcb25e | 142 | if (usb == NULL && ser == NULL) |
Helmut Tschemernjak | 22:9cca40fcb25e | 143 | return NULL; |
Helmut Tschemernjak | 33:617765dcce6c | 144 | #else |
Helmut Tschemernjak | 33:617765dcce6c | 145 | if (ser == NULL) |
Helmut Tschemernjak | 33:617765dcce6c | 146 | return NULL; |
Helmut Tschemernjak | 33:617765dcce6c | 147 | #endif |
Helmut Tschemernjak | 22:9cca40fcb25e | 148 | |
Helmut Tschemernjak | 22:9cca40fcb25e | 149 | Timer t; |
Helmut Tschemernjak | 22:9cca40fcb25e | 150 | int start = 0; |
Helmut Tschemernjak | 22:9cca40fcb25e | 151 | if (timeout_ms) { |
Helmut Tschemernjak | 22:9cca40fcb25e | 152 | t.start(); |
Helmut Tschemernjak | 22:9cca40fcb25e | 153 | start = t.read_ms(); |
Helmut Tschemernjak | 22:9cca40fcb25e | 154 | } |
Helmut Tschemernjak | 22:9cca40fcb25e | 155 | |
Helmut Tschemernjak | 33:617765dcce6c | 156 | #ifdef FEATURE_USBSERIAL |
Helmut Tschemernjak | 22:9cca40fcb25e | 157 | if (usb) { |
Helmut Tschemernjak | 14:d9340be18c3d | 158 | usb->flush(); |
Helmut Tschemernjak | 14:d9340be18c3d | 159 | while(usb->readable()) |
Helmut Tschemernjak | 14:d9340be18c3d | 160 | usb->getc(); // flush old chars |
Helmut Tschemernjak | 14:d9340be18c3d | 161 | } |
Helmut Tschemernjak | 33:617765dcce6c | 162 | #endif |
Helmut Tschemernjak | 14:d9340be18c3d | 163 | if (ser) { |
Helmut Tschemernjak | 14:d9340be18c3d | 164 | while(ser->readable()) |
Helmut Tschemernjak | 14:d9340be18c3d | 165 | ser->getc(); // flush old chars |
Helmut Tschemernjak | 22:9cca40fcb25e | 166 | } |
Helmut Tschemernjak | 14:d9340be18c3d | 167 | |
Helmut Tschemernjak | 22:9cca40fcb25e | 168 | while(true) { |
Helmut Tschemernjak | 22:9cca40fcb25e | 169 | if (timeout_ms && t.read_ms() - start > timeout_ms) |
Helmut Tschemernjak | 22:9cca40fcb25e | 170 | return NULL; |
Helmut Tschemernjak | 22:9cca40fcb25e | 171 | int c = -2; |
Helmut Tschemernjak | 33:617765dcce6c | 172 | #ifdef FEATURE_USBSERIAL |
Helmut Tschemernjak | 22:9cca40fcb25e | 173 | if (usb && usb->readable()) |
Helmut Tschemernjak | 22:9cca40fcb25e | 174 | c = usb->getc(); |
Helmut Tschemernjak | 33:617765dcce6c | 175 | #endif |
Helmut Tschemernjak | 22:9cca40fcb25e | 176 | if (ser && ser->readable()) |
Helmut Tschemernjak | 22:9cca40fcb25e | 177 | c = ser->getc(); |
Helmut Tschemernjak | 22:9cca40fcb25e | 178 | if (c == -2) |
Helmut Tschemernjak | 22:9cca40fcb25e | 179 | continue; |
Helmut Tschemernjak | 22:9cca40fcb25e | 180 | |
Helmut Tschemernjak | 22:9cca40fcb25e | 181 | if (c == 0 || c == -1 || c == '\r' || c == '\n' || c == 3 || c == 4) |
Helmut Tschemernjak | 22:9cca40fcb25e | 182 | break; |
Helmut Tschemernjak | 22:9cca40fcb25e | 183 | if (c == '\b' || c == 0x7f) { // backspace |
Helmut Tschemernjak | 22:9cca40fcb25e | 184 | if (count < 1) |
Helmut Tschemernjak | 22:9cca40fcb25e | 185 | continue; |
Helmut Tschemernjak | 22:9cca40fcb25e | 186 | buf[--count] = 0; |
Helmut Tschemernjak | 22:9cca40fcb25e | 187 | if (echo) |
Helmut Tschemernjak | 22:9cca40fcb25e | 188 | rprintf("\b \b"); |
Helmut Tschemernjak | 33:617765dcce6c | 189 | #ifdef FEATURE_USBSERIAL |
Helmut Tschemernjak | 22:9cca40fcb25e | 190 | if (usb) |
Helmut Tschemernjak | 22:9cca40fcb25e | 191 | usb->flush(); |
Helmut Tschemernjak | 33:617765dcce6c | 192 | #endif |
Helmut Tschemernjak | 22:9cca40fcb25e | 193 | continue; |
Helmut Tschemernjak | 14:d9340be18c3d | 194 | } |
Helmut Tschemernjak | 22:9cca40fcb25e | 195 | if (echo) { |
Helmut Tschemernjak | 22:9cca40fcb25e | 196 | rprintf("%c", c); |
Helmut Tschemernjak | 33:617765dcce6c | 197 | #ifdef FEATURE_USBSERIAL |
Helmut Tschemernjak | 22:9cca40fcb25e | 198 | if (usb) |
Helmut Tschemernjak | 22:9cca40fcb25e | 199 | usb->flush(); |
Helmut Tschemernjak | 33:617765dcce6c | 200 | #endif |
Helmut Tschemernjak | 22:9cca40fcb25e | 201 | } |
Helmut Tschemernjak | 22:9cca40fcb25e | 202 | |
Helmut Tschemernjak | 33:617765dcce6c | 203 | start = t.read_ms(); |
Helmut Tschemernjak | 22:9cca40fcb25e | 204 | buf[count] = c; |
Helmut Tschemernjak | 22:9cca40fcb25e | 205 | if (count++ >= buflen-2) |
Helmut Tschemernjak | 22:9cca40fcb25e | 206 | break; |
Helmut Tschemernjak | 22:9cca40fcb25e | 207 | // dprintf("Got char: '%c'(%d)", c, c); |
Helmut Tschemernjak | 14:d9340be18c3d | 208 | } |
Helmut Tschemernjak | 22:9cca40fcb25e | 209 | |
Helmut Tschemernjak | 14:d9340be18c3d | 210 | if (echo) |
Helmut Tschemernjak | 14:d9340be18c3d | 211 | rprintf("\r\n"); |
Helmut Tschemernjak | 14:d9340be18c3d | 212 | if (count) |
Helmut Tschemernjak | 14:d9340be18c3d | 213 | return buf; |
Helmut Tschemernjak | 14:d9340be18c3d | 214 | return NULL; |
Helmut Tschemernjak | 14:d9340be18c3d | 215 | } |
Helmut Tschemernjak | 14:d9340be18c3d | 216 | |
Helmut64 | 0:3b6c2ce051a6 | 217 | |
Helmut64 | 30:8bc655c9b224 | 218 | void dump(const char *title, void *data, int len) |
Helmut64 | 30:8bc655c9b224 | 219 | { |
Helmut64 | 30:8bc655c9b224 | 220 | dump(title, data, len, false); |
Helmut64 | 30:8bc655c9b224 | 221 | } |
Helmut64 | 30:8bc655c9b224 | 222 | |
Helmut64 | 0:3b6c2ce051a6 | 223 | void dump(const char *title, const void *data, int len, bool dwords) |
Helmut64 | 0:3b6c2ce051a6 | 224 | { |
Helmut Tschemernjak | 14:d9340be18c3d | 225 | dprintf("dump(\"%s\", 0x%x, %d bytes)", title, (unsigned int)data, len); |
Helmut64 | 0:3b6c2ce051a6 | 226 | |
Helmut64 | 0:3b6c2ce051a6 | 227 | int i, j, cnt; |
Helmut64 | 0:3b6c2ce051a6 | 228 | unsigned char *u; |
Helmut64 | 0:3b6c2ce051a6 | 229 | const int width = 16; |
Helmut64 | 0:3b6c2ce051a6 | 230 | const int seppos = 7; |
Helmut64 | 0:3b6c2ce051a6 | 231 | |
Helmut64 | 0:3b6c2ce051a6 | 232 | cnt = 0; |
Helmut64 | 0:3b6c2ce051a6 | 233 | u = (unsigned char *)data; |
Helmut64 | 0:3b6c2ce051a6 | 234 | while (len > 0) { |
Helmut64 | 0:3b6c2ce051a6 | 235 | rprintf("%08x: ", (unsigned int)data + cnt); |
Helmut64 | 0:3b6c2ce051a6 | 236 | if (dwords) { |
Helmut64 | 0:3b6c2ce051a6 | 237 | unsigned int *ip = ( unsigned int *)u; |
Helmut64 | 0:3b6c2ce051a6 | 238 | rprintf(" 0x%08x\r\n", *ip); |
Helmut64 | 0:3b6c2ce051a6 | 239 | u+= 4; |
Helmut64 | 0:3b6c2ce051a6 | 240 | len -= 4; |
Helmut64 | 0:3b6c2ce051a6 | 241 | cnt += 4; |
Helmut64 | 0:3b6c2ce051a6 | 242 | continue; |
Helmut64 | 0:3b6c2ce051a6 | 243 | } |
Helmut64 | 0:3b6c2ce051a6 | 244 | cnt += width; |
Helmut64 | 0:3b6c2ce051a6 | 245 | j = len < width ? len : width; |
Helmut64 | 0:3b6c2ce051a6 | 246 | for (i = 0; i < j; i++) { |
Helmut64 | 0:3b6c2ce051a6 | 247 | rprintf("%2.2x ", *(u + i)); |
Helmut64 | 0:3b6c2ce051a6 | 248 | if (i == seppos) |
Helmut64 | 0:3b6c2ce051a6 | 249 | rprintf(" "); |
Helmut64 | 0:3b6c2ce051a6 | 250 | } |
Helmut64 | 0:3b6c2ce051a6 | 251 | rprintf(" "); |
Helmut64 | 0:3b6c2ce051a6 | 252 | if (j < width) { |
Helmut64 | 0:3b6c2ce051a6 | 253 | i = width - j; |
Helmut64 | 0:3b6c2ce051a6 | 254 | if (i > seppos + 1) |
Helmut64 | 0:3b6c2ce051a6 | 255 | rprintf(" "); |
Helmut64 | 0:3b6c2ce051a6 | 256 | while (i--) { |
Helmut64 | 0:3b6c2ce051a6 | 257 | rprintf("%s", " "); |
Helmut64 | 0:3b6c2ce051a6 | 258 | } |
Helmut64 | 0:3b6c2ce051a6 | 259 | } |
Helmut64 | 0:3b6c2ce051a6 | 260 | for (i = 0; i < j; i++) { |
Helmut64 | 0:3b6c2ce051a6 | 261 | int c = *(u + i); |
Helmut64 | 0:3b6c2ce051a6 | 262 | if (c >= ' ' && c <= '~') |
Helmut64 | 0:3b6c2ce051a6 | 263 | rprintf("%c", c); |
Helmut64 | 0:3b6c2ce051a6 | 264 | else |
Helmut64 | 0:3b6c2ce051a6 | 265 | rprintf("."); |
Helmut64 | 0:3b6c2ce051a6 | 266 | if (i == seppos) |
Helmut64 | 0:3b6c2ce051a6 | 267 | rprintf(" "); |
Helmut64 | 0:3b6c2ce051a6 | 268 | } |
Helmut64 | 0:3b6c2ce051a6 | 269 | len -= width; |
Helmut64 | 0:3b6c2ce051a6 | 270 | u += width; |
Helmut64 | 0:3b6c2ce051a6 | 271 | rprintf("\r\n"); |
Helmut Tschemernjak | 22:9cca40fcb25e | 272 | if (ser) |
Helmut Tschemernjak | 22:9cca40fcb25e | 273 | wait_ms(5); // give the serial some time. |
Helmut64 | 0:3b6c2ce051a6 | 274 | } |
Helmut64 | 0:3b6c2ce051a6 | 275 | rprintf("--\r\n"); |
Helmut64 | 0:3b6c2ce051a6 | 276 | } |
Helmut64 | 0:3b6c2ce051a6 | 277 | |
Helmut64 | 0:3b6c2ce051a6 | 278 | /* |
Helmut64 | 0:3b6c2ce051a6 | 279 | * Convert compile time to system time |
Helmut64 | 0:3b6c2ce051a6 | 280 | */ |
Helmut64 | 0:3b6c2ce051a6 | 281 | time_t |
Helmut64 | 0:3b6c2ce051a6 | 282 | cvt_date(char const *date, char const *time) |
Helmut64 | 0:3b6c2ce051a6 | 283 | { |
Helmut64 | 0:3b6c2ce051a6 | 284 | char s_month[5]; |
Helmut64 | 0:3b6c2ce051a6 | 285 | int year; |
Helmut64 | 0:3b6c2ce051a6 | 286 | struct tm t; |
Helmut64 | 0:3b6c2ce051a6 | 287 | static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; |
Helmut64 | 0:3b6c2ce051a6 | 288 | sscanf(date, "%s %d %d", s_month, &t.tm_mday, &year); |
Helmut64 | 0:3b6c2ce051a6 | 289 | sscanf(time, "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); |
Helmut64 | 0:3b6c2ce051a6 | 290 | // Find where is s_month in month_names. Deduce month value. |
Helmut64 | 0:3b6c2ce051a6 | 291 | t.tm_mon = (strstr(month_names, s_month) - month_names) / 3; |
Helmut64 | 0:3b6c2ce051a6 | 292 | t.tm_year = year - 1900; |
Helmut64 | 0:3b6c2ce051a6 | 293 | return (int)mktime(&t); |
Helmut64 | 0:3b6c2ce051a6 | 294 | } |
Helmut Tschemernjak | 1:56fdc660a26a | 295 | |
Helmut Tschemernjak | 1:56fdc660a26a | 296 | |
Helmut Tschemernjak | 1:56fdc660a26a | 297 | |
Helmut Tschemernjak | 1:56fdc660a26a | 298 | void InterrruptMSG(enum InterrruptDevice irqid) { |
Helmut Tschemernjak | 1:56fdc660a26a | 299 | help_atomic_or_relaxed(&PendingInterrupts, irqid); |
Helmut Tschemernjak | 1:56fdc660a26a | 300 | } |
Helmut Tschemernjak | 1:56fdc660a26a | 301 | |
Helmut Tschemernjak | 1:56fdc660a26a | 302 | |
Helmut Tschemernjak | 1:56fdc660a26a | 303 | uint32_t readclrPendingInterrupts() { |
Helmut Tschemernjak | 1:56fdc660a26a | 304 | return help_atomic_readclr_relaxed(&PendingInterrupts); |
Helmut Tschemernjak | 1:56fdc660a26a | 305 | } |
Helmut Tschemernjak | 1:56fdc660a26a | 306 | |
Helmut Tschemernjak | 1:56fdc660a26a | 307 | uint32_t readPendingInterrupts() { |
Helmut Tschemernjak | 1:56fdc660a26a | 308 | return help_atomic_load_relaxed(&PendingInterrupts); |
Helmut Tschemernjak | 1:56fdc660a26a | 309 | } |
Helmut Tschemernjak | 1:56fdc660a26a | 310 | |
Helmut Tschemernjak | 1:56fdc660a26a | 311 | const char * |
Helmut Tschemernjak | 1:56fdc660a26a | 312 | BatterySource(void) |
Helmut Tschemernjak | 1:56fdc660a26a | 313 | { |
Helmut Tschemernjak | 1:56fdc660a26a | 314 | const char *pwrSource = "Battery"; |
Helmut Tschemernjak | 1:56fdc660a26a | 315 | #ifdef BATPOWER_EN |
Helmut Tschemernjak | 1:56fdc660a26a | 316 | { |
Helmut Tschemernjak | 1:56fdc660a26a | 317 | DigitalIn pwr(BATPOWER_EN); |
Helmut Tschemernjak | 1:56fdc660a26a | 318 | if (pwr == BATPOWER_EXT) |
Helmut Tschemernjak | 1:56fdc660a26a | 319 | pwrSource = "USB"; |
Helmut Tschemernjak | 1:56fdc660a26a | 320 | } |
Helmut Tschemernjak | 1:56fdc660a26a | 321 | #endif |
Helmut Tschemernjak | 1:56fdc660a26a | 322 | return pwrSource; |
Helmut Tschemernjak | 1:56fdc660a26a | 323 | } |
Helmut Tschemernjak | 1:56fdc660a26a | 324 | |
Helmut Tschemernjak | 22:9cca40fcb25e | 325 | |
Helmut Tschemernjak | 22:9cca40fcb25e | 326 | void MCUReset(void) |
Helmut Tschemernjak | 22:9cca40fcb25e | 327 | { |
Helmut Tschemernjak | 22:9cca40fcb25e | 328 | #define AIRCR_VECTKEY_MASK 0x05FA0000 |
Helmut Tschemernjak | 22:9cca40fcb25e | 329 | SCB->AIRCR = AIRCR_VECTKEY_MASK | 0x04; // NVIC_GenerateSystemReset(); |
Helmut Tschemernjak | 22:9cca40fcb25e | 330 | } |
Helmut Tschemernjak | 22:9cca40fcb25e | 331 |