KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
sd.h File Reference

Block-level access to an SD card attached to the SCI or SCIF port. More...

#include <sys/cdefs.h>
#include <arch/types.h>
#include <kos/blockdev.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  sd_init_params_t
 SD card initialization parameters. More...
 

Enumerations

enum  sd_interface_t { SD_IF_SCIF = 0 , SD_IF_SCI = 1 }
 SD card interface type. More...
 

Functions

uint8 sd_crc7 (const uint8 *data, int size, uint8 crc)
 Calculate a SD/MMC-style CRC over a block of data.
 
int sd_init_ex (const sd_init_params_t *params)
 Initialize the SD card with extended parameters.
 
int sd_init (void)
 Initialize the SD card for use.
 
int sd_shutdown (void)
 Shut down SD card support.
 
int sd_read_blocks (uint32 block, size_t count, uint8 *buf)
 Read one or more blocks from the SD card.
 
int sd_write_blocks (uint32 block, size_t count, const uint8 *buf)
 Write one or more blocks to the SD card.
 
uint64 sd_get_size (void)
 Retrieve the size of the SD card.
 
int sd_blockdev_for_partition (int partition, kos_blockdev_t *rv, uint8 *partition_type)
 Get a block device for a given partition on the SD card.
 
int sd_blockdev_for_device (kos_blockdev_t *rv)
 Get a block device for the SD card.
 

Detailed Description

Block-level access to an SD card attached to the SCI or SCIF port.

This file contains the interface to working with SD card readers. The original SD card reader designed by jj1odm connects to the SCIF port, while the SCI port implementation was developed by SWAT (Ruslan Rostovtsev). The SCIF implementation uses bit-banging technique to emulate SPI protocol, while the SCI implementation utilizes the synchronous mode of this interface, which is very similar to SPI.

For reference, all I/O through this code should be done in the order of SD card blocks (which are 512 bytes a piece). Also, this should adequately support SD and SDHC cards (and possibly SDXC, but I don't have any of them to try out).

This code doesn't directly implement any filesystems on top of the SD card, but rather provides you with direct block-level access. This probably will not be useful to most people in its current form (without a filesystem), but this will provide you with all of the building blocks you should need to actually make it work for you.

Due to the patent-encumbered nature of certain parts of the FAT32 filesystem, that filesystem will likely never be supported in KOS proper (unless, of course, people are still using KOS after those patents expire). I'm not going to encourage anyone to violate Microsoft's patents on FAT32 and I'm not going to be the enabler for anyone to do so either. So, if you want FAT32, you're on your own.

Author
Lawrence Sebald
See also
dc/scif.h