@@ -35,9 +35,6 @@ static uint8_t m_init_packet[64]; /**< Init packet
3535static uint8_t m_init_packet_length ; /**< Length of init packet received. */
3636static uint16_t m_image_crc ; /**< Calculated CRC of the image received. */
3737
38- APP_TIMER_DEF (m_dfu_timer_id ); /**< Application timer id. */
39- static bool m_dfu_timed_out = false; /**< Boolean flag value for tracking DFU timer timeout state. */
40-
4138static pstorage_handle_t m_storage_handle_app ; /**< Pstorage handle for the application area (bank 0). Bank used when updating a SoftDevice w/wo bootloader. Handle also used when swapping received application from bank 1 to bank 0. */
4239static pstorage_handle_t * mp_storage_handle_active ; /**< Pointer to the pstorage handle for the active bank for receiving of data packets. */
4340
@@ -83,47 +80,6 @@ static void pstorage_callback_handler(pstorage_handle_t * p_handle,
8380 APP_ERROR_CHECK (result );
8481}
8582
86-
87- /**@brief Function for handling the DFU timeout.
88- *
89- * @param[in] p_context The timeout context.
90- */
91- static void dfu_timeout_handler (void * p_context )
92- {
93- UNUSED_PARAMETER (p_context );
94- dfu_update_status_t update_status ;
95-
96- m_dfu_timed_out = true;
97- update_status .status_code = DFU_TIMEOUT ;
98-
99- bootloader_dfu_update_process (update_status );
100- }
101-
102-
103- /**@brief Function for restarting the DFU Timer.
104- *
105- * @details This function will stop and restart the DFU timer. This function will be called by the
106- * functions handling any DFU packet received from the peer that is transferring a firmware
107- * image.
108- */
109- static uint32_t dfu_timer_restart (void )
110- {
111- if (m_dfu_timed_out )
112- {
113- // The DFU timer had already timed out.
114- return NRF_ERROR_INVALID_STATE ;
115- }
116-
117- uint32_t err_code = app_timer_stop (m_dfu_timer_id );
118- APP_ERROR_CHECK (err_code );
119-
120- err_code = app_timer_start (m_dfu_timer_id , DFU_TIMEOUT_INTERVAL , NULL );
121- APP_ERROR_CHECK (err_code );
122-
123- return err_code ;
124- }
125-
126-
12783/**@brief Function for preparing of flash before receiving SoftDevice image.
12884 *
12985 * @details This function will erase current application area to ensure sufficient amount of
@@ -289,16 +245,6 @@ uint32_t dfu_init(void)
289245
290246 m_storage_handle_app .block_id = DFU_BANK_0_REGION_START ;
291247
292- // Create the timer to monitor the activity by the peer doing the firmware update.
293- err_code = app_timer_create (& m_dfu_timer_id ,
294- APP_TIMER_MODE_SINGLE_SHOT ,
295- dfu_timeout_handler );
296- APP_ERROR_CHECK (err_code );
297-
298- // Start the DFU timer.
299- err_code = app_timer_start (m_dfu_timer_id , DFU_TIMEOUT_INTERVAL , NULL );
300- APP_ERROR_CHECK (err_code );
301-
302248 m_data_received = 0 ;
303249 m_dfu_state = DFU_STATE_IDLE ;
304250
@@ -314,8 +260,6 @@ void dfu_register_callback(dfu_callback_t callback_handler)
314260
315261uint32_t dfu_start_pkt_handle (dfu_update_packet_t * p_packet )
316262{
317- uint32_t err_code ;
318-
319263 m_start_packet = * (p_packet -> params .start_packet );
320264
321265 // Check that the requested update procedure is supported.
@@ -367,22 +311,11 @@ uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet)
367311 m_functions .activate = dfu_activate_app ;
368312 }
369313
370- switch (m_dfu_state )
371- {
372- case DFU_STATE_IDLE :
373- // Valid peer activity detected. Hence restart the DFU timer.
374- err_code = dfu_timer_restart ();
375- VERIFY_SUCCESS (err_code );
376- m_functions .prepare (m_image_size );
314+ if ( DFU_STATE_IDLE != m_dfu_state ) return NRF_ERROR_INVALID_STATE ;
377315
378- break ;
316+ m_functions . prepare ( m_image_size ) ;
379317
380- default :
381- err_code = NRF_ERROR_INVALID_STATE ;
382- break ;
383- }
384-
385- return err_code ;
318+ return NRF_SUCCESS ;
386319}
387320
388321
@@ -422,10 +355,6 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet)
422355 return NRF_ERROR_DATA_SIZE ;
423356 }
424357
425- // Valid peer activity detected. Hence restart the DFU timer.
426- err_code = dfu_timer_restart ();
427- VERIFY_SUCCESS (err_code );
428-
429358 p_data = (uint32_t * )p_packet -> params .data_packet .p_data_packet ;
430359
431360 if ( is_ota () )
@@ -493,7 +422,6 @@ uint32_t dfu_init_pkt_complete(void)
493422
494423uint32_t dfu_init_pkt_handle (dfu_update_packet_t * p_packet )
495424{
496- uint32_t err_code = NRF_SUCCESS ;
497425 uint32_t length ;
498426
499427 switch (m_dfu_state )
@@ -511,10 +439,6 @@ uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet)
511439 return NRF_ERROR_INVALID_STATE ;
512440 }
513441
514- // Valid peer activity detected. Hence restart the DFU timer.
515- err_code = dfu_timer_restart ();
516- VERIFY_SUCCESS (err_code );
517-
518442 length = p_packet -> params .data_packet .packet_length * sizeof (uint32_t );
519443 if ((m_init_packet_length + length ) > sizeof (m_init_packet ))
520444 {
@@ -529,11 +453,10 @@ uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet)
529453
530454 default :
531455 // Either the start packet was not received or dfu_init function was not called before.
532- err_code = NRF_ERROR_INVALID_STATE ;
533- break ;
456+ return NRF_ERROR_INVALID_STATE ;
534457 }
535458
536- return err_code ;
459+ return NRF_SUCCESS ;
537460}
538461
539462
@@ -555,16 +478,9 @@ uint32_t dfu_image_validate()
555478 {
556479 m_dfu_state = DFU_STATE_VALIDATE ;
557480
558- // Valid peer activity detected. Hence restart the DFU timer.
559- err_code = dfu_timer_restart ();
560- if (err_code == NRF_SUCCESS )
561- {
562- err_code = dfu_init_postvalidate ((uint8_t * )mp_storage_handle_active -> block_id ,
563- m_image_size );
564- VERIFY_SUCCESS (err_code );
565-
566- m_dfu_state = DFU_STATE_WAIT_4_ACTIVATE ;
567- }
481+ err_code = dfu_init_postvalidate ((uint8_t * )mp_storage_handle_active -> block_id , m_image_size );
482+ VERIFY_SUCCESS (err_code );
483+ m_dfu_state = DFU_STATE_WAIT_4_ACTIVATE ;
568484 }
569485 break ;
570486
@@ -584,11 +500,6 @@ uint32_t dfu_image_activate()
584500 switch (m_dfu_state )
585501 {
586502 case DFU_STATE_WAIT_4_ACTIVATE :
587-
588- // Stop the DFU Timer because the peer activity need not be monitored any longer.
589- err_code = app_timer_stop (m_dfu_timer_id );
590- APP_ERROR_CHECK (err_code );
591-
592503 err_code = m_functions .activate ();
593504 break ;
594505
0 commit comments