/** @file spi_demo.h @brief This file is used to define bt demo for different Quectel Project. */ /*================================================================ Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved. Quectel Wireless Solution Proprietary and Confidential. =================================================================*/ /*================================================================= EDIT HISTORY FOR MODULE This section contains comments describing changes made to the module. Notice that changes are listed in reverse chronological order. WHEN WHO WHAT, WHERE, WHY ------------ ------- ------------------------------------------------------------------------------- =================================================================*/ #ifndef SPI_DEMO_H #define SPI_DEMO_H #ifdef __cplusplus extern "C" { #endif #define APP_A_ADDR (0x8000) #define BOOT_INFO_ADDR (0x3c000) #define DATA_LENTH (512) #define FRAME_HEAD (0X5A) #define DATA_HEAD (0X5A) #define FRAME_TAIL (0XA5) #define MPU_ADDR (0X10) #define MCU_ADDR (0X20) #define MASTER_CMD (0X50) #define SLAVE_CMD_ACK (0X5C) #define SLAVE_CMD_NACK (0X5F) #define MASTER_CTR (0X60) #define SLAVE_CTR_ACK (0X6C) #define SLAVE_CTR_NACK (0X6F) #define SPI_BUF_LEN (512) /*======================================================================== * Variable Definition *========================================================================*/ #define SPI_DEMO_TASK_PRIO 12 #define SPI_DEMO_TASK_STACK_SIZE 8*1024 #define SPI_DEMO_TASK_EVENT_CNT 4 #include "ql_api_spi.h" /*======================================================================== * function Definition *========================================================================*/ QlOSStatus ql_spi_demo_init(void); #pragma pack(1) /* 固定开头帧 */ typedef struct { uint8_t frame_head; uint16_t data_lenth; uint8_t source_addr; uint8_t destination_addr; uint8_t cmd; uint8_t cmd_type; }frame_pack_t;// --- 7 /* 固定帧各字节顺序*/ enum { FRAME_HEAD_INDEX = 0, FRAME_LEN_INDEX, FRAME_SOUADDR_INDEX = 3, FRAME_DETADDR_INDEX, FRAME_CMD_INDEX, FRAME_CMD_TYPE_INDEX, }; /***********-- --- --0X01 查询-- --- --***********/ #define TEMP_NUMBER (15) /*设备状态*/ typedef struct { uint8_t work_status; uint8_t temperatures_number; int8_t temperatures_data[TEMP_NUMBER]; uint8_t backup_voltage; uint8_t backup_temperature; uint8_t high_driver_number; uint8_t high_driver_status;//最大8路 bit uint8_t low_driver_number; uint8_t low_driver_status; //最大8路 bit uint8_t last_wake_up_source; uint8_t location_status; }cmd_05_01_device_status_t; /*定位信息*/ typedef struct { uint8_t locate_mark; //֨定位标志 uint8_t satellite_num;//卫星数量 uint8_t direction[2]; //方位 uint8_t speed[2]; //̙速度 uint8_t altitude[2]; //海拔 uint8_t latitude[4]; //纬度 uint8_t longitude[4]; //经度 uint8_t accmileage[4];// } gps_info_t; /***********-- --- --0X03 查询-- --- --***********/ /*通讯数据*/ typedef struct { uint16_t x_data; uint16_t y_data; uint16_t z_data; uint8_t can0_data_status; uint8_t can0_fault_status; uint16_t can0_data_lenth; uint8_t can0_data[16]; uint8_t can1_data_status; uint8_t can1_fault_status; uint16_t can1_data_lenth; uint8_t can1_data[16]; uint8_t rs485_data_status; uint16_t rs485_data_lenth; uint8_t rs485_data[128]; }cmd_05_03_communication_data_t; /**0X60*/ /***********控制****************/ /*输出控制*/ #define PWM_NUM_CONFIG 2 typedef struct { uint8_t output_number;//最大8路 uint8_t output_control;//bit uint16_t pwm_number; uint8_t pwm_data[PWM_NUM_CONFIG][3];//PWM_NUM_CONFIG路PWM 频率2bytes,占空比1byte }output_control_t; /*休眠控制*/ typedef struct { uint8_t control_type; uint16_t sleep_time; //s }sleep_control_t; /*通讯控制*/ typedef struct { uint8_t can_send_data_type; uint32_t can_send_data_lenth; uint8_t can_send_data[13]; uint8_t rs485_send_data_type; uint32_t rs485_send_data_lenth; uint8_t rs485_send_data[256]; }communication_control_t; #pragma pack() void spi_dma_write_hc(ql_spi_port_e spi_port, uint8_t *pbuf, uint32 len, ql_spi_clk_e spiclk); void spi_dma_read_hc(ql_spi_port_e spi_port, uint8_t *pbuf, uint32 len, ql_spi_clk_e spiclk); unsigned short crc16_modbus(unsigned char *pdata, int len); 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); 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); uint16_t Full_Frame_Verifi(uint8_t *srcdata, uint16_t srcLen, uint16_t* frame_start); void creat_software_crc16(int fd, uint16_t *cur_crc); #ifdef __cplusplus } /*"C" */ #endif #endif /* SPI_DEMO_H */