-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path259macros.h
280 lines (201 loc) · 5.92 KB
/
259macros.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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/************* 259macros.h ***************/
/*
* Version 4.00 March 8, 2011
*
*
*/
// some useful macros
#define max(a,b) (((a)<(b))?(b):(a))
#define min(a,b) (((a)<(b))?(a):(b))
// //////////////////////////////////////////////////////////////////////////
//
//
// Global constant declarations for all I/O addresses
//
//
// Example usage:
//
// volatile int *pLEDR = ADDR_LEDR;
// *pLEDR = 0x8F;
//
// int switch = *pSWITCH;
// switch = switch & 0x04; // isolate SW2
//
//
#define ADDR_LEDR 0x10000000 /* output only, RED (DE1 10b, DE2 18b) */
#define ADDR_LEDG 0x10000010 /* output only, GREEN (DE1 8b, DE2 9b) */
#define ADDR_HEX7SEG 0x10000020 /* output only, HEX3 to HEX0 (32b) */
#define ADDR_HEX7SEGA 0x10000020 /* output only, HEX3 to HEX0 (32b) */
#define ADDR_HEX7SEGB 0x10000030 /* output only, HEX7 to HEX4 (32b), DE2 only */
#define ADDR_SWITCH 0x10000040 /* input only, (DE1 10b, DE2 18b) */
#define ADDR_KEY 0x10000050 /* input only, KEY3 to KEY0 (4b) */
#define ADDR_GPIO0 0x10000060 /* I/O connections to connector GPIO0 */
#define ADDR_GPIO1 0x10000070 /* I/O connections to connector GPIO1 */
#define ADDR_COUNTER 0x10000080 /* input only, 50 MHz counter (32b) */
#define ADDR_PS2 0x10000100 /* in/out, PS2 connector for kb and mouse (8b data) */
#define ADDR_JTAG 0x10001000 /* send/recv chars to Terminal window */
#define ADDR_RS232 0x10001010 /* send/recv chars to RS232 terminal */
#define ADDR_TIMER 0x10002000 /* timer controller */
#define ADDR_SYSID 0x10002020 /* unique systemID */
#define ADDR_AVCONFIG 0x10003000 /* configure audio and vga */
#define ADDR_AUDIO 0x10003040 /* audio registers */
#define ADDR_VGA 0x08000000 /* vga pixel framebuffer */
#define ADDR_CHARBUF 0x09000000 /* vga character framebuffer */
#define ADDR_SDRAM 0x00000000 /* SDRAM chip, 8MB */
#define ADDR_SDRAM_END 0x00800000
#define ADDR_SRAM 0x08000000 /* SRAM chip, 512kB, also used for vga pixel framebuffer */
#define ADDR_SRAM_END 0x08080000
// Global variable declarations
extern volatile unsigned int *pLEDR;
extern volatile unsigned int *pLEDG;
extern volatile unsigned int *pSWITCH;
extern volatile unsigned int *pKEY;
extern volatile unsigned int *pHEX7SEG;
extern volatile unsigned int *pHEX7SEGA;
extern volatile unsigned int *pHEX7SEGB;
extern volatile unsigned int *pCOUNTER;
extern volatile unsigned int *pPS2;
extern volatile unsigned int *pSNDCTL;
extern volatile unsigned int *pSNDRDY;
extern volatile unsigned int *pSNDL;
extern volatile unsigned int *pSNDR;
extern volatile unsigned int *pTERMINAL;
extern volatile unsigned int *pTERMINALCTL;
extern volatile unsigned int *pRS232;
extern volatile unsigned int *pRS232CTL;
extern volatile unsigned int *pAVCONFIG;
extern volatile unsigned int *pSNDCONFIG;
extern volatile unsigned int *pGPIO0;
extern unsigned int last_counter_value;
// //////////////////////////////////////////////////////////////////////////
//
//
// HEX 7 SEGMENT display
//
//
// Write "0" to a bit to turn "off" a 7-segment display LED.
// Each bit position at address ADDR_HEX7SEG works as follows:
// HEX3 HEX2 HEX1 HEX0
// 24 16 8 0
// ---- ---- ---- ----
// 29| |25 21| |17 13| |9 5| |1
// | 30 | | 22 | | 14 | | 6 |
// ---- ---- ---- ----
// | | | | | | | |
// 28| |26 20| |18 12| |10 4| |2
// ---- ---- ---- ----
// 27 19 11 3
// Note that bits 31, 23, 15, and 7 are not used.
//
#define DIGIT_ 0x00 /* blank space */
#define DIGIT0 0x3F /* 0xC0 */
#define DIGIT1 0x06 /* 0xF9 */
#define DIGIT2 0x5B /* 0xA4 */
#define DIGIT3 0x4F /* 0xB0 */
#define DIGIT4 0x66 /* 0x99 */
#define DIGIT5 0x6D /* 0x92 */
#define DIGIT6 0x7D /* 0x82 */
#define DIGIT7 0x07 /* 0xF8 */
#define DIGIT8 0x7F /* 0x80 */
#define DIGIT9 0x67 /* 0x98 */
#define DIGITA 0x77 /* 0x88 */
#define DIGITB 0x7C /* 0x83 */
#define DIGITC 0x39 /* 0xC6 */
#define DIGITD 0x5E /* 0xA1 */
#define DIGITE 0x79 /* 0x86 */
#define DIGITF 0x71 /* 0x8E */
// //////////////////////////////////////////////////////////////////////////
//
//
// VGA or LCD frame buffer core
//
//
#define MAX_X_PIXELS 320
#define MAX_Y_PIXELS 240
#define MAX_X_BITS 9 /* CEIL(LOG2(MAX_X_PIXELS)) */
#define MAX_Y_BITS 8 /* CEIL(LOG2(MAX_Y_PIXELS)) */
#define MAX_X_CHARS 40
#define MAX_Y_CHARS 30
#define MAX_X_CHAR_BITS 6 /* CEIL(LOG2(MAX_X_CHARS)) */
#define MAX_Y_CHAR_BITS 5 /* CEIL(LOG2(MAX_Y_CHARS)) */
void
initChars();
void
initScreen();
void
fillScreen( unsigned short colour );
void
drawPixel( int x, int y, unsigned short colour );
unsigned short
makeColour( int r, int g, int b );
unsigned short *
getPixelAddr( int x, int y );
void
drawChar( int x, int y, int character );
unsigned char *
getCharAddr( int x, int y );
// //////////////////////////////////////////////////////////////////////////
//
//
// RS232 core
//
//
unsigned int
getRS2332_nowait();
int
getcharRS232();
void
putcharRS232( int c );
void
flushRS232();
// //////////////////////////////////////////////////////////////////////////
//
//
// JTAG core
//
//
unsigned int
getJTAG_nowait();
int
getcharJTAG();
void
putcharJTAG( int c );
void
printstringJTAG( char *psz );
void
printbyteJTAG( int c );
// //////////////////////////////////////////////////////////////////////////
//
//
// PS2 core
//
//
#define PS2_ERROR 0
#define PS2_MOUSE 1
#define PS2_KB 2
#define MOUSE_BUTTON1 0x01
#define MOUSE_BUTTON2 0x04
#define MOUSE_BUTTON3 0x02
unsigned int
getPS2_nowait();
int
getcharPS2();
void
putcharPS2( int c );
void
flushPS2();
int
resetPS2();
int
getMouseMotion( int *pdx, int *pdy, int *pbuttons );
int
getMouseMotion_nowait( int *pdx, int *pdy, int *pbuttons );
// //////////////////////////////////////////////////////////////////////////
//
//
// 50 MHz Counter core
//
//
#define ONE_MS 50000
void
timedDelay( int delay_amount );