178 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			178 lines
		
	
	
		
			5.8 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_H
 | |||
|  | #define IOT_SUNSOLAR_STA_H
 | |||
|  | 
 | |||
|  | /* os shim includes */ | |||
|  | #include "os_types_api.h"
 | |||
|  | #include "os_timer_api.h"
 | |||
|  | 
 | |||
|  | /* common includes */ | |||
|  | #include "proto_645.h"
 | |||
|  | #include "iot_task_api.h"
 | |||
|  | 
 | |||
|  | #ifdef __cplusplus
 | |||
|  | extern "C" { | |||
|  | #endif
 | |||
|  | 
 | |||
|  | /* max pv number of this module. */ | |||
|  | #define LOCAL_PV_MAX                                        (2)
 | |||
|  | 
 | |||
|  | /* calibration time, if time is too large unit:s */ | |||
|  | #define IOT_SOLR_STA_CHECK_RTC_TIME                         (2)
 | |||
|  | 
 | |||
|  | /* 输入电压阈值:当高于此值,才打开RSD的输出,单位: 0.1V */ | |||
|  | #define IOT_SUNSOLAR_STA_LOW_VOLT_RESUME_THR                (120)
 | |||
|  | 
 | |||
|  | /* 输入电压过低触发输出关断后,到重新打开输出的时间计数,单位:0.25s */ | |||
|  | #define IOT_SUNSOLAR_STA_LOW_VOLT_RESUME_CHK_DELAY          (8)
 | |||
|  | 
 | |||
|  | /* max inactive duration not receive heartbeat to disable RSD output,
 | |||
|  |  * unit: sec | |||
|  |  */ | |||
|  | #define IOT_SUNSOLAR_CCTT_MAX_INACTIVE_DUR                  (30)
 | |||
|  | 
 | |||
|  | /* size of received upgrade data bitmap */ | |||
|  | #define IOT_SUNSOLAR_UPGRADE_BM_SIZE                        (1024)
 | |||
|  | /* recv upgrade data length once time */ | |||
|  | #define IOT_SUNSOLAR_UPGRADE_BLOCK_SIZE                     (200)
 | |||
|  | /* receive upgrade data max lost count */ | |||
|  | #define IOT_SUNSOLAR_UPGRADE_DATA_LOST_CNT_MAX              (60)
 | |||
|  | 
 | |||
|  | /* rsd func info */ | |||
|  | typedef struct _iot_sunsolar_sta_rsd_ctrl_t { | |||
|  |     /* RSD gpio */ | |||
|  |     uint8_t             rsd_io; | |||
|  |     /* RSD led control gpio, low level on  */ | |||
|  |     uint8_t             rsd_led; | |||
|  |     /* RSD check voltage 0.1V */ | |||
|  |     uint16_t            rsd_volt; | |||
|  | } iot_sunsolar_sta_rsd_ctrl_t; | |||
|  | 
 | |||
|  | typedef struct _iot_sunsolar_sta_rsd_state_t { | |||
|  |     /* the rsd ctrl output src bitmap */ | |||
|  |     uint8_t             off_src_bm; | |||
|  |     /* RSD real time status */ | |||
|  |     uint8_t             real_status; | |||
|  | } iot_sunsolar_sta_rsd_logic_state_t; | |||
|  | 
 | |||
|  | /* define RSD trigger source */ | |||
|  | typedef enum _rsd_out_trig_src_t { | |||
|  |     RSD_TRIG_SRC_CMD, | |||
|  |     RSD_TRIG_SRC_HEARTBEAT, | |||
|  |     RSD_TRIG_SRC_PV0_LOW_VOLT, | |||
|  |     RSD_TRIG_SRC_PV1_LOW_VOLT | |||
|  | } rsd_out_trig_src_t; | |||
|  | 
 | |||
|  | /* dev states data struct */ | |||
|  | typedef struct _dev_state_e_t { | |||
|  |     /* unit is 0.1V */ | |||
|  |     uint16_t         voltage; | |||
|  |     /* unit is 0.1C */ | |||
|  |     int16_t          temperature; | |||
|  |     /* unit is mA */ | |||
|  |     uint16_t         current; | |||
|  |     /* period all power out  unit:mWh */ | |||
|  |     uint32_t         period_energy; | |||
|  |     /* history total energy  unit:mWh */ | |||
|  |     uint64_t         total_energy; | |||
|  |     /* sunsolar low volt produce to restart open output' all time count n,
 | |||
|  |      * all time = n * 0.25s | |||
|  |      */ | |||
|  |     uint8_t          low_volt_resume_chk_cold; | |||
|  |     /* flag to mark if this photovoltaic panle output low voltage */ | |||
|  |     uint8_t          low_volt    : 1, | |||
|  |     /* reserved for future */ | |||
|  |                      rsvd        : 7; | |||
|  |     /* rsd info */ | |||
|  |     iot_sunsolar_sta_rsd_ctrl_t rsd_ctrl; | |||
|  | } dev_state_e_t; | |||
|  | 
 | |||
|  | /* sunsolar heart beat info */ | |||
|  | typedef struct _iot_sunsolar_sta_hb_info { | |||
|  |     /* last heartbeat time */ | |||
|  |     uint32_t            last_hb_tm; | |||
|  |     /* heartbeat time out flag */ | |||
|  |     uint8_t             hb_timeout_flag; | |||
|  | } iot_sunsolar_sta_hb_info; | |||
|  | 
 | |||
|  | typedef struct _iot_sunsolar_upgrade_file { | |||
|  |     /* index bitmap for sta receive block from cctt. */ | |||
|  |     uint8_t             block_bitmap[IOT_SUNSOLAR_UPGRADE_BM_SIZE]; | |||
|  |     /* upgrade file total count */ | |||
|  |     uint16_t            total_cnt; | |||
|  | } iot_sunsolar_upgrade_file_t; | |||
|  | 
 | |||
|  | typedef struct _iot_sunsolar_sta_global { | |||
|  |     /* buffer is used to cache protocol data */ | |||
|  |     uint8_t             proto_buff[PROTO_645_MAX_PKT_LEN]; | |||
|  |     /* dev check timer handle */ | |||
|  |     timer_id_t          dev_check_timer; | |||
|  |     /* dev reset timer handle */ | |||
|  |     timer_id_t          dev_reboot_timer; | |||
|  |     /* device state */ | |||
|  |     dev_state_e_t       dev_state[LOCAL_PV_MAX]; | |||
|  |     /* local pv count */ | |||
|  |     uint8_t             pv_count; | |||
|  |     /* cache reboot type, see PROTO_645_SUNSOLAR_REBOOT_TYPE_XX */ | |||
|  |     uint8_t             reboot_type; | |||
|  |     /* record every time cctt's time */ | |||
|  |     iot_time_tm_t       last_cctt_tm; | |||
|  |     /* sunsolar heart beat info */ | |||
|  |     iot_sunsolar_sta_hb_info            hb_info; | |||
|  |     /* rsd function, pv0,pv1 public rsd state */ | |||
|  |     iot_sunsolar_sta_rsd_logic_state_t  rsd_logic_state; | |||
|  |     /* upgrade id for diffrent */ | |||
|  |     uint32_t                            upgrade_id; | |||
|  |     /* upgrade file info */ | |||
|  |     iot_sunsolar_upgrade_file_t         file_info; | |||
|  | } iot_sunsolar_sta_global_t; | |||
|  | 
 | |||
|  | /**
 | |||
|  |  * @brief iot_sunsolar_sta_get_reboot_cnt() -  get total reboot count | |||
|  |  * @return:  total reboot count | |||
|  |  */ | |||
|  | uint16_t iot_sunsolar_sta_get_reboot_cnt(void); | |||
|  | 
 | |||
|  | #if (IOT_SUNSOLAR_APP_ENABLE && PLC_SUPPORT_STA_ROLE)
 | |||
|  | 
 | |||
|  | /**
 | |||
|  |  * @brief    iot_sunsolar_sta_init() - init sunsolar sta role device specific | |||
|  |  *           operation. | |||
|  |  * @return:  0    -   for success case | |||
|  |  * @return:  otherwise   -   error number | |||
|  |  */ | |||
|  | uint32_t iot_sunsolar_sta_init(); | |||
|  | 
 | |||
|  | /**
 | |||
|  |  * @brief iot_sunsolar_sta_deinit() - deinit sunsolar sta role device specific | |||
|  |  *        operation. | |||
|  |  */ | |||
|  | void iot_sunsolar_sta_deinit(); | |||
|  | 
 | |||
|  | #else /* IOT_SUNSOLAR_APP_ENABLE && PLC_SUPPORT_STA_ROLE */
 | |||
|  | 
 | |||
|  | #define iot_sunsolar_sta_init()   (ERR_NOSUPP)
 | |||
|  | 
 | |||
|  | #define iot_sunsolar_sta_deinit()
 | |||
|  | 
 | |||
|  | #endif /* IOT_SUNSOLAR_APP_ENABLE && PLC_SUPPORT_STA_ROLE */
 | |||
|  | 
 | |||
|  | #ifdef __cplusplus
 | |||
|  | } | |||
|  | #endif
 | |||
|  | 
 | |||
|  | #endif /* IOT_SUNSOLAR_STA_H */
 |