Commit 203b98c4 authored by Damien George's avatar Damien George

drivers/sdcard: Make ioctl(4), ioctl(5) return num blocks, block size.

For CSD v1.0 the computed size is in bytes, so convert it to number of
512-byte blocks, and then ioctl(4) will return the correct value.

Also implement ioctl(5) to return the block size, which is always 512.
Signed-off-by: default avatarDamien George <damien@micropython.org>
parent ab6ad867
......@@ -103,7 +103,8 @@ class SDCard:
c_size = (csd[6] & 0b11) << 10 | csd[7] << 2 | csd[8] >> 6
c_size_mult = (csd[9] & 0b11) << 1 | csd[10] >> 7
read_bl_len = csd[5] & 0b1111
self.sectors = (c_size + 1) * (2 ** (c_size_mult + 2)) * (2**read_bl_len)
capacity = (c_size + 1) * (2 ** (c_size_mult + 2)) * (2**read_bl_len)
self.sectors = capacity // 512
else:
raise OSError("SD card CSD format not supported")
# print('sectors', self.sectors)
......@@ -282,3 +283,5 @@ class SDCard:
def ioctl(self, op, arg):
if op == 4: # get number of blocks
return self.sectors
if op == 5: # get block size in bytes
return 512
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