Skip to content
Snippets Groups Projects
Unverified Commit 2ba57ac0 authored by Marian Buschsieweke's avatar Marian Buschsieweke
Browse files

tests/driver_ltc4150: Workarround for msp430

The msp430 toolchain is missing an `fputs()` implementation. This commit makes
them use the `printf("%s", str);` instead of `fputs(str, stdout);`, which is
semantically equivalent (but has more overhead).
parent 618e2e58
No related branches found
No related tags found
No related merge requests found
...@@ -6,3 +6,7 @@ USEMODULE += fmt ...@@ -6,3 +6,7 @@ USEMODULE += fmt
USEMODULE += ltc4150 USEMODULE += ltc4150
include $(RIOTBASE)/Makefile.include include $(RIOTBASE)/Makefile.include
ifneq (,$(filter $(BOARD),msb-430 msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1))
CFLAGS += -DNO_FPUTS
endif
...@@ -62,6 +62,22 @@ static void *recorder_data[] = { ...@@ -62,6 +62,22 @@ static void *recorder_data[] = {
#include "ltc4150_params.h" #include "ltc4150_params.h"
/**
* @brief Like `puts()`, but do not append a newline
*
* Normally I would just use `fputs(str, stdout)` directly, but the msp430
* toolchain lacks `fputs()`. This wrapper allows to add a less efficient
* fallback to printf()
*/
static inline void puts_no_nl(const char *s)
{
#ifndef NO_FPUTS
fputs(s, stdout);
#else
printf("%s", s);
#endif
}
/** /**
* @brief Callback function to reset/initialize the recorder data * @brief Callback function to reset/initialize the recorder data
*/ */
...@@ -142,11 +158,11 @@ static void print_spaces(size_t number) ...@@ -142,11 +158,11 @@ static void print_spaces(size_t number)
{ {
static const char *spaces = " "; static const char *spaces = " ";
while (number > 16) { while (number > 16) {
fputs(spaces, stdout); puts_no_nl(spaces);
number -= 16; number -= 16;
} }
fputs(spaces + 16 - number, stdout); puts_no_nl(spaces + 16 - number);
} }
/** /**
...@@ -164,7 +180,7 @@ static void print_col_u32(uint32_t number, size_t width) ...@@ -164,7 +180,7 @@ static void print_col_u32(uint32_t number, size_t width)
if (width > slen) { if (width > slen) {
print_spaces(width - slen); print_spaces(width - slen);
} }
fputs(sbuf, stdout); puts_no_nl(sbuf);
} }
/** /**
...@@ -188,7 +204,7 @@ static void print_col_i32(int32_t number, size_t width) ...@@ -188,7 +204,7 @@ static void print_col_i32(int32_t number, size_t width)
if (width > slen) { if (width > slen) {
print_spaces(width - slen); print_spaces(width - slen);
} }
fputs(sbuf, stdout); puts_no_nl(sbuf);
} }
/** /**
...@@ -204,7 +220,7 @@ static void print_current(int32_t current, size_t width) ...@@ -204,7 +220,7 @@ static void print_current(int32_t current, size_t width)
sbuf[0] = '.'; sbuf[0] = '.';
sbuf[1] = '0' + current % 10; sbuf[1] = '0' + current % 10;
sbuf[2] = '\0'; sbuf[2] = '\0';
fputs(sbuf, stdout); puts_no_nl(sbuf);
} }
int main(void) int main(void)
...@@ -220,7 +236,7 @@ int main(void) ...@@ -220,7 +236,7 @@ int main(void)
ltc4150_pulses2c(&ltc4150, &ten_uc_per_pulse, NULL, 10000, 0); ltc4150_pulses2c(&ltc4150, &ten_uc_per_pulse, NULL, 10000, 0);
if (retval) { if (retval) {
fputs("Failed to initialize LTC4150 driver:", stdout); puts_no_nl("Failed to initialize LTC4150 driver:");
switch (retval) { switch (retval) {
case -EINVAL: case -EINVAL:
puts("Invalid parameter"); puts("Invalid parameter");
...@@ -291,11 +307,11 @@ int main(void) ...@@ -291,11 +307,11 @@ int main(void)
puts("ltc4150_charge() failed!"); puts("ltc4150_charge() failed!");
return -1; return -1;
} }
fputs("| ", stdout); puts_no_nl("| ");
print_col_u32(charged, 13); print_col_u32(charged, 13);
fputs(" | ", stdout); puts_no_nl(" | ");
print_col_u32(discharged, 13); print_col_u32(discharged, 13);
fputs(" | ", stdout); puts_no_nl(" | ");
/* Get & print avg current */ /* Get & print avg current */
if (ltc4150_avg_current(&ltc4150, &avg_current)) { if (ltc4150_avg_current(&ltc4150, &avg_current)) {
...@@ -303,7 +319,7 @@ int main(void) ...@@ -303,7 +319,7 @@ int main(void)
return -1; return -1;
} }
print_current(avg_current, 7); print_current(avg_current, 7);
fputs(" | ", stdout); puts_no_nl(" | ");
/* Get & print last minute current */ /* Get & print last minute current */
if (ltc4150_last_minute_charge(&ltc4150, &last_minute_data, if (ltc4150_last_minute_charge(&ltc4150, &last_minute_data,
...@@ -315,7 +331,7 @@ int main(void) ...@@ -315,7 +331,7 @@ int main(void)
current = (int32_t)discharged - (int32_t)charged; current = (int32_t)discharged - (int32_t)charged;
current /= 60; current /= 60;
print_col_i32(current, 11); print_col_i32(current, 11);
fputs(" | ", stdout); puts_no_nl(" | ");
/* Calculate & print the current between the last two pulses */ /* Calculate & print the current between the last two pulses */
current = (int32_t)((test_data.now_usec - test_data.last_usec) / MS_PER_SEC); current = (int32_t)((test_data.now_usec - test_data.last_usec) / MS_PER_SEC);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment