int FileThread::stop_writing() { if(is_writing) { int i, buffer, layer, frame; swap_buffer(); input_lock[current_buffer]->lock("FileThread::stop_writing 1"); last_buffer[current_buffer] = 1; for(i = 0; i < ring_buffers; i++) output_lock[i]->unlock(); swap_buffer(); // wait for thread to finish Thread::join(); // delete buffers file_lock->lock("FileThread::stop_writing 2"); if(do_audio) { for(buffer = 0; buffer < ring_buffers; buffer++) { for(i = 0; i < file->asset->channels; i++) delete [] audio_buffer[buffer][i]; delete [] audio_buffer[buffer]; } delete [] audio_buffer; audio_buffer = 0; } // printf("FileThread::stop_writing %d %d %d %d\n", // do_video, // ring_buffers, // file->asset->layers, // buffer_size); if(do_video) { for(buffer = 0; buffer < ring_buffers; buffer++) { for(layer = 0; layer < file->asset->layers; layer++) { for(frame = 0; frame < buffer_size; frame++) { delete video_buffer[buffer][layer][frame]; } delete [] video_buffer[buffer][layer]; } delete [] video_buffer[buffer]; } delete [] video_buffer; video_buffer = 0; } file_lock->unlock(); } return 0; }
void ms_read_process(MSRead *r) { MSFifo *f; MSQueue *q; MSMessage *msg=NULL; int err; gint gran=r->gran; void *p; f=r->foutputs[0]; if ((f!=NULL) && (r->state==MS_READ_STATE_STARTED)) { ms_fifo_get_write_ptr(f,gran,&p); if (p!=NULL) { err=read(r->fd,p,gran); if (err<0) { /* temp: */ g_warning("ms_read_process: failed to read: %s.\n",strerror(errno)); } else if (err<gran){ ms_trace("ms_read_process: end of file."); ms_filter_notify_event(MS_FILTER(r),MS_READ_EVENT_EOF,NULL); r->state=MS_READ_STATE_STOPPED; close(r->fd); r->fd=-1; } if (r->need_swap) swap_buffer(p,gran); } } /* process output queues*/ q=r->qoutputs[0]; if ((q!=NULL) && (r->fd>0)) { msg=ms_message_new(r->gran); err=read(r->fd,msg->data,r->gran); if (err>0){ msg->size=err; ms_queue_put(q,msg); if (r->need_swap) swap_buffer(msg->data,r->gran); }else{ ms_filter_notify_event(MS_FILTER(r),MS_READ_EVENT_EOF,NULL); ms_trace("End of file reached."); r->state=MS_READ_STATE_STOPPED; } } }
void swap_buffers_tolast(){ if(shellbuff.changed == 0){ swap_buffer(); shellbuff.changed = 1; } return; }
void swap_buffers_tofirst(){ if(shellbuff.changed == 1){ swap_buffer(); shellbuff.changed = 0; } return; }
_inline void openmp_rows(transform_direction dir, cpx **in, cpx **out, const cpx *w, const int n) { #pragma omp parallel for schedule(static) for (int row = 0; row < n * n; row += n) openmp_const_geom_2d_helper(dir, (*in) + row, (*out) + row, w, n); if (log2_32(n) % 2 == 0) swap_buffer(in, out); }
void openmp_const_geom_2d(transform_direction dir, cpx **in, cpx **out, const int n) { cpx *w = (cpx *)malloc(sizeof(cpx) * n); openmp_twiddle_factors(w, dir, n); openmp_rows(dir, in, out, w, n); openmp_transpose(*out, *in, n); openmp_rows(dir, in, out, w, n); openmp_transpose(*out, *in, n); swap_buffer(in, out); free(w); }
_inline void openmp_const_geom_2d_helper(transform_direction dir, cpx *in, cpx *out, const cpx *w, const int n) { const int n_half = n / 2; int steps_left = log2_32(n); int steps = 0; openmp_inner_body(in, out, w, 0xffffffff << steps, n_half); while (++steps < steps_left) { swap_buffer(&in, &out); openmp_inner_body(in, out, w, 0xffffffff << steps, n_half); } openmp_bit_reverse(out, dir, 32 - steps_left, n); }
void ms_ring_player_process(MSRingPlayer *r) { MSFifo *f; gint err; gint processed=0; gint gran=r->gran; char *p; g_return_if_fail(gran>0); /* process output fifos*/ f=r->foutputs[0]; ms_fifo_get_write_ptr(f,gran,(void**)&p); g_return_if_fail(p!=NULL); for (processed=0;processed<gran;){ switch(r->state){ case PLAY_RING: err=read(r->fd,&p[processed],gran-processed); if (err<0) { memset(&p[processed],0,gran-processed); processed=gran; g_warning("ms_ring_player_process: failed to read: %s.\n",strerror(errno)); return; } else if (err<gran) {/* end of file */ r->current_pos=r->silence_bytes; lseek(r->fd,WAVE_HEADER_OFFSET,SEEK_SET); r->state=PLAY_SILENCE; ms_filter_notify_event(MS_FILTER(r),MS_RING_PLAYER_END_OF_RING_EVENT,NULL); } if (r->need_swap) swap_buffer(&p[processed],err); processed+=err; break; case PLAY_SILENCE: err=gran-processed; if (r->current_pos>err){ memset(&p[processed],0,err); r->current_pos-=gran; processed=gran; }else{ memset(&p[processed],0,r->current_pos); processed+=r->current_pos; r->state=PLAY_RING; } break; } } }
void openmp_const_geom(transform_direction dir, cpx **in, cpx **out, const int n) { const int n_half = n / 2; int steps_left = log2_32(n); int steps = 0; cpx *w = (cpx *)malloc(sizeof(cpx) * n); openmp_twiddle_factors(w, dir, n); openmp_inner_body(*in, *out, w, 0xffffffff << steps, n_half); while (++steps < steps_left) { swap_buffer(in, out); openmp_inner_body(*in, *out, w, 0xffffffff << steps, n_half); } openmp_bit_reverse(*out, dir, 32 - steps_left, n); free(w); }
static void do_send(struct rp_generator_t *self) { assert(self->buf_sending->size == 0); swap_buffer( &self->buf_sending, self->client != NULL ? &self->client->sock->input : &self->last_content_before_send); if (self->buf_sending->size != 0) { h2o_iovec_t buf = h2o_iovec_init(self->buf_sending->bytes, self->buf_sending->size); h2o_send(self->src_req, &buf, 1, self->client == NULL); } else if (self->client == NULL) { h2o_send(self->src_req, NULL, 0, 1); } }
void openmp_const_geom_alt(transform_direction dir, cpx **in, cpx **out, const int n) { int bit = log2_32(n); const int leading_bits = 32 - bit; int steps = --bit; unsigned int mask = 0xffffffff << (steps - bit); float global_angle = dir * M_2_PI / n; openmp_inner_body(*in, *out, global_angle, mask, n); while (bit-- > 0) { swap_buffer(in, out); mask = 0xffffffff << (steps - bit); openmp_inner_body(*in, *out, global_angle, mask, n); } openmp_bit_reverse(*out, dir, leading_bits, n); }
static void storage_serialize(at **pp, int code) { storage_t *st; int type, kind; size_t size; if (code != SRZ_READ) { st = Mptr(*pp); type = (int)st->type; kind = (int)st->kind; size = st->size; } // Read/write basic info serialize_int(&type, code); serialize_int(&kind, code); serialize_size(&size, code); // Create storage if needed if (code == SRZ_READ) { st = new_storage_managed((storage_type_t)type, size, NIL); *pp = st->backptr; } // Read/write storage data st = Mptr(*pp); if (type == ST_AT) { at **data = st->data; for (int i=0; i<size; i++) serialize_atstar( &data[i], code); } else { FILE *f = serialization_file_descriptor(code); if (code == SRZ_WRITE) { extern int in_bwrite; in_bwrite += sizeof(int) + size * storage_sizeof[type]; write4(f, STORAGE_NORMAL); storage_save(st, f); } else if (code == SRZ_READ) { int magic = read4(f); storage_load(st, f); if (magic == STORAGE_SWAPPED) swap_buffer(st->data, size, storage_sizeof[type]); else if (magic != STORAGE_NORMAL) RAISEF("Corrupted binary file",NIL); } } }
static void step (AppData *appdata) { cairo_t *cr; set_up_for_buffer (appdata, &cr); cairo_save (cr); cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); appdata->x += 10 * appdata->dir; if (appdata->x > 1239 || appdata->x < 0) appdata->dir *= -1; cairo_set_source_rgb (cr, 1, 0, 0); cairo_rectangle (cr, appdata->x - 50, 75, 681, 800); cairo_fill (cr); cairo_translate (cr, appdata->x, 200); cairo_set_source_surface (cr, appdata->craig, 0, 0); cairo_rectangle (cr, 0, 0, 681, 800); cairo_fill (cr); cairo_restore (cr); /* cairo_save (cr); cairo_scale (cr, 2, 2); rsvg_handle_render_cairo (appdata->tiger, cr); cairo_restore (cr); */ swap_buffer (appdata); step_cursor (appdata); step_cursor (appdata); step_cursor (appdata); step_cursor (appdata); step_cursor (appdata); step_cursor (appdata); step_cursor (appdata); ++appdata->time; }
void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags) { struct ngene_channel *chan = priv; struct ngene *dev = chan->dev; u32 alen; alen = dvb_ringbuffer_avail(&dev->tsout_rbuf); alen -= alen % 188; if (alen < len) FillTSBuffer(buf + alen, len - alen, flags); else alen = len; dvb_ringbuffer_read(&dev->tsout_rbuf, buf, alen); if (flags & DF_SWAP32) swap_buffer((u32 *)buf, alen); wake_up_interruptible(&dev->tsout_rbuf.queue); return buf; }
void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags) { struct ngene_channel *chan = priv; struct ngene *dev = chan->dev; if (flags & DF_SWAP32) swap_buffer(buf, len); if (dev->ci.en && chan->number == 2) { while (len >= 188) { if (memcmp(buf, fill_ts, sizeof fill_ts) != 0) { if (dvb_ringbuffer_free(&dev->tsin_rbuf) >= 188) { dvb_ringbuffer_write(&dev->tsin_rbuf, buf, 188); wake_up(&dev->tsin_rbuf.queue); #ifdef DEBUG_CI_XFER ok++; #endif } #ifdef DEBUG_CI_XFER else overflow++; #endif } #ifdef DEBUG_CI_XFER else stripped++; if (ok % 100 == 0 && overflow) printk(KERN_WARNING "%s: ok %u overflow %u dropped %u\n", __func__, ok, overflow, stripped); #endif buf += 188; len -= 188; } return NULL; } if (chan->users > 0) dvb_dmx_swfilter(&chan->demux, buf, len); return NULL; }
int rdieee_file(float *array, int n, int header, FILE *input) { int i, j; unsigned int l; unsigned char buff[BSIZ]; unsigned char h4[4],t4[4]; float *p; n = n*4; if (header) { if (fread(h4,1,4,input) != 4) fatal_error("rdieee: header read",""); if (ieee_little_endian) l = (h4[3] << 24) | (h4[2] << 16) | (h4[1] << 8) | h4[0]; else l = (h4[0] << 24) | (h4[1] << 16) | (h4[2] << 8) | h4[3]; if (l != n) fatal_error_ii("rdieee: bad header=%u expecting %d",l,n); } p = array; while (n > 0) { j = n < BSIZ ? n : BSIZ; fread(buff,1,j,input); if (ieee_little_endian) swap_buffer(buff, j); for (i = 0; i < j; i += 4) { *p++ = ieee2flt(buff + i); } n = n - j; } if (header) { if (fread(t4,1,4,input) != 4) fatal_error("rdieee: trailer read",""); if (h4[0] != t4[0] || h4[1] != t4[1] || h4[2] != t4[2] || h4[3] != t4[3]) fatal_error("rdieee: bad trailer",""); } return 0; }
void Game::update(){ //std::cout<<"Game::update() 1"<<std::endl; input->update(); handle_game_signal(); //std::cout<<"Game::update() 2"<<std::endl; //===========game update=============== game_update(); Scene* cur_scene=get_cur_scene(); //std::cout<<"Game::update() cur_scene="<<cur_scene->scene_name()<<std::endl; //===============system pre_update======================= //std::cout<<"Game::update() controller_system->pre_update()"<<std::endl; controller_system->pre_update(); //std::cout<<"Game::update() controller_system->pre_update() end"<<std::endl; //===============scene_update()====================== //std::cout<<"Game::update() cur_scene="<<cur_scene->scene_name()<<std::endl; cur_scene->update(); //std::cout<<"Game::update() cur_scene->update() end"<<std::endl; //===========system update============= controller_system->update(); //std::cout<<"Game::update() controller_system->update() end"<<std::endl; //===========update end================ cur_scene->scene_update_end(); //===========draw start================ //std::cout<<"Game::update() cur_scene->draw_scene(); start"<<std::endl; cur_scene->draw_scene(); //std::cout<<"Game::update() cur_scene->draw_scene(); end"<<std::endl; //===========render start============== //std::cout<<"Game::update() renderer->render() start"<<std::endl; renderer->render(); //std::cout<<"Game::update() renderer->render() end"<<std::endl; //===========wait for render end======= //render_thread->join(); draw->clear_tmp_data(); //std::cout<<"Game::update() draw->clear_tmp_data()"<<std::endl; swap_buffer();//swap screen buffer //std::cout<<"Game::update() end"<<std::endl; }
/*------------------------------------------------------------------------ * main - extract_region * * input : argc, argv - command line args * * result: EXIT_SUCCESS or EXIT_FAILURE * * effect: Input consists of grid file file_in whose dimensions are * defined by bytes_per_cell, cols_in, and rows_in. * Output consists of raster file file_out consisting of a region * of file_in defined by col_start, row_start, cols_out, and * rows_out and having the same number of bytes_per_cell as * file_in. *------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { char *option; int bytes_per_cell, cols_in, rows_in; int col_start, row_start, cols_out, rows_out; char *file_in; char *file_out; byte1 *buf_in = NULL; byte1 *buf_out = NULL; byte1 *buf_temp = NULL; int fd_in = -1; int fd_out = -1; bool there_were_errors; int row; int bytes_per_row_in, bytes_per_row_out; int last_row_in_region; bool byte_swap; double scale; bool float_scale; int cells_per_col; /* * set defaults */ verbose = very_verbose = NULL; byte_swap = FALSE; scale = 1.0; float_scale = FALSE; cells_per_col = 1; there_were_errors = FALSE; /* * get command line options */ while (--argc > 0 && (*++argv)[0] == '-') { for (option = argv[0]+1; *option != '\0'; option++) { switch (*option) { case 'v': if (very_verbose) very_very_verbose = stdout; if (verbose) very_verbose = stdout; verbose = stdout; break; case 'V': fprintf(stderr,"%s\n", extract_region_c_rcsid); break; case 'b': byte_swap = TRUE; break; case 's': ++argv; --argc; if (argc <= 0) DisplayInvalidParameter("scale"); if (sscanf(*argv, "%lf", &scale) != 1) DisplayInvalidParameter("scale"); break; case 'f': float_scale = TRUE; break; case 'c': ++argv; --argc; if (argc <= 0) DisplayInvalidParameter("cells_per_col"); if (sscanf(*argv, "%d", &cells_per_col) != 1) DisplayInvalidParameter("cells_per_col"); break; default: fprintf(stderr, "extract_region: invalid option %c\n", *option); error_exit(usage); } } } /* * get command line args */ if (argc != 9) error_exit(usage); if (sscanf(*argv++, "%d", &bytes_per_cell) != 1) { fprintf(stderr, "invalid bytes_per_cell value %s\n", *argv); error_exit(usage); } if (sscanf(*argv++, "%d", &cols_in) != 1) { fprintf(stderr, "invalid cols_in value %s\n", *argv); error_exit(usage); } if (sscanf(*argv++, "%d", &rows_in) != 1) { fprintf(stderr, "invalid rows_in value %s\n", *argv); error_exit(usage); } if (sscanf(*argv++, "%d", &col_start) != 1) { fprintf(stderr, "invalid col_start value %s\n", *argv); error_exit(usage); } if (sscanf(*argv++, "%d", &row_start) != 1) { fprintf(stderr, "invalid row_start value %s\n", *argv); error_exit(usage); } if (sscanf(*argv++, "%d", &cols_out) != 1) { fprintf(stderr, "invalid cols_out value %s\n", *argv); error_exit(usage); } if (sscanf(*argv++, "%d", &rows_out) != 1) { fprintf(stderr, "invalid rows_out value %s\n", *argv); error_exit(usage); } file_in = *argv++; file_out = *argv++; /* * display command line parameters */ if (verbose) { fprintf(stderr, "extract_region: %s\n", extract_region_c_rcsid); fprintf(stderr, " byte_swap: %d\n", byte_swap); fprintf(stderr, " scale: %lf\n", scale); fprintf(stderr, " float_scale: %d\n", float_scale); fprintf(stderr, " cells_per_col: %d\n", cells_per_col); fprintf(stderr, " bytes_per_cell: %d\n", bytes_per_cell); fprintf(stderr, " cols_in: %d\n", cols_in); fprintf(stderr, " rows_in: %d\n", rows_in); fprintf(stderr, " col_start: %d\n", col_start); fprintf(stderr, " row_start: %d\n", row_start); fprintf(stderr, " cols_out: %d\n", cols_out); fprintf(stderr, " rows_out: %d\n", rows_out); fprintf(stderr, " file_in: %s\n", file_in); fprintf(stderr, " file_out: %s\n", file_out); } /* * use loop even though it's one time through for easy error exit */ for(;;) { /* * check for a valid region */ if (col_start + cols_out > cols_in) { fprintf(stderr, "extract_region: col_start + cols_out must be <= cols_in\n"); there_were_errors = TRUE; } if (row_start + rows_out > rows_in) { fprintf(stderr, "extract_region: row_start + rows_out must be <= rows_in\n"); there_were_errors = TRUE; } if (bytes_per_cell != 1 && bytes_per_cell != 2 && bytes_per_cell != 4 && bytes_per_cell != 8) { fprintf(stderr, "extract_region: bytes_per_cell must be 1, 2, 4, or 8\n"); there_were_errors = TRUE; } if (float_scale == TRUE && scale != 1.0 && bytes_per_cell != 4 && bytes_per_cell != 8) { fprintf(stderr, "extract_region: bytes_per_cell must be 4 or 8 if -f is specified and scale != 1.0\n"); there_were_errors = TRUE; } if (there_were_errors) break; /* * initialize buffer size for i/o */ bytes_per_row_in = cols_in * cells_per_col * bytes_per_cell; bytes_per_row_out = cols_out * cells_per_col * bytes_per_cell; last_row_in_region = row_start + rows_out - 1; /* * allocate a buffer for each input and output grid file. */ if (very_verbose) fprintf(stderr, "extract_region: allocating buffers\n"); buf_in = (byte1 *)calloc(bytes_per_row_in, sizeof(byte1)); if (!buf_in) { fprintf(stderr, "error allocating %d bytes for file_in buffer\n", bytes_per_row_in); perror("extract_region"); there_were_errors = TRUE; break; } buf_out = buf_in + col_start * cells_per_col * bytes_per_cell; /* * open input file */ if (very_verbose) fprintf(stderr, "extract_region: opening input file\n"); fd_in = open(file_in, O_RDONLY); if (fd_in < 0) { fprintf(stderr, "error opening %s\n", file_in); perror("extract_region"); there_were_errors = TRUE; break; } /* * open output file */ if (very_verbose) fprintf(stderr, "extract_region: opening output file\n"); fd_out = creat(file_out, 0644); if (fd_out < 0) { fprintf(stderr, "error opening %s\n", file_out); perror("extract_region"); there_were_errors = TRUE; break; } /* * seek to first row in region of input file */ if (very_verbose) fprintf(stderr, "extract_region: seeking to first byte in region\n"); if (lseek(fd_in, (off_t)row_start * bytes_per_row_in, SEEK_SET) == -1) { fprintf(stderr, "error seeking to first row in region of %s\n", file_in); perror("extract_region"); there_were_errors = TRUE; break; } /* * for each row */ for (row = row_start; row <= last_row_in_region; row++) { if (very_very_verbose) fprintf(stderr, "reading row %d\n", row); if (read(fd_in, buf_in, bytes_per_row_in) != bytes_per_row_in) { fprintf(stderr, "error reading %s\n", file_in); perror("extract_region"); there_were_errors = TRUE; break; } if (byte_swap) swap_buffer(buf_out, cols_out, cells_per_col, bytes_per_cell); if (scale != 1.0) scale_buffer(buf_out, cols_out, cells_per_col, bytes_per_cell, scale, float_scale); if (very_very_verbose) fprintf(stderr, "writing row %d\n", row); if (write(fd_out, buf_out, bytes_per_row_out) != bytes_per_row_out) { fprintf(stderr, "error writing %s\n", file_out); perror("extract_region"); there_were_errors = TRUE; break; } } break; } /* * close input and output grid files */ if (fd_out >= 0) close(fd_out); if (fd_in) close(fd_in); /* * Deallocate buffers */ if (buf_in) free(buf_in); if (buf_temp) free(buf_temp); if (very_verbose) { if (there_were_errors) fprintf(stderr, "extract_region: done, but there were errors\n"); else fprintf(stderr, "extract_region: done, ok\n"); } return (there_were_errors ? EXIT_FAILURE : EXIT_SUCCESS); }
/* During a receive, the cur_rx points to the current incoming buffer. * When we update through the ring, if the next incoming buffer has * not been given to the system, we just set the empty indicator, * effectively tossing the packet. */ static int fec_enet_rx(struct net_device *ndev, int budget) { struct fec_enet_private *fep = netdev_priv(ndev); const struct platform_device_id *id_entry = platform_get_device_id(fep->pdev); struct bufdesc *bdp; unsigned short status; struct sk_buff *skb; ushort pkt_len; __u8 *data; int pkt_received = 0; #ifdef CONFIG_M532x flush_cache_all(); #endif /* First, grab all of the stats for the incoming packet. * These get messed up if we get called due to a busy condition. */ bdp = fep->cur_rx; while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) { if (pkt_received >= budget) break; pkt_received++; /* Since we have allocated space to hold a complete frame, * the last indicator should be set. */ if ((status & BD_ENET_RX_LAST) == 0) printk("FEC ENET: rcv is not +last\n"); if (!fep->opened) goto rx_processing_done; /* Check for errors. */ if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO | BD_ENET_RX_CR | BD_ENET_RX_OV)) { ndev->stats.rx_errors++; if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) { /* Frame too long or too short. */ ndev->stats.rx_length_errors++; } if (status & BD_ENET_RX_NO) /* Frame alignment */ ndev->stats.rx_frame_errors++; if (status & BD_ENET_RX_CR) /* CRC Error */ ndev->stats.rx_crc_errors++; if (status & BD_ENET_RX_OV) /* FIFO overrun */ ndev->stats.rx_fifo_errors++; } /* Report late collisions as a frame error. * On this error, the BD is closed, but we don't know what we * have in the buffer. So, just drop this frame on the floor. */ if (status & BD_ENET_RX_CL) { ndev->stats.rx_errors++; ndev->stats.rx_frame_errors++; goto rx_processing_done; } /* Process the incoming frame. */ ndev->stats.rx_packets++; pkt_len = bdp->cbd_datlen; ndev->stats.rx_bytes += pkt_len; data = (__u8*)__va(bdp->cbd_bufaddr); dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr, FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE); if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) swap_buffer(data, pkt_len); /* This does 16 byte alignment, exactly what we need. * The packet length includes FCS, but we don't want to * include that when passing upstream as it messes up * bridging applications. */ skb = netdev_alloc_skb(ndev, pkt_len - 4 + NET_IP_ALIGN); if (unlikely(!skb)) { printk("%s: Memory squeeze, dropping packet.\n", ndev->name); ndev->stats.rx_dropped++; } else { skb_reserve(skb, NET_IP_ALIGN); skb_put(skb, pkt_len - 4); /* Make room */ skb_copy_to_linear_data(skb, data, pkt_len - 4); skb->protocol = eth_type_trans(skb, ndev); /* Get receive timestamp from the skb */ if (fep->hwts_rx_en && fep->bufdesc_ex) { struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); unsigned long flags; struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; memset(shhwtstamps, 0, sizeof(*shhwtstamps)); spin_lock_irqsave(&fep->tmreg_lock, flags); shhwtstamps->hwtstamp = ns_to_ktime( timecounter_cyc2time(&fep->tc, ebdp->ts)); spin_unlock_irqrestore(&fep->tmreg_lock, flags); } if (!skb_defer_rx_timestamp(skb)) napi_gro_receive(&fep->napi, skb); } bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, data, FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE); rx_processing_done: /* Clear the status flags for this buffer */ status &= ~BD_ENET_RX_STATS; /* Mark the buffer empty */ status |= BD_ENET_RX_EMPTY; bdp->cbd_sc = status; if (fep->bufdesc_ex) { struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; ebdp->cbd_esc = BD_ENET_RX_INT; ebdp->cbd_prot = 0; ebdp->cbd_bdu = 0; } /* Update BD pointer to next entry */ if (status & BD_ENET_RX_WRAP) bdp = fep->rx_bd_base; else bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex); /* Doing this here will keep the FEC running while we process * incoming frames. On a heavily loaded network, we should be * able to keep up at the expense of system resources. */ writel(0, fep->hwp + FEC_R_DES_ACTIVE); } fep->cur_rx = bdp; return pkt_received; }
static netdev_tx_t fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev) { struct fec_enet_private *fep = netdev_priv(ndev); const struct platform_device_id *id_entry = platform_get_device_id(fep->pdev); struct bufdesc *bdp; void *bufaddr; unsigned short status; unsigned long flags; if (!fep->link) { /* Link is down or autonegotiation is in progress. */ return NETDEV_TX_BUSY; } spin_lock_irqsave(&fep->hw_lock, flags); /* Fill in a Tx ring entry */ bdp = fep->cur_tx; status = bdp->cbd_sc; if (status & BD_ENET_TX_READY) { /* Ooops. All transmit buffers are full. Bail out. * This should not happen, since ndev->tbusy should be set. */ printk("%s: tx queue full!.\n", ndev->name); spin_unlock_irqrestore(&fep->hw_lock, flags); return NETDEV_TX_BUSY; } /* Clear all of the status flags */ status &= ~BD_ENET_TX_STATS; /* Set buffer length and buffer pointer */ bufaddr = skb->data; bdp->cbd_datlen = skb->len; /* * On some FEC implementations data must be aligned on * 4-byte boundaries. Use bounce buffers to copy data * and get it aligned. Ugh. */ if (((unsigned long) bufaddr) & FEC_ALIGNMENT) { unsigned int index; if (fep->bufdesc_ex) index = (struct bufdesc_ex *)bdp - (struct bufdesc_ex *)fep->tx_bd_base; else index = bdp - fep->tx_bd_base; memcpy(fep->tx_bounce[index], skb->data, skb->len); bufaddr = fep->tx_bounce[index]; } /* * Some design made an incorrect assumption on endian mode of * the system that it's running on. As the result, driver has to * swap every frame going to and coming from the controller. */ if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) swap_buffer(bufaddr, skb->len); /* Save skb pointer */ fep->tx_skbuff[fep->skb_cur] = skb; ndev->stats.tx_bytes += skb->len; fep->skb_cur = (fep->skb_cur+1) & TX_RING_MOD_MASK; /* Push the data cache so the CPM does not get stale memory * data. */ bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, bufaddr, FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE); /* Send it on its way. Tell FEC it's ready, interrupt when done, * it's the last BD of the frame, and to put the CRC on the end. */ status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR | BD_ENET_TX_LAST | BD_ENET_TX_TC); bdp->cbd_sc = status; if (fep->bufdesc_ex) { struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; ebdp->cbd_bdu = 0; if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && fep->hwts_tx_en)) { ebdp->cbd_esc = (BD_ENET_TX_TS | BD_ENET_TX_INT); skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; } else { ebdp->cbd_esc = BD_ENET_TX_INT; } } /* Trigger transmission start */ writel(0, fep->hwp + FEC_X_DES_ACTIVE); /* If this was the last BD in the ring, start at the beginning again. */ if (status & BD_ENET_TX_WRAP) bdp = fep->tx_bd_base; else bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex); if (bdp == fep->dirty_tx) { fep->tx_full = 1; netif_stop_queue(ndev); } fep->cur_tx = bdp; skb_tx_timestamp(skb); spin_unlock_irqrestore(&fep->hw_lock, flags); return NETDEV_TX_OK; }
void write_rawiv_float(float *result,FILE* fp) { int i, j, k; float c_float; size_t fwrite_return; //#ifdef _LITTLE_ENDIAN if(!big_endian()) { swap_buffer((char *)minext, 3, sizeof(float)); swap_buffer((char *)maxext, 3, sizeof(float)); swap_buffer((char *)&nverts, 1, sizeof(int)); swap_buffer((char *)&ncells, 1, sizeof(int)); swap_buffer((char *)dim, 3, sizeof(unsigned int)); swap_buffer((char *)orig, 3, sizeof(float)); swap_buffer((char *)span, 3, sizeof(float)); } //#endif fwrite_return = fwrite(minext, sizeof(float), 3, fp); fwrite_return = fwrite(maxext, sizeof(float), 3, fp); fwrite_return = fwrite(&nverts, sizeof(int), 1, fp); fwrite_return = fwrite(&ncells, sizeof(int), 1, fp); fwrite_return = fwrite(dim, sizeof(unsigned int), 3, fp); fwrite_return = fwrite(orig, sizeof(float), 3, fp); fwrite_return = fwrite(span, sizeof(float), 3, fp); //#ifdef _LITTLE_ENDIAN if(!big_endian()) { swap_buffer((char *)minext, 3, sizeof(float)); swap_buffer((char *)maxext, 3, sizeof(float)); swap_buffer((char *)&nverts, 1, sizeof(int)); swap_buffer((char *)&ncells, 1, sizeof(int)); swap_buffer((char *)dim, 3, sizeof(unsigned int)); swap_buffer((char *)orig, 3, sizeof(float)); swap_buffer((char *)span, 3, sizeof(float)); } //#endif for (k=0; k<ZDIM; k++) for (j=0; j<YDIM; j++) for (i=0; i<XDIM; i++) { c_float = result[IndexVect(i,j,k)]; //#ifdef _LITTLE_ENDIAN if(!big_endian()) swap_buffer((char *)&c_float, 1, sizeof(float)); //#endif fwrite_return = fwrite(&c_float, sizeof(float), 1, fp); //#ifdef _LITTLE_ENDIAN if(!big_endian()) swap_buffer((char *)&c_float, 1, sizeof(float)); //#endif } fclose(fp); }
void read_data(int *xd, int *yd, int *zd, float **data, /*float *span_t, float *orig_t,*/ const char *input_name) { float c_float; unsigned char c_unchar; unsigned short c_unshort; int i,j,k; float *dataset; struct stat filestat; size_t size[3]; int datatype = 0; int found; FILE *fp; size_t fread_return=0; if ((fp=fopen(input_name, "rb"))==NULL){ printf("read error...\n"); exit(0); } stat(input_name, &filestat); /* reading RAWIV header */ fread_return = fread(minext, sizeof(float), 3, fp); fread_return = fread(maxext, sizeof(float), 3, fp); fread_return = fread(&nverts, sizeof(int), 1, fp); fread_return = fread(&ncells, sizeof(int), 1, fp); //#ifdef _LITTLE_ENDIAN if(!big_endian()) { swap_buffer((char *)minext, 3, sizeof(float)); swap_buffer((char *)maxext, 3, sizeof(float)); swap_buffer((char *)&nverts, 1, sizeof(int)); swap_buffer((char *)&ncells, 1, sizeof(int)); } //#endif size[0] = 12 * sizeof(float) + 2 * sizeof(int) + 3 * sizeof(unsigned int) + nverts * sizeof(unsigned char); size[1] = 12 * sizeof(float) + 2 * sizeof(int) + 3 * sizeof(unsigned int) + nverts * sizeof(unsigned short); size[2] = 12 * sizeof(float) + 2 * sizeof(int) + 3 * sizeof(unsigned int) + nverts * sizeof(float); found = 0; for (i = 0; i < 3; i++) if (size[i] == (unsigned int)filestat.st_size) { if (found == 0) { datatype = i; found = 1; } } if (found == 0) { printf("Corrupted file or unsupported dataset type\n"); exit(5); } fread_return = fread(dim, sizeof(unsigned int), 3, fp); fread_return = fread(orig, sizeof(float), 3, fp); fread_return = fread(span, sizeof(float), 3, fp); //#ifdef _LITTLE_ENDIAN if(!big_endian()) { swap_buffer((char *)dim, 3, sizeof(unsigned int)); swap_buffer((char *)orig, 3, sizeof(float)); swap_buffer((char *)span, 3, sizeof(float)); } //#endif /* span_t[0] = span[0]; span_t[1] = span[1]; span_t[2] = span[2]; orig_t[0] = orig[0]; orig_t[1] = orig[1]; orig_t[2] = orig[2]; */ XDIM = dim[0]; YDIM = dim[1]; ZDIM = dim[2]; dataset = (float *)malloc(sizeof(float)*XDIM*YDIM*ZDIM); maxraw = -99999999.f; minraw = 99999999.f; if (datatype == 0) { printf("data type: unsigned char \n"); for (i=0; i<ZDIM; i++) for (j=0; j<YDIM; j++) for (k=0; k<XDIM; k++) { fread_return = fread(&c_unchar, sizeof(unsigned char), 1, fp); dataset[IndexVect(k,j,i)]=(float)c_unchar; if (c_unchar > maxraw) maxraw = c_unchar; if (c_unchar < minraw) minraw = c_unchar; } } else if (datatype == 1) { printf("data type: unsigned short \n"); for (i=0; i<ZDIM; i++) for (j=0; j<YDIM; j++) for (k=0; k<XDIM; k++) { fread_return = fread(&c_unshort, sizeof(unsigned short), 1, fp); //#ifdef _LITTLE_ENDIAN if(!big_endian()) swap_buffer((char *)&c_unshort, 1, sizeof(unsigned short)); //#endif dataset[IndexVect(k,j,i)]=(float)c_unshort; if (c_unshort > maxraw) maxraw = c_unshort; if (c_unshort < minraw) minraw = c_unshort; } } else if (datatype == 2) { printf("data type: float \n"); for (i=0; i<ZDIM; i++) for (j=0; j<YDIM; j++) for (k=0; k<XDIM; k++) { fread_return = fread(&c_float, sizeof(float), 1, fp); //#ifdef _LITTLE_ENDIAN if(!big_endian()) swap_buffer((char *)&c_float, 1, sizeof(float)); //#endif dataset[IndexVect(k,j,i)]=c_float; if (c_float > maxraw) maxraw = c_float; if (c_float < minraw) minraw = c_float; } } else { printf("error\n"); fclose(fp); exit(1); } fclose(fp); for (i=0; i<ZDIM; i++) for (j=0; j<YDIM; j++) for (k=0; k<XDIM; k++) dataset[IndexVect(k,j,i)] = 255*(dataset[IndexVect(k,j,i)] - minraw)/(maxraw-minraw); printf("minimum = %f, maximum = %f \n",minraw,maxraw); *xd = XDIM; *yd = YDIM; *zd = ZDIM; *data = dataset; loadedVolumeInfo.read(input_name); }
/* During a receive, the cur_rx points to the current incoming buffer. * When we update through the ring, if the next incoming buffer has * not been given to the system, we just set the empty indicator, * effectively tossing the packet. */ static void fec_enet_rx(struct rtnet_device *ndev, int *packets, nanosecs_abs_t *time_stamp) { struct fec_enet_private *fep = rtnetdev_priv(ndev); const struct platform_device_id *id_entry = platform_get_device_id(fep->pdev); struct bufdesc *bdp; unsigned short status; struct rtskb *skb; ushort pkt_len; __u8 *data; #ifdef CONFIG_M532x flush_cache_all(); #endif rtdm_lock_get(&fep->hw_lock); /* First, grab all of the stats for the incoming packet. * These get messed up if we get called due to a busy condition. */ bdp = fep->cur_rx; while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) { /* Since we have allocated space to hold a complete frame, * the last indicator should be set. */ if ((status & BD_ENET_RX_LAST) == 0) printk("FEC ENET: rcv is not +last\n"); if (!fep->opened) goto rx_processing_done; /* Check for errors. */ if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO | BD_ENET_RX_CR | BD_ENET_RX_OV)) { fep->stats.rx_errors++; if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) { /* Frame too long or too short. */ fep->stats.rx_length_errors++; } if (status & BD_ENET_RX_NO) /* Frame alignment */ fep->stats.rx_frame_errors++; if (status & BD_ENET_RX_CR) /* CRC Error */ fep->stats.rx_crc_errors++; if (status & BD_ENET_RX_OV) /* FIFO overrun */ fep->stats.rx_fifo_errors++; } /* Report late collisions as a frame error. * On this error, the BD is closed, but we don't know what we * have in the buffer. So, just drop this frame on the floor. */ if (status & BD_ENET_RX_CL) { fep->stats.rx_errors++; fep->stats.rx_frame_errors++; goto rx_processing_done; } /* Process the incoming frame. */ fep->stats.rx_packets++; pkt_len = bdp->cbd_datlen; fep->stats.rx_bytes += pkt_len; data = (__u8*)__va(bdp->cbd_bufaddr); dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr, FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE); if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) swap_buffer(data, pkt_len); /* This does 16 byte alignment, exactly what we need. * The packet length includes FCS, but we don't want to * include that when passing upstream as it messes up * bridging applications. */ skb = dev_alloc_rtskb(pkt_len - 4 + NET_IP_ALIGN, &fep->skb_pool); /* RTnet */ if (unlikely(!skb)) { printk("%s: Memory squeeze, dropping packet.\n", ndev->name); fep->stats.rx_dropped++; } else { rtskb_reserve(skb, NET_IP_ALIGN); rtskb_put(skb, pkt_len - 4); /* Make room */ memcpy(skb->data, data, pkt_len - 4); skb->protocol = rt_eth_type_trans(skb, ndev); skb->rtdev = ndev; skb->time_stamp = *time_stamp; rtnetif_rx(skb); (*packets)++; /* RTnet */ } bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, data, FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE); rx_processing_done: /* Clear the status flags for this buffer */ status &= ~BD_ENET_RX_STATS; /* Mark the buffer empty */ status |= BD_ENET_RX_EMPTY; bdp->cbd_sc = status; /* Update BD pointer to next entry */ if (status & BD_ENET_RX_WRAP) bdp = fep->rx_bd_base; else bdp++; /* Doing this here will keep the FEC running while we process * incoming frames. On a heavily loaded network, we should be * able to keep up at the expense of system resources. */ writel(0, fep->hwp + FEC_R_DES_ACTIVE); } fep->cur_rx = bdp; rtdm_lock_put(&fep->hw_lock); }
*/ void rebcmp_compose(REBCMP_CTX* ctx, REBGOB* winGob, REBGOB* gob, REBOOL only) /* ** Compose content of the specified gob. Main compositing function. ** ** If the ONLY arg is TRUE then the specified gob area will be ** rendered to the buffer at 0x0 offset.(used by TO-IMAGE) ** ***********************************************************************/ { REBINT max_depth = 1000; // avoid infinite loops REBD32 abs_x = 0; REBD32 abs_y = 0; REBD32 abs_ox; REBD32 abs_oy; REBGOB* parent_gob = gob; REBINT x = GOB_LOG_X_INT(gob); REBINT y = GOB_LOG_Y_INT(gob); REBINT w = GOB_LOG_W_INT(gob); REBINT h = GOB_LOG_H_INT(gob); /* RL_Print("Composing gob: %x (%dx%d, %dx%d) in wingob %x\n", gob, (int)GOB_LOG_X(gob), (int)GOB_LOG_Y(gob), GOB_W_INT(gob), GOB_H_INT(gob), winGob); */ //reset clip region to window area if (ctx->Win_Region != NULL){ XDestroyRegion(ctx->Win_Region); } ctx->Win_Region = XCreateRegion(); //calculate absolute offset of the gob while (GOB_PARENT(parent_gob) && (max_depth-- > 0) && !GET_GOB_FLAG(parent_gob, GOBF_WINDOW)) { abs_x += GOB_LOG_X(parent_gob); abs_y += GOB_LOG_Y(parent_gob); parent_gob = GOB_PARENT(parent_gob); } assert(max_depth > 0); //the offset is shifted to render given gob at offset 0x0 (used by TO-IMAGE) if (only){ ctx->absOffset.x = -abs_x; ctx->absOffset.y = -abs_y; abs_x = 0; abs_y = 0; } else { ctx->absOffset.x = 0; ctx->absOffset.y = 0; } ctx->New_Clip.x = abs_x; ctx->New_Clip.y = abs_y; ctx->New_Clip.width = GOB_LOG_W_INT(gob); ctx->New_Clip.height = GOB_LOG_H_INT(gob); //handle newly added gob case if (!GET_GOB_STATE(gob, GOBS_NEW)){ //calculate absolute old offset of the gob abs_ox = abs_x + (GOB_XO(gob) - GOB_LOG_X(gob)); abs_oy = abs_y + (GOB_YO(gob) - GOB_LOG_Y(gob)); //set region with old gob location and dimensions ctx->Old_Clip.x = abs_ox; ctx->Old_Clip.y = abs_oy; ctx->Old_Clip.width = GOB_WO_INT(gob); ctx->Old_Clip.height = GOB_HO_INT(gob); XUnionRectWithRegion(&ctx->Old_Clip, ctx->Win_Region, ctx->Win_Region); //RL_Print("OLD: %dx%d %dx%d\n",(REBINT)abs_ox, (REBINT)abs_oy, (REBINT)abs_ox + GOB_WO_INT(gob), (REBINT)abs_oy + GOB_HO_INT(gob)); } //RL_Print("NEW: %dx%d %dx%d\n",(REBINT)abs_x, (REBINT)abs_y, (REBINT)abs_x + GOB_LOG_W_INT(gob), (REBINT)abs_y + GOB_LOG_H_INT(gob)); //Create union of "new" and "old" gob location XUnionRectWithRegion(&ctx->New_Clip, ctx->Win_Region, ctx->Win_Region); /* XClipBox(ctx->Win_Region, &win_rect); RL_Print("Old+New, %dx%d,%dx%d\n", win_rect.x, win_rect.y, win_rect.x + win_rect.width, win_rect.y + win_rect.height); */ if (!XEmptyRegion(ctx->Win_Region)) { swap_buffer(ctx); ctx->Window_Buffer = rebcmp_get_buffer(ctx); if (gob == winGob) { memset(ctx->Window_Buffer, 0, ctx->pixbuf_len); } //redraw gobs process_gobs(ctx, winGob); rebcmp_release_buffer(ctx); ctx->Window_Buffer = NULL; } //update old GOB area GOB_XO(gob) = GOB_LOG_X(gob); GOB_YO(gob) = GOB_LOG_Y(gob); GOB_WO(gob) = GOB_LOG_W(gob); GOB_HO(gob) = GOB_LOG_H(gob); }
/********************************************************************************************************* * emulation thread - runs the core */ m64p_error main_init(void) { size_t i; unsigned int disable_extra_mem; static int channels[] = { 0, 1, 2, 3 }; /* take the r4300 emulator mode from the config file at this point and cache it in a global variable */ r4300emu = ConfigGetParamInt(g_CoreConfig, "R4300Emulator"); /* set some other core parameters based on the config file values */ no_compiled_jump = ConfigGetParamBool(g_CoreConfig, "NoCompiledJump"); disable_extra_mem = ConfigGetParamInt(g_CoreConfig, "DisableExtraMem"); #if 0 count_per_op = ConfigGetParamInt(g_CoreConfig, "CountPerOp"); #endif if (count_per_op <= 0) count_per_op = 2; /* do byte-swapping if it's not been done yet */ if (g_MemHasBeenBSwapped == 0) { swap_buffer(g_rom, 4, g_rom_size / 4); g_MemHasBeenBSwapped = 1; } if (g_DDMemHasBeenBSwapped == 0) { swap_buffer(g_ddrom, 4, g_ddrom_size / 4); g_DDMemHasBeenBSwapped = 1; } connect_all(&g_r4300, &g_dp, &g_sp, &g_ai, &g_pi, &g_ri, &g_si, &g_vi, &g_dd, g_rdram, (disable_extra_mem == 0) ? 0x800000 : 0x400000, g_rom, g_rom_size, g_ddrom, g_ddrom_size, g_dd_disk, g_dd_disk_size); init_memory(); // Attach rom to plugins printf("Gfx RomOpen.\n"); if (!gfx.romOpen()) { printf("Gfx RomOpen failed.\n"); return M64ERR_PLUGIN_FAIL; } printf("Input RomOpen.\n"); if (!input.romOpen()) { printf("Input RomOpen failed.\n"); gfx.romClosed(); return M64ERR_PLUGIN_FAIL; } /* connect external time source to AF_RTC component */ g_si.pif.af_rtc.user_data = NULL; g_si.pif.af_rtc.get_time = get_time_using_C_localtime; /* connect external game controllers */ for(i = 0; i < GAME_CONTROLLERS_COUNT; ++i) { g_si.pif.controllers[i].user_data = &channels[i]; g_si.pif.controllers[i].is_connected = egcvip_is_connected; g_si.pif.controllers[i].get_input = egcvip_get_input; } /* connect external rumblepaks */ for(i = 0; i < GAME_CONTROLLERS_COUNT; ++i) { g_si.pif.controllers[i].rumblepak.user_data = &channels[i]; g_si.pif.controllers[i].rumblepak.rumble = rvip_rumble; } /* connect saved_memory.mempacks to mempaks */ for(i = 0; i < GAME_CONTROLLERS_COUNT; ++i) { g_si.pif.controllers[i].mempak.user_data = NULL; g_si.pif.controllers[i].mempak.save = dummy_save; g_si.pif.controllers[i].mempak.data = &saved_memory.mempack[i][0]; } /* connect saved_memory.eeprom to eeprom */ g_si.pif.eeprom.user_data = NULL; g_si.pif.eeprom.save = dummy_save; g_si.pif.eeprom.data = saved_memory.eeprom; if (ROM_SETTINGS.savetype != EEPROM_16KB) { /* 4kbits EEPROM */ g_si.pif.eeprom.size = 0x200; g_si.pif.eeprom.id = 0x8000; } else { /* 16kbits EEPROM */ g_si.pif.eeprom.size = 0x800; g_si.pif.eeprom.id = 0xc000; } /* connect saved_memory.flashram to flashram */ g_pi.flashram.user_data = NULL; g_pi.flashram.save = dummy_save; g_pi.flashram.data = saved_memory.flashram; /* connect saved_memory.sram to SRAM */ g_pi.sram.user_data = NULL; g_pi.sram.save = dummy_save; g_pi.sram.data = saved_memory.sram; #ifdef DBG if (ConfigGetParamBool(g_CoreConfig, "EnableDebugger")) init_debugger(); #endif g_EmulatorRunning = 1; StateChanged(M64CORE_EMU_STATE, M64EMU_RUNNING); /* call r4300 CPU core and run the game */ r4300_reset_hard(); r4300_reset_soft(); r4300_init(); return M64ERR_SUCCESS; }
/*NAPI polling Receive packets */ static int fec_rx_poll(struct napi_struct *napi, int budget) { struct fec_enet_private *fep = container_of(napi, struct fec_enet_private, napi); struct net_device *ndev = napi->dev; struct fec_ptp_private *fpp = fep->ptp_priv; const struct platform_device_id *id_entry = platform_get_device_id(fep->pdev); int pkt_received = 0; struct bufdesc *bdp; unsigned short status; struct sk_buff *skb; ushort pkt_len; __u8 *data; if (fep->use_napi) WARN_ON(!budget); #ifdef CONFIG_M532x flush_cache_all(); #endif /* First, grab all of the stats for the incoming packet. * These get messed up if we get called due to a busy condition. */ bdp = fep->cur_rx; while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) { if (pkt_received >= budget) break; pkt_received++; /* Since we have allocated space to hold a complete frame, * the last indicator should be set. */ if ((status & BD_ENET_RX_LAST) == 0) dev_err(&ndev->dev, "FEC ENET: rcv is not +last\n"); if (!fep->opened) goto rx_processing_done; /* Check for errors. */ if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO | BD_ENET_RX_CR | BD_ENET_RX_OV)) { ndev->stats.rx_errors++; if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) { /* Frame too long or too short. */ ndev->stats.rx_length_errors++; } if (status & BD_ENET_RX_NO) /* Frame alignment */ ndev->stats.rx_frame_errors++; if (status & BD_ENET_RX_CR) /* CRC Error */ ndev->stats.rx_crc_errors++; if (status & BD_ENET_RX_OV) /* FIFO overrun */ ndev->stats.rx_fifo_errors++; } /* Report late collisions as a frame error. * On this error, the BD is closed, but we don't know what we * have in the buffer. So, just drop this frame on the floor. */ if (status & BD_ENET_RX_CL) { ndev->stats.rx_errors++; ndev->stats.rx_frame_errors++; goto rx_processing_done; } /* Process the incoming frame. */ ndev->stats.rx_packets++; pkt_len = bdp->cbd_datlen; ndev->stats.rx_bytes += pkt_len; data = (__u8 *)__va(bdp->cbd_bufaddr); if (bdp->cbd_bufaddr) dma_unmap_single(&ndev->dev, bdp->cbd_bufaddr, FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE); if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) swap_buffer(data, pkt_len); /* This does 16 byte alignment, exactly what we need. * The packet length includes FCS, but we don't want to * include that when passing upstream as it messes up * bridging applications. */ skb = dev_alloc_skb(pkt_len - 4 + NET_IP_ALIGN); if (unlikely(!skb)) { dev_err(&ndev->dev, "%s: Memory squeeze, dropping packet.\n", ndev->name); ndev->stats.rx_dropped++; } else { skb_reserve(skb, NET_IP_ALIGN); skb_put(skb, pkt_len - 4); /* Make room */ skb_copy_to_linear_data(skb, data, pkt_len - 4); /* 1588 messeage TS handle */ if (fep->ptimer_present) fec_ptp_store_rxstamp(fpp, skb, bdp); skb->protocol = eth_type_trans(skb, ndev); netif_receive_skb(skb); } bdp->cbd_bufaddr = dma_map_single(&ndev->dev, data, FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE); rx_processing_done: /* Clear the status flags for this buffer */ status &= ~BD_ENET_RX_STATS; /* Mark the buffer empty */ status |= BD_ENET_RX_EMPTY; bdp->cbd_sc = status; #ifdef CONFIG_ENHANCED_BD bdp->cbd_esc = BD_ENET_RX_INT; bdp->cbd_prot = 0; bdp->cbd_bdu = 0; #endif /* Update BD pointer to next entry */ if (status & BD_ENET_RX_WRAP) bdp = fep->rx_bd_base; else bdp++; /* Doing this here will keep the FEC running while we process * incoming frames. On a heavily loaded network, we should be * able to keep up at the expense of system resources. */ writel(0, fep->hwp + FEC_R_DES_ACTIVE); } fep->cur_rx = bdp; if (pkt_received < budget) { napi_complete(napi); fec_rx_int_is_enabled(ndev, true); } return pkt_received; }
void to_big_endian_buffer(void *buffer, size_t length, size_t count) { #ifndef M64P_BIG_ENDIAN swap_buffer(buffer, length, count); #endif }
void BPNN::_load_train_data() { const char fileName[] = "train-images.idx3-ubyte"; const char labelFileName[] = "train-labels.idx1-ubyte"; ifstream lab_ifs(labelFileName, ios_base::binary); ifstream ifs(fileName, ios_base::binary); if( lab_ifs.fail() ) { cerr << "[ERROR] error when open the label train file!" << endl; exit (0); } if (ifs.fail()) { cerr << "[ERROR] error when open the train file!" << endl; exit (0); } //Read train data number and image rows / cols char magicNum[4], ccount[4], crows[4], ccols[4]; ifs.read(magicNum, sizeof(magicNum)); ifs.read(ccount, sizeof(ccount)); ifs.read(crows, sizeof(crows)); ifs.read(ccols, sizeof(ccols)); swap_buffer(magicNum); swap_buffer(ccount); swap_buffer(crows); swap_buffer(ccols); int count, rows, cols; memcpy(&count, ccount, sizeof(count)); memcpy(&rows, crows, sizeof(rows)); memcpy(&cols, ccols, sizeof(cols)); lab_ifs.read(magicNum, sizeof(magicNum)); lab_ifs.read(ccount, sizeof(magicNum)); int idx = 0; while(! ifs.eof() && idx < _train_sample_cnt) { int pt = 0; double val[28][28]; for(int i = 0; i < 28; i ++) { for(int j = 0; j < 28; j ++) { char st[4] ={'0'}; ifs.read(st, 1); int t = 0; memcpy(&t, st, sizeof(t)); // load _x feature // _x[idx][pt ++] = t; val[i][j] = t; } } int tot = 0; for ( int i = 0; i < 7; i ++) { for ( int j = 0; j < 7; j ++) { int cnt = 0; for ( int k = i * 4; k < i * 4 + 4; k ++) { for ( int l = j * 4; l < j * 4 + 4; l ++) { if ( val[k][l] > 0 ) { cnt += 1; } } } _x[idx][pt ++] = cnt; tot += cnt; } } for ( int i = 0; i < pt; i ++) { _x[idx][i] /= tot*1.0; } char num[4] = {'0'}; lab_ifs.read(num, 1); int out; memcpy(&out, num, sizeof(out)); memset(_y[idx], 0, sizeof(_y[idx])); _y[idx][out] = 1; idx += 1; } cerr << "[LOG] Train data is loaded completed! "<<endl; }
void ZDisplay::update(uint32_t dtime) { swap_buffer(); }