struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / device / include / mcs51 / compiler.h
blob11a73070aaae13cd0c822d7bdfa7a81fbd6a68ad
1 /*-------------------------------------------------------------------------
2 compiler.h
4 Copyright (C) 2006, Maarten Brock, sourceforge.brock@dse.nl
5 Portions of this file are Copyright 2014 Silicon Laboratories, Inc.
6 http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt
8 This library is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
11 later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this library; see the file COPYING. If not, write to the
20 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21 MA 02110-1301, USA.
23 As a special exception, if you link this library with other files,
24 some of which are compiled with SDCC, to produce an executable,
25 this library does not by itself cause the resulting executable to
26 be covered by the GNU General Public License. This exception does
27 not however invalidate any other reasons why the executable file
28 might be covered by the GNU General Public License.
29 -------------------------------------------------------------------------*/
32 * Header file to overcome 8051 compiler differences for specifying
33 * special function registers. The following compilers are supported:
34 * SDCC, Keil, Raisonance, IAR, Hi-Tech, Tasking, Crossware, Wickenhaeuser.
35 * Unfortunately not for use with Dunfield. The compilers are identified by
36 * their unique predefined macros. See also:
37 * http://predef.sourceforge.net/precomp.html
39 * SBIT and SFR define special bit and special function registers at the given
40 * address. SFR16 and SFR32 define sfr combinations at adjacent addresses in
41 * little-endian format. SFR16E and SFR32E define sfr combinations without
42 * prerequisite byte order or adjacency. None of these multi-byte sfr
43 * combinations will guarantee the order in which they are accessed when read
44 * or written.
45 * SFR16X and SFR32X for 16 bit and 32 bit xdata registers are not defined
46 * to avoid portability issues because of compiler endianness.
47 * SFR16LEX is provided for 16 bit little endian xdata registers. It is usable
48 * on little endian compilers only; on big endian compilers, these registers
49 * will not be defined.
50 * This file is to be included in every microcontroller specific header file.
51 * Example:
53 * // my_mcu.h: sfr definitions for my mcu
54 * #include <compiler.h>
56 * SBIT (P0_1, 0x80, 1); // Port 0 pin 1
58 * SFR (P0, 0x80); // Port 0
60 * SFRX (CPUCS, 0xE600); // Cypress FX2 Control and Status register in xdata memory at 0xE600
62 * SFR16 (TMR2, 0xCC); // Timer 2, lsb at 0xCC, msb at 0xCD
64 * SFR16E(TMR0, 0x8C8A); // Timer 0, lsb at 0x8A, msb at 0x8C
66 * SFR32 (MAC0ACC, 0x93); // SiLabs C8051F120 32 bits MAC0 Accumulator, lsb at 0x93, msb at 0x96
68 * SFR32E(SUMR, 0xE5E4E3E2); // TI MSC1210 SUMR 32 bits Summation register, lsb at 0xE2, msb at 0xE5
72 #ifndef COMPILER_H
73 #define COMPILER_H
75 /** SDCC - Small Device C Compiler
76 * http://sdcc.sf.net
78 #if defined (SDCC) || defined (__SDCC)
79 # define SBIT(name, addr, bit) __sbit __at(addr+bit) name
80 # define SFR(name, addr) __sfr __at(addr) name
81 # define SFRX(name, addr) __xdata volatile unsigned char __at(addr) name
82 # define SFR16(name, addr) __sfr16 __at(((addr+1U)<<8) | addr) name
83 # define SFR16E(name, fulladdr) __sfr16 __at(fulladdr) name
84 # define SFR16LEX(name, addr) __xdata volatile unsigned short __at(addr) name
85 # define SFR32(name, addr) __sfr32 __at(((addr+3UL)<<24) | ((addr+2UL)<<16) | ((addr+1UL)<<8) | addr) name
86 # define SFR32E(name, fulladdr) __sfr32 __at(fulladdr) name
88 # define INTERRUPT(name, vector) void name (void) __interrupt (vector)
89 # define INTERRUPT_USING(name, vector, regnum) void name (void) __interrupt (vector) __using (regnum)
91 // NOP () macro support
92 #define NOP() __asm NOP __endasm
94 /** Keil C51
95 * http://www.keil.com
97 #elif defined __CX51__
98 # define SBIT(name, addr, bit) sbit name = addr^bit
99 # define SFR(name, addr) sfr name = addr
100 # define SFRX(name, addr) volatile unsigned char xdata name _at_ addr
101 # define SFR16(name, addr) sfr16 name = addr
102 # define SFR16E(name, fulladdr) /* not supported */
103 # define SFR16LEX(name, addr) /* not supported */
104 # define SFR32(name, fulladdr) /* not supported */
105 # define SFR32E(name, fulladdr) /* not supported */
107 # define INTERRUPT(name, vector) void name (void) interrupt vector
108 # define INTERRUPT_USING(name, vector, regnum) void name (void) interrupt vector using regnum
110 // NOP () macro support
111 extern void _nop_ (void);
112 #define NOP() _nop_()
114 /** Raisonance
115 * http://www.raisonance.com
117 #elif defined __RC51__
118 # define SBIT(name, addr, bit) at (addr+bit) sbit name
119 # define SFR(name, addr) sfr at addr name
120 # define SFRX(name, addr) xdata at addr volatile unsigned char name
121 # define SFR16(name, addr) sfr16 at addr name
122 # define SFR16E(name, fulladdr) /* not supported */
123 # define SFR16LEX(name, addr) /* not supported */
124 # define SFR32(name, fulladdr) /* not supported */
125 # define SFR32E(name, fulladdr) /* not supported */
127 # define INTERRUPT(name, vector) void name (void) interrupt vector
128 # define INTERRUPT_USING(name, vector, regnum) void name (void) interrupt vector using regnum
130 // NOP () macro support -- NOP is opcode 0x00
131 #define NOP() asm { 0x00 }
133 /** IAR 8051
134 * http://www.iar.com
136 #elif defined __ICC8051__
137 # define SBIT(name, addr, bit) __bit __no_init volatile bool name @ (addr+bit)
138 # define SFR(name, addr) __sfr __no_init volatile unsigned char name @ addr
139 # define SFRX(name, addr) __xdata __no_init volatile unsigned char name @ addr
140 # define SFR16(name, addr) __sfr __no_init volatile unsigned int name @ addr
141 # define SFR16E(name, fulladdr) /* not supported */
142 # define SFR16LEX(name, addr) /* not supported */
143 # define SFR32(name, fulladdr) __sfr __no_init volatile unsigned long name @ addr
144 # define SFR32E(name, fulladdr) /* not supported */
146 # define _PPTOSTR_(x) #x
147 # define _PPARAM_(address) _PPTOSTR_(vector=address * 8 + 3)
148 # define _PPARAM2_(regbank) _PPTOSTR_(register_bank=regbank)
149 # define INTERRUPT(name, vector) _Pragma(_PPARAM_(vector)) __interrupt void name(void)
150 # define INTERRUPT_USING(name, vector, regnum) _Pragma(_PPARAM2_(regnum)) _Pragma(_PPARAM_(vector)) __interrupt void name(void)
152 extern __intrinsic void __no_operation (void);
153 #define NOP() __no_operation()
155 /** Tasking / Altium
156 * http://www.altium.com/tasking
158 #elif defined _CC51
159 # define SBIT(name, addr, bit) _sfrbit name _at(addr+bit)
160 # define SFR(name, addr) _sfrbyte name _at(addr)
161 # define SFRX(name, addr) _xdat volatile unsigned char name _at(addr)
162 #if _CC51 > 71
163 # define SFR16(name, addr) _sfrword _little name _at(addr)
164 #else
165 # define SFR16(name, addr) /* not supported */
166 #endif
167 # define SFR16E(name, fulladdr) /* not supported */
168 # define SFR16LEX(name, addr) /* not supported */
169 # define SFR32(name, fulladdr) /* not supported */
170 # define SFR32E(name, fulladdr) /* not supported */
172 # define INTERRUPT(name, vector) _interrupt (vector) void name (void)
173 # define INTERRUPT_USING(name, vector, regnum) _interrupt (vector) _using(regnum) void name (void)
175 // NOP () macro support
176 extern void _nop (void);
177 #define NOP() _nop()
179 /** Hi-Tech 8051
180 * http://www.htsoft.com
182 #elif defined HI_TECH_C
183 # define SBIT(name, addr, bit) volatile bit name @ (addr+bit)
184 # define SFR(name, addr) volatile unsigned char name @ addr
185 # define SFRX(name, addr) volatile far unsigned char name @ addr
186 # define SFR16(name, addr) /* not supported */
187 # define SFR16E(name, fulladdr) /* not supported */
188 # define SFR16LEX(name, addr) /* not supported */
189 # define SFR32(name, fulladdr) /* not supported */
190 # define SFR32E(name, fulladdr) /* not supported */
192 # define INTERRUPT(name, vector) void name (void) interrupt vector
193 # define INTERRUPT_PROTO(name, vector)
195 // NOP () macro support
196 #define NOP() asm(" nop ")
198 /** Crossware
199 * http://www.crossware.com
201 #elif defined _XC51_VER
202 # define SBIT(name, addr, bit) _sfrbit name = (addr+bit)
203 # define SFR(name, addr) _sfr name = addr
204 # define SFRX(name, addr) volatile unsigned char _xdata name _at addr
205 # define SFR16(name, addr) _sfrword name = addr
206 # define SFR16E(name, fulladdr) /* not supported */
207 # define SFR16LEX(name, addr) /* not supported */
208 # define SFR32(name, fulladdr) /* not supported */
209 # define SFR32E(name, fulladdr) /* not supported */
211 /** Wickenhaeuser
212 * http://www.wickenhaeuser.de
214 #elif defined __UC__
215 # define SBIT(name, addr, bit) unsigned char bit name @ (addr+bit)
216 # define SFR(name, addr) near unsigned char name @ addr
217 # define SFRX(name, addr) xdata volatile unsigned char name @ addr
218 # define SFR16(name, addr) /* not supported */
219 # define SFR16E(name, fulladdr) /* not supported */
220 # define SFR16LEX(name, addr) /* not supported */
221 # define SFR32(name, fulladdr) /* not supported */
222 # define SFR32E(name, fulladdr) /* not supported */
224 /** default
225 * unrecognized compiler
227 #else
228 # warning unrecognized compiler
229 # define SBIT(name, addr, bit) volatile bool name
230 # define SFR(name, addr) volatile unsigned char name
231 # define SFRX(name, addr) volatile unsigned char name
232 # define SFR16(name, addr) volatile unsigned short name
233 # define SFR16E(name, fulladdr) volatile unsigned short name
234 # define SFR16LEX(name, addr) volatile unsigned short name
235 # define SFR32(name, fulladdr) volatile unsigned long name
236 # define SFR32E(name, fulladdr) volatile unsigned long name
238 #endif
240 #endif //COMPILER_H