Simple library of a few functions.
Utilities.h@0:b9079d9bc64d, 2019-10-11 (annotated)
- Committer:
- WiredHome
- Date:
- Fri Oct 11 20:53:46 2019 +0000
- Revision:
- 0:b9079d9bc64d
Simplify as a library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WiredHome | 0:b9079d9bc64d | 1 | /// Utilities.h is an adapter to support easier transition from |
WiredHome | 0:b9079d9bc64d | 2 | /// the mbed cloud compiler to Visual Studio |
WiredHome | 0:b9079d9bc64d | 3 | /// |
WiredHome | 0:b9079d9bc64d | 4 | #ifndef UTILITIES_H |
WiredHome | 0:b9079d9bc64d | 5 | #define UTILITIES_H |
WiredHome | 0:b9079d9bc64d | 6 | #include <string.h> |
WiredHome | 0:b9079d9bc64d | 7 | |
WiredHome | 0:b9079d9bc64d | 8 | // Helper functions follow. These functions may exist in some environments and |
WiredHome | 0:b9079d9bc64d | 9 | // not in other combinations of libraries and compilers, so private versions |
WiredHome | 0:b9079d9bc64d | 10 | // are here to ensure consistent behavior. |
WiredHome | 0:b9079d9bc64d | 11 | |
WiredHome | 0:b9079d9bc64d | 12 | /// Access to intentionally reset the mbed |
WiredHome | 0:b9079d9bc64d | 13 | /// |
WiredHome | 0:b9079d9bc64d | 14 | extern "C" void mbed_reset(); |
WiredHome | 0:b9079d9bc64d | 15 | |
WiredHome | 0:b9079d9bc64d | 16 | #if 0 |
WiredHome | 0:b9079d9bc64d | 17 | /// mytolower exists because not all compiler libraries have this function |
WiredHome | 0:b9079d9bc64d | 18 | /// |
WiredHome | 0:b9079d9bc64d | 19 | /// This takes a character and if it is upper-case, it converts it to |
WiredHome | 0:b9079d9bc64d | 20 | /// lower-case and returns it. |
WiredHome | 0:b9079d9bc64d | 21 | /// |
WiredHome | 0:b9079d9bc64d | 22 | /// @param a is the character to convert |
WiredHome | 0:b9079d9bc64d | 23 | /// @returns the lower case equivalent to a |
WiredHome | 0:b9079d9bc64d | 24 | /// |
WiredHome | 0:b9079d9bc64d | 25 | char mytolower(char a); |
WiredHome | 0:b9079d9bc64d | 26 | |
WiredHome | 0:b9079d9bc64d | 27 | |
WiredHome | 0:b9079d9bc64d | 28 | /// mystrnicmp exists because not all compiler libraries have this function. |
WiredHome | 0:b9079d9bc64d | 29 | /// |
WiredHome | 0:b9079d9bc64d | 30 | /// Some have strnicmp, others _strnicmp, and others have C++ methods, which |
WiredHome | 0:b9079d9bc64d | 31 | /// is outside the scope of this C-portable set of functions. |
WiredHome | 0:b9079d9bc64d | 32 | /// |
WiredHome | 0:b9079d9bc64d | 33 | /// @param l is a pointer to the string on the left |
WiredHome | 0:b9079d9bc64d | 34 | /// @param r is a pointer to the string on the right |
WiredHome | 0:b9079d9bc64d | 35 | /// @param n is the number of characters to compare |
WiredHome | 0:b9079d9bc64d | 36 | /// @returns -1 if l < r |
WiredHome | 0:b9079d9bc64d | 37 | /// @returns 0 if l == r |
WiredHome | 0:b9079d9bc64d | 38 | /// @returns +1 if l > r |
WiredHome | 0:b9079d9bc64d | 39 | /// |
WiredHome | 0:b9079d9bc64d | 40 | int mystrnicmp(const char *l, const char *r, size_t n); |
WiredHome | 0:b9079d9bc64d | 41 | #endif |
WiredHome | 0:b9079d9bc64d | 42 | |
WiredHome | 0:b9079d9bc64d | 43 | /// mystrcat exists because not all compiler libraries have this function |
WiredHome | 0:b9079d9bc64d | 44 | /// |
WiredHome | 0:b9079d9bc64d | 45 | /// This function concatinates one string onto another. It is generally |
WiredHome | 0:b9079d9bc64d | 46 | /// considered unsafe, because of the potential for buffer overflow. |
WiredHome | 0:b9079d9bc64d | 47 | /// Some libraries offer a strcat_s as the safe version, and others may have |
WiredHome | 0:b9079d9bc64d | 48 | /// _strcat. Because this is needed only internal to the CommandProcessor, |
WiredHome | 0:b9079d9bc64d | 49 | /// this version was created. |
WiredHome | 0:b9079d9bc64d | 50 | /// |
WiredHome | 0:b9079d9bc64d | 51 | /// @param dst is a pointer to the destination string |
WiredHome | 0:b9079d9bc64d | 52 | /// @param src is a pointer to the source string |
WiredHome | 0:b9079d9bc64d | 53 | /// @returns nothing |
WiredHome | 0:b9079d9bc64d | 54 | /// |
WiredHome | 0:b9079d9bc64d | 55 | void mystrcat(char *dst, char *src); |
WiredHome | 0:b9079d9bc64d | 56 | |
WiredHome | 0:b9079d9bc64d | 57 | /// myisprint exists because not all compiler libraries have this function |
WiredHome | 0:b9079d9bc64d | 58 | /// |
WiredHome | 0:b9079d9bc64d | 59 | /// This function tests a character to see if it is printable (a member |
WiredHome | 0:b9079d9bc64d | 60 | /// of the standard ASCII set). |
WiredHome | 0:b9079d9bc64d | 61 | /// |
WiredHome | 0:b9079d9bc64d | 62 | /// @param c is the character to test |
WiredHome | 0:b9079d9bc64d | 63 | /// @returns TRUE if the character is printable |
WiredHome | 0:b9079d9bc64d | 64 | /// @returns FALSE if the character is not printable |
WiredHome | 0:b9079d9bc64d | 65 | /// |
WiredHome | 0:b9079d9bc64d | 66 | int myisprint(int c); |
WiredHome | 0:b9079d9bc64d | 67 | |
WiredHome | 0:b9079d9bc64d | 68 | |
WiredHome | 0:b9079d9bc64d | 69 | /// hextoi converts a hex string to an unsigned integer |
WiredHome | 0:b9079d9bc64d | 70 | /// |
WiredHome | 0:b9079d9bc64d | 71 | /// This functions converts text to an unsigned integer, as long as |
WiredHome | 0:b9079d9bc64d | 72 | /// the stream contains hex-ASCII characters |
WiredHome | 0:b9079d9bc64d | 73 | /// |
WiredHome | 0:b9079d9bc64d | 74 | /// @param p is a pointer to the string |
WiredHome | 0:b9079d9bc64d | 75 | /// @returns unsigned long integer value |
WiredHome | 0:b9079d9bc64d | 76 | /// |
WiredHome | 0:b9079d9bc64d | 77 | unsigned long hextoul(char *p); |
WiredHome | 0:b9079d9bc64d | 78 | |
WiredHome | 0:b9079d9bc64d | 79 | |
WiredHome | 0:b9079d9bc64d | 80 | #ifdef WIN32 |
WiredHome | 0:b9079d9bc64d | 81 | //####################################################################### |
WiredHome | 0:b9079d9bc64d | 82 | //####################################################################### |
WiredHome | 0:b9079d9bc64d | 83 | //####################################################################### |
WiredHome | 0:b9079d9bc64d | 84 | // |
WiredHome | 0:b9079d9bc64d | 85 | // Everything from here forward is intended to "satisfy" the Visual |
WiredHome | 0:b9079d9bc64d | 86 | // Studio 2010 compiler. It isn't intended to necessarily run, since |
WiredHome | 0:b9079d9bc64d | 87 | // we're faking out hardware for the most part. |
WiredHome | 0:b9079d9bc64d | 88 | // |
WiredHome | 0:b9079d9bc64d | 89 | |
WiredHome | 0:b9079d9bc64d | 90 | #include <memory.h> |
WiredHome | 0:b9079d9bc64d | 91 | #include <stdio.h> |
WiredHome | 0:b9079d9bc64d | 92 | #include <stdlib.h> |
WiredHome | 0:b9079d9bc64d | 93 | #include <string.h> |
WiredHome | 0:b9079d9bc64d | 94 | #include <math.h> |
WiredHome | 0:b9079d9bc64d | 95 | #include <conio.h> |
WiredHome | 0:b9079d9bc64d | 96 | |
WiredHome | 0:b9079d9bc64d | 97 | #define __disable_irq() |
WiredHome | 0:b9079d9bc64d | 98 | #define __enable_irq() |
WiredHome | 0:b9079d9bc64d | 99 | |
WiredHome | 0:b9079d9bc64d | 100 | enum { |
WiredHome | 0:b9079d9bc64d | 101 | CANData, |
WiredHome | 0:b9079d9bc64d | 102 | CANRemote |
WiredHome | 0:b9079d9bc64d | 103 | }; |
WiredHome | 0:b9079d9bc64d | 104 | |
WiredHome | 0:b9079d9bc64d | 105 | enum { |
WiredHome | 0:b9079d9bc64d | 106 | CANStandard, |
WiredHome | 0:b9079d9bc64d | 107 | CANExtended |
WiredHome | 0:b9079d9bc64d | 108 | }; |
WiredHome | 0:b9079d9bc64d | 109 | |
WiredHome | 0:b9079d9bc64d | 110 | enum { |
WiredHome | 0:b9079d9bc64d | 111 | PullNone |
WiredHome | 0:b9079d9bc64d | 112 | }; |
WiredHome | 0:b9079d9bc64d | 113 | |
WiredHome | 0:b9079d9bc64d | 114 | typedef unsigned int uint32_t; |
WiredHome | 0:b9079d9bc64d | 115 | //typedef unsigned int PinName; |
WiredHome | 0:b9079d9bc64d | 116 | typedef enum { |
WiredHome | 0:b9079d9bc64d | 117 | NC, |
WiredHome | 0:b9079d9bc64d | 118 | USBTX, |
WiredHome | 0:b9079d9bc64d | 119 | USBRX, |
WiredHome | 0:b9079d9bc64d | 120 | LED1, |
WiredHome | 0:b9079d9bc64d | 121 | LED2, |
WiredHome | 0:b9079d9bc64d | 122 | LED3, |
WiredHome | 0:b9079d9bc64d | 123 | LED4, |
WiredHome | 0:b9079d9bc64d | 124 | p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, |
WiredHome | 0:b9079d9bc64d | 125 | p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, |
WiredHome | 0:b9079d9bc64d | 126 | p21, p22, p23, p24, p25, p26, p27, p28, p29, p30 |
WiredHome | 0:b9079d9bc64d | 127 | } PinName; |
WiredHome | 0:b9079d9bc64d | 128 | |
WiredHome | 0:b9079d9bc64d | 129 | |
WiredHome | 0:b9079d9bc64d | 130 | #define SystemCoreClock 48000000 |
WiredHome | 0:b9079d9bc64d | 131 | |
WiredHome | 0:b9079d9bc64d | 132 | typedef struct { |
WiredHome | 0:b9079d9bc64d | 133 | uint32_t WDMOD; |
WiredHome | 0:b9079d9bc64d | 134 | uint32_t WDCLKSEL; |
WiredHome | 0:b9079d9bc64d | 135 | uint32_t WDTC; |
WiredHome | 0:b9079d9bc64d | 136 | uint32_t WDFEED; |
WiredHome | 0:b9079d9bc64d | 137 | } LPC_WDT_BASE; |
WiredHome | 0:b9079d9bc64d | 138 | |
WiredHome | 0:b9079d9bc64d | 139 | extern LPC_WDT_BASE * LPC_WDT; |
WiredHome | 0:b9079d9bc64d | 140 | |
WiredHome | 0:b9079d9bc64d | 141 | typedef struct { |
WiredHome | 0:b9079d9bc64d | 142 | uint32_t MOD; |
WiredHome | 0:b9079d9bc64d | 143 | uint32_t GSR; |
WiredHome | 0:b9079d9bc64d | 144 | uint32_t ICR; |
WiredHome | 0:b9079d9bc64d | 145 | uint32_t IER; |
WiredHome | 0:b9079d9bc64d | 146 | uint32_t BTR; |
WiredHome | 0:b9079d9bc64d | 147 | uint32_t EWL; |
WiredHome | 0:b9079d9bc64d | 148 | uint32_t SR; |
WiredHome | 0:b9079d9bc64d | 149 | uint32_t RFS; |
WiredHome | 0:b9079d9bc64d | 150 | uint32_t RID; |
WiredHome | 0:b9079d9bc64d | 151 | uint32_t RDA; |
WiredHome | 0:b9079d9bc64d | 152 | uint32_t RDB; |
WiredHome | 0:b9079d9bc64d | 153 | uint32_t TFI1; |
WiredHome | 0:b9079d9bc64d | 154 | uint32_t TID1; |
WiredHome | 0:b9079d9bc64d | 155 | uint32_t TDA1; |
WiredHome | 0:b9079d9bc64d | 156 | uint32_t TDB1; |
WiredHome | 0:b9079d9bc64d | 157 | uint32_t TFI2; |
WiredHome | 0:b9079d9bc64d | 158 | uint32_t TID2; |
WiredHome | 0:b9079d9bc64d | 159 | uint32_t TDA2; |
WiredHome | 0:b9079d9bc64d | 160 | uint32_t TDB2; |
WiredHome | 0:b9079d9bc64d | 161 | uint32_t TFI3; |
WiredHome | 0:b9079d9bc64d | 162 | uint32_t TID3; |
WiredHome | 0:b9079d9bc64d | 163 | uint32_t TDA3; |
WiredHome | 0:b9079d9bc64d | 164 | uint32_t TDB3; |
WiredHome | 0:b9079d9bc64d | 165 | } LPC_CAN_BASE; |
WiredHome | 0:b9079d9bc64d | 166 | |
WiredHome | 0:b9079d9bc64d | 167 | extern LPC_CAN_BASE * LPC_CAN1; |
WiredHome | 0:b9079d9bc64d | 168 | extern LPC_CAN_BASE * LPC_CAN2; |
WiredHome | 0:b9079d9bc64d | 169 | |
WiredHome | 0:b9079d9bc64d | 170 | |
WiredHome | 0:b9079d9bc64d | 171 | class CANMessage { |
WiredHome | 0:b9079d9bc64d | 172 | public: |
WiredHome | 0:b9079d9bc64d | 173 | CANMessage(); |
WiredHome | 0:b9079d9bc64d | 174 | CANMessage(uint32_t _id, char * _pdata, int _len, int _type, int _format); |
WiredHome | 0:b9079d9bc64d | 175 | ~CANMessage(); |
WiredHome | 0:b9079d9bc64d | 176 | uint32_t id; |
WiredHome | 0:b9079d9bc64d | 177 | int dir; |
WiredHome | 0:b9079d9bc64d | 178 | char data[8]; |
WiredHome | 0:b9079d9bc64d | 179 | int len; |
WiredHome | 0:b9079d9bc64d | 180 | int format; |
WiredHome | 0:b9079d9bc64d | 181 | int type; |
WiredHome | 0:b9079d9bc64d | 182 | }; |
WiredHome | 0:b9079d9bc64d | 183 | |
WiredHome | 0:b9079d9bc64d | 184 | class CAN { |
WiredHome | 0:b9079d9bc64d | 185 | public: |
WiredHome | 0:b9079d9bc64d | 186 | CAN(PinName r, PinName t); |
WiredHome | 0:b9079d9bc64d | 187 | ~CAN(); |
WiredHome | 0:b9079d9bc64d | 188 | int write(CANMessage msg); |
WiredHome | 0:b9079d9bc64d | 189 | int read(CANMessage &msg); |
WiredHome | 0:b9079d9bc64d | 190 | void attach(void(*fp)(void)); |
WiredHome | 0:b9079d9bc64d | 191 | void monitor(bool t); |
WiredHome | 0:b9079d9bc64d | 192 | bool frequency(uint32_t f); |
WiredHome | 0:b9079d9bc64d | 193 | uint32_t tderror(); |
WiredHome | 0:b9079d9bc64d | 194 | uint32_t rderror(); |
WiredHome | 0:b9079d9bc64d | 195 | void reset(); |
WiredHome | 0:b9079d9bc64d | 196 | }; |
WiredHome | 0:b9079d9bc64d | 197 | |
WiredHome | 0:b9079d9bc64d | 198 | class PwmOut { |
WiredHome | 0:b9079d9bc64d | 199 | public: |
WiredHome | 0:b9079d9bc64d | 200 | PwmOut(PinName p); |
WiredHome | 0:b9079d9bc64d | 201 | ~PwmOut(); |
WiredHome | 0:b9079d9bc64d | 202 | double &PwmOut::operator=(double p); |
WiredHome | 0:b9079d9bc64d | 203 | private: |
WiredHome | 0:b9079d9bc64d | 204 | double p; |
WiredHome | 0:b9079d9bc64d | 205 | }; |
WiredHome | 0:b9079d9bc64d | 206 | |
WiredHome | 0:b9079d9bc64d | 207 | class Timeout { |
WiredHome | 0:b9079d9bc64d | 208 | public: |
WiredHome | 0:b9079d9bc64d | 209 | Timeout(); |
WiredHome | 0:b9079d9bc64d | 210 | ~Timeout(); |
WiredHome | 0:b9079d9bc64d | 211 | template <typename T> void attach(T * tptr, void (T::*mptr)(void), float t) { |
WiredHome | 0:b9079d9bc64d | 212 | (void)tptr; |
WiredHome | 0:b9079d9bc64d | 213 | (void)mptr; |
WiredHome | 0:b9079d9bc64d | 214 | (void)t; |
WiredHome | 0:b9079d9bc64d | 215 | } |
WiredHome | 0:b9079d9bc64d | 216 | }; |
WiredHome | 0:b9079d9bc64d | 217 | |
WiredHome | 0:b9079d9bc64d | 218 | class DigitalInOut { |
WiredHome | 0:b9079d9bc64d | 219 | public: |
WiredHome | 0:b9079d9bc64d | 220 | DigitalInOut(PinName p); |
WiredHome | 0:b9079d9bc64d | 221 | ~DigitalInOut(); |
WiredHome | 0:b9079d9bc64d | 222 | void output(); |
WiredHome | 0:b9079d9bc64d | 223 | void input(); |
WiredHome | 0:b9079d9bc64d | 224 | void write(bool v); |
WiredHome | 0:b9079d9bc64d | 225 | void mode(int m); |
WiredHome | 0:b9079d9bc64d | 226 | }; |
WiredHome | 0:b9079d9bc64d | 227 | |
WiredHome | 0:b9079d9bc64d | 228 | class Serial { |
WiredHome | 0:b9079d9bc64d | 229 | public: |
WiredHome | 0:b9079d9bc64d | 230 | Serial(PinName t, PinName r); |
WiredHome | 0:b9079d9bc64d | 231 | ~Serial(); |
WiredHome | 0:b9079d9bc64d | 232 | int printf(char *fmt, ...); |
WiredHome | 0:b9079d9bc64d | 233 | int readable(); |
WiredHome | 0:b9079d9bc64d | 234 | int getc(); |
WiredHome | 0:b9079d9bc64d | 235 | int putc(int c); |
WiredHome | 0:b9079d9bc64d | 236 | void baud(uint32_t freq); |
WiredHome | 0:b9079d9bc64d | 237 | }; |
WiredHome | 0:b9079d9bc64d | 238 | |
WiredHome | 0:b9079d9bc64d | 239 | class Timer { |
WiredHome | 0:b9079d9bc64d | 240 | public: |
WiredHome | 0:b9079d9bc64d | 241 | Timer(); |
WiredHome | 0:b9079d9bc64d | 242 | ~Timer(); |
WiredHome | 0:b9079d9bc64d | 243 | void start(); |
WiredHome | 0:b9079d9bc64d | 244 | uint32_t read_ms(); |
WiredHome | 0:b9079d9bc64d | 245 | uint32_t read_us(); |
WiredHome | 0:b9079d9bc64d | 246 | }; |
WiredHome | 0:b9079d9bc64d | 247 | |
WiredHome | 0:b9079d9bc64d | 248 | void wait(float t); |
WiredHome | 0:b9079d9bc64d | 249 | |
WiredHome | 0:b9079d9bc64d | 250 | #endif // WIN32 |
WiredHome | 0:b9079d9bc64d | 251 | |
WiredHome | 0:b9079d9bc64d | 252 | #endif // UTILITIES_H |
WiredHome | 0:b9079d9bc64d | 253 | /// Utilities.h is an adapter to support easier transition from |
WiredHome | 0:b9079d9bc64d | 254 | /// the mbed cloud compiler to Visual Studio |
WiredHome | 0:b9079d9bc64d | 255 | /// |
WiredHome | 0:b9079d9bc64d | 256 | #ifndef UTILITIES_H |
WiredHome | 0:b9079d9bc64d | 257 | #define UTILITIES_H |
WiredHome | 0:b9079d9bc64d | 258 | #include <string.h> |
WiredHome | 0:b9079d9bc64d | 259 | |
WiredHome | 0:b9079d9bc64d | 260 | // Helper functions follow. These functions may exist in some environments and |
WiredHome | 0:b9079d9bc64d | 261 | // not in other combinations of libraries and compilers, so private versions |
WiredHome | 0:b9079d9bc64d | 262 | // are here to ensure consistent behavior. |
WiredHome | 0:b9079d9bc64d | 263 | |
WiredHome | 0:b9079d9bc64d | 264 | /// Access to intentionally reset the mbed |
WiredHome | 0:b9079d9bc64d | 265 | /// |
WiredHome | 0:b9079d9bc64d | 266 | extern "C" void mbed_reset(); |
WiredHome | 0:b9079d9bc64d | 267 | |
WiredHome | 0:b9079d9bc64d | 268 | |
WiredHome | 0:b9079d9bc64d | 269 | /// mytolower exists because not all compiler libraries have this function |
WiredHome | 0:b9079d9bc64d | 270 | /// |
WiredHome | 0:b9079d9bc64d | 271 | /// This takes a character and if it is upper-case, it converts it to |
WiredHome | 0:b9079d9bc64d | 272 | /// lower-case and returns it. |
WiredHome | 0:b9079d9bc64d | 273 | /// |
WiredHome | 0:b9079d9bc64d | 274 | /// @param a is the character to convert |
WiredHome | 0:b9079d9bc64d | 275 | /// @returns the lower case equivalent to a |
WiredHome | 0:b9079d9bc64d | 276 | /// |
WiredHome | 0:b9079d9bc64d | 277 | char mytolower(char a); |
WiredHome | 0:b9079d9bc64d | 278 | |
WiredHome | 0:b9079d9bc64d | 279 | /// mystrnicmp exists because not all compiler libraries have this function. |
WiredHome | 0:b9079d9bc64d | 280 | /// |
WiredHome | 0:b9079d9bc64d | 281 | /// Some have strnicmp, others _strnicmp, and others have C++ methods, which |
WiredHome | 0:b9079d9bc64d | 282 | /// is outside the scope of this C-portable set of functions. |
WiredHome | 0:b9079d9bc64d | 283 | /// |
WiredHome | 0:b9079d9bc64d | 284 | /// @param l is a pointer to the string on the left |
WiredHome | 0:b9079d9bc64d | 285 | /// @param r is a pointer to the string on the right |
WiredHome | 0:b9079d9bc64d | 286 | /// @param n is the number of characters to compare |
WiredHome | 0:b9079d9bc64d | 287 | /// @returns -1 if l < r |
WiredHome | 0:b9079d9bc64d | 288 | /// @returns 0 if l == r |
WiredHome | 0:b9079d9bc64d | 289 | /// @returns +1 if l > r |
WiredHome | 0:b9079d9bc64d | 290 | /// |
WiredHome | 0:b9079d9bc64d | 291 | int mystrnicmp(const char *l, const char *r, size_t n); |
WiredHome | 0:b9079d9bc64d | 292 | |
WiredHome | 0:b9079d9bc64d | 293 | /// mystrcat exists because not all compiler libraries have this function |
WiredHome | 0:b9079d9bc64d | 294 | /// |
WiredHome | 0:b9079d9bc64d | 295 | /// This function concatinates one string onto another. It is generally |
WiredHome | 0:b9079d9bc64d | 296 | /// considered unsafe, because of the potential for buffer overflow. |
WiredHome | 0:b9079d9bc64d | 297 | /// Some libraries offer a strcat_s as the safe version, and others may have |
WiredHome | 0:b9079d9bc64d | 298 | /// _strcat. Because this is needed only internal to the CommandProcessor, |
WiredHome | 0:b9079d9bc64d | 299 | /// this version was created. |
WiredHome | 0:b9079d9bc64d | 300 | /// |
WiredHome | 0:b9079d9bc64d | 301 | /// @param dst is a pointer to the destination string |
WiredHome | 0:b9079d9bc64d | 302 | /// @param src is a pointer to the source string |
WiredHome | 0:b9079d9bc64d | 303 | /// @returns nothing |
WiredHome | 0:b9079d9bc64d | 304 | /// |
WiredHome | 0:b9079d9bc64d | 305 | void mystrcat(char *dst, char *src); |
WiredHome | 0:b9079d9bc64d | 306 | |
WiredHome | 0:b9079d9bc64d | 307 | /// myisprint exists because not all compiler libraries have this function |
WiredHome | 0:b9079d9bc64d | 308 | /// |
WiredHome | 0:b9079d9bc64d | 309 | /// This function tests a character to see if it is printable (a member |
WiredHome | 0:b9079d9bc64d | 310 | /// of the standard ASCII set). |
WiredHome | 0:b9079d9bc64d | 311 | /// |
WiredHome | 0:b9079d9bc64d | 312 | /// @param c is the character to test |
WiredHome | 0:b9079d9bc64d | 313 | /// @returns TRUE if the character is printable |
WiredHome | 0:b9079d9bc64d | 314 | /// @returns FALSE if the character is not printable |
WiredHome | 0:b9079d9bc64d | 315 | /// |
WiredHome | 0:b9079d9bc64d | 316 | int myisprint(int c); |
WiredHome | 0:b9079d9bc64d | 317 | |
WiredHome | 0:b9079d9bc64d | 318 | |
WiredHome | 0:b9079d9bc64d | 319 | /// hextoi converts a hex string to an unsigned integer |
WiredHome | 0:b9079d9bc64d | 320 | /// |
WiredHome | 0:b9079d9bc64d | 321 | /// This functions converts text to an unsigned integer, as long as |
WiredHome | 0:b9079d9bc64d | 322 | /// the stream contains hex-ASCII characters |
WiredHome | 0:b9079d9bc64d | 323 | /// |
WiredHome | 0:b9079d9bc64d | 324 | /// @param p is a pointer to the string |
WiredHome | 0:b9079d9bc64d | 325 | /// @returns unsigned long integer value |
WiredHome | 0:b9079d9bc64d | 326 | /// |
WiredHome | 0:b9079d9bc64d | 327 | unsigned long hextoul(char *p); |
WiredHome | 0:b9079d9bc64d | 328 | |
WiredHome | 0:b9079d9bc64d | 329 | |
WiredHome | 0:b9079d9bc64d | 330 | #ifdef WIN32 |
WiredHome | 0:b9079d9bc64d | 331 | //####################################################################### |
WiredHome | 0:b9079d9bc64d | 332 | //####################################################################### |
WiredHome | 0:b9079d9bc64d | 333 | //####################################################################### |
WiredHome | 0:b9079d9bc64d | 334 | // |
WiredHome | 0:b9079d9bc64d | 335 | // Everything from here forward is intended to "satisfy" the Visual |
WiredHome | 0:b9079d9bc64d | 336 | // Studio 2010 compiler. It isn't intended to necessarily run, since |
WiredHome | 0:b9079d9bc64d | 337 | // we're faking out hardware for the most part. |
WiredHome | 0:b9079d9bc64d | 338 | // |
WiredHome | 0:b9079d9bc64d | 339 | |
WiredHome | 0:b9079d9bc64d | 340 | #include <memory.h> |
WiredHome | 0:b9079d9bc64d | 341 | #include <stdio.h> |
WiredHome | 0:b9079d9bc64d | 342 | #include <stdlib.h> |
WiredHome | 0:b9079d9bc64d | 343 | #include <string.h> |
WiredHome | 0:b9079d9bc64d | 344 | #include <math.h> |
WiredHome | 0:b9079d9bc64d | 345 | #include <conio.h> |
WiredHome | 0:b9079d9bc64d | 346 | |
WiredHome | 0:b9079d9bc64d | 347 | #define __disable_irq() |
WiredHome | 0:b9079d9bc64d | 348 | #define __enable_irq() |
WiredHome | 0:b9079d9bc64d | 349 | |
WiredHome | 0:b9079d9bc64d | 350 | enum { |
WiredHome | 0:b9079d9bc64d | 351 | CANData, |
WiredHome | 0:b9079d9bc64d | 352 | CANRemote |
WiredHome | 0:b9079d9bc64d | 353 | }; |
WiredHome | 0:b9079d9bc64d | 354 | |
WiredHome | 0:b9079d9bc64d | 355 | enum { |
WiredHome | 0:b9079d9bc64d | 356 | CANStandard, |
WiredHome | 0:b9079d9bc64d | 357 | CANExtended |
WiredHome | 0:b9079d9bc64d | 358 | }; |
WiredHome | 0:b9079d9bc64d | 359 | |
WiredHome | 0:b9079d9bc64d | 360 | enum { |
WiredHome | 0:b9079d9bc64d | 361 | PullNone |
WiredHome | 0:b9079d9bc64d | 362 | }; |
WiredHome | 0:b9079d9bc64d | 363 | |
WiredHome | 0:b9079d9bc64d | 364 | typedef unsigned int uint32_t; |
WiredHome | 0:b9079d9bc64d | 365 | //typedef unsigned int PinName; |
WiredHome | 0:b9079d9bc64d | 366 | typedef enum { |
WiredHome | 0:b9079d9bc64d | 367 | NC, |
WiredHome | 0:b9079d9bc64d | 368 | USBTX, |
WiredHome | 0:b9079d9bc64d | 369 | USBRX, |
WiredHome | 0:b9079d9bc64d | 370 | LED1, |
WiredHome | 0:b9079d9bc64d | 371 | LED2, |
WiredHome | 0:b9079d9bc64d | 372 | LED3, |
WiredHome | 0:b9079d9bc64d | 373 | LED4, |
WiredHome | 0:b9079d9bc64d | 374 | p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, |
WiredHome | 0:b9079d9bc64d | 375 | p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, |
WiredHome | 0:b9079d9bc64d | 376 | p21, p22, p23, p24, p25, p26, p27, p28, p29, p30 |
WiredHome | 0:b9079d9bc64d | 377 | } PinName; |
WiredHome | 0:b9079d9bc64d | 378 | |
WiredHome | 0:b9079d9bc64d | 379 | |
WiredHome | 0:b9079d9bc64d | 380 | #define SystemCoreClock 48000000 |
WiredHome | 0:b9079d9bc64d | 381 | |
WiredHome | 0:b9079d9bc64d | 382 | typedef struct { |
WiredHome | 0:b9079d9bc64d | 383 | uint32_t WDMOD; |
WiredHome | 0:b9079d9bc64d | 384 | uint32_t WDCLKSEL; |
WiredHome | 0:b9079d9bc64d | 385 | uint32_t WDTC; |
WiredHome | 0:b9079d9bc64d | 386 | uint32_t WDFEED; |
WiredHome | 0:b9079d9bc64d | 387 | } LPC_WDT_BASE; |
WiredHome | 0:b9079d9bc64d | 388 | |
WiredHome | 0:b9079d9bc64d | 389 | extern LPC_WDT_BASE * LPC_WDT; |
WiredHome | 0:b9079d9bc64d | 390 | |
WiredHome | 0:b9079d9bc64d | 391 | typedef struct { |
WiredHome | 0:b9079d9bc64d | 392 | uint32_t MOD; |
WiredHome | 0:b9079d9bc64d | 393 | uint32_t GSR; |
WiredHome | 0:b9079d9bc64d | 394 | uint32_t ICR; |
WiredHome | 0:b9079d9bc64d | 395 | uint32_t IER; |
WiredHome | 0:b9079d9bc64d | 396 | uint32_t BTR; |
WiredHome | 0:b9079d9bc64d | 397 | uint32_t EWL; |
WiredHome | 0:b9079d9bc64d | 398 | uint32_t SR; |
WiredHome | 0:b9079d9bc64d | 399 | uint32_t RFS; |
WiredHome | 0:b9079d9bc64d | 400 | uint32_t RID; |
WiredHome | 0:b9079d9bc64d | 401 | uint32_t RDA; |
WiredHome | 0:b9079d9bc64d | 402 | uint32_t RDB; |
WiredHome | 0:b9079d9bc64d | 403 | uint32_t TFI1; |
WiredHome | 0:b9079d9bc64d | 404 | uint32_t TID1; |
WiredHome | 0:b9079d9bc64d | 405 | uint32_t TDA1; |
WiredHome | 0:b9079d9bc64d | 406 | uint32_t TDB1; |
WiredHome | 0:b9079d9bc64d | 407 | uint32_t TFI2; |
WiredHome | 0:b9079d9bc64d | 408 | uint32_t TID2; |
WiredHome | 0:b9079d9bc64d | 409 | uint32_t TDA2; |
WiredHome | 0:b9079d9bc64d | 410 | uint32_t TDB2; |
WiredHome | 0:b9079d9bc64d | 411 | uint32_t TFI3; |
WiredHome | 0:b9079d9bc64d | 412 | uint32_t TID3; |
WiredHome | 0:b9079d9bc64d | 413 | uint32_t TDA3; |
WiredHome | 0:b9079d9bc64d | 414 | uint32_t TDB3; |
WiredHome | 0:b9079d9bc64d | 415 | } LPC_CAN_BASE; |
WiredHome | 0:b9079d9bc64d | 416 | |
WiredHome | 0:b9079d9bc64d | 417 | extern LPC_CAN_BASE * LPC_CAN1; |
WiredHome | 0:b9079d9bc64d | 418 | extern LPC_CAN_BASE * LPC_CAN2; |
WiredHome | 0:b9079d9bc64d | 419 | |
WiredHome | 0:b9079d9bc64d | 420 | |
WiredHome | 0:b9079d9bc64d | 421 | class CANMessage { |
WiredHome | 0:b9079d9bc64d | 422 | public: |
WiredHome | 0:b9079d9bc64d | 423 | CANMessage(); |
WiredHome | 0:b9079d9bc64d | 424 | CANMessage(uint32_t _id, char * _pdata, int _len, int _type, int _format); |
WiredHome | 0:b9079d9bc64d | 425 | ~CANMessage(); |
WiredHome | 0:b9079d9bc64d | 426 | uint32_t id; |
WiredHome | 0:b9079d9bc64d | 427 | int dir; |
WiredHome | 0:b9079d9bc64d | 428 | char data[8]; |
WiredHome | 0:b9079d9bc64d | 429 | int len; |
WiredHome | 0:b9079d9bc64d | 430 | int format; |
WiredHome | 0:b9079d9bc64d | 431 | int type; |
WiredHome | 0:b9079d9bc64d | 432 | }; |
WiredHome | 0:b9079d9bc64d | 433 | |
WiredHome | 0:b9079d9bc64d | 434 | class CAN { |
WiredHome | 0:b9079d9bc64d | 435 | public: |
WiredHome | 0:b9079d9bc64d | 436 | CAN(PinName r, PinName t); |
WiredHome | 0:b9079d9bc64d | 437 | ~CAN(); |
WiredHome | 0:b9079d9bc64d | 438 | int write(CANMessage msg); |
WiredHome | 0:b9079d9bc64d | 439 | int read(CANMessage &msg); |
WiredHome | 0:b9079d9bc64d | 440 | void attach(void(*fp)(void)); |
WiredHome | 0:b9079d9bc64d | 441 | void monitor(bool t); |
WiredHome | 0:b9079d9bc64d | 442 | bool frequency(uint32_t f); |
WiredHome | 0:b9079d9bc64d | 443 | uint32_t tderror(); |
WiredHome | 0:b9079d9bc64d | 444 | uint32_t rderror(); |
WiredHome | 0:b9079d9bc64d | 445 | void reset(); |
WiredHome | 0:b9079d9bc64d | 446 | }; |
WiredHome | 0:b9079d9bc64d | 447 | |
WiredHome | 0:b9079d9bc64d | 448 | class PwmOut { |
WiredHome | 0:b9079d9bc64d | 449 | public: |
WiredHome | 0:b9079d9bc64d | 450 | PwmOut(PinName p); |
WiredHome | 0:b9079d9bc64d | 451 | ~PwmOut(); |
WiredHome | 0:b9079d9bc64d | 452 | double &PwmOut::operator=(double p); |
WiredHome | 0:b9079d9bc64d | 453 | private: |
WiredHome | 0:b9079d9bc64d | 454 | double p; |
WiredHome | 0:b9079d9bc64d | 455 | }; |
WiredHome | 0:b9079d9bc64d | 456 | |
WiredHome | 0:b9079d9bc64d | 457 | class Timeout { |
WiredHome | 0:b9079d9bc64d | 458 | public: |
WiredHome | 0:b9079d9bc64d | 459 | Timeout(); |
WiredHome | 0:b9079d9bc64d | 460 | ~Timeout(); |
WiredHome | 0:b9079d9bc64d | 461 | template <typename T> void attach(T * tptr, void (T::*mptr)(void), float t) { |
WiredHome | 0:b9079d9bc64d | 462 | (void)tptr; |
WiredHome | 0:b9079d9bc64d | 463 | (void)mptr; |
WiredHome | 0:b9079d9bc64d | 464 | (void)t; |
WiredHome | 0:b9079d9bc64d | 465 | } |
WiredHome | 0:b9079d9bc64d | 466 | }; |
WiredHome | 0:b9079d9bc64d | 467 | |
WiredHome | 0:b9079d9bc64d | 468 | class DigitalInOut { |
WiredHome | 0:b9079d9bc64d | 469 | public: |
WiredHome | 0:b9079d9bc64d | 470 | DigitalInOut(PinName p); |
WiredHome | 0:b9079d9bc64d | 471 | ~DigitalInOut(); |
WiredHome | 0:b9079d9bc64d | 472 | void output(); |
WiredHome | 0:b9079d9bc64d | 473 | void input(); |
WiredHome | 0:b9079d9bc64d | 474 | void write(bool v); |
WiredHome | 0:b9079d9bc64d | 475 | void mode(int m); |
WiredHome | 0:b9079d9bc64d | 476 | }; |
WiredHome | 0:b9079d9bc64d | 477 | |
WiredHome | 0:b9079d9bc64d | 478 | class Serial { |
WiredHome | 0:b9079d9bc64d | 479 | public: |
WiredHome | 0:b9079d9bc64d | 480 | Serial(PinName t, PinName r); |
WiredHome | 0:b9079d9bc64d | 481 | ~Serial(); |
WiredHome | 0:b9079d9bc64d | 482 | int printf(char *fmt, ...); |
WiredHome | 0:b9079d9bc64d | 483 | int readable(); |
WiredHome | 0:b9079d9bc64d | 484 | int getc(); |
WiredHome | 0:b9079d9bc64d | 485 | int putc(int c); |
WiredHome | 0:b9079d9bc64d | 486 | void baud(uint32_t freq); |
WiredHome | 0:b9079d9bc64d | 487 | }; |
WiredHome | 0:b9079d9bc64d | 488 | |
WiredHome | 0:b9079d9bc64d | 489 | class Timer { |
WiredHome | 0:b9079d9bc64d | 490 | public: |
WiredHome | 0:b9079d9bc64d | 491 | Timer(); |
WiredHome | 0:b9079d9bc64d | 492 | ~Timer(); |
WiredHome | 0:b9079d9bc64d | 493 | void start(); |
WiredHome | 0:b9079d9bc64d | 494 | uint32_t read_ms(); |
WiredHome | 0:b9079d9bc64d | 495 | uint32_t read_us(); |
WiredHome | 0:b9079d9bc64d | 496 | }; |
WiredHome | 0:b9079d9bc64d | 497 | |
WiredHome | 0:b9079d9bc64d | 498 | void wait(float t); |
WiredHome | 0:b9079d9bc64d | 499 | |
WiredHome | 0:b9079d9bc64d | 500 | #endif // WIN32 |
WiredHome | 0:b9079d9bc64d | 501 | |
WiredHome | 0:b9079d9bc64d | 502 | #endif // UTILITIES_H |