static void antfs_event_upload_fail_handle(const antfs_event_return_t * p_event) { if (m_antfs_dfu_state == ANTFS_DFU_STATE_READY) // All other failure like RF transfers. { UNUSED_VARIABLE(antfs_upload_data_resp_transmit(false)); } }
/**@brief Function for processing ANTFS upload complete event. */ static __INLINE void event_upload_complete_handle(void) { printf("ANTFS_EVENT_UPLOAD_COMPLETE\n"); // @note: Suppress return value as no use case for handling it exists. UNUSED_VARIABLE(antfs_upload_data_resp_transmit(m_upload_success)); if (m_upload_success) { m_file_offset = 0; } }
static void antfs_event_upload_complete_handle(const antfs_event_return_t * p_event) { uint32_t err_code; if (m_antfs_dfu_state == ANTFS_DFU_STATE_VALIDATED) { // only send this response if we have validated the upload UNUSED_VARIABLE(antfs_upload_data_resp_transmit(true)); } else if (m_antfs_dfu_state == ANTFS_DFU_STATE_READY) { if (flash_busy()) { m_antfs_dfu_state = ANTFS_DFU_STATE_FLASH_PENDING; // Image completed but still busy writing, postpone it on flash call back. return; } if (m_image_data_complete == true) { err_code = dfu_image_validate(m_header_crc_seed); if (err_code == NRF_SUCCESS) { m_antfs_dfu_state = ANTFS_DFU_STATE_VALIDATED; UNUSED_VARIABLE(antfs_upload_data_resp_transmit(true)); } else { upload_data_response_fail_reset(); } } else { UNUSED_VARIABLE(antfs_upload_data_resp_transmit(true)); // This is expected on block transfers. } } else { // no implementation } }
/* * NOTE: This callback is only called by the following * - Storing done operation by dfu_data_pkt_handle * - And all clearing done operation. */ static void dfu_cb_handler(uint32_t result, uint8_t * p_data) { uint32_t err_code; uint16_t rxd_buffer_len = 0; uint16_t ram_crc = 0; uint16_t flash_crc = 0; #if defined (DBG_DFU_UART_OUT_PIN) DEBUG_UART_OUT(0xFF); DEBUG_UART_OUT(m_antfs_dfu_state); #endif switch (m_antfs_dfu_state) { case ANTFS_DFU_STATE_INIT_DELAYED: // This is when upon initialization, a pre-erase operation have occured i.e. bank1 pre clearing. services_init(); break; case ANTFS_DFU_STATE_FLASH_ERASE: // Handles upload and download request response delay when there is ongoing flash activities // Generally we need to avoid flash activities and burst activities to happen at the same time. // ANTFS request response are delayed and when flash is done response are handled here. if (m_upload_request_in_progress) { m_upload_request_in_progress = false; // Make sure we got all the latest values. m_response_info.file_size.data = m_current_offset; m_response_info.file_crc = m_current_crc; if (result == NRF_SUCCESS) { m_upload_swap_space_prepared = true; UNUSED_VARIABLE(antfs_upload_req_resp_transmit(RESPONSE_MESSAGE_OK, &m_response_info)); } else { /* Not ready */ UNUSED_VARIABLE(antfs_upload_req_resp_transmit(RESPONSE_MESSAGE_UPLOAD_NOT_READY, &m_response_info)); } } if (m_download_request_in_progress) { m_download_request_in_progress = false; UNUSED_VARIABLE(antfs_download_req_resp_prepare(RESPONSE_MESSAGE_OK, &m_response_info)); } m_antfs_dfu_state = ANTFS_DFU_STATE_READY; break; case ANTFS_DFU_STATE_FLASH_PENDING: case ANTFS_DFU_STATE_READY: // Handles Flash write call back queued by Upload Data. if (result != NRF_SUCCESS) { upload_data_response_fail_reset(); return; } if ((m_mem_pool_1.a_mem_pool <= p_data) && (p_data <= (m_mem_pool_1.a_mem_pool + ANTFS_UPLOAD_DATA_BUFFER_MAX_SIZE))) { rxd_buffer_len = m_mem_pool_1.size; ram_crc = m_mem_pool_1.crc; m_mem_pool_1.size = 0; } else if ((m_mem_pool_2.a_mem_pool <= p_data) && (p_data <= (m_mem_pool_2.a_mem_pool + ANTFS_UPLOAD_DATA_BUFFER_MAX_SIZE))) { rxd_buffer_len = m_mem_pool_2.size; ram_crc = m_mem_pool_2.crc; m_mem_pool_2.size = 0; } else { upload_data_response_fail_reset(); return; } // Verify the data written to flash. flash_crc = crc_crc16_update(0, (uint8_t*)(dfu_storage_start_address_get() + m_image_data_offset), rxd_buffer_len); if (flash_crc != ram_crc) { upload_data_response_fail_reset(); return; } //update current offsets and crc m_current_offset += rxd_buffer_len; m_current_crc = crc_crc16_update(m_current_crc, (uint8_t*)(dfu_storage_start_address_get() + m_image_data_offset), rxd_buffer_len); m_image_data_offset += rxd_buffer_len; if (m_antfs_dfu_state == ANTFS_DFU_STATE_FLASH_PENDING) { m_antfs_dfu_state = ANTFS_DFU_STATE_READY; // Update it with the latest values; m_response_info.file_size.data = m_current_offset; m_response_info.file_crc = m_current_crc; if (m_upload_request_in_progress) { m_upload_request_in_progress = false; UNUSED_VARIABLE(antfs_upload_req_resp_transmit(RESPONSE_MESSAGE_OK, &m_response_info)); } else // data response { if (m_image_data_complete == true) { if (m_image_data_max == m_image_data_offset) { err_code = dfu_image_validate(m_header_crc_seed); if (err_code == NRF_SUCCESS) { UNUSED_VARIABLE(antfs_upload_data_resp_transmit(true)); m_antfs_dfu_state = ANTFS_DFU_STATE_VALIDATED; return; } else { upload_data_response_fail_reset(); } } if ((m_mem_pool_1.size != 0) || (m_mem_pool_2.size != 0)) { m_antfs_dfu_state = ANTFS_DFU_STATE_FLASH_PENDING; } } else //m_image_data_complete == false { if ((m_mem_pool_1.size == 0) && (m_mem_pool_2.size == 0)) { UNUSED_VARIABLE(antfs_upload_data_resp_transmit(true)); // Handles block transfers } else { m_antfs_dfu_state = ANTFS_DFU_STATE_FLASH_PENDING; } } } } break; default: break; } }
static void upload_data_response_fail_reset(void) { UNUSED_VARIABLE(antfs_upload_data_resp_transmit(false)); m_antfs_dfu_state = ANTFS_DFU_STATE_STALL; }
/**@brief Function for processing a single ANTFS event. * * @param[in] p_event The event extracted from the queue to be processed. */ static void antfs_event_process(const antfs_event_return_t * p_event) { switch (p_event->event) { case ANTFS_EVENT_OPEN_COMPLETE: printf("ANTFS_EVENT_OPEN_COMPLETE\n"); break; case ANTFS_EVENT_CLOSE_COMPLETE: printf("ANTFS_EVENT_CLOSE_COMPLETE\n"); break; case ANTFS_EVENT_LINK: printf("ANTFS_EVENT_LINK\n"); break; case ANTFS_EVENT_AUTH: printf("ANTFS_EVENT_AUTH\n"); break; case ANTFS_EVENT_TRANS: printf("ANTFS_EVENT_TRANS\n"); break; case ANTFS_EVENT_PAIRING_REQUEST: printf("ANTFS_EVENT_PAIRING_REQUEST\n"); event_pairing_request_handle(); break; case ANTFS_EVENT_PAIRING_TIMEOUT: printf("ANTFS_EVENT_PAIRING_TIMEOUT\n"); break; case ANTFS_EVENT_DOWNLOAD_REQUEST: printf("ANTFS_EVENT_DOWNLOAD_REQUEST\n"); event_download_request_handle(p_event); break; case ANTFS_EVENT_DOWNLOAD_START: printf("ANTFS_EVENT_DOWNLOAD_START\n"); break; case ANTFS_EVENT_DOWNLOAD_REQUEST_DATA: event_download_data_handle(p_event); break; case ANTFS_EVENT_DOWNLOAD_COMPLETE: printf("ANTFS_EVENT_DOWNLOAD_COMPLETE\n"); break; case ANTFS_EVENT_DOWNLOAD_FAIL: printf("ANTFS_EVENT_DOWNLOAD_FAIL\n"); break; case ANTFS_EVENT_UPLOAD_REQUEST: printf("ANTFS_EVENT_UPLOAD_REQUEST\n"); event_upload_request_handle(p_event); break; case ANTFS_EVENT_UPLOAD_START: printf("ANTFS_EVENT_UPLOAD_START\n"); break; case ANTFS_EVENT_UPLOAD_DATA: event_upload_data_handle(p_event); break; case ANTFS_EVENT_UPLOAD_FAIL: printf("ANTFS_EVENT_UPLOAD_FAIL\n"); // @note: Suppress return value as no use case for handling it exists. UNUSED_VARIABLE(antfs_upload_data_resp_transmit(false)); break; case ANTFS_EVENT_UPLOAD_COMPLETE: printf("ANTFS_EVENT_UPLOAD_COMPLETE\n"); event_upload_complete_handle(); break; case ANTFS_EVENT_ERASE_REQUEST: printf("ANTFS_EVENT_ERASE_REQUEST\n"); event_erase_request_handle(p_event); break; default: break; } }