📄 sd_cmd.c~
字号:
/***************************** C SOURCE FILE ********************************
**
** Project: FlashFile
** Filename: SD_CMD.C
** Version: 3.0.1
** Date: April 7, 2006
**
*****************************************************************************
**
** Source Code Solution Software
** License Agreement
**
** IMPORTANT: READ THIS AGREEMENT CAREFULLY.
**
** BY SELECTING THE "I ACCEPT THE AGREEMENT" OPTION AND CLICKING ON THE "NEXT"
** BUTTON, OR BY INSTALLING, COPYING, RUNNING, OR OTHERWISE USING THE PRIIO
** SOFTWARE, YOU AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE AGREEMENT. IF
** YOU DO NOT AGREE TO THE TERMS OF THIS LICENSE AGREEMENT, PLEASE CLICK THE
** "CANCEL" BUTTON, AND DO NOT INSTALL, RUN, COPY, OR OTHERWISE USE THE PRIIO
** SOFTWARE.
**
** This End User License Agreement ("License") is a legal agreement between
** you and Progressive Resources LLC DBA Priio, 4105 Vincennes Road,
** Indianapolis, IN 46268, USA ("Priio") concerning your use of the Priio
** Software, together with any electronic documentation that may be provided
** therewith (collectively, "the software") through the Software. YOU HEREBY
** AGREE, BOTH ON YOUR OWN BEHALF AND AS AN AUTHORIZED REPERSENTATIVE OF ANY
** ORGANIZATION FOR WHICH YOU ARE USING THE SOFTWARE ("EMPLOYER"), THAT YOU
** AND THE EMPLOYER WILL USE THE SOFTWARE ONLY IN ACCORDANCE WITH THE
** FOLLOWING TERMS:
**
** 1. Disclaimer of Warranty. You expressly acknowledge and agree that use
** of the Software is at your sole risk. THE SOFTWARE IS PROVIDED "AS
** IS" WITH ALL FAULTS AND WITHOUT WARRANTY OF ANY KIND, PRIIO does not
** warrant that the functions contained in the Software will meet your
** requirements or those of the Employer, or that the operation of the
** Software will be uninterrupted or error-free, or that defects in the
** Software will be corrected. Furthermore, Priio does not warrant or
** make any representation regarding the use or the results of the use of
** the Software (including the related documentation) in terms of their
** correctness, accuracy, reliability, or otherwise. Should the Software
** prove defective, you (and not Priio) assume the entire cost of all
** necessary servicing, repair, or correction.
**
** ** PRIIO EXPRESSLY DISCLAIMS ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR
** A PARTICULAR PURPOSE, TITLE, OR NONINFRINGEMENT WITH RESPECT TO THE
** SOFTWARE. **
**
** The Software may be provided with third-party plug-ins or other third-party
** software, or this Software may be provided as a plug-in for or otherwise in
** association with third-party software. Use of any such third-party
** software will be governed by the applicable license agreement, if any, with
** such third party.
**
** * PRIIO IS NOT RESPONSIBLE FOR ANY THIRD-PARTY SOFTWARE AND WILL HAVE NO
** LIABILITY OF ANY KIND FOR YOUR USE OF SUCH THIRD-PARTY SOFTWARE AND MAKES
** NO WARRANTY OF ANY KIND WITH RESPECT TO SUCH THIRD-PARTY SOFTWARE. *
**
** SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF IMPLIED
** WARRANTIES, SO THE ABOVE EXCLUSIONS MIGHT NOT APPLY TO YOU.
**
** 2. Limitation of Liability. In no event will Priio抯 total liability for
** all damages exceed the amount of fifty dollars ($50.00).
**
** **UNDER NO CIRCUMSTANCES, INCLUDING NEGLIGENCE, WILL PRIIO BE LIABLE FOR
** ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE, OR CONSEQUENTIAL DAMAGES,
** INCLUDING LOST DATA, LOST REVENUE, OR LOST PROFITS, ARISING OUT OF OR
** RELATING TO THIS LICENSE OR THE SOFTWARE.**
**
** SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSTION OR LIMITATION OF
** CONSEQUENTIAL OR INDIRECT DAMAGES, SO THE ABOVE LIMITATION MAY NOT APPLY TO
** YOU.
**
** 3. License Grant. Priio grants to you, and you accept, a personal,
** nonexclusive, nontransferable license to install and use the Software
** in source code format as a single site. You may not transfer, share or
** distribute the Software in any reusable form, without the express
** written permission of Priio. You may embed and deploy the executable
** forms of this Software with your product without royalty. You may make
** one copy of the Software in human-readable form for backup purposes
** only. The backup copy must include all copyright and license
** information contained on the original. This License is effective
** until terminated as provided below. You may terminate this License by
** destroying the Software and any copies of the Software in your
** possession. This License will terminate automatically upon any
** violation of its terms by you or the Employer. You acknowledge that
** this License does not entitle you to any support, maintenance, or
** upgrade from Priio.
**
** 4. License Restrictions. You may not do any of the following yourself, or
** through any third party, and you may not permit any third party with
** whom you have a business relationship to do any of the following: (A)
** copy the Software, except as expressly set forth in paragraph 3 above;
** (B) sell, license, sublicense, lease, or rent, to any third party,
** whether for profit or without charge, any portion of the Software, or,
** in particular, without limiting the generality of the foregoing,
** distribute the Software on any media; make the Software accessible to
** the public or third parties, whether over networks, electronic
** bulletin boards, website, or otherwise; or allow any third to use the
** Software except for purpose of your internal business; (C) publish or
** otherwise communicate any review of or information about the
** performance of the Software to any third party without the prior
** written consent of Priio; (D) export, re-export, download, or
** otherwise use the Software in violation of any laws or regulations,
** including U.S. Department of Commerce Export Administration
** regulations and other applicable laws; or (E) use the Software in
** connection with life support systems, human implantation, medical
** devices, nuclear facilities, nuclear systems or weapons, aviation,
** mass transit, or any application where failure or malfunction could
** lead to possible loss of life or catastrophic property damage.
**
** 5. Title and Ownership. This software is protected by United State
** Patent, Copyright Law and International Treaty provisions. Except for
** the rights expressly granted above, this License transfers to you no
** right, title, or interest in the Software, or any copyright, patent,
** trademark, trade secret, or other intellectual property or proprietary
** right in the Software. Priio retains sole and exclusive title to all
** portions of the Software and any copies thereof, and you hereby assign
** to Priio all right, title and interest in and to any modifications you
** make to the Software, whether or not such modifications are permitted.
** You agree not to disclose the Software to anyone.
**
** 6. Export Law Assurances. You may not export, re-export, download, or
** otherwise use the Software except as authorized by United States law
** and the laws of the jurisdiction in which it is obtained.
**
** 7. Notice to Government End Users. The Software, including any
** documentation, is provided to the United States Government with
** restricted rights. If the Software is supplied to the United State
** Government, the software is classified as "restricted computer
** software" as defined in clause 52.227-19 of the FAR. The United
** States Government抯 rights to the Software are as provided in clause
** 52.227-19 if the FAR.
**
** 8. Controlling Law and Severability. This License will be governed by
** the laws of the United States and the State of Indiana without regard
** to their provisions regarding conflicts of laws. This License will
** not be governed by the United Nations Convention on Contracts for the
** International Sale of Goods, the application of which is expressly
** excluded. You irrevocably submit to the jurisdiction of the state and
** federal courts sitting in Indiana, and any action or proceeding
** arising out of this License will be heard and determined in such
** courts. If for any reason a court of competent jurisdiction finds any
** provision, or portion thereof, to be unenforceable, such provision
** will be interpreted in order to give effect to such provision to the
** maximum extent permitted by law, and the remainder of this License
** will continue in full force and effect.
**
** 9. Complete Agreement. This License constitutes the entire agreement
** between the parties with respect to the use of the Software and
** supersedes all prior or contemporaneous understandings regarding such
** subject matter. No amendment to or modification of this License will
** be binding unless in writing and signed by Priio.
**
** BY SELECTING THE "I ACCEPT THE AGREEMENT" OPTION AND CLICKING ON THE "NEXT"
** BUTTON, OR BY INSTALLING, COPYING, RUNNING, OR OTHERWISE USING THE PRIIO
** SOFTWARE, YOU AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE AGREEMENT. IF
** YOU DO NOT AGREE TO THE TERMS OF THIS LICENSE AGREEMENT, PLEASE CLICK THE
** "CANCEL" BUTTON, AND DO NOT INSTALL, RUN, COPY, OR OTHERWISE USE THE PRIIO
** SOFTWARE.
**
*****************************************************************************
**
** VERSION HISTORY:
** ----------------
** Version: 3.0
** Date: March 29, 2006
** Revised by: Erick M. Higa
** Description:
** - See "FILE_SYS.C" file for any chages up to this point.
**
** Version: 3.0.1
** Date: April 7, 2006
** Revised by: Erick M. Higa
** Description:
** - Fixed initialize_media() so that the active partition entry
** (reguardless if it is the first entry) will be used.
**
****************************************************************************/
#define _SD_CMD_C_SRC
/*****************************************************************************
**
** MODULES USED
**
*****************************************************************************/
#include "..\flash\sd_cmd.h"
#include "..\flash\file_sys.h"
#ifdef _RTC_ON_
#include "..\flash\twi.h"
#endif
/*****************************************************************************
**
** PROTOTYPES OF LOCAL FUNCTIONS
**
*****************************************************************************/
void _FF_spi_init(void); // no need use this function in integrated code
void _SD_send_cmd(uint8 command, uint32 argument);
void clear_sd_buff(void);
int8 reset_sd(void);
int8 init_sd(void);
/*****************************************************************************
**
** EXPORTED VARIABLES
**
*****************************************************************************/
uint8 _FF_Buff[512];
#ifndef _BYTES_PER_SEC_512_
HiLo16Union BPB_BytsPerSec;
#endif
uint8 BPB_SecPerClus;
HiLo16Union BPB_RsvdSecCnt;
HiLo16Union BPB_RootEntCnt;
HiLo16Union BPB_FATSz16;
uint8 BPB_FATType;
#ifndef _BIG_ENDIAN_
uint32 BS_VolSerial;
#else
HiLo32Union BS_VolSerial;
#endif
int8 BS_VolLab[12];
uint16 _FF_PartitionAddr;
uint32 _FF_RootAddr;
#ifdef _DIRECTORIES_SUPPORTED_
uint32 _FF_DirAddr;
#endif
uint16 _FF_Fat1Addr;
uint32 _FF_Fat2Addr;
uint16 FirstDataSector;
uint8 _FF_error;
uint32 _FF_BuffAddr;
uint16 Clus0Counter;
int8 _FF_FullPath[_FF_PATH_LENGTH];
uint16 DataClusTot;
#if defined(_SD_BLOCK_WRITE_) && !defined(_READ_ONLY_)
uint32 SDBlockWriteBlockCnt;
#endif
/*****************************************************************************
**
** GLOBAL VARIABLES
**
*****************************************************************************/
#ifdef _DEBUG_ON_
flash int8 _FF_VersionInfoStr[] = "\r\nFlashFile ";
flash int8 _FF_BSecStr[] = "\r\nBoot_Sec:\t[%X %X %X] [%X] [%X]";
flash int8 _FF_BootSecPartAddrStr[] = "\r\nPart Address:\t%lX";
flash int8 _FF_BPB_BPSStr[] = "\r\nBPB_BytsPerSec:\t%X";
flash int8 _FF_BPB_SPCStr[] = "\r\nBPB_SecPerClus:\t%X";
flash int8 _FF_BPB_RSCStr[] = "\r\nBPB_RsvdSecCnt:\t%X";
flash int8 _FF_BPB_NFATStr[] = "\r\nBPB_NumFATs:\t%X";
flash int8 _FF_BPB_RECStr[] = "\r\nBPB_RootEntCnt:\t%X";
flash int8 _FF_BPB_Fz16Str[] = "\r\nBPB_FATSz16:\t%X";
flash int8 _FF_BPB_TS16Str[] = "\r\nBPB_TotSec16:\t%lX";
flash int8 _FF_BPB_FTStr[] = "\r\nBPB_FATType:\tFAT";
flash int8 _FF_1CStr[] = "1%c";
flash int8 _FF_ERRStr[] = " ERROR!!";
flash int8 _FF_BPB_FTEStr[] = "\r\nBPB_FATType:\tFAT ERROR!!!";
flash int8 _FF_CCntStr[] = "\r\nClusterCnt:\t%lX";
flash int8 _FF_RAddrStr[] = "\r\nROOT_ADDR:\t%lX";
flash int8 _FF_F2AddrStr[] = "\r\nFAT2_ADDR:\t%lX";
flash int8 _FF_RDSecStr[] = "\r\nRootDirSectors:\t%X";
flash int8 _FF_FDSecStr[] = "\r\nFirstDataSector:\t%X";
flash int8 _FF_RErrStr[] = "\r\nRead ERROR!!!";
flash int8 _FF_InvParTblStr[] = "\r\nInvalid Partition Table Error";
flash int8 _FF_InvBootSecStr[] = "\r\nInvalid Boot Sector";
flash int8 _FF_ResetCMDStr[] = "\r\nReset CMD: ";
flash int8 _FF_OkStr[] = "OK!!!";
flash int8 _FF_Err02Str[] = "ERROR-%02X";
flash int8 _FF_InitStr[] = "\r\nInitialization: ";
flash int8 _FF_CRLFStr[] = "\r\n";
flash int8 _FF_02XStr[] = "%02X ";
#endif
#ifdef _FF_READ_DEBUG_
flash int8 _read_addrStr[] = "\r\nReadADDR[0x%lX]";
#endif
#ifdef _DEBUG_MULTI_BLOCK_
uint32 _BLOCK_ADDRESS_;
flash int8 _FF_StartBlockWriteStr[] = "\r\nStart Block Write";
flash int8 _FF_StartMultiErrStr[] = " - MultiStartError%d-%02X";
flash int8 _FF_MultiWriteStr[] = "\r\nBlock Write @ 0x%lX";
flash int8 _FF_Multi02Str[] = "-%02X-";
flash int8 _FF_MultiEndStr[] = "[MultiEndErr-%d]";
flash int8 _FF_WriteBlockStartStr[] = "\r\nStart Block Write";
flash int8 _FF_WriteBlock02XStr[] = "[%02X-%d]";
flash int8 _FF_WriteMultiStartStr[] = " - MultiStartError%d-%02X";
#endif
#ifdef _FF_WRITE_DEBUG_
flash int8 _FF_WriteAddr_ldXStr[] = "\r\nWriteADDR[0x%lX]";
flash int8 _FF_WriteAddrErrStr[] = "\tWriteErr[%d]";
#endif
/*****************************************************************************
**
** EXPORTED FUNCTIONS
**
*****************************************************************************/
#ifdef _DEBUG_ON_
/****************************************************************************
**
** Debug funtion that gets one character from the UART
**
** Parameters: NONE
**
** Returns: Charater received
**
****************************************************************************/
int16 _FF_getchar(void)
{
while(!(UCSR1A & 0x80))
;
return(UDR1); /* grab character */
}
/****************************************************************************
**
** Debug funtion that sends one character to the UART
**
** Parameters: send_char, character to send
**
** Returns: Sent character
**
****************************************************************************/
int16 _FF_putchar(int16 send_char)
{
while (!(UCSR1A & 0x20))
; /* wait xmit ready */
UDR1 = (uint8) send_char;
return(send_char);
}
/****************************************************************************
**
** Clears the SD/MMC's SPI bus so commands can be sent cleanly.
**
** Parameters: None
**
** Returns: None
**
****************************************************************************/
#if defined(_CVAVR_) || defined(_ICCAVR_) || defined(_ROWLEY_CWAVR_)
void _FF_printf(flash int8 *pstr, ...)
#elif defined(_IAR_EWAVR_)
void _FF_printf(PGM_P pstr, ...)
#endif /*defined(_CVAVR_) || defined(_ICCAVR_)*/
{
va_list arglist;
#ifdef _CVAVR_
int8 temp_buff[_FF_MAX_FPRINTF], *fp;
va_start(arglist, pstr);
vsprintf(temp_buff, pstr, arglist);
#else
int8 temp_buff[_FF_MAX_FPRINTF], *fp;
int8 pstr_sram[_FF_MAX_FPRINTF];
int16 cntr;
cntr = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -