Пример #1
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#");
}
Пример #2
0
static void USBFrameHandler(U16 wFrame __attribute__((unused)))
{
	if (fifo_avail(&txfifo) > 0) {
		// data available, enable NAK interrupt on bulk in
		USBHwNakIntEnable(INACK_BI);
	}
}
Пример #3
0
static void USBFrameHandler(u16 wFrame)
{
	if (fifo_avail(&txfifo) > 0) {
		// data available, enable NAK interrupt on bulk in
		USBHwNakIntEnable(INACK_BI);
	}
}
Пример #4
0
/**
   USB frame interrupt handler
        
   Called every milisecond by the hardware driver.
        
   This function is responsible for sending the first of a chain of packets
   to the host. A chain is always terminated by a short packet, either a
   packet shorter than the maximum packet size or a zero-length packet
   (as required by the windows usbser.sys driver).

*/
 static void USBFrameHandler(U16 wFrame) 
 { 
	 /*!fBulkInBusy &&*/
 	if ( (fifo_avail(&bulk_txfifo) != 0)) { 
 		// send first packet 
 		//SendNextBulkIn(BULK_IN_EP, TRUE); 
 	} 
 } 
Пример #5
0
int fifo_kill(struct simple_fifo *fifo, long int bytes) {
	int ret = 0;

	if (bytes <= fifo_avail(fifo)) {
		fifo->head += bytes;
		ret = bytes;
	}

	return(ret);
}
Пример #6
0
void test5() {
	struct fifo p1;
	int buf1[128];
	int elem;
	int output_buf[128];
	int test_arr[512];
	size_t i;

	srand(time(NULL));
	for(i = 0; i < ARRAY_SIZE(test_arr); i++) {
		test_arr[i] = rand();
	}
	diag("++++test5++++");	
	
	fifo_init(&p1, buf1, sizeof(int), ARRAY_SIZE(buf1) );
	ok1(fifo_amt(&p1) == 0);
	ok1(fifo_avail(&p1) == ARRAY_SIZE(buf1));

	fifo_write(&p1, test_arr, 128);
	ok1(fifo_amt(&p1) == 128);
	ok1(fifo_avail(&p1) == 0);
	fifo_peek(&p1, output_buf, 128);
	ok1(memcmp(output_buf, test_arr, 128*sizeof(int)) == 0);
	
	for(i = 0; i < 256; i++) {
		fifo_pop(&p1, &elem);
		ok1(elem == test_arr[i] && fifo_amt(&p1) == 127 \
				&& fifo_avail(&p1) == 1);
		fifo_push(&p1, test_arr+128+i);
		ok1(fifo_amt(&p1) == 128 && fifo_avail(&p1) == 0);
		memset(output_buf, 0, 128*sizeof(int));
		fifo_peek(&p1, output_buf, 128);
		ok1(memcmp(output_buf, test_arr+i, 128*sizeof(int)));
	}
	
#define TEST5AMT 2 + 3 + 256*3
	diag("----test5----\n#");
}
Пример #7
0
int usb_serial_read(unsigned subdevice, char *buf, unsigned int count)
{
  int avail;
  int i;

  if (count == 0) return 0;

  avail = fifo_avail(&rxfifo);
  if (avail == 0) return 0;

  if (count > avail)
    count = avail;

  for (i = 0; i < count; i++)
    *buf++ = VCOM_getchar();

  return count;
}
Пример #8
0
long int fifo_read(char *out, struct simple_fifo *fifo, long int bytes) {
	long int ret = 0;
	void *pret;

//	printf("fifo_read(): want %li, have %li.\n", bytes, fifo_avail(fifo));fflush(stdout);

	if (bytes <= fifo_avail(fifo)) {
		if (out == NULL) out = malloc(bytes); // Malloc if out is new

		pret = memmove(out, fifo->head, bytes); // Move data
		if (pret != NULL) {
			fifo->head += bytes;
			ret = bytes;
		}
	}

	return(ret);
}
Пример #9
0
void test2() {
	struct fifo p1;
	int buf1[256];
	int elem;
	int output_buf[16];
	int test_arr[19];
	size_t i;
	int input;

	srand(time(NULL));
	for(i = 0; i < ARRAY_SIZE(test_arr); i++) {
		test_arr[i] = rand();
	}
	diag("++++test2++++");	
	
	fifo_init(&p1, buf1, sizeof(int), ARRAY_SIZE(buf1) );
	ok1(fifo_amt(&p1) == 0);
	ok1(fifo_avail(&p1) == ARRAY_SIZE(buf1));

	input = 345;
	fifo_push(&p1, &input);
	ok1(fifo_amt(&p1) == 1);
	ok1(fifo_avail(&p1) == (ARRAY_SIZE(buf1)-1));
	fifo_top(&p1, &elem);
	ok1(elem == 345);
	
	elem = 0;
	fifo_write(&p1, test_arr, 7);
	ok1(fifo_amt(&p1) == 1+7);
	ok1(fifo_avail(&p1) == (ARRAY_SIZE(buf1)-1-7));
	fifo_pop(&p1, &elem);
	ok1(elem == 345);
	ok1(fifo_amt(&p1) == 7);
	ok1(fifo_avail(&p1) == (ARRAY_SIZE(buf1)-7));
	fifo_pop(&p1, &elem);
	ok1(elem == test_arr[0]);
	ok1(fifo_amt(&p1) == 6);
	ok1(fifo_avail(&p1) == (ARRAY_SIZE(buf1)-6));
	fifo_consume(&p1, output_buf, 6);
	ok1(memcmp(test_arr+1, output_buf, 6*sizeof(int)) == 0);
	ok1(fifo_amt(&p1) == 0);
	ok1(fifo_avail(&p1) == (ARRAY_SIZE(buf1)));

#define TEST2AMT 2 + 3 + 11
	diag("----test2----\n#");
}
Пример #10
0
/**
	Local function to handle outgoing bulk data

	@param [in] bEP
	@param [in] bEPStatus
 */
static void BulkIn(U8 bEP, U8 bEPStatus __attribute__((unused)))
{
	int i, iLen;

	if (fifo_avail(&txfifo) == 0) {
		// no more data, disable further NAK interrupts until next USB frame
		USBHwNakIntEnable(0);
		return;
	}

	// get bytes from transmit FIFO into intermediate buffer
	for (i = 0; i < MAX_PACKET_SIZE; i++) {
		if (!fifo_get(&txfifo, &abBulkBuf[i])) {
			break;
		}
	}
	iLen = i;

	// send over USB
	if (iLen > 0) {
		USBHwEPWrite(bEP, abBulkBuf, iLen);
	}
}
Пример #11
0
void test1() {
	struct fifo p1;
	char buf1[256];
	char elem;
	char output_buf[16];

	diag("++++test1++++");	
	
	fifo_init(&p1, buf1, sizeof(char), ARRAY_SIZE(buf1) );
	ok1(fifo_amt(&p1) == 0);
	ok1(fifo_avail(&p1) == ARRAY_SIZE(buf1));

	fifo_push(&p1, "a");
	ok1(fifo_amt(&p1) == 1);
	ok1(fifo_avail(&p1) == (ARRAY_SIZE(buf1)-1));
	fifo_top(&p1, &elem);
	ok1(elem == 'a');
	
	elem = '\0';
	fifo_write(&p1, "zbcdefg", 7);
	ok1(fifo_amt(&p1) == 1+7);
	ok1(fifo_avail(&p1) == (ARRAY_SIZE(buf1)-1-7));
	fifo_pop(&p1, &elem);
	ok1(elem == 'a');
	ok1(fifo_amt(&p1) == 7);
	ok1(fifo_avail(&p1) == (ARRAY_SIZE(buf1)-7));
	fifo_pop(&p1, &elem);
	ok1(elem == 'z');
	ok1(fifo_amt(&p1) == 6);
	ok1(fifo_avail(&p1) == (ARRAY_SIZE(buf1)-6));
	fifo_consume(&p1, output_buf, 6);
	ok1(memcmp("bcdefg", output_buf, 6) == 0);
	ok1(fifo_amt(&p1) == 0);
	ok1(fifo_avail(&p1) == (ARRAY_SIZE(buf1)));
	
	

#define TEST1AMT 2 + 3 + 11
	diag("----test1----\n#");
}
Пример #12
0
/**
	Checks if data available in VCOM buffer

	@returns character read, or EOF if character could not be read
 */
int VCOM_check_available(void)
{
	return (fifo_avail(&rxfifo));
}
Пример #13
0
int fifo_free(fifo_t *fifo)
{
	return (VCOM_FIFO_SIZE - 1 - fifo_avail(fifo));
}
Пример #14
0
int usb_serial_rxready(unsigned subdevice)
{
  return fifo_avail(&rxfifo);
}
Пример #15
0
u32 mempool_free_entities(struct mempool *mp)
{
	return (mp) ? fifo_avail(mp->f) : 0;
}
Пример #16
0
int _fifo_free(fifo_t *fifo)
{
	return (SERIAL_FIFO_SIZE - 1 - fifo_avail(fifo));
}
Пример #17
0
int fifo_free(fifo_type *fifo) {
    return (sizeof(fifo->buf) - 1 - fifo_avail(fifo));
}