Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface mbed-rtos
SerialDevice.cpp
00001 #include "mbed.h" 00002 #include "SerialDevice.h" 00003 00004 // static value declaration. 00005 void(*SerialDevice_putc)(const char c); 00006 uint8_t(*SerialDevice_available)(); 00007 uint8_t(*SerialDevice_getc)(); 00008 00009 int32_t INFINITE = -1; 00010 00011 #if 1 00012 static Timer timer; 00013 #endif 00014 00015 int8_t SerialDevice_read(uint8_t* buffer, const uint8_t size, const int32_t &wait_usec) 00016 { 00017 int32_t us; 00018 timer.reset(); 00019 timer.start(); 00020 for(unsigned int i = 0;i < size;i++) { 00021 while (1) { 00022 if(SerialDevice_available() > 0) { 00023 break; 00024 } 00025 us = timer.read_us(); 00026 if (us >= wait_usec && wait_usec != INFINITE) { 00027 timer.stop(); 00028 return -TIMEOUT; 00029 } 00030 } 00031 buffer[i] = SerialDevice_getc(); 00032 } 00033 timer.stop(); 00034 return size; 00035 } 00036 00037
Generated on Fri Jul 22 2022 21:22:50 by
1.7.2