Ejemplo n.º 1
0
Archivo: midi.c Proyecto: recri/keyer
static int _read(_t *data, jack_nframes_t *framep, Tcl_Obj **bytes) {
  if (ring_buffer_items_available_to_read(&data->rb) < 3+sizeof(jack_nframes_t)+sizeof(size_t))
    return 0;
  int n = ring_buffer_get(&data->rb, sizeof(*framep), (unsigned char *)framep);
  size_t size;
  n += ring_buffer_get(&data->rb, sizeof(size), (unsigned char *)&size);
  *bytes = Tcl_NewObj();
  n += ring_buffer_get(&data->rb, size, Tcl_SetByteArrayLength(*bytes, size));
  return n;
}
Ejemplo n.º 2
0
SEXP R_ring_buffer_copy(SEXP srcPtr, SEXP destPtr, SEXP r_count) {
  size_t count = INTEGER(r_count)[0];
  ring_buffer *src = ring_buffer_get(srcPtr, 1),
    *dest = ring_buffer_get(destPtr, 1);
  data_t * head = (data_t *) ring_buffer_copy(dest, src, count);
  if (head == NULL) {
    // TODO: better reporting here; make this a general thing I think.
    // See memcpy_from and tail_read for other places this is needed.
    Rf_error("Buffer underflow");
  }
  return ScalarInteger(head - dest->data);
}
Ejemplo n.º 3
0
int uart_read (struct file * filp, char *buf, size_t count, loff_t *t)
{
    int rcount=0;

    // To do: increase the semaphore


    while ( (rcount < count) && !ring_buffer_isenmpty(&ring) ) {
        // read recive character form register
        *(prbuf+rcount)=ring_buffer_get (&ring);
        rcount++;
    }

    // To do: decrease the semaphore


    if( rcount != 0 ) {
      // Copy the data to user space
      if( copy_to_user(buf, prbuf, rcount) != 0) {
        return -EFAULT;
      }
    }

    return rcount;
}
Ejemplo n.º 4
0
int uart_read (struct file * filp, char *buf, size_t count, loff_t *t)
{
    int rcount=0;

    if( ring_buffer_isenmpty(&ring) ) {
      // To do: wait for an event.
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
      bSleep=0;
      wait_event_interruptible(wq, bSleep);
#elif LINUX_VERSION_CODE > KERNEL_VERSION(2,4,0)
      interruptible_sleep_on(&wq);
#endif
    }

    while ( (rcount < count) && !ring_buffer_isenmpty(&ring) ) {
      *(prbuf+rcount)=ring_buffer_get(&ring);
      printk("uart_int: %c\n", *(prbuf+rcount));
      rcount++;
    }

    if( rcount != 0 ) {
      if( copy_to_user(buf, prbuf, rcount) != 0)
        return -EFAULT;
    }

    return rcount;
}
Ejemplo n.º 5
0
void ring_buffer_finalize(SEXP extPtr) {
  ring_buffer *buffer = ring_buffer_get(extPtr, 0);
  if (buffer) {
    ring_buffer_destroy(buffer);
    R_ClearExternalPtr(extPtr);
  }
}
Ejemplo n.º 6
0
bool
ring_cursor_next(Cursor *scursor) {
  ring_buffer_cursor *cursor = (ring_buffer_cursor *)scursor;
  bool out = ++cursor->pos < (cursor->rb->written - cursor->rb->capacity);
  cursor->as_cursor.data = ring_buffer_get(cursor->rb, cursor->pos * cursor->width, cursor->width);
  return out;
}
Ejemplo n.º 7
0
SEXP R_ring_buffer_data(SEXP extPtr) {
  ring_buffer * buffer = ring_buffer_get(extPtr, 1);
  size_t len = ring_buffer_size(buffer, 1);
  SEXP ret = PROTECT(allocVector(RAWSXP, len));
  memcpy(RAW(ret), ring_buffer_data(buffer), len);
  UNPROTECT(1);
  return ret;
}
Ejemplo n.º 8
0
bool
ring_cursor_prev(Cursor *scursor) {
  ring_buffer_cursor *cursor = (ring_buffer_cursor *)scursor;
  long max = cursor->rb->written / cursor->width;
  if(cursor->pos > max) {
    cursor->pos = max;
  }
  cursor->pos--;
  return (cursor->as_cursor.data = ring_buffer_get(cursor->rb, cursor->pos * cursor->width, cursor->width));
}
Ejemplo n.º 9
0
SEXP R_ring_buffer_tail(SEXP extPtr) {
  ring_buffer * buffer = ring_buffer_get(extPtr, 1);
  if (ring_buffer_empty(buffer)) {
    Rf_error("Buffer is empty");
  }
  SEXP ret = PROTECT(allocVector(RAWSXP, buffer->stride));
  memcpy(RAW(ret), ring_buffer_tail(buffer), buffer->stride);
  UNPROTECT(1);
  return ret;
}
Ejemplo n.º 10
0
SEXP R_ring_buffer_memcpy_into(SEXP extPtr, SEXP src) {
  ring_buffer *buffer = ring_buffer_get(extPtr, 1);
  size_t len = LENGTH(src), stride = buffer->stride;
  if (len % stride != 0) {
    Rf_error("Incorrect size data (%d bytes); expected multiple of %d bytes",
             len, stride);
  }
  size_t count = len / stride;
  data_t * head = (data_t *) ring_buffer_memcpy_into(buffer, RAW(src), count);
  return ScalarInteger(head - buffer->data);
}
void uart_a0_tx_rdy_handler(void) {
	char c;
	if (ring_buffer_get(_uart_a0_tx_ringbuffer_id, &c) == 0) {
		UCA0TXBUF = c;
		EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE,
		EUSCI_A_UART_TRANSMIT_INTERRUPT);
	} else { // ringbuffer empty, nothing to send anymore...
		EUSCI_A_UART_disableInterrupt(EUSCI_A0_BASE,
		EUSCI_A_UART_TRANSMIT_INTERRUPT);
		UCA0IFG |= EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG;
	}
}
Ejemplo n.º 12
0
SEXP R_ring_buffer_tail_read(SEXP extPtr, SEXP r_count) {
  size_t count = INTEGER(r_count)[0];
  ring_buffer * buffer = ring_buffer_get(extPtr, 1);
  SEXP ret = PROTECT(allocVector(RAWSXP, count * buffer->stride));
  if (ring_buffer_tail_read(buffer, RAW(ret), count) == NULL) {
    Rf_error("Buffer underflow");
  }
  UNPROTECT(1);
  // NOTE: In C we return the tail position here but that is not done
  // for the R version.
  return ret;
}
Ejemplo n.º 13
0
static int _get(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj* const *objv) {
  // return the current detimed string
  _t *dp = (_t *)clientData;
  // hmm, how to avoid the buffer here, allocate a byte array?
  unsigned n = ring_buffer_items_available_to_read(&dp->ring);
  // fprintf(stderr, "%s:%d %u bytes available\n", __FILE__, __LINE__, n);
  Tcl_Obj *result = Tcl_NewObj();
  char *buff = Tcl_SetByteArrayLength(result, n);
  ring_buffer_get(&dp->ring, n, buff);
  Tcl_SetObjResult(interp, result);
  return TCL_OK;
}
Ejemplo n.º 14
0
pstring *
ring_buffer_get_pstring(void *data, long off, int len) {
  RingBuffer *rb = data;
	char *val = ring_buffer_get(rb, off, len);
	if(val == NULL) {
		return NULL;
	} else {
		pstring *pstr = malloc(sizeof(pstring));
		pstr->val = val;
		pstr->len = len;
		return pstr;
	}
}
void uart_a0_tx_start_handler(void) {
	if (EUSCI_A_UART_getInterruptStatus(EUSCI_A0_BASE,
	EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG)) {
		char c;
		if (ring_buffer_get(_uart_a0_tx_ringbuffer_id, &c) == 0) {
			UCA0TXBUF = c;
		} else {
			panic(
					"uart_a0_tx_start_handler: invoked but tx_rbf is empty");
		}
	}
	EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE,
	EUSCI_A_UART_TRANSMIT_INTERRUPT);
}
Ejemplo n.º 16
0
SEXP R_ring_buffer_tail_offset(SEXP extPtr, SEXP r_offset) {
  size_t offset = INTEGER(r_offset)[0];
  ring_buffer * buffer = ring_buffer_get(extPtr, 1);
  SEXP ret = PROTECT(allocVector(RAWSXP, buffer->stride));
  data_t *data = (data_t*) ring_buffer_tail_offset(buffer, offset);
  if (data == NULL) {
    Rf_error("Buffer underflow");
  }
  memcpy(RAW(ret), data, buffer->stride);
  UNPROTECT(1);
  // NOTE: In C we return the tail position here but that is not done
  // for the R version.
  return ret;
}
Ejemplo n.º 17
0
Archivo: engine.c Proyecto: fizx/sit
pstring *
engine_get_document(Engine *engine, long doc_id) {
  if (doc_id < 0) {
    return NULL;
  }
  long off = doc_id * sizeof(DocRef);
  DocRef *dr = ring_buffer_get(engine->docs, off, sizeof(DocRef));
  if(dr == NULL) {
    return NULL;
  } else {
		pstring *doc = ring_buffer_get_pstring(engine->stream, dr->off, dr->len);
    free(dr);
		return doc;
  }
}
Ejemplo n.º 18
0
SEXP R_ring_buffer_memcpy_from(SEXP extPtr, SEXP r_count) {
  size_t count = INTEGER(r_count)[0];
  ring_buffer * buffer = ring_buffer_get(extPtr, 1);
  SEXP ret = PROTECT(allocVector(RAWSXP, count * buffer->stride));
  if (ring_buffer_memcpy_from(RAW(ret), buffer, count) == NULL) {
    // TODO: this would be better reporting than just saying "Buffer
    // underflow".  But we need to switch here on stride being 1 or
    // compute the byte size of `count` entries.
    Rf_error("Buffer underflow (requested %d bytes but %d available)",
             count, ring_buffer_used(buffer, 1) / buffer->stride);
  }
  UNPROTECT(1);
  // NOTE: In C we return the tail position here but that is not done
  // for the R version.
  return ret;
}
Ejemplo n.º 19
0
int uart_read (struct file * filp, char *buf, size_t count, loff_t *t)
{
    int rcount=0;

    while ( (rcount < count) && !ring_buffer_isempty(&ring) ) {
        // To do: read recive character form ring buffer
        *(prbuf+rcount) = ring_buffer_get(&ring);
        rcount++;
    }

    if( rcount != 0 ) {
      // copy the data to user space
      if( copy_to_user(buf, prbuf, rcount) != 0)
        return -EFAULT;
    }

    return rcount;
}
Ejemplo n.º 20
0
static void draw_waveform(void) {
    int n = MIN((int) round(current_width * display_zoom), sizeof_ring_buffer);
    int m = current_width;

    while (pthread_mutex_trylock(samples_drawable_lock) != 0) {
        nanosecond_sleep();
    }
    while (pthread_mutex_trylock(ring_buffer->elements_lock) != 0) {
        nanosecond_sleep();
    }

    memset(samples_drawable, 0, sizeof(TYPE) * current_width);
    for(size_t i = 0; i < current_width; i++) {
        int sample_offset = (int) round((i * n + m / 2.0) / m);
        TYPE sample = ring_buffer_get(ring_buffer, sample_offset);
        samples_drawable[i] = sample;
    }
    pthread_mutex_unlock(ring_buffer->elements_lock);
    pthread_mutex_unlock(samples_drawable_lock);

    glClearColor(base3[0], base3[1], base3[2], base3[3]);
    glColor4fv(orange);
    glLineWidth(1.0);
    glBegin(GL_LINE_STRIP);

    while (pthread_mutex_trylock(samples_drawable_lock) != 0) {
        nanosecond_sleep();
    }

    for (size_t j = 0; j < current_width; j++) {
        if (j == 0) {
            continue;
        }
        TYPE sample = samples_drawable[current_width - j];
        double gl_x_coord = j;
        double gl_y_coord = sample * current_height;
        if (fabs(gl_y_coord) < EPSILON) {
            gl_y_coord = 1.0;
        }
        glVertex2f(gl_x_coord, gl_y_coord);
    }
    pthread_mutex_unlock(samples_drawable_lock);
    glEnd();
}
Ejemplo n.º 21
0
int uart_read (struct file * filp, char *buf, size_t count, loff_t *t)
{
    int rcount=0;

    if( ring_buffer_isenmpty(&ring) ) {
      // To do: wait for an event.

    }

    while ( (rcount < count) && !ring_buffer_isenmpty(&ring) ) {
        *(prbuf+rcount)=ring_buffer_get (&ring);
        rcount++;
    }

    if( rcount != 0 ) {
      if( copy_to_user(buf, prbuf, rcount) != 0)
        return -EFAULT;
    }

    return rcount;
}
Ejemplo n.º 22
0
void *
ring_cursor_entry(Cursor *scursor) {
  ring_buffer_cursor *cursor = (ring_buffer_cursor *)scursor;
  return ring_buffer_get(cursor->rb, cursor->pos * cursor->width, cursor->width);
}
Ejemplo n.º 23
0
SEXP R_ring_buffer_used(SEXP extPtr, SEXP bytes) {
  return ScalarInteger(ring_buffer_used(ring_buffer_get(extPtr, 1),
                                          logical_scalar(bytes)));
}
Ejemplo n.º 24
0
/**
 * \brief Function for getting a char from the UART receive buffer
 *
 * \retval Next data byte in receive buffer
 */
static inline uint8_t uart_getchar(void)
{
	return ring_buffer_get(&ring_buffer_in);
}
Ejemplo n.º 25
0
SEXP R_ring_buffer_reset(SEXP extPtr) {
  ring_buffer_reset(ring_buffer_get(extPtr, 1));
  return R_NilValue;
}
Ejemplo n.º 26
0
SEXP R_ring_buffer_empty(SEXP extPtr) {
  return ScalarLogical(ring_buffer_empty(ring_buffer_get(extPtr, 1)));
}
Ejemplo n.º 27
0
SEXP R_ring_buffer_bytes_data(SEXP extPtr) {
  return ScalarInteger(ring_buffer_bytes_data(ring_buffer_get(extPtr, 1)));
}
Ejemplo n.º 28
0
SEXP R_ring_buffer_stride(SEXP extPtr) {
  return ScalarInteger(ring_buffer_get(extPtr, 1)->stride);
}
Ejemplo n.º 29
0
SEXP R_ring_buffer_clone(SEXP extPtr) {
  ring_buffer *prev = ring_buffer_get(extPtr, 1);
  return R_ring_buffer_build(ring_buffer_clone(prev));
}
Ejemplo n.º 30
0
SEXP R_ring_buffer_memset(SEXP extPtr, SEXP c, SEXP len) {
  return ScalarInteger(ring_buffer_memset(ring_buffer_get(extPtr, 1),
                                            RAW(c)[0], INTEGER(len)[0]));
}