TLM-2.0
2.0.3
Accellera TLM-2.0 proof-of-concept library
Main Page
Namespaces
Classes
Files
File List
File Members
tlm_core
tlm_2
tlm_generic_payload
tlm_helpers.h
Go to the documentation of this file.
1
/*****************************************************************************
2
3
The following code is derived, directly or indirectly, from the SystemC
4
source code Copyright (c) 1996-2014 by all Contributors.
5
All Rights reserved.
6
7
The contents of this file are subject to the restrictions and limitations
8
set forth in the SystemC Open Source License (the "License");
9
You may not use this file except in compliance with such restrictions and
10
limitations. You may obtain instructions on how to receive a copy of the
11
License at http://www.accellera.org/. Software distributed by Contributors
12
under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13
ANY KIND, either express or implied. See the License for the specific
14
language governing rights and limitations under the License.
15
16
*****************************************************************************/
17
18
/* ---------------------------------------------------------------------------------------
19
@file tlm_helpers.h
20
21
@brief
22
23
Original Authors:
24
Charles Wilson, ESLX
25
26
--------------------------------------------------------------------------------------- */
27
28
#ifndef __TLM_HELPERS_H__
29
#define __TLM_HELPERS_H__
30
31
//#include <sys/param.h>
32
//#include <cstring>
33
34
namespace
tlm {
35
36
enum
tlm_endianness
{
TLM_UNKNOWN_ENDIAN
,
TLM_LITTLE_ENDIAN
,
TLM_BIG_ENDIAN
};
37
38
inline
tlm_endianness
get_host_endianness
(
void
)
39
{
40
static
tlm_endianness
host_endianness =
TLM_UNKNOWN_ENDIAN
;
41
42
if
(host_endianness ==
TLM_UNKNOWN_ENDIAN
) {
43
unsigned
int
number = 1;
44
unsigned
char
*p_msb_or_lsb = (
unsigned
char
*)&number;
45
46
host_endianness = (p_msb_or_lsb[0] == 0) ?
TLM_BIG_ENDIAN
:
TLM_LITTLE_ENDIAN
;
47
}
48
return
host_endianness;
49
}
50
51
inline
bool
host_has_little_endianness
(
void
)
52
{
53
static
tlm_endianness
host_endianness =
TLM_UNKNOWN_ENDIAN
;
54
static
bool
host_little_endian =
false
;
55
56
if
(host_endianness ==
TLM_UNKNOWN_ENDIAN
) {
57
unsigned
int
number = 1;
58
unsigned
char
*p_msb_or_lsb = (
unsigned
char
*)&number;
59
60
host_little_endian = (p_msb_or_lsb[0] == 0) ?
false
:
true
;
61
}
62
63
return
host_little_endian;
64
}
65
66
inline
bool
has_host_endianness
(
tlm_endianness
endianness)
67
{
68
if
(
host_has_little_endianness
()) {
69
return
endianness ==
TLM_LITTLE_ENDIAN
;
70
71
}
else
{
72
return
endianness ==
TLM_BIG_ENDIAN
;
73
}
74
}
75
76
}
// namespace tlm
77
78
#endif
/* __TLM_HELPERS_H__ */
tlm::TLM_BIG_ENDIAN
Definition:
tlm_helpers.h:36
tlm::has_host_endianness
bool has_host_endianness(tlm_endianness endianness)
Definition:
tlm_helpers.h:66
tlm::host_has_little_endianness
bool host_has_little_endianness(void)
Definition:
tlm_helpers.h:51
tlm::get_host_endianness
tlm_endianness get_host_endianness(void)
Definition:
tlm_helpers.h:38
tlm::tlm_endianness
tlm_endianness
Definition:
tlm_helpers.h:36
tlm::TLM_UNKNOWN_ENDIAN
Definition:
tlm_helpers.h:36
tlm::TLM_LITTLE_ENDIAN
Definition:
tlm_helpers.h:36
Generated on Thu Jun 19 2014 07:42:05 for TLM-2.0 by
1.8.6