📄 test-1.c~
字号:
_FF_printf(CR_ModTime);
_FF_printf(_S_STR, modify_info);
_FF_printf(CR_ATTR, c);
_FF_printf(CR_STARTCLUS, n, (clust_to_addr(n)<<9));
}
else
_FF_printf(CRLF_ERROR_X, _FF_error);
chdir(tempback);
if(rx_counter0)
{
c = _FF_getchar();
if(c == 0x1B)
break;
}
} /*for(d = 0; d < 100; d++)*/
_FF_printf(doneStr);
}
#endif /*defined(_DIRECTORIES_SUPPORTED_)*/
#endif /*!defined(_READ_ONLY_)*/
#ifndef _READ_ONLY_
/****************************************************************************
**
** Function that runs a demo program to show a normal file creation and
** writing to the file using the fwrite function for binary data.
**
** Parameters: None
**
** Returns: None
**
****************************************************************************/
void fwrite_demo(void)
{
FILE *pntr1;
uint16 i;
uint8 c, n;
int8 test_buff[16];
/* Create File */
pntr1 = fcreatec(_FF_FWRITENAME, ATTR_ARCHIVE);
i = 0;
while(pntr1 == 0)
{
if(pntr1 == 0)
{
_FF_printf(Fail02Str, _FF_error);
i++;
if(i & 0xF0)
return;
}
pntr1 = fcreatec(_FF_FWRITENAME, ATTR_ARCHIVE);
}
_FF_strcpyf(test_buff, _FF_FWRITENAME);
_FF_printf(CreatedStr, 0x22, test_buff, 0x22);
for(n = 0; n < 16; n++)
{
for(c = 0; c < 16; c++)
test_buff[c] = c;
for(c = 0; c < 16; c++)
test_buff[c] |= (n << 4);
if(fwrite(test_buff, 1, 16, pntr1) != 16)
{
_FF_printf(FWriteErrStr);
break;
}
}
fclose(pntr1);
pntr1 = 0;
n = 0;
while(pntr1 == 0)
{
pntr1 = fopenc(_FF_FWRITENAME, READ);
n++;
if(n & 0xF0)
return;
}
_FF_printf(doneStr);
}
#if defined(_SD_BLOCK_WRITE_)
/****************************************************************************
**
** Function that runs the demo program to show how to use the block writing
** capabilities of the SD or MMC media.
**
** Parameters: None
**
** Returns: None
**
****************************************************************************/
void run_stream_demo(void)
{
FILE *fp;
int32 ltemp;
int8 temp_buff[_FF_MAX_FPRINTF];
int8 *ptr;
#ifdef _RTC_ON_
rtc_get_timeNdate(&RTCHour, &RTCMin, &RTCSec, &RTCDay, &RTCMonth, &RTCYear);
#endif
_FF_printf(ReserveSpaceStr);
/* Reserve 1MB maximum for the file */
if (fstream_filec(_FF_StreamNameStr, 1048576))
{
return;
}
_FF_printf(WritingBigFileStr);
for(ltemp = 0; ltemp < 100000L; ltemp++)
{
if((ltemp % 10) == 0)
{
SD_write_block_byte('\r');
SD_write_block_byte('\n');
}
_FF_sprintf(temp_buff, LDCommaStr, ltemp);
ptr = temp_buff;
while(*ptr)
{
if(SDBlockWriteBlockCnt <= 1048576)
SD_write_block_byte(*ptr++);
else
{
/* More bytes trying to be written than reserved */
ltemp = 100000L;
*ptr = 0;
}
}
}
_FF_printf(EndFileLDBytesStr, SDBlockWriteBlockCnt);
/* End the block write */
if (SD_write_block_end())
{
_FF_printf(EndBlockErrorStr);
return;
}
/* Reopen the file in APPEND mode to change the file */
fp = fopenc(_FF_StreamNameStr, APPEND);
if (fp == NULL)
{
_FF_printf(FOpenErrStr);
return;
}
/* Find where the data was done writing */
if (fseek(fp, SDBlockWriteBlockCnt, SEEK_SET))
{
_FF_printf(FSeekErrStr);
return;
}
/* Current cluster should be the last now, erase the cluster chain */
if (erase_clus_chain(fp->clus_current))
{
_FF_printf(EraseChainErrStr);
return;
}
/* Set current cluster to EOF marker */
if (write_clus_table(fp->clus_current, EOF, SINGLE))
{
_FF_printf(WriteTableErrStr);
return;
}
/* Manually Reset File Size so the TOC gets updated right */
fp->length = SDBlockWriteBlockCnt;
/* Close file, saves new changes */
if (fclose(fp))
{
_FF_printf(FileCloseErrStr);
return;
}
return;
}
#endif /*defined(_SD_BLOCK_WRITE_)*/
/****************************************************************************
**
** Function that runs the demo program to shows a file being created,
** modified, and closed.
**
** Parameters: None
**
** Returns: None
**
****************************************************************************/
void run_reopen(void)
{
FILE *pntr1;
uint8 c;
uint16 n;
int8 tempc[14];
HiLo16Union c2;
_FF_strcpyf(tempc, _FF_REOPENNAME);
pntr1 = fcreate(tempc, ATTR_ARCHIVE);
for(n = 0; n < 5; n++)
{
if(pntr1 == 0)
{
_FF_printf(CreateFailedStr, 0x22, tempc, 0x22);
pntr1 = fcreate(tempc, ATTR_ARCHIVE);
}
else
n = 5;
}
if(pntr1 == 0)
{
_FF_printf(CreateFailedStr, 0x22, tempc, 0x22);
return;
}
_FF_printf(CreatedStr, 0x22, tempc, 0x22);
/* Write to file */
#ifdef _RTC_ON_
/* if real time clock enabled, get and print time and date to file */
rtc_get_timeNdate(&RTCHour, &RTCMin, &RTCSec, &RTCDay, &RTCMonth, &RTCYear);
fprintf(pntr1, C2DStr, 0x22, RTCMonth);
fprintf(pntr1, p2DSlashStr, RTCDay);
fprintf(pntr1, p4DStr, RTCYear);
fprintf(pntr1, p2DColinStr, RTCHour);
fprintf(pntr1, p2DColinStr, RTCMin);
fprintf(pntr1, p2DCRLFStr, RTCSec, 0x22);
#endif
fclose(pntr1);
for(n = 0; n < 0x100; n++)
{
fopen(tempc, APPEND);
fprintf(pntr1, CSCStr, 0x22, tempc, 0x22);
c2.uval8.lo = n & 0x0F;
if(c2.uval8.lo > 9)
c2.uval8.lo += 0x37;
else
c2.uval8.lo += 0x30;
c2.uval8.hi = (n >> 4) & 0x0F;
if(c2.uval8.hi > 9)
c2.uval8.hi += 0x37;
else
c2.uval8.hi += 0x30;
c = 0;
while((pntr1->position % 512) < 507)
{
if((pntr1->position % 64) == 62)
fputc('\r', pntr1);
else if((pntr1->position % 64) == 63)
{
fputc('\n', pntr1);
c = 0;
}
else
{
if((c % 3) == 0)
fputc(c2.uval8.hi, pntr1);
else if((c % 3) == 1)
fputc(c2.uval8.lo, pntr1);
else if((c % 3) == 2)
fputc(' ', pntr1);
c++;
}
}
fclose(pntr1);
}
_FF_printf(doneStr);
}
#endif /*_READ_ONLY_*/
/****************************************************************************
**
** Function that displays the Root Commands for the Full Demo
**
** Parameters: None
**
** Returns: None
**
****************************************************************************/
void handle_level1(uint8 test_char)
{
int8 *pointer, sd_temp[14], sd_temp2[24], create_info[22], modify_info[22];
uint16 status, n;
uint32 addr_sd;
uint8 print_demo_flag;
#ifndef _READ_ONLY_
uint32 c;
#endif
pointer = 0;
print_demo_flag = 1; /* assume for now that we will recognize the command! */
switch(test_char)
{
case '1':
_FF_printf(CRLF_INIT);
print_result(initialize_media(), 0, 0);
break;
#ifdef _DEBUG_ON_
case '2':
read_directory();
break;
#endif
#ifndef _READ_ONLY_
case '3':
_FF_printf(CRLF_CREATE);
if(get_input_str(sd_temp2, 24) != 0)
{
_FF_printf(_FF_CRLFStr);
file1 = fcreate(sd_temp2, ATTR_ARCHIVE);
print_result((int) file1, 1, NULL);
if(file1 != 0)
fclose(file1);
}
break;
case '4':
_FF_printf(CRLF_DELETE);
if(get_input_str(sd_temp2, 24) != 0)
print_result(remove(sd_temp2), 1, EOF);
break;
case '5':
_FF_printf(CRLF_RENAME);
if(get_input_str(sd_temp2, 24) != 0)
{
_FF_printf(CRLF_NEWNAME);
flush_receive(); /* clear out any hanging characters from last entry */
if(get_input_str(sd_temp, 12) != 0)
print_result(rename(sd_temp2, sd_temp), 1, EOF);
}
break;
#endif
case '6':
_FF_printf(CRLF_OPEN);
if(get_input_str(sd_temp2, 24) != 0)
{
_FF_printf(CRLF_CHOOSE);
flush_receive(); /* clear out any hanging characters from last entry */
status = _FF_getchar();
switch(status)
{
case '1':
_FF_printf(DASH_READ);
file1 = fopen(sd_temp2, READ);
break;
case '2':
_FF_printf(DASH_WRITE);
file1 = fopen(sd_temp2, WRITE);
break;
case '3':
_FF_printf(DASH_APPEND);
file1 = fopen(sd_temp2, APPEND);
break;
}
if(file1 == 0)
_FF_printf(CRLF_OPENERROR, _FF_error);
else
{
_FF_printf(CRLF_SUCCESSOPEN, sd_temp2);
menu_level = 2;
display_file_commands();
print_demo_flag = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -