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

Committer:
ysuga
Date:
2013-08-29
Revision:
7:6c7af1d50fb3
Parent:
1:f74116b37bc9

File content as of revision 7:6c7af1d50fb3:

#include "mbed.h"
#include "SerialDevice.h"

// static value declaration.
void(*SerialDevice_putc)(const char c);
uint8_t(*SerialDevice_available)();
uint8_t(*SerialDevice_getc)();

int32_t INFINITE = -1;

#if 1
static Timer timer;
#endif

int8_t SerialDevice_read(uint8_t* buffer, const uint8_t size, const int32_t &wait_usec)
{
  int32_t us;
  timer.reset();
  timer.start();
  for(unsigned int i = 0;i < size;i++) {
    while (1) {
      if(SerialDevice_available() > 0) {
        break;
      }
      us = timer.read_us();
      if (us >= wait_usec && wait_usec != INFINITE) {
        timer.stop();
        return -TIMEOUT;
      }
    }
    buffer[i] = SerialDevice_getc();
  }
  timer.stop();
  return size;
}