END_TEST

START_TEST(test_ring_write_read_max)
{
	s32 ret;
	u8 i, ch;

	for(i=0; i<9; i++){
		ret = (u8)ring_write_ch(&test_ring, i);

		fail_unless(i == ret);
	}

	fail_unless(-1 == ring_write_ch(&test_ring, 10));

	for(i=0; i<9; i++){
		ret = (u8)ring_read_ch(&test_ring, &ch);

		fail_unless(i == ret);
		fail_unless(i == ch);
	}

	ch = 10;
	fail_unless(-1 == ring_read_ch(&test_ring, &ch));
	fail_unless(10 == ch);
}
void usart2_isr(void)
{
	/* Check if we were called because of RXNE. */
	if (((USART_CR1(USART2) & USART_CR1_RXNEIE) != 0) &&
	    ((USART_SR(USART2) & USART_SR_RXNE) != 0)) {

		/* Indicate that we got data. */
		gpio_toggle(GPIOA, GPIO8);

		/* Retrieve the data from the peripheral. */
		ring_write_ch(&output_ring, usart_recv(USART2));

		/* Enable transmit interrupt so it sends back the data. */
		USART_CR1(USART2) |= USART_CR1_TXEIE;
	}

	/* Check if we were called because of TXE. */
	if (((USART_CR1(USART2) & USART_CR1_TXEIE) != 0) &&
	    ((USART_SR(USART2) & USART_SR_TXE) != 0)) {

		int32_t data;

		data = ring_read_ch(&output_ring, NULL);

		if (data == -1) {
			/* Disable the TXE interrupt, it's no longer needed. */
			USART_CR1(USART2) &= ~USART_CR1_TXEIE;
		} else {
			/* Put data into the transmit register. */
			usart_send(USART2, data);
		}
	}
}
Exemple #3
0
int gpm_send_get_version(void)
{
	if (0 <= ring_write_ch(&gpm_output_ring, GP_MODE_STRING)) {
		if (gpm_hooks.trigger_output)
			gpm_hooks.trigger_output(gpm_hooks.trigger_output_data);
		return 0;
	}

	return 1;
}
static int32_t ring_write(struct ring *ring, uint8_t *data, ring_size_t size)
{
	int32_t i;

	for (i = 0; i < size; i++) {
		if (ring_write_ch(ring, data[i]) < 0)
			return -i;
	}

	return i;
}
s32 ring_write(struct ring *ring, u8 *data, ring_size_t size)
{
	s32 i;

	for (i = 0; i < size; i++) {
		if (ring_write_ch(ring, data[i]) < 0)
			return -i;
	}

	return i;
}
Exemple #6
0
s32 ring_safe_write_ch(struct ring *ring, u8 ch)
{
	int ret;
	int retry_count = 100;

	do {
		ret = ring_write_ch(ring, ch);
	} while ((ret < 0) && ((retry_count--) > 0));

	return ret;
}
Exemple #7
0
int gpm_send_get_cont(u8 addr)
{
    u8 out = addr | GP_MODE_READ | GP_MODE_CONT;

    if(addr > 31)
	    return 1;

    if(0 <= ring_write_ch(&gpm_output_ring, out)){
	    if(gpm_hooks.trigger_output) gpm_hooks.trigger_output(gpm_hooks.trigger_output_data);
	    return 0;
    }

    return 1;
}
END_TEST

START_TEST(test_ring_write_read_one)
{
	s32 ret;
	u8 ch;

	ret = ring_write_ch(&test_ring, (u8)'A');

	fail_unless('A' == ret);

	ret = ring_read_ch(&test_ring, &ch);

	fail_unless('A' == ret);
	fail_unless('A' == ch);
}
Exemple #9
0
static int
vrprintf(struct ring *ring, const char *fmt, va_list va)
{
    uint32_t mark = ring_mark(ring);
    char bf[24];
    char ch;

    while ((ch = *(fmt++))) {
        if (ch == '\n') {
            ring_write_ch(ring, '\n');
            ring_write_ch(ring, '\r');
        } else if (ch != '%') {
            ring_write_ch(ring, ch);
        } else {
            char zero_pad = 0;
            char *ptr;
            uint32_t len;

            ch = *(fmt++);

            /* Zero padding requested */
            if (ch == '0') {
                ch = *(fmt++);
                if (ch == '\0')
                    goto end;
                if (ch >= '0' && ch <= '9')
                    zero_pad = ch - '0';
                ch = *(fmt++);
            }

            switch (ch) {
            case 0:
                goto end;

            case 'u':
            case 'd':
                len = itoa(va_arg(va, uint32_t), 10, 0, (ch == 'u'), bf, zero_pad);
                ring_write(ring, (uint8_t *)bf, len);
                break;

            case 'x':
            case 'X':
                len = itoa(va_arg(va, uint32_t), 16, (ch == 'X'), 1, bf, zero_pad);
                ring_write(ring, (uint8_t *)bf, len);
                break;

            case 'c' :
                ring_write_ch(ring, (char)(va_arg(va, int)));
                break;

            case 's' :
                ptr = va_arg(va, char*);
                ring_write(ring, (uint8_t *)ptr, strlen(ptr));
                break;

            default:
                ring_write_ch(ring, ch);
                break;
            }
        }
    }
end:
    return ring_marklen(ring, mark);
}