protocol.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. ******************************************************************************
  3. * @file eeprom.h
  4. * @author Vincent
  5. * @version V1.0.0
  6. * @date 23-12-2015
  7. * @brief AT24C02 eeprom read and write function.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __PROTOCOL_H__
  39. #define __PROTOCOL_H__
  40. /* Includes ------------------------------------------------------------------*/
  41. //#include "stm32f3xx_hal.h"
  42. /* Define to variables declare---------------------------------------------------*/
  43. //通信协议命令字
  44. //#ifdef HEAD1
  45. //#define PRO_HEAD1 HEAD1
  46. //#else
  47. //#define PRO_HEAD1 1
  48. //#endif
  49. //#ifdef HEAD1
  50. //#define PRO_HEAD2 HEAD2
  51. //#else
  52. //#define PRO_HEAD2 2
  53. //#endif
  54. #define FRAME_HEAD1 0x55
  55. #define FRAME_HEAD2 0xAA
  56. #define PRO_HEAD1 0x55
  57. #define PRO_HEAD2 0xAA
  58. #define PRO_TAIL 0xF0 //帧尾
  59. #define FRAME_MODE_WRITE 0x16
  60. #define FILE_HEAD 0x01 //文件头
  61. #define FILE_BODY 0x02 //文件体
  62. #define FILE_TAIL 0x03 //文件体
  63. #define CMD_UPDATA 0xA10B
  64. #define CMD_PACKAGE_INFO 0xA204
  65. #define CMD_PACKAGE_DATA 0xA385
  66. #define CMD_UPDATA_END 0xA401
  67. #define CMD_BOOT_INFO 0xC109
  68. #define CMD_ACK_OK 0xC202
  69. #define CMD_ACK_ERR 0xC302
  70. #define CMD_ACK_REQ 0xC402
  71. #define CMD_ACK_EOT 0xC502
  72. #define CMD_ACK_ERR_FLASH 0xC602
  73. #define ACK_OK 0x06 //应答确认
  74. #define ACK_ERROR 0x15 //文件错误
  75. #define MODEM_CANCLE 0x18 //取消传输
  76. #define ACK_REQ 0x43 //请求传输
  77. #define PACKET_128B_SIZE ((uint8_t)128)
  78. #define PACKET_1K_SIZE ((uint16_t)1024)
  79. #define PACKET_128B_TOTAL_SIZE (PACKET_128B_SIZE+PACKET_OVERHEAD)
  80. #define PACKET_1K_TOTAL_SIZE (PACKET_1K_SIZE+PACKET_OVERHEAD)
  81. #define FRAME_HEAD ((uint8_t)6)
  82. #define FRAME_TRAIL ((uint8_t)5)
  83. #define FRAME_HEAD_TRAIL (FRAME_HEAD + FRAME_TRAIL)
  84. #define PACKAGE_DATA_HEAD ((uint8_t)5)
  85. #define FRAME_DATA_SIZE (PACKET_128B_SIZE + PACKAGE_DATA_HEAD + FRAME_HEAD_TRAIL)
  86. /**************************************************************************/
  87. #define FILE_HEAD 0x01 //文件头
  88. #define FILE_BODY 0x02 //文件体
  89. #define FILE_TAIL 0x03 //文件体
  90. #define ACK_OK 0x06 //应答确认
  91. #define ACK_ERROR 0x15 //文件错误
  92. #define MODEM_CANCLE 0x18 //取消传输
  93. #define ACK_REQ 0x43 //请求传输
  94. #define PACKET_HEADER ((uint8_t)5)
  95. #define PACKET_TRAILER ((uint8_t)3)
  96. #define PACKET_OVERHEAD (PACKET_HEADER + PACKET_TRAILER)
  97. #define PACKET_128B_SIZE ((uint8_t)128)
  98. #define PACKET_1K_SIZE ((uint16_t)1024)
  99. #define PACKET_128B_TOTAL_SIZE (PACKET_128B_SIZE+PACKET_OVERHEAD)
  100. #define PACKET_1K_TOTAL_SIZE (PACKET_1K_SIZE+PACKET_OVERHEAD)
  101. /*************************************************************************/
  102. /* Private variables declare---------------------------------------------------*/
  103. extern uint16_t __CC(uint8_t* ucDataBuf,uint32_t size);
  104. /*Private function declare---------------------------------------------------*/
  105. #endif /*__PROTOCOL_H__ */
  106. /*---------------------------- file end -------------------------------------*/