📄 tftpc.h
字号:
/*********************************************************************
*
* TFTP Client module for Microchip TCP/IP Stack
*
*********************************************************************
* FileName: TFTPc.h
* Dependencies: StackTsk.h
* Processor: PIC18
* Complier: MCC18 v1.00.50 or higher
* HITECH PICC-18 V8.10PL1 or higher
* Company: Microchip Technology, Inc.
*
* Software License Agreement
*
* This software is owned by Microchip Technology Inc. ("Microchip")
* and is supplied to you for use exclusively as described in the
* associated software agreement. This software is protected by
* software and other intellectual property laws. Any use in
* violation of the software license may subject the user to criminal
* sanctions as well as civil liability. Copyright 2006 Microchip
* Technology Inc. All rights reserved.
*
* This software is provided "AS IS." MICROCHIP DISCLAIMS ALL
* WARRANTIES, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, NOT LIMITED
* TO MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
* INFRINGEMENT. Microchip shall in no event be liable for special,
* incidental, or consequential damages.
*
* Author Date Comment
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Nilesh Rajbharti 8/5/03 Original (Rev 1.0)
********************************************************************/
#ifndef TFTPC_H
#define TFTPC_H
#include "StackTsk.h"
#include "UDP.h"
// Number of seconds to wait before declaring TIMEOUT error on Get.
#define TFTP_GET_TIMEOUT_VAL (3 * TICKS_PER_SECOND)
// Number of seconds to wait before declaring TIMEOUT error on Put
#define TFTP_ARP_TIMEOUT_VAL (3 * TICKS_PER_SECOND)
// Number of attempts before declaring TIMEOUT error.
#define TFTP_MAX_RETRIES (3)
// Retry count must be 1 or more.
#if TFTP_MAX_RETRIES <= 0
#error Retry count must at least be 1
#endif
// Enum. of results returned by most of the TFTP functions.
typedef enum _TFTP_RESULT
{
TFTP_OK = 0,
TFTP_NOT_READY,
TFTP_END_OF_FILE,
TFTP_ERROR,
TFTP_RETRY,
TFTP_TIMEOUT
} TFTP_RESULT;
// File open mode as used by TFTPFileOpen().
typedef enum _TFTP_FILE_MODE
{
TFTP_FILE_MODE_READ = 1,
TFTP_FILE_MODE_WRITE = 2
} TFTP_FILE_MODE;
// Standard error codes as defined by TFTP spec.
// Use to decode value retuned by TFTPGetError().
typedef enum _TFTP_ACCESS_ERROR
{
TFTP_ERROR_NOT_DEFINED = 0,
TFTP_ERROR_FILE_NOT_FOUND,
TFTP_ERROR_ACCESS_VIOLATION,
TFTP_ERROR_DISK_FULL,
TFTP_ERROR_INVALID_OPERATION,
TFTP_ERROR_UNKNOWN_TID,
TFTP_ERROR_FILE_EXISTS,
TFTP_ERROR_NO_SUCH_USE
} TFTP_ACCESS_ERROR;
/*********************************************************************
* Function: void TFTPOpen(IP_ADDR *host)
*
* PreCondition: UDP module is already initialized
* and at least one UDP socket is available.
*
* Input: host - IP address of remote TFTP server
*
* Output: None
*
* Side Effects: None
*
* Overview: Initiates ARP for given host and prepares
* TFTP module for next sequence of function calls.
*
* Note: Use TFTPIsOpened() to check if a connection was
* successfully opened or not.
*
********************************************************************/
void TFTPOpen(IP_ADDR *host);
/*********************************************************************
* Function: TFTP_RESULT TFTPIsOpened(void)
*
* PreCondition: TFTPOpen() is already called.
*
* Input: None
*
* Output: TFTP_OK if previous call to TFTPOpen is complete
*
* TFTP_TIMEOUT if remote host did not respond to
* previous ARP request.
*
* TFTP_NOT_READY if remote has still not responded
* and timeout has not expired.
*
* Side Effects: None
*
* Overview: Waits for ARP reply and opens a UDP socket
* to perform further TFTP operations.
*
* Note: Once opened, application may keep TFTP socket
* open and future TFTP operations.
* If TFTPClose() is called to close the connection
* TFTPOpen() must be called again before performing
* any other TFTP operations.
********************************************************************/
TFTP_RESULT TFTPIsOpened(void);
/*********************************************************************
* Macro: void TFTPClose(void)
*
* PreCondition: TFTPOpen is already called and TFTPIsOpened()
* returned TFTP_OK.
*
* Input: None
*
* Output: None
*
* Side Effects: None
*
* Overview: Closes TFTP client socket.
*
* Note: Once closed, application must do TFTPOpen to
* perform any new TFTP operations.
*
* If TFTP server does not change during application
* life-time, one may not need to call TFTPClose
* and keep TFTP socket open.
********************************************************************/
#define TFTPClose(void) UDPClose(_tftpSocket)
extern UDP_SOCKET _tftpSocket;
/*********************************************************************
* Macro: BOOL TFTPIsFileOpenReady(void)
*
* PreCondition: TFTPOpen is already called and TFTPIsOpened()
* returned TFTP_OK.
*
* Input: None
*
* Output: TRUE, if it is ok to call TFTPOpenFile()
* FALSE, if otherwise.
*
* Side Effects: None
*
* Overview: Checks to see if it is okay to send TFTP file
* open request to remote server.
*
* Note: None
********************************************************************/
#define TFTPIsFileOpenReady() UDPIsPutReady(_tftpSocket)
/*********************************************************************
* Function: void TFTPOpenFile(char *fileName,
* TFTP_FILE_MODE mode)
*
* PreCondition: TFPTIsFileOpenReady() = TRUE
*
* Input: fileName - File name that is to be opened.
* mode - Mode of file access
* Must be
* TFTP_FILE_MODE_READ for read
* TFTP_FILE_MODE_WRITE for write
*
* Output: None
*
* Side Effects: None
*
* Overview: Prepares and sends TFTP file name and mode packet.
*
* Note: By default, this funciton uses "octet" or binary
* mode of file transfer.
* Use TFTPIsFileOpened() to check if file is
* ready to be read or written.
********************************************************************/
void TFTPOpenFile(char *fileName, TFTP_FILE_MODE mode);
/*********************************************************************
* Function: TFTP_RESULT TFTPIsFileOpened(void)
*
* PreCondition: TFTPOpenFile() is called.
*
* Input: None
*
* Output: TFTP_OK if file is ready to be read or written
*
* TFTP_RETRY if previous attempt was timed out
* needs to be retried.
*
* TFTP_TIMEOUT if all attempts were exhausted.
*
* TFTP_NOT_ERROR if remote server responded with
* error
*
* TFTP_NOT_READY if file is not yet opened.
*
* Side Effects: None
*
* Overview: Waits for remote server response regarding
* previous attempt to open file.
* If no response is received within specified
* timeout, fnction returns with TFTP_RETRY
* and application logic must issue another
* TFTPFileOpen().
*
* Note: None
********************************************************************/
TFTP_RESULT TFTPIsFileOpened(void);
/*********************************************************************
* Function: void TFTPCloseFile(void)
*
* PreCondition: TFTPOpenFile() was called and TFTPIsFileOpened()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -