From 03f4913e1a66e3bef8d3af1d2fec2acc145d309e Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Mon, 27 Feb 2017 15:34:41 +0000 Subject: [PATCH] macros: add min()/max() --- macros.h | 4 ++++ shell.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 macros.h diff --git a/macros.h b/macros.h new file mode 100644 index 0000000..5464d6f --- /dev/null +++ b/macros.h @@ -0,0 +1,4 @@ +#pragma once + +#define min(x, y) ((x < y) ? (x) : (y)) +#define max(x, y) ((x > y) ? (x) : (y)) diff --git a/shell.c b/shell.c index 1397911..bda79bf 100644 --- a/shell.c +++ b/shell.c @@ -13,6 +13,7 @@ #include #include +#include "macros.h" #include "shell.h" #include "spi_flash.h" #include "usart.h" @@ -156,7 +157,7 @@ static void do_read(FILE *fp, const char *s) return; while (len) { - nbytes = (len > 256) ? 256 : len; + nbytes = min(len, 256); spi_flash_read(SPI1, addr, buf, nbytes); print_hex_ascii(fp, buf, nbytes);