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

Committer:
ysuga
Date:
Thu Aug 29 05:29:55 2013 +0000
Revision:
7:6c7af1d50fb3
Parent:
1:f74116b37bc9
update v5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ysuga 0:5f7bc45bc2e8 1 #define RTNO_SUBMODULE_DEFINE
ysuga 0:5f7bc45bc2e8 2
ysuga 0:5f7bc45bc2e8 3 #include "mbed.h"
ysuga 0:5f7bc45bc2e8 4 #include "UART.h"
ysuga 0:5f7bc45bc2e8 5
ysuga 1:f74116b37bc9 6 #define UART_RX_BUFFER_SIZE 64
ysuga 0:5f7bc45bc2e8 7
ysuga 0:5f7bc45bc2e8 8 static Serial *m_pSerial;
ysuga 0:5f7bc45bc2e8 9 unsigned char uart_rx_buffer[UART_RX_BUFFER_SIZE];
ysuga 0:5f7bc45bc2e8 10 int uart_rx_buffer_pointer_head = 0;
ysuga 0:5f7bc45bc2e8 11 int uart_rx_buffer_pointer_tail = 0;
ysuga 0:5f7bc45bc2e8 12
ysuga 0:5f7bc45bc2e8 13
ysuga 0:5f7bc45bc2e8 14 /**
ysuga 0:5f7bc45bc2e8 15 * Push data to ring buffer.
ysuga 0:5f7bc45bc2e8 16 */
ysuga 1:f74116b37bc9 17 int uart_rx_buffer_push(unsigned char* c) {
ysuga 1:f74116b37bc9 18 uart_rx_buffer[uart_rx_buffer_pointer_tail] = *c;
ysuga 0:5f7bc45bc2e8 19 uart_rx_buffer_pointer_tail++;
ysuga 0:5f7bc45bc2e8 20 if(uart_rx_buffer_pointer_tail >= UART_RX_BUFFER_SIZE) {
ysuga 0:5f7bc45bc2e8 21 uart_rx_buffer_pointer_tail = 0;
ysuga 0:5f7bc45bc2e8 22 }
ysuga 0:5f7bc45bc2e8 23 return 0;
ysuga 0:5f7bc45bc2e8 24 }
ysuga 0:5f7bc45bc2e8 25
ysuga 1:f74116b37bc9 26
ysuga 1:f74116b37bc9 27
ysuga 0:5f7bc45bc2e8 28 /**
ysuga 0:5f7bc45bc2e8 29 * Pop data fron ring buffer
ysuga 0:5f7bc45bc2e8 30 */
ysuga 0:5f7bc45bc2e8 31 int uart_rx_buffer_pop(unsigned char *c) {
ysuga 0:5f7bc45bc2e8 32 *c = uart_rx_buffer[uart_rx_buffer_pointer_head];
ysuga 0:5f7bc45bc2e8 33 uart_rx_buffer_pointer_head++;
ysuga 0:5f7bc45bc2e8 34 if(uart_rx_buffer_pointer_head >= UART_RX_BUFFER_SIZE) {
ysuga 0:5f7bc45bc2e8 35 uart_rx_buffer_pointer_head = 0;
ysuga 0:5f7bc45bc2e8 36 }
ysuga 0:5f7bc45bc2e8 37 return 0;
ysuga 0:5f7bc45bc2e8 38 }
ysuga 0:5f7bc45bc2e8 39
ysuga 0:5f7bc45bc2e8 40 int uart_rx_buffer_get_size() {
ysuga 0:5f7bc45bc2e8 41 int size = uart_rx_buffer_pointer_tail - uart_rx_buffer_pointer_head;
ysuga 0:5f7bc45bc2e8 42 if(size < 0) {
ysuga 0:5f7bc45bc2e8 43 size += UART_RX_BUFFER_SIZE;
ysuga 0:5f7bc45bc2e8 44 }
ysuga 0:5f7bc45bc2e8 45 return size;
ysuga 0:5f7bc45bc2e8 46 }
ysuga 0:5f7bc45bc2e8 47
ysuga 0:5f7bc45bc2e8 48 void rx_isr(void) {
ysuga 1:f74116b37bc9 49 int8_t c = m_pSerial->getc();
ysuga 1:f74116b37bc9 50 uart_rx_buffer_push((uint8_t*)&c);
ysuga 0:5f7bc45bc2e8 51 }
ysuga 0:5f7bc45bc2e8 52
ysuga 0:5f7bc45bc2e8 53
ysuga 0:5f7bc45bc2e8 54
ysuga 0:5f7bc45bc2e8 55 void UART_init(unsigned char num, unsigned long baudrate)
ysuga 0:5f7bc45bc2e8 56 {
ysuga 0:5f7bc45bc2e8 57 PinName rx, tx;
ysuga 0:5f7bc45bc2e8 58 switch(num) {
ysuga 0:5f7bc45bc2e8 59 case 0:
ysuga 0:5f7bc45bc2e8 60 rx = USBRX; tx = USBTX;
ysuga 0:5f7bc45bc2e8 61 break;
ysuga 0:5f7bc45bc2e8 62 case 1:
ysuga 0:5f7bc45bc2e8 63 tx = p9, rx = p10;
ysuga 0:5f7bc45bc2e8 64 break;
ysuga 0:5f7bc45bc2e8 65 case 2:
ysuga 0:5f7bc45bc2e8 66 tx = p13, rx = p14;
ysuga 0:5f7bc45bc2e8 67 break;
ysuga 0:5f7bc45bc2e8 68 case 3:
ysuga 0:5f7bc45bc2e8 69 tx = p28, rx = p27;
ysuga 0:5f7bc45bc2e8 70 break;
ysuga 0:5f7bc45bc2e8 71 }
ysuga 0:5f7bc45bc2e8 72
ysuga 0:5f7bc45bc2e8 73 m_pSerial = new Serial(tx, rx);
ysuga 0:5f7bc45bc2e8 74 m_pSerial->baud(baudrate);
ysuga 0:5f7bc45bc2e8 75 m_pSerial->attach(rx_isr, Serial::RxIrq);
ysuga 0:5f7bc45bc2e8 76
ysuga 0:5f7bc45bc2e8 77 SerialDevice_putc = UART_putc;
ysuga 0:5f7bc45bc2e8 78 SerialDevice_getc = UART_getc;
ysuga 0:5f7bc45bc2e8 79 SerialDevice_available = UART_available;
ysuga 0:5f7bc45bc2e8 80 }
ysuga 0:5f7bc45bc2e8 81
ysuga 0:5f7bc45bc2e8 82 void UART_putc(const char c) {
ysuga 1:f74116b37bc9 83 while(!m_pSerial->writeable()) {
ysuga 1:f74116b37bc9 84 wait_us(100);
ysuga 1:f74116b37bc9 85 }
ysuga 0:5f7bc45bc2e8 86 m_pSerial->putc(c);
ysuga 0:5f7bc45bc2e8 87 }
ysuga 0:5f7bc45bc2e8 88
ysuga 0:5f7bc45bc2e8 89 uint8_t UART_available()
ysuga 0:5f7bc45bc2e8 90 {
ysuga 0:5f7bc45bc2e8 91 return uart_rx_buffer_get_size();
ysuga 0:5f7bc45bc2e8 92 }
ysuga 0:5f7bc45bc2e8 93
ysuga 0:5f7bc45bc2e8 94
ysuga 1:f74116b37bc9 95 uint8_t UART_getc()
ysuga 0:5f7bc45bc2e8 96 {
ysuga 0:5f7bc45bc2e8 97 unsigned char c;
ysuga 0:5f7bc45bc2e8 98 uart_rx_buffer_pop(&c);
ysuga 0:5f7bc45bc2e8 99 return c;
ysuga 0:5f7bc45bc2e8 100 }