u16 pci_r16 (usys bus_num, usys dev_num, usys func_num, usys addr) { usys data ; read_func (get_addr (bus_num, dev_num, func_num, addr), &data) ; data >>= (addr % 4) * 8 ; return ((u16) (data & 0xffff)) ; } /* End of Function pci_r16 () */
static bool_t decode_pcm_callback(void *data) { struct decode_pcm *self = (struct decode_pcm *) data; pcm_read_func_t read_func; sample_t *write_pos; u8_t *read_pos; u32_t s, num_samples; sample_t sample; size_t sz; sz = streambuf_read(self->read_buffer + self->leftover, 0, BLOCKSIZE - self->leftover, NULL); if (!sz) { current_decoder_state |= DECODE_STATE_UNDERRUN; return FALSE; } current_decoder_state &= ~DECODE_STATE_UNDERRUN; sz += self->leftover; read_func = pcm_read_funcs[(2 * self->sample_size) + self->big_endian]; read_pos = self->read_buffer; write_pos = self->write_buffer; num_samples = sz / pcm_sample_widths[self->sample_size]; if (self->stereo) { /* we need the same number of sample for both channels */ num_samples &= ~0x01; } for (s = 0; s < num_samples; s++) { sample = read_func(read_pos); *write_pos++ = sample; if (!self->stereo) { *write_pos++ = sample; } read_pos += pcm_sample_widths[self->sample_size]; } if (num_samples) { decode_output_samples(self->write_buffer, self->stereo ? num_samples / 2 : num_samples, self->sample_rate); } self->leftover = sz - (read_pos - self->read_buffer); if (self->leftover) { memcpy(self->read_buffer, read_pos, self->leftover); } return TRUE; }
svn_error_t * svn_spillbuf__process(svn_boolean_t *exhausted, svn_spillbuf_t *buf, svn_spillbuf_read_t read_func, void *read_baton, apr_pool_t *scratch_pool) { svn_boolean_t has_seeked = FALSE; apr_pool_t *iterpool = svn_pool_create(scratch_pool); *exhausted = FALSE; while (TRUE) { struct memblock_t *mem; svn_error_t *err; svn_boolean_t stop; svn_pool_clear(iterpool); /* If this call to read_data() will read from the spill file, and we have not seek'd the file... then do it now. */ if (!has_seeked) SVN_ERR(maybe_seek(&has_seeked, buf, iterpool)); /* Get some content to pass to the read callback. */ SVN_ERR(read_data(&mem, buf, iterpool)); if (mem == NULL) { *exhausted = TRUE; break; } err = read_func(&stop, read_baton, mem->data, mem->size, iterpool); return_buffer(buf, mem); if (err) return svn_error_trace(err); /* If the callbacks told us to stop, then we're done for now. */ if (stop) break; } svn_pool_destroy(iterpool); return SVN_NO_ERROR; }
/*---------------------------------------------------------------------------*/ void pci_w8 (usys bus_num, usys dev_num, usys func_num, usys addr, u8 val) { usys data ; read_func (get_addr (bus_num, dev_num, func_num, addr), &data) ; /* Zero out the correct byte */ data &= ~(0xff << (addr % 4) * 8) ; /* Write the needed value to correct byte */ data |= val << (addr % 4) * 8 ; /* Write back the value */ write_func (get_addr (bus_num, dev_num, func_num, addr), data) ; } /* End of Function pci_w8 () */
void pci_w16 (usys bus_num, usys dev_num, usys func_num, usys addr, u16 val) { usys data ; /* Read the Current Value */ read_func (get_addr (bus_num, dev_num, func_num, addr), &data) ; /* Zero out the correct 16 bits */ data &= ~(0xffff << (addr % 4) * 8) ; /* Write the needed value to correct byte */ data |= val << (addr % 4) * 8 ; write_func (get_addr (bus_num, dev_num, func_num, addr), data) ; } /* End of Function pci_w16 () */
void seq_parse_se_sf(seq_file_t *sf, uint8_t ascii_fq_offset, read_t *r1, void (*read_func)(read_t *r1, read_t *r2, uint8_t qoffset1, uint8_t qoffset2, void *ptr), void *reader_ptr) { status("[seq] Parsing sequence file %s", futil_inpath_str(sf->path)); // Guess offset if needed uint8_t qoffset = ascii_fq_offset; uint8_t qmin = ascii_fq_offset, qmax = 126; int format; if(ascii_fq_offset == 0 && (format = guess_fastq_format(sf)) != -1) { qmin = (uint8_t)FASTQ_MIN[format]; qmax = (uint8_t)FASTQ_MAX[format]; qoffset = (uint8_t)FASTQ_OFFSET[format]; } // warn_flags keeps track of which of the error msgs have been printed // (only print each error msg once per file) uint8_t warn_flags = 0; size_t num_se_reads = 0, num_pe_pairs = 0; int s; while((s = seq_read_primary(sf, r1)) > 0) { warn_flags = check_new_read(r1, qmin, qmax, sf->path, warn_flags); read_func(r1, NULL, qoffset, 0, reader_ptr); num_se_reads++; } if(s < 0) warn("Input error: %s\n", sf->path); char num_se_reads_str[100], num_pe_pairs_str[100]; ulong_to_str(num_pe_pairs, num_pe_pairs_str); ulong_to_str(num_se_reads, num_se_reads_str); status("[seq] Loaded %s reads and %s reads pairs (file: %s)", num_se_reads_str, num_pe_pairs_str, futil_inpath_str(sf->path)); }
int read_seq_write_rand(command_list *cl, DCB_registered_src *r_src, unsigned char is_overlay, cfile *out_cfh, unsigned long buf_size) { unsigned char *buf; unsigned char *p; unsigned long x, start=0, end=0, len=0; unsigned long max_pos = 0, pos = 0; unsigned long offset; signed long tmp_len; dcb_src_read_func read_func; cfile_window *cfw; u_dcb_src u_src; #define END_POS(x) ((x).src_pos + (x).len) pos = 0; max_pos = 0; if(is_overlay) { read_func = r_src->mask_read_func; } else { read_func = r_src->read_func; } assert(read_func != NULL); u_src = r_src->src_ptr; if(0 != cseek(u_src.cfh, 0, CSEEK_FSTART)) { ap_printf("cseeked failed: bailing, io_error 0\n"); return IO_ERROR; } if((buf = (unsigned char *)malloc(buf_size)) == NULL) { return MEM_ERROR; } // we should *never* go backwards u_src.cfh->state_flags |= CFILE_FLAG_BACKWARD_SEEKS; while(start < cl->com_count) { if(pos < cl->full_command[start].src_pos) { pos = cl->full_command[start].src_pos; max_pos = END_POS(cl->full_command[start]); } else { while(start < cl->com_count && pos > cl->full_command[start].src_pos) { start++; } if(start == cl->com_count) continue; pos = cl->full_command[start].src_pos; max_pos = MAX(max_pos, END_POS(cl->full_command[start])); } if(end < start) { end = start; } while(end < cl->com_count && cl->full_command[end].src_pos < max_pos) { max_pos = MAX(max_pos, END_POS(cl->full_command[end])); end++; } if(pos == max_pos) { continue; } while(pos < max_pos) { len = MIN(max_pos - pos, buf_size); x = read_func(u_src, pos, buf, len); // if(len < max_pos - pos) // v0printf("buffered %lu, max was %lu\n", len, max_pos - pos); if(len != x){ ap_printf("x=%lu, pos=%lu, len=%lu\n", x, pos, len); ap_printf("bailing, io_error 2\n"); free(buf); return IO_ERROR; } for(x=start; x < end; x++) { offset = MAX(cl->full_command[x].src_pos, pos); tmp_len = MIN(END_POS(cl->full_command[x]), pos + len) - offset; if(tmp_len > 0) { if(cl->full_command[x].ver_pos + (offset - cl->full_command[x].src_pos) != cseek(out_cfh, cl->full_command[x].ver_pos + (offset - cl->full_command[x].src_pos), CSEEK_FSTART)) { ap_printf("bailing, io_error 3\n"); free(buf); return IO_ERROR; } if(is_overlay) { p = buf + offset - pos; cfw = expose_page(out_cfh); if(cfw->write_end == 0) { cfw->write_start = cfw->pos; } while(buf + offset - pos + tmp_len > p) { if(cfw->pos == cfw->end) { cfw->write_end = cfw->end; cfw = next_page(out_cfh); if(cfw->end == 0) { ap_printf("bailing from applying overlay mask in read_seq_writ_rand\n"); free(buf); return IO_ERROR; } } cfw->buff[cfw->pos] += *p; p++; cfw->pos++; } cfw->write_end = cfw->pos; } else { if(tmp_len != cwrite(out_cfh, buf + offset - pos, tmp_len)) { ap_printf("bailing, io_error 4\n"); free(buf); return IO_ERROR; } } } } pos += len; } } u_src.cfh->state_flags &= ~CFILE_FLAG_BACKWARD_SEEKS; free(buf); return 0; }
u32 pci_r32 (usys bus_num, usys dev_num, usys func_num, usys addr) { usys data ; read_func (get_addr (bus_num, dev_num, func_num, addr), &data) ; return ((u32) data) ; } /* End of Function pci_r32 () */
static int serial(int argc, char ** argv) { struct chrdev * device = NULL; ssize_t (* read_func)(struct chrdev *, u8_t *, size_t); struct serial_parameter param; char * name = NULL, * str = NULL; char * baud = 0; char * data_bit = 0; char * parity = 0; char * stop_bit = 0; u8_t c; s32_t i; if(argc < 2) { serial_info(); return 0; } if( !strcmp((const char *)argv[1],"info") ) { serial_info(); } else if( !strcmp((const char *)argv[1],"send") ) { if(argc != 4) { printk("usage:\r\n serial [info]\r\n" " serial send <DEVICE NAME> <STRING>\r\n" " serial recv <DEVICE NAME>\r\n" " serial param <DEVICE NAME> [-b BAUD] [-d DATABITS] [-p PARITY] [-s STOPBITS]\r\n"); return (-1); } name = (char *)argv[2]; str = (char *)argv[3]; device = search_chrdev_with_type((const char *)name, CHR_DEV_SERIAL); if(!device) { printk(" not found serial device \"%s\"\r\n", name); printk(" try 'serial info' for list all of serial devices\r\n"); return -1; } if(device->open) (device->open)(device); if(device->write) (device->write)(device, (u8_t *)str, strlen(str)); if(device->close) (device->close)(device); } else if( !strcmp((const char *)argv[1],"recv") ) { if(argc != 3) { printk("usage:\r\n serial [info]\r\n" " serial send <DEVICE NAME> <STRING>\r\n" " serial recv <DEVICE NAME>\r\n" " serial param <DEVICE NAME> [-b BAUD] [-d DATABITS] [-p PARITY] [-s STOPBITS]\r\n"); return (-1); } name = (char *)argv[2]; device = search_chrdev_with_type((const char *)name, CHR_DEV_SERIAL); if(!device) { printk(" not found serial device \"%s\"\r\n", name); printk(" try 'serial info' for list all of serial devices\r\n"); return -1; } if(device->open) (device->open)(device); if(device->read) { read_func = device->read; while(1) { if(read_func(device, &c, 1) == 1) { if(isprint(c) || isspace(c)) printk("%c", c); else printk("<%02x>", c); } if(ctrlc()) break; } } if(device->close) (device->close)(device); } else if( !strcmp((const char *)argv[1],"param") ) { if(argc < 3) { printk("usage:\r\n serial [info]\r\n" " serial send <DEVICE NAME> <STRING>\r\n" " serial recv <DEVICE NAME>\r\n" " serial param <DEVICE NAME> [-b BAUD] [-d DATABITS] [-p PARITY] [-s STOPBITS]\r\n"); return (-1); } for(i=2; i<argc; i++) { if( !strcmp((const char *)argv[i],"-b") && (argc > i+1)) { baud = (char *)argv[i+1]; i++; } else if( !strcmp((const char *)argv[i],"-d") && (argc > i+1)) { data_bit = (char *)argv[i+1]; i++; } else if( !strcmp((const char *)argv[i],"-p") && (argc > i+1)) { parity = (char *)argv[i+1]; i++; } else if( !strcmp((const char *)argv[i],"-s") && (argc > i+1)) { stop_bit = (char *)argv[i+1]; i++; } else if(*argv[i] != '-' && strcmp((const char *)argv[i], "-") != 0) { name = (char *)argv[i]; device = search_chrdev_with_type((const char *)name, CHR_DEV_SERIAL); if(!device) { printk(" not found serial device \"%s\"\r\n", name); printk(" try 'serial info' for list all of serial devices\r\n"); return -1; } if(!(device->ioctl)) { printk(" don't support ioctl function at this device.\r\n"); return -1; } } } if(!name) { printk("usage:\r\n serial [info]\r\n" " serial send <DEVICE NAME> <STRING>\r\n" " serial recv <DEVICE NAME>\r\n" " serial param <DEVICE NAME> [-b BAUD] [-d DATABITS] [-p PARITY] [-s STOPBITS]\r\n"); return (-1); } if(baud) { if(!strcmp(baud, "50")) param.baud_rate = B50; else if(!strcmp(baud, "75")) param.baud_rate = B75; else if(!strcmp(baud, "110")) param.baud_rate = B110; else if(!strcmp(baud, "134")) param.baud_rate = B134; else if(!strcmp(baud, "200")) param.baud_rate = B200; else if(!strcmp(baud, "300")) param.baud_rate = B300; else if(!strcmp(baud, "600")) param.baud_rate = B600; else if(!strcmp(baud, "1200")) param.baud_rate = B1200; else if(!strcmp(baud, "1800")) param.baud_rate = B1800; else if(!strcmp(baud, "2400")) param.baud_rate = B2400; else if(!strcmp(baud, "4800")) param.baud_rate = B4800; else if(!strcmp(baud, "9600")) param.baud_rate = B9600; else if(!strcmp(baud, "19200")) param.baud_rate = B19200; else if(!strcmp(baud, "38400")) param.baud_rate = B38400; else if(!strcmp(baud, "57600")) param.baud_rate = B57600; else if(!strcmp(baud, "76800")) param.baud_rate = B76800; else if(!strcmp(baud, "115200")) param.baud_rate = B115200; else if(!strcmp(baud, "230400")) param.baud_rate = B230400; else if(!strcmp(baud, "380400")) param.baud_rate = B380400; else if(!strcmp(baud, "460800")) param.baud_rate = B460800; else if(!strcmp(baud, "921600")) param.baud_rate = B921600; else { printk("unrecognize the parameter of baud rate \"%s\"\r\n", baud); return -1; } if(device->ioctl(device, IOCTL_WR_SERIAL_BAUD_RATE, (void *)(&(param.baud_rate))) < 0) { printk("setting serial device's baud rate fail. (%s)\r\n", device->name); return -1; } } if(data_bit) { if(!strcmp(data_bit, "5")) param.data_bit = DATA_BITS_5; else if(!strcmp(data_bit, "6")) param.data_bit = DATA_BITS_6; else if(!strcmp(data_bit, "7")) param.data_bit = DATA_BITS_7; else if(!strcmp(data_bit, "8")) param.data_bit = DATA_BITS_8; else { printk("unrecognize the parameter of data bits \"%s\"\r\n", data_bit); return -1; } if(device->ioctl(device, IOCTL_WR_SERIAL_DATA_BITS, (void *)(&(param.data_bit))) < 0) { printk("setting serial device's data bits fail. (%s)\r\n", device->name); return -1; } } if(parity) { if(!strcmp(parity, "N")) param.parity = PARITY_NONE; else if(!strcmp(parity, "E")) param.parity = PARITY_EVEN; else if(!strcmp(parity, "O")) param.parity = PARITY_ODD; else { printk("unrecognize the parameter of parity \"%s\"\r\n", parity); return -1; } if(device->ioctl(device, IOCTL_WR_SERIAL_PARITY_BIT, (void *)(&(param.parity))) < 0) { printk("setting serial device's parity fail. (%s)\r\n", device->name); return -1; } } if(stop_bit) { if(!strcmp(stop_bit, "1")) param.stop_bit = STOP_BITS_1; else if(!strcmp(stop_bit, "1.5")) param.stop_bit = STOP_BITS_1_5; else if(!strcmp(stop_bit, "2")) param.stop_bit = STOP_BITS_2; else { printk("unrecognize the parameter of stop bits \"%s\"\r\n", stop_bit); return -1; } if(device->ioctl(device, IOCTL_WR_SERIAL_STOP_BITS, (void *)(&(param.stop_bit))) < 0) { printk("setting serial device's stop bit fail. (%s)\r\n", device->name); return -1; } } printk("setting serial device's parameter successed. (%s)\r\n", device->name); return 0; } else { printk("serial: invalid option '%s'\r\n", argv[1]); printk("usage:\r\n serial [info]\r\n" " serial send <DEVICE NAME> <STRING>\r\n" " serial recv <DEVICE NAME>\r\n" " serial param <DEVICE NAME> [-b BAUD] [-d DATABITS] [-p PARITY] [-s STOPBITS]\r\n"); printk("try 'help serial' for more information.\r\n"); return (-1); } return 0; }
void seq_parse_pe_sf(seq_file_t *sf1, seq_file_t *sf2, uint8_t ascii_fq_offset, read_t *r1, read_t *r2, void (*read_func)(read_t *_r1, read_t *_r2, uint8_t _qoffset1, uint8_t _qoffset2, void *_ptr), void *reader_ptr) { if(sf2 == NULL) { seq_parse_se_sf(sf1, ascii_fq_offset, r1, read_func, reader_ptr); return; } status("[seq] Parsing sequence files %s %s\n", futil_inpath_str(sf1->path), futil_inpath_str(sf2->path)); // Guess offset if needed uint8_t qoffset1 = ascii_fq_offset, qoffset2 = ascii_fq_offset; uint8_t qmin1 = ascii_fq_offset, qmin2 = ascii_fq_offset; uint8_t qmax1 = 126, qmax2 = 126; if(ascii_fq_offset == 0) { int fmt1, fmt2; if((fmt1 = guess_fastq_format(sf1)) != -1) { qmin1 = (uint8_t)FASTQ_MIN[fmt1]; qmax1 = (uint8_t)FASTQ_MAX[fmt1]; qoffset1 = (uint8_t)FASTQ_OFFSET[fmt1]; } if((fmt2 = guess_fastq_format(sf2)) != -1) { qmin2 = (uint8_t)FASTQ_MIN[fmt2]; qmax2 = (uint8_t)FASTQ_MAX[fmt2]; qoffset2 = (uint8_t)FASTQ_OFFSET[fmt2]; } } // warn_flags keeps track of which of the error msgs have been printed // (only print each error msg once per file) uint8_t warn_flags = 0; int success1, success2; size_t num_pe_pairs = 0; while(1) { success1 = seq_read_primary(sf1, r1); success2 = seq_read_primary(sf2, r2); if(success1 < 0) warn("input error: %s", sf1->path); if(success2 < 0) warn("input error: %s", sf2->path); if(!success1 != !success2) { warn("Different number of reads in pe files [%s; %s]\n", sf1->path, sf2->path); } if(success1 <= 0 || success2 <= 0) break; // PE // We don't care about read orientation at this point warn_flags = check_new_read(r1, qmin1, qmax1, sf1->path, warn_flags); warn_flags = check_new_read(r2, qmin2, qmax2, sf2->path, warn_flags); read_func(r1, r2, qoffset1, qoffset2, reader_ptr); num_pe_pairs++; } char num_pe_pairs_str[100]; ulong_to_str(num_pe_pairs, num_pe_pairs_str); status("[seq] Loaded %s read pairs (files: %s, %s)", num_pe_pairs_str, futil_inpath_str(sf1->path), futil_inpath_str(sf2->path)); }
void seq_parse_interleaved_sf(seq_file_t *sf, uint8_t ascii_fq_offset, read_t *r1, read_t *r2, void (*read_func)(read_t *_r1, read_t *_r2, uint8_t _qoffset1, uint8_t _qoffset2, void *_ptr), void *reader_ptr) { status("[seq] Reading a (possibly) interleaved file (expect both S.E. & P.E. reads)"); // Guess offset if needed uint8_t qoffset = ascii_fq_offset; uint8_t qmin = ascii_fq_offset, qmax = 126; int format; if(ascii_fq_offset == 0 && (format = guess_fastq_format(sf)) != -1) { qmin = (uint8_t)FASTQ_MIN[format]; qmax = (uint8_t)FASTQ_MAX[format]; qoffset = (uint8_t)FASTQ_OFFSET[format]; } read_t *r[2] = {r1,r2}; int ridx = 0, s; uint8_t warn_flags = 0; size_t num_se_reads = 0, num_pe_pairs = 0; while((s = seq_read_primary(sf, r[ridx])) > 0) { warn_flags = check_new_read(r[ridx], qmin, qmax, sf->path, warn_flags); if(ridx) { // ridx == 1 if(seq_read_names_cmp(r[0]->name.b, r[1]->name.b) == 0) { // Either read may be the first in the pair if from SAM/BAM int r0 = (r[1]->from_sam && seq_read_bam(r[1])->core.flag & BAM_FREAD1); read_func(r[r0], r[!r0], qoffset, qoffset, reader_ptr); num_pe_pairs++; ridx = 0; } else { read_func(r[0], NULL, qoffset, 0, reader_ptr); num_se_reads++; SWAP(r[0], r[1]); ridx = 1; } } else ridx = 1; } // Process last read if(ridx == 1) { read_func(r[0], NULL, qoffset, 0, reader_ptr); num_se_reads++; } if(s < 0) warn("Input error: %s\n", sf->path); char num_se_reads_str[100], num_pe_pairs_str[100]; ulong_to_str(num_pe_pairs, num_pe_pairs_str); ulong_to_str(num_se_reads, num_se_reads_str); status("[seq] Loaded %s reads and %s reads pairs (file: %s)", num_se_reads_str, num_pe_pairs_str, futil_inpath_str(sf->path)); }