262 lines
		
	
	
		
			8.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			262 lines
		
	
	
		
			8.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /****************************************************************************
 | |
| 
 | |
| Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | |
| 
 | |
| This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | |
| be copied by any method or incorporated into another program without
 | |
| the express written consent of Aerospace C.Power. This Information or any portion
 | |
| thereof remains the property of Aerospace C.Power. The Information contained herein
 | |
| is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | |
| liability for its use in any way and conveys no license or title under
 | |
| any patent or copyright and makes no representation or warranty that this
 | |
| Information is free from patent or copyright infringement.
 | |
| 
 | |
| ****************************************************************************/
 | |
| 
 | |
| #ifndef _VC_COMMANDS_H_
 | |
| #define _VC_COMMANDS_H_
 | |
| 
 | |
| /**
 | |
|  * @brief vc_cmd_cid_e - List of commands id.
 | |
|  * Request:
 | |
|  * VC_CID_REQUEST_STATUS - K68 get status of stm32.
 | |
|  * VC_CID_REQUEST_FW_INFO - K68 get firmware version of stm32.
 | |
|  * VC_CID_REQUEST_USB_ENA - K68 enable/disable USB port of stm32.
 | |
|  * VC_CID_REQUEST_STATISTIC - K68 get statistics of all channels on stm32.
 | |
|  * VC_CID_REQUEST_DEBUG_ENA - K68 enable/disable debug information of stm32.
 | |
| 
 | |
|  * Response:
 | |
|  * VC_CID_RESPONSE_STATUS - Stm32 response its status.
 | |
|  * VC_CID_RESPONSE_FW_INFO - Stm32 response version of frmware.
 | |
|  * VC_CID_RESPONSE_USB_ENA - Stm32 response the enable/disable status of USB port.
 | |
|  * VC_CID_RESPONSE_STATISTIC - Stm32 response the statistics of all channels.
 | |
|  * VC_CID_RESPONSE_STATUS - Stm32 response the enable/disable status of debug.
 | |
|  * VC_CID_RESPONSE_DEBUG_REPT - Stm32 report the debug information.
 | |
|  */
 | |
| typedef enum _vc_command_id_list_e_ {
 | |
|     VC_CID_REQUEST_STATUS       = 0x00,
 | |
|     VC_CID_REQUEST_FW_INFO      = 0x01,
 | |
|     VC_CID_REQUEST_USB_ENA      = 0x02,
 | |
|     VC_CID_REQUEST_STATISTIC    = 0x03,
 | |
|     VC_CID_REQUEST_DEBUG_ENA    = 0x7D,
 | |
| 
 | |
|     VC_CID_RESPONSE_STATUS      = 0x80,
 | |
|     VC_CID_RESPONSE_FW_INFO     = 0x81,
 | |
|     VC_CID_RESPONSE_USB_ENA     = 0x82,
 | |
|     VC_CID_RESPONSE_STATISTIC   = 0x83,
 | |
|     VC_CID_RESPONSE_DEBUG_ENA   = 0xFD,
 | |
|     VC_CID_RESPONSE_DEBUG_REPT  = 0xFE,
 | |
| 
 | |
|     VC_CID_INVALID              = 0xFF
 | |
| } vc_cmd_cid_e;
 | |
| 
 | |
| /**
 | |
|  * @brief vc_cmd_resp_status_ready_e - Bitmap of response status.
 | |
|  * VC_RESP_STATUS_READY_USB - USB port is ready for transceiving.
 | |
|  * No inner error & device enabled.
 | |
|  * VC_RESP_STATUS_READY_UART - UART port is ready for transceiving.
 | |
|  * VC_RESP_STATUS_READY_SPI - SPI port is ready for transceiving.
 | |
|  */
 | |
| typedef enum _vc_command_response_status_bitmap_ready_list_e_ {
 | |
|     VC_RESP_STATUS_READY_USB    = 0x01,
 | |
|     VC_RESP_STATUS_READY_UART   = 0x02,
 | |
|     VC_RESP_STATUS_READY_SPI    = 0x04
 | |
| } vc_cmd_resp_status_ready_e;
 | |
| 
 | |
| /**
 | |
|  * @brief vc_cmd_resp_status_error_e - Bitmap of response status.
 | |
|  * VC_RESP_STATUS_ERROR_USB_FAULT - USB port has inner error on stm32.
 | |
|  * VC_RESP_STATUS_ERROR_OTHER_FAULT - Stm32 has other errors.
 | |
|  */
 | |
| typedef enum _vc_command_response_status_bitmap_error_list_e_ {
 | |
|     VC_RESP_STATUS_ERROR_USB_FAULT      = 0x01,
 | |
|     VC_RESP_STATUS_ERROR_OTHER_FAULT    = 0x02
 | |
| } vc_cmd_resp_status_error_e;
 | |
| 
 | |
| /**
 | |
|  * @brief VC_COMMAND_PRECODE - Fix pre-code as 0xAA AA.
 | |
|  */
 | |
| #define VC_COMMAND_PRECODE              0xAAAA
 | |
| 
 | |
| /**
 | |
|  * @brief VC_COMMAND_PSTCODE - Fix pre-code as 0xFF.
 | |
|  */
 | |
| #define VC_COMMAND_PSTCODE              0xFF
 | |
| 
 | |
| /**
 | |
|  * @brief VC_COMMAND_FRAME_BREAK_TIMEOUT - Frame break time, in ms.
 | |
|  */
 | |
| #define VC_COMMAND_FRAME_BREAK_TIMEOUT   500
 | |
| 
 | |
| #pragma pack(push)  /* save the pack status */
 | |
| #pragma pack(1)     /* 1 byte align */
 | |
| 
 | |
| /**
 | |
|  * @brief vc_cmd_header_t - Header of virtual channel frame.
 | |
|  */
 | |
| typedef struct _vc_command_frame_header_t_ {
 | |
|     uint16_t pre_code;      /* Pre-code, fixed as 0xAAAA */
 | |
|     uint8_t channel;        /* Channel number. */
 | |
|     uint8_t reserved;        /* Reserved, keep 0. */
 | |
|     uint16_t sequnce;       /* Sequnce of frames. 0 ~ 65535. */
 | |
|     uint16_t data_length;   /* Length of data section. */
 | |
|     union {
 | |
|         uint8_t  data[0];   /* If channel is not 0, the data section hold data. */
 | |
|         uint8_t  fn[0];     /* If channel is 0, the data section hold command. */
 | |
|     };
 | |
| } vc_cmd_header_t;
 | |
| 
 | |
| /**
 | |
|  * @brief vc_cmd_tail_t - Tail of virtual channel frame.
 | |
|  */
 | |
| typedef struct _vc_command_frame_tail_t_ {
 | |
|     uint16_t crc16;         /* CRC16, from "channel" to end of data. */
 | |
|     uint8_t  pst_code;      /* Post-code, fixed as 0xFF. */
 | |
| } vc_cmd_tail_t;
 | |
| 
 | |
| /**
 | |
|  * @brief VC_COMMAND_FRAME_HEADER_LENGTH - Length of header.
 | |
|  */
 | |
| #define VC_COMMAND_FRAME_HEADER_LENGTH  sizeof(vc_cmd_header_t)
 | |
| 
 | |
| /**
 | |
|  * @brief VC_COMMAND_PSTCODE - Fix pre-code as 0xFF.
 | |
|  */
 | |
| #define VC_COMMAND_FRAME_TAIL_LENGTH     sizeof(vc_cmd_tail_t)
 | |
| 
 | |
| /**
 | |
|  * @brief VC_COMMAND_MAX_PAYLOAD_LENGTH - Max length of payload in frame.
 | |
|  */
 | |
| #define VC_COMMAND_MAX_PAYLOAD_LENGTH    (2048)
 | |
| 
 | |
| /**
 | |
|  * @brief VC_COMMAND_MAX_FRAME_LENGTH - Max length of frame in bytes.
 | |
|  */
 | |
| #define VC_COMMAND_MAX_FRAME_LENGTH     ( VC_COMMAND_MAX_PAYLOAD_LENGTH + \
 | |
|     VC_COMMAND_FRAME_HEADER_LENGTH + VC_COMMAND_FRAME_TAIL_LENGTH)
 | |
| 
 | |
| /**
 | |
|  * @brief VC_COMMAND_MIN_FRAME_LENGTH - Mib length of frame in bytes.
 | |
|  */
 | |
| #define VC_COMMAND_MIN_FRAME_LENGTH      \
 | |
|     (VC_COMMAND_FRAME_HEADER_LENGTH + VC_COMMAND_FRAME_TAIL_LENGTH)
 | |
| 
 | |
| #define VC_COMMAND_CRC_LENGTH_IN_HEAD   \
 | |
|     (sizeof(vc_cmd_header_t) - (int)&((vc_cmd_header_t *)0)->channel)
 | |
| /**
 | |
|  * @brief vc_cmd_req_status_t - K68 query the status of stm32.
 | |
|  */
 | |
| typedef struct _vc_command_request_status_t_ {
 | |
|     uint8_t fn; /* 0x00 */
 | |
| } vc_cmd_req_status_t;
 | |
| 
 | |
|  /**
 | |
|   * @brief vc_cmd_res_status_t - Stm32 response the status.
 | |
|   * See vc_cmd_resp_status_ready_e & vc_cmd_resp_status_error_e
 | |
|   */
 | |
| typedef struct _vc_command_response_status_t_ {
 | |
|     uint8_t fn; /* 0x80 */
 | |
|     uint8_t bitmap_ready;
 | |
|     uint8_t bitmap_error;
 | |
| } vc_cmd_res_status_t;
 | |
| 
 | |
| /**
 | |
|  * @brief vc_cmd_req_fw_ver_t - K68 query the version of stm32 firmware.
 | |
|  */
 | |
| typedef struct _vc_command_request_frimware_version_t_ {
 | |
|     uint8_t fn; /* 0x01 */
 | |
|  } vc_cmd_req_fw_ver_t;
 | |
| 
 | |
| /**
 | |
|  * @brief vc_cmd_res_fw_ver_t - Stm32 response the firmware version.
 | |
|  */
 | |
| typedef struct _vc_command_response_frimware_version_t_ {
 | |
|    uint8_t fn; /* 0x81 */
 | |
|    uint32_t version;
 | |
|    uint32_t length;
 | |
|    uint32_t crc32;
 | |
| } vc_cmd_res_fw_ver_t;
 | |
| 
 | |
| /**
 | |
|  * @brief vc_cmd_req_usb_ena_t - K68 set the ability of stm32 USB port.
 | |
|  */
 | |
| typedef struct _vc_command_request_usb_enable_t_ {
 | |
|     uint8_t fn; /* 0x02 */
 | |
|     uint8_t enable;
 | |
| } vc_cmd_req_usb_ena_t;
 | |
| 
 | |
| /**
 | |
|  * @brief vc_cmd_res_usb_ena_t - Stm32 response the ability of USB port.
 | |
|  */
 | |
| typedef struct _vc_command_response_usb_enable_t_ {
 | |
|     uint8_t fn; /* 0x82 */
 | |
|     uint8_t enable;
 | |
| } vc_cmd_res_usb_ena_t;
 | |
| 
 | |
| /**
 | |
|  * @brief vc_cmd_req_statistic_t - K68 set the statistics of stm32.
 | |
|  */
 | |
| typedef struct _vc_command_request_statistics_t_ {
 | |
|     uint8_t fn; /* 0x03 */
 | |
| } vc_cmd_req_statistic_t;
 | |
| 
 | |
| /**
 | |
|  * @brief vc_cmd_res_statistics_t - Stm32 response the statistics
 | |
|  * of all channels.
 | |
|  */
 | |
| typedef struct _vc_command_channel_statistic_t_ {
 | |
|     uint32_t tx_frames; /* Total frames of data stm32 sent in the channel. */
 | |
|     uint32_t tx_bytes;  /* Total bytes of data stm32 sent in the channel. */
 | |
|     uint32_t rx_frames; /* Total frames of data stm32 received in the channel. */
 | |
|     uint32_t rx_bytes;  /* Total bytes of data stm32 received in the channel. */
 | |
| } vc_cmd_chn_statistic_t;
 | |
| 
 | |
| typedef struct _vc_command_response_statistics_t_ {
 | |
|     uint8_t fn; /* 0x83 */
 | |
|     uint8_t chn_cnt;
 | |
|     vc_cmd_chn_statistic_t statistic[0];
 | |
| } vc_cmd_res_statistics_t;
 | |
| 
 | |
| #define vc_get_channel_bitmap(chn, bmap)    \
 | |
|     (((bmap) & (1 << (chn))) ? 1 : 0)
 | |
| 
 | |
| #define vc_set_channel_bitmap(chn, bmap, ena)    \
 | |
|     do { \
 | |
|         if (ena) { \
 | |
|             (bmap) |= (1 << (chn)); \
 | |
|         } else { \
 | |
|             (bmap) &= ~(1 << (chn)); \
 | |
|         } \
 | |
|     } while(0)
 | |
| 
 | |
| /**
 | |
|  * @brief vc_cmd_req_chn_dbg_t - K68 set the statistics of stm32.
 | |
|  */
 | |
| typedef struct _vc_command_request_channel_debug_t_ {
 | |
|     uint8_t fn; /* 0x7E */
 | |
|     uint32_t bitmap_channel; /* bitmap as : vc_get_channel_bitmap(channel). */
 | |
| } vc_cmd_req_chn_dbg_t;
 | |
| 
 | |
| /**
 | |
|  * @brief vc_cmd_res_chn_dbg_t - Stm32 response the statistics status.
 | |
|  */
 | |
| typedef struct _vc_command_response_channel_debug_t_ {
 | |
|     uint8_t fn; /* 0xFE */
 | |
|     uint32_t bitmap_channel; /* bitmap as : vc_get_channel_bitmap(channel). */
 | |
| } vc_cmd_res_chn_dbg_t;
 | |
| 
 | |
| /**
 | |
|  * @brief vc_cmd_res_chn_dbg_str_t - Stm32 reports the debug
 | |
|  * information to k68
 | |
|  * without requesting.
 | |
|  */
 | |
| typedef struct _vc_command_response_channel_debug_string_t_ {
 | |
|     uint8_t fn; /* 0xFF */
 | |
|     uint16_t str_len;
 | |
|     uint8_t str_data[0]; /* printf string. */
 | |
| } vc_cmd_res_chn_dbg_str_t;
 | |
| 
 | |
| #pragma pack(pop)   /* restore the pack status */
 | |
| 
 | |
| #endif /* _VC_COMMANDS_H_ */
 |