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); } } }
s32 ring_read(struct ring *ring, u8 *data, ring_size_t size) { s32 i; for (i = 0; i < size; i++) { if (ring_read_ch(ring, data + i) < 0) return i; } return -i; }
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); }
s32 gpm_pickup_byte(void) { return ring_read_ch(&gpm_output_ring, 0); }