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/meteotime.c | 67 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) (limited to 'app/meteotime.c') 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); } -- cgit v1.2.3