From 6bc7601e8f6c83c8def86aa7ae7cf06f51593771 Mon Sep 17 00:00:00 2001 From: James McKenzie Date: Sat, 18 Feb 2023 18:48:42 +0000 Subject: remove all use of FP in printf as it's not thread safe --- app/Makefile | 2 +- app/dcf77.c | 2 +- app/display.c | 4 ++-- app/gps.c | 53 +++++++++++++++++++++++--------------------- app/httpd.c | 38 ++++++++++++++------------------ app/main.c | 2 +- app/meteotime.c | 67 ++++++++++++++++++++++++++++---------------------------- app/prototypes.h | 4 ++++ app/time_fn.c | 2 +- 9 files changed, 89 insertions(+), 85 deletions(-) diff --git a/app/Makefile b/app/Makefile index 78f0d9b..9547a09 100644 --- a/app/Makefile +++ b/app/Makefile @@ -31,7 +31,7 @@ default: ${PROG}.elf CSRCS=led.c ticker.c ring.c usart.c stdio.c lwip_glue.c steth.c msf.c abs.c \ pll.c main.c time_fn.c ntp.c dcf77.c util.c stats.c gps.c hexdump.c bits.c \ max7219.c report.c sysclk.c cdcacm.c usb.c dfu.c adc.c dummy_kb.c ref.c \ - ptp.c display.c httpd.c alarm.c meteotime.c ephemeris.c + ptp.c display.c httpd.c alarm.c meteotime.c ephemeris.c fp.c HSRCS= events.h gps.h project.h ring.h steth.h time_fn.h ubx.h diff --git a/app/dcf77.c b/app/dcf77.c index 4b69a69..b9b7dcd 100644 --- a/app/dcf77.c +++ b/app/dcf77.c @@ -104,7 +104,7 @@ static void process_bits (uint64_t abs, uint64_t ptp) printf ("DCF77: Next minute is: %02d-%02d-%02d %02d:%02d\r\n", u.year, u.month, u.mday, u.hour, u.minute); time_print_epoch ("DCF77: ", e, dcf77_info); - meteotime_save(&u,bits); + meteotime_save (&u, bits); dump_bits ("dcf77", bits); } diff --git a/app/display.c b/app/display.c index 5c745b7..bf811d8 100644 --- a/app/display.c +++ b/app/display.c @@ -115,7 +115,7 @@ void display_dispatch (void) case 1: if (!have_lock) break; - snprintf (buf, sizeof (buf), "%.8f", gps_lat); + snprintf (buf, sizeof (buf), "%s", fd1 (gps_lat, 0, 1, 8)); buf[sizeof (buf) - 1] = 0; max7219_write_string (buf, 0, 2); break; @@ -123,7 +123,7 @@ void display_dispatch (void) case 2: if (!have_lock) break; - snprintf (buf, sizeof (buf), "%.8f", gps_lon); + snprintf (buf, sizeof (buf), "%s", fd1 (gps_lon, 0, 1, 8)); buf[sizeof (buf) - 1] = 0; max7219_write_string (buf, 0, 2); break; diff --git a/app/gps.c b/app/gps.c index a8b8099..e87167d 100644 --- a/app/gps.c +++ b/app/gps.c @@ -120,25 +120,25 @@ static int ubx_recv_aid_eph (uint8_t *ptr, unsigned len) ptr += ubx_get_u32 (ptr, &sv); len -= 4; - if ((sv<1) ||( sv>32)) return 0; + if ((sv < 1) || (sv > 32)) return 0; + + i = sv - 1; - i=sv-1; - ptr += ubx_get_u32 (ptr, &ephemeris[i].how); len -= 4; - printf("Received %d bytes of ephemeris for SV%d\r\n",len,(int) sv); + printf ("Received %d bytes of ephemeris for SV%d\r\n", len, (int) sv); - if ((!len) ||( !ephemeris[i].how)) return 0 ; + if ((!len) || (!ephemeris[i].how)) return 0 ; - memcpy(&ephemeris[i].sf1,ptr,32); - len-=32; - ptr+=32; - memcpy(&ephemeris[i].sf2,ptr,32); - len-=32; - ptr+=32; - memcpy(&ephemeris[i].sf3,ptr,32); + memcpy (&ephemeris[i].sf1, ptr, 32); + len -= 32; + ptr += 32; + memcpy (&ephemeris[i].sf2, ptr, 32); + len -= 32; + ptr += 32; + memcpy (&ephemeris[i].sf3, ptr, 32); return 0; } @@ -170,9 +170,9 @@ ubx_recv_nav_posllh (uint8_t *ptr, unsigned len) gps_lon = 1.e-7 * (double) ilon; - printf ("POS: %.4f %.4f\r\n", gps_lat, gps_lon); + printf ("POS: %s %s\r\n", fd1 (gps_lat, 0, 1, 4), fd2 (gps_lon, 0, 1, 4)); - snprintf (gps_pos, sizeof (gps_pos) - 1, "location: %.4f %.4f", gps_lat, gps_lon); + snprintf (gps_pos, sizeof (gps_pos) - 1, "location: %s %s", fd1 (gps_lat, 0, 1, 4), fd2 (gps_lon, 0, 1, 4)); return 0; } @@ -636,6 +636,7 @@ ubx_recv (uint8_t class, uint8_t id, uint8_t *payload, unsigned len) } break; + case 0xd: switch (id) { case 0x4: @@ -669,9 +670,10 @@ ubx_recv (uint8_t class, uint8_t id, uint8_t *payload, unsigned len) case 0x30: ubx_recv_almanac (payload, len); break; - case 0x31: - ubx_recv_aid_eph(payload,len); - break; + + case 0x31: + ubx_recv_aid_eph (payload, len); + break; case 0x50: printf ("xfer ack\r\n"); @@ -900,20 +902,21 @@ ubx_send (uint8_t class, uint8_t id, const void *_payload, unsigned len) void gps_dispatch (void) { -static uint32_t last_eph; -uint32_t t ; + static uint32_t last_eph; + uint32_t t ; ubx_dispatch_search (-1, -1, NULL); gps_pps_dispatch(); -t=ticks-last_eph; -if (t>60000) { - printf("Requesting ephemeris data\r\n"); - gps_dump_eph(); - last_eph=ticks; -} + t = ticks - last_eph; + + if (t > 60000) { + printf ("Requesting ephemeris data\r\n"); + gps_dump_eph(); + last_eph = ticks; + } } diff --git a/app/httpd.c b/app/httpd.c index 71c62a4..1c8fb17 100644 --- a/app/httpd.c +++ b/app/httpd.c @@ -52,11 +52,11 @@ static uint32_t make_alarm (void) } PTB_ADD (" UTC: %s\n", buf); - PTB_ADD (" RA: %.9f\n", ra); + PTB_ADD (" RA: %sf\n", fd1 (ra, 0, 1, 9)); PTB_ADD ("\n"); PTB_ADD ("\n"); - PTB_ADD ("\n", lra); + PTB_ADD ("\n", fd1 (lra, 0, 1, 9)); PTB_ADD ("\n", l.hour, l.minute, l.second, l.nanosecond / 1000); PTB_ADD ("
LRA:
LRA:
LST:
\n"); @@ -94,8 +94,8 @@ static uint32_t make_index (void) PTB_ADD ("
\n");
   PTB_ADD (" UTC: %s\n", buf);
-  PTB_ADD (" RA:                  %.9f\n", ra);
-  PTB_ADD (" LRA:                 %.9f\n", lra);
+  PTB_ADD (" RA:                  %s\n", fd1 (ra, 0, 1, 9));
+  PTB_ADD (" LRA:                 %s\n", fd1 (lra, 0, 1, 9));
   PTB_ADD (" LST:                 %02d:%02d:%02d.%06d\n", l.hour, l.minute, l.second, l.nanosecond / 1000);
   PTB_ADD ("
\n"); PTB_ADD ("\n"); @@ -125,8 +125,8 @@ static uint32_t make_index (void) } PTB_ADD (" UTC: %s\n", buf); - PTB_ADD (" RA: %.9f\n", ra); - PTB_ADD (" LRA: %.9f\n", lra); + PTB_ADD (" RA: %s\n", fd1 (ra, 0, 1, 9)); + PTB_ADD (" LRA: %s\n", fd1 (lra, 0, 1, 9)); PTB_ADD (" LST: %02d:%02d:%02d.%06d\n", l.hour, l.minute, l.second, l.nanosecond / 1000); PTB_ADD ("\n"); @@ -259,22 +259,18 @@ int fs_open_custom (struct fs_file *file, const char *name) { if (!strcmp (name, "/index.html")) { - file->data = (const char *)html_buf; - file->len = make_index(); - } - else if (!strcmp (name, "/alarm.html")) { - file->data = (const char *)html_buf; + file->data = (const char *)html_buf; + file->len = make_index(); + } else if (!strcmp (name, "/alarm.html")) { + file->data = (const char *)html_buf; file->len = make_alarm(); - } - else if (!strcmp (name, "/meteotime.dat")) { - file->data = (const char *)meteotime_data; - file->len=sizeof(meteotime_data); - } - else if (!strcmp (name, "/ephemeris.dat")) { - file->data = (const char *)ephemeris; - file->len=sizeof(ephemeris); - } - else { + } else if (!strcmp (name, "/meteotime.dat")) { + file->data = (const char *)meteotime_data; + file->len = sizeof (meteotime_data); + } else if (!strcmp (name, "/ephemeris.dat")) { + file->data = (const char *)ephemeris; + file->len = sizeof (ephemeris); + } else { printf ("looking for url=%s, found nothing\n", name); return 0; } diff --git a/app/main.c b/app/main.c index 3fe11eb..47c1a4b 100644 --- a/app/main.c +++ b/app/main.c @@ -222,7 +222,7 @@ static void timer_setup (void) timer_slave_set_trigger (TIM2, TIM_SMCR_TS_ITR0); /*clock from timer 1*/ timer_enable_counter (TIM2); #else - /* New Scheme 10MHz -> TIM2_ETR PA8->PA15*/ + /* New Scheme 10MHz -> TIM2_ETR PA8->PA15*/ #define REFCLK_IN (GPIO15) #define REFCLK_IN_PORT GPIOA diff --git a/app/meteotime.c b/app/meteotime.c index 5734a0b..e18220f 100644 --- a/app/meteotime.c +++ b/app/meteotime.c @@ -8,7 +8,7 @@ #define BITS_PER_WORD 32 -#define N_WORDS (((N_BITS)+(BITS_PER_WORD-1))/(BITS_PER_WORD)) +#define N_WORDS (((N_BITS)+(BITS_PER_WORD-1))/(BITS_PER_WORD)) #define M1 (~0UL) @@ -16,50 +16,51 @@ uint32_t meteotime_data[N_WORDS]; -void meteotime_save(UTC *u, uint8_t *bits) +void meteotime_save (UTC *u, uint8_t *bits) { -uint32_t c; -uint32_t d1; -uint32_t d2; + uint32_t c; + uint32_t d1; + uint32_t d2; -unsigned i; -unsigned word; -unsigned bit; -unsigned ibit; + unsigned i; + unsigned word; + unsigned bit; + unsigned ibit; -//0-13 -for (d1=0,c=1,i=1;i<15;++i,c<<=1) - if (bits[i]) d1|=c; + //0-13 + for (d1 = 0, c = 1, i = 1; i < 15; ++i, c <<= 1) + if (bits[i]) d1 |= c; -//14 -if (bits[17]) d1|=c; -c<<=1; + //14 + if (bits[17]) d1 |= c; -//15-31 -for (i=36;i<53;++i,c<<=1) - if (bits[i]) d1|=c; + c <<= 1; -//0-4 -for (d2=0,c=1,i=53;i<58;++i,c<<=1) - if (bits[i]) d2|=c; + //15-31 + for (i = 36; i < 53; ++i, c <<= 1) + if (bits[i]) d1 |= c; -bit=u->hour; -bit*=60; -bit+=u->minute; -bit*=BITS_PER_MIN; + //0-4 + for (d2 = 0, c = 1, i = 53; i < 58; ++i, c <<= 1) + if (bits[i]) d2 |= c; -word=bit/BITS_PER_WORD; -bit=bit & (BITS_PER_WORD -1); -ibit=BITS_PER_WORD-bit; + bit = u->hour; + bit *= 60; + bit += u->minute; + bit *= BITS_PER_MIN; + word = bit / BITS_PER_WORD; + bit = bit & (BITS_PER_WORD - 1); + ibit = BITS_PER_WORD - bit; -meteotime_data[word] &=~(M1 << bit); -meteotime_data[word] |=(d1 << bit); -word++; + meteotime_data[word] &= ~ (M1 << bit); + meteotime_data[word] |= (d1 << bit); -meteotime_data[word] &=~((M1 >> ibit) |(M2 <> ibit) | (d2 <> ibit) | (M2 << bit)); + meteotime_data[word] |= (d1 >> ibit) | (d2 << bit); } diff --git a/app/prototypes.h b/app/prototypes.h index 2fb6277..82be3cb 100644 --- a/app/prototypes.h +++ b/app/prototypes.h @@ -212,3 +212,7 @@ extern uint32_t meteotime_data[(((((37)*(60)*(24)))+(32 -1))/(32))]; extern void meteotime_save(UTC *u, uint8_t *bits); /* ephemeris.c */ extern Ephemeris ephemeris[32]; +/* fp.c */ +extern char *fd1(double f, int s, int bp, int dp); +extern char *fd2(double f, int s, int bp, int dp); +extern char *fd3(double f, int s, int bp, int dp); diff --git a/app/time_fn.c b/app/time_fn.c index 75b69d3..8c6c4f1 100644 --- a/app/time_fn.c +++ b/app/time_fn.c @@ -437,7 +437,7 @@ EPOCH time_ra_to_next_epoch (EPOCH l, double tra) int dog = 48; - printf ("time_ra_to_next_epoch %.9f\n", tra); + printf ("time_ra_to_next_epoch %s\n", fd1 (tra, 0, 1, 9)); /* XXX: we should use newton raphson, but */ /* 1) we're on team hooke */ -- cgit v1.2.3