ThingPlug GMMP library for mbed
Dependents: ThingPlug_WiFi_Example
Util/GMMP_Util.cpp@4:bb6c1ee1d5f0, 2015-08-13 (annotated)
- Committer:
- lesmin
- Date:
- Thu Aug 13 07:04:29 2015 +0000
- Revision:
- 4:bb6c1ee1d5f0
- Parent:
- 0:32c20cfb2b30
added NTP error return
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lesmin | 0:32c20cfb2b30 | 1 | /* |
lesmin | 0:32c20cfb2b30 | 2 | * GMMP_Util.c |
lesmin | 0:32c20cfb2b30 | 3 | * |
lesmin | 0:32c20cfb2b30 | 4 | * Created on: 2013. 11. 27. |
lesmin | 0:32c20cfb2b30 | 5 | * Author: root |
lesmin | 0:32c20cfb2b30 | 6 | */ |
lesmin | 0:32c20cfb2b30 | 7 | |
lesmin | 0:32c20cfb2b30 | 8 | #include "GMMP_Util.h" |
lesmin | 0:32c20cfb2b30 | 9 | |
lesmin | 0:32c20cfb2b30 | 10 | short ltobs(const short nShort) |
lesmin | 0:32c20cfb2b30 | 11 | { |
lesmin | 0:32c20cfb2b30 | 12 | return _btols(nShort); |
lesmin | 0:32c20cfb2b30 | 13 | } |
lesmin | 0:32c20cfb2b30 | 14 | |
lesmin | 0:32c20cfb2b30 | 15 | short btols(const short nShort) |
lesmin | 0:32c20cfb2b30 | 16 | { |
lesmin | 0:32c20cfb2b30 | 17 | return _btols(nShort); |
lesmin | 0:32c20cfb2b30 | 18 | } |
lesmin | 0:32c20cfb2b30 | 19 | |
lesmin | 0:32c20cfb2b30 | 20 | short _btols(const short nShort) |
lesmin | 0:32c20cfb2b30 | 21 | { |
lesmin | 0:32c20cfb2b30 | 22 | short nValue = 0; |
lesmin | 0:32c20cfb2b30 | 23 | |
lesmin | 0:32c20cfb2b30 | 24 | nValue = (unsigned short)nShort >> 8; |
lesmin | 0:32c20cfb2b30 | 25 | nValue |=(unsigned short) nShort << 8; |
lesmin | 0:32c20cfb2b30 | 26 | |
lesmin | 0:32c20cfb2b30 | 27 | return nValue; |
lesmin | 0:32c20cfb2b30 | 28 | } |
lesmin | 0:32c20cfb2b30 | 29 | |
lesmin | 0:32c20cfb2b30 | 30 | long ltobi(const long nInt) |
lesmin | 0:32c20cfb2b30 | 31 | { |
lesmin | 0:32c20cfb2b30 | 32 | return _ltobi(nInt); |
lesmin | 0:32c20cfb2b30 | 33 | } |
lesmin | 0:32c20cfb2b30 | 34 | |
lesmin | 0:32c20cfb2b30 | 35 | long btoli(const long nInt) |
lesmin | 0:32c20cfb2b30 | 36 | { |
lesmin | 0:32c20cfb2b30 | 37 | return _ltobi(nInt); |
lesmin | 0:32c20cfb2b30 | 38 | } |
lesmin | 0:32c20cfb2b30 | 39 | |
lesmin | 0:32c20cfb2b30 | 40 | long _ltobi(const long nInt) |
lesmin | 0:32c20cfb2b30 | 41 | { |
lesmin | 0:32c20cfb2b30 | 42 | long nVal0, nVal1, nVal2, nVal3; |
lesmin | 0:32c20cfb2b30 | 43 | |
lesmin | 0:32c20cfb2b30 | 44 | nVal0 = (unsigned long)nInt >> 24; |
lesmin | 0:32c20cfb2b30 | 45 | nVal1 = (unsigned long)(nInt & 0x00FF0000) >> 8; |
lesmin | 0:32c20cfb2b30 | 46 | nVal2 = (unsigned long)(nInt & 0x0000FF00) << 8; |
lesmin | 0:32c20cfb2b30 | 47 | nVal3 = (unsigned long)nInt << 24; |
lesmin | 0:32c20cfb2b30 | 48 | |
lesmin | 0:32c20cfb2b30 | 49 | return (nVal0 | nVal1 | nVal2 | nVal3); |
lesmin | 0:32c20cfb2b30 | 50 | } |
lesmin | 0:32c20cfb2b30 | 51 | |
lesmin | 0:32c20cfb2b30 | 52 | int freeRam () { |
lesmin | 0:32c20cfb2b30 | 53 | // __brkval is the address of the top of the heap |
lesmin | 0:32c20cfb2b30 | 54 | // if memory has been allocated. |
lesmin | 0:32c20cfb2b30 | 55 | // If __brkval is zero then it means malloc has not used any memory yet, so |
lesmin | 0:32c20cfb2b30 | 56 | // we look at the address of __heap_start. |
lesmin | 0:32c20cfb2b30 | 57 | |
lesmin | 0:32c20cfb2b30 | 58 | return 0; |
lesmin | 0:32c20cfb2b30 | 59 | } |