summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/SystemEnvironment/include/types.h
blob: 16be44045dc95acc9c0e5ce7986c42264f3e8669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/************************************************************************************************//**
  \file types.h

  \brief The header file describes global system types and pre-processor words
         which depends on compiler or platform

  \author
    Atmel Corporation: http://www.atmel.com \n
    Support email: avr@atmel.com

  Copyright (c) 2008-2011, Atmel Corporation. All rights reserved.
  Licensed under Atmel's Limited License Agreement (BitCloudTM).

  \internal
*****************************************************************************************************/

#ifndef _TYPES_H
#define _TYPES_H

#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <stddef.h>
#include <bcEndian.h>

#if defined(__ICCAVR__) || defined(__ICCARM__) || defined(__ICCAVR32__)

// \cond
#if defined(AT91SAM7X256) || defined(AT91SAM3S4C)
  #include <intrinsics.h>
#elif defined(ATMEGA1281) || defined(ATMEGA2561) || defined(ATMEGA1284) || defined(AT90USB1287) \
   || defined(ATXMEGA128A1) || defined(ATXMEGA256A3) || defined(ATXMEGA256D3) || defined(ATMEGA128RFA1)
  #include <inavr.h>
  #include <ioavr.h>
  #include <intrinsics.h>
  #include <pgmspace.h>
#elif defined(AT32UC3A0512)
  #include <intrinsics.h>
#endif
// \endcond

/**
 * Some preprocessor magic to allow for a header file abstraction of
 * interrupt service routine declarations for the IAR compiler.  This
 * requires the use of the C99 _Pragma() directive (rather than the
 * old #pragma one that could not be used as a macro replacement), as
 * well as two different levels of preprocessor concetanations in
 * order to do both, assign the correct interrupt vector name, as well
 * as construct a unique function name for the ISR.
 *
 * Do *NOT* try to reorder the macros below, or you'll suddenly find
 * out about all kinds of IAR bugs...
 */
#define PRAGMA(x) _Pragma(#x)

// \cond
#if defined(AT91SAM7X256) || defined(AT91SAM3S4C)

  #define PROGMEM_DECLARE(x) x
  #define FLASH_VAR
  #define FLASH_PTR
  #define memcpy_P   memcpy
  #define hw_platform_address_size_t    uint32_t
  #define BEGIN_PACK PRAGMA(pack(push, 1))
  #define END_PACK   PRAGMA(pack(pop))
  #define INLINE static inline

#elif defined(AT32UC3A0512)

  #define PROGMEM_DECLARE(x) x
  #define FLASH_VAR
  #define FLASH_PTR
  #define memcpy_P   memcpy
  #define hw_platform_address_size_t    uint32_t
  #define BEGIN_PACK PRAGMA(pack(push, 1))
  #define END_PACK   PRAGMA(pack(pop))
  #define INLINE static inline
  #define INTERRUPT   __interrupt

#elif defined(ATMEGA1281) || defined(ATMEGA2561) || defined(ATMEGA1284) || defined(AT90USB1287) \
   || defined(ATXMEGA128A1) || defined(ATXMEGA256A3) || defined(ATXMEGA256D3) || defined(ATMEGA128RFA1)

  #ifndef __HAS_ELPM__
    #define _MEMATTR  __flash
  #else /* __HAS_ELPM__ */
    #define _MEMATTR  __farflash
  #endif /* __HAS_ELPM__ */

  #define PROGMEM_DECLARE(x) _MEMATTR x
  #define FLASH_VAR _MEMATTR
  #define FLASH_PTR _MEMATTR
  #define BEGIN_PACK
  #define END_PACK
  #define INLINE PRAGMA(inline=forced) static

  #define ASM     asm
  #define __SLEEP   __sleep()

  #if defined(ATXMEGA128A1) || defined(ATXMEGA256A3) || defined(ATXMEGA256D3)
    #define ENABLE_CHANGE_PROTECTION_REGISTER   CCP = 0xD8
  #endif

  #define ISR(vec) PRAGMA(vector=vec) __interrupt void handler_##vec(void)
  #define sei() (__enable_interrupt())
  #define cli() (__disable_interrupt())
  /** Wait until bit \c bit in IO register \c sfr is clear. */
  #define loop_until_bit_is_clear(sfr, bit) do {;} while (sfr & (1 << bit))

  #define wdt_reset() (__watchdog_reset())

  #define SF_GET_LOW_FUSES() __AddrToZByteToSPMCR_LPM((void __flash *)0x0000, 0x09)
#endif

#if defined(ATMEGA1284)
  #define EEMPE  2
  #define EEPE   1
  #define PSRASY 1
#endif

#if defined(AT90USB1287)
  #define UPE1 2
  #define USB_GEN_vect USB_General_vect
  #define USB_COM_vect USB_Endpoint_Pipe_vect
#endif

// \endcond

#define PACK
#define MAY_ALIAS
#define NOP       __no_operation()
#define nop() (__no_operation())
#define PRINTF_STYLE

#elif defined(__GNUC__)

// Leave this here until new security naming will settle
#pragma GCC poison _HIGH_SECURITY_ _USE_SKKE_ _AUTHENTICATION_ _ZCL_KE_CLUSTER_

// \cond
#if defined(AT91SAM7X256) || defined(AT91SAM3S4C)
#elif defined(X86)
#elif defined(ATMEGA1281) || defined(ATMEGA2561) || defined(ATMEGA1284) || defined(AT90USB1287) \
   || defined(ATXMEGA128A1) || defined(ATXMEGA256A3) || defined(ATXMEGA256D3) || defined(ATMEGA128RFA1)
  #include <avr/io.h>
  #include <avr/pgmspace.h>
    #if !defined(ATXMEGA128A1) && !defined(ATXMEGA256A3) && !defined(ATXMEGA256D3)
      #include <avr/boot.h>
    #endif
  #include <avr/interrupt.h>
  #include <avr/wdt.h>
#elif defined(SIMULATOR)
#endif
// \endcond

// \cond
#if defined(AT91SAM7X256) || defined(AT91SAM3S4C)

  #define PROGMEM_DECLARE(x) x
  #define FLASH_VAR
  #define FLASH_PTR
  #define memcpy_P   memcpy
  #define hw_platform_address_size_t    uint32_t
  #define BEGIN_PACK
  #define END_PACK
  #define PACK __attribute__ ((packed))

#elif defined(ATMEGA1281) || defined(ATMEGA2561) || defined(ATMEGA1284) || defined(AT90USB1287) \
   || defined(ATXMEGA128A1) || defined(ATXMEGA256A3) || defined(ATXMEGA256D3) || defined(ATMEGA128RFA1)

  #define SF_GET_LOW_FUSES() boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS)
  #define PROGMEM_DECLARE(x) x __attribute__((__progmem__))
  #define FLASH_VAR PROGMEM
  #define FLASH_PTR
  #define hw_platform_address_size_t    uint16_t
  #define BEGIN_PACK
  #define END_PACK
  #define PACK

  #define ASM     asm volatile
  #define __SLEEP   asm volatile ("sleep")
  #define UINT64_MEMCMP

  #if defined(ATXMEGA128A1) || defined(ATXMEGA256A3) || defined(ATXMEGA256D3)
    #define ENABLE_CHANGE_PROTECTION_REGISTER   CCP = 0xD8
  #endif

#elif defined(X86)
  #define PROGMEM_DECLARE(x) x
  #define FLASH_VAR
  #define FLASH_PTR
  #define memcpy_P   memcpy
  #define hw_platform_address_size_t    uint32_t
  #define BEGIN_PACK
  #define END_PACK
  #define PACK __attribute__ ((packed))

#elif defined(SIMULATOR)
  #define PROGMEM_DECLARE(x) x
  #define FLASH_VAR
  #define FLASH_PTR
  #define memcpy_P   memcpy
  #define hw_platform_address_size_t    uint32_t
  #define BEGIN_PACK
  #define END_PACK
  #define PACK __attribute__ ((packed))

#endif
// \endcond

#define INLINE static inline __attribute__ ((always_inline))
#define MAY_ALIAS __attribute__((__may_alias__))
#define NOP       asm volatile ("nop")
#define PRINTF_STYLE __attribute__ ((format (printf, 1, 2)))

#else
  #error 'Compiler not supported.'
#endif

typedef bool result_t;
typedef uint64_t BcTime_t;

BEGIN_PACK
typedef struct PACK {uint16_t val;} u16Packed_t;
typedef struct PACK {uint32_t val;} u32Packed_t;
typedef struct PACK {uint64_t val;} u64Packed_t;
typedef struct PACK {int16_t val;}  s16Packed_t;
typedef struct PACK {int32_t val;}  s32Packed_t;
typedef struct PACK {int64_t val;}  s64Packed_t;
END_PACK

#if defined __ICCAVR__ || defined __ICCARM__
  typedef uint8_t BitField_t;
#else
  typedef unsigned int BitField_t;
#endif

#define BC_SUCCESS false
#define BC_FAIL    true

#endif
// eof types.h