int handle_raw_tx(struct modemctl *mc, struct sk_buff *skb) { struct raw_hdr raw; unsigned char ftr = 0x7e; unsigned sz; sz = skb->len + sizeof(raw) + 1; if (fifo_space(&mc->raw_tx) < sz) { MODEM_COUNT(mc, tx_fifo_full); return -1; } raw.start = 0x7f; raw.len = 6 + skb->len; raw.channel = RAW_CH_VNET0; raw.control = 0; fifo_write(&mc->raw_tx, &raw, sizeof(raw)); fifo_write(&mc->raw_tx, skb->data, skb->len); fifo_write(&mc->raw_tx, &ftr, 1); mc->ndev->stats.tx_packets++; mc->ndev->stats.tx_bytes += skb->len; mc->mmio_signal_bits |= MBD_SEND_RAW; dev_kfree_skb_irq(skb); return 0; }
void test4() { struct fifo p1; int buf1[256]; int output_buf[128]; int zero[128]; int buf_val[128]; int alt_buf_val[128]; size_t i; for(i = 0; i < 128; i++) { buf_val[i] = 0xaabbccdd; alt_buf_val[i] = 0x5ab8cc84; } fifo_init(&p1, buf1, sizeof(int), 128); ok1(fifo_amt(&p1) == 0); ok1(fifo_avail(&p1) == 128); ok1(p1.read == 0); fifo_write(&p1, buf_val, 128); for(i = 0; i < 128; i++) { buf1[128+i] = 0x01234567; } memset(zero, 0, 128*sizeof(int)); ok1(fifo_amt(&p1) == 128); ok1(fifo_avail(&p1) == 0); ok1(p1.read == 0); memset(output_buf, 0, 128); fifo_peek(&p1, output_buf, 128); ok1(memcmp(output_buf, buf_val, 128*sizeof(int)) == 0); memset(output_buf, 0, 128*sizeof(int)); fifo_consume(&p1, output_buf, 96); ok1(memcmp(output_buf, buf_val, 96*sizeof(int)) == 0); ok1(memcmp(&output_buf[96], zero, 32*sizeof(int)) == 0); ok1(fifo_amt(&p1) == 32); ok1(fifo_avail(&p1) == 96); ok1(p1.read == 96); fifo_write(&p1, buf_val, 32); ok1(fifo_amt(&p1) == 64); ok1(fifo_avail(&p1) == 64); ok1(p1.read == 96); memset(output_buf, 0, 128*sizeof(int)); fifo_write(&p1, alt_buf_val, 64); ok1(fifo_amt(&p1) == 128); ok1(fifo_avail(&p1) == 0); ok1(p1.read == 96); ok1(memcmp(buf1, buf_val, 32*sizeof(int)) == 0); ok1(memcmp(buf1+32, alt_buf_val, 64*sizeof(int)) == 0); ok1(memcmp(buf1+96, buf_val, 32*sizeof(int)) == 0); #define TEST4AMT 3 + 3 + 1 + 5 + 3 + 3 + 3 diag("----test4----\n#"); }
void SendLine() { uint8_t byte; //check if serial buffer is empty if(out->fifo.length==0) { /** for(i=0;i<128;i++) { if(Result[i]==whiteThreshold) byte = '.'; else if(Result[i]==blackThreshold) byte = '|'; else byte = 'x'; fifo_write(&out->fifo,&byte,1); } **/ /* uint8_t ones; uint8_t tens; uint8_t hunds; uint8_t thous; uint8_t tenThous; tenThous = (uint8_t)(exposureTime/10000); thous = (uint8_t)((exposureTime - tenThous*10000)%1000); hunds = (uint8_t)((exposureTime - tenThous*10000 - thous*1000)%100); tens = (uint8_t)((exposureTime - tenThous*10000 - thous*1000 - hunds*100)%10); ones = (uint8_t)(exposureTime - tenThous*10000 - thous*1000 - hunds*100 - tens*10); tenThous += 48; fifo_write(&out->fifo,&tenThous,1); thous += 48; fifo_write(&out->fifo,&thous,1); hunds += 48; fifo_write(&out->fifo,&hunds,1); tens += 48; fifo_write(&out->fifo,&tens,1); ones += 48; fifo_write(&out->fifo,&ones,1); */ uint32_t copyExposureTime = exposureTime; for(i=0; i<5; i++) { byte = exposureTime%10 + 0x30; exposureTime = exposureTime/10; fifo_write(&out->fifo,&byte,1); } byte = '\n'; fifo_write(&out->fifo,&byte,1); byte = '\r'; fifo_write(&out->fifo,&byte,1); exposureTime = copyExposureTime; } }
bool ffemu_push_video(ffemu_t *handle, const struct ffemu_video_data *data) { unsigned y; bool drop_frame = handle->video.frame_drop_count++ % handle->video.frame_drop_ratio; handle->video.frame_drop_count %= handle->video.frame_drop_ratio; if (drop_frame) return true; for (;;) { slock_lock(handle->lock); unsigned avail = fifo_write_avail(handle->attr_fifo); slock_unlock(handle->lock); if (!handle->alive) return false; if (avail >= sizeof(*data)) break; slock_lock(handle->cond_lock); if (handle->can_sleep) { handle->can_sleep = false; scond_wait(handle->cond, handle->cond_lock); handle->can_sleep = true; } else scond_signal(handle->cond); slock_unlock(handle->cond_lock); } slock_lock(handle->lock); // Tightly pack our frame to conserve memory. libretro tends to use a very large pitch. struct ffemu_video_data attr_data = *data; if (attr_data.is_dupe) attr_data.width = attr_data.height = attr_data.pitch = 0; else attr_data.pitch = attr_data.width * handle->video.pix_size; fifo_write(handle->attr_fifo, &attr_data, sizeof(attr_data)); int offset = 0; for (y = 0; y < attr_data.height; y++, offset += data->pitch) fifo_write(handle->video_fifo, (const uint8_t*)data->data + offset, attr_data.pitch); slock_unlock(handle->lock); scond_signal(handle->cond); return true; }
void DMA2_Stream0_IRQHandler(void) { int i, sam; short signed_buf[ADC_BUF_SZ/2]; /* Half transfer interrupt */ if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_HTIF0) != RESET) { half++; /* convert to signed */ for(i=0; i<ADC_BUF_SZ/2; i++) { sam = (int)adc_buf[i] - 32768; //sam = (int)adc_buf[i]; signed_buf[i] = sam; } /* write first half to fifo */ if (fifo_write(DMA2_Stream0_fifo, signed_buf, ADC_BUF_SZ/2) == -1) { adc_overflow++; } /* Clear DMA Stream Transfer Complete interrupt pending bit */ DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_HTIF0); } /* Transfer complete interrupt */ if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0) != RESET) { full++; /* convert to signed */ for(i=0; i<ADC_BUF_SZ/2; i++) { sam = (int)adc_buf[ADC_BUF_SZ/2 + i] - 32768; //sam = (int)adc_buf[ADC_BUF_SZ/2 + i]; signed_buf[i] = sam; } /* write second half to fifo */ if (fifo_write(DMA2_Stream0_fifo, signed_buf, ADC_BUF_SZ/2) == -1) { adc_overflow++; } /* Clear DMA Stream Transfer Complete interrupt pending bit */ DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0); } }
static ssize_t rs_write(void *data, const void *buf, size_t size) { rsd_t *rsd = (rsd_t*)data; if (rsd->has_error) return -1; if (rsd->nonblock) { size_t avail, write_amt; rsd_callback_lock(rsd->rd); avail = fifo_write_avail(rsd->buffer); write_amt = avail > size ? size : avail; fifo_write(rsd->buffer, buf, write_amt); rsd_callback_unlock(rsd->rd); return write_amt; } else { size_t written = 0; while (written < size && !rsd->has_error) { size_t avail; rsd_callback_lock(rsd->rd); avail = fifo_write_avail(rsd->buffer); if (avail == 0) { rsd_callback_unlock(rsd->rd); if (!rsd->has_error) { slock_lock(rsd->cond_lock); scond_wait(rsd->cond, rsd->cond_lock); slock_unlock(rsd->cond_lock); } } else { size_t write_amt = size - written > avail ? avail : size - written; fifo_write(rsd->buffer, (const char*)buf + written, write_amt); rsd_callback_unlock(rsd->rd); written += write_amt; } } return written; } }
static ssize_t alsa_thread_write(void *data, const void *buf, size_t size) { alsa_thread_t *alsa = (alsa_thread_t*)data; if (alsa->thread_dead) return -1; if (alsa->nonblock) { size_t avail; size_t write_amt; slock_lock(alsa->fifo_lock); avail = fifo_write_avail(alsa->buffer); write_amt = MIN(avail, size); fifo_write(alsa->buffer, buf, write_amt); slock_unlock(alsa->fifo_lock); return write_amt; } else { size_t written = 0; while (written < size && !alsa->thread_dead) { size_t avail; slock_lock(alsa->fifo_lock); avail = fifo_write_avail(alsa->buffer); if (avail == 0) { slock_unlock(alsa->fifo_lock); slock_lock(alsa->cond_lock); if (!alsa->thread_dead) scond_wait(alsa->cond, alsa->cond_lock); slock_unlock(alsa->cond_lock); } else { size_t write_amt = MIN(size - written, avail); fifo_write(alsa->buffer, (const char*)buf + written, write_amt); slock_unlock(alsa->fifo_lock); written += write_amt; } } return written; } }
/* must be called with pipe->tx_lock held */ static int modem_pipe_send(struct m_pipe *pipe, struct modem_io *io) { char hdr[M_PIPE_MAX_HDR]; static char ftr = 0x7e; unsigned size; int ret; ret = pipe->push_header(io, hdr); if (ret) return ret; size = io->size + pipe->header_size + 1; if (io->size > 0x10000000) return -EINVAL; if (size >= (pipe->tx->size - 1)) return -EINVAL; for (;;) { ret = modem_acquire_mmio(pipe->mc); if (ret) return ret; modem_update_pipe(pipe); if (pipe->tx->avail >= size) { fifo_write(pipe->tx, hdr, pipe->header_size); fifo_write_user(pipe->tx, io->data, io->size); fifo_write(pipe->tx, &ftr, 1); modem_update_pipe(pipe); modem_release_mmio(pipe->mc, pipe->tx->bits); MODEM_COUNT(pipe->mc, pipe_tx); return 0; } pr_info("modem_pipe_send: wait for space\n"); MODEM_COUNT(pipe->mc, pipe_tx_delayed); modem_release_mmio(pipe->mc, 0); ret = wait_event_interruptible_timeout( pipe->mc->wq, (pipe->tx->avail >= size) || modem_offline(pipe->mc), 5 * HZ); if (ret == 0) return -ENODEV; if (ret < 0) return ret; } }
// The top-level function for AUGH void augh_main () { do { fifo_read(stdin, &input[0]); fifo_read(stdin, &input[1]); fifo_read(stdin, &input[2]); bidon(); fifo_write(stdout, &output[0]); fifo_write(stdout, &output[1]); }while(1); }
bool ffemu_push_audio(ffemu_t *handle, const struct ffemu_audio_data *data) { for (;;) { slock_lock(handle->lock); unsigned avail = fifo_write_avail(handle->audio_fifo); slock_unlock(handle->lock); if (!handle->alive) return false; if (avail >= data->frames * handle->params.channels * sizeof(int16_t)) break; slock_lock(handle->cond_lock); if (handle->can_sleep) { handle->can_sleep = false; scond_wait(handle->cond, handle->cond_lock); handle->can_sleep = true; } else scond_signal(handle->cond); slock_unlock(handle->cond_lock); } slock_lock(handle->lock); fifo_write(handle->audio_fifo, data->data, data->frames * handle->params.channels * sizeof(int16_t)); slock_unlock(handle->lock); scond_signal(handle->cond); return true; }
static int decoder(playa_info_t * info) { int status; int n; status = FillYM(); if (status < 0) { spool_error_message(); return INP_DECODE_ERROR; } if (status & INP_DECODE_INFO) { disk_info(info, 0); } n = 0; if (app.mix.buflen > 0) { n = fifo_write((int *)app.mix.buf, app.mix.buflen); if (n > 0) { app.mix.buf += n; app.mix.buflen -= n; } } if (!n) { /* Nothing has been written. fifo must be full ! */ status &= ~INP_DECODE_CONT; } return (n < 0) ? INP_DECODE_ERROR : status; }
sampleCount EffectReverb::ProcessBlock(float **inBlock, float **outBlock, sampleCount blockLen) { float *ichans[2] = {NULL, NULL}; float *ochans[2] = {NULL, NULL}; for (int c = 0; c < mNumChans; c++) { ichans[c] = inBlock[c]; ochans[c] = outBlock[c]; } float const dryMult = mParams.mWetOnly ? 0 : dB_to_linear(mParams.mDryGain); sampleCount remaining = blockLen; while (remaining) { sampleCount len = wxMin(remaining, BLOCK); for (int c = 0; c < mNumChans; c++) { // Write the input samples to the reverb fifo. Returned value is the address of the // fifo buffer which contains a copy of the input samples. mP[c].dry = (float *) fifo_write(&mP[c].reverb.input_fifo, len, ichans[c]); reverb_process(&mP[c].reverb, len); } if (mNumChans == 2) { for (sampleCount i = 0; i < len; i++) { for (int w = 0; w < 2; w++) { ochans[w][i] = dryMult * mP[w].dry[i] + 0.5 * (mP[0].wet[w][i] + mP[1].wet[w][i]); } } } else { for (sampleCount i = 0; i < len; i++) { ochans[0][i] = dryMult * mP[0].dry[i] + mP[0].wet[0][i]; } } remaining -= len; for (int c = 0; c < mNumChans; c++) { ichans[c] += len; ochans[c] += len; } } return blockLen; }
static ssize_t dsound_write(void *data, const void *buf_, size_t size) { size_t written = 0; dsound_t *ds = (dsound_t*)data; const uint8_t *buf = (const uint8_t*)buf_; if (!ds->thread_alive) return -1; while (size > 0) { size_t avail; EnterCriticalSection(&ds->crit); avail = fifo_write_avail(ds->buffer); if (avail > size) avail = size; fifo_write(ds->buffer, buf, avail); LeaveCriticalSection(&ds->crit); buf += avail; size -= avail; written += avail; if (ds->nonblock || !ds->thread_alive) break; if (avail == 0) WaitForSingleObject(ds->event, INFINITE); } return written; }
static PyObject* fifoWrite(PyObject* self, PyObject* arg) { PyObject* transferTuple; unsigned int id, returnVal ; if(!PyArg_ParseTuple(arg, "lO", &id, &transferTuple)) return NULL; if(!PyTuple_Check(transferTuple)) pabort("Only accepts a single tuple as an argument\n"); uint32_t tupleSize = PyTuple_Size(transferTuple); uint8_t tx[tupleSize]; PyObject* tempItem; uint32_t i=0; while(i < tupleSize) { tempItem = PyTuple_GetItem(transferTuple, i); if(!PyInt_Check(tempItem)) { pabort("non-integer contained in tuple\n"); } tx[i] = (uint8_t)PyInt_AsSsize_t(tempItem); i++; } returnVal = fifo_write(id, tx, tupleSize); return Py_BuildValue("l", returnVal) ; }
void test_is_empty(void) { uint32_t dummy; TEST_ASSERT_TRUE(fifo_isEmpty(&ff_non_overwritable)); fifo_write(&ff_non_overwritable, &dummy); TEST_ASSERT_FALSE(fifo_isEmpty(&ff_non_overwritable)); }
uint8_t fifo_write_array(fifo_t *fifo, uint8_t *array, uint8_t size) { uint8_t i = 0; while(i < size && fifo_write(fifo, array[i]) == 0) { i++; } return i; }
static telnet_send_opt(fifo_buffer *out, char code, char opt) { char buf[3]; buf[0] = TELNET_IAC; buf[1] = code; buf[2] = opt; fifo_write(out, buf, 3); }
static ssize_t sdl_audio_write(void *data, const void *buf, size_t size) { sdl_audio_t *sdl = (sdl_audio_t*)data; ssize_t ret = 0; if (sdl->nonblock) { SDL_LockAudio(); size_t avail = fifo_write_avail(sdl->buffer); size_t write_amt = avail > size ? size : avail; fifo_write(sdl->buffer, buf, write_amt); SDL_UnlockAudio(); ret = write_amt; } else { size_t written = 0; while (written < size) { SDL_LockAudio(); size_t avail = fifo_write_avail(sdl->buffer); if (avail == 0) { SDL_UnlockAudio(); slock_lock(sdl->lock); scond_wait(sdl->cond, sdl->lock); slock_unlock(sdl->lock); } else { size_t write_amt = size - written > avail ? avail : size - written; fifo_write(sdl->buffer, (const char*)buf + written, write_amt); SDL_UnlockAudio(); written += write_amt; } } ret = written; } return ret; }
/* * Write wrapper for fifo's. */ int ufsfifo_write(void *v) { struct vop_write_args *ap = v; /* * Set update and change flags. */ VTOI(ap->a_vp)->i_flag |= IN_CHANGE | IN_UPDATE; return (fifo_write(ap)); }
static void *sdl_audio_init(const char *device, unsigned rate, unsigned latency) { (void)device; if (SDL_WasInit(0) == 0) { if (SDL_Init(SDL_INIT_AUDIO) < 0) return NULL; } else if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) return NULL; sdl_audio_t *sdl = (sdl_audio_t*)calloc(1, sizeof(*sdl)); if (!sdl) return NULL; // We have to buffer up some data ourselves, so we let SDL carry approx half of the latency. SDL double buffers audio and we do as well. int frames = find_num_frames(rate, latency / 4); SDL_AudioSpec spec = {0}; spec.freq = rate; spec.format = AUDIO_S16SYS; spec.channels = 2; spec.samples = frames; // This is in audio frames, not samples ... :( spec.callback = sdl_audio_cb; spec.userdata = sdl; SDL_AudioSpec out; if (SDL_OpenAudio(&spec, &out) < 0) { RARCH_ERR("Failed to open SDL audio: %s\n", SDL_GetError()); free(sdl); return 0; } g_settings.audio.out_rate = out.freq; sdl->lock = slock_new(); sdl->cond = scond_new(); RARCH_LOG("SDL audio: Requested %u ms latency, got %d ms\n", latency, (int)(out.samples * 4 * 1000 / g_settings.audio.out_rate)); // Create a buffer twice as big as needed and prefill the buffer. size_t bufsize = out.samples * 4 * sizeof(int16_t); void *tmp = calloc(1, bufsize); sdl->buffer = fifo_new(bufsize); if (tmp) { fifo_write(sdl->buffer, tmp, bufsize); free(tmp); } SDL_PauseAudio(0); return sdl; }
void test_is_full(void) { TEST_ASSERT_FALSE(fifo_isFull(&ff_non_overwritable)); for(uint32_t i=0; i < FIFO_SIZE; i++) { fifo_write(&ff_non_overwritable, &i); } TEST_ASSERT_TRUE(fifo_isFull(&ff_non_overwritable)); }
static void libusb_hid_device_send_control(void *data, uint8_t* data_buf, size_t size) { struct libusb_adapter *adapter = (struct libusb_adapter*)data; if (!adapter) return; slock_lock(adapter->send_control_lock); if (fifo_write_avail(adapter->send_control_buffer) >= size + sizeof(size)) { fifo_write(adapter->send_control_buffer, &size, sizeof(size)); fifo_write(adapter->send_control_buffer, data_buf, size); } else { RARCH_WARN("adapter write buffer is full, cannot write send control\n"); } slock_unlock(adapter->send_control_lock); }
void test_normal(void) { for(uint32_t i=0; i < FIFO_SIZE; i++) { fifo_write(&ff_non_overwritable, &i); } for(uint32_t i=0; i < FIFO_SIZE; i++) { uint32_t c; fifo_read(&ff_non_overwritable, &c); TEST_ASSERT_EQUAL(i, c); } }
void SendRawData() { uint8_t byte; //check if serial buffer is empty if(out->fifo.length==0) { for(i=0; i<128; i++) { byte = lineADC[i]; fifo_write(&out->fifo,&byte,1); } byte = line_middle; fifo_write(&out->fifo,&byte,1); for(i=0; i<5; i++) { byte = (i%2 == 0)?255:0; fifo_write(&out->fifo,&byte,1); } } }
int tmpfs_fifo_write(void *v) { struct vop_write_args /* { struct vnode *a_vp; struct uio *a_uio; int a_ioflag; kauth_cred_t a_cred; } */ *ap = v; struct vnode *vp = ap->a_vp; VP_TO_TMPFS_NODE(vp)->tn_status |= TMPFS_NODE_MODIFIED; return (fifo_write(v)); }
void test_circular(void) { FIFO_DEF(ff_overwritable, 2, uint32_t, true, 0); uint32_t data; // feed fifo to full data = 1; fifo_write(&ff_overwritable, &data); // 1 data = 2; fifo_write(&ff_overwritable, &data); // 2 // overflow data data = 100; fifo_write(&ff_overwritable, &data); //------------- 1st read should be 2, second is 100 -------------// fifo_read(&ff_overwritable, &data); TEST_ASSERT_EQUAL(2, data); fifo_read(&ff_overwritable, &data); TEST_ASSERT_EQUAL(100, data); }
/* must be called with pipe->tx_lock held */ static int modem_pipe_send(struct m_pipe *pipe, struct modem_io *io) { char hdr[M_PIPE_MAX_HDR]; unsigned size; int ret; io->magic = 0xCAFECAFE; ret = pipe->push_header(io, hdr); if (ret) return ret; size = io->datasize + pipe->header_size; if (size > 0x1000 /*pipe->tx->size*/) { pr_err ("Trying to send bigger than 4kB frame - MULTIPACKET not implemented yet.\n"); return -EINVAL; } for (;;) { ret = modem_acquire_mmio(pipe->mc); if (ret) return ret; modem_update_pipe(pipe); if (pipe->tx->avail >= size) { fifo_write(pipe->tx, hdr, pipe->header_size); fifo_move_head(pipe->tx, pipe->header_size); fifo_write_user(pipe->tx, io->data, io->datasize); fifo_move_head(pipe->tx, SIZ_PACKET_BUFSIZE); modem_update_pipe(pipe); modem_release_mmio(pipe->mc, pipe->tx->bits); MODEM_COUNT(pipe->mc, pipe_tx); return 0; } pr_info("modem_pipe_send: wait for space\n"); MODEM_COUNT(pipe->mc, pipe_tx_delayed); modem_release_mmio(pipe->mc, 0); ret = wait_event_interruptible(pipe->mc->wq, (pipe->tx->avail >= size) || modem_offline(pipe->mc)); if (ret) return ret; } }
void do_kb() //0x21 { outb(0x20,0x61); /* master PIC */ scan_code = inb(0x60); if(scan_code == 0x2a || scan_code == 0x36) { key_shf = 1; outb(0x20,0x61); /* master PIC */ return; } else if(scan_code == 0xaa || scan_code == 0xb6) key_shf = 0; //show_char(); fifo_write(&global_fifo,scan_code+KB_STA); }
int qm_ss_spi_irq_transfer(const qm_ss_spi_t spi, const qm_ss_spi_async_transfer_t *const xfer) { QM_CHECK(spi < QM_SS_SPI_NUM, -EINVAL); QM_CHECK(xfer, -EINVAL); /* Load and save initial control register */ uint32_t ctrl = __builtin_arc_lr(base[spi] + QM_SS_SPI_CTRL); uint8_t tmode = (uint8_t)((ctrl & QM_SS_SPI_CTRL_TMOD_MASK) >> QM_SS_SPI_CTRL_TMOD_OFFS); uint8_t bytes = BYTES_PER_FRAME(ctrl); QM_CHECK(tmode == QM_SS_SPI_TMOD_TX_RX ? (xfer->tx_len == xfer->rx_len) : 1, -EINVAL); spi_async_transfer[spi] = xfer; tx_c[spi] = xfer->tx_len; rx_c[spi] = xfer->rx_len; /* Set NDF (Number of Data Frames) in RX or EEPROM Read mode. (-1) */ if (tmode == QM_SS_SPI_TMOD_RX || tmode == QM_SS_SPI_TMOD_EEPROM_READ) { ctrl &= ~QM_SS_SPI_CTRL_NDF_MASK; ctrl |= ((xfer->rx_len - 1) << QM_SS_SPI_CTRL_NDF_OFFS) & QM_SS_SPI_CTRL_NDF_MASK; __builtin_arc_sr(ctrl, base[spi] + QM_SS_SPI_CTRL); } uint32_t ftlr = (((FIFO_RX_W_MARK < xfer->rx_len ? FIFO_RX_W_MARK : xfer->rx_len) - 1) << QM_SS_SPI_FTLR_RFT_OFFS) & QM_SS_SPI_FTLR_RFT_MASK; __builtin_arc_sr(ftlr, base[spi] + QM_SS_SPI_FTLR); /* Unmask all interrupts */ __builtin_arc_sr(QM_SS_SPI_INTR_ALL, base[spi] + QM_SS_SPI_INTR_MASK); /* Enable SPI device */ QM_SS_REG_AUX_OR(base[spi] + QM_SS_SPI_SPIEN, QM_SS_SPI_SPIEN_EN); /* RX only transfers need a dummy frame byte to be sent. */ if (tmode == QM_SS_SPI_TMOD_RX) { fifo_write(spi, (uint8_t *)&dummy_frame, bytes); } return 0; }
static ssize_t coreaudio_write(void *data, const void *buf_, size_t size) { coreaudio_t *dev = (coreaudio_t*)data; const uint8_t *buf = (const uint8_t*)buf_; size_t written = 0; #ifdef IOS struct timeval time; gettimeofday(&time, 0); struct timespec timeout; memset(&timeout, 0, sizeof(timeout)); timeout.tv_sec = time.tv_sec + 3; timeout.tv_nsec = time.tv_usec * 1000; #endif while (!g_interrupted && size > 0) { pthread_mutex_lock(&dev->lock); size_t write_avail = fifo_write_avail(dev->buffer); if (write_avail > size) write_avail = size; fifo_write(dev->buffer, buf, write_avail); buf += write_avail; written += write_avail; size -= write_avail; if (dev->nonblock) { pthread_mutex_unlock(&dev->lock); break; } #ifdef IOS if (write_avail == 0 && pthread_cond_timedwait(&dev->cond, &dev->lock, &timeout) == ETIMEDOUT) g_interrupted = true; #else if (write_avail == 0) pthread_cond_wait(&dev->cond, &dev->lock); #endif pthread_mutex_unlock(&dev->lock); } return written; }