170 lines
		
	
	
		
			5.3 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			170 lines
		
	
	
		
			5.3 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
/****************************************************************************
 | 
						|
 | 
						|
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 _IOT_SG_EXT_API_H_
 | 
						|
#define _IOT_SG_EXT_API_H_
 | 
						|
 | 
						|
#include "iot_uart_api.h"
 | 
						|
#include "iot_utils_api.h"
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
extern "C" {
 | 
						|
#endif
 | 
						|
 | 
						|
#define IOT_SG_EXT_PROTO_ID_645_97     1
 | 
						|
#define IOT_SG_EXT_PROTO_ID_645_07     2
 | 
						|
#define IOT_SG_EXT_PROTO_ID_69845      3
 | 
						|
 | 
						|
/** Invalid threshold flag. */
 | 
						|
#define IOT_SG_EXT_INVALID_THRD  (-1)
 | 
						|
 | 
						|
/* ext common command sub id */
 | 
						|
#define IOT_SG_EXT_SID_DEFAULT                  (0x0)
 | 
						|
/* sub_id of configuring a uart port. */
 | 
						|
#define IOT_SG_EXT_SID_UART_CFG                 (0x1)
 | 
						|
/* sub_id of configuring msdu enable. */
 | 
						|
#define IOT_SG_EXT_SID_MSDU_FWD_ENABLE          (0x2)
 | 
						|
 | 
						|
/* ext common message id */
 | 
						|
#define IOT_SG_EXT_MID_UART_DATA_FROM_CUS       (0x00)
 | 
						|
#define IOT_SG_EXT_MID_UART_DATA_FROM_SG        (0x01)
 | 
						|
#define IOT_SG_EXT_MID_COMMAND                  (0x02)
 | 
						|
#define IOT_SG_EXT_MID_TRANS_MSDU_FROM_SG       (0x03)
 | 
						|
#define IOT_SG_EXT_MID_TRANS_MSDU_FROM_CUS      (0x04)
 | 
						|
#define IOT_SG_EXT_MID_MSDU_SEND                (0x05)
 | 
						|
 | 
						|
/* msdu send type */
 | 
						|
/* unicast packet */
 | 
						|
#define IOT_SG_EXT_CUS_TYPE_UNICAST             (0x01)
 | 
						|
/* proxy broadcast */
 | 
						|
#define IOT_SG_EXT_CUS_TYPE_BCAST               (0x03)
 | 
						|
/* whole network broadcast */
 | 
						|
#define IOT_SG_EXT_CUS_TYPE_BCAST_ALL           (0x06)
 | 
						|
 | 
						|
/* priority definition */
 | 
						|
#define IOT_SG_EXT_CUS_PRO_MAX                  (0x03)
 | 
						|
 | 
						|
/* local default retry count */
 | 
						|
#define IOT_SG_EXT_CUS_LOCAL_RETRY_CNT          (0)
 | 
						|
/* whole network broadcast max retry count */
 | 
						|
#define IOT_SG_EXT_CUS_BCAST_ALL_MAX_RETRY_CNT  (3)
 | 
						|
 | 
						|
/* uart data channel, for local protocol */
 | 
						|
#define IOT_SG_EXT_UART_DATA_CCTT               (0x00)
 | 
						|
#define IOT_SG_EXT_UART_DATA_CUS                (0x03)
 | 
						|
 | 
						|
/* query command result */
 | 
						|
#define IOT_SG_EXT_QRY_RESULT_SUCCESS           (0)
 | 
						|
#define IOT_SG_EXT_QRY_RESULT_FAIL              (1)
 | 
						|
 | 
						|
/* uart data channel convert for cco*/
 | 
						|
#define IOT_SG_EXT_UART_CHNN_SET(src, channel) \
 | 
						|
    do { \
 | 
						|
        (src) &= ~0x06; \
 | 
						|
        (src) |= (channel << 1); \
 | 
						|
    } while(0)
 | 
						|
#define IOT_SG_EXT_UART_CHNN_GET(data)          ((data & 0x06) >> 1)
 | 
						|
 | 
						|
/* uart data full frame convert */
 | 
						|
#define IOT_SG_EXT_UART_FULL_FRAME_SET(src)     (src |= 0x01)
 | 
						|
#define IOT_SG_EXT_UART_FULL_FRAME_GET(src)     (src &= 0x01)
 | 
						|
 | 
						|
/** Only cus-app -> sg-app need this. */
 | 
						|
enum _iot_sg_ext_data_frame_status {
 | 
						|
    /** This packet of data is a part of a full frame. */
 | 
						|
    IOT_SG_EXT_DF_PART,
 | 
						|
    /** This packet of data is a full frame. */
 | 
						|
    IOT_SG_EXT_DF_FULL
 | 
						|
};
 | 
						|
 | 
						|
#pragma pack(push)  // save the pack status
 | 
						|
#pragma pack(1)     // 1 byte align
 | 
						|
 | 
						|
typedef struct _iot_sg_ext_header {
 | 
						|
    /** message id, enum iot_sg_message_id_e. */
 | 
						|
    uint8_t mid;
 | 
						|
    /**
 | 
						|
     * IOT_SG_EXT_MID_COMMAND:
 | 
						|
     * sub_id.
 | 
						|
     * IOT_SG_EXT_MID_UART_DATA_FROM_CUS:
 | 
						|
     * bit0 - ull_frame flag.
 | 
						|
     * bit1-bit2 - channel.
 | 
						|
     */
 | 
						|
    uint8_t arg;
 | 
						|
    /** reserved bytes. */
 | 
						|
    uint8_t rsv[2];
 | 
						|
    /** data pointer */
 | 
						|
    uint8_t data[0];
 | 
						|
} iot_sg_ext_header_t;
 | 
						|
 | 
						|
typedef struct _iot_sg_ext_uart {
 | 
						|
    /** baud rate */
 | 
						|
    uint32_t baudrate;
 | 
						|
    /**
 | 
						|
     * threshold for receive timeout.IOT_SG_EXT_INVALID_THRD means ignore this.
 | 
						|
     */
 | 
						|
    uint32_t thd_rx_tm;
 | 
						|
    /**
 | 
						|
     * threshold for receive fifo full.IOT_SG_EXT_INVALID_THRD means
 | 
						|
     * ignore this.
 | 
						|
     */
 | 
						|
    uint32_t thd_rx_ful;
 | 
						|
    /** parity. see IOT_UART_PARITY_XXX */
 | 
						|
    uint8_t parity;
 | 
						|
    /** length of data. see IOT_UART_DLEN_X_BITS */
 | 
						|
    uint8_t data;
 | 
						|
    /** stop bit. see IOT_UART_STOP_XX_BITS */
 | 
						|
    uint8_t stop;
 | 
						|
    /** stands for if 'fmt' valid. 1 : valid, 0 : invalid. */
 | 
						|
    uint8_t fmt_valid;
 | 
						|
    /** the format structure of the frame */
 | 
						|
    iot_frame_fmt fmt;
 | 
						|
} iot_sg_ext_uart_t;
 | 
						|
 | 
						|
typedef struct _iot_sg_ext_cus_msdu_fwd_enable {
 | 
						|
    /* enable msdu handle */
 | 
						|
    uint8_t enable;
 | 
						|
} iot_sg_ext_cus_msdu_fwd_enable_t;
 | 
						|
 | 
						|
typedef struct _iot_sg_ext_cus_msdu_send_data {
 | 
						|
    /* dest mac addr, big - endian */
 | 
						|
    uint8_t dest_mac[IOT_MAC_ADDR_LEN];
 | 
						|
    /* msg send type, see IOT_SG_EXT_CUS_TYPE_XXX */
 | 
						|
    uint8_t msg_type;
 | 
						|
    /* msg priority, see IOT_SG_EXT_CUS_PRO_XXX */
 | 
						|
    uint8_t pro;
 | 
						|
    /* msg retry count, see IOT_SG_EXT_CUS_XXX */
 | 
						|
    uint8_t retry_cnt;
 | 
						|
    /* msdu data length */
 | 
						|
    uint16_t len;
 | 
						|
    /* msdu data */
 | 
						|
    uint8_t data[0];
 | 
						|
} iot_sg_ext_cus_msdu_send_data_t;
 | 
						|
 | 
						|
typedef struct _iot_sg_ext_rsp_result {
 | 
						|
    /* query command result, see IOT_SG_EXT_QRY_RESULT_XXX */
 | 
						|
    uint8_t result;
 | 
						|
} iot_sg_ext_rsp_result_t;
 | 
						|
 | 
						|
#pragma pack(pop)   // restore the pack status
 | 
						|
 | 
						|
/** 4 byte reserved for header. */
 | 
						|
#define IOT_SG_EXT_HEADROOM     (sizeof(iot_sg_ext_header_t) + 10)
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
#endif /* _IOT_SG_EXT_API_H_ */
 |