172 lines
5.1 KiB
C
172 lines
5.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.
|
|
|
|
****************************************************************************/
|
|
#ifndef IOT_SG_CCO_FLASH_H
|
|
#define IOT_SG_CCO_FLASH_H
|
|
|
|
/* os shim includes */
|
|
#include "os_types_api.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#if (PLC_SUPPORT_CCO_ROLE && IOT_SMART_GRID_ENABLE)
|
|
|
|
/* pack for the structures in the whole file */
|
|
#pragma pack(push) /* save the pack status */
|
|
#pragma pack(1) /* 1 byte align */
|
|
|
|
/* flash mode */
|
|
#define IOT_SG_CCO_FLASH_MODE_INVALID (0)
|
|
#define IOT_SG_CCO_FLASH_MODE_MAC_LIST (1)
|
|
|
|
/* mac list count */
|
|
#define IOT_SG_CCO_FLASH_MAC_LIST_CNT (100)
|
|
|
|
/* tsfm dectect address count */
|
|
#define IOT_SG_CCO_FLASH_MAC_LIST_TSFM_ADDR_CNT (16)
|
|
|
|
/* address */
|
|
typedef struct _iot_sg_cco_flash_addr {
|
|
/* address, little endian */
|
|
uint8_t addr[IOT_MAC_ADDR_LEN];
|
|
/* tsfm dectect state, 0 - different transformer, 1 - same transformer */
|
|
uint8_t tsfm_state :1,
|
|
/* node tsfm dectect mac addr index */
|
|
tsfm_addr_idx :4,
|
|
/* if the node index is valid */
|
|
tsfm_addr_idx_valid :1,
|
|
rsvd1 :2;
|
|
/* reserved for future */
|
|
uint8_t rsvd2[5];
|
|
} iot_sg_cco_flash_addr_t;
|
|
|
|
/* mac address list */
|
|
typedef struct _iot_sg_cco_flash_mac_list {
|
|
/* mac list crc value */
|
|
uint32_t crc;
|
|
/* power meter address count */
|
|
uint8_t pm_addr_cnt;
|
|
/* node tsfm dectect mac addr, big endian */
|
|
uint8_t tsfm_addr[IOT_SG_CCO_FLASH_MAC_LIST_TSFM_ADDR_CNT][
|
|
IOT_MAC_ADDR_LEN];
|
|
/* mac address list */
|
|
iot_sg_cco_flash_addr_t mac_list[IOT_SG_CCO_FLASH_MAC_LIST_CNT];
|
|
} iot_sg_cco_flash_mac_list_t;
|
|
|
|
/**
|
|
* @brief flash function initial.
|
|
* @param mode: flash mode, see IOT_SG_CCO_FLASH_MODE_XXX
|
|
* @retval: ERR_OK - for success case
|
|
* @retval: ERR_XXX - error code
|
|
*/
|
|
uint32_t iot_sg_cco_flash_init(uint8_t mode);
|
|
|
|
/**
|
|
* @brief flash function deinit.
|
|
*/
|
|
void iot_sg_cco_flash_deinit();
|
|
|
|
/**
|
|
* @brief flash commit handler
|
|
*/
|
|
void iot_sg_cco_flash_handle_commit();
|
|
|
|
/**
|
|
* @brief get mac address list.
|
|
* @retval: mac list pointer.
|
|
*/
|
|
iot_sg_cco_flash_mac_list_t *iot_sg_cco_flash_get_mac_list();
|
|
|
|
/**
|
|
* @brief add data to list, but not save to flash.
|
|
* @param addr: pm address.
|
|
* @retval: ERR_OK - for success case
|
|
* @retval: ERR_XXX - error code
|
|
*/
|
|
uint32_t iot_sg_cco_flash_add_mac_list(uint8_t *addr);
|
|
|
|
/**
|
|
* @brief remove data to list, but not save to flash.
|
|
* @param addr: pm address, little endian.
|
|
* @retval: ERR_OK - for success case
|
|
* @retval: ERR_XXX - error code
|
|
*/
|
|
uint32_t iot_sg_cco_flash_rm_mac_list_by_addr(uint8_t *pm_addr);
|
|
|
|
/**
|
|
* @brief remove data to list, but not save to flash.
|
|
* @param index: index in list.
|
|
* @retval: ERR_OK - for success case
|
|
* @retval: ERR_XXX - error code
|
|
*/
|
|
uint32_t iot_sg_cco_flash_rm_mac_list_by_index(uint8_t index);
|
|
|
|
/**
|
|
* @brief clear mac list in list, but not save to flash.
|
|
* @retval: ERR_OK - for success case
|
|
* @retval: ERR_XXX - error code
|
|
*/
|
|
uint32_t iot_sg_cco_flash_clr_mac_list();
|
|
|
|
/**
|
|
* @brief save mac list to flash.
|
|
* @retval: ERR_OK - for success case
|
|
* @retval: ERR_XXX - error code
|
|
*/
|
|
uint32_t iot_sg_cco_flash_mac_list_commit();
|
|
|
|
/**
|
|
* @brief add tsfm addr to list, but not save to flash.
|
|
* @param tsfm_addr: tsfm addr, big endian.
|
|
* @retval: tsfm address index
|
|
*/
|
|
uint8_t iot_sg_cco_flash_add_tsfm_addr(uint8_t *tsfm_addr);
|
|
|
|
/**
|
|
* @brief add tsfm state to list, but not save to flash.
|
|
* @param pm_addr: pm addr, little endian.
|
|
* @param tsfm_addr: tsfm addr, big endian.
|
|
* @param tsfm_state: tsfm dectect state, 0 - different transformer,
|
|
* 1 - same transformer.
|
|
* @retval: ERR_OK - for success case
|
|
* @retval: ERR_XXX - error code
|
|
*/
|
|
uint32_t iot_sg_cco_flash_add_tsfm_state(uint8_t *pm_addr, uint8_t *tsfm_addr,
|
|
uint8_t tsfm_state);
|
|
|
|
/**
|
|
* @brief clear tsfm state in list, but not save to flash.
|
|
*/
|
|
void iot_sg_cco_flash_clr_tsfm_state();
|
|
|
|
/**
|
|
* @brief check if the power meter exist in mac list.
|
|
* @param pm_addr: pm address.
|
|
* @retval: ERR_OK - exist
|
|
* @retval: ERR_XXX - not exist
|
|
*/
|
|
uint32_t iot_sg_cco_flash_mac_exist(uint8_t *pm_addr);
|
|
|
|
#pragma pack(pop) /* restore the pack status */
|
|
|
|
#endif /* PLC_SUPPORT_CCO_ROLE && IOT_SMART_GRID_ENABLE */
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* IOT_SG_CCO_FLASH_H */
|