sdcard.h
116 lines
| 3.7 KiB
| text/x-c
|
CLexer
r11 | /*------------------------------------------------------------------------------ | |||
-- This file is a part of the libuc, microcontroler library | ||||
-- Copyright (C) 2012, Alexis Jeandet | ||||
-- | ||||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
-- the Free Software Foundation; either version 3 of the License, or | ||||
-- (at your option) any later version. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
------------------------------------------------------------------------------- | ||||
-- Author : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@gmail.com | ||||
-------------------------------------------------------------------------------*/ | ||||
#ifndef SDCARD_H | ||||
#define SDCARD_H | ||||
#include "blkdevice.h" | ||||
#include <libucstrings.h> | ||||
/* MMC/SD command */ | ||||
#define CMD0 (0) /* GO_IDLE_STATE */ | ||||
#define CMD1 (1) /* SEND_OP_COND (MMC) */ | ||||
#define ACMD41 (0x80+41) /* SEND_OP_COND (SDC) */ | ||||
#define CMD8 (8) /* SEND_IF_COND */ | ||||
#define CMD9 (9) /* SEND_CSD */ | ||||
#define CMD10 (10) /* SEND_CID */ | ||||
#define CMD12 (12) /* STOP_TRANSMISSION */ | ||||
#define ACMD13 (0x80+13) /* SD_STATUS (SDC) */ | ||||
#define CMD16 (16) /* SET_BLOCKLEN */ | ||||
#define CMD17 (17) /* READ_SINGLE_BLOCK */ | ||||
#define CMD18 (18) /* READ_MULTIPLE_BLOCK */ | ||||
#define CMD23 (23) /* SET_BLOCK_COUNT (MMC) */ | ||||
#define ACMD23 (0x80+23) /* SET_WR_BLK_ERASE_COUNT (SDC) */ | ||||
#define CMD24 (24) /* WRITE_BLOCK */ | ||||
#define CMD25 (25) /* WRITE_MULTIPLE_BLOCK */ | ||||
#define CMD32 (32) /* ERASE_ER_BLK_START */ | ||||
#define CMD33 (33) /* ERASE_ER_BLK_END */ | ||||
#define CMD38 (38) /* ERASE */ | ||||
#define CMD55 (55) /* APP_CMD */ | ||||
#define CMD58 (58) /* READ_OCR */ | ||||
/* Card type flags (CardType) */ | ||||
#define CT_MMC 0x01 /* MMC ver 3 */ | ||||
#define CT_SD1 0x02 /* SD ver 1 */ | ||||
#define CT_SD2 0x04 /* SD ver 2 */ | ||||
#define CT_SDC (CT_SD1|CT_SD2) /* SD */ | ||||
#define CT_BLOCK 0x08 /* Block addressing */ | ||||
struct sdcard_str | ||||
{ | ||||
void* phy; | ||||
void (*rcvr_mmc) (void* phy,char *buff,unsigned int bc); | ||||
void (*xmit_mmc) (void* phy,const char *buff,unsigned int bc); | ||||
void (*setspeed) (void* phy,unsigned int speed); | ||||
DSTATUS Stat; | ||||
char CardType; | ||||
}; | ||||
typedef volatile struct sdcard_str sdcardDev; | ||||
extern void sdcardmake(sdcardDev* sdcard,void* phy,void (*rcvr_mmc) (void*,char *,unsigned int ),void (*xmit_mmc) (void*,const char *,unsigned int ),void (*setspeed) (void* phy,unsigned int speed)); | ||||
extern void sdcardmakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected); | ||||
extern int sdcardselect (blkdevice* _this); | ||||
extern void sdcarddeselect (blkdevice* _this); | ||||
extern int sdcardwait_ready (sdcardDev* sdcard); | ||||
extern int sdcardxmit_datablock (sdcardDev* sdcard,const char *buff,char token); | ||||
extern int sdcardrcvr_datablock (sdcardDev* sdcard,char *buff,unsigned int btr); | ||||
extern char sdcardsend_cmd (blkdevice* _this,char cmd,unsigned int arg); | ||||
extern DSTATUS sdcarddisk_status (blkdevice* _this,char drv); | ||||
extern DSTATUS sdcarddisk_initialize (blkdevice* _this,char drv); | ||||
extern DRESULT sdcarddisk_read (blkdevice* _this,char drv,char *buff,unsigned int sector,char count); | ||||
extern DRESULT sdcarddisk_write (blkdevice* _this,char drv,const char *buff,unsigned int sector,char count); | ||||
extern DRESULT sdcarddisk_ioctl (blkdevice* _this,char drv,char ctrl,void *buff); | ||||
#endif | ||||