📄 test-1__.c
字号:
i = SDBlockWriteBlockCnt % 512;
if(i)
{
while(i++ < 512)
_FF_spi(0xFF); /* Pad the rest of the block */
_FF_spi(0xFF); /* Send 2 blank CRC bytes */
_FF_spi(0xFF);
resp = _FF_spi(0xFF); /* Response should be 0bXXX00101 */
calc = resp | 0xE0;
if(calc == 0xE5)
{
n = 0;
do
{
/* Wait for not busy */
resp = _FF_spi(0xFF);
if(n++ > 30000)
{
#ifdef _DEBUG_MULTI_BLOCK_
_FF_printf(_FF_MultiEndStr, 1);
#endif
resp = 0xFF; /* Response not received for too long, ignore*/
}
} while(resp == 0);
}
else
{
SD_CS_OFF();
_FF_spi(0xFF);
#ifdef _DEBUG_MULTI_BLOCK_
_FF_printf(_FF_MultiEndStr, 2);
#endif
return((int8) EOF);
}
}
_FF_spi(0xFF);
_FF_spi(SD_STOP_TRANS); /* Stop Block Token */
n = 0;
do
{
/* Wait for not busy */
resp = _FF_spi(0xFF);
if(n++ > 30000)
resp = 0xFF; /* Response not received for too long, ignore*/
} while(resp == 0);
SD_CS_OFF();
_FF_spi(0xFF);
return(0);
}
#endif /*defined(_SD_BLOCK_WRITE_) && !defined(_READ_ONLY_)*/
/*****************************************************************************
**
** LOCAL FUNCTIONS
**
*****************************************************************************/
/****************************************************************************
**
** Initializes the SPI bus in the correct mode to use with the SD/MMC media.
**
** Parameters: None
**
** Returns: None
**
****************************************************************************/
void _FF_spi_init(void)
{
/* SPI BUS SETUP */
/* SPI initialization */
/* SPI Type: Master */
/* SPI Clock Rate: 921.600 kHz */
/* SPI Clock Phase: Cycle Half */
/* SPI Clock Polarity: Low */
/* SPI Data Order: MSB First */
#ifdef _MEGAAVRDEV_
DDRB = 0xB0 | DEMO_LED;
#else
DDRB |= 0x07; /* Set SS, SCK, and MOSI to Output (If not output, processor will be a slave) */
DDRB &= 0xF7; /* Set MISO to Input */
#endif
CS_DDR_SET(); /* Set CS to Output */
SPSR = 0x01;
SPCR = _FF_SPCR_SET; /* Initialize the SPI bus as a master */
}
/****************************************************************************
**
** Initializes all timers in the system. This call must be made before any
** time-dependent functions can be called. The application should not enable
** interrupts before TimeInit is called.
**
** Parameters: command, the command to send to the card
** argument, any data needed associated with the command
**
** Returns: None
**
****************************************************************************/
void _SD_send_cmd(uint8 command, uint32 argument)
{
HiLo32Union arg_temp;
SD_CS_ON(); /* select SD Card */
/* send the command */
_FF_spi(command);
arg_temp.uval32 = argument;
_FF_spi(arg_temp.uval8.hi);
_FF_spi(arg_temp.uval8.mh);
_FF_spi(arg_temp.uval8.ml);
_FF_spi(arg_temp.uval8.lo);
/* Send the CRC byte */
if(command == CMD0)
_FF_spi(0x95); /* CRC byte, don't care except for CMD0 = 0x95 */
else
_FF_spi(0xFF);
return;
}
/****************************************************************************
**
** Clears the SD/MMC's SPI bus so commands can be sent cleanly.
**
** Parameters: None
**
** Returns: None
**
****************************************************************************/
void clear_sd_buff(void)
{
int8 n;
SD_CS_OFF();
for(n = 0; n < 10; n++)
_FF_spi(0xFF);
}
/****************************************************************************
**
** Sends the "RESET" command to the SD/MMC media, the first command that has
** to be sent to the card when initally powered.
**
** Parameters: None
**
** Returns: 0 - Reset command successful
** -1 - Failed to reset the card
**
****************************************************************************/
int8 reset_sd(void)
{
int8 resp, c;
int16 n;
#ifdef _DEBUG_INIT_SD_
_FF_printf(_FF_ResetCMDStr);
#endif
for(c = 0; c < 10; c++) /* try reset command 3 times if needed */
{
clear_sd_buff();
_SD_send_cmd(CMD0, 0);
for(n = 0; n < 1000; n++)
{
resp = _FF_spi(0xFF);
if(resp == 0x1)
{
SD_CS_OFF();
#ifdef _DEBUG_INIT_SD_
_FF_printf(_FF_OkStr);
#endif
_FF_spi(0xFF);
return(0);
}
}
#ifdef _DEBUG_INIT_SD_
_FF_printf(_FF_Err02Str, resp);
#endif
}
return((int8) EOF);
}
/****************************************************************************
**
** Sends the "RESET" command to the SD/MMC media, the first command that has
** to be sent to the card when initally powered.
**
** Parameters: None
**
** Returns: 0 - Reset command successful
** -1 - Failed to reset the card
**
****************************************************************************/
int8 init_sd(void)
{
uint8 resp;
int16 i, n;
clear_sd_buff();
#ifdef _DEBUG_INIT_SD_
_FF_printf(_FF_InitStr);
#endif
resp = 0xFF;
for(i = 0; ((i < 10000) && (resp != 0)); i++)
{
_SD_send_cmd(CMD1, 0);
for(n = 0; ((n < 200) && (resp != 0)); n++)
resp = _FF_spi(0xFF);
}
_FF_spi(0xFF);
SD_CS_OFF();
if(resp == 0)
{
#ifdef _DEBUG_INIT_SD_
_FF_printf(_FF_OkStr);
#endif
return(0);
}
else
{
#ifdef _DEBUG_INIT_SD_
_FF_printf(_FF_Err02Str, resp);
#endif
return((int8) EOF);
}
}
/*****************************************************************************
**
** EOF
**
*****************************************************************************/
/***************************** C SOURCE FILE *********************************
**
** Project: FlashFile
** Filename: FILE_SYS.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?s 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,
** whet
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -