spi_demo.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /** @file
  2. spi_demo.h
  3. @brief
  4. This file is used to define bt demo for different Quectel Project.
  5. */
  6. /*================================================================
  7. Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  8. Quectel Wireless Solution Proprietary and Confidential.
  9. =================================================================*/
  10. /*=================================================================
  11. EDIT HISTORY FOR MODULE
  12. This section contains comments describing changes made to the module.
  13. Notice that changes are listed in reverse chronological order.
  14. WHEN WHO WHAT, WHERE, WHY
  15. ------------ ------- -------------------------------------------------------------------------------
  16. =================================================================*/
  17. #ifndef SPI_DEMO_H
  18. #define SPI_DEMO_H
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #define APP_A_ADDR (0x8000)
  23. #define BOOT_INFO_ADDR (0x3c000)
  24. #define DATA_LENTH (512)
  25. #define FRAME_HEAD (0X5A)
  26. #define DATA_HEAD (0X5A)
  27. #define FRAME_TAIL (0XA5)
  28. #define MPU_ADDR (0X10)
  29. #define MCU_ADDR (0X20)
  30. #define MASTER_CMD (0X50)
  31. #define SLAVE_CMD_ACK (0X5C)
  32. #define SLAVE_CMD_NACK (0X5F)
  33. #define MASTER_CTR (0X60)
  34. #define SLAVE_CTR_ACK (0X6C)
  35. #define SLAVE_CTR_NACK (0X6F)
  36. #define SPI_BUF_LEN (512)
  37. /*========================================================================
  38. * Variable Definition
  39. *========================================================================*/
  40. #define SPI_DEMO_TASK_PRIO 12
  41. #define SPI_DEMO_TASK_STACK_SIZE 8*1024
  42. #define SPI_DEMO_TASK_EVENT_CNT 4
  43. #include "ql_api_spi.h"
  44. /*========================================================================
  45. * function Definition
  46. *========================================================================*/
  47. QlOSStatus ql_spi_demo_init(void);
  48. #pragma pack(1)
  49. /* 固定开头帧 */
  50. typedef struct
  51. {
  52. uint8_t frame_head;
  53. uint16_t data_lenth;
  54. uint8_t source_addr;
  55. uint8_t destination_addr;
  56. uint8_t cmd;
  57. uint8_t cmd_type;
  58. }frame_pack_t;// --- 7
  59. /* 固定帧各字节顺序*/
  60. enum
  61. {
  62. FRAME_HEAD_INDEX = 0,
  63. FRAME_LEN_INDEX,
  64. FRAME_SOUADDR_INDEX = 3,
  65. FRAME_DETADDR_INDEX,
  66. FRAME_CMD_INDEX,
  67. FRAME_CMD_TYPE_INDEX,
  68. };
  69. /***********-- --- --0X01 查询-- --- --***********/
  70. #define TEMP_NUMBER (15)
  71. /*设备状态*/
  72. typedef struct
  73. {
  74. uint8_t work_status;
  75. uint8_t temperatures_number;
  76. int8_t temperatures_data[TEMP_NUMBER];
  77. uint8_t backup_voltage;
  78. uint8_t backup_temperature;
  79. uint8_t high_driver_number;
  80. uint8_t high_driver_status;//最大8路 bit
  81. uint8_t low_driver_number;
  82. uint8_t low_driver_status; //最大8路 bit
  83. uint8_t last_wake_up_source;
  84. uint8_t location_status;
  85. }cmd_05_01_device_status_t;
  86. /*定位信息*/
  87. typedef struct
  88. {
  89. uint8_t locate_mark; //֨定位标志
  90. uint8_t satellite_num;//卫星数量
  91. uint8_t direction[2]; //方位
  92. uint8_t speed[2]; //̙速度
  93. uint8_t altitude[2]; //海拔
  94. uint8_t latitude[4]; //纬度
  95. uint8_t longitude[4]; //经度
  96. uint8_t accmileage[4];//
  97. } gps_info_t;
  98. /***********-- --- --0X03 查询-- --- --***********/
  99. /*通讯数据*/
  100. typedef struct
  101. {
  102. uint16_t x_data;
  103. uint16_t y_data;
  104. uint16_t z_data;
  105. uint8_t can0_data_status;
  106. uint8_t can0_fault_status;
  107. uint16_t can0_data_lenth;
  108. uint8_t can0_data[16];
  109. uint8_t can1_data_status;
  110. uint8_t can1_fault_status;
  111. uint16_t can1_data_lenth;
  112. uint8_t can1_data[16];
  113. uint8_t rs485_data_status;
  114. uint16_t rs485_data_lenth;
  115. uint8_t rs485_data[128];
  116. }cmd_05_03_communication_data_t;
  117. /**0X60*/
  118. /***********控制****************/
  119. /*输出控制*/
  120. #define PWM_NUM_CONFIG 2
  121. typedef struct
  122. {
  123. uint8_t output_number;//最大8路
  124. uint8_t output_control;//bit
  125. uint16_t pwm_number;
  126. uint8_t pwm_data[PWM_NUM_CONFIG][3];//PWM_NUM_CONFIG路PWM 频率2bytes,占空比1byte
  127. }output_control_t;
  128. /*休眠控制*/
  129. typedef struct
  130. {
  131. uint8_t control_type;
  132. uint16_t sleep_time; //s
  133. }sleep_control_t;
  134. /*通讯控制*/
  135. typedef struct
  136. {
  137. uint8_t can_send_data_type;
  138. uint32_t can_send_data_lenth;
  139. uint8_t can_send_data[13];
  140. uint8_t rs485_send_data_type;
  141. uint32_t rs485_send_data_lenth;
  142. uint8_t rs485_send_data[256];
  143. }communication_control_t;
  144. #pragma pack()
  145. void spi_dma_write_hc(ql_spi_port_e spi_port, uint8_t *pbuf, uint32 len, ql_spi_clk_e spiclk);
  146. void spi_dma_read_hc(ql_spi_port_e spi_port, uint8_t *pbuf, uint32 len, ql_spi_clk_e spiclk);
  147. unsigned short crc16_modbus(unsigned char *pdata, int len);
  148. uint16_t data_decode_mpu(uint8_t *input_data, uint16_t input_data_len, uint8_t* output, uint16_t* output_data_len, ql_spi_clk_e spiclk);
  149. uint8_t data_mpu_pack(uint8_t* output, uint16_t* output_data_len, uint8_t cmd, uint8_t cmd_type, ql_spi_clk_e spiclk);
  150. uint16_t Full_Frame_Verifi(uint8_t *srcdata, uint16_t srcLen, uint16_t* frame_start);
  151. void creat_software_crc16(int fd, uint16_t *cur_crc);
  152. #ifdef __cplusplus
  153. } /*"C" */
  154. #endif
  155. #endif /* SPI_DEMO_H */