• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************/
18 
19 #ifndef STACK_BLE_SERVICE_OTA_OTA_SERVER_H_
20 #define STACK_BLE_SERVICE_OTA_OTA_SERVER_H_
21 
22 #include <ble_common.h>
23 
24 /**
25  * @brief	OTA start command callback declaration
26  */
27 typedef void (*ota_startCb_t)(void);
28 
29 /**
30  * @brief	OTA version callback declaration
31  */
32 typedef void (*ota_versionCb_t)(void);
33 
34 /**
35  * @brief		OTA result indicate callback declaration
36  * @param[in]   result - OTA result
37  */
38 typedef void (*ota_resIndicateCb_t)(int result);
39 
40 /**
41  * @brief      this function is used for user to initialize OTA server module.
42  * 			   // attention: this API must called before any other OTA relative settings.
43  * @param	   none
44  * @return     none
45  */
46 void blc_ota_initOtaServer_module(void);
47 
48 /**
49  * @brief      This function is used to set OTA new firmware storage address on Flash.
50  * 			   note: this function must be called before "sys_init" or "cpu_wakeup_init".
51  * @param[in]  firmware_size_k - set the firmware size. i.e. OTA erase flash size.note: unit is 1K(1024B)
52  * @param[in]  new_fw_addr - new firmware storage address, 1.choose from multiple boot address
53  * @return     Status - 0x00: command succeeded; 0x01-0xFF: command failed
54  */
55 ble_sts_t blc_ota_setFirmwareSizeAndBootAddress(int firmware_size_k, multi_boot_addr_e new_fw_addr);
56 
57 /**
58  * @brief      This function is used to set OTA firmware version number.
59  * 			   if user use version compare to decide if OTA update, should use this API to set firmware version.
60  * @param[in]  version_number - firmware version number
61  * @return     none
62  */
63 void blc_ota_setFirmwareVersionNumber(u16 version_number);
64 
65 /**
66  * @brief      This function is used to register OTA start command callback.
67  * 			   when local device receive OTA command  "CMD_OTA_START" and  "CMD_OTA_START_EXT"  form peer device,
68  * 			   after checking all parameters are correct, local device will enter OTA update
69  *             and trigger OTA start command callback.
70  * @param[in]  cb - callback function
71  * @return     none
72  */
73 void blc_ota_registerOtaStartCmdCb(ota_startCb_t cb);
74 
75 /**
76  * @brief      This function is used to register OTA version command callback
77  * 			   when local device receive OTA command  "CMD_OTA_VERSION", trigger this callback.
78  * @param[in]  cb - callback function
79  * @return     none
80  */
81 void blc_ota_registerOtaFirmwareVersionReqCb(ota_versionCb_t cb);
82 
83 /**
84  * @brief      This function is used to register OTA result indication callback
85  * @param[in]  cb - callback function
86  * @return     none
87  */
88 void blc_ota_registerOtaResultIndicationCb(ota_resIndicateCb_t cb);
89 
90 /**
91  * @brief      This function is used to set OTA whole process timeout value
92  * 			   if not set, default value is 30 S
93  * @param[in]  timeout_second - timeout value, unit: S, should in range of 4 ~ 250
94  * @return     Status - 0x00: command succeeded; 0x01-0xFF: command failed
95  */
96 ble_sts_t blc_ota_setOtaProcessTimeout(int timeout_second);
97 
98 /**
99  * @brief      This function is used to set OTA packet interval timeout value
100  * 			   if not set, default value is 5 S
101  * @param[in]  timeout_ms - timeout value, unit: mS, should in range of 1 ~ 20
102  * @return     Status - 0x00: command succeeded; 0x01-0xFF: command failed
103  */
104 ble_sts_t blc_ota_setOtaDataPacketTimeout(int timeout_second);
105 
106 /**
107  * @brief      This function is used to write OTA data to flash
108  * @param[in]  connHandle - ACL connection handle
109  * @return     p - GATT data buffer pointer of write_req or write_cmd
110  */
111 int otaWrite(u16 connHandle, void *p);
112 
113 #endif /* STACK_BLE_SERVICE_OTA_OTA_SERVER_H_ */
114