91 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			91 lines
		
	
	
		
			3.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_BRM_CACHE_H
							 | 
						||
| 
								 | 
							
								#define __IOT_BRM_CACHE_H
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* os_shim header files */
							 | 
						||
| 
								 | 
							
								#include "os_types_api.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "iot_config_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_brm_common.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define cache data type */
							 | 
						||
| 
								 | 
							
								typedef enum {
							 | 
						||
| 
								 | 
							
								    iot_brm_cache_data_type_cr,
							 | 
						||
| 
								 | 
							
								    iot_brm_cache_data_type_max,
							 | 
						||
| 
								 | 
							
								} iot_brm_cache_data_type_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* curve descriptor */
							 | 
						||
| 
								 | 
							
								typedef struct {
							 | 
						||
| 
								 | 
							
								    /* time tag */
							 | 
						||
| 
								 | 
							
								    uint32_t ts;
							 | 
						||
| 
								 | 
							
								    /* A/B/C phase current, uint is 0.001A */
							 | 
						||
| 
								 | 
							
								    int32_t  i[IOT_BRM_PHASE_C];
							 | 
						||
| 
								 | 
							
								    /* total/A/B/C active power, uint is 0.0001 KW */
							 | 
						||
| 
								 | 
							
								    int32_t  p[IOT_BRM_PHASE_MAX];
							 | 
						||
| 
								 | 
							
								    /* total/A/B/C reactive power, uint is 0.0001 Kvar */
							 | 
						||
| 
								 | 
							
								    int32_t  q[IOT_BRM_PHASE_MAX];
							 | 
						||
| 
								 | 
							
								    /* total forward active energy, uint is 0.01kWh */
							 | 
						||
| 
								 | 
							
								    uint32_t ept_pos;
							 | 
						||
| 
								 | 
							
								    /* total reverse active energy, uint is 0.01kWh */
							 | 
						||
| 
								 | 
							
								    uint32_t ept_neg;
							 | 
						||
| 
								 | 
							
								    /* A/B/C phase voltage, uint is 0.1v */
							 | 
						||
| 
								 | 
							
								    uint16_t v[IOT_BRM_PHASE_C];
							 | 
						||
| 
								 | 
							
								    /* total/A/B/C power factor, uint is 0.001 */
							 | 
						||
| 
								 | 
							
								    int16_t  pf[IOT_BRM_PHASE_MAX];
							 | 
						||
| 
								 | 
							
								} iot_brm_cache_cr_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if IOT_BRM_ENABLE
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_cache_insert() - insert data into cache.
							 | 
						||
| 
								 | 
							
								 * @param addr: owner address of the data
							 | 
						||
| 
								 | 
							
								 * @param type: data type, see iot_brm_cache_data_type_t.
							 | 
						||
| 
								 | 
							
								 * @param data: pointer to data
							 | 
						||
| 
								 | 
							
								 * @retval ERR_OK - for success case, othersie - error code.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t iot_brm_cache_insert(uint8_t *addr,
							 | 
						||
| 
								 | 
							
								    iot_brm_cache_data_type_t type, void *data);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_cache_find() - find the data of the specified address and time.
							 | 
						||
| 
								 | 
							
								 * @param addr:  specified address
							 | 
						||
| 
								 | 
							
								 * @param type:  data type, see iot_brm_cache_data_type_t.
							 | 
						||
| 
								 | 
							
								 * @param ts:    specified timestamp
							 | 
						||
| 
								 | 
							
								 * @param margin: if the specified time cannot be found, the earlier time data
							 | 
						||
| 
								 | 
							
								 *                is used. This is the allowable time margin.
							 | 
						||
| 
								 | 
							
								 * @retval: pointer to the data block found or NULL if no wafound.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void* iot_brm_cache_find(uint8_t *addr, iot_brm_cache_data_type_t type,
							 | 
						||
| 
								 | 
							
								    uint32_t ts, uint32_t margin);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_cache_init() - initializing the BRM cache module.
							 | 
						||
| 
								 | 
							
								 * @retval ERR_OK - for success case, othersie - error code.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t iot_brm_cache_init(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif /* IOT_BRM_ENABLE */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif /* __IOT_BRM_CACHE_H */
							 |