169 lines
5.4 KiB
C
169 lines
5.4 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 _IOT_PLC_CKB_H
|
|
#define _IOT_PLC_CKB_H
|
|
|
|
#include "iot_task_api.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define UART_0_BAUD_RATE 9600
|
|
|
|
/* define priorities for message to be handle */
|
|
#define IOT_CKB_TASK_QUEUE_HP 0
|
|
#define IOT_CKB_TASK_QUEUE_LP 1
|
|
#define IOT_CKB_TASK_QUEUE_MAX_PRIO 2
|
|
|
|
#define IOT_CKB_TASK_LIKE_ID 2
|
|
#define IOT_CKB_TASK_POOL_SIZE 128
|
|
|
|
/* message type */
|
|
#define IOT_CKB_MAC_MSG 0
|
|
#define IOT_CKB_TIMER_MSG 1
|
|
#define IOT_CKB_UART_RECV_MSG 2
|
|
|
|
/* message id for timer */
|
|
#define IOT_CKB_TIMER_CHECK 1 /* check cache data in buffer */
|
|
|
|
/* check cache data in sendq interval, unit is ms */
|
|
#define IOT_CKB_PERIODIC_TIMER_INTERVAL (250)
|
|
/* count for boardcast sta connection_less's mode config interval */
|
|
#define IOT_CKB_BCAST_TIMER_CNT 4
|
|
/* max life-span cnt, which decide how long will the buff keep the frame info */
|
|
#define IOT_CKB_MAX_LIFE_SPAN_CNT 16
|
|
/* parameter sent to sta for meter reading timeout config, uint is 100ms */
|
|
#define IOT_CKB_CFG_MR_TIMEOUT 16
|
|
|
|
/* Macro to define msdu pkt pool number*/
|
|
#define IOT_CKB_POOL_NUM 8
|
|
/* UART received buffer size */
|
|
#define IOT_CKB_UART_RECV_BUF_SIZE 256
|
|
/* sta control configuring effective duration, unit is sec */
|
|
#define IOT_CKB_MODE_CFG_DUR 30
|
|
|
|
/* uart frame protocal */
|
|
#define IOT_CKB_PROTO_TYPE_TRANSPARENT 0
|
|
#define IOT_CKB_PROTO_TYPE_645_1997 1
|
|
#define IOT_CKB_PROTO_TYPE_645_2007 2
|
|
#define IOT_CKB_PROTO_TYPE_69845 3
|
|
|
|
/* define target device type ID */
|
|
#define IOT_CKB_TARGET_ID_CCO 0
|
|
#define IOT_CKB_TARGET_ID_STA 1
|
|
|
|
/* defining target device type identifier mask */
|
|
#define IOT_CKB_TARGET_ID_MSK_CCO \
|
|
(1 << IOT_CKB_TARGET_ID_CCO)
|
|
#define IOT_CKB_TARGET_ID_MSK_STA \
|
|
(1 << IOT_CKB_TARGET_ID_STA)
|
|
|
|
/* rerty invterval , unit is IOT_CKB_PERIODIC_TIMER_INTERVAL */
|
|
#define IOT_CKB_APP_MAX_RETRY_INTV_CNT 8
|
|
|
|
#pragma pack(push) /* save the pack status */
|
|
#pragma pack(1) /* 1 byte align */
|
|
|
|
typedef struct _ckb_mode_cfg {
|
|
/* band ID to be configured, see PLC_LIB_FREQ_BAND_X */
|
|
uint8_t band_id;
|
|
/* configuring effective duration, uint is sec */
|
|
uint8_t dur;
|
|
/* the target device ID group that needs to respond to this command.
|
|
* see IOT_CKB_TARGET_ID_MSK_XXX.
|
|
*/
|
|
uint32_t target_id_mask;
|
|
} ckb_mode_cfg_t;
|
|
|
|
#pragma pack(pop) /* restore the pack status */
|
|
|
|
/* store the frame and infor extracted from the frame */
|
|
typedef struct _frame_pkt_t {
|
|
/* msdu sequnce number */
|
|
uint16_t app_sn;
|
|
/* dst meter addresss */
|
|
uint8_t dst_mac[IOT_MAC_ADDR_LEN];
|
|
/* full 645/698 frame */
|
|
iot_pkt_t *data;
|
|
} frame_pkt_t;
|
|
|
|
/* frame infor extracted from the frame */
|
|
typedef struct _frame_info_t {
|
|
/* life-span counter */
|
|
uint16_t span_cnt;
|
|
/* msdu been sent counter, 0 means the buffer is not used */
|
|
uint8_t send_cnt;
|
|
/* frame data and releated infor */
|
|
frame_pkt_t frm;
|
|
} frame_info_t;
|
|
|
|
/* frame infor pool */
|
|
typedef struct _info_pool_t {
|
|
/* how many buffers are not used */
|
|
uint8_t remain_cnt;
|
|
/* infor extracted from the frame */
|
|
frame_info_t frm_info[IOT_CKB_POOL_NUM];
|
|
} info_pool_t;
|
|
|
|
typedef struct _iot_ckb_msg {
|
|
/* standard iot_task message */
|
|
iot_task_msg_t msg;
|
|
/* pointer to message data */
|
|
void *data;
|
|
}iot_ckb_task_msg_t;
|
|
|
|
typedef struct _iot_ckb_task_data {
|
|
/* app sending sequnce number for msdu */
|
|
uint16_t app_sn;
|
|
/* handle of the ping iot_task */
|
|
iot_task_h task_handle;
|
|
/* a flag indicating if app registered successfully */
|
|
uint8_t app_registered;
|
|
/* link id used for sending msdu */
|
|
uint8_t link_id;
|
|
/* indication for device is ready for data transmition or not */
|
|
uint8_t dev_ready;
|
|
/* device type */
|
|
uint8_t dev_type;
|
|
/* role of local device */
|
|
uint8_t dev_role;
|
|
/* mac address of local device */
|
|
uint8_t mac_addr[IOT_MAC_ADDR_LEN];
|
|
/* frequency band value, see PLC_LIB_FREQ_BAND_X*/
|
|
uint8_t band_id;
|
|
/* handle of this app */
|
|
iot_plc_app_h app_handle;
|
|
/* frame infor pool */
|
|
info_pool_t info_pool;
|
|
}iot_ckb_task_data_t;
|
|
|
|
/*
|
|
* brief: entry for ckb app
|
|
* @return:
|
|
* @retval: ERR_PENDING - if app want to delay the plc network formation.
|
|
* @retval: other - plc network formation will be started automatically.
|
|
*/
|
|
uint32_t app_ckb_entry();
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif //_IOT_PLC_CKB_H
|
|
|