blob: 9f742384dac07b3dce28456218bef0d340f8add5 [file] [log] [blame]
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001/****************************************************************************
2
3 (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4 www.systec-electronic.com
5
6 Project: openPOWERLINK
7
8 Description: Abstract Memory Interface for x86 compatible
9
10 License:
11
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions
14 are met:
15
16 1. Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18
19 2. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
22
23 3. Neither the name of SYSTEC electronic GmbH nor the names of its
24 contributors may be used to endorse or promote products derived
25 from this software without prior written permission. For written
26 permission, please contact info@systec-electronic.com.
27
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32 COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 POSSIBILITY OF SUCH DAMAGE.
40
41 Severability Clause:
42
43 If a provision of this License is or becomes illegal, invalid or
44 unenforceable in any jurisdiction, that shall not affect:
45 1. the validity or enforceability in that jurisdiction of any other
46 provision of this License; or
47 2. the validity or enforceability in other jurisdictions of that or
48 any other provision of this License.
49
50 -------------------------------------------------------------------------
51
52 $RCSfile: amix86.c,v $
53
54 $Author: D.Krueger $
55
56 $Revision: 1.3 $ $Date: 2008/04/17 21:36:32 $
57
58 $State: Exp $
59
60 Build Environment:
61 ...
62
63 -------------------------------------------------------------------------
64
65 Revision History:
66
67 r.s.: first implemetation
68
69 2006-06-13 d.k.: duplicate functions for little endian and big endian
70
71****************************************************************************/
72
73//#include "global.h"
74//#include "EplAmi.h"
75#include "EplInc.h"
76
77#if (!defined(EPL_AMI_INLINED)) || defined(INLINE_ENABLED)
78
79//---------------------------------------------------------------------------
80// typedef
81//---------------------------------------------------------------------------
82
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -080083typedef struct {
84 WORD m_wWord;
Daniel Krueger9d7164c2008-12-19 11:41:57 -080085
86} twStruct;
87
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -080088typedef struct {
89 DWORD m_dwDword;
Daniel Krueger9d7164c2008-12-19 11:41:57 -080090
91} tdwStruct;
92
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -080093typedef struct {
94 QWORD m_qwQword;
Daniel Krueger9d7164c2008-12-19 11:41:57 -080095
96} tqwStruct;
97
Daniel Krueger9d7164c2008-12-19 11:41:57 -080098//=========================================================================//
99// //
100// P U B L I C F U N C T I O N S //
101// //
102//=========================================================================//
103
104//---------------------------------------------------------------------------
105//
106// Function: AmiSetXXXToBe()
107//
108// Description: writes the specified value to the absolute address in
109// big endian
110//
111// Parameters: pAddr_p = absolute address
112// xXXXVal_p = value
113//
114// Returns: (none)
115//
116// State:
117//
118//---------------------------------------------------------------------------
119
120//------------< write BYTE in big endian >--------------------------
121/*
122void PUBLIC AmiSetByteToBe (void FAR* pAddr_p, BYTE bByteVal_p)
123{
124
125 *(BYTE FAR*)pAddr_p = bByteVal_p;
126
127}
128*/
129
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800130//------------< write WORD in big endian >--------------------------
131
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800132INLINE_FUNCTION void PUBLIC AmiSetWordToBe(void FAR * pAddr_p, WORD wWordVal_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800133{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800134 twStruct FAR *pwStruct;
135 twStruct wValue;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800136
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800137 wValue.m_wWord = (WORD) ((wWordVal_p & 0x00FF) << 8); //LSB to MSB
138 wValue.m_wWord |= (WORD) ((wWordVal_p & 0xFF00) >> 8); //MSB to LSB
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800139
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800140 pwStruct = (twStruct FAR *) pAddr_p;
141 pwStruct->m_wWord = wValue.m_wWord;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800142
143}
144
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800145//------------< write DWORD in big endian >-------------------------
146
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800147INLINE_FUNCTION void PUBLIC AmiSetDwordToBe(void FAR * pAddr_p,
148 DWORD dwDwordVal_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800149{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800150 tdwStruct FAR *pdwStruct;
151 tdwStruct dwValue;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800152
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800153 dwValue.m_dwDword = ((dwDwordVal_p & 0x000000FF) << 24); //LSB to MSB
154 dwValue.m_dwDword |= ((dwDwordVal_p & 0x0000FF00) << 8);
155 dwValue.m_dwDword |= ((dwDwordVal_p & 0x00FF0000) >> 8);
156 dwValue.m_dwDword |= ((dwDwordVal_p & 0xFF000000) >> 24); //MSB to LSB
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800157
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800158 pdwStruct = (tdwStruct FAR *) pAddr_p;
159 pdwStruct->m_dwDword = dwValue.m_dwDword;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800160
161}
162
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800163//---------------------------------------------------------------------------
164//
165// Function: AmiSetXXXToLe()
166//
167// Description: writes the specified value to the absolute address in
168// little endian
169//
170// Parameters: pAddr_p = absolute address
171// xXXXVal_p = value
172//
173// Returns: (none)
174//
175// State:
176//
177//---------------------------------------------------------------------------
178
179//------------< write BYTE in little endian >--------------------------
180/*
181void PUBLIC AmiSetByteToLe (void FAR* pAddr_p, BYTE bByteVal_p)
182{
183
184 *(BYTE FAR*)pAddr_p = bByteVal_p;
185
186}
187*/
188
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800189//------------< write WORD in little endian >--------------------------
190
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800191INLINE_FUNCTION void PUBLIC AmiSetWordToLe(void FAR * pAddr_p, WORD wWordVal_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800192{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800193 twStruct FAR *pwStruct;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800194
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800195 pwStruct = (twStruct FAR *) pAddr_p;
196 pwStruct->m_wWord = wWordVal_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800197
198}
199
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800200//------------< write DWORD in little endian >-------------------------
201
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800202INLINE_FUNCTION void PUBLIC AmiSetDwordToLe(void FAR * pAddr_p,
203 DWORD dwDwordVal_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800204{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800205 tdwStruct FAR *pdwStruct;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800206
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800207 pdwStruct = (tdwStruct FAR *) pAddr_p;
208 pdwStruct->m_dwDword = dwDwordVal_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800209
210}
211
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800212//---------------------------------------------------------------------------
213//
214// Function: AmiGetXXXFromBe()
215//
216// Description: reads the specified value from the absolute address in
217// big endian
218//
219// Parameters: pAddr_p = absolute address
220//
221// Returns: XXX = value
222//
223// State:
224//
225//---------------------------------------------------------------------------
226
227//------------< read BYTE in big endian >---------------------------
228/*
229BYTE PUBLIC AmiGetByteFromBe (void FAR* pAddr_p)
230{
231
232 return ( *(BYTE FAR*)pAddr_p );
233
234}
235*/
236
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800237//------------< read WORD in big endian >---------------------------
238
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800239INLINE_FUNCTION WORD PUBLIC AmiGetWordFromBe(void FAR * pAddr_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800240{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800241 twStruct FAR *pwStruct;
242 twStruct wValue;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800243
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800244 pwStruct = (twStruct FAR *) pAddr_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800245
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800246 wValue.m_wWord = (WORD) ((pwStruct->m_wWord & 0x00FF) << 8); //LSB to MSB
247 wValue.m_wWord |= (WORD) ((pwStruct->m_wWord & 0xFF00) >> 8); //MSB to LSB
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800248
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800249 return (wValue.m_wWord);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800250
251}
252
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800253//------------< read DWORD in big endian >--------------------------
254
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800255INLINE_FUNCTION DWORD PUBLIC AmiGetDwordFromBe(void FAR * pAddr_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800256{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800257 tdwStruct FAR *pdwStruct;
258 tdwStruct dwValue;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800259
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800260 pdwStruct = (tdwStruct FAR *) pAddr_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800261
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800262 dwValue.m_dwDword = ((pdwStruct->m_dwDword & 0x000000FF) << 24); //LSB to MSB
263 dwValue.m_dwDword |= ((pdwStruct->m_dwDword & 0x0000FF00) << 8);
264 dwValue.m_dwDword |= ((pdwStruct->m_dwDword & 0x00FF0000) >> 8);
265 dwValue.m_dwDword |= ((pdwStruct->m_dwDword & 0xFF000000) >> 24); //MSB to LSB
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800266
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800267 return (dwValue.m_dwDword);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800268
269}
270
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800271//---------------------------------------------------------------------------
272//
273// Function: AmiGetXXXFromLe()
274//
275// Description: reads the specified value from the absolute address in
276// little endian
277//
278// Parameters: pAddr_p = absolute address
279//
280// Returns: XXX = value
281//
282// State:
283//
284//---------------------------------------------------------------------------
285
286//------------< read BYTE in little endian >---------------------------
287/*
288BYTE PUBLIC AmiGetByteFromLe (void FAR* pAddr_p)
289{
290
291 return ( *(BYTE FAR*)pAddr_p );
292
293}
294*/
295
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800296//------------< read WORD in little endian >---------------------------
297
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800298INLINE_FUNCTION WORD PUBLIC AmiGetWordFromLe(void FAR * pAddr_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800299{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800300 twStruct FAR *pwStruct;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800301
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800302 pwStruct = (twStruct FAR *) pAddr_p;
303 return (pwStruct->m_wWord);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800304
305}
306
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800307//------------< read DWORD in little endian >--------------------------
308
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800309INLINE_FUNCTION DWORD PUBLIC AmiGetDwordFromLe(void FAR * pAddr_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800310{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800311 tdwStruct FAR *pdwStruct;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800312
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800313 pdwStruct = (tdwStruct FAR *) pAddr_p;
314 return (pdwStruct->m_dwDword);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800315
316}
317
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800318//---------------------------------------------------------------------------
319//
320// Function: AmiSetDword24ToBe()
321//
322// Description: sets a 24 bit value to a buffer in big endian
323//
324// Parameters: pAddr_p = pointer to destination buffer
325// dwDwordVal_p = value to set
326//
327// Return: void
328//
329// State: not tested
330//
331//---------------------------------------------------------------------------
332
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800333INLINE_FUNCTION void PUBLIC AmiSetDword24ToBe(void FAR * pAddr_p,
334 DWORD dwDwordVal_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800335{
336
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800337 ((BYTE FAR *) pAddr_p)[0] = ((BYTE FAR *) & dwDwordVal_p)[2];
338 ((BYTE FAR *) pAddr_p)[1] = ((BYTE FAR *) & dwDwordVal_p)[1];
339 ((BYTE FAR *) pAddr_p)[2] = ((BYTE FAR *) & dwDwordVal_p)[0];
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800340
341}
342
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800343//---------------------------------------------------------------------------
344//
345// Function: AmiSetDword24ToLe()
346//
347// Description: sets a 24 bit value to a buffer in little endian
348//
349// Parameters: pAddr_p = pointer to destination buffer
350// dwDwordVal_p = value to set
351//
352// Return: void
353//
354// State: not tested
355//
356//---------------------------------------------------------------------------
357
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800358INLINE_FUNCTION void PUBLIC AmiSetDword24ToLe(void FAR * pAddr_p,
359 DWORD dwDwordVal_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800360{
361
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800362 ((BYTE FAR *) pAddr_p)[0] = ((BYTE FAR *) & dwDwordVal_p)[0];
363 ((BYTE FAR *) pAddr_p)[1] = ((BYTE FAR *) & dwDwordVal_p)[1];
364 ((BYTE FAR *) pAddr_p)[2] = ((BYTE FAR *) & dwDwordVal_p)[2];
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800365
366}
367
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800368//---------------------------------------------------------------------------
369//
370// Function: AmiGetDword24FromBe()
371//
372// Description: reads a 24 bit value from a buffer in big endian
373//
374// Parameters: pAddr_p = pointer to source buffer
375//
376// Return: DWORD = read value
377//
378// State: not tested
379//
380//---------------------------------------------------------------------------
381
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800382INLINE_FUNCTION DWORD PUBLIC AmiGetDword24FromBe(void FAR * pAddr_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800383{
384
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800385 tdwStruct dwStruct;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800386
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800387 dwStruct.m_dwDword = AmiGetDwordFromBe(pAddr_p);
388 dwStruct.m_dwDword >>= 8;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800389
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800390 return (dwStruct.m_dwDword);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800391
392}
393
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800394//---------------------------------------------------------------------------
395//
396// Function: AmiGetDword24FromLe()
397//
398// Description: reads a 24 bit value from a buffer in little endian
399//
400// Parameters: pAddr_p = pointer to source buffer
401//
402// Return: DWORD = read value
403//
404// State: not tested
405//
406//---------------------------------------------------------------------------
407
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800408INLINE_FUNCTION DWORD PUBLIC AmiGetDword24FromLe(void FAR * pAddr_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800409{
410
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800411 tdwStruct dwStruct;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800412
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800413 dwStruct.m_dwDword = AmiGetDwordFromLe(pAddr_p);
414 dwStruct.m_dwDword &= 0x00FFFFFF;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800415
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800416 return (dwStruct.m_dwDword);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800417
418}
419
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800420//#ifdef USE_VAR64
421
422//---------------------------------------------------------------------------
423//
424// Function: AmiSetQword64ToBe()
425//
426// Description: sets a 64 bit value to a buffer in big endian
427//
428// Parameters: pAddr_p = pointer to destination buffer
429// qwQwordVal_p = quadruple word value
430//
431// Return: void
432//
433// State: not tested
434//
435//---------------------------------------------------------------------------
436
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800437INLINE_FUNCTION void PUBLIC AmiSetQword64ToBe(void FAR * pAddr_p,
438 QWORD qwQwordVal_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800439{
440
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800441 ((BYTE FAR *) pAddr_p)[0] = ((BYTE FAR *) & qwQwordVal_p)[7];
442 ((BYTE FAR *) pAddr_p)[1] = ((BYTE FAR *) & qwQwordVal_p)[6];
443 ((BYTE FAR *) pAddr_p)[2] = ((BYTE FAR *) & qwQwordVal_p)[5];
444 ((BYTE FAR *) pAddr_p)[3] = ((BYTE FAR *) & qwQwordVal_p)[4];
445 ((BYTE FAR *) pAddr_p)[4] = ((BYTE FAR *) & qwQwordVal_p)[3];
446 ((BYTE FAR *) pAddr_p)[5] = ((BYTE FAR *) & qwQwordVal_p)[2];
447 ((BYTE FAR *) pAddr_p)[6] = ((BYTE FAR *) & qwQwordVal_p)[1];
448 ((BYTE FAR *) pAddr_p)[7] = ((BYTE FAR *) & qwQwordVal_p)[0];
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800449
450}
451
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800452//---------------------------------------------------------------------------
453//
454// Function: AmiSetQword64ToLe()
455//
456// Description: sets a 64 bit value to a buffer in little endian
457//
458// Parameters: pAddr_p = pointer to destination buffer
459// qwQwordVal_p = quadruple word value
460//
461// Return: void
462//
463// State: not tested
464//
465//---------------------------------------------------------------------------
466
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800467INLINE_FUNCTION void PUBLIC AmiSetQword64ToLe(void FAR * pAddr_p,
468 QWORD qwQwordVal_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800469{
470
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800471 QWORD FAR *pqwDst;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800472
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800473 pqwDst = (QWORD FAR *) pAddr_p;
474 *pqwDst = qwQwordVal_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800475
476}
477
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800478//---------------------------------------------------------------------------
479//
480// Function: AmiGetQword64FromBe()
481//
482// Description: reads a 64 bit value from a buffer in big endian
483//
484// Parameters: pAddr_p = pointer to source buffer
485//
486// Return: void
487//
488// State: not tested
489//
490//---------------------------------------------------------------------------
491
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800492INLINE_FUNCTION QWORD PUBLIC AmiGetQword64FromBe(void FAR * pAddr_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800493{
494
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800495 tqwStruct qwStruct;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800496
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800497 ((BYTE FAR *) & qwStruct.m_qwQword)[0] = ((BYTE FAR *) pAddr_p)[7];
498 ((BYTE FAR *) & qwStruct.m_qwQword)[1] = ((BYTE FAR *) pAddr_p)[6];
499 ((BYTE FAR *) & qwStruct.m_qwQword)[2] = ((BYTE FAR *) pAddr_p)[5];
500 ((BYTE FAR *) & qwStruct.m_qwQword)[3] = ((BYTE FAR *) pAddr_p)[4];
501 ((BYTE FAR *) & qwStruct.m_qwQword)[4] = ((BYTE FAR *) pAddr_p)[3];
502 ((BYTE FAR *) & qwStruct.m_qwQword)[5] = ((BYTE FAR *) pAddr_p)[2];
503 ((BYTE FAR *) & qwStruct.m_qwQword)[6] = ((BYTE FAR *) pAddr_p)[1];
504 ((BYTE FAR *) & qwStruct.m_qwQword)[7] = ((BYTE FAR *) pAddr_p)[0];
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800505
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800506 return (qwStruct.m_qwQword);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800507
508}
509
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800510//---------------------------------------------------------------------------
511//
512// Function: AmiGetQword64FromLe()
513//
514// Description: reads a 64 bit value from a buffer in little endian
515//
516// Parameters: pAddr_p = pointer to source buffer
517//
518// Return: void
519//
520// State: not tested
521//
522//---------------------------------------------------------------------------
523
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800524INLINE_FUNCTION QWORD PUBLIC AmiGetQword64FromLe(void FAR * pAddr_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800525{
526
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800527 tqwStruct FAR *pqwStruct;
528 tqwStruct qwStruct;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800529
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800530 pqwStruct = (tqwStruct FAR *) pAddr_p;
531 qwStruct.m_qwQword = pqwStruct->m_qwQword;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800532
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800533 return (qwStruct.m_qwQword);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800534
535}
536
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800537//---------------------------------------------------------------------------
538//
539// Function: AmiSetQword40ToBe()
540//
541// Description: sets a 40 bit value to a buffer in big endian
542//
543// Parameters: pAddr_p = pointer to destination buffer
544// qwQwordVal_p = quadruple word value
545//
546// Return: void
547//
548// State: not tested
549//
550//---------------------------------------------------------------------------
551
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800552INLINE_FUNCTION void PUBLIC AmiSetQword40ToBe(void FAR * pAddr_p,
553 QWORD qwQwordVal_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800554{
555
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800556 ((BYTE FAR *) pAddr_p)[0] = ((BYTE FAR *) & qwQwordVal_p)[4];
557 ((BYTE FAR *) pAddr_p)[1] = ((BYTE FAR *) & qwQwordVal_p)[3];
558 ((BYTE FAR *) pAddr_p)[2] = ((BYTE FAR *) & qwQwordVal_p)[2];
559 ((BYTE FAR *) pAddr_p)[3] = ((BYTE FAR *) & qwQwordVal_p)[1];
560 ((BYTE FAR *) pAddr_p)[4] = ((BYTE FAR *) & qwQwordVal_p)[0];
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800561
562}
563
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800564//---------------------------------------------------------------------------
565//
566// Function: AmiSetQword40ToLe()
567//
568// Description: sets a 40 bit value to a buffer in little endian
569//
570// Parameters: pAddr_p = pointer to destination buffer
571// qwQwordVal_p = quadruple word value
572//
573// Return: void
574//
575// State: not tested
576//
577//---------------------------------------------------------------------------
578
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800579INLINE_FUNCTION void PUBLIC AmiSetQword40ToLe(void FAR * pAddr_p,
580 QWORD qwQwordVal_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800581{
582
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800583 ((DWORD FAR *) pAddr_p)[0] = ((DWORD FAR *) & qwQwordVal_p)[0];
584 ((BYTE FAR *) pAddr_p)[4] = ((BYTE FAR *) & qwQwordVal_p)[4];
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800585
586}
587
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800588//---------------------------------------------------------------------------
589//
590// Function: AmiGetQword40FromBe()
591//
592// Description: reads a 40 bit value from a buffer in big endian
593//
594// Parameters: pAddr_p = pointer to source buffer
595//
596// Return: QWORD
597//
598// State: not tested
599//
600//---------------------------------------------------------------------------
601
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800602INLINE_FUNCTION QWORD PUBLIC AmiGetQword40FromBe(void FAR * pAddr_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800603{
604
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800605 tqwStruct qwStruct;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800606
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800607 qwStruct.m_qwQword = AmiGetQword64FromBe(pAddr_p);
608 qwStruct.m_qwQword >>= 24;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800609
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800610 return (qwStruct.m_qwQword);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800611
612}
613
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800614//---------------------------------------------------------------------------
615//
616// Function: AmiGetQword40FromLe()
617//
618// Description: reads a 40 bit value from a buffer in little endian
619//
620// Parameters: pAddr_p = pointer to source buffer
621//
622// Return: QWORD
623//
624// State: not tested
625//
626//---------------------------------------------------------------------------
627
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800628INLINE_FUNCTION QWORD PUBLIC AmiGetQword40FromLe(void FAR * pAddr_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800629{
630
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800631 tqwStruct qwStruct;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800632
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800633 qwStruct.m_qwQword = AmiGetQword64FromLe(pAddr_p);
634 qwStruct.m_qwQword &= 0x000000FFFFFFFFFFLL;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800635
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800636 return (qwStruct.m_qwQword);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800637
638}
639
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800640//---------------------------------------------------------------------------
641//
642// Function: AmiSetQword48ToBe()
643//
644// Description: sets a 48 bit value to a buffer in big endian
645//
646// Parameters: pAddr_p = pointer to destination buffer
647// qwQwordVal_p = quadruple word value
648//
649// Return: void
650//
651// State: not tested
652//
653//---------------------------------------------------------------------------
654
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800655INLINE_FUNCTION void PUBLIC AmiSetQword48ToBe(void FAR * pAddr_p,
656 QWORD qwQwordVal_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800657{
658
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800659 ((BYTE FAR *) pAddr_p)[0] = ((BYTE FAR *) & qwQwordVal_p)[5];
660 ((BYTE FAR *) pAddr_p)[1] = ((BYTE FAR *) & qwQwordVal_p)[4];
661 ((BYTE FAR *) pAddr_p)[2] = ((BYTE FAR *) & qwQwordVal_p)[3];
662 ((BYTE FAR *) pAddr_p)[3] = ((BYTE FAR *) & qwQwordVal_p)[2];
663 ((BYTE FAR *) pAddr_p)[4] = ((BYTE FAR *) & qwQwordVal_p)[1];
664 ((BYTE FAR *) pAddr_p)[5] = ((BYTE FAR *) & qwQwordVal_p)[0];
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800665
666}
667
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800668//---------------------------------------------------------------------------
669//
670// Function: AmiSetQword48ToLe()
671//
672// Description: sets a 48 bit value to a buffer in little endian
673//
674// Parameters: pAddr_p = pointer to destination buffer
675// qwQwordVal_p = quadruple word value
676//
677// Return: void
678//
679// State: not tested
680//
681//---------------------------------------------------------------------------
682
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800683INLINE_FUNCTION void PUBLIC AmiSetQword48ToLe(void FAR * pAddr_p,
684 QWORD qwQwordVal_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800685{
686
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800687 ((DWORD FAR *) pAddr_p)[0] = ((DWORD FAR *) & qwQwordVal_p)[0];
688 ((WORD FAR *) pAddr_p)[2] = ((WORD FAR *) & qwQwordVal_p)[2];
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800689
690}
691
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800692//---------------------------------------------------------------------------
693//
694// Function: AmiGetQword48FromBe()
695//
696// Description: reads a 48 bit value from a buffer in big endian
697//
698// Parameters: pAddr_p = pointer to source buffer
699//
700// Return: QWORD
701//
702// State: not tested
703//
704//---------------------------------------------------------------------------
705
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800706INLINE_FUNCTION QWORD PUBLIC AmiGetQword48FromBe(void FAR * pAddr_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800707{
708
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800709 tqwStruct qwStruct;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800710
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800711 qwStruct.m_qwQword = AmiGetQword64FromBe(pAddr_p);
712 qwStruct.m_qwQword >>= 16;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800713
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800714 return (qwStruct.m_qwQword);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800715
716}
717
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800718//---------------------------------------------------------------------------
719//
720// Function: AmiGetQword48FromLe()
721//
722// Description: reads a 48 bit value from a buffer in little endian
723//
724// Parameters: pAddr_p = pointer to source buffer
725//
726// Return: QWORD
727//
728// State: not tested
729//
730//---------------------------------------------------------------------------
731
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800732INLINE_FUNCTION QWORD PUBLIC AmiGetQword48FromLe(void FAR * pAddr_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800733{
734
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800735 tqwStruct qwStruct;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800736
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800737 qwStruct.m_qwQword = AmiGetQword64FromLe(pAddr_p);
738 qwStruct.m_qwQword &= 0x0000FFFFFFFFFFFFLL;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800739
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800740 return (qwStruct.m_qwQword);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800741
742}
743
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800744//---------------------------------------------------------------------------
745//
746// Function: AmiSetQword56ToBe()
747//
748// Description: sets a 56 bit value to a buffer in big endian
749//
750// Parameters: pAddr_p = pointer to destination buffer
751// qwQwordVal_p = quadruple word value
752//
753// Return: void
754//
755// State: not tested
756//
757//---------------------------------------------------------------------------
758
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800759INLINE_FUNCTION void PUBLIC AmiSetQword56ToBe(void FAR * pAddr_p,
760 QWORD qwQwordVal_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800761{
762
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800763 ((BYTE FAR *) pAddr_p)[0] = ((BYTE FAR *) & qwQwordVal_p)[6];
764 ((BYTE FAR *) pAddr_p)[1] = ((BYTE FAR *) & qwQwordVal_p)[5];
765 ((BYTE FAR *) pAddr_p)[2] = ((BYTE FAR *) & qwQwordVal_p)[4];
766 ((BYTE FAR *) pAddr_p)[3] = ((BYTE FAR *) & qwQwordVal_p)[3];
767 ((BYTE FAR *) pAddr_p)[4] = ((BYTE FAR *) & qwQwordVal_p)[2];
768 ((BYTE FAR *) pAddr_p)[5] = ((BYTE FAR *) & qwQwordVal_p)[1];
769 ((BYTE FAR *) pAddr_p)[6] = ((BYTE FAR *) & qwQwordVal_p)[0];
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800770
771}
772
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800773//---------------------------------------------------------------------------
774//
775// Function: AmiSetQword56ToLe()
776//
777// Description: sets a 56 bit value to a buffer in little endian
778//
779// Parameters: pAddr_p = pointer to destination buffer
780// qwQwordVal_p = quadruple word value
781//
782// Return: void
783//
784// State: not tested
785//
786//---------------------------------------------------------------------------
787
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800788INLINE_FUNCTION void PUBLIC AmiSetQword56ToLe(void FAR * pAddr_p,
789 QWORD qwQwordVal_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800790{
791
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800792 ((DWORD FAR *) pAddr_p)[0] = ((DWORD FAR *) & qwQwordVal_p)[0];
793 ((WORD FAR *) pAddr_p)[2] = ((WORD FAR *) & qwQwordVal_p)[2];
794 ((BYTE FAR *) pAddr_p)[6] = ((BYTE FAR *) & qwQwordVal_p)[6];
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800795
796}
797
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800798//---------------------------------------------------------------------------
799//
800// Function: AmiGetQword56FromBe()
801//
802// Description: reads a 56 bit value from a buffer in big endian
803//
804// Parameters: pAddr_p = pointer to source buffer
805//
806// Return: QWORD
807//
808// State: not tested
809//
810//---------------------------------------------------------------------------
811
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800812INLINE_FUNCTION QWORD PUBLIC AmiGetQword56FromBe(void FAR * pAddr_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800813{
814
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800815 tqwStruct qwStruct;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800816
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800817 qwStruct.m_qwQword = AmiGetQword64FromBe(pAddr_p);
818 qwStruct.m_qwQword >>= 8;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800819
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800820 return (qwStruct.m_qwQword);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800821
822}
823
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800824//---------------------------------------------------------------------------
825//
826// Function: AmiGetQword56FromLe()
827//
828// Description: reads a 56 bit value from a buffer in little endian
829//
830// Parameters: pAddr_p = pointer to source buffer
831//
832// Return: QWORD
833//
834// State: not tested
835//
836//---------------------------------------------------------------------------
837
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800838INLINE_FUNCTION QWORD PUBLIC AmiGetQword56FromLe(void FAR * pAddr_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800839{
840
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800841 tqwStruct qwStruct;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800842
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800843 qwStruct.m_qwQword = AmiGetQword64FromLe(pAddr_p);
844 qwStruct.m_qwQword &= 0x00FFFFFFFFFFFFFFLL;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800845
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800846 return (qwStruct.m_qwQword);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800847
848}
849
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800850//---------------------------------------------------------------------------
851//
852// Function: AmiSetTimeOfDay()
853//
854// Description: sets a TIME_OF_DAY (CANopen) value to a buffer
855//
856// Parameters: pAddr_p = pointer to destination buffer
857// pTimeOfDay_p = pointer to struct TIME_OF_DAY
858//
859// Return: void
860//
861// State: not tested
862//
863//---------------------------------------------------------------------------
864
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800865INLINE_FUNCTION void PUBLIC AmiSetTimeOfDay(void FAR * pAddr_p,
866 tTimeOfDay FAR * pTimeOfDay_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800867{
868
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800869 AmiSetDwordToLe(((BYTE FAR *) pAddr_p),
870 pTimeOfDay_p->m_dwMs & 0x0FFFFFFF);
871 AmiSetWordToLe(((BYTE FAR *) pAddr_p) + 4, pTimeOfDay_p->m_wDays);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800872
873}
874
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800875//---------------------------------------------------------------------------
876//
877// Function: AmiGetTimeOfDay()
878//
879// Description: reads a TIME_OF_DAY (CANopen) value from a buffer
880//
881// Parameters: pAddr_p = pointer to source buffer
882// pTimeOfDay_p = pointer to struct TIME_OF_DAY
883//
884// Return: void
885//
886// State: not tested
887//
888//---------------------------------------------------------------------------
889
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800890INLINE_FUNCTION void PUBLIC AmiGetTimeOfDay(void FAR * pAddr_p,
891 tTimeOfDay FAR * pTimeOfDay_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800892{
893
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800894 pTimeOfDay_p->m_dwMs =
895 AmiGetDwordFromLe(((BYTE FAR *) pAddr_p)) & 0x0FFFFFFF;
896 pTimeOfDay_p->m_wDays = AmiGetWordFromLe(((BYTE FAR *) pAddr_p) + 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800897
898}
899
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800900#endif
901
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800902// EOF
903
904// Die letzte Zeile muß unbedingt eine leere Zeile sein, weil manche Compiler
905// damit ein Problem haben, wenn das nicht so ist (z.B. GNU oder Borland C++ Builder).