|
1 /* |
|
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** file LittleEndianPacker.INL |
|
19 * |
|
20 * Implements inline macro functions used to interface between USB |
|
21 * (little-endian) byte buffers and standard data types. |
|
22 * |
|
23 * The implementation uses inline macros (for speed) that are used to |
|
24 * step down a little-endian USB buffer to extract and insert members. |
|
25 * |
|
26 * The functions update the given buffer index so that they can be |
|
27 * used in sequence to extract or pack successive parts of a message. |
|
28 * |
|
29 * Although these functions are of more general use than just the CDC |
|
30 * application, they are located here pending possible promotion into |
|
31 * the chapter.9 area, where they would become available for use in |
|
32 * other classes, e.g. HID |
|
33 * |
|
34 * Copyright (c) 2003 Symbian Ltd. All rights reserved. |
|
35 */ |
|
36 |
|
37 #ifndef __LITTLEENDIANPACKER_INL__ |
|
38 #define __LITTLEENDIANPACKER_INL__ |
|
39 |
|
40 #include <e32def.h> |
|
41 |
|
42 /* ------------------------------------------------------------------------- */ |
|
43 |
|
44 typedef union _FloatInt |
|
45 { |
|
46 TUint32 uVal; |
|
47 TReal32 fVal; |
|
48 } |
|
49 UFloatInt; |
|
50 |
|
51 inline TReal32 CCdcControlInterface::GetF32( TUint8** aPPbuf ) |
|
52 { |
|
53 UFloatInt retval; |
|
54 |
|
55 retval.uVal = GetU32(aPPbuf); |
|
56 |
|
57 return retval.fVal; |
|
58 }; |
|
59 |
|
60 inline void CCdcControlInterface::PutF32( TUint8** aPPbuf, TReal32 aF32 ) |
|
61 { |
|
62 UFloatInt inval; |
|
63 |
|
64 inval.fVal = aF32; |
|
65 |
|
66 PutU32(aPPbuf,inval.uVal); |
|
67 }; |
|
68 |
|
69 /* ------------------------------------------------------------------------- */ |
|
70 |
|
71 inline TUint32 CCdcControlInterface::GetU32( TUint8** aPPbuf ) |
|
72 { |
|
73 TUint8* pbuf = *aPPbuf; |
|
74 |
|
75 *aPPbuf = pbuf + sizeof(TUint32); |
|
76 |
|
77 return (TUint32)( (pbuf[3] << 24 ) | ( pbuf[2] << 16 ) | ( pbuf[1] << 8 ) | ( pbuf[0] ) ); |
|
78 }; |
|
79 |
|
80 inline void CCdcControlInterface::PutU32( TUint8** aPPbuf, TUint32 aU32 ) |
|
81 { |
|
82 TUint8* pbuf = *aPPbuf; |
|
83 |
|
84 *aPPbuf = pbuf + sizeof(TUint32); |
|
85 |
|
86 pbuf[3] = (TUint8) ((aU32 >> 24) ); // mask not needed, only 8 bits left |
|
87 pbuf[2] = (TUint8) ((aU32 >> 16) & 0xFF); |
|
88 pbuf[1] = (TUint8) ((aU32 >> 8) & 0xFF); |
|
89 pbuf[0] = (TUint8) ((aU32 ) & 0xFF); // shift not needed, mask takes 8 bits |
|
90 }; |
|
91 |
|
92 /* ------------------------------------------------------------------------- */ |
|
93 |
|
94 inline TUint16 CCdcControlInterface::GetU16( TUint8** aPPbuf ) |
|
95 { |
|
96 TUint8* pbuf = *aPPbuf; |
|
97 |
|
98 *aPPbuf = pbuf + sizeof(TUint16); |
|
99 |
|
100 return (TUint16) ( ( pbuf[1] << 8) | ( pbuf[0] ) ); |
|
101 }; |
|
102 |
|
103 inline void CCdcControlInterface::PutU16( TUint8** aPPbuf, TUint16 aU16 ) |
|
104 { |
|
105 TUint8* pbuf = *aPPbuf; |
|
106 |
|
107 *aPPbuf = pbuf + sizeof(TUint16); |
|
108 |
|
109 pbuf[3] = (TUint8) ((aU16 >> 8) ); // mask not needed, only 8 bits left |
|
110 pbuf[0] = (TUint8) ((aU16 ) & 0xFF); // shift not needed, mask takes 8 bits |
|
111 }; |
|
112 |
|
113 /* ------------------------------------------------------------------------- */ |
|
114 |
|
115 inline TUint8 CCdcControlInterface::GetU08( TUint8** aPPbuf ) |
|
116 { |
|
117 TUint8* pbuf = *aPPbuf; |
|
118 |
|
119 *aPPbuf = pbuf + sizeof(TUint8); |
|
120 |
|
121 return (TUint8) ( pbuf[0] ); |
|
122 }; |
|
123 |
|
124 inline void CCdcControlInterface::PutU08( TUint8** aPPbuf, TUint8 aU8 ) |
|
125 { |
|
126 TUint8* pbuf = *aPPbuf; |
|
127 |
|
128 *aPPbuf = pbuf + sizeof(TUint8); |
|
129 |
|
130 pbuf[0] = (aU8); |
|
131 }; |
|
132 |
|
133 /* ------------------------------------------------------------------------- */ |
|
134 #endif // __LITTLEENDIANPACKER_INL__ |
|
135 /* ------------------------------------------------------------------------- */ |
|
136 |