ymodem.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef __YMODEM_H__
  2. #define __YMODEM_H__
  3. /*******************************************************************************************************/
  4. #include "type.h"
  5. #define YMODEM_BUFF_LEN (3 + 1024 + 2 + 1)
  6. /* 数据包大小. */
  7. #define YMODEM_PACKET_128_SIZE (128)
  8. #define YMODEM_PACKET_1024_SIZE (1024)
  9. #define YMODEM_PACKET_CRC_SIZE (2)
  10. /* 协议定义的字节. */
  11. #define YMODEM_SOH (1) /**< 包头 (128 bytes). */
  12. #define YMODEM_STX (2) /**< 包头 (1024 bytes). */
  13. #define YMODEM_EOT (4) /**< 传输结束. */
  14. #define YMODEM_ACK (6) /**< 应答. */
  15. #define YMODEM_NAK (0x15) /**< 非应答. */
  16. #define YMODEM_CAN (0x18) /**< 取消. */
  17. #define YMODEM_C (0x43) /**< ASCII“C”,要通知上位机,我们要用CRC16. */
  18. /*******************************************************************************************************/
  19. //接收缓冲区
  20. typedef struct
  21. {
  22. uint8 buff[YMODEM_BUFF_LEN];
  23. uint16 num; //数据计数器
  24. uint16 len; //数据包长度
  25. uint8 tmout_cunt;
  26. uint8 tmout_t;
  27. } ymodem_buff_stk;
  28. //数据帧格式定义
  29. typedef union
  30. {
  31. uint8 array[YMODEM_BUFF_LEN];
  32. struct
  33. {
  34. uint8 h1;
  35. uint8 sn;
  36. uint8 sn_c;
  37. uint8 dat[1];
  38. uint8 crc_h;
  39. uint8 crc_l;
  40. }stk;
  41. }ymodem_frame_stk;
  42. //传输上下文
  43. typedef struct
  44. {
  45. uint8 task_ps;
  46. uint8 comm_tmout;
  47. uint8 eot_num;
  48. uint16 pkgs_num;
  49. int flash_partition;
  50. uint32 file_size;
  51. uint32 file_offset;
  52. }ymodem_context_stk;
  53. /*******************************************************************************************************/
  54. void ymodem_start(void *arg);
  55. void ymodem_task(void);
  56. #endif
  57. /*******************************************************************************************************
  58. ** End Of File
  59. ********************************************************************************************************/