Fixed SDC sector count logic for SDC read/write

This commit is contained in:
Peter Weingartner 2024-12-22 21:21:47 -05:00
parent c5b0e00e04
commit 206f2d5e6b
4 changed files with 23 additions and 3 deletions

View file

@ -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;

View file

@ -7,6 +7,16 @@
#include <ctype.h>
#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

View file

@ -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
*

View file

@ -7,6 +7,6 @@
#define VER_MAJOR 1
#define VER_MINOR 1
#define VER_BUILD 9
#define VER_BUILD 10
#endif