288 lines
8.4 KiB
C
Executable File
288 lines
8.4 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_GRAPP_H
|
|
#define IOT_GRAPP_H
|
|
|
|
#include "iot_uart_api.h"
|
|
|
|
#ifndef IOT_GE_CKQ_MODE_ENABLE
|
|
#define IOT_GE_CKQ_MODE_ENABLE 0
|
|
#endif
|
|
|
|
#define INCLUDE_AT_COMMAND_MODULE 0
|
|
|
|
#include "iot_at.h"
|
|
|
|
#include "iot_dev_test.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/** key, online upgraded */
|
|
#define ENABLE_GREE_UPGRADE 1
|
|
|
|
#if (IOT_LWIP_SUPPORT && HW_PLATFORM != HW_PLATFORM_SIMU)
|
|
|
|
#define SUPPORT_HOST_PORT_ETH 1
|
|
|
|
#define IOT_GE_INCLUDE_HTTPD 1
|
|
|
|
#define IOT_GE_INCLUDE_LWMQTT 0
|
|
#else
|
|
/** default not support eth port */
|
|
#define SUPPORT_HOST_PORT_ETH 0
|
|
|
|
/** default not support httpd */
|
|
#define IOT_GE_INCLUDE_HTTPD 0
|
|
|
|
/** default not support mqtt */
|
|
#define IOT_GE_INCLUDE_LWMQTT 0
|
|
#endif /* end (IOT_LWIP_SUPPORT && HW_PLATFORM != HW_PLATFORM_SIMU) */
|
|
|
|
/** aes func ctrl **/
|
|
#if (HW_PLATFORM == HW_PLATFORM_SIMU)
|
|
#define IOT_GE_AES_ENABLE 0
|
|
#else
|
|
#define IOT_GE_AES_ENABLE 0
|
|
#endif
|
|
|
|
/** paging func ctrl **/
|
|
#define IOT_GE_PAGING_ENABLE 0
|
|
|
|
/** const, gree app task priority */
|
|
#define APP_GR_PRIORITY 3
|
|
|
|
/** host port enum */
|
|
enum host_port_e {
|
|
/** uart */
|
|
HOST_PORT_UART = 0,
|
|
/** eth */
|
|
HOST_PORT_ETH = 1,
|
|
/** MQTT */
|
|
HOST_PORT_MQTT = 2,
|
|
/* custom task */
|
|
HOST_PORT_CUSTOM_TASK = 3,
|
|
/** max value */
|
|
HOST_PORT_MAX,
|
|
};
|
|
|
|
/** const, COM0 rev char dump buf size */
|
|
#define IOT_GRAPP_LOG_BUF_LEN 64
|
|
|
|
/* uart baud rate macro */
|
|
#define PROTO_GE_UART_BAUD_3000000 3000000
|
|
#define PROTO_GE_UART_BAUD_256000 256000
|
|
#define PROTO_GE_UART_BAUD_115200 115200
|
|
#define PROTO_GE_UART_BAUD_19200 19200
|
|
#define PROTO_GE_UART_BAUD_9600 9600
|
|
#define PROTO_GE_UART_BAUD_4800 4800
|
|
#define PROTO_GE_UART_BAUD_2400 2400
|
|
/* uart baud rate value list */
|
|
#define PROTO_GE_UART_BAUD_VALUE {115200,9600,2400,256000,3000000,4800,19200}
|
|
/* uart baud index maximum value */
|
|
#define PROTO_GE_UART_BAUD_IDX_MAX 7
|
|
|
|
/* iot module board, stamps package, 22 pins */
|
|
#define IOT_GRAPP_BOARD_STAMP_22P (41)
|
|
/* iot module board, goldenfinger package, 17 pins */
|
|
#define IOT_GRAPP_BOARD_GOLDFINGER_17P (42)
|
|
|
|
/* define default uart parity */
|
|
#if PLC_SUPPORT_CCO_ROLE
|
|
#define DEF_UART_PARITY IOT_UART_PARITY_NONE
|
|
#else
|
|
#define DEF_UART_PARITY IOT_UART_PARITY_EVEN
|
|
#endif
|
|
|
|
/** const, uart drv report rev buffer max size */
|
|
#if PLC_SUPPORT_CCO_ROLE && ENABLE_GREE_UPGRADE
|
|
#define UART_RECV_SIZE_MAX 500
|
|
#else
|
|
#define UART_RECV_SIZE_MAX 256
|
|
#endif
|
|
|
|
typedef uint8_t(*UART_RECV_HANDLER)(uint8_t* buffer, uint16_t len);
|
|
typedef uint8_t(*ETH_RECV_HANDLER)(uint8_t* buffer, uint16_t len);
|
|
typedef uint8_t(*MQTT_RECV_HANDLER)(uint8_t* buffer, uint16_t len);
|
|
typedef uint8_t(*CUS_APP_RECV_HANDLER)(uint8_t* buffer, uint16_t len);
|
|
|
|
/** app uart recv handler enum */
|
|
enum app_uart_recv_handler_e {
|
|
/** gree proto mode */
|
|
GR_MCU_OP_MODE = 0,
|
|
/** at mode */
|
|
GR_AT_OP_MODE = 1,
|
|
/** dev test mode */
|
|
GR_DEV_TEST_OP_MODE = 2,
|
|
/** max mode */
|
|
UART_DISPATCH_METHOD_MAX,
|
|
};
|
|
|
|
typedef struct _prototask_contxt_t prototask_contxt_t;
|
|
|
|
#if IOT_GE_AES_ENABLE
|
|
typedef enum {
|
|
ECB_MODE = 0,
|
|
CBC_MODE,
|
|
CTR_MODE,
|
|
INVALID_MODE,
|
|
} GE_AES_MODE;
|
|
|
|
typedef enum {
|
|
AES_KEY_128 = 0,
|
|
AES_KEY_196,
|
|
AES_KEY_256,
|
|
INVALID_KEY_BITS,
|
|
} GE_AES_KEY;
|
|
|
|
typedef struct _ge_aes_contxt_t {
|
|
/* reserve 1 byte for expansion and address casting */
|
|
uint8_t resv;
|
|
/* whether to enable aes function, 0->disable(default), 1->enable */
|
|
uint8_t enable : 1,
|
|
/* key select 0->ge_key(default), 1->user_key */
|
|
key_type : 1,
|
|
/* the secret key type, 0->128(default), 1->192, 2->256 */
|
|
key_bits : 2,
|
|
/* the secret key type, 0->ECB(default), 1->CBC, 2->CTR */
|
|
mode : 2,
|
|
/* in order to align */
|
|
resv_bit : 2;
|
|
} ge_aes_contxt_t;
|
|
#endif
|
|
|
|
/* gree app top layer structure*/
|
|
typedef struct _greeplc_app_t
|
|
{
|
|
/** proto task handle*/
|
|
iot_task_h proto_task;
|
|
/** proto task context pointer*/
|
|
prototask_contxt_t* proto_context;
|
|
/** plctxrx task handle*/
|
|
iot_task_h plcxmit_task;
|
|
/** at task handler*/
|
|
iot_task_h at_task;
|
|
/** at task context handler*/
|
|
at_context_t *at_context;
|
|
/** dev test task handler*/
|
|
iot_task_h dev_test_task;
|
|
/** dev test context handler*/
|
|
dev_test_context_t *devtest_context;
|
|
/** handle of this app */
|
|
iot_plc_app_h app_handle;
|
|
/** com for upper host */
|
|
void* uart_com;
|
|
/** uart work mode at or greeapp */
|
|
uint8_t uart_mode;
|
|
/** host port, uart or eth */
|
|
uint8_t host_port;
|
|
/** top level on uart interface with mcu */
|
|
UART_RECV_HANDLER uart_dispatch_fntable[UART_DISPATCH_METHOD_MAX];
|
|
/** top level on eth interface with mcu */
|
|
ETH_RECV_HANDLER eth_dispatch_fntable[UART_DISPATCH_METHOD_MAX];
|
|
/** top level on mqtt */
|
|
MQTT_RECV_HANDLER mqtt_dispatch_fntable[UART_DISPATCH_METHOD_MAX];
|
|
/** top level on led controller */
|
|
CUS_APP_RECV_HANDLER app_dispatch_fntable[UART_DISPATCH_METHOD_MAX];
|
|
/** grapp init flag */
|
|
bool_t grapp_init_success;
|
|
#if IOT_GE_AES_ENABLE
|
|
/* aes contxt */
|
|
ge_aes_contxt_t aes;
|
|
#endif
|
|
}greeplc_app_t;
|
|
|
|
extern greeplc_app_t *greeapp;
|
|
|
|
typedef struct _grapp_uart_cfg_t
|
|
{
|
|
/* uart port num */
|
|
uint8_t port;
|
|
/* uart baudrate */
|
|
uint32_t baud;
|
|
/* uart parity bit */
|
|
uint8_t parity;
|
|
/* uart number of data bit */
|
|
uint8_t data;
|
|
/* uart number of stop bit */
|
|
uint8_t stop;
|
|
/*the pointer of callback when the uart receive the data*/
|
|
iot_uart_recv_func_t rec_ptr;
|
|
/* the receiver buffer size */
|
|
uint32_t recbuf_sz;
|
|
}grapp_uart_cfg_t;
|
|
|
|
/**
|
|
* @brief app_gr_app_entry() - add gr app in os app list.
|
|
* @return ERR_OK -- for success case
|
|
* @return ERR_PENDING -- system will not boot up
|
|
*/
|
|
uint32_t app_gr_app_entry(void);
|
|
|
|
/**
|
|
* @brief iot_grapp_set_uart() - config COM0 port setting
|
|
* @param uart: com0 handle
|
|
* @param cfg: config params
|
|
* @return false -- for failure case
|
|
* @return true -- for success case
|
|
*/
|
|
bool_t iot_grapp_set_uart(iot_uart_h uart, grapp_uart_cfg_t *cfg);
|
|
|
|
/**
|
|
* @brief iot_grapp_set_uart_config() - config uart COM port setting
|
|
* @param uart: uart com handle
|
|
* @return false -- for failure case
|
|
* @return true -- for success case
|
|
*/
|
|
bool_t iot_grapp_set_uart_config(iot_uart_h uart);
|
|
|
|
/**
|
|
* @brief iot_grapp_modify_uart_param() -modify uart meter port parameters
|
|
* @param baud_idx: baud index
|
|
* @param parity: parity check
|
|
* @param data_bit: data bit
|
|
* @param stop_bit: stop bit
|
|
*/
|
|
void iot_grapp_modify_uart_param(uint8_t baud_idx, uint8_t parity,
|
|
uint8_t data_bit, uint8_t stop_bit);
|
|
|
|
/**
|
|
* @brief : Get function pointer that send data to GE.
|
|
* @param : host - uplayer who sends data. Reference to enum host_port_e
|
|
*/
|
|
#define iot_grapp_get_fn_send_to_ge(host) \
|
|
(iot_proto_uplayer_data_recv_func)
|
|
|
|
/**
|
|
* @brief : Register function that process data received from GE.
|
|
* @param : host - uplayer who receives data. Reference to enum host_port_e.
|
|
* @param : fn - function pointer for receiving data from GE.
|
|
*/
|
|
#define iot_grapp_reg_fn_receive_from_ge(host, fn) \
|
|
iot_proto_register_response_to_uplayer(fn)
|
|
|
|
#if IOT_GE_EXT_SDK_ENABLE
|
|
uint8_t iot_cus_task_message_to_ge(uint8_t *mq_str, uint16_t str_len);
|
|
|
|
bool_t iot_grapp_init_success();
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // IOT_GRAPP_H
|