RTno is communicating library and framework which allows you to make your embedded device capable of communicating with RT-middleware world. RT-middleware is a platform software to realize Robotic system. In RTM, robots are developed by constructing robotics technologies\' elements (components) named RT-component. Therefore, the RTno helps you to create your own RT-component with your mbed and arduino. To know how to use your RTno device, visit here: http://ysuga.net/robot_e/rtm_e/rtc_e/1065?lang=en To know about RT-middleware and RT-component, visit http://www.openrtm.org
Dependencies: EthernetInterface mbed-rtos
UART.cpp
- Committer:
- ysuga
- Date:
- 2013-06-24
- Revision:
- 0:5f7bc45bc2e8
- Child:
- 1:f74116b37bc9
File content as of revision 0:5f7bc45bc2e8:
#define RTNO_SUBMODULE_DEFINE #include "mbed.h" #include "UART.h" #define UART_RX_BUFFER_SIZE 128 static Serial *m_pSerial; unsigned char uart_rx_buffer[UART_RX_BUFFER_SIZE]; int uart_rx_buffer_pointer_head = 0; int uart_rx_buffer_pointer_tail = 0; /** * Push data to ring buffer. */ int uart_rx_buffer_push(unsigned char c) { uart_rx_buffer[uart_rx_buffer_pointer_tail] = c; uart_rx_buffer_pointer_tail++; if(uart_rx_buffer_pointer_tail >= UART_RX_BUFFER_SIZE) { uart_rx_buffer_pointer_tail = 0; } return 0; } /** * Pop data fron ring buffer */ int uart_rx_buffer_pop(unsigned char *c) { *c = uart_rx_buffer[uart_rx_buffer_pointer_head]; uart_rx_buffer_pointer_head++; if(uart_rx_buffer_pointer_head >= UART_RX_BUFFER_SIZE) { uart_rx_buffer_pointer_head = 0; } return 0; } int uart_rx_buffer_get_size() { int size = uart_rx_buffer_pointer_tail - uart_rx_buffer_pointer_head; if(size < 0) { size += UART_RX_BUFFER_SIZE; } return size; } void rx_isr(void) { uart_rx_buffer_push(m_pSerial->getc()); } void UART_init(unsigned char num, unsigned long baudrate) { PinName rx, tx; switch(num) { case 0: rx = USBRX; tx = USBTX; break; case 1: tx = p9, rx = p10; break; case 2: tx = p13, rx = p14; break; case 3: tx = p28, rx = p27; break; } m_pSerial = new Serial(tx, rx); m_pSerial->baud(baudrate); m_pSerial->attach(rx_isr, Serial::RxIrq); SerialDevice_putc = UART_putc; SerialDevice_getc = UART_getc; SerialDevice_available = UART_available; } void UART_putc(const char c) { m_pSerial->putc(c); } uint8_t UART_available() { return uart_rx_buffer_get_size(); } char UART_getc() { unsigned char c; uart_rx_buffer_pop(&c); return c; }