static void *printer(void *arg) { (void)arg; msg_t msg; msg_t msg_queue[8]; msg_init_queue(msg_queue, 8); while (1) { msg_receive(&msg); int dev = (int)msg.content.value; char c; printf("UART_DEV(%i) RX: ", dev); do { c = (int)ringbuffer_get_one(&(ctx[dev].rx_buf)); if (c == 0) { puts(""); } else if (c >= ' ' && c <= '~') { printf("%c", c); } else { printf("0x%02x", (unsigned char)c); } } while (c != 0); } /* this should never be reached */ return NULL; }
void UART_2_ISR(void) { /* Check for RX data valid interrupt */ if(UART_2_DEV->STATUS & LEUART_STATUS_RXDATAV) { /* Copy data into RX Buffer */ uint8_t rxData = LEUART_Rx(UART_2_DEV); irq_read(UART_2, rxData); } /* Check TX buffer level status */ if(UART_2_DEV->IF & LEUART_IF_TXBL & UART_2_DEV->IEN) { #if UART_2_ENABLE_BUF int data = ringbuffer_get_one(&rb_uart2); if(-1 != data) { /* Avoid deadlock if modifying the same register twice when freeze mode is */ /* activated. */ if(!(UART_2_DEV->FREEZE & LEUART_FREEZE_REGFREEZE)) { /* Wait for any pending previous write operation to have been completed */ /* in low frequency domain */ while(UART_2_DEV->SYNCBUSY & LEUART_SYNCBUSY_TXDATA) ;; } /* Write data to TX register */ UART_2_DEV->TXDATA = (uint32_t)data; } else { LEUART_IntDisable(UART_2_DEV, LEUART_IF_TXBL); } #endif } if(sched_context_switch_request) { thread_yield(); } }
void usbdev_acm_evt_out(usbdev_t *dev) { usbdev_ops_t *driver = dev->driver; size_t l = driver->read_ep(ENDPOINT_ADDR_OUT(USBDEV_ACM_EP_BULKOUT), rec_buffer, USBDEV_ACM_EP_PACKET_SIZE); ringbuffer_add(&cdcacm_rx_rb, (char*)rec_buffer, l); if (ucb_config.rx_cb != NULL) { int retval = ringbuffer_get_one(&cdcacm_rx_rb); while (retval != -1) { ucb_config.rx_cb(ucb_config.arg, (char)retval); retval = ringbuffer_get_one(&cdcacm_rx_rb); } } }
int _slip_tx_cb(void *arg) { if (_SLIP_DEV(arg)->out_buf->avail > 0) { char c = (char)ringbuffer_get_one(_SLIP_DEV(arg)->out_buf); uart_write((uart_t)(_SLIP_DEV(arg)->uart), c); return 1; } return 0; }
int tx(void *ptr) { char data; if (tx_buf.avail > 0) { data = ringbuffer_get_one(&tx_buf); uart_write(DEV, data); return 1; } return 0; }
void UART_1_TX_ISR(void) { /* Check TX buffer level status */ if(UART_1_DEV->STATUS & UART_STATUS_TXBL) { int data = ringbuffer_get_one(&rb_uart1); if(-1 != data) { /* Write data to buffer */ UART_1_DEV->TXDATA = (uint32_t)data; } else { USART_IntDisable(UART_1_DEV, USART_IF_TXBL); } } if(sched_context_switch_request) { thread_yield(); } }
static void assert_get_one(int assumed_result) { int actual_result = ringbuffer_get_one(&rb); TEST_ASSERT_EQUAL_INT(assumed_result, actual_result); }