/**@brief Function for freeing an element. * * @param[in] element_index index of the element. */ static uint32_t data_queue_element_free(uint8_t element_index) { uint8_t * p_data; uint32_t retval; retval = NRF_ERROR_INVALID_PARAM; if (MAX_BUFFERS > element_index) { p_data = (uint8_t *)DATA_QUEUE_ELEMENT_GET_PDATA(element_index); if (INVALID_PACKET != DATA_QUEUE_ELEMENT_GET_PTYPE(element_index)) { m_data_queue.count--; data_queue_element_init (element_index); retval = hci_transport_rx_pkt_consume((p_data - 4)); APP_ERROR_CHECK(retval); } } else { return NRF_ERROR_INVALID_PARAM; } return NRF_SUCCESS; }
/**@brief Function for Allocating element. * * @param[in] packet_type packet type. * @param[out] p_element_index index of the element. */ static uint32_t data_queue_element_alloc(uint8_t * p_element_index, uint8_t packet_type) { uint32_t retval; uint32_t index; retval = NRF_ERROR_NO_MEM; if (INVALID_PACKET == packet_type) { retval = NRF_ERROR_INVALID_PARAM; } else if (true == DATA_QUEUE_FULL()) { retval = NRF_ERROR_NO_MEM; } else { for (index = 0; index < MAX_BUFFERS; index++) { if (INVALID_PACKET == DATA_QUEUE_ELEMENT_GET_PTYPE(index)) { // Found a free element: allocate, and end search. *p_element_index = index; DATA_QUEUE_ELEMENT_SET_PTYPE(index, packet_type); retval = NRF_SUCCESS; m_data_queue.count++; break; } } } return retval; }
static void process_dfu_packet(void * p_event_data, uint16_t event_size) { uint32_t retval; uint32_t index; dfu_update_packet_t * packet; while (false == DATA_QUEUE_EMPTY()) { // Fetch the element to be processed. for (index = 0; index < MAX_BUFFERS ; index++) { packet = &m_data_queue.data_packet[index]; if (INVALID_PACKET != packet->packet_type) { switch (DATA_QUEUE_ELEMENT_GET_PTYPE(index)) { case DATA_PACKET: (void)dfu_data_pkt_handle(packet); break; case START_PACKET: packet->params.start_packet = (dfu_start_packet_t*)packet->params.data_packet.p_data_packet; retval = dfu_start_pkt_handle(packet); APP_ERROR_CHECK(retval); break; case STOP_DATA_PACKET: (void)dfu_image_validate(); (void)dfu_image_activate(); // Break the loop by returning. return; case INIT_PACKET: // Validate init packet. // We expect to receive the init packet in two rounds of 512 bytes. // If that fails, we abort, and boot the application. // @note: Current release doesn't handle an init packet. break; default: // No implementation needed. break; } // Free the processed element. retval = data_queue_element_free(index); APP_ERROR_CHECK(retval); } } } }
static void process_dfu_packet(void * p_event_data, uint16_t event_size) { uint32_t retval; uint32_t index; dfu_update_packet_t * packet; while (false == DATA_QUEUE_EMPTY()) { // Fetch the element to be processed. for (index = 0; index < MAX_BUFFERS ; index++) { packet = &m_data_queue.data_packet[index]; if (INVALID_PACKET != packet->packet_type) { switch (DATA_QUEUE_ELEMENT_GET_PTYPE(index)) { case DATA_PACKET: (void)dfu_data_pkt_handle(packet); break; case START_PACKET: packet->params.start_packet = (dfu_start_packet_t*)packet->params.data_packet.p_data_packet; retval = dfu_start_pkt_handle(packet); APP_ERROR_CHECK(retval); break; case INIT_PACKET: (void)dfu_init_pkt_handle(packet); retval = dfu_init_pkt_complete(); APP_ERROR_CHECK(retval); break; case STOP_DATA_PACKET: (void)dfu_image_validate(); (void)dfu_image_activate(); // Break the loop by returning. return; default: // No implementation needed. break; } // Free the processed element. retval = data_queue_element_free(index); APP_ERROR_CHECK(retval); } } } }