RetroArch
Macros | Typedefs | Functions | Variables
sdgecko_io.c File Reference
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <ogcsys.h>
#include "asm.h"
#include "processor.h"
#include "exi.h"
#include "lwp.h"
#include "system.h"
#include "semaphore.h"
#include "card_cmn.h"
#include "card_io.h"
Include dependency graph for sdgecko_io.c:

Macros

#define SECTOR_ADDRESSING   0
 
#define BYTE_ADDRESSING   1
 
#define TYPE_SD   0
 
#define TYPE_SDHC   1
 
#define MMC_ERROR_PARAM   0x0040
 
#define MMC_ERROR_ADDRESS   0x0020
 
#define MMC_ERROR_ERASE_SEQ   0x0010
 
#define MMC_ERROR_CRC   0x0008
 
#define MMC_ERROR_ILL   0x0004
 
#define MMC_ERROR_ERASE_RES   0x0002
 
#define MMC_ERROR_IDLE   0x0001
 
#define CARDIO_OP_INITFAILED   0x8000
 
#define CARDIO_OP_TIMEDOUT   0x4000
 
#define CARDIO_OP_IOERR_IDLE   0x2000
 
#define CARDIO_OP_IOERR_PARAM   0x1000
 
#define CARDIO_OP_IOERR_WRITE   0x0200
 
#define CARDIO_OP_IOERR_ADDR   0x0100
 
#define CARDIO_OP_IOERR_CRC   0x0002
 
#define CARDIO_OP_IOERR_ILL   0x0001
 
#define CARDIO_OP_IOERR_FATAL   (CARDIO_OP_IOERR_PARAM|CARDIO_OP_IOERR_WRITE|CARDIO_OP_IOERR_ADDR|CARDIO_OP_IOERR_CRC|CARDIO_OP_IOERR_ILL)
 
#define _SHIFTL(v, s, w)   ((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s)))
 
#define _SHIFTR(v, s, w)   ((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1)))
 

Typedefs

typedef s32(* cardiocallback) (s32 drv_no)
 

Functions

unsigned long gettick ()
 
static __inline__ u32 __check_response (s32 drv_no, u8 res)
 
static void __init_crc7 ()
 
static u8 __make_crc7 (void *buffer, u32 len)
 
static void __init_crc16 ()
 
static u16 __make_crc16 (void *buffer, u32 len)
 
static u32 __card_checktimeout (s32 drv_no, u32 startT, u32 timeout)
 
static s32 __exi_unlock (s32 chn, s32 dev)
 
static void __exi_wait (s32 drv_no)
 
static s32 __card_exthandler (s32 chn, s32 dev)
 
static s32 __card_writecmd0 (s32 drv_no)
 
static s32 __card_writecmd (s32 drv_no, void *buf, s32 len)
 
static s32 __card_readresponse (s32 drv_no, void *buf, s32 len)
 
static s32 __card_stopreadresponse (s32 drv_no, void *buf, s32 len)
 
static s32 __card_datares (s32 drv_no, void *buf)
 
static s32 __card_stopresponse (s32 drv_no)
 
static s32 __card_dataresponse (s32 drv_no)
 
static s32 __card_dataread (s32 drv_no, void *buf, u32 len)
 
static s32 __card_multidatawrite (s32 drv_no, void *buf, u32 len)
 
static s32 __card_multiwritestop (s32 drv_no)
 
static s32 __card_response1 (s32 drv_no)
 
static s32 __card_response2 (s32 drv_no)
 
static s32 __card_sendappcmd (s32 drv_no)
 
static s32 __card_sendopcond (s32 drv_no)
 
static s32 __card_sendCMD8 (s32 drv_no)
 
static s32 __card_sendCMD58 (s32 drv_no)
 
static s32 __card_sendcmd (s32 drv_no, u8 cmd, u8 *arg)
 
static s32 __card_setblocklen (s32 drv_no, u32 block_len)
 
static s32 __card_readcsd (s32 drv_no)
 
static s32 __card_readcid (s32 drv_no)
 
static s32 __card_sd_status (s32 drv_no)
 
static s32 __card_softreset (s32 drv_no)
 
static bool __card_check (s32 drv_no)
 
static s32 __card_retrycb (s32 drv_no)
 
static void __convert_sector (s32 drv_no, u32 sector_no, u8 *arg)
 
void sdgecko_initIODefault ()
 
s32 sdgecko_initIO (s32 drv_no)
 
s32 sdgecko_preIO (s32 drv_no)
 
s32 sdgecko_readCID (s32 drv_no)
 
s32 sdgecko_readCSD (s32 drv_no)
 
s32 sdgecko_readStatus (s32 drv_no)
 
s32 sdgecko_readSectors (s32 drv_no, u32 sector_no, u32 num_sectors, void *buf)
 
s32 sdgecko_writeSectors (s32 drv_no, u32 sector_no, u32 num_sectors, const void *buf)
 
s32 sdgecko_doUnmount (s32 drv_no)
 
void sdgecko_insertedCB (s32 drv_no)
 
void sdgecko_ejectedCB (s32 drv_no)
 
void sdgecko_setSpeed (u32 freq)
 
u32 sdgecko_getPageSize (s32 drv_no)
 
u32 sdgecko_setPageSize (s32 drv_no, int size)
 
u32 sdgecko_getAddressingType (s32 drv_no)
 

Variables

u8 g_CID [MAX_DRIVE][16]
 
u8 g_CSD [MAX_DRIVE][16]
 
u8 g_CardStatus [MAX_DRIVE][64]
 
u8 g_mCode [MAX_MI_NUM] = { 0x03 }
 
u16 g_dCode [MAX_MI_NUM][MAX_DI_NUM]
 
static u8 _ioWPFlag
 
static u8 _ioClrFlag
 
static u32 _ioCardFreq
 
static u32 _ioRetryCnt
 
static cardiocallback _ioRetryCB = NULL
 
static lwpq_t _ioEXILock [MAX_DRIVE]
 
static u32 _ioPageSize [MAX_DRIVE]
 
static u32 _ioFlag [MAX_DRIVE]
 
static u32 _ioError [MAX_DRIVE]
 
static bool _ioCardInserted [MAX_DRIVE]
 
static u8 _ioResponse [MAX_DRIVE][128]
 
static u8 _ioCrc7Table [256]
 
static u16 _ioCrc16Table [256]
 
static u32 _initType [MAX_DRIVE]
 
static u32 _ioAddressingType [MAX_DRIVE]
 
static void(* pfCallbackIN [MAX_DRIVE])(s32) = {NULL, NULL}
 
static void(* pfCallbackOUT [MAX_DRIVE])(s32) = {NULL, NULL}
 

Macro Definition Documentation

◆ _SHIFTL

#define _SHIFTL (   v,
  s,
  w 
)    ((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s)))

◆ _SHIFTR

#define _SHIFTR (   v,
  s,
  w 
)    ((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1)))

◆ BYTE_ADDRESSING

#define BYTE_ADDRESSING   1

◆ CARDIO_OP_INITFAILED

#define CARDIO_OP_INITFAILED   0x8000

◆ CARDIO_OP_IOERR_ADDR

#define CARDIO_OP_IOERR_ADDR   0x0100

◆ CARDIO_OP_IOERR_CRC

#define CARDIO_OP_IOERR_CRC   0x0002

◆ CARDIO_OP_IOERR_FATAL

◆ CARDIO_OP_IOERR_IDLE

#define CARDIO_OP_IOERR_IDLE   0x2000

◆ CARDIO_OP_IOERR_ILL

#define CARDIO_OP_IOERR_ILL   0x0001

◆ CARDIO_OP_IOERR_PARAM

#define CARDIO_OP_IOERR_PARAM   0x1000

◆ CARDIO_OP_IOERR_WRITE

#define CARDIO_OP_IOERR_WRITE   0x0200

◆ CARDIO_OP_TIMEDOUT

#define CARDIO_OP_TIMEDOUT   0x4000

◆ MMC_ERROR_ADDRESS

#define MMC_ERROR_ADDRESS   0x0020

◆ MMC_ERROR_CRC

#define MMC_ERROR_CRC   0x0008

◆ MMC_ERROR_ERASE_RES

#define MMC_ERROR_ERASE_RES   0x0002

◆ MMC_ERROR_ERASE_SEQ

#define MMC_ERROR_ERASE_SEQ   0x0010

◆ MMC_ERROR_IDLE

#define MMC_ERROR_IDLE   0x0001

◆ MMC_ERROR_ILL

#define MMC_ERROR_ILL   0x0004

◆ MMC_ERROR_PARAM

#define MMC_ERROR_PARAM   0x0040

◆ SECTOR_ADDRESSING

#define SECTOR_ADDRESSING   0

◆ TYPE_SD

#define TYPE_SD   0

◆ TYPE_SDHC

#define TYPE_SDHC   1

Typedef Documentation

◆ cardiocallback

typedef s32(* cardiocallback) (s32 drv_no)

Function Documentation

◆ __card_check()

static bool __card_check ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_checktimeout()

static u32 __card_checktimeout ( s32  drv_no,
u32  startT,
u32  timeout 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_dataread()

static s32 __card_dataread ( s32  drv_no,
void buf,
u32  len 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_datares()

static s32 __card_datares ( s32  drv_no,
void buf 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_dataresponse()

static s32 __card_dataresponse ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_exthandler()

static s32 __card_exthandler ( s32  chn,
s32  dev 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_multidatawrite()

static s32 __card_multidatawrite ( s32  drv_no,
void buf,
u32  len 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_multiwritestop()

static s32 __card_multiwritestop ( s32  drv_no)
static

0xfd

Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_readcid()

static s32 __card_readcid ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_readcsd()

static s32 __card_readcsd ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_readresponse()

static s32 __card_readresponse ( s32  drv_no,
void buf,
s32  len 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_response1()

static s32 __card_response1 ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_response2()

static s32 __card_response2 ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_retrycb()

static s32 __card_retrycb ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_sd_status()

static s32 __card_sd_status ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_sendappcmd()

static s32 __card_sendappcmd ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_sendcmd()

static s32 __card_sendcmd ( s32  drv_no,
u8  cmd,
u8 arg 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_sendCMD58()

static s32 __card_sendCMD58 ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_sendCMD8()

static s32 __card_sendCMD8 ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_sendopcond()

static s32 __card_sendopcond ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_setblocklen()

static s32 __card_setblocklen ( s32  drv_no,
u32  block_len 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_softreset()

static s32 __card_softreset ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_stopreadresponse()

static s32 __card_stopreadresponse ( s32  drv_no,
void buf,
s32  len 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_stopresponse()

static s32 __card_stopresponse ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_writecmd()

static s32 __card_writecmd ( s32  drv_no,
void buf,
s32  len 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __card_writecmd0()

static s32 __card_writecmd0 ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __check_response()

static __inline__ u32 __check_response ( s32  drv_no,
u8  res 
)
static
Here is the caller graph for this function:

◆ __convert_sector()

static void __convert_sector ( s32  drv_no,
u32  sector_no,
u8 arg 
)
static
Here is the caller graph for this function:

◆ __exi_unlock()

static s32 __exi_unlock ( s32  chn,
s32  dev 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __exi_wait()

static void __exi_wait ( s32  drv_no)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __init_crc16()

static void __init_crc16 ( )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __init_crc7()

static void __init_crc7 ( )
static
Here is the caller graph for this function:

◆ __make_crc16()

static u16 __make_crc16 ( void buffer,
u32  len 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __make_crc7()

static u8 __make_crc7 ( void buffer,
u32  len 
)
static
Here is the caller graph for this function:

◆ gettick()

unsigned long gettick ( )
Here is the caller graph for this function:

◆ sdgecko_doUnmount()

s32 sdgecko_doUnmount ( s32  drv_no)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdgecko_ejectedCB()

void sdgecko_ejectedCB ( s32  drv_no)
Here is the caller graph for this function:

◆ sdgecko_getAddressingType()

u32 sdgecko_getAddressingType ( s32  drv_no)

◆ sdgecko_getPageSize()

u32 sdgecko_getPageSize ( s32  drv_no)

◆ sdgecko_initIO()

s32 sdgecko_initIO ( s32  drv_no)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdgecko_initIODefault()

void sdgecko_initIODefault ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdgecko_insertedCB()

void sdgecko_insertedCB ( s32  drv_no)
Here is the caller graph for this function:

◆ sdgecko_preIO()

s32 sdgecko_preIO ( s32  drv_no)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdgecko_readCID()

s32 sdgecko_readCID ( s32  drv_no)
Here is the call graph for this function:

◆ sdgecko_readCSD()

s32 sdgecko_readCSD ( s32  drv_no)
Here is the call graph for this function:

◆ sdgecko_readSectors()

s32 sdgecko_readSectors ( s32  drv_no,
u32  sector_no,
u32  num_sectors,
void buf 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdgecko_readStatus()

s32 sdgecko_readStatus ( s32  drv_no)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdgecko_setPageSize()

u32 sdgecko_setPageSize ( s32  drv_no,
int  size 
)
Here is the call graph for this function:

◆ sdgecko_setSpeed()

void sdgecko_setSpeed ( u32  freq)

◆ sdgecko_writeSectors()

s32 sdgecko_writeSectors ( s32  drv_no,
u32  sector_no,
u32  num_sectors,
const void buf 
)
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _initType

u32 _initType[MAX_DRIVE]
static

◆ _ioAddressingType

u32 _ioAddressingType[MAX_DRIVE]
static

◆ _ioCardFreq

u32 _ioCardFreq
static

◆ _ioCardInserted

bool _ioCardInserted[MAX_DRIVE]
static

◆ _ioClrFlag

u8 _ioClrFlag
static

◆ _ioCrc16Table

u16 _ioCrc16Table[256]
static

◆ _ioCrc7Table

u8 _ioCrc7Table[256]
static

◆ _ioError

u32 _ioError[MAX_DRIVE]
static

◆ _ioEXILock

lwpq_t _ioEXILock[MAX_DRIVE]
static

◆ _ioFlag

u32 _ioFlag[MAX_DRIVE]
static

◆ _ioPageSize

u32 _ioPageSize[MAX_DRIVE]
static

◆ _ioResponse

u8 _ioResponse[MAX_DRIVE][128]
static

◆ _ioRetryCB

cardiocallback _ioRetryCB = NULL
static

◆ _ioRetryCnt

u32 _ioRetryCnt
static

◆ _ioWPFlag

u8 _ioWPFlag
static

◆ g_CardStatus

u8 g_CardStatus[MAX_DRIVE][64]

◆ g_CID

u8 g_CID[MAX_DRIVE][16]

◆ g_CSD

u8 g_CSD[MAX_DRIVE][16]

◆ g_dCode

Initial value:
=
{
{
0x033f,
0x0383,
0x074b,
0x0edf,
0x0f03
}
}

◆ g_mCode

u8 g_mCode[MAX_MI_NUM] = { 0x03 }

◆ pfCallbackIN

void(* pfCallbackIN[MAX_DRIVE])(s32) = {NULL, NULL}
static

◆ pfCallbackOUT

void(* pfCallbackOUT[MAX_DRIVE])(s32) = {NULL, NULL}
static