Commit 5ebdfd93 authored by Florent Kermarrec's avatar Florent Kermarrec

liblitesdcard/sdcard: clamp divider value.

parent 23085cff
......@@ -31,6 +31,13 @@
unsigned int sdcard_response[SD_CMD_RESPONSE_SIZE/4];
/*-----------------------------------------------------------------------*/
/* Helpers */
/*-----------------------------------------------------------------------*/
#define max(x, y) (((x) > (y)) ? (x) : (y))
#define min(x, y) (((x) < (y)) ? (x) : (y))
/*-----------------------------------------------------------------------*/
/* SDCard command helpers */
/*-----------------------------------------------------------------------*/
......@@ -124,6 +131,8 @@ static void sdcard_set_clk_freq(uint32_t clk_freq) {
uint32_t divider;
divider = CONFIG_CLOCK_FREQUENCY/clk_freq + 1;
divider = (1 << log2(divider));
divider = max(divider, 2);
divider = min(divider, 128);
#ifdef SDCARD_DEBUG
printf("Setting SDCard clk freq to ");
if (clk_freq > 1000000)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment