⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test-1.c~

📁 This fat 16 can be used for logging function. The user can use it for logger device.
💻 C~
📖 第 1 页 / 共 5 页
字号:
/***************************** C SOURCE FILE *********************************
**
**  Project:    FlashFile
**  Filename:   FDEMO.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 
**      tight 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 conditional compile for _RTC_ON_ not used.
**
*****************************************************************************/

#define _DEMO_C_SRC

/*****************************************************************************
**
** MODULES USED 
**
*****************************************************************************/
#include "options.h"
#include "demo.h"

/*****************************************************************************
**
** PROTOTYPES OF LOCAL FUNCTIONS 
**
*****************************************************************************/
#if defined(_ICCAVR_)
    int16 putchar(int8 send_char);
#endif
void port_init(void);
void uart0_init(void);
void uart1_init(void);
void init_devices(void);
void display_demo_commands(void);
void display_file_commands(void);
void flush_receive(void);
int16 get_input_str(int8 *input_str, int16 max_size);
#ifdef _RTC_ON_
    void set_date_time(void);
#endif
void print_result(int16 result,int8 error_flag,int16 bad_compare_value);
uint32 get_addr_entry(uint8 addr_size);
#ifndef _READ_ONLY_
    void run_demo(void);
    void run_multi(void);
    #if defined(_DIRECTORIES_SUPPORTED_)
        void run_multifold(void);
    #endif
    #if defined(_SD_BLOCK_WRITE_)
        void run_stream_demo(void);
    #endif
    void fwrite_demo(void);
    void run_reopen(void);
#endif
void handle_level1(uint8 test_char);
void handle_level2(uint8 testchar);
void main(void);

/*****************************************************************************
**
** EXPORTED VARIABLES 
**
*****************************************************************************/
/*****************************************************************************
**
** GLOBAL VARIABLES 
**
*****************************************************************************/
int8 menu_level;
FILE *file1;

flash int8 TestCmd0Str[] = "\r\nTest Commands:";
flash int8 TestCmd1Str[] = "\r\n\t(1)-Initialize Media\t(2)-Read Directory Files";
flash int8 TestCmd2Str[] = "\r\n\t(3)-Create File\t\t(4)-Delete File";
flash int8 TestCmd3Str[] = "\r\n\t(5)-Rename File\t\t(6)-Open File";
flash int8 TestCmd4Str[] = "\r\n\t(7)-Make Directory\t(8)-Delete Directory";
flash int8 TestCmd5Str[] = "\r\n\t(9)-Change Working Dir\t(0)-Get File Info";
flash int8 TestCmd6Str[] = "\r\n\t(F)-Quick Format Card\t(V)-Get Media Serial & Label";
#ifndef _READ_ONLY_
    flash int8 TestCmd7Str[] = "\r\n\t(d)-Run Demo\t\t(D)-Run Multifile Demo";
    flash int8 TestCmd8Str[] = "\r\n\t(W)-Run fwrite Demo";
    #ifdef _DIRECTORIES_SUPPORTED_
        flash int8 TestCmd9Str[] = "\t(Q)-Run Multifolder Demo";
    #endif
    #ifdef _SD_BLOCK_WRITE_
        flash int8 TestCmd10Str[] = "\r\n\t(S)-Run Stream Demo";
    #endif
    flash int8 FormatDoneStr[] = " * Format Done * ";
#endif
#ifdef _RTC_ON_
    flash int8 TimeDateStr[] =     "\r\n\t(c)-Display Time/Date\t(C)-Set Time/Date";
#endif
flash int8 OpenFile0Str[] = "\r\nOpen File Commands:";
flash int8 OpenFile1Str[] = "\r\n\t(1)-ftell\t\t(2)-fseek";
flash int8 OpenFile2Str[] = "\r\n\t(3)-fgetc\t\t(4)-ungetc";
flash int8 OpenFile3Str[] = "\r\n\t(5)-Read file till END\t(6)-Write to File";
flash int8 OpenFile4Str[] = "\r\n\t(7)-Dump Buffer - HEX\t(8)-Dump Buffer - ASCII";
flash int8 OpenFile5Str[] = "\r\n\t(9)-fflush\t\t(0)-fclose";
flash int8 OpenFile6Str[] = "\r\n\t(E)-Free File Memory\r\n";
flash int8 CRLF_SENDDATE[] = "\r\nSend Date and Time as mm/dd/yyyy hh:mm:ss[ENTER]\r\n";
flash int8 CRLF_DateInsert[] = "\r\n%02d/%02d/%04d %02d:%02d:%02d";
flash int8 CRLF_OK[] = "\r\n - OK!";
flash int8 CRLF_ERROR[] = "\r\n - ERROR!";
flash int8 DASH_X[] = " - %X";
flash int8 _FF_FNAME[] = "demo.dat";
flash int8 _FF_FWRITENAME[] = "raw.pas";
flash int8 _FF_REOPENNAME[] = "reopen.dat";
flash int8 ldStr[] = "%03d, ";
flash int8 doneStr[] = "\r\n\r\nDONE!!!";
flash int8 column_d[] = "Column %d, ";
flash int8 Fail02Str[] = "\r\nFAILED!!! - %02X";
flash int8 CreateFailedStr[] = "\r\n%c%s%c Creation FAILED!!!";
flash int8 CSCStr[] = "%c%s%c\r\n";
flash int8 CreatedStr[] = "\r\n%c%s%c Created ";
flash int8 DEMO_FILENAME8[] = "demo";
flash int8 DEMO_FILENAME3[] = ".dat";
flash int8 SDSStr[] = "%s%02d%s";
flash int8 EOFStr[] = "EOF\r\n";
#ifdef _DIRECTORIES_SUPPORTED_
    flash int8 WORKING_FOLDER[] = "\\TESTFOLD";
    flash int8 DEMO_FOLDNAME[] = "FOLD%02d";
#endif
flash int8 C2DStr[] = "%c%02d/";
flash int8 p2DSlashStr[] = "%02d/";
flash int8 p4DStr[] = "%04d  ";
flash int8 p2DColinStr[] = "%02d:";
flash int8 p2DCRLFStr[] = "%02d%c\r\n";
flash int8 P2DCStr[] = "%02d%c";
flash int8 FWriteErrStr[] = "\r\nFWRITE ERROR!!!";
flash int8 CRLF_BOOTLOAD[] = "\r\nJumping to Bootloader";
flash int8 CRLF_INIT[] = "\r\nInitializing... ";
flash int8 CRLF_CREATE[] = "\r\nCreating File:  ";
flash int8 CRLF_DELETE[] = "\r\nDeleting File:  ";
flash int8 CRLF_RENAME[] = "\r\nRename File:\r\n\tOld Name:  ";
flash int8 CRLF_NEWNAME[] = "\r\n\tNew Name:  ";
flash int8 CRLF_OPEN[] = "\r\nOpen file:  ";
flash int8 CRLF_CHOOSE[] = "\r\nChoose:  (1)-READ  (2)-WRITE  (3)-APPEND";
flash int8 DASH_READ[] = " - READ";
flash int8 DASH_WRITE[] = " - WRITE";
flash int8 DASH_APPEND[] = " - APPEND";
flash int8 CRLF_OPENERROR[] = "\r\nFileOpen Error = %x";
flash int8 CRLF_SUCCESSOPEN[] = "\r\nSuccess!!! - %s - Opened! \r\n";
#ifdef _DIRECTORIES_SUPPORTED_
    flash int8 CRLF_MKDIR[] = "\r\nMake Directory:  ";
    flash int8 CRLF_DELDIR[] = "\r\nDelete Directory:  ";
    flash int8 CRLF_CHDIR[] = "\r\nChange Current Directory to:  ";
#endif
flash int8 CRLF_GETFILEINFO[] = "\r\nGet File Info for:  ";
flash int8 CRLF_FileSize[] = "\r\n  File Size:  %ld bytes\r\n  Create Time:  ";
flash int8 CR_ModTime[] = "\r\n  Modify Time:  ";
flash int8 CR_ATTR[] = "\r\n  Attributes:  0x%02X";
flash int8 CR_STARTCLUS[] = "\r\n  Starting Cluster:  0x%X @ ADDR: 0x%lX\r\n";
flash int8 CRLF_ERROR_X[] = "\r\n - ERROR! - %X\r\n";
flash int8 CRLF_QUICKFORMAT[] = "\r\nQuick Format Card and delete all existing data?  (Y)es  (N)o\r\n  ";
flash int8 es_dash[] = "es - ";
flash int8 o_Cancel[] = "o - Cancelled\r\n";
flash int8 INV_RESP[] = " - Ivnalid Response - Cancelled\r\n";
flash int8 CRLF_READMEDIA[] = "\r\nRead Media - Enter Address: ";
flash int8 CRLF_CALCADDR[] = "\r\nCalc. address: %lx";
flash int8 CRLF_FINDCLUS[] = "\r\nFinding Next Avaliable Cluster:  [%X],  _FF_error = [%X]";
flash int8 CRLF_LOCATE[] = "\r\nLocated @ 0x%lX";
flash int8 CRLF_PCLUST[] = "\r\nPoint Cluster: 0x";
flash int8 CRLF_ECLUST[] = "\r\nErase Cluster Chain: 0x";
flash int8 CRLF_NCLUST[] = "\r\nNext Cluster: 0x";
flash int8 NCLUST[] = " is 0x%X";
flash int8 CRLF_TCLUST[] = "\r\nTo Cluster: 0x";
flash int8 DASH_OK[] = " - OK!!!";
flash int8 DASH_ERROR[] = " - ERROR!!!";
flash int8 CRLF_VolSer[] = "\r\nVolume Serial Number and Label:";
flash int8 _S_STR[] = "%s";
flash int8 CRLF_FTELL[] = "\r\nftell:  position = 0x%lX";
flash int8 CRLF_FSEEK[] = "\r\nfseek:  Offset = 0x";
flash int8 CRLF_SEEKMODE[] = "=%lX\r\n    Mode:  (1)-SEEK_CUR  (2)-SEEK_END  (3)-SEEK_SET :";
flash int8 DASH_CUR[] = " - SEEK_CUR";
flash int8 DASH_END[] = " - SEEK_END";
flash int8 DASH_SET[] = " - SEEK_SET";
flash int8 CRLF_ENTERCHAR[] = "\r\nEnter character to push back: ";
flash int8 DASH_OK_CRLF[] = " - OK!\r\n";
flash int8 CRLF_WRITEFILE[] = "\r\nWrite to file:   Press [ESC] to end 'Write' mode\r\n";
flash int8 CRLF_WRITEERROR[] = "\r\nWrite ERROR!!!";
flash int8 CRLF_FFLUSH[] = "\r\nFile Flushing...";
flash int8 CRLF_FCLOSE[] = "\r\nFile Closing...";
flash int8 CRLF_CLOSEPROMPT[] = "\r\nClose File w/o saving buffered data?  (Y)es  (N)o\r\n  ";
flash int8 CRLF_MICRORESET[] = "\r\nMicrocontroller Reset!!!\r\n";
flash int8 CRLF_FF_VER[] = "\r\nFlashFile ";
flash int8 CRLF_1toINIT[] = "\r\nPress '1' to initialize media:";
flash int8 CRLF_ERROR_CRLF[] = "\r\n  ERROR!!!\r\n";
#ifndef _DEBUG_ON_
    flash int8 _FF_CRLFStr[] = "\r\n";
#endif
#if defined(_SD_BLOCK_WRITE_)
    flash int8 _FF_StreamNameStr[] = "BIG_FILE.TXT";
    flash int8 ReserveSpaceStr[] = "\r\nReserve Space ";
    flash int8 WritingBigFileStr[] = "\tWriting to \"BIG_FILE\" ";
    flash int8 LDCommaStr[] = "%ld, ";
    flash int8 EndFileLDBytesStr[] = "\r\nEnd File %ld bytes!!!";
    flash int8 EndBlockErrorStr[] = "\r\nEnd Multiblock Error!!!";
    flash int8 FileCloseErrStr[] = "\r\nFile Close Error";
    flash int8 WriteTableErrStr[] = "\r\nWrite Table Error";
    flash int8 EraseChainErrStr[] = "\r\nErase Chain Error";
    flash int8 FSeekErrStr[] = "\r\nfseek Error!!!";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -