inline void lo_peakbuf_to_texture(Renderer* renderer, WaveformActor* actor, int b, Section* section, int n_chans, int block_size) { // borders: source data is not blocked so borders need to be added here. Waveform* waveform = actor->waveform; WaveformPriv* w = waveform->priv; WfPeakBuf* peak = &w->peak; int _b = b % MAX_BLOCKS_PER_TEXTURE; int mm_level = 0; int* lod_max = ((NGRenderer*)renderer)->mmidx_max; int* lod_min = ((NGRenderer*)renderer)->mmidx_min; #define B_SIZE (WF_PEAK_TEXTURE_SIZE - 2 * TEX_BORDER) #define is_last_block(W, b) (b == ((HiResNGWaveform*)W->render_data[MODE_LOW])->n_blocks - 1) int stop = is_last_block(w, b) ? peak->size / (WF_PEAK_VALUES_PER_SAMPLE * WF_PEAK_STD_TO_LO) + TEX_BORDER - B_SIZE * b : WF_PEAK_TEXTURE_SIZE; int c; for(c=0;c<n_chans;c++){ int src = WF_PEAK_VALUES_PER_SAMPLE * (b * B_SIZE - TEX_BORDER) * WF_PEAK_STD_TO_LO; int dest = _b * block_size + (c * block_size / 2); int t = 0; if(b == 0){ for(t=0;t<TEX_BORDER;t++){ ng_gl2_set_(section, dest + lod_max[mm_level] + t, 0); ng_gl2_set_(section, dest + lod_min[mm_level] + t, 0); } src = 0; } for(; t<stop; t++, src+=2*WF_PEAK_STD_TO_LO){ WfPeakSample p = {0, 0}; int j; for(j=0;j<2*WF_PEAK_STD_TO_LO;j+=WF_PEAK_VALUES_PER_SAMPLE){ p.positive = MAX(p.positive, peak->buf[c][src + j ]); p.negative = MIN(p.negative, peak->buf[c][src + j + 1]); } ng_gl2_set_(section, dest + lod_max[mm_level] + t, short_to_char( p.positive)); ng_gl2_set_(section, dest + lod_min[mm_level] + t, short_to_char(-p.negative)); } other_lods(renderer, section, dest); } }
/** **************************************************************************************** * @brief Handles GATTC_EVENT_IND event. * * @param[in] msgid Id of the message received. * @param[in] param Pointer to the parameters of the message. * @param[in] dest_id ID of the receiving task instance (TASK_GAP). * @param[in] src_id ID of the sending task instance. * * @return If the message was consumed or not. **************************************************************************************** */ int gattc_event_ind_handler(ke_msg_id_t msgid, struct gattc_event_ind *param, ke_task_id_t dest_id, ke_task_id_t src_id) { // handle notifications from SPOTA_SERV_STATUS only if(param->handle != app_env.peer_device.spota.serv_status_handle) { return 0; } // retrieve notification value app_env.peer_device.spota.serv_status_value = param->value[0]; if (app_env.state == APP_WR_MEM_DEV) { // check if write SPOTA_MEM_DEV completed successfully if (app_env.peer_device.spota.serv_status_value != SPOTA_STATUS_IMG_STARTED) { printf("error: SPOTA_SERV_STATUS = 0x%02X after writing to SPOTA_MEM_DEV\n", app_env.peer_device.spota.serv_status_value); // disconnect app_env.state = APP_DISCONNECTING; app_disconnect(); return 0; // in order to exit this function immediately } // trigger next step - write SPOTA_GPIO_MAP app_suota_write_gpio_map(); } else if (app_env.state == APP_WR_PATCH_DATA) // handle the notification only after the last chunk has been written { // check SPOTA_SERV_STATUS if (app_env.peer_device.spota.serv_status_value != SPOTA_STATUS_CMP_OK) { printf("Error: SPOTA_SERV_STATUS = 0x%02X after writing block \n", app_env.peer_device.spota.serv_status_value); // disconnect app_env.state = APP_DISCONNECTING; app_disconnect(); return 0; // in order to exit this function immediately } if(is_last_block()) { // no more blocks to write // trigger next step - read SPOTA_MEM_INFO (the 2nd time) app_env.state = APP_RD_MEM_INFO_2; app_characteristic_read(KE_IDX_GET(src_id), app_env.peer_device.spota.mem_info_handle); } else { // advance to the next block next_block(); if( is_last_block() ) // we may need a different block length for the last block { // trigger next step - write SPOTA_PATCH_LEN for last block app_suota_write_patch_len(block_length); } else { // trigger next step - start writing the block chunks app_suota_write_chunks(); } } } else if (app_env.state == APP_WR_END_OF_SUOTA) // handle the notification after the end of SUOTA command has been issued { // check SPOTA_SERV_STATUS if (app_env.peer_device.spota.serv_status_value != SPOTA_STATUS_CMP_OK) { printf("error: SPOTA_SERV_STATUS = 0x%02X after sending END OF SUOTA \n", app_env.peer_device.spota.serv_status_value); // disconnect app_env.state = APP_DISCONNECTING; app_disconnect(); return 0; // in order to exit this function immediately } // no more blocks to write - SUOTA procedure completed successfully printf("\nSUOTA procedure completed successfully \n\n"); print_time(); // send boot command - the receiver will reboot when it receives this command // the connection is expected to be lost { void app_suota_reboot(void); app_suota_reboot(); } // trigger next step - disconnect app_env.state = APP_DISCONNECTING; app_disconnect(); } else { // no handling of notifications in the rest of the states /// printf(" SPOTA_SERV_STATUS = 0x%02X app_env.state = %d\n", app_env.peer_device.spota.serv_status_value, app_env.state ); } return 0; }
void *mm_realloc(void *ptr, size_t size){ if (size == 0) { //if newsize is 0, call mm_free(ptr) and return NULL mm_free(ptr); return NULL; }else if (ptr == NULL) { //if ptr is NULL, call and return mm_malloc(ptr) return mm_malloc(size); }else if(size > 0) { //Otherwise: Return a block of size >= newsize that preserves //all the data from the payload of the block ptr. //I'll use several optimizations listed below: //idea gotten from : //http://condor.depaul.edu/glancast/374class/docs/lecOct30.html //http://condor.depaul.edu/glancast/374class/docs/lecOct11.html /* (1) If newsize <= current size of ptr, just return ptr (2) If the next block after ptr is free and its size plus the size of ptr is >= the requested newsize, remove the free block, rewrite the header and then the footer of ptr to change the size of ptr and return ptr. (3) If the next block after bp is free, but its size plus the size of ptr is NOT >= the requested newsize, BUT this next block is the 'last' block (before the epilog), call sbrk() to get additional size and rewrite the header and then the footer of bp to change the size of bp. Return ptr. (4) If bp is the 'last' block (before the epilog), call extend_heap to get additional size and rewrite the header and then the footer of bp to change the size of bp. Return bp. */ //this is the pointer to the head of the block to be realloced blockHdr *bp = (blockHdr *)((char *)ptr - BLK_HDR_SIZE); //the alligned size (actual size to check for) size_t new_size = ALIGN(size + BLK_HDR_FTR_SIZE); //get next block after bp blockHdr *next_block = (blockHdr *)((char *)bp + ((bp ->size) & ~1)); size_t next_block_size = ((next_block ->size) & ~1); int next_block_free = !((next_block ->size) & 1); size_t curr_block_size = ((bp ->size) & ~1); if(new_size <= curr_block_size){ //case 1 - If newsize <= current size of ptr, just return ptr //simply return ptr; //if the new size is much smaller than the current size, //then we may have to split it return ptr; }else if(next_block_free && ((next_block_size + curr_block_size) >= new_size)){ //case 2 - If the next block after ptr is free and its size plus the //size of ptr is >= the requested newsize, remove the free //block, rewrite the header and then the footer of ptr to change //the size of ptr and return ptr. //remove the next block from the free list remove_from_free_lists(next_block); //now change the sizes of the current block header and footer bp ->size &= ~1; bp ->size += next_block_size; blockFtr *foot = (blockFtr *)((char *)bp + ((bp->size) & (~1)) - BLK_FTR_SIZE); bp ->size |= 1; foot->size = bp->size; //now return the resized block return (void *)((char *)bp + BLK_HDR_SIZE); }else if(next_block_free && is_last_block(next_block) ){ //case 3 - If the next block after bp is free, but its size plus the //size of ptr is NOT >= the requested newsize, BUT this next //block is the 'last' block (before the epilog), call //sbrk() to get additional size and rewrite the header and //then the footer of bp to change the size of bp. Return ptr. //remove the next block from the free list remove_from_free_lists(next_block); //get additional size that should be allocated int add_size = new_size - (next_block_size + curr_block_size); //get current epilogue blockHdr *epilogue = GET_EPILOGUE; epilogue -> size = BLK_HDR_SIZE; //now allocate this size by using sbrk blockHdr *free_block = mem_sbrk(add_size); //if there's an error during allocation return NULL if (free_block <= 0) return NULL ; //then set the header and footer sizes to reflect this change bp ->size = new_size|1; blockFtr *foot = (blockFtr *)((char *)bp + ((bp ->size) & (~1)) - BLK_FTR_SIZE); foot ->size = bp ->size; //adjust the epilogue epilogue = GET_EPILOGUE; epilogue->next_p = epilogue; epilogue->prior_p = epilogue; epilogue->size = BLK_HDR_SIZE | 1; //return newly extended block (actually payload) return (void *)((char *)bp + BLK_HDR_SIZE); }else if(is_last_block(bp)){ //case 4 - If bp is the 'last' block (before the epilog), call //sbrk to get additional size and rewrite the header and //then the footer of bp to change the size of bp. Return bp. //get additional size that should be allocated int add_size = new_size - (curr_block_size); //get current epilogue blockHdr *epilogue = GET_EPILOGUE; epilogue->size = BLK_HDR_SIZE; //now allocate this size by using sbrk blockHdr *free_block = mem_sbrk(add_size); //if there's an error during allocation return NULL if (free_block <= 0) return NULL ; //then set the header and footer sizes to reflect this change bp ->size = new_size|1; blockFtr *foot = (blockFtr *)((char *)bp + ((bp ->size) & (~1)) - BLK_FTR_SIZE); foot ->size = bp ->size; //adjust the epilogue epilogue = GET_EPILOGUE; epilogue->next_p = epilogue; epilogue->prior_p = epilogue; epilogue->size = BLK_HDR_SIZE | 1; //return newly extended block (actually payload) return (void *)((char *)bp + BLK_HDR_SIZE); }else{ //well, there's nothing else to do. Just use malloc to get more space //and copy the payload over to this space //malloc with the new size void *new_blk = mm_malloc(size); //copy payload memcpy(new_blk,ptr,curr_block_size); //free previous block (ptr) mm_free(ptr); //return newly malloced block return new_blk; } } return NULL; //well, the given size was negative }