From 14d0743d8be9c09b33a7e21a625d3465b229c1fc Mon Sep 17 00:00:00 2001 From: Matthias Merz Date: Sat, 11 Dec 2010 00:38:05 +0100 Subject: [PATCH] spi.c fix output of warning for wrong baudrate * do crude cpp-calculation for case when we want to warn --- firmware/shared/spi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/firmware/shared/spi.c b/firmware/shared/spi.c index ca39c0b..e2dc977 100644 --- a/firmware/shared/spi.c +++ b/firmware/shared/spi.c @@ -45,9 +45,18 @@ void spi_init(){ return d-1; // the -1 because minimum divisor is /2 } + /* do pseudo-calculation in preprocessor, to get warnings + * we right-shift 8 times; if result >0, d will be >7 + * so output warning in that case + */ +#define D_VAL (F_CPU / SPI_BAUDRATE) +#if ((D_VAL >> 8) > 0 ) +#warning "spi baudrate too slow, cannot be set" +#endif + d = spi_clock_divisor(); if(d>7){ - #warning "spi baudrate too slow, cannot be set" + // warning was (hopefully) output previously by cpp d=7; }