77 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			77 lines
		
	
	
		
			2.0 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. | ||
|  | 
 | ||
|  | ****************************************************************************/ | ||
|  | 
 | ||
|  | #include "iot_errno_api.h"
 | ||
|  | #include "iot_app_pib_cco_api.h"
 | ||
|  | 
 | ||
|  | #if PLC_SUPPORT_CCO_ROLE
 | ||
|  | 
 | ||
|  | extern app_pib_rw_t *iot_get_rw_pib_info(void); | ||
|  | 
 | ||
|  | uint8_t iot_app_get_work_band_in_pib(void) | ||
|  | { | ||
|  |     uint8_t band = 0; | ||
|  |     app_pib_rw_t *pib_rw = iot_get_rw_pib_info(); | ||
|  | 
 | ||
|  |     if (pib_rw == NULL) { | ||
|  |         return band; | ||
|  |     } | ||
|  | 
 | ||
|  |     if (pib_rw->band_valid) { | ||
|  |         return pib_rw->work_band + 1; | ||
|  |     } | ||
|  | 
 | ||
|  |     return band; | ||
|  | } | ||
|  | 
 | ||
|  | uint8_t iot_app_save_work_band_to_pib(uint8_t work_band) | ||
|  | { | ||
|  |     uint16_t ticket; | ||
|  |     uint8_t ref; | ||
|  |     app_pib_rw_t *pib_rw = iot_get_rw_pib_info(); | ||
|  | 
 | ||
|  |     if (pib_rw == NULL) { | ||
|  |         return ERR_FAIL; | ||
|  |     } | ||
|  |     /* check band */ | ||
|  |     if (work_band > PLC_LIB_FREQ_BAND_MAX) { | ||
|  |         return ERR_NOSUPP; | ||
|  |     } | ||
|  | 
 | ||
|  |     iot_pib_acquire_app_commit_ref(&ref); | ||
|  |     pib_rw->band_valid = 1; | ||
|  |     pib_rw->work_band = work_band; | ||
|  |     iot_pib_release_app_commit_ref(&ref); | ||
|  |     iot_pib_app_commit(&ticket); | ||
|  | 
 | ||
|  |     return ERR_OK; | ||
|  | } | ||
|  | 
 | ||
|  | #else /* PLC_SUPPORT_CCO_ROLE */
 | ||
|  | 
 | ||
|  | uint8_t iot_app_get_work_band_in_pib(void) | ||
|  | { | ||
|  |      /* sta not support */ | ||
|  |     return 0; | ||
|  | } | ||
|  | 
 | ||
|  | uint8_t iot_app_save_work_band_to_pib(uint8_t work_band) | ||
|  | { | ||
|  |     (void)work_band; | ||
|  |     return ERR_FAIL; | ||
|  | } | ||
|  | 
 | ||
|  | #endif /* PLC_SUPPORT_CCO_ROLE */
 |