Files
kunlun/app/iot_sunsolar_app/inc/iot_sunsolar_sta_nv.h
2024-09-28 14:24:04 +08:00

133 lines
4.3 KiB
C

/****************************************************************************
Copyright(c) 2024 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_SUNSOLAR_STA_NV_H
#define IOT_SUNSOLAR_STA_NV_H
/* os shim includes */
#include "os_types_api.h"
/* sunsolar internal header files */
#include "iot_sunsolar_sta.h"
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------
* nv region layout shows like below
*----------------------------------------
* |-----------------------------|
* | |
* | config data | 8k bytes
* | |
* |-----------------------------|
* | |
* | nv info | 8k bytes
* | |
* |-----------------------------|
*/
/* non-volatile parameter config section start addr */
#define IOT_SOLR_STA_NV_CFG_SEC_START IOT_SOLR_STA_NV_REGION_START
/* non-volatile parameter config section size */
#define IOT_SOLR_STA_NV_CFG_SEC_SIZE (8 * 1024)
/* non-volatile parameter config section end addr */
#define IOT_SOLR_STA_NV_CFG_SEC_END \
(IOT_SOLR_STA_NV_CFG_SEC_START + IOT_SOLR_STA_NV_CFG_SEC_SIZE)
/* non-volatile info section start addr */
#define IOT_SOLR_STA_NV_INFO_SEC_START IOT_SOLR_STA_NV_CFG_SEC_END
/* non-volatile info section start size */
#define IOT_SOLR_STA_NV_INFO_SEC_SIZE (8 * 1024)
/* non-volatile info section end addr */
#define IOT_SOLR_STA_NV_INFO_SEC_END \
(IOT_SOLR_STA_NV_INFO_SEC_START + IOT_SOLR_STA_NV_INFO_SEC_SIZE)
#define PV_SN_STR_MAX_LEN 18
/* sunsolar sta NV region section ID */
typedef enum {
/* nv cfg section */
iot_sunsolar_nv_cfg_id,
/* nv info section */
iot_sunsolar_nv_info_id,
/* max */
iot_sunsolar_nv_id_max,
} iot_sunsolar_nv_id_t;
#pragma pack(push) /* save the pack status */
#pragma pack(1) /* 1 byte align */
/* PV module SN string */
typedef struct _pv_sn_t {
uint8_t pv_sn[PV_SN_STR_MAX_LEN];
} pv_sn_t;
typedef struct _iot_sunsolar_sta_nv_cfg {
/* pvsn of pv. */
pv_sn_t pvsn[LOCAL_PV_MAX];
/* heartbeat function: 1 enable, 0 disable. */
uint8_t heartbeat_en : 1,
/* reserved for future */
rsv1 : 7;
/* reserved for future */
uint8_t rsv2[469];
} iot_sunsolar_sta_nv_cfg_t;
typedef struct _iot_sunsolar_sta_nv_info {
/* history generated energy of each pv, unit: mWalt*hour */
uint64_t total_mWh[LOCAL_PV_MAX];
/* last RSD control command from the command */
uint8_t rsd_last_cmd;
/* reserved for future */
uint8_t rsv[41];
} iot_sunsolar_sta_nv_info_t;
#pragma pack(pop)
/**
* @brief iot_sunsolar_sta_nv_init() - init sunsolar sta nv .
* @return: 0 - for success case
* @return: otherwise - error number
*/
uint32_t iot_sunsolar_sta_nv_init(void);
/**
* @brief iot_sunsolar_sta_nv_deinit() - deinit sunsolar sta nv.
*/
void iot_sunsolar_sta_nv_deinit(void);
/**
* @brief iot_sunsolar_nv_get_section() - gets the buffer pointer for the
* specified section
* @param id: seticon id, see iot_sunsolar_nv_id_t
* @retval: buffer pointer for the specified section
*/
void *iot_sunsolar_nv_get_section(iot_sunsolar_nv_id_t id);
/**
* @brief void iot_sunsolar_nv_update_section(iot_sunsolar_nv_id_t id)
* update the specified seticon to
* non-volatile storage
* @param id: seticon id, see iot_sunsolar_nv_id_t
*/
void iot_sunsolar_nv_update_section(iot_sunsolar_nv_id_t id);
#ifdef __cplusplus
}
#endif
#endif /* IOT_SUNSOLAR_STA_NV_H */