1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - include
3   File:     platform.h
4 
5   Copyright 2006-2008 Nintendo. All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Date:: 2008-09-17#$
14   $Rev: 8556 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 #ifndef NITRO_PLATFORM_HEADER__
18 #define NITRO_PLATFORM_HEADER__
19 
20 
21 // for OS_DisableInterrupts()
22 #include <nitro/os/common/system.h>
23 
24 /*****************************************************************************/
25 /* Shared definitions */
26 
27 /* Endian and bit-order definitions */
28 #define PLATFORM_ENDIAN_BIG     0
29 #define PLATFORM_ENDIAN_LITTLE  1
30 
31 
32 /*****************************************************************************/
33 /* Platform-specific definitions */
34 
35 /* Endian (PLATFORM_ENDIAN_*) */
36 #define PLATFORM_BYTES_ENDIAN           PLATFORM_ENDIAN_LITTLE
37 
38 /* When accessing data, if a boundary alignment is needed with the access width, it is 1; otherwise, it is 0. */
39 #define PLATFORM_BYTES_ALIGN            1
40 
41 /* The size of the cache line that the program needs to be aware of (1 if not needed) */
42 #define PLATFORM_CACHE_SIZE             32
43 
44 /* The modifier designated by the variable that shows cache line boundary alignment is needed (empty definition if not needed) */
45 #define PLATFORM_ATTRIBUTE_CACHEALIGN   ATTRIBUTE_ALIGN(32)
46 
47 /* Interrupt prohibition functions that can be called at the start of the block */
48 #define PLATFORM_ENTER_CRITICALSECTION()    OSIntrMode bak_interrupt_mode_ = OS_DisableInterrupts()
49 
50 /* Interrupt cancellation functions paired up with the functions above */
51 #define PLATFORM_LEAVE_CRITICALSECTION()    (void)OS_RestoreInterrupts(bak_interrupt_mode_)
52 
53 
54 /*****************************************************************************/
55 /* Processing-specific definitions */
56 
57 #if	defined(SDK_CW) || defined(SDK_RX) || defined(__MWERKS__)
58 
59 /* The order in which the bit field was filled (PLATFORM_ENDIAN_*) */
60 #define PLATFORM_BITFIELDS_ENDIAN       PLATFORM_ENDIAN_LITTLE
61 
62 /* Macro for determining validity when compiling */
63 #define PLATFORM_COMPILER_ASSERT(expr) \
64     extern void platform_compiler_assert ## __LINE__ (char is[(expr) ? +1 : -1])
65 
66 /*
67  * This modifier is explicitly specified after the closing bracket ('}') of a structure definition so that the structure is not padded with a value larger than the maximum member size.
68  *
69  */
70 #define PLATFORM_STRUCT_PADDING_FOOTER
71 
72 /* Function inline specifier */
73 #define PLATFORM_ATTRIBUTE_INLINE       SDK_INLINE
74 
75 
76 #else
77 # TO BE DEFINED
78 #endif
79 
80 
81 /*****************************************************************************/
82 /* Shared type definitions */
83 
84 /*
85  * Size-specified integer structures
86  *
87  * These are used instead of embedded types to show that unintentional, direct access of integer data exchanged through external devices or communication circuits is prohibited.
88  *
89  * Use functions such as MI_Store* to save embedded types in these structures and functions such as MI_Load* to access values from these structures.
90  *
91  */
92 
93 /* 8-bit little endian type */
94 typedef struct PLATFORM_LE8
95 {
96     unsigned char byte[1];
97 }
98 PLATFORM_STRUCT_PADDING_FOOTER PLATFORM_LE8;
99 
100 /* 16-bit little endian type */
101 typedef struct PLATFORM_LE16
102 {
103     unsigned char byte[2];
104 }
105 PLATFORM_STRUCT_PADDING_FOOTER PLATFORM_LE16;
106 
107 /* 32-bit little endian type */
108 typedef struct PLATFORM_LE32
109 {
110     unsigned char byte[4];
111 }
112 PLATFORM_STRUCT_PADDING_FOOTER PLATFORM_LE32;
113 
114 /* 8-bit big endian type */
115 typedef struct PLATFORM_BE8
116 {
117     unsigned char byte[1];
118 }
119 PLATFORM_STRUCT_PADDING_FOOTER PLATFORM_BE8;
120 
121 /* 16-bit big endian type */
122 typedef struct PLATFORM_BE16
123 {
124     unsigned char byte[2];
125 }
126 PLATFORM_STRUCT_PADDING_FOOTER PLATFORM_BE16;
127 
128 /* 32-bit big endian type */
129 typedef struct PLATFORM_BE32
130 {
131     unsigned char byte[4];
132 }
133 PLATFORM_STRUCT_PADDING_FOOTER PLATFORM_BE32;
134 
135 
136 /*****************************************************************************/
137 
138 
139 #endif /* NINTENDO_PLATFORM_HEADER__ */
140