| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- /**
- ******************************************************************************
- * @file IAP_Main/Inc/ymodem.h
- * @author MCD Application Team
- * @version 1.0.0
- * @date 8-April-2015
- * @brief This file provides all the software function headers of the ymodem.c
- * file.
- ******************************************************************************
- *
- * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.st.com/software_license_agreement_liberty_v2
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- */
- /* Define to prevent recursive inclusion -------------------------------------*/
- #ifndef __YMODEM_H_
- #define __YMODEM_H_
- #include "stdint.h"
- #include "string.h"
- #include "stm32g0xx_hal.h"
- #include "stm32g0xx_hal_usart.h"
- #include "rtthread.h"
- extern UART_HandleTypeDef UartHandle;
- //#define TX_TIMEOUT ((uint32_t)1000)
- /* Includes ------------------------------------------------------------------*/
- /* Exported types ------------------------------------------------------------*/
- #define N_APP_ADDR_BASE 0x8005800 //APP起始地址 /BootLoader空间+flash存储空间之后之后起算 20K-2K
- #define USER_FLASH_SIZE ((uint32_t)0x0000A800) /* Small default template application */
- /**
- * @brief Comm status structures definition
- */
- typedef enum
- {
- COM_OK = 0x00,
- COM_ERROR = 0x01,
- COM_ABORT = 0x02,
- COM_TIMEOUT = 0x03,
- COM_DATA = 0x04,
- COM_LIMIT = 0x05
- } COM_StatusTypeDef;
- /**
- * @}
- */
- /* Exported constants --------------------------------------------------------*/
- /* Exported macro ------------------------------------------------------------*/
- #define IS_CAP_LETTER(c) (((c) >= 'A') && ((c) <= 'F'))
- #define IS_LC_LETTER(c) (((c) >= 'a') && ((c) <= 'f'))
- #define IS_09(c) (((c) >= '0') && ((c) <= '9'))
- #define ISVALIDHEX(c) (IS_CAP_LETTER(c) || IS_LC_LETTER(c) || IS_09(c))
- #define ISVALIDDEC(c) IS_09(c)
- #define CONVERTDEC(c) (c - '0')
- #define CONVERTHEX_ALPHA(c) (IS_CAP_LETTER(c) ? ((c) - 'A'+10) : ((c) - 'a'+10))
- #define CONVERTHEX(c) (IS_09(c) ? ((c) - '0') : CONVERTHEX_ALPHA(c))
- /* Packet structure defines */
- #define PACKET_HEADER_SIZE ((uint32_t)3)
- #define PACKET_DATA_INDEX ((uint32_t)4)
- #define PACKET_START_INDEX ((uint32_t)1)
- #define PACKET_NUMBER_INDEX ((uint32_t)2)
- #define PACKET_CNUMBER_INDEX ((uint32_t)3)
- #define PACKET_TRAILER_SIZE ((uint32_t)2)
- #define PACKET_OVERHEAD_SIZE (PACKET_HEADER_SIZE + PACKET_TRAILER_SIZE-1)
- #define PACKET_SIZE ((uint32_t)128)
- #define PACKET_1K_SIZE ((uint32_t)1024)
- /* /-------- Packet in IAP memory ------------------------------------------\
- * | 0 | 1 | 2 | 3 | 4 | ... | n+4 | n+5 | n+6 |
- * |------------------------------------------------------------------------|
- * | unused | start | number | !num | data[0] | ... | data[n] | crc0 | crc1 |
- * \------------------------------------------------------------------------/
- * the first byte is left unused for memory alignment reasons */
- #define FILE_NAME_LENGTH ((uint32_t)64)
- #define FILE_SIZE_LENGTH ((uint32_t)16)
- #define SOH ((uint8_t)0x01) /* start of 128-byte data packet */
- #define STX ((uint8_t)0x02) /* start of 1024-byte data packet */
- #define EOT ((uint8_t)0x04) /* end of transmission */
- #define ACK ((uint8_t)0x06) /* acknowledge */
- #define NAK ((uint8_t)0x15) /* negative acknowledge */
- #define CA ((uint32_t)0x18) /* two of these in succession aborts transfer */
- #define CRC16 ((uint8_t)0x43) /* 'C' == 0x43, request 16-bit CRC */
- #define NEGATIVE_BYTE ((uint8_t)0xFF)
- #define ABORT1 ((uint8_t)0x41) /* 'A' == 0x41, abort by user */
- #define ABORT2 ((uint8_t)0x61) /* 'a' == 0x61, abort by user */
- #define NAK_TIMEOUT ((uint32_t)0x100000)
- #define DOWNLOAD_TIMEOUT ((uint32_t)3000) /* One second retry delay */
- #define MAX_ERRORS ((uint32_t)5)
- /* Exported functions ------------------------------------------------------- */
- COM_StatusTypeDef Ymodem_Receive(uint32_t *p_size);
- COM_StatusTypeDef Ymodem_Transmit(uint8_t *p_buf, const uint8_t *p_file_name, uint32_t file_size);
- HAL_StatusTypeDef Serial_PutByte(uint8_t param);
- #endif /* __YMODEM_H_ */
- /*******************(C)COPYRIGHT STMicroelectronics ********END OF FILE********/
|