-
Notifications
You must be signed in to change notification settings - Fork 7
/
ch554_platform.h
158 lines (125 loc) · 3.75 KB
/
ch554_platform.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
#ifndef __PLATFORM
#define __PLATFORM
#if defined (SDCC) || defined (__SDCC)
#ifndef __SDCC
#define __SDCC
#endif
// Use GCC defined standard types
#include <stdint.h>
// SDCC is little-endian
#define __LITTLE_ENDIAN
// Define Keil C51 specified derivatives
#define xdata __xdata
#define idata __idata
#define code __code
#define interrupt __interrupt
#define xdatabuf(addr, name, sz) __xdata __at(addr) uint8_t name[sz]
#define extern_xdatabuf(addr, name) extern __xdata __at(addr) uint8_t name[]
#elif defined (__C51__) || defined (__CX51__)
#ifndef __C51__
#define __C51__
#endif
// Define standard types
#ifndef bool
typedef bit bool;
#endif
#ifndef uint8_t
typedef unsigned char uint8_t;
#endif
#ifndef int8_t
typedef signed char int8_t;
#endif
#ifndef uint16_t
typedef unsigned short uint16_t;
#endif
#ifndef int16_t
typedef signed short int16_t;
#endif
#ifndef uint32_t
typedef unsigned long uint32_t;
#endif
#ifndef int32_t
typedef signed long int32_t;
#endif
// Keil C51 is big-endian
#define __BIG_ENDIAN
// SDCC style SBIT
#define SBIT(var, port, pin) sbit var = port^pin
#define xdatabuf(addr, name, sz) xdata uint8_t name[sz] _at_ addr
#define extern_xdatabuf(addr, name) extern xdata uint8_t name[]
#else
#error "Unsupported compiler!"
#endif
#if defined __BIG_ENDIAN
// uint16_t
#define U16B0(u) (((uint8_t*)&u)[1])
#define U16B1(u) (((uint8_t*)&u)[0])
// uint32_t
#define U32B0(u) (((uint8_t*)&u)[3])
#define U32B1(u) (((uint8_t*)&u)[2])
#define U32B2(u) (((uint8_t*)&u)[1])
#define U32B3(u) (((uint8_t*)&u)[0])
#define U16_XBig(dstAddr, srcAddr) { \
((uint8_t*)dstAddr)[0] = ((uint8_t*)srcAddr)[0]; \
((uint8_t*)dstAddr)[1] = ((uint8_t*)srcAddr)[1]; \
}
#define U16_XLittle(dstAddr, srcAddr) { \
((uint8_t*)dstAddr)[0] = ((uint8_t*)srcAddr)[1]; \
((uint8_t*)dstAddr)[1] = ((uint8_t*)srcAddr)[0]; \
}
#define U32_XBig(dstAddr, srcAddr) { \
((uint8_t*)dstAddr)[0] = ((uint8_t*)srcAddr)[0]; \
((uint8_t*)dstAddr)[1] = ((uint8_t*)srcAddr)[1]; \
((uint8_t*)dstAddr)[2] = ((uint8_t*)srcAddr)[2]; \
((uint8_t*)dstAddr)[3] = ((uint8_t*)srcAddr)[3]; \
}
#define U32_XLittle(dstAddr, srcAddr) { \
((uint8_t*)dstAddr)[0] = ((uint8_t*)srcAddr)[3]; \
((uint8_t*)dstAddr)[1] = ((uint8_t*)srcAddr)[2]; \
((uint8_t*)dstAddr)[2] = ((uint8_t*)srcAddr)[1]; \
((uint8_t*)dstAddr)[3] = ((uint8_t*)srcAddr)[0]; \
}
#elif defined __LITTLE_ENDIAN
// uint16_t
#define U16B0(u) (((uint8_t*)&u)[0])
#define U16B1(u) (((uint8_t*)&u)[1])
// uint32_t
#define U32B0(u) (((uint8_t*)&u)[0])
#define U32B1(u) (((uint8_t*)&u)[1])
#define U32B2(u) (((uint8_t*)&u)[2])
#define U32B3(u) (((uint8_t*)&u)[3])
#define U16_XBig(dstAddr, srcAddr) { \
((uint8_t*)dstAddr)[0] = ((uint8_t*)srcAddr)[1]; \
((uint8_t*)dstAddr)[1] = ((uint8_t*)srcAddr)[0]; \
}
#define U16_XLittle(dstAddr, srcAddr) { \
((uint8_t*)dstAddr)[0] = ((uint8_t*)srcAddr)[0]; \
((uint8_t*)dstAddr)[1] = ((uint8_t*)srcAddr)[1]; \
}
#define U32_XBig(dstAddr, srcAddr) { \
((uint8_t*)dstAddr)[0] = ((uint8_t*)srcAddr)[3]; \
((uint8_t*)dstAddr)[1] = ((uint8_t*)srcAddr)[2]; \
((uint8_t*)dstAddr)[2] = ((uint8_t*)srcAddr)[1]; \
((uint8_t*)dstAddr)[3] = ((uint8_t*)srcAddr)[0]; \
}
#define U32_XLittle(dstAddr, srcAddr) { \
((uint8_t*)dstAddr)[0] = ((uint8_t*)srcAddr)[0]; \
((uint8_t*)dstAddr)[1] = ((uint8_t*)srcAddr)[1]; \
((uint8_t*)dstAddr)[2] = ((uint8_t*)srcAddr)[2]; \
((uint8_t*)dstAddr)[3] = ((uint8_t*)srcAddr)[3]; \
}
#else
#error "Little-Endian or Big-Endian?"
#endif
#endif // __PLATFORM
#define GPIO1 0x90
#define GPIO2 0xA0
#define GPIO3 0xB0
#include "ch554_conf.H"
#ifdef __SDCC
#include "include\ch554.h"
#include "include\ch554_usb.h"
#endif
#ifdef __C51__
#include "keilc51\ch554.h"
#endif