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
SerialDevice.cpp@7:6c7af1d50fb3, 2013-08-29 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
ysuga | 1:f74116b37bc9 | 1 | #include "mbed.h" |
ysuga | 1:f74116b37bc9 | 2 | #include "SerialDevice.h" |
ysuga | 1:f74116b37bc9 | 3 | |
ysuga | 1:f74116b37bc9 | 4 | // static value declaration. |
ysuga | 1:f74116b37bc9 | 5 | void(*SerialDevice_putc)(const char c); |
ysuga | 1:f74116b37bc9 | 6 | uint8_t(*SerialDevice_available)(); |
ysuga | 1:f74116b37bc9 | 7 | uint8_t(*SerialDevice_getc)(); |
ysuga | 1:f74116b37bc9 | 8 | |
ysuga | 1:f74116b37bc9 | 9 | int32_t INFINITE = -1; |
ysuga | 1:f74116b37bc9 | 10 | |
ysuga | 1:f74116b37bc9 | 11 | #if 1 |
ysuga | 1:f74116b37bc9 | 12 | static Timer timer; |
ysuga | 1:f74116b37bc9 | 13 | #endif |
ysuga | 1:f74116b37bc9 | 14 | |
ysuga | 1:f74116b37bc9 | 15 | int8_t SerialDevice_read(uint8_t* buffer, const uint8_t size, const int32_t &wait_usec) |
ysuga | 1:f74116b37bc9 | 16 | { |
ysuga | 1:f74116b37bc9 | 17 | int32_t us; |
ysuga | 1:f74116b37bc9 | 18 | timer.reset(); |
ysuga | 1:f74116b37bc9 | 19 | timer.start(); |
ysuga | 1:f74116b37bc9 | 20 | for(unsigned int i = 0;i < size;i++) { |
ysuga | 1:f74116b37bc9 | 21 | while (1) { |
ysuga | 1:f74116b37bc9 | 22 | if(SerialDevice_available() > 0) { |
ysuga | 1:f74116b37bc9 | 23 | break; |
ysuga | 1:f74116b37bc9 | 24 | } |
ysuga | 1:f74116b37bc9 | 25 | us = timer.read_us(); |
ysuga | 1:f74116b37bc9 | 26 | if (us >= wait_usec && wait_usec != INFINITE) { |
ysuga | 1:f74116b37bc9 | 27 | timer.stop(); |
ysuga | 1:f74116b37bc9 | 28 | return -TIMEOUT; |
ysuga | 1:f74116b37bc9 | 29 | } |
ysuga | 1:f74116b37bc9 | 30 | } |
ysuga | 1:f74116b37bc9 | 31 | buffer[i] = SerialDevice_getc(); |
ysuga | 1:f74116b37bc9 | 32 | } |
ysuga | 1:f74116b37bc9 | 33 | timer.stop(); |
ysuga | 1:f74116b37bc9 | 34 | return size; |
ysuga | 1:f74116b37bc9 | 35 | } |
ysuga | 1:f74116b37bc9 | 36 | |
ysuga | 1:f74116b37bc9 | 37 |