-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysTypes.h
165 lines (131 loc) · 4.6 KB
/
sysTypes.h
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
#include "config.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* \file sysTypes.h
*
* \brief System types and definitions
*
* Copyright (C) 2012-2014, Atmel Corporation. All rights reserved.
*
* \asf_license_start
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name of Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an
* Atmel microcontroller product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* \asf_license_stop
*
* $Id: sysTypes.h 9177 2014-02-06 21:06:25Z ataradov $
*
*/
#ifndef _SYS_TYPES_H_
#define _SYS_TYPES_H_
#include <stdint.h>
#define SYS_LW_MESH_ENV
#if defined(__ICCAVR__)
#include <inavr.h>
#include <ioavr.h>
#include <intrinsics.h>
#include <pgmspace.h>
#define SYS_MCU_ARCH_AVR
#define PACK
#define PRAGMA(x) _Pragma(#x)
#define INLINE PRAGMA(inline=forced) static
#define SYS_EnableInterrupts() __enable_interrupt()
#define wdt_reset() (__watchdog_reset())
#define wdt_enable(timeout) do { \
uint8_t __atomic = SREG; __disable_interrupt(); \
__watchdog_reset(); \
WDTCSR |= (1 << WDCE) | (1 << WDE); \
WDTCSR = (1 << WDE) | timeout; \
SREG = __atomic; \
} while (0)
#define wdt_disable() do { \
MCUSR = 0; \
WDTCSR |= (1 << WDCE) | (1 << WDE); \
WDTCSR = 0x00; \
} while (0)
#define ISR(vec) PRAGMA(vector=vec) __interrupt void handler_##vec(void)
#define ATOMIC_SECTION_ENTER { uint8_t __atomic = SREG; __disable_interrupt();
#define ATOMIC_SECTION_LEAVE SREG = __atomic; }
/*
#elif defined(__ICCARM__)
#error Unsupported compiler
#elif defined(__ICCAVR32__)
#error Unsupported compiler
*/
#else
#if defined(HAL_ATSAMD20J18)
#define DONT_USE_CMSIS_INIT
#include "samd20j18.h"
#define SYS_MCU_ARCH_CORTEX_M
#else // All AVRs
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#define SYS_MCU_ARCH_AVR
#endif
#if defined(SYS_MCU_ARCH_CORTEX_M)
#define PRAGMA(x)
#define PACK __attribute__ ((packed))
#define INLINE static inline __attribute__ ((always_inline))
#define SYS_EnableInterrupts() __asm volatile ("cpsie i");
#define ATOMIC_SECTION_ENTER { register uint32_t __atomic; \
__asm volatile ("mrs %0, primask" : "=r" (__atomic) ); \
__asm volatile ("cpsid i");
#define ATOMIC_SECTION_LEAVE __asm volatile ("msr primask, %0" : : "r" (__atomic) ); }
#elif defined(SYS_MCU_ARCH_AVR)
#define PRAGMA(x)
#define PACK __attribute__ ((packed))
#define INLINE static inline __attribute__ ((always_inline))
#define SYS_EnableInterrupts() sei()
#define ATOMIC_SECTION_ENTER { uint8_t __atomic = SREG; cli();
#define ATOMIC_SECTION_LEAVE SREG = __atomic; }
#endif
#endif
#if defined(HAL_ATMEGA1281)
#define SYS_DEVICE_SIZE 131072
#define SYS_PAGE_SIZE 256
#define SYS_BOOTLOADER_SIZE 2048
#elif defined(HAL_ATMEGA128RFA1)
#define SYS_DEVICE_SIZE 131072
#define SYS_PAGE_SIZE 256
#define SYS_BOOTLOADER_SIZE 2048
#elif defined(HAL_ATMEGA256RFR2)
#elif defined(HAL_ATXMEGA128B1)
#elif defined(HAL_ATXMEGA256A3U)
#elif defined(HAL_ATSAMD20J18)
#else
#error Unknown HAL
#endif
#endif // _SYS_TYPES_H_
#ifdef __cplusplus
}
#endif