Files
kunlun/plc/cvg/nwm/inc/cvg_nwm_ctrl_proto_internal.h

254 lines
8.6 KiB
C
Raw Permalink Normal View History

2024-09-28 14:24:04 +08:00
/****************************************************************************
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 __CVG_NWM_CTRL_PROTO_INTERNAL_H
#define __CVG_NWM_CTRL_PROTO_INTERNAL_H
#include "plc_fr.h"
#ifdef __cplusplus
extern "C" {
#endif
#if (PLC_SUPPORT_EXT_PROTO)
/* define interval for sending sync frames, uint is 1ms */
#define CVG_NWM_CTRL_SEND_SYNC_INTERVAL 100
/* define the maximum number for send sync frames. */
#define CVG_NWM_CTRL_SEND_SYNC_MAX_CNT 5
/* define interval for sending search frames, uint is 1ms */
#define CVG_NWM_CTRL_SEND_SEARCH_INTERVAL 200
/* defines the limited parameter of sending search frames in each band. */
#define CVG_NWM_CTRL_SEND_SEARCH_CNT_MIN 5 /* minimum number */
#define CVG_NWM_CTRL_SEND_SEARCH_CNT_MAX 25 /* maximum number */
/* define the maximum duration of search for target devices. uint is 1s */
#define CVG_NWM_CTRL_SEARCH_MAX_DUR 100
/* define timer unit duration, uint is 1ms */
#define CVG_NWM_CTRL_TIMER_UNIT_DUR 10000
/* waiting duration for synchronous frame reception, uint is 1ms */
#define CVG_NWM_CTRL_WAIT_SYNC_DUR 2000
/* sync frame send interval in connected state
* uint is CVG_NWM_CTRL_TIMER_UNIT_DUR.
*/
#define CVG_NWM_CTRL_MAINTAIN_INTERVAL 3
/* if the device end does not receive any app message from the controller for
* several consecutive check period, the connection will be disconnected
* automatically, uint is CVG_NWM_CTRL_TIMER_UNIT_DUR
*/
#define CVG_NWM_CTRL_DIS_CONN_CNT 18
/* define the state of the connected remote device */
#define CVG_NWM_CTRL_PROTO_REMOTE_S_INVALID 0
#define CVG_NWM_CTRL_PROTO_REMOTE_S_SYNCING 1
#define CVG_NWM_CTRL_PROTO_REMOTE_S_CONNECTING 2
#define CVG_NWM_CTRL_PROTO_REMOTE_S_CONNECTED 3
/* defining two logical roles in the controller protocol */
/* master end, initiator of connection */
#define CVG_NWM_CTRL_PROTO_ROLE_MAS 1
/* slave end -- CCO and STA, connection recipients */
#define CVG_NWM_CTRL_PROTO_ROLE_SLA 0
/* defining the priority of controller protocol frame */
#define CVG_NWM_CTRL_PROTO_SYNC_PRIO 3
#define CVG_NWM_CTRL_PROTO_SEARCH_PRIO 3
/* defining the retry cnt of controller protocol frame */
#define CVG_NWM_CTRL_PROTO_SYNC_RETRY_CNT 0
#define CVG_NWM_CTRL_PROTO_SEARCH_RETRY_CNT 0
/* sof frame from remote dev, msdu sn rec array size */
#define CVG_NWM_CTRL_PROTO_REC_CNT 32
/* connected remote device descriptor */
typedef struct _cvg_nwm_ctrl_remote_desc {
/* TEI of the connected remote device, as follows:
* 1. CCO: PLC_TEI_CCO
* 2. STA without network: 0
* 3. STA with network: 2 ~ PLC_TEI_MAX
* 4. controller: PLC_TEI_CTRL
*/
tei_t tei;
/* inactive counters of connected remote device, uint is
* CVG_NWM_CTRL_TIMER_UNIT_DUR.
*/
uint8_t inactive_cnt;
/* state of connected remote device, see CVG_NWM_CTRL_PROTO_REMOTE_S_XXXX */
uint8_t state;
/* band id, see BEACON_FREQ_BAND_ID_XXX */
uint8_t band_id;
} cvg_nwm_ctrl_remote_desc_t;
/* persistent info */
typedef struct _cvg_nwm_ctrl_ps_info {
/* target address to be connected, available if local device is master
* role.
*/
uint8_t addr[IOT_MAC_ADDR_LEN];
/* current logical role, see CVG_NWM_CTRL_PROTO_ROLE_XXX */
uint8_t role;
/* current device sn */
uint8_t sn;
} cvg_nwm_ctrl_ps_info_t;
/* master role descriptor */
typedef struct _cvg_nwm_ctrl_mas_desc {
/* band index */
uint8_t band_idx;
/* sending search frame counters.*/
uint8_t search_cnt;
/* send maximum number of search frame in the current band */
uint8_t search_max;
/* search target device start time stamp, uint is 1s. */
uint32_t search_start_ts;
} cvg_nwm_ctrl_mas_desc_t;
/* slave role descriptor */
typedef struct _cvg_nwm_ctrl_sla_desc {
/* sending sync frame counters */
uint8_t sync_cnt;
} cvg_nwm_ctrl_sla_desc_t;
/* controller protocol control block */
typedef struct _cvg_nwm_ctrl_pcb {
/* persistent info */
cvg_nwm_ctrl_ps_info_t ps_info;
/* check timer */
timer_id_t check_timer;
/* sof frame from remote dev msdu record array */
uint16_t msdu_rec[CVG_NWM_CTRL_PROTO_REC_CNT];
/* lastest in use record index in msdu_rec array */
uint8_t msdu_rec_idx :7,
/* flag to mark if all msdu record is valid */
msdu_rec_valid :1;
/* remote device data structure */
cvg_nwm_ctrl_remote_desc_t remote;
/* local device data structure */
union {
cvg_nwm_ctrl_mas_desc_t mas;
cvg_nwm_ctrl_sla_desc_t sla;
} desc;
} cvg_nwm_ctrl_pcb_t;
/**
* @brief cvg_nwm_ctrl_proto_check_slave() - period check of controller protocol.
* as slave device - CCO and STA
* @param: nwm - nwm vdev pointer
* @retval: ERR_OK - normal connection behavior
* @retval: otherwise - abnormal connection behavior
*/
uint8_t cvg_nwm_ctrl_proto_check_slave(cvg_nwm_vdev_t *nwm);
/*
* @brief cvg_nwm_ctrl_proto_reset_internal() - controller protocol reset
* internal.
* @param: pcb - controller protocol pcb pointer
*/
void cvg_nwm_ctrl_proto_reset_internal(cvg_nwm_ctrl_pcb_t *pcb);
/*
* @brief cvg_nwm_ctrl_proto_is_started() - check controller protocol state is
* started.
* @param: pcb - controller protocol pcb pointer
* @retval: 0 - is not started
* otherwise - is started
*/
uint8_t cvg_nwm_ctrl_proto_is_started(cvg_nwm_ctrl_pcb_t *pcb);
/*
* @brief cvg_nwm_ctrl_proto_set_active() - set controller protocol state to
* actived.
* @param: nwm - nwm vdev pointer.
*/
void cvg_nwm_ctrl_proto_set_active(cvg_nwm_vdev_t *nwm);
/*
* @brief cvg_nwm_ctrl_proto_check_msdu_rec() - check if this is a duplicate
* controller protocol sof frame.
* @param: pcb - controller protocol pcb pointer
* @param: sn - msdu sn
* @retval: 0 - is not duplicate
* otherwise - is duplicate
*/
uint8_t cvg_nwm_ctrl_proto_check_msdu_rec(cvg_nwm_ctrl_pcb_t *pcb, uint16_t sn);
/*
* @brief cvg_nwm_ctrl_proto_search_req_rx() - handling search info from master
* device (controller)
* @param: nwm - nwm vdev pointer.
* @param: addr - target address to be searched.
* @param: src_tei - TEI of master dev(controller).
* @param: band_id - band id.
* @param: phase - logic phase.
* @param: sn - sn
* @retval: ERR_OK - search accepted.
* ERR_DISCONNECT - connection behavior terminated and disconnected.
* otherwise - see err code.
*/
uint8_t cvg_nwm_ctrl_proto_search_req_rx(cvg_nwm_vdev_t *nwm,
uint8_t *addr, tei_t src_tei, uint8_t band_id, uint8_t phase, uint8_t sn);
/*
* @brief cvg_nwm_ctrl_proto_init() - controller protocol initialization.
* @param: nwm - nwm vdev pointer
* @retval: ERR_OK - for success case
* otherwise - for failure case, see error code
*/
uint32_t cvg_nwm_ctrl_proto_init(cvg_nwm_vdev_t *nwm);
/*
* @brief cvg_nwm_ctrl_proto_init() - controller protocol deinit.
* @param: nwm -- nwm vdev pointer
*/
void cvg_nwm_ctrl_proto_deinit(cvg_nwm_vdev_t *nwm);
/*
* @brief cvg_nwm_ctrl_proto_reset() - controller protocol reset.
* @param: nwm -- nwm vdev pointer
*/
void cvg_nwm_ctrl_proto_reset(cvg_nwm_vdev_t *nwm);
#else /* PLC_SUPPORT_EXT_PROTO */
#define cvg_nwm_ctrl_proto_is_started(pcb) (0)
#define cvg_nwm_ctrl_proto_set_active(nwm)
#define cvg_nwm_ctrl_proto_check_msdu_rec(pcb, sn) (0)
#define cvg_nwm_ctrl_proto_init(nwm) (ERR_NOSUPP)
#define cvg_nwm_ctrl_proto_deinit(nwm)
#define cvg_nwm_ctrl_proto_reset(nwm)
uint8_t cvg_nwm_ctrl_proto_search_req_rx(cvg_nwm_vdev_t *nwm,
uint8_t *addr, tei_t src_tei, uint8_t band_id, uint8_t phase, uint8_t sn);
#endif /* PLC_SUPPORT_EXT_PROTO */
#ifdef __cplusplus
}
#endif
#endif /* __CVG_NWM_CTRL_PROTO_INTERNAL_H */