Simple functions to ease cross compiling between mbed and Visual Studio

Committer:
WiredHome
Date:
Thu Nov 08 12:53:47 2012 +0000
Revision:
0:7c744796fa67
Rebuild as a library compatible with mbed v43

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 0:7c744796fa67 1 /// A collection of utilities that ease the migration to/from Visual Studio and mbed
WiredHome 0:7c744796fa67 2 /// cloud compiler.
WiredHome 0:7c744796fa67 3
WiredHome 0:7c744796fa67 4 #include "Utilities.h" // mbed <-> Visual Studio
WiredHome 0:7c744796fa67 5
WiredHome 0:7c744796fa67 6
WiredHome 0:7c744796fa67 7 #include "string.h"
WiredHome 0:7c744796fa67 8
WiredHome 0:7c744796fa67 9 #ifndef TRUE
WiredHome 0:7c744796fa67 10 #define TRUE 1
WiredHome 0:7c744796fa67 11 #define FALSE 0
WiredHome 0:7c744796fa67 12 #endif
WiredHome 0:7c744796fa67 13
WiredHome 0:7c744796fa67 14 // Helper functions follow. These functions may exist in some environments and
WiredHome 0:7c744796fa67 15 // not in other combinations of libraries and compilers, so private versions
WiredHome 0:7c744796fa67 16 // are here to ensure consistent behavior.
WiredHome 0:7c744796fa67 17
WiredHome 0:7c744796fa67 18 /// mytolower exists because not all compiler libraries have this function
WiredHome 0:7c744796fa67 19 ///
WiredHome 0:7c744796fa67 20 /// This takes a character and if it is upper-case, it converts it to
WiredHome 0:7c744796fa67 21 /// lower-case and returns it.
WiredHome 0:7c744796fa67 22 ///
WiredHome 0:7c744796fa67 23 /// @param a is the character to convert
WiredHome 0:7c744796fa67 24 /// @returns the lower case equivalent to a
WiredHome 0:7c744796fa67 25 ///
WiredHome 0:7c744796fa67 26 char mytolower(char a) {
WiredHome 0:7c744796fa67 27 if (a >= 'A' && a <= 'Z')
WiredHome 0:7c744796fa67 28 return (a - 'A' + 'a');
WiredHome 0:7c744796fa67 29 else
WiredHome 0:7c744796fa67 30 return a;
WiredHome 0:7c744796fa67 31 }
WiredHome 0:7c744796fa67 32
WiredHome 0:7c744796fa67 33 /// mystrnicmp exists because not all compiler libraries have this function.
WiredHome 0:7c744796fa67 34 ///
WiredHome 0:7c744796fa67 35 /// Some have strnicmp, others _strnicmp, and others have C++ methods, which
WiredHome 0:7c744796fa67 36 /// is outside the scope of this C-portable set of functions.
WiredHome 0:7c744796fa67 37 ///
WiredHome 0:7c744796fa67 38 /// @param l is a pointer to the string on the left
WiredHome 0:7c744796fa67 39 /// @param r is a pointer to the string on the right
WiredHome 0:7c744796fa67 40 /// @param n is the number of characters to compare
WiredHome 0:7c744796fa67 41 /// @returns -1 if l < r
WiredHome 0:7c744796fa67 42 /// @returns 0 if l == r
WiredHome 0:7c744796fa67 43 /// @returns +1 if l > r
WiredHome 0:7c744796fa67 44 ///
WiredHome 0:7c744796fa67 45 int mystrnicmp(const char *l, const char *r, size_t n) {
WiredHome 0:7c744796fa67 46 int result = 0;
WiredHome 0:7c744796fa67 47
WiredHome 0:7c744796fa67 48 if (n != 0) {
WiredHome 0:7c744796fa67 49 do {
WiredHome 0:7c744796fa67 50 result = mytolower(*l++) - mytolower(*r++);
WiredHome 0:7c744796fa67 51 } while ((result == 0) && (*l != '\0') && (--n > 0));
WiredHome 0:7c744796fa67 52 }
WiredHome 0:7c744796fa67 53 if (result < -1)
WiredHome 0:7c744796fa67 54 result = -1;
WiredHome 0:7c744796fa67 55 else if (result > 1)
WiredHome 0:7c744796fa67 56 result = 1;
WiredHome 0:7c744796fa67 57 return result;
WiredHome 0:7c744796fa67 58 }
WiredHome 0:7c744796fa67 59
WiredHome 0:7c744796fa67 60 /// mystrcat exists because not all compiler libraries have this function
WiredHome 0:7c744796fa67 61 ///
WiredHome 0:7c744796fa67 62 /// This function concatinates one string onto another. It is generally
WiredHome 0:7c744796fa67 63 /// considered unsafe, because of the potential for buffer overflow.
WiredHome 0:7c744796fa67 64 /// Some libraries offer a strcat_s as the safe version, and others may have
WiredHome 0:7c744796fa67 65 /// _strcat. Because this is needed only internal to the CommandProcessor,
WiredHome 0:7c744796fa67 66 /// this version was created.
WiredHome 0:7c744796fa67 67 ///
WiredHome 0:7c744796fa67 68 /// @param dst is a pointer to the destination string
WiredHome 0:7c744796fa67 69 /// @param src is a pointer to the source string
WiredHome 0:7c744796fa67 70 /// @returns nothing
WiredHome 0:7c744796fa67 71 ///
WiredHome 0:7c744796fa67 72 void mystrcat(char *dst, char *src) {
WiredHome 0:7c744796fa67 73 while (*dst)
WiredHome 0:7c744796fa67 74 dst++;
WiredHome 0:7c744796fa67 75 do
WiredHome 0:7c744796fa67 76 *dst++ = *src;
WiredHome 0:7c744796fa67 77 while (*src++);
WiredHome 0:7c744796fa67 78 }
WiredHome 0:7c744796fa67 79
WiredHome 0:7c744796fa67 80 /// myisprint exists because not all compiler libraries have this function
WiredHome 0:7c744796fa67 81 ///
WiredHome 0:7c744796fa67 82 /// This function tests a character to see if it is printable (a member
WiredHome 0:7c744796fa67 83 /// of the standard ASCII set).
WiredHome 0:7c744796fa67 84 ///
WiredHome 0:7c744796fa67 85 /// @param c is the character to test
WiredHome 0:7c744796fa67 86 /// @returns TRUE if the character is printable
WiredHome 0:7c744796fa67 87 /// @returns FALSE if the character is not printable
WiredHome 0:7c744796fa67 88 ///
WiredHome 0:7c744796fa67 89 int myisprint(int c) {
WiredHome 0:7c744796fa67 90 if (c >= ' ' && c <= '~')
WiredHome 0:7c744796fa67 91 return TRUE;
WiredHome 0:7c744796fa67 92 else
WiredHome 0:7c744796fa67 93 return FALSE;
WiredHome 0:7c744796fa67 94 }
WiredHome 0:7c744796fa67 95
WiredHome 0:7c744796fa67 96
WiredHome 0:7c744796fa67 97 /// hextoi converts a hex string to an unsigned integer
WiredHome 0:7c744796fa67 98 ///
WiredHome 0:7c744796fa67 99 /// This functions converts text to an unsigned integer, as long as
WiredHome 0:7c744796fa67 100 /// the stream contains hex-ASCII characters
WiredHome 0:7c744796fa67 101 ///
WiredHome 0:7c744796fa67 102 /// @param p is a pointer to the string
WiredHome 0:7c744796fa67 103 /// @returns unsigned long integer value
WiredHome 0:7c744796fa67 104 ///
WiredHome 0:7c744796fa67 105 unsigned long hextoul(char *p) {
WiredHome 0:7c744796fa67 106 unsigned long x = 0;
WiredHome 0:7c744796fa67 107 while (*p) {
WiredHome 0:7c744796fa67 108 x <<= 4;
WiredHome 0:7c744796fa67 109 if (*p >= '0' && *p <= '9')
WiredHome 0:7c744796fa67 110 x += *p - '0';
WiredHome 0:7c744796fa67 111 else if (*p >= 'a' && *p <= 'f')
WiredHome 0:7c744796fa67 112 x += *p - 'a' + 10;
WiredHome 0:7c744796fa67 113 else if (*p >= 'A' && *p <= 'F')
WiredHome 0:7c744796fa67 114 x += *p - 'A' + 10;
WiredHome 0:7c744796fa67 115 p++;
WiredHome 0:7c744796fa67 116 }
WiredHome 0:7c744796fa67 117 return x;
WiredHome 0:7c744796fa67 118 }
WiredHome 0:7c744796fa67 119
WiredHome 0:7c744796fa67 120
WiredHome 0:7c744796fa67 121
WiredHome 0:7c744796fa67 122 #ifdef WIN32
WiredHome 0:7c744796fa67 123 //#######################################################################
WiredHome 0:7c744796fa67 124 //#######################################################################
WiredHome 0:7c744796fa67 125 //#######################################################################
WiredHome 0:7c744796fa67 126 //
WiredHome 0:7c744796fa67 127 // Everything from here forward is intended to "satisfy" the Visual
WiredHome 0:7c744796fa67 128 // Studio 2010 compiler. It isn't intended to necessarily run, since
WiredHome 0:7c744796fa67 129 // we're faking out hardware for the most part.
WiredHome 0:7c744796fa67 130 //
WiredHome 0:7c744796fa67 131
WiredHome 0:7c744796fa67 132 LPC_WDT_BASE * LPC_WDT;
WiredHome 0:7c744796fa67 133
WiredHome 0:7c744796fa67 134 LPC_CAN_BASE * LPC_CAN1;
WiredHome 0:7c744796fa67 135 LPC_CAN_BASE * LPC_CAN2;
WiredHome 0:7c744796fa67 136
WiredHome 0:7c744796fa67 137
WiredHome 0:7c744796fa67 138 void wait(float t) {
WiredHome 0:7c744796fa67 139 (void)t;
WiredHome 0:7c744796fa67 140 }
WiredHome 0:7c744796fa67 141
WiredHome 0:7c744796fa67 142
WiredHome 0:7c744796fa67 143 CANMessage::CANMessage() {
WiredHome 0:7c744796fa67 144 }
WiredHome 0:7c744796fa67 145
WiredHome 0:7c744796fa67 146 CANMessage::CANMessage(uint32_t _id, char *_pdata, int _len, int _type, int _format) {
WiredHome 0:7c744796fa67 147 id = _id;
WiredHome 0:7c744796fa67 148 dir = 0;
WiredHome 0:7c744796fa67 149 len = _len;
WiredHome 0:7c744796fa67 150 format = _format;
WiredHome 0:7c744796fa67 151 type = _type;
WiredHome 0:7c744796fa67 152 for (int i=0; i<len; i++)
WiredHome 0:7c744796fa67 153 data[i] = _pdata[i];
WiredHome 0:7c744796fa67 154 }
WiredHome 0:7c744796fa67 155
WiredHome 0:7c744796fa67 156 CANMessage::~CANMessage() {
WiredHome 0:7c744796fa67 157 }
WiredHome 0:7c744796fa67 158
WiredHome 0:7c744796fa67 159
WiredHome 0:7c744796fa67 160 CAN::CAN(PinName r, PinName t) {
WiredHome 0:7c744796fa67 161 (void)r;
WiredHome 0:7c744796fa67 162 (void)t;
WiredHome 0:7c744796fa67 163 }
WiredHome 0:7c744796fa67 164 CAN::~CAN() {
WiredHome 0:7c744796fa67 165 }
WiredHome 0:7c744796fa67 166 int CAN::write(CANMessage msg) {
WiredHome 0:7c744796fa67 167 (void)msg;
WiredHome 0:7c744796fa67 168 return 1;
WiredHome 0:7c744796fa67 169 }
WiredHome 0:7c744796fa67 170 int CAN::read(CANMessage &msg) {
WiredHome 0:7c744796fa67 171 (void)msg;
WiredHome 0:7c744796fa67 172 return 1;
WiredHome 0:7c744796fa67 173 }
WiredHome 0:7c744796fa67 174 void CAN::attach(void(*fp)(void)) {
WiredHome 0:7c744796fa67 175 (void)fp;
WiredHome 0:7c744796fa67 176 }
WiredHome 0:7c744796fa67 177 void CAN::monitor(bool t) {
WiredHome 0:7c744796fa67 178 (void)t;
WiredHome 0:7c744796fa67 179 }
WiredHome 0:7c744796fa67 180 bool CAN::frequency(uint32_t f) {
WiredHome 0:7c744796fa67 181 (void)f;
WiredHome 0:7c744796fa67 182 return true;
WiredHome 0:7c744796fa67 183 }
WiredHome 0:7c744796fa67 184 uint32_t CAN::tderror() {
WiredHome 0:7c744796fa67 185 return 0;
WiredHome 0:7c744796fa67 186 }
WiredHome 0:7c744796fa67 187 uint32_t CAN::rderror() {
WiredHome 0:7c744796fa67 188 return 0;
WiredHome 0:7c744796fa67 189 }
WiredHome 0:7c744796fa67 190 void CAN::reset() {
WiredHome 0:7c744796fa67 191 }
WiredHome 0:7c744796fa67 192
WiredHome 0:7c744796fa67 193 PwmOut::PwmOut(PinName p) {
WiredHome 0:7c744796fa67 194 (void)p;
WiredHome 0:7c744796fa67 195 }
WiredHome 0:7c744796fa67 196 PwmOut::~PwmOut() {
WiredHome 0:7c744796fa67 197 }
WiredHome 0:7c744796fa67 198 double &PwmOut::operator=(double _p) {
WiredHome 0:7c744796fa67 199 return p = _p;
WiredHome 0:7c744796fa67 200 }
WiredHome 0:7c744796fa67 201
WiredHome 0:7c744796fa67 202 Timeout::Timeout() {
WiredHome 0:7c744796fa67 203 }
WiredHome 0:7c744796fa67 204 Timeout::~Timeout() {
WiredHome 0:7c744796fa67 205 }
WiredHome 0:7c744796fa67 206
WiredHome 0:7c744796fa67 207 DigitalInOut::DigitalInOut(PinName p) {
WiredHome 0:7c744796fa67 208 (void)p;
WiredHome 0:7c744796fa67 209 }
WiredHome 0:7c744796fa67 210 DigitalInOut::~DigitalInOut() {
WiredHome 0:7c744796fa67 211 }
WiredHome 0:7c744796fa67 212 void DigitalInOut::output() {
WiredHome 0:7c744796fa67 213 }
WiredHome 0:7c744796fa67 214 void DigitalInOut::input() {
WiredHome 0:7c744796fa67 215 }
WiredHome 0:7c744796fa67 216 void DigitalInOut::write(bool v) {
WiredHome 0:7c744796fa67 217 (void)v;
WiredHome 0:7c744796fa67 218 }
WiredHome 0:7c744796fa67 219 void DigitalInOut::mode(int m) {
WiredHome 0:7c744796fa67 220 (void)m;
WiredHome 0:7c744796fa67 221 }
WiredHome 0:7c744796fa67 222
WiredHome 0:7c744796fa67 223 Serial::Serial(PinName t, PinName r) {
WiredHome 0:7c744796fa67 224 (void)t;
WiredHome 0:7c744796fa67 225 (void)r;
WiredHome 0:7c744796fa67 226 }
WiredHome 0:7c744796fa67 227 Serial::~Serial() {
WiredHome 0:7c744796fa67 228 }
WiredHome 0:7c744796fa67 229 void Serial::baud(uint32_t freq) {
WiredHome 0:7c744796fa67 230 (void)freq;
WiredHome 0:7c744796fa67 231 }
WiredHome 0:7c744796fa67 232 int Serial::getc() {
WiredHome 0:7c744796fa67 233 return _getch();
WiredHome 0:7c744796fa67 234 }
WiredHome 0:7c744796fa67 235 int Serial::putc(int c) {
WiredHome 0:7c744796fa67 236 return _putch(c);
WiredHome 0:7c744796fa67 237 }
WiredHome 0:7c744796fa67 238 int Serial::readable() {
WiredHome 0:7c744796fa67 239 return _kbhit();
WiredHome 0:7c744796fa67 240 }
WiredHome 0:7c744796fa67 241 int Serial::printf(char * fmt, ...) {
WiredHome 0:7c744796fa67 242 return ::printf(fmt);
WiredHome 0:7c744796fa67 243 }
WiredHome 0:7c744796fa67 244
WiredHome 0:7c744796fa67 245 Timer::Timer() {
WiredHome 0:7c744796fa67 246 }
WiredHome 0:7c744796fa67 247 Timer::~Timer() {
WiredHome 0:7c744796fa67 248 }
WiredHome 0:7c744796fa67 249 void Timer::start() {
WiredHome 0:7c744796fa67 250 }
WiredHome 0:7c744796fa67 251 uint32_t Timer::read_ms() {
WiredHome 0:7c744796fa67 252 return 0;
WiredHome 0:7c744796fa67 253 }
WiredHome 0:7c744796fa67 254 uint32_t Timer::read_us() {
WiredHome 0:7c744796fa67 255 return 0;
WiredHome 0:7c744796fa67 256 }
WiredHome 0:7c744796fa67 257
WiredHome 0:7c744796fa67 258
WiredHome 0:7c744796fa67 259 extern "C" {
WiredHome 0:7c744796fa67 260 void mbed_reset() {
WiredHome 0:7c744796fa67 261 }
WiredHome 0:7c744796fa67 262 }
WiredHome 0:7c744796fa67 263
WiredHome 0:7c744796fa67 264 #endif // WIN32