-
Notifications
You must be signed in to change notification settings - Fork 11
/
compiler.h
186 lines (167 loc) · 7.68 KB
/
compiler.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*-------------------------------------------------------------------------
compiler.h
Copyright (C) 2006, Maarten Brock, [email protected]
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
As a special exception, if you link this library with other files,
some of which are compiled with SDCC, to produce an executable,
this library does not by itself cause the resulting executable to
be covered by the GNU General Public License. This exception does
not however invalidate any other reasons why the executable file
might be covered by the GNU General Public License.
-------------------------------------------------------------------------*/
/*
* Header file to overcome 8051 compiler differences for specifying
* special function registers. The following compilers are supported:
* SDCC, Keil, Raisonance, IAR, Hi-Tech, Tasking, Crossware, Wickenhaeuser.
* Unfortunately not for use with Dunfield. The compilers are identified by
* their unique predefined macros. See also:
* http://predef.sourceforge.net/precomp.html
*
* SBIT and SFR define special bit and special function registers at the given
* address. SFR16 and SFR32 define sfr combinations at adjacent addresses in
* little-endian format. SFR16E and SFR32E define sfr combinations without
* prerequisite byte order or adjacency. None of these multi-byte sfr
* combinations will guarantee the order in which they are accessed when read
* or written.
* SFR16X and SFR32X for 16 bit and 32 bit xdata registers are not defined
* to avoid portability issues because of compiler endianness.
* This file is to be included in every microcontroller specific header file.
* Example:
*
* // my_mcu.h: sfr definitions for my mcu
* #include <compiler.h>
*
* SBIT (P0_1, 0x80, 1); // Port 0 pin 1
*
* SFR (P0, 0x80); // Port 0
*
* SFRX (CPUCS, 0xE600); // Cypress FX2 Control and Status register in xdata memory at 0xE600
*
* SFR16 (TMR2, 0xCC); // Timer 2, lsb at 0xCC, msb at 0xCD
*
* SFR16E(TMR0, 0x8C8A); // Timer 0, lsb at 0x8A, msb at 0x8C
*
* SFR32 (MAC0ACC, 0x93); // SiLabs C8051F120 32 bits MAC0 Accumulator, lsb at 0x93, msb at 0x96
*
* SFR32E(SUMR, 0xE5E4E3E2); // TI MSC1210 SUMR 32 bits Summation register, lsb at 0xE2, msb at 0xE5
*
*/
#ifndef COMPILER_H
#define COMPILER_H
/** SDCC - Small Device C Compiler
* http://sdcc.sf.net
*/
#if defined (SDCC) || defined (__SDCC)
# define SBIT(name, addr, bit) __sbit __at(addr+bit) name
# define SFR(name, addr) __sfr __at(addr) name
# define SFRX(name, addr) __xdata volatile unsigned char __at(addr) name
# define SFR16(name, addr) __sfr16 __at(((addr+1U)<<8) | addr) name
# define SFR16E(name, fulladdr) __sfr16 __at(fulladdr) name
# define SFR32(name, addr) __sfr32 __at(((addr+3UL)<<24) | ((addr+2UL)<<16) | ((addr+1UL)<<8) | addr) name
# define SFR32E(name, fulladdr) __sfr32 __at(fulladdr) name
/** Keil C51
* http://www.keil.com
*/
#elif defined __CX51__
# define SBIT(name, addr, bit) sbit name = addr^bit
# define SFR(name, addr) sfr name = addr
# define SFRX(name, addr) volatile unsigned char xdata name _at_ addr
# define SFR16(name, addr) sfr16 name = addr
# define SFR16E(name, fulladdr) /* not supported */
# define SFR32(name, fulladdr) /* not supported */
# define SFR32E(name, fulladdr) /* not supported */
/** Raisonance
* http://www.raisonance.com
*/
#elif defined __RC51__
# define SBIT(name, addr, bit) at (addr+bit) sbit name
# define SFR(name, addr) sfr at addr name
# define SFRX(name, addr) xdata at addr volatile unsigned char name
# define SFR16(name, addr) sfr16 at addr name
# define SFR16E(name, fulladdr) /* not supported */
# define SFR32(name, fulladdr) /* not supported */
# define SFR32E(name, fulladdr) /* not supported */
/** IAR 8051
* http://www.iar.com
*/
#elif defined __ICC8051__
# define SBIT(name, addr, bit) __bit __no_init volatile bool name @ (addr+bit)
# define SFR(name, addr) __sfr __no_init volatile unsigned char name @ addr
# define SFRX(name, addr) __xdata __no_init volatile unsigned char name @ addr
# define SFR16(name, addr) __sfr __no_init volatile unsigned int name @ addr
# define SFR16E(name, fulladdr) /* not supported */
# define SFR32(name, fulladdr) __sfr __no_init volatile unsigned long name @ addr
# define SFR32E(name, fulladdr) /* not supported */
/** Tasking / Altium
* http://www.altium.com/tasking
*/
#elif defined _CC51
# define SBIT(name, addr, bit) _sfrbit name _at(addr+bit)
# define SFR(name, addr) _sfrbyte name _at(addr)
# define SFRX(name, addr) _xdat volatile unsigned char name _at(addr)
#if _CC51 > 71
# define SFR16(name, addr) _sfrword _little name _at(addr)
#else
# define SFR16(name, addr) /* not supported */
#endif
# define SFR16E(name, fulladdr) /* not supported */
# define SFR32(name, fulladdr) /* not supported */
# define SFR32E(name, fulladdr) /* not supported */
/** Hi-Tech 8051
* http://www.htsoft.com
*/
#elif defined HI_TECH_C
# define SBIT(name, addr, bit) volatile bit name @ (addr+bit)
# define SFR(name, addr) volatile unsigned char name @ addr
# define SFRX(name, addr) volatile far unsigned char name @ addr
# define SFR16(name, addr) /* not supported */
# define SFR16E(name, fulladdr) /* not supported */
# define SFR32(name, fulladdr) /* not supported */
# define SFR32E(name, fulladdr) /* not supported */
/** Crossware
* http://www.crossware.com
*/
#elif defined _XC51_VER
# define SBIT(name, addr, bit) _sfrbit name = (addr+bit)
# define SFR(name, addr) _sfr name = addr
# define SFRX(name, addr) volatile unsigned char _xdata name _at addr
# define SFR16(name, addr) _sfrword name = addr
# define SFR16E(name, fulladdr) /* not supported */
# define SFR32(name, fulladdr) /* not supported */
# define SFR32E(name, fulladdr) /* not supported */
/** Wickenhaeuser
* http://www.wickenhaeuser.de
*/
#elif defined __UC__
# define SBIT(name, addr, bit) unsigned char bit name @ (addr+bit)
# define SFR(name, addr) near unsigned char name @ addr
# define SFRX(name, addr) xdata volatile unsigned char name @ addr
# define SFR16(name, addr) /* not supported */
# define SFR16E(name, fulladdr) /* not supported */
# define SFR32(name, fulladdr) /* not supported */
# define SFR32E(name, fulladdr) /* not supported */
/** default
* unrecognized compiler
*/
#else
# warning unrecognized compiler
# define SBIT(name, addr, bit) volatile unsigned char name
# define SFR(name, addr) volatile unsigned char name
# define SFRX(name, addr) volatile unsigned char name
# define SFR16(name, addr) volatile unsigned short name
# define SFR16E(name, fulladdr) volatile unsigned short name
# define SFR32(name, fulladdr) volatile unsigned long name
# define SFR32E(name, fulladdr) volatile unsigned long name
#endif
#endif //COMPILER_H