Files
kunlun/driver/extern/virtualchannel/inc/vc_task_api.h
2024-09-28 14:24:04 +08:00

341 lines
10 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_TASK_API_H_
#define _VC_TASK_API_H_
#include "os_types.h"
#include "iot_pkt_api.h"
/**
* @brief vc_chn_id_e - List of channels ID.
*/
typedef enum _virtual_channel_id_e_ {
VC_CHNID_0 = 0,
VC_CHNID_1,
VC_CHNID_2,
VC_CHNID_3,
VC_CHNID_MAX
} vc_chn_id_e;
/**
* @brief vc_drv_id_e - List of channels ID.
*/
typedef enum _virtual_channel_driver_id_e_ {
VC_DRVID_UART = 0,
VC_DRVID_SPI,
VC_DRVID_MAX
} vc_drv_id_e;
/**
* @brief vc_chn_rcv_func - Function pointer to get received data from channel.
* @param chn: Virtual channel port that received data.
* @param pkt: Pointer to a packet holding data received.
* @return Bytes of data that confirmed by this function.
*/
typedef uint32_t (*vc_chn_rcv_func)(vc_chn_id_e chn, iot_pkt_t *pkt);
/**
* @brief vc_sts_bitmap_stm32_e - List of STM32 status.
* VC_STS_SLV_READY - STM32 is ready to transmit & receive data.
* VC_STS_SLV_UPGRADING - STM32 is in ungrading.
* VC_STS_SLV_NO_RESPONSE - STM32 has no response for requesting from KL.
* VC_STS_SLV_USB_STOPPED - USB port on STM32 is not enabled.
* VC_STS_SLV_FIRMWARE_ERROR - STM32 has a wrong version or CRC failed FW.
* VC_STS_SLV_OTHER_ERROR - Other error like uart port fault in STM32.
*/
typedef enum _virtual_channel_status_stm32_e_ {
VC_STS_SLV_READY = 0x01,
VC_STS_SLV_UPGRADING = 0x02,
VC_STS_SLV_NO_RESPONSE = 0x04,
VC_STS_SLV_USB_STOPPED = 0x08,
VC_STS_SLV_FIRMWARE_ERROR = 0x10,
VC_STS_SLV_OTHER_ERROR = 0x800000000
} vc_sts_bitmap_stm32_e;
/**
* @brief vc_sts_bitmap_k68_e - List of Kunlun status.
*/
typedef enum _virtual_channel_status_k68_e_ {
VC_STS_HST_READY = 0x01,
VC_STS_HST_INIT_FAILED = 0x02,
VC_STS_HST_OTHER_ERROR = 0x800000000
} vc_sts_bitmap_k68_e;
/**
* @brief vc_fw_ver_t - The firmware version of stm32.
*/
typedef struct _virtual_channel_frimware_version_t_ {
uint32_t version;
uint32_t length;
uint32_t crc32;
} vc_fw_ver_t;
/**
* @brief vc_dev_status_t - Status of this module, include k68(KUNLUN)
* and stm32(STM32).
*/
typedef struct _virtual_channel_device_status_t_ {
uint32_t stm32; /* Bitmap, see vc_sts_bitmap_stm32_e */
uint32_t k68; /* Bitmap, see vc_sts_bitmap_k68_e */
} vc_dev_status_t;
/**
* @brief vc_channel_info_t - Information of channel.
*/
typedef struct _virtual_channel_channel_info_t_ {
uint32_t channel;
uint32_t tx_buffer_size;
uint32_t rx_buffer_size;
/* TODO */
} vc_channel_info_t;
/**
* @brief vc_info_t - Information of this module.
*/
typedef struct _virtual_channel_device_info_t_ {
vc_channel_info_t chn[VC_CHNID_MAX];
} vc_info_t;
/**
* @brief vc_point_statistic_t - Statistic of one point on one direction.
*/
typedef struct _virtual_channel_point_statistic_t_ {
uint32_t frames;
uint32_t bytes;
} vc_point_statistic_t;
/**
* @brief vc_line_statistic_t - Statistic of one end/terminal on two directions.
*/
typedef struct _virtual_channel_end_statistic_t_ {
vc_point_statistic_t sent;
vc_point_statistic_t recvd;
} vc_end_statistic_t;
/**
* @brief vc_chn_statistic_t - Statistic of four points on bi-direction.
*/
typedef struct _virtual_channel_channel_statistic_t_ {
/* Stm32 -> k68 */
vc_end_statistic_t k68;
/* K68 -> stm32 */
vc_end_statistic_t stm32;
} vc_chn_statistic_t;
/**
* @brief vc_upgrd_state_e - State of STM32 in upgrading.
*/
typedef enum _virtual_channel_upgrade_state_e_ {
/* STM32 not in upgrading state. */
VC_UPGRD_STATE_IDLE = 0,
/* STM32 is clearing flash of the last 256bytes. */
VC_UPGRD_STATE_CLEAR_STORAGE_HEADER,
/* STM32 is clearing flash of the fw file. */
VC_UPGRD_STATE_CLEAR_STORAGE,
/* STM32 is writing its firmware header.*/
VC_UPGRD_STATE_WRITE_HEADER,
/* STM32 is writing its firmware.*/
VC_UPGRD_STATE_WRITE_DATA,
/* STM32 finishes upgrading succseefully.*/
VC_UPGRD_STATE_ENDUP,
/* Error occors while upgrading. Need send STOP cmd to reset the state. */
VC_UPGRD_STATE_ERR,
} vc_upgrd_state_e;
/**
* @brief vc_cmd_e - Commands to vc-task from app.
*/
typedef enum _virtual_channel_command_e_ {
/* Get status of stm32. Remote query stm32. */
VC_CMD_GET_STM32_STATUS = 0,
/* Get info. of stm32-fw. Remote query stm32. */
VC_CMD_GET_STM32_FW_INFO,
/* Set enable/disable of usb on stm32 side. Remote query stm32. */
VC_CMD_SET_STM32_USB,
/* Get statistics of K68 & stm32. Remote query stm32. */
VC_CMD_GET_STATISTICS,
/* Set debug log from stm32 printf on k68. Remote query stm32. */
VC_CMD_SET_STM32_DBG_LOG,
/* Start upgrading stm32. Local query K68. */
VC_CMD_START_UPGD,
/* Stop upgrading stm32. Local query K68. */
VC_CMD_STOP_UPGD,
/* Get info. of upgrading stm32. Local query K68. */
VC_CMD_GET_UPGD_INFO,
VC_CMD_MAX
}vc_cmd_e;
/**
* @brief vc_cmd_t - Top structure of command to vc-task from app.
*/
typedef struct _virtual_channel_command_t_ {
/* See vc_cmd_e. */
uint8_t cmd;
/* Reserved byte, keep 0. */
uint8_t rsv[1];
/* Length of payload. */
uint16_t payload_len;
/* Structure of command. */
uint8_t payload[0];
}vc_cmd_t;
/**
* @brief vc_cmd_set_usb_t - Structure of command VC_CMD_SET_STM32_USB.
*/
typedef struct _virtual_channel_command_set_usb_t {
/* 0 : disable usb. 1 : enable usb. */
uint8_t enable;
/* Reserved byte, keep 0. */
uint8_t rsv[3];
}vc_cmd_set_usb_t;
/**
* @brief vc_cmd_set_dbg_log_t - Structure of command VC_CMD_SET_STM32_DBG_LOG.
*/
typedef struct _virtual_channel_command_set_dbg_log_t {
/* Channel index. See vc_chn_id_e. */
uint8_t chn;
/* 0 : disable print log. 1 : enable print log. */
uint8_t enable;
/* Reserved byte, keep 0. */
uint8_t rsv[2];
}vc_cmd_set_dbg_log_t;
/**
* @brief vc_ack_e - Acknowledges to app from vc-task. See vc_cmd_e.
*/
typedef enum _virtual_channel_acknowledge_e_ {
VC_ACK_GET_STM32_STATUS = 0,
VC_ACK_GET_STM32_FW_INFO,
VC_ACK_SET_STM32_USB,
VC_ACK_GET_STATISTICS,
VC_ACK_SET_STM32_DBG_LOG,
VC_ACK_START_UPGD,
VC_ACK_STOP_UPGD,
VC_ACK_GET_UPGD_INFO,
VC_ACK_MAX
}vc_ack_e;
/**
* @brief vc_cmd_t - Top structure of acknowledge to app from vc-task.
*/
typedef struct _virtual_channel_acknowledge_t_ {
/* See vc_ack_e. */
uint8_t ack;
/* ERR_OK / ERR_FAIL / ERR_TIMEOVER. */
uint8_t ret;
/* Length of payload. */
uint16_t payload_len;
/* Structure of acknowledges. */
uint8_t payload[0];
}vc_ack_t;
/**
* @brief vc_ack_get_statistics_t - Structure of acknowledge VC_ACK_GET_STATISTICS.
*/
typedef struct _virtual_channel_acknowledge_get_statistics_t {
/* Count of channel statistics. */
uint8_t chn_cnt;
/* Reserved byte, keep 0. */
uint8_t rsv[3];
/* Statistics of each channel, statistics[0] ~ statistics[3]. */
vc_chn_statistic_t statistics[0];
}vc_ack_get_statistics_t;
/**
* @brief vc_ack_get_status_t - Structure of acknowledge VC_ACK_GET_STM32_STATUS.
*/
typedef struct _virtual_channel_acknowledge_get_status_t {
/* Status of STM32. See vc_sts_bitmap_stm32_e. */
uint32_t status;
}vc_ack_get_status_t;
/**
* @brief vc_ack_get_fw_info_t - Structure of acknowledge VC_ACK_GET_STM32_FW_INFO.
*/
typedef struct _virtual_channel_acknowledge_get_fw_info_t {
/* Info of local firmware on flash. */
vc_fw_ver_t local;
/* Info of remote firmware is running. */
vc_fw_ver_t remote;
}vc_ack_get_fw_info_t;
/**
* @brief vc_ack_get_upgrade_info_t - Structure of acknowledge VC_ACK_GET_UPGD_INFO.
*/
typedef struct _virtual_channel_acknowledge_get_upgrade_info_t {
/* Percentage of upgrading. e.g. 80 -> 80% */
uint8_t percentage;
/* See vc_upgrd_state_e. */
uint8_t state;
/* Reserved byte, keep 0. */
uint8_t rsv[2];
}vc_ack_get_upgrade_info_t;
/**
* @brief vc_module_cmd_rcv_func - Function pointer to get acknowledge of command.
* @param p_ack: Acknowledge to get.
* @return ERR_FAIL -- Operation failed.
* @return ERR_OK -- Operation Successful.
*/
typedef uint32_t (*vc_module_ack_rcv_func)(vc_ack_t *p_ack);
/**
* @brief vc_module_command_send - Open the command path.
* @param p_func: Handle to receive the acknowledge of command.
* @return ERR_FAIL -- Operation failed.
* @return ERR_OK -- Operation Successful.
*/
uint32_t vc_module_command_open(vc_module_ack_rcv_func p_func);
/**
* @brief vc_module_command_send - Send command to VC-TASK.
* @param p_cmd: Command to execute.
* @return ERR_FAIL -- Operation failed.
* @return ERR_OK -- Operation Successful.
*/
uint32_t vc_module_command_send(vc_cmd_t *p_cmd);
/**
* @brief vc_channel_open - Open a virtual channel.
* @param port: Virtual channel to open.
* @param p_func: Function pointer to receive data.
* @param drv: Select low layer driver to send data to stm32 side.
* @return ERR_FAIL -- Operation failed.
* @return ERR_OK -- Operation Successful.
*/
uint32_t vc_channel_open (vc_chn_id_e chn, vc_chn_rcv_func p_func, vc_drv_id_e drv);
/**
* @brief vc_channel_send - Send data to the virtual channel.
* @param chn: Virtual channel to send data.
* @param p_buf: Pointer of a buffer holding data to send.
* @param len: Length of buffer.
* @return Bytes of data that sent.
*/
uint32_t vc_channel_send(vc_chn_id_e chn, uint8_t *p_buf, uint32_t len);
/**
* @brief vc_module_init - Initialize this virtual channel module.
* @return ERR_FAIL -- Operation failed.
* @return ERR_OK -- Operation Successful.
*/
uint32_t vc_module_init(void);
#endif /* _VC_TASK_H_ */