144 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			144 lines
		
	
	
		
			4.6 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_BSRM_UPGRADE_H
 | ||
|  | #define IOT_BSRM_UPGRADE_H
 | ||
|  | 
 | ||
|  | #if IOT_BSRM_MODE
 | ||
|  | 
 | ||
|  | #ifdef __cplusplus
 | ||
|  | extern "C" { | ||
|  | #endif
 | ||
|  | 
 | ||
|  | /* bsrm upgrade state */ | ||
|  | #define IOT_BSRM_UPGRADE_ST_INVALID                   0
 | ||
|  | #define IOT_BSRM_UPGRADE_ST_IDLE                      1
 | ||
|  | #define IOT_BSRM_UPGRADE_ST_RECEIVE                   2
 | ||
|  | #define IOT_BSRM_UPGRADE_ST_RECV_DONE                 3
 | ||
|  | #define IOT_BSRM_UPGRADE_ST_EXECUTE                   4
 | ||
|  | 
 | ||
|  | /* bsrm upgrade file max bitmap size */ | ||
|  | #define IOT_BSRM_BM_SIZE                            (1024)
 | ||
|  | /* bsrm upgrade file max size */ | ||
|  | #define IOT_BSRM_MAX_SIZE                           (512 * 1024)
 | ||
|  | 
 | ||
|  | /* opo device upgrade descriptor */ | ||
|  | typedef struct _iot_bsrm_upgrade { | ||
|  |     /* current running part */ | ||
|  |     uint32_t                current_part; | ||
|  |     /* index bitmap for bsrm receive block. */ | ||
|  |     uint8_t                 block_bitmap[IOT_BSRM_BM_SIZE]; | ||
|  |     /* upgrade status */ | ||
|  |     uint8_t                 state; | ||
|  |     /* upgrade id */ | ||
|  |     uint32_t                upgrade_id; | ||
|  |     /* total block cnt */ | ||
|  |     uint32_t                total_block_cnt; | ||
|  |     /* block size */ | ||
|  |     uint32_t                block_size; | ||
|  |     /* upgrade file crc value  */ | ||
|  |     uint32_t                crc; | ||
|  |     /* skip upgrade flag */ | ||
|  |     uint8_t                 skip; | ||
|  |     /* received data size */ | ||
|  |     uint32_t                received_size; | ||
|  |     /* total received block */ | ||
|  |     uint32_t                rec_block_cnt; | ||
|  |     /* window time of upgrade - unit: s */ | ||
|  |     uint32_t                window_tm; | ||
|  | } iot_bsrm_upgrade_t; | ||
|  | 
 | ||
|  | typedef struct _iot_bsrm_upgrade_info { | ||
|  |     /* bsrm upgrade status see - IOT_BSRM_UPGRADE_ST_XXX */ | ||
|  |     uint32_t    state; | ||
|  |     /* total block count of the upgrading file */ | ||
|  |     uint32_t    block_cnt; | ||
|  |     /* upgrade file crc value. */ | ||
|  |     uint32_t    crc; | ||
|  |     /* received block count */ | ||
|  |     uint32_t    recv_cnt; | ||
|  | } iot_bsrm_upgrade_info_t; | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief: init bsrm device upgrade. | ||
|  |  * @retval: init upgrade result, ERR_OK - init successful, others - fail. | ||
|  |  */ | ||
|  | uint32_t iot_bsrm_upgrade_init(); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief: deinit bsrm device upgrade. | ||
|  |  * @param bsrm_upgrade_handle: bsrm upgrade handle. | ||
|  |  */ | ||
|  | void iot_bsrm_upgrade_deinit(); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief: start bsrm device upgrade. | ||
|  |  * @param total_block_cnt: upgrade file total block count. | ||
|  |  * @param block_size: block size. | ||
|  |  * @retval: ERR_OK - successful, others - fail. | ||
|  |  */ | ||
|  | uint32_t iot_bsrm_upgrade_start(uint32_t total_block_cnt, uint32_t block_size); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief: handle upgrade data. | ||
|  |  * @param block_index: current upgrade data block index. | ||
|  |  * @param block_len: current upgrade data block length. | ||
|  |  * @param data: current upgrade data ptr. | ||
|  |  * @retval: ERR_OK - successful handle upgrade data, others - fail. | ||
|  |  */ | ||
|  | uint32_t iot_bsrm_upgrade_data(uint32_t block_index, uint32_t block_len, | ||
|  |     uint8_t *data); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief: stop upgrade. | ||
|  |  * @retval: ERR_OK - successful handle upgrade data, others - fail. | ||
|  |  */ | ||
|  | uint32_t iot_bsrm_upgrade_stop(); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief: exe upgrade, commit data, reset module. | ||
|  |  * @retval: ERR_OK - successful handle upgrade data, others - fail. | ||
|  |  */ | ||
|  | uint32_t iot_bsrm_upgrade_exe(); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief: psrm upgrade windows, stop upgrade when upgrade timeout. | ||
|  |  */ | ||
|  | void iot_bsrm_upgrade_windows(); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief: query bsrm upgrade info. | ||
|  |  * @retval: ERR_OK - successful, others - fail. | ||
|  |  */ | ||
|  | uint32_t iot_bsrm_query_upgrade_info(iot_bsrm_upgrade_info_t *query_info); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief:                get the upgrade file segment bitmap info, | ||
|  |  *                        invalid bitmap data set 0. | ||
|  |  * @param bitmap:         dec bitmap address. | ||
|  |  * @param start_index:    file segment bitmap offset address, start offset is 0. | ||
|  |  * @param size:           size of the dec bitmap. | ||
|  |  * @return:               valid dec bitmap size. | ||
|  |  */ | ||
|  | uint32_t iot_bsrm_upgrade_query_bitmap_info(uint8_t *bitmap, | ||
|  |     uint32_t start_index, uint32_t size); | ||
|  | 
 | ||
|  | #ifdef __cplusplus
 | ||
|  | } | ||
|  | #endif
 | ||
|  | 
 | ||
|  | #endif /* IOT_BSRM_MODE */
 | ||
|  | 
 | ||
|  | #endif /* IOT_BSRM_UPGRADE_H */
 |