| BlueNRG-1 DK: BLE examples

- Main Page
- Modules
- Files

- File List

OTA_ServiceManager_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : OTA_ServiceManager_main.c
4 * Author : VMA DIVISION
5 * Version : 1.1.0
6 * Date : 15-January-2016
7 * Description : Code demostrating the BLE OTA Service Manager application
8 ********************************************************************************
9 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15 *******************************************************************************/
16
169 /* Includes ------------------------------------------------------------------*/
170 #include <stdio.h>
171 #include <string.h>
172 #include "BlueNRG1_conf.h"
173 #include "bluenrg1_stack.h"
174 #include "clock.h"
175 #include "sleep.h"
176
177 #include "OTA_ServiceManager.h"
178 #include "OTA_ServiceManager_config.h"
179 #include "ble_const.h"
180 #include "SDK_EVAL_Config.h"
181 #include "OTA_btl.h"
182 #include "BluenRG1_flash.h"
183 #include "bluenrg1_it_stub.h"
184
185 /* Private typedef -----------------------------------------------------------*/
186 typedef void (*pFunction)(void);
187 /* Private define ------------------------------------------------------------*/
188 #define RESET_WAKE_DEEPSLEEP_REASONS 0x05
189
190 #define BLE_OTA_SERVICE_MANAGER_VERSION_STRING "1.0.0"
191
192 /* Private macro -------------------------------------------------------------*/
193 /* Private variables ---------------------------------------------------------*/
194
195 /* Private function prototypes -----------------------------------------------*/
196
204 static void OTA_Erase_Flash(uint16_t startNumber, uint16_t endNumber)
205 {
206 uint16_t k;
207
208 for(k=startNumber;k<=endNumber;k++)
209 {
210 FLASH_ErasePage(k);
211 }
212
213 }
214
223 static void OTA_Check_ServiceManager_Operation(void)
224 {
225 if ((*(uint32_t *)(OTA_SERVICE_MANAGER_RAM_LOCATION)) == OTA_APP_SWITCH_OP_CODE_GO_TO_OTA_SERVICE_MANAGER) //Go to OTA Service manager
226 {
227 /* Set Invalid valid tag x OTA Application with OTA Service Manager for allowing jumping to OTA Service manager */
228 FLASH_ProgramWord(APP_WITH_OTA_SERVICE_ADDRESS + OTA_TAG_VECTOR_TABLE_ENTRY_OFFSET,OTA_INVALID_OLD_TAG);
229
230 /* Reset Service Manager ram location */
231 (*(uint32_t *)(OTA_SERVICE_MANAGER_RAM_LOCATION)) = OTA_INVALID_OLD_TAG;
232 }
233 }
234
244 static uint32_t OTA_Check_Application_Tags_Value(void)
245 {
246 uint32_t appAddress = 0;
247
248 if (((TAG_VALUE(APP_OTA_SERVICE_ADDRESS) == OTA_SERVICE_MANAGER_TAG) && (TAG_VALUE(APP_WITH_OTA_SERVICE_ADDRESS) == OTA_IN_PROGRESS_TAG))|| /* 10 */
249 ((TAG_VALUE(APP_OTA_SERVICE_ADDRESS) == OTA_SERVICE_MANAGER_TAG) && (TAG_VALUE(APP_WITH_OTA_SERVICE_ADDRESS) == OTA_INVALID_OLD_TAG))) /* 11 */
250 {
251 /* Jump to OTA Service Manager Application */
252 appAddress = APP_OTA_SERVICE_ADDRESS;
253 }
254 else if ((TAG_VALUE(APP_OTA_SERVICE_ADDRESS) == OTA_SERVICE_MANAGER_TAG) && (TAG_VALUE(APP_WITH_OTA_SERVICE_ADDRESS) == OTA_VALID_TAG)) /* 12 */
255 {
256 /* Jump to Application using OTA Service Manager */
257 appAddress = APP_WITH_OTA_SERVICE_ADDRESS;
258 }
259
260 return appAddress;
261 }
262
263 int main(void)
264 {
265 pFunction Jump_To_Application;
266 uint32_t JumpAddress, appAddress;
267 uint8_t ret;
268
269 /* Check Service manager RAM Location to verify if a jump to Service Manager has been set from the Application */
270 OTA_Check_ServiceManager_Operation();
271
272 /* Identifies the valid application where to jump based on the OTA application validity tags values placed on
273 reserved vector table entry: OTA_TAG_VECTOR_TABLE_ENTRY_INDEX */
274 appAddress = OTA_Check_Application_Tags_Value();
275
276 /* Check if there is a valid application where to jump */
277 if (appAddress == APP_WITH_OTA_SERVICE_ADDRESS)
278 {
279 /* Jump to user application */
280 JumpAddress = *(__IO uint32_t*) (appAddress + 4);
281 Jump_To_Application = (pFunction) JumpAddress;
282 /* Initialize user application's Stack Pointer */
283 __set_MSP(*(__IO uint32_t*) appAddress);
284 Jump_To_Application();
285
286 /* Infinite loop */
287 while (1)
288 {
289 }
290 }
291
292 /* Here Ota Service Manager Application is started */
293
294 /* System Init */
295 SystemInit();
296
297 /* Identify BlueNRG1 platform */
298 SdkEvalIdentification();
299
300 Clock_Init();
301 SdkEvalComUartInit(UART_BAUDRATE);
302
303 /* Erase the storage area from start page to end page */
304 OTA_Erase_Flash(APP_WITH_OTA_SERVICE_PAGE_NUMBER_START,APP_WITH_OTA_SERVICE_PAGE_NUMBER_END);
305
306 /* BlueNRG-1 stack init */
307 ret = BlueNRG_Stack_Initialization(&BlueNRG_Stack_Init_params);
308 if (ret != BLE_STATUS_SUCCESS) {
309 PRINTF("Error in BlueNRG_Stack_Initialization() 0x%02x\r\n", ret);
310 while(1);
311 }
312
313 PRINTF("\r\nBlueNRG-1 BLE OTA Service Manager (version: %s)\r\n", BLE_OTA_SERVICE_MANAGER_VERSION_STRING);
314
315 /* Init OTA Service Manager Device */
316 ret = OTA_ServiceManager_DeviceInit();
317 if (ret != BLE_STATUS_SUCCESS) {
318 PRINTF("OTA_ServiceManager_DeviceInit()--> Failed 0x%02x\r\n", ret);
319 while(1);
320 }
321
322 while(1)
323 {
324 /* BlueNRG-1 stack tick */
325 BTLE_StackTick();
326
327 /* Application tick */
328 APP_Tick();
329
330 /* Check if the OTA firmware upgrade session has been completed */
331 if (OTA_Tick() == 1)
332 {
333 /* Jump to the new application */
334 OTA_Jump_To_New_Application();
335 }
336 BlueNRG_Sleep(SLEEPMODE_NOTIMER, 0, 0, 0);
337 }
338
339 }
340
341 #ifdef USE_FULL_ASSERT
342 /*******************************************************************************
343 * Function Name : assert_failed
344 * Description : Reports the name of the source file and the source line number
345 * where the assert_param error has occurred.
346 * Input : - file: pointer to the source file name
347 * - line: assert_param error line source number
348 * Output : None
349 * Return : None
350 *******************************************************************************/
351 void assert_failed(uint8_t* file, uint32_t line)
352 {
353 /* User can add his own implementation to report the file name and line number,
354 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
355
356 /* Infinite loop */
357 while (1)
358 {}
359 }
360 #endif
361
362 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/