📄 sdmmc.h
字号:
/******************************************************************************
*
* PIC18 C18 Secure Digital and Multimedia Cards Interface
*
******************************************************************************
* FileName: sdmmc.h
* Dependencies: GenericTypeDefs.h
* _fat.def
* _FATDefs.h
* Processor: PIC18
* Compiler: C18
* Company: Microchip Technology, Inc.
*
* Software License Agreement
*
* The software supplied herewith by Microchip Technology Incorporated
* (the 揅ompany? for its PICmicro?Microcontroller is intended and
* supplied to you, the Company抯 customer, for use solely and
* exclusively on Microchip PICmicro Microcontroller products. The
* software is owned by the Company and/or its supplier, and is
* protected under applicable copyright laws. All rights are reserved.
* Any use in violation of the foregoing restrictions may subject the
* user to criminal sanctions under applicable laws, as well as to
* civil liability for the breach of the terms and conditions of this
* license.
*
* THIS SOFTWARE IS PROVIDED IN AN 揂S IS?CONDITION. NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
* TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*
*****************************************************************************/
#ifndef SDMMC_H
#define SDMMC_H
#include "GenericTypeDefs.h"
#include "_fat.def"
#include "_FATDefs.h"
#define FALSE 0
#define TRUE 1
#ifdef USE_PIC18
#if defined(FAT_MEDIA_IF_SPI)
#define SPICON SSPCON1
#define SPISTAT SSPSTAT
#define SPIBUF SSPBUF
#define SPISTAT_RBF SSPSTATbits.BF
#elif defined(FAT_MEDIA_IF_SPI1)
#define SPICON SSP1CON1
#define SPISTAT SSP1STAT
#define SPIBUF SSP1BUF
#define SPISTAT_RBF SSPSTATbits.BF
#elif defined(FAT_MEDIA_IF_SPI2)
#define SPICON SSP2CON
#define SPISTAT SSP2STAT
#define SPIBUF SSP2BUF
#define SPISTAT_RBF SSPSTATbits.BF
#else
#error Media SPI port is not defined. See "FAT_MEDIA_IF_XXX" define in fat.def
#endif
#else
#if defined(FAT_MEDIA_IF_SPI)
#define SPICON SPICON1
#define SPISTAT SPISTAT
#define SPIBUF SPIBUF
#define SPISTAT_RBF SPISTATbits.SPIRBF
#elif defined(FAT_MEDIA_IF_SPI1)
#ifdef USE_PIC30
#define SPICON SPI1CON
#else
#define SPICON SPI1CON1
#endif
#define SPISTAT SPI1STAT
#define SPIBUF SPI1BUF
#define SPISTAT_RBF SPI1STATbits.SPIRBF
#elif defined(FAT_MEDIA_IF_SPI2)
#define SPICON SPI2CON
#define SPISTAT SPI2STAT
#define SPIBUF SPI2BUF
#define SPISTAT_RBF SPISTAT2bits.SPIRBF
#else
#error Media SPI port is not defined. See "FAT_MEDIA_IF_XXX" define in fat.def
#endif
#endif
#define MEDIA_SECTOR_SIZE 512
#define INPUT 1
#define OUTPUT 0
#define low(num) (num & 0xFF)
#define high(num) ((num >> 8) & 0xFF)
#define upper(num) ((num >> 16) & 0xFF)
#ifdef USE_PIC18
#define CLKSPERINSTRUCTION (BYTE) 4
#else
#define CLKSPERINSTRUCTION (BYTE) 2
#endif
#define TMR1PRESCALER (BYTE) 8
#define TMR1OVERHEAD (BYTE) 5
#define MILLISECDELAY (WORD)((SYSTEM_CLOCK/CLKSPERINSTRUCTION/TMR1PRESCALER/(WORD)1000) - TMR1OVERHEAD)
#define B115K26MHZ 0x0C // = 115.2K baud @26MHz
#define SD_CMD_IDLE 0
#define SD_CMD_SEND_OP_COND 1
#define SD_CMD_SET_BLOCK_LEN 16
#define SD_CMD_READ_BLOCK 17
#define SD_CMD_WRITE_BLOCK 24
#define SD_CARD_SYSTEM // Does this mean we are supporting more than one cards? - NR
typedef enum
{
GO_IDLE_STATE,
SEND_OP_COND,
SEND_CSD,
SEND_CID,
STOP_TRANSMISSION,
SEND_STATUS,
SET_BLOCKLEN,
READ_SINGLE_BLOCK,
READ_MULTI_BLOCK,
WRITE_SINGLE_BLOCK,
WRITE_MULTI_BLOCK,
TAG_SECTOR_START,
TAG_SECTOR_END,
UNTAG_SECTOR,
TAG_ERASE_GRP_START,
TAG_ERASE_GRP_END,
UNTAG_ERASE_GRP,
ERASE,
LOCK_UNLOCK,
SD_APP_OP_COND,
APP_CMD,
READ_OCR,
CRC_ON_OFF
}sdmmc_cmd;
BYTE MediaInit(void);
#define MediaIsPresent() (!SD_CD)
#define MediaIsWriteProtected() (SD_WE)
BYTE MediaDetect(void);
BYTE MediaInitialize(void);
BYTE SECTORread(DWORD sector_addr, BYTE* buffer);
BYTE SECTORwrite(DWORD sector_addr, BYTE* buffer);
extern BYTE gblSDMMCBuf[];
extern BYTE FATBuffer[];
extern DISK glbDiskData;
BYTE MediaDetect(void);
BYTE WriteProtectState(void);
void ShutdownMedia(void);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -