159 lines
4.1 KiB
C
159 lines
4.1 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.
|
|
|
|
****************************************************************************/
|
|
|
|
#include "os_types.h"
|
|
#include "os_mem.h"
|
|
#include "os_utils.h"
|
|
#include "os_timer.h"
|
|
#include "iot_errno_api.h"
|
|
#include "iot_io_api.h"
|
|
#include "iot_system.h"
|
|
#include "iot_oem.h"
|
|
|
|
#include "plc_fr.h"
|
|
#include "plc_protocol.h"
|
|
#include "mac_pdev.h"
|
|
#include "mac_vdev.h"
|
|
#include "mac_msg.h"
|
|
#include "mac.h"
|
|
#include "mac_sched_hw.h"
|
|
#include "mac_isr.h"
|
|
#include "mac_status.h"
|
|
#include "iot_bitops_api.h"
|
|
#include "iot_board_api.h"
|
|
#include "gpio_mtx.h"
|
|
#include "mac_zc_hw.h"
|
|
#include "mac_zc.h"
|
|
|
|
#if MAC_ZC_ENABLE
|
|
|
|
uint32_t mac_start_zc_ntb_collect_internal(uint8_t pdev_id, uint8_t vdev_id,
|
|
iot_pkt_t *pkt)
|
|
{
|
|
mac_vdev_t *vdev;
|
|
mac_zc_ntb_get_para_t *para;
|
|
mac_zc_ntb_rpt_t *rpt;
|
|
uint32_t cnt;
|
|
|
|
vdev = get_vdev_ptr(pdev_id, vdev_id);
|
|
if (!vdev || !vdev->is_up) {
|
|
return ERR_NOT_READY;
|
|
}
|
|
|
|
if (!pkt) {
|
|
return ERR_INVAL;
|
|
}
|
|
|
|
para = (mac_zc_ntb_get_para_t *)iot_pkt_push(pkt, sizeof(*para));
|
|
if (NULL == para) {
|
|
return ERR_INVAL;
|
|
}
|
|
|
|
rpt = (mac_zc_ntb_rpt_t *)iot_pkt_pull(pkt, sizeof(mac_zc_ntb_get_para_t));
|
|
if (NULL == rpt) {
|
|
return ERR_INVAL;
|
|
}
|
|
|
|
/* check get count valid */
|
|
cnt = iot_pkt_tail_len(pkt);
|
|
/* set pkt tail to end */
|
|
if (NULL == iot_pkt_put(pkt, cnt)) {
|
|
return ERR_INVAL;
|
|
}
|
|
cnt = cnt / sizeof(uint32_t);
|
|
/* check pkt tail len & para->count valid */
|
|
if (cnt < para->count) {
|
|
*(uint32_t *)(para + 1) = cnt;
|
|
IOT_ASSERT_DUMP(0, (uint32_t *)para,
|
|
sizeof(*para)/sizeof(uint32_t) + 1);
|
|
}
|
|
|
|
mac_status_add_zc_req_cnt();
|
|
|
|
return mac_zc_get_ntb(pdev_id, rpt, (uint16_t)para->count,
|
|
(uint8_t)para->is_full_period, (uint8_t)para->is_get_history,
|
|
para->nid, para->ntb);
|
|
}
|
|
|
|
uint32_t mac_start_zc_ntb_collect(uint8_t pdev_id, uint8_t vdev_id,
|
|
iot_pkt_t **pkt, uint16_t cnt, uint8_t is_full_period, uint32_t nid,
|
|
uint32_t *ntb_ptr)
|
|
{
|
|
uint32_t ret = ERR_NOMEM;
|
|
uint32_t ntb;
|
|
uint8_t is_history_ntb;
|
|
mac_zc_ntb_get_para_t *para;
|
|
mac_msg_sync_t *msg = mac_alloc_msg_sync();
|
|
|
|
do {
|
|
if (NULL == msg) {
|
|
IOT_ASSERT(0);
|
|
break;
|
|
}
|
|
|
|
MAC_ZC_RPT_PKT_GET(*pkt, cnt, PLC_MAC_ZC_MID);
|
|
|
|
if (NULL == *pkt) {
|
|
break;
|
|
}
|
|
|
|
if (ntb_ptr) {
|
|
is_history_ntb = 1;
|
|
ntb = *ntb_ptr;
|
|
} else {
|
|
is_history_ntb = 0;
|
|
ntb = 0;
|
|
}
|
|
|
|
para = (mac_zc_ntb_get_para_t *)iot_pkt_push(*pkt, sizeof(*para));
|
|
if (!para) {
|
|
break;
|
|
}
|
|
|
|
para->count = cnt;
|
|
para->is_full_period = !!is_full_period;
|
|
para->is_get_history = !!is_history_ntb;
|
|
para->nid = nid;
|
|
para->ntb = ntb;
|
|
if (NULL == iot_pkt_pull(*pkt, sizeof(*para))) {
|
|
break;
|
|
}
|
|
|
|
ret = ERR_OK;
|
|
} while (0);
|
|
|
|
if (ret != ERR_OK) {
|
|
if (*pkt) {
|
|
iot_pkt_free(*pkt);
|
|
*pkt = NULL;
|
|
}
|
|
} else {
|
|
msg->msg.type = MAC_MSG_TYPE_CVG;
|
|
msg->msg.id = MAC_MSG_ID_CVG_START_ZC_NTB;
|
|
msg->msg.data1 = (((uint32_t)pdev_id) << 8) | vdev_id;
|
|
msg->msg.data2 = (void *)*pkt;
|
|
mac_queue_msg_sync(msg, MAC_MSG_QUEUE_HP);
|
|
ret = msg->msg.data1;
|
|
}
|
|
|
|
if (msg) {
|
|
mac_free_msg_sync(msg);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
#endif
|