diff --git a/src/dev/channel.c b/src/dev/channel.c index afcc92b..acb4fdc 100644 --- a/src/dev/channel.c +++ b/src/dev/channel.c @@ -7,11 +7,8 @@ */ #include "log_level.h" -#ifdef DEFAULT_LOG_LEVEL - //#undef DEFAULT_LOG_LEVEL -#endif #ifndef DEFAULT_LOG_LEVEL - #define DEFAULT_LOG_LEVEL LOG_TRACE + #define DEFAULT_LOG_LEVEL LOG_ERROR #endif #include diff --git a/src/dev/sdc_f256.c b/src/dev/sdc_f256.c index 48e2f7c..c6f7546 100644 --- a/src/dev/sdc_f256.c +++ b/src/dev/sdc_f256.c @@ -23,6 +23,7 @@ #include "interrupt.h" #include "F256/sdc_spi.h" #include "sdc_f256.h" +#include "utilities.h" /* MMC/SD command (SPI mode) */ #define CMD0 (0) /* GO_IDLE_STATE */ @@ -379,7 +380,7 @@ static short sdc_read(p_dev_block dev, long lba, uint8_t * buffer, short size) { p_sd_card_info card = (p_sd_card_info)dev->data; p_sdc_spi sd = card->reg; uint8_t cmd; - short count = size % 512 + 1; + short count = ceil_div_short(size, 512); if (card->status & SDC_STAT_NOINIT) { return ERR_NOT_READY; @@ -420,7 +421,7 @@ static short sdc_write(p_dev_block dev, long lba, const uint8_t * buffer, short p_sd_card_info card = (p_sd_card_info)dev->data; p_sdc_spi sd = card->reg; uint8_t cmd; - short count = size % 512 + 1; + short count = ceil_div_short(size, 512); if (card->status & SDC_STAT_NOINIT) { return ERR_NOT_READY; diff --git a/src/toolbox.c b/src/toolbox.c index 7ffb4b6..760915e 100644 --- a/src/toolbox.c +++ b/src/toolbox.c @@ -3,8 +3,8 @@ */ #include "log_level.h" -#define DEFAULT_LOG_LEVEL LOG_INFO -#define LOG_CHANNEL LOG_CHANNEL_UART0 +#define DEFAULT_LOG_LEVEL LOG_ERROR +#define LOG_CHANNEL LOG_CHANNEL_CHANNEL_A #include #include diff --git a/src/utilities.c b/src/utilities.c index 24a1174..f1b7fb7 100644 --- a/src/utilities.c +++ b/src/utilities.c @@ -7,6 +7,16 @@ #include #include "utilities.h" +/** + * Return the ceiling of a/b using only short operations + * + * @param a the numerator + * @param b the denominator + * @return the smallest short c such that c >= a / b + */ +short ceil_div_short(short a, short b) { + return (a + (b - 1)) / b; +} /** * Re-entrant version of strtok_r, because VBCC does not provide it diff --git a/src/utilities.h b/src/utilities.h index c4f2e06..46a2815 100644 --- a/src/utilities.h +++ b/src/utilities.h @@ -13,6 +13,15 @@ /** Return the maximum value of x or y */ #define max(x, y) ((x < y) ? y : x) +/** + * Return the ceiling of a/b using only short operations + * + * @param a the numerator + * @param b the denominator + * @return the smallest short c such that c >= a / b + */ +extern short ceil_div_short(short a, short b); + /** * Re-entrant version of strtok_r, because VBCC does not provide it *