int main() { TIMER_TYPE s, e; // Generate shortcut for m_cost=0 printf("**** Generating shortcut for t_cost=100000 and m_cost=0 ****\n"); TIMER_FUNC(s); PHS_break(100000, 0, 32, false); TIMER_FUNC(e); printf("Took %0.2f seconds\n", TIMER_DIFF(s, e)); // Benchmark m_cost=0 printf("\n\n**** Benchmarking constant time t_cost=100000 and m_cost=0 ****\n"); benchmarkNoMem(4); // Access pattern printf("\n\n**** Access pattern m_cost=50000 ****\n"); accessPattern(50000); // Generate shortcut for m_cost=5000 printf("\n\n**** Generating shortcut for m_cost=5000 ****\n"); printf("Current version...\n"); TIMER_FUNC(s); PHS_break(0, 5000, 32, false); TIMER_FUNC(e); printf("Took %0.2f seconds\n\n", TIMER_DIFF(s, e)); printf("Fixed version...\n"); TIMER_FUNC(s); PHS_fixed_break(0, 5000, 32, false); TIMER_FUNC(e); printf("Took %0.2f seconds\n", TIMER_DIFF(s, e)); return 0; }
void BuildsWindow::Update() { if (!queue.empty() && TIMER_DIFF(send_timer) > 600) { if (GW::Map::GetInstanceType() != GW::Constants::InstanceType::Loading && GW::Agents::GetPlayer()) { send_timer = TIMER_INIT(); GW::Chat::SendChat('#', queue.front().c_str()); queue.pop(); } } }
static void tx_timeout(uint32_t timestamp, void* p_context) { uint32_t next_timeout = timestamp + (UINT32_MAX / 2); for (uint32_t i = 0; i < DFU_TX_SLOTS; ++i) { if (m_tx_slots[i].p_packet) { uint32_t timeout = next_tx_timeout(&m_tx_slots[i]); if (TIMER_OLDER_THAN(timeout, (timestamp + DFU_TX_TIMER_MARGIN_US))) { if (tc_tx(m_tx_slots[i].p_packet, &m_tx_config) == NRF_SUCCESS) { m_tx_slots[i].tx_count++; if (m_tx_slots[i].tx_count == TX_REPEATS_INF && m_tx_slots[i].repeats == TX_REPEATS_INF) { m_tx_slots[i].order_time = timeout; m_tx_slots[i].tx_count = 0; } else if (m_tx_slots[i].tx_count >= m_tx_slots[i].repeats) { mesh_packet_ref_count_dec(m_tx_slots[i].p_packet); memset(&m_tx_slots[i], 0, sizeof(dfu_tx_t)); } timeout = next_tx_timeout(&m_tx_slots[i]); } } if (TIMER_DIFF(timeout, timestamp) < TIMER_DIFF(next_timeout, timestamp)) { next_timeout = timeout; } } } m_tx_timer_evt.timestamp = next_timeout; APP_ERROR_CHECK(timer_sch_reschedule(&m_tx_timer_evt, next_timeout)); m_tx_scheduled = true; }
void test_data(int socket,char *filename) { TIMER_DECLARE(start,end); TIMER_DECLARE(Rstart,Rend); TIMER_DECLARE(Sstart,Send); char buf[SOCKET_BUF_SIZE+1] = {0}; int readlen=0; double total_time=0; double send_time=0; double read_time=0; double total_len=0; int fd=-1; if ((fd=open(filename, O_RDONLY)) < 0) { printf("%s,%d open file error!\n",__FILE__,__LINE__); return; } TIMER_START(start); while(1){ TIMER_START(Rstart); if((readlen=readn(fd, buf, SOCKET_BUF_SIZE))<=0) break; TIMER_END(Rend); TIMER_DIFF(read_time,Rstart,Rend); TIMER_START(Sstart); bnet_send(socket,buf,readlen); TIMER_END(Send); TIMER_DIFF(send_time,Sstart,Send); total_len+=readlen; } TIMER_END(end); TIMER_DIFF(total_time,start,end); close(fd); close(socket); printf("read time=%.4f %.4fMB/s\n",read_time,total_len/read_time/1036288); printf("send time=%.4f %.4fMB/s\n",send_time,total_len/send_time/1036288); printf("total time=%.4f %.4fMB/s\n", total_time,total_len/total_time/1036288); }
void benchmarkNoMem(uint32_t times) { uint64_t out[4]; TIMER_TYPE s, e; TIMER_FUNC(s); for (uint32_t i = 0; i < times; i++) { PHS(out, sizeof(out), "password", 8, "salt", 4, 100000, 0); } TIMER_FUNC(e); printf("Normal method took average time of %0.9f seconds:\n", TIMER_DIFF(s, e) / times); printf("%016llx %016llx %016llx %016llx\n\n", SWAP_ENDIAN_64(out[0]), SWAP_ENDIAN_64(out[1]), SWAP_ENDIAN_64(out[2]), SWAP_ENDIAN_64(out[3])); TIMER_FUNC(s); for (uint32_t i = 0; i < times; i++) { PHS_Fast(out, sizeof(out), "password", 8, "salt", 4, 100000, 0); } TIMER_FUNC(e); printf("Fast method took average time of %0.9f seconds:\n", TIMER_DIFF(s, e) / times); printf("%016llx %016llx %016llx %016llx\n", SWAP_ENDIAN_64(out[0]), SWAP_ENDIAN_64(out[1]), SWAP_ENDIAN_64(out[2]), SWAP_ENDIAN_64(out[3])); printf("%016llx %016llx %016llx %016llx\n", ~SWAP_ENDIAN_64(out[0]), ~SWAP_ENDIAN_64(out[1]), ~SWAP_ENDIAN_64(out[2]), ~SWAP_ENDIAN_64(out[3])); }
static void * timerThread(void *_data) { TIMER_DECLARE(period); Timer *timer = (Timer *) _data; #if defined(HAVE_STRUCT_TIMESPEC) pthreadSleep(timer->delay.tv_sec, timer->delay.tv_nsec); #elif defined(HAVE_STRUCT_TIMEVAL) pthreadSleep(timer->delay.tv_sec, timer->delay.tv_usec); #else pthreadSleep(timer->delay, 0); #endif do { if (timer->task == NULL) break; TIMER_START(period); #ifdef __unix__ pthread_testcancel(); #endif #if defined(__WIN32__) || defined(__CYGWIN__) if (timerIsCanceled(timer)) break; #endif (*timer->task)(timer); #ifdef __unix__ pthread_testcancel(); #endif #if defined(__WIN32__) || defined(__CYGWIN__) if (timerIsCanceled(timer)) break; #endif TIMER_DIFF(period); period = timer->period; CLOCK_SUB(&period, &TIMER_DIFF_VAR(period)); #if defined(HAVE_STRUCT_TIMESPEC) pthreadSleep(period.tv_sec, period.tv_nsec); #elif defined(HAVE_STRUCT_TIMEVAL) pthreadSleep(period.tv_sec, period.tv_usec); #else pthreadSleep(period, 0); #endif } while (TIMER_NE_CONST(timer->period, 0, 0)); return NULL; }
static void S9xCheckPointerTimer (void) { if (!gui_config->pointer_is_visible) return; gettimeofday (&now, NULL); if (TIMER_DIFF (now, gui_config->pointer_timestamp) > 1000000) { top_level->hide_mouse_cursor (); gui_config->pointer_is_visible = FALSE; } return; }
// If the current time is > debounce counter, set the counter to enable input. void update_debounce_counters(uint8_t num_rows, uint8_t current_time) { counters_need_update = false; debounce_counter_t *debounce_pointer = debounce_counters; for (uint8_t row = 0; row < num_rows; row++) { for (uint8_t col = 0; col < MATRIX_COLS; col++) { if (*debounce_pointer != DEBOUNCE_ELAPSED) { if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= DEBOUNCE) { *debounce_pointer = DEBOUNCE_ELAPSED; } else { counters_need_update = true; } } debounce_pointer++; } } }
static void * timerThread(void *_data) { int error; TIMER_DECLARE(period); struct timespec abstime, delay; Timer *timer = (Timer *) _data; PTHREAD_MUTEX_LOCK(&timer->mutex); /* Set initial delay. */ delay = *(struct timespec *) &timer->delay; #if !defined(HAVE_CLOCK_GETTIME) && defined(HAVE_GETTIMEOFDAY) delay.tv_nsec *= 1000; #endif timespecSetAbstime(&abstime, &delay); while ((error = pthread_cond_timedwait(&timer->cv, &timer->mutex, &abstime)) != 0) { if (error != ETIMEDOUT || timer->task == NULL) break; TIMER_START(period); (*timer->task)(timer); pthread_testcancel(); if (memcmp(&timer->period, &time_zero, sizeof (time_zero)) == 0) break; /* Compute execution time of task. */ TIMER_DIFF(period); /* Compute remainder of period. */ period = timer->period; CLOCK_SUB(&period, &TIMER_DIFF_VAR(period)); #if !defined(HAVE_CLOCK_GETTIME) && defined(HAVE_GETTIMEOFDAY) period.tv_usec *= 1000; #endif /* Set end of next iteration. */ timespecSetAbstime(&abstime, (struct timespec *) &period); } PTHREAD_MUTEX_UNLOCK(&timer->mutex); #if defined(__WIN32__) || defined(__CYGWIN__) pthread_exit(NULL); #endif return NULL; }
/* SyncSpeed Handles delays between frames, similar to unix.cpp version, * cleaned up for clarity, adjusted for GUI event loop */ void S9xSyncSpeed (void) { unsigned int limit; int lag; #ifdef NETPLAY_SUPPORT if (S9xNetplaySyncSpeed ()) return; #endif if (Settings.HighSpeedSeek > 0) { Settings.HighSpeedSeek--; IPPU.RenderThisFrame = FALSE; IPPU.SkippedFrames = 0; gettimeofday (&now, NULL); next_frame_time = now; syncing = 0; return; } else if (Settings.TurboMode) { if ((++IPPU.FrameSkip >= Settings.TurboSkipFrames) && !Settings.HighSpeedSeek) { IPPU.FrameSkip = 0; IPPU.SkippedFrames = 0; IPPU.RenderThisFrame = TRUE; } else { IPPU.SkippedFrames++; IPPU.RenderThisFrame = FALSE; } return; } gettimeofday (&now, NULL); if (next_frame_time.tv_sec == 0) { next_frame_time = now; ++next_frame_time.tv_usec; } if (Settings.SkipFrames == AUTO_FRAMERATE && !Settings.SoundSync) { lag = TIMER_DIFF (now, next_frame_time); /* We compensate for the frame time by a frame in case it's just a CPU * discrepancy. We can recover lost time in the next frame anyway. */ if (lag > (int) (Settings.FrameTime)) { if (lag > (int) Settings.FrameTime * 10) { /* Running way too slowly */ next_frame_time = now; IPPU.RenderThisFrame = 1; IPPU.SkippedFrames = 0; } else { IPPU.RenderThisFrame = 0; IPPU.SkippedFrames++; } } else { IPPU.RenderThisFrame = 1; IPPU.SkippedFrames = 0; } } else { limit = Settings.SoundSync ? 1 : Settings.SkipFrames + 1; IPPU.SkippedFrames++; IPPU.RenderThisFrame = 0; if (IPPU.SkippedFrames >= limit) { IPPU.RenderThisFrame = 1; IPPU.SkippedFrames = 0; } } syncing = 1; return; }
/* Finishes syncing by using more accurate system sleep functions*/ void S9xSyncSpeedFinish (void) { if (!syncing) return; gettimeofday (&now, NULL); if (Settings.SoundSync) { while (!S9xSyncSound ()) { usleep (100); gettimeofday (&next_frame_time, NULL); /* If we can't sync sound within a second, we're probably deadlocked */ if (TIMER_DIFF (next_frame_time, now) > 1000000) { /* Flush out our sample buffer and give up. */ S9xClearSamples (); break; } } next_frame_time = now; return; } if (TIMER_DIFF (next_frame_time, now) < -500000) { next_frame_time = now; } while (timercmp (&next_frame_time, &now, >)) { int time_left = TIMER_DIFF (next_frame_time, now); if (time_left > 500000) { next_frame_time = now; break; } usleep (time_left); gettimeofday (&now, NULL); } next_frame_time.tv_usec += Settings.FrameTime; if (next_frame_time.tv_usec >= 1000000) { next_frame_time.tv_sec += next_frame_time.tv_usec / 1000000; next_frame_time.tv_usec %= 1000000; } syncing = 0; return; }
void S9xSyncSpeed(void) { struct timeval now; // calculate lag gettimeofday (&now, NULL); if (SI_NextFrameTime.tv_sec == 0) { SI_NextFrameTime = now; ++SI_NextFrameTime.tv_usec; } int lag = TIMER_DIFF (now, SI_NextFrameTime); SI_FrameTimeDebt += lag-(int)Settings.FrameTime; //printf("Frame Time: %i. Should be less than %i\n", lag, (int)Settings.FrameTime); // if we're going too fast bool sleptThis = 0; if(SI_FrameTimeDebt < 0 && IPPU.SkippedFrames == 0) //if(debt+(int)Settings.FrameTime < 0 && IPPU.SkippedFrames == 0) { int audioOffset = SIAudioOffset(); if(-SI_FrameTimeDebt+audioOffset > 0) usleep(-SI_FrameTimeDebt+audioOffset); //usleep(-(debt+(int)Settings.FrameTime)); SI_FrameTimeDebt = 0; sleptThis = 1; } // if we're going too slow or fixed frameskip if (Settings.SkipFrames == AUTO_FRAMERATE && !Settings.SoundSync) { // auto frameskip if(SI_FrameTimeDebt > (int)Settings.FrameTime*10 || IPPU.SkippedFrames >= 2) SI_FrameTimeDebt = 0; if(SI_FrameTimeDebt > 0 && SI_SleptLastFrame == 0) { IPPU.RenderThisFrame = 0; IPPU.SkippedFrames++; } else { IPPU.RenderThisFrame = 1; IPPU.SkippedFrames = 0; } } else { // frameskip a set number of frames if(IPPU.SkippedFrames < Settings.SkipFrames) { IPPU.RenderThisFrame = 0; IPPU.SkippedFrames++; } else { IPPU.RenderThisFrame = 1; IPPU.SkippedFrames = 0; } } if(sleptThis == 1) SI_SleptLastFrame = 1; else SI_SleptLastFrame = 0; //next_frame_time = now; gettimeofday (&SI_NextFrameTime, NULL); }
void backup_formal(int fd,char *msg){ JCR *jcr=NULL; char fileset[256]={0}; char *buf=(char *)calloc(1,SOCKET_BUF_SIZE+21); int len; int index=1; char vol_name[FILE_NAME_LEN]; int vol_fd; Recipe *rp=NULL; FingerChunk *fc=NULL; char *p=NULL; int64_t rwlen=0; jobcount_init(); jcr=jcr_new(); jcr->dataSocket=fd; memset(vol_name,0,FILE_NAME_LEN); strcpy(vol_name,BackupVolPath); strcat(vol_name,"data_vol"); vol_fd=open(vol_name,O_RDWR| O_CREAT,00644); if(vol_fd<0){ err_msg1("can't open file"); goto FAIL; } printf("%s %d vol_name:%s\n",__FILE__,__LINE__,vol_name); rwlen=lseek(vol_fd,0,SEEK_END); TIMER_DECLARE(gstart,gend); TIMER_DECLARE(wstart,wend); TIMER_START(gstart); if(sscanf(msg,backup_cmd,fileset)!=1){ // backup cmd goto FAIL; } jcr->jobv=jobv_new(fileset); jcr->nJobId=jcr->jobv->nJobId; printf("===========backup start==============\n"); printf("%s,%d pathname:%s \n", __FILE__,__LINE__,fileset); while(bnet_recv(jcr->dataSocket,buf,&len)!=ERROR){ //文件名 if(len==STREAM_END){ printf("%s %d backup is over\n",__FILE__,__LINE__); break; } //printf("\033[40;32m recv file: %s (%d) \033[0m\n",buf,len); rp=recipe_new(); memcpy(rp->filename,buf,len); rp->fileindex=index++; while(bnet_recv(jcr->dataSocket,buf,&len)>0){ /*format: fingerprintf data data dta..*/ //printf("\033[40;32m recv: file data (%d) \033[0m\n",len); fc=fingerchunk_new(buf,0); fc->offset=rwlen; fc->length=len-sizeof(Fingerprint); check_data(fc->fingerprint,buf+sizeof(Fingerprint),fc->length); TIMER_START(wstart); if(writen(vol_fd,buf+sizeof(Fingerprint),fc->length)!=fc->length) err_msg1("wrintn wrong"); TIMER_END(wend); TIMER_DIFF(jcr->writeDataTime,wstart,wend); rwlen+=fc->length; jcr->nChunkCount++; jcr->nSize+=fc->length; recipe_append_fingerchunk(rp,fc); } jcr->nFileCount++; if(G_VERBOSE) printf("receive file %s OK, total: %d\n",rp->filename,jcr->nFileCount); jobv_insert_recipe(jcr->jobv, rp); rp=NULL; } FAIL: bnet_send(fd,"OK",2); // 发送备份成功信息 TIMER_END(gend); TIMER_DIFF(jcr->recvTime,gstart,gend); printf("============back over===============\n"); printf("total time:%.4f %.4f MB/s\n",jcr->recvTime,jcr->nSize*1.0/jcr->recvTime/1036288.0); printf("write time:%.4f %.4f MB/s\n",jcr->writeDataTime,jcr->nSize*1.0/jcr->writeDataTime/1036288.0); printf("chunk count:%d\n",jcr->nChunkCount); printf("file count:%d\n",jcr->nFileCount); if(rp){ recipe_free(rp); } jobv_destroy(jcr->jobv); jcr_free(jcr); jobcount_close(); close(vol_fd); }
uint32_t dfu_evt_handler(bl_evt_t* p_evt) { __LOG("BL EVT (0x%x)\n", p_evt->type); switch (p_evt->type) { case BL_EVT_TYPE_ECHO: __LOG("\tEcho: %s\n", p_evt->params.echo.str); break; case BL_EVT_TYPE_DFU_ABORT: { __LOG("\tAbort event. Reason: 0x%x\n", p_evt->params.dfu.abort.reason); rbc_mesh_event_t evt; evt.type = RBC_MESH_EVENT_TYPE_DFU_END; evt.params.dfu.end.dfu_type = m_transfer_state.type; evt.params.dfu.end.role = m_transfer_state.role; evt.params.dfu.end.fwid = m_transfer_state.fwid; evt.params.dfu.end.end_reason = p_evt->params.dfu.abort.reason; memset(&m_transfer_state, 0, sizeof(dfu_transfer_state_t)); rbc_mesh_event_push(&evt); } break; case BL_EVT_TYPE_DFU_NEW_FW: { __LOG("\tNew firmware!\n"); rbc_mesh_event_t evt; evt.type = RBC_MESH_EVENT_TYPE_DFU_NEW_FW_AVAILABLE; evt.params.dfu.new_fw.dfu_type = p_evt->params.dfu.new_fw.fw_type; evt.params.dfu.new_fw.new_fwid = p_evt->params.dfu.new_fw.fwid; if (get_curr_fwid( p_evt->params.dfu.new_fw.fw_type, &evt.params.dfu.new_fw.current_fwid) == NRF_SUCCESS) { rbc_mesh_event_push(&evt); } } break; case BL_EVT_TYPE_DFU_REQ: { __LOG("\tSource/relay request!\n"); /* Forward to application */ rbc_mesh_event_t evt; switch (p_evt->params.dfu.req.role) { case DFU_ROLE_RELAY: evt.type = RBC_MESH_EVENT_TYPE_DFU_RELAY_REQ; evt.params.dfu.relay_req.dfu_type = p_evt->params.dfu.req.dfu_type; evt.params.dfu.relay_req.fwid = p_evt->params.dfu.req.fwid; evt.params.dfu.relay_req.authority = p_evt->params.dfu.req.dfu_type; break; case DFU_ROLE_SOURCE: evt.type = RBC_MESH_EVENT_TYPE_DFU_SOURCE_REQ; evt.params.dfu.source_req.dfu_type = p_evt->params.dfu.req.dfu_type; break; default: return NRF_ERROR_NOT_SUPPORTED; } rbc_mesh_event_push(&evt); } break; case BL_EVT_TYPE_DFU_START: { __LOG("\tDFU start\n"); if (p_evt->params.dfu.start.role == DFU_ROLE_TARGET) { m_transfer_state.state = DFU_STATE_TARGET; } else if (p_evt->params.dfu.start.role == DFU_ROLE_RELAY) { m_transfer_state.state = DFU_STATE_RELAY; } rbc_mesh_event_t evt; evt.type = RBC_MESH_EVENT_TYPE_DFU_START; evt.params.dfu.start.dfu_type = p_evt->params.dfu.start.dfu_type; evt.params.dfu.start.fwid = p_evt->params.dfu.start.fwid; evt.params.dfu.start.role = p_evt->params.dfu.start.role; rbc_mesh_event_push(&evt); m_timer_evt.cb = abort_timeout; return timer_sch_reschedule(&m_timer_evt, timer_now() + TIMER_START_TIMEOUT); } case BL_EVT_TYPE_DFU_DATA_SEGMENT_RX: m_transfer_state.data_progress = (uint8_t) ( ((uint32_t) p_evt->params.dfu.data_segment.received_segment * 100) / ((uint32_t) p_evt->params.dfu.data_segment.total_segments)); m_timer_evt.cb = abort_timeout; return timer_sch_reschedule(&m_timer_evt, timer_now() + TIMER_DATA_TIMEOUT); case BL_EVT_TYPE_DFU_END: { __LOG("\tDFU END!\n"); rbc_mesh_event_t evt; evt.type = RBC_MESH_EVENT_TYPE_DFU_END; evt.params.dfu.end.dfu_type = p_evt->params.dfu.end.dfu_type; evt.params.dfu.end.fwid = p_evt->params.dfu.end.fwid; evt.params.dfu.end.end_reason = DFU_END_SUCCESS; evt.params.dfu.end.role = p_evt->params.dfu.end.role; rbc_mesh_event_push(&evt); timer_sch_abort(&m_timer_evt); } break; case BL_EVT_TYPE_BANK_AVAILABLE: { __LOG("\tDFU BANK AVAILABLE\n"); rbc_mesh_event_t evt; evt.type = RBC_MESH_EVENT_TYPE_DFU_BANK_AVAILABLE; evt.params.dfu.bank.dfu_type = p_evt->params.bank_available.bank_dfu_type; evt.params.dfu.bank.fwid = p_evt->params.bank_available.bank_fwid; evt.params.dfu.bank.is_signed = p_evt->params.bank_available.is_signed; evt.params.dfu.bank.p_start_addr = p_evt->params.bank_available.p_bank_addr; rbc_mesh_event_push(&evt); } break; case BL_EVT_TYPE_FLASH_ERASE: { if (p_evt->params.flash.erase.start_addr & (NRF_FICR->CODEPAGESIZE - 1)) { return NRF_ERROR_INVALID_ADDR; } if (p_evt->params.flash.erase.length & (NRF_FICR->CODEPAGESIZE - 1)) { return NRF_ERROR_INVALID_LENGTH; } uint32_t error_code = mesh_flash_op_push(FLASH_OP_TYPE_ERASE, &p_evt->params.flash); if (error_code == NRF_SUCCESS) { __LOG("\tErase flash at: 0x%x (length %d)\n", p_evt->params.flash.erase.start_addr, p_evt->params.flash.erase.length); } return error_code; } case BL_EVT_TYPE_FLASH_WRITE: { if (!IS_WORD_ALIGNED(p_evt->params.flash.write.start_addr)) { return NRF_ERROR_INVALID_ADDR; } if (!IS_WORD_ALIGNED(p_evt->params.flash.write.length)) { return NRF_ERROR_INVALID_LENGTH; } uint32_t error_code = mesh_flash_op_push(FLASH_OP_TYPE_WRITE, &p_evt->params.flash); if (error_code == NRF_SUCCESS) { __LOG("\tWrite flash at: 0x%x (length %d)\n", p_evt->params.flash.write.start_addr, p_evt->params.flash.write.length); } return error_code; } case BL_EVT_TYPE_TX_RADIO: __LOG("\tRADIO TX! SLOT %d, count %d, interval: %s, handle: %x\n", p_evt->params.tx.radio.tx_slot, p_evt->params.tx.radio.tx_count, p_evt->params.tx.radio.interval_type == BL_RADIO_INTERVAL_TYPE_EXPONENTIAL ? "exponential" : "periodic", p_evt->params.tx.radio.p_dfu_packet->packet_type ); if (m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet) { mesh_packet_ref_count_dec(m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet); m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet = NULL; } if (mesh_packet_acquire(&m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet)) { uint32_t time_now = timer_now(); /* build packet */ mesh_packet_set_local_addr(m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet); m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet->header.type = BLE_PACKET_TYPE_ADV_NONCONN_IND; m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet->header.length = DFU_PACKET_OVERHEAD + p_evt->params.tx.radio.length; ((ble_ad_t*) m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet->payload)->adv_data_type = MESH_ADV_DATA_TYPE; ((ble_ad_t*) m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet->payload)->data[0] = (MESH_UUID & 0xFF); ((ble_ad_t*) m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet->payload)->data[1] = (MESH_UUID >> 8) & 0xFF; ((ble_ad_t*) m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet->payload)->adv_data_length = DFU_PACKET_ADV_OVERHEAD + p_evt->params.tx.radio.length; memcpy(&m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet->payload[4], p_evt->params.tx.radio.p_dfu_packet, p_evt->params.tx.radio.length); /* fill other fields in the TX slot. */ m_tx_slots[p_evt->params.tx.radio.tx_slot].interval_type = p_evt->params.tx.radio.interval_type; m_tx_slots[p_evt->params.tx.radio.tx_slot].repeats = p_evt->params.tx.radio.tx_count; m_tx_slots[p_evt->params.tx.radio.tx_slot].tx_count = 0; m_tx_slots[p_evt->params.tx.radio.tx_slot].order_time = time_now + DFU_TX_TIMER_MARGIN_US + (rand_prng_get(&m_prng) & (DFU_TX_START_DELAY_MASK_US)); /* Fire away */ if (!m_tx_scheduled || TIMER_DIFF(m_tx_slots[p_evt->params.tx.radio.tx_slot].order_time, time_now) < TIMER_DIFF(m_tx_timer_evt.timestamp, time_now)) { m_tx_scheduled = true; timer_sch_reschedule(&m_tx_timer_evt, m_tx_slots[p_evt->params.tx.radio.tx_slot].order_time); } } else { return NRF_ERROR_NO_MEM;