-
Notifications
You must be signed in to change notification settings - Fork 0
/
Constants.cs
418 lines (389 loc) · 16.5 KB
/
Constants.cs
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
using System;
using System.Collections.Generic;
using System.Text;
namespace PICkit2V2
{
public class Constants
{
// APPLICATION VERSION
public const string AppVersion = "2.61.01";
public const byte DevFileCompatLevel = 6;
public const byte DevFileCompatLevelMin = 0;
public const string UserGuideFileName = "\\PICkit2 User Guide 51553E.pdf";
// min firmware version
public const byte FWVerMajorReq = 2;
public const byte FWVerMinorReq = 32;
public const byte FWVerDotReq = 0;
public const string FWFileName = "PK2V023200.hex";
public const uint PACKET_SIZE = 65; // 64 + leading 0
public const uint USB_REPORTLENGTH = 64;
//
public const byte BIT_MASK_0 = 0x01;
public const byte BIT_MASK_1 = 0x02;
public const byte BIT_MASK_2 = 0x04;
public const byte BIT_MASK_3 = 0x08;
public const byte BIT_MASK_4 = 0x10;
public const byte BIT_MASK_5 = 0x20;
public const byte BIT_MASK_6 = 0x40;
public const byte BIT_MASK_7 = 0x80;
//
public const ushort MChipVendorID = 0x04D8;
public const ushort Pk2DeviceID = 0x0033;
//
public const ushort ConfigRows = 2;
public const ushort ConfigColumns = 4;
public const ushort MaxReadCfgMasks = 8;
public const ushort NumConfigMasks = 9;
//
public enum PICkit2USB
{
found, // implies firmware version is good.
notFound,
writeError,
readError,
firmwareInvalid,
bootloader
};
public enum PICkit2PWR
{
no_response,
vdd_on,
vdd_off,
vdderror,
vpperror,
vddvpperrors,
selfpowered,
unpowered
};
public enum FileRead
{
success,
failed,
noconfig,
partialcfg,
largemem
};
public enum StatusColor
{
normal,
green,
yellow,
red
};
public enum VddTargetSelect
{
auto,
pickit2,
target
};
public const float VddThresholdForSelfPoweredTarget = 2.3F;
public const bool NoMessage = false;
public const bool ShowMessage = true;
public const bool UpdateMemoryDisplays = true;
public const bool DontUpdateMemDisplays = false;
public const bool EraseEE = true;
public const bool WriteEE = false;
//
public const int UploadBufferSize = 128;
public const int DownLoadBufferSize = 256;
//
public const byte READFWFLASH = 1;
public const byte WRITEFWFLASH = 2;
public const byte ERASEFWFLASH = 3;
public const byte READFWEEDATA = 4;
public const byte WRITEFWEEDATA = 5;
public const byte RESETFWDEVICE = 0xFF;
//
public const byte ENTER_BOOTLOADER = 0x42;
public const byte NO_OPERATION = 0x5A;
public const byte FIRMWARE_VERSION = 0x76;
public const byte SETVDD = 0xA0;
public const byte SETVPP = 0xA1;
public const byte READ_STATUS = 0xA2;
public const byte READ_VOLTAGES = 0xA3;
public const byte DOWNLOAD_SCRIPT = 0xA4;
public const byte RUN_SCRIPT = 0xA5;
public const byte EXECUTE_SCRIPT = 0xA6;
public const byte CLR_DOWNLOAD_BUFFER = 0xA7;
public const byte DOWNLOAD_DATA = 0xA8;
public const byte CLR_UPLOAD_BUFFER = 0xA9;
public const byte UPLOAD_DATA = 0xAA;
public const byte CLR_SCRIPT_BUFFER = 0xAB;
public const byte UPLOAD_DATA_NOLEN = 0xAC;
public const byte END_OF_BUFFER = 0xAD;
public const byte RESET = 0xAE;
public const byte SCRIPT_BUFFER_CHKSUM = 0xAF;
public const byte SET_VOLTAGE_CALS = 0xB0;
public const byte WR_INTERNAL_EE = 0xB1;
public const byte RD_INTERNAL_EE = 0xB2;
public const byte ENTER_UART_MODE = 0xB3;
public const byte EXIT_UART_MODE = 0xB4;
public const byte ENTER_LEARN_MODE = 0xB5;
public const byte EXIT_LEARN_MODE = 0xB6;
public const byte ENABLE_PK2GO_MODE = 0xB7;
public const byte LOGIC_ANALYZER_GO = 0xB8;
public const byte COPY_RAM_UPLOAD = 0xB9;
// META COMMANDS
public const byte MC_READ_OSCCAL = 0x80;
public const byte MC_WRITE_OSCCAL = 0x81;
public const byte MC_START_CHECKSUM = 0x82;
public const byte MC_VERIFY_CHECKSUM = 0x83;
public const byte MC_CHECK_DEVICE_ID = 0x84;
public const byte MC_READ_BANDGAP = 0x85;
public const byte MC_WRITE_CFG_BANDGAP = 0x86;
public const byte MC_CHANGE_CHKSM_FRMT = 0x87;
//
public const byte _VDD_ON = 0xFF;
public const byte _VDD_OFF = 0xFE;
public const byte _VDD_GND_ON = 0xFD;
public const byte _VDD_GND_OFF = 0xFC;
public const byte _VPP_ON = 0xFB;
public const byte _VPP_OFF = 0xFA;
public const byte _VPP_PWM_ON = 0xF9;
public const byte _VPP_PWM_OFF = 0xF8;
public const byte _MCLR_GND_ON = 0xF7;
public const byte _MCLR_GND_OFF = 0xF6;
public const byte _BUSY_LED_ON = 0xF5;
public const byte _BUSY_LED_OFF = 0xF4;
public const byte _SET_ICSP_PINS = 0xF3;
public const byte _WRITE_BYTE_LITERAL = 0xF2;
public const byte _WRITE_BYTE_BUFFER = 0xF1;
public const byte _READ_BYTE_BUFFER = 0xF0;
public const byte _READ_BYTE = 0xEF;
public const byte _WRITE_BITS_LITERAL = 0xEE;
public const byte _WRITE_BITS_BUFFER = 0xED;
public const byte _READ_BITS_BUFFER = 0xEC;
public const byte _READ_BITS = 0xEB;
public const byte _SET_ICSP_SPEED = 0xEA;
public const byte _LOOP = 0xE9;
public const byte _DELAY_LONG = 0xE8;
public const byte _DELAY_SHORT = 0xE7;
public const byte _IF_EQ_GOTO = 0xE6;
public const byte _IF_GT_GOTO = 0xE5;
public const byte _GOTO_INDEX = 0xE4;
public const byte _EXIT_SCRIPT = 0xE3;
public const byte _PEEK_SFR = 0xE2;
public const byte _POKE_SFR = 0xE1;
public const byte _ICDSLAVE_RX = 0xE0;
public const byte _ICDSLAVE_TX_LIT = 0xDF;
public const byte _ICDSLAVE_TX_BUF = 0xDE;
public const byte _LOOPBUFFER = 0xDD;
public const byte _ICSP_STATES_BUFFER = 0xDC;
public const byte _POP_DOWNLOAD = 0xDB;
public const byte _COREINST18 = 0xDA;
public const byte _COREINST24 = 0xD9;
public const byte _NOP24 = 0xD8;
public const byte _VISI24 = 0xD7;
public const byte _RD2_BYTE_BUFFER = 0xD6;
public const byte _RD2_BITS_BUFFER = 0xD5;
public const byte _WRITE_BUFWORD_W = 0xD4;
public const byte _WRITE_BUFBYTE_W = 0xD3;
public const byte _CONST_WRITE_DL = 0xD2;
public const byte _WRITE_BITS_LIT_HLD = 0xD1;
public const byte _WRITE_BITS_BUF_HLD = 0xD0;
public const byte _SET_AUX = 0xCF;
public const byte _AUX_STATE_BUFFER = 0xCE;
public const byte _I2C_START = 0xCD;
public const byte _I2C_STOP = 0xCC;
public const byte _I2C_WR_BYTE_LIT = 0xCB;
public const byte _I2C_WR_BYTE_BUF = 0xCA;
public const byte _I2C_RD_BYTE_ACK = 0xC9;
public const byte _I2C_RD_BYTE_NACK = 0xC8;
public const byte _SPI_WR_BYTE_LIT = 0xC7;
public const byte _SPI_WR_BYTE_BUF = 0xC6;
public const byte _SPI_RD_BYTE_BUF = 0xC5;
public const byte _SPI_RDWR_BYTE_LIT = 0xC4;
public const byte _SPI_RDWR_BYTE_BUF = 0xC3;
public const byte _ICDSLAVE_RX_BL = 0xC2;
public const byte _ICDSLAVE_TX_LIT_BL = 0xC1;
public const byte _ICDSLAVE_TX_BUF_BL = 0xC0;
public const byte _MEASURE_PULSE = 0xBF;
public const byte _UNIO_TX = 0xBE;
public const byte _UNIO_TX_RX = 0xBD;
public const byte _JT2_SETMODE = 0xBC;
public const byte _JT2_SENDCMD = 0xBB;
public const byte _JT2_XFERDATA8_LIT = 0xBA;
public const byte _JT2_XFERDATA32_LIT = 0xB9;
public const byte _JT2_XFRFASTDAT_LIT = 0xB8;
public const byte _JT2_XFRFASTDAT_BUF = 0xB7;
public const byte _JT2_XFERINST_BUF = 0xB6;
public const byte _JT2_GET_PE_RESP = 0xB5;
public const byte _JT2_WAIT_PE_RESP = 0xB4;
//
public const int SEARCH_ALL_FAMILIES = 0xFFFFFF;
//
// Script Buffer Reserved Locations
public const byte PROG_ENTRY = 0;
public const byte PROG_EXIT = 1;
public const byte RD_DEVID = 2;
public const byte PROGMEM_RD = 3;
public const byte ERASE_CHIP_PREP = 4;
public const byte PROGMEM_ADDRSET = 5;
public const byte PROGMEM_WR_PREP = 6;
public const byte PROGMEM_WR = 7;
public const byte EE_RD_PREP = 8;
public const byte EE_RD = 9;
public const byte EE_WR_PREP = 10;
public const byte EE_WR = 11;
public const byte CONFIG_RD_PREP = 12;
public const byte CONFIG_RD = 13;
public const byte CONFIG_WR_PREP = 14;
public const byte CONFIG_WR = 15;
public const byte USERID_RD_PREP = 16;
public const byte USERID_RD = 17;
public const byte USERID_WR_PREP = 18;
public const byte USERID_WR = 19;
public const byte OSSCAL_RD = 20;
public const byte OSSCAL_WR = 21;
public const byte ERASE_CHIP = 22;
public const byte ERASE_PROGMEM = 23;
public const byte ERASE_EE = 24;
//public const byte ERASE_CONFIG = 25;
public const byte ROW_ERASE = 26;
public const byte TESTMEM_RD = 27;
public const byte EEROW_ERASE = 28;
// OSCCAL valid mask in config masks
public const int OSCCAL_MASK = 7;
// EEPROM config words
public const int PROTOCOL_CFG = 0;
public const int ADR_MASK_CFG = 1;
public const int ADR_BITS_CFG = 2;
public const int CS_PINS_CFG = 3;
// EEPROM Protocols
public const int I2C_BUS = 1;
public const int SPI_BUS = 2;
public const int MICROWIRE_BUS = 3;
public const int UNIO_BUS = 4;
public const bool READ_BIT = true;
public const bool WRITE_BIT = false;
// for user32.dll window flashing
//Stop flashing. The system restores the window to its original state.
public const UInt32 FLASHW_STOP = 0;
//Flash the window caption.
public const UInt32 FLASHW_CAPTION = 1;
//Flash the taskbar button.
public const UInt32 FLASHW_TRAY = 2;
//Flash both the window caption and taskbar button.
//This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
public const UInt32 FLASHW_ALL = 3;
//Flash continuously, until the FLASHW_STOP flag is set.
public const UInt32 FLASHW_TIMER = 4;
//Flash continuously until the window comes to the foreground.
public const UInt32 FLASHW_TIMERNOFG = 12;
// PICkit 2 internal EEPROM Locations
public const byte ADC_CAL_L = 0x00;
public const byte ADC_CAL_H = 0x01;
public const byte CPP_OFFSET = 0x02;
public const byte CPP_CAL = 0x03;
public const byte UNIT_ID = 0xF0; //through 0xFF
/*
public struct OVERLAPPED
{
public int Internal;
public int InternalHigh;
public int Offset;
public int OffsetHigh;
public int hEvent;
};
*/
// PIC32 related
public const uint P32_PROGRAM_FLASH_START_ADDR = 0x1D000000;
public const uint P32_BOOT_FLASH_START_ADDR = 0x1FC00000;
// OSCCAL regeration
public static uint[] BASELINE_CAL = new uint[41]{
0x0C00, 0x0025, 0x0067, 0x0068, 0x0069, 0x0066, 0x0CFE, 0x0006,
0x0626, 0x0A08, 0x0726, 0x0A0A, 0x0070, 0x0C82, 0x0031, 0x02F0,
0x0A0F, 0x02F1, 0x0A0F, 0x0CF9, 0x0030, 0x0CC8, 0x0031, 0x0506,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x02F0, 0x0A18, 0x0000,
0x0CF9, 0x0030, 0x0000, 0x0000, 0x0000, 0x02F1, 0x0A18, 0x0406,
0x0A08 };
public static uint[] MR16F676FAM_CAL = new uint[48]{
0x3000, 0x2805, 0x0000, 0x0000, 0x0009, 0x1683, 0x0090, 0x0191,
0x019F, 0x30FE, 0x0085, 0x1283, 0x3007, 0x0099, 0x0185, 0x1885,
0x280F, 0x1C85, 0x2811, 0x01A0, 0x3082, 0x00A1, 0x0BA0, 0x2816,
0x0BA1, 0x2816, 0x30F9, 0x00A0, 0x30C8, 0x00A1, 0x1405, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0BA0, 0x281F, 0x0000, 0x30F9,
0x00A0, 0x0000, 0x0000, 0x0000, 0x0BA1, 0x281F, 0x1005, 0x280F};
}
public enum OPCODES {
_VDD_ON = 0xFF,
_VDD_OFF = 0xFE,
_VDD_GND_ON = 0xFD,
_VDD_GND_OFF = 0xFC,
_VPP_ON = 0xFB,
_VPP_OFF = 0xFA,
_VPP_PWM_ON = 0xF9,
_VPP_PWM_OFF = 0xF8,
_MCLR_GND_ON = 0xF7,
_MCLR_GND_OFF = 0xF6,
_BUSY_LED_ON = 0xF5,
_BUSY_LED_OFF = 0xF4,
_SET_ICSP_PINS = 0xF3,
_WRITE_BYTE_LITERAL = 0xF2,
_WRITE_BYTE_BUFFER = 0xF1,
_READ_BYTE_BUFFER = 0xF0,
_READ_BYTE = 0xEF,
_WRITE_BITS_LITERAL = 0xEE,
_WRITE_BITS_BUFFER = 0xED,
_READ_BITS_BUFFER = 0xEC,
_READ_BITS = 0xEB,
_SET_ICSP_SPEED = 0xEA,
_LOOP = 0xE9,
_DELAY_LONG = 0xE8,
_DELAY_SHORT = 0xE7,
_IF_EQ_GOTO = 0xE6,
_IF_GT_GOTO = 0xE5,
_GOTO_INDEX = 0xE4,
_EXIT_SCRIPT = 0xE3,
_PEEK_SFR = 0xE2,
_POKE_SFR = 0xE1,
_ICDSLAVE_RX = 0xE0,
_ICDSLAVE_TX_LIT = 0xDF,
_ICDSLAVE_TX_BUF = 0xDE,
_LOOPBUFFER = 0xDD,
_ICSP_STATES_BUFFER = 0xDC,
_POP_DOWNLOAD = 0xDB,
_COREINST18 = 0xDA,
_COREINST24 = 0xD9,
_NOP24 = 0xD8,
_VISI24 = 0xD7,
_RD2_BYTE_BUFFER = 0xD6,
_RD2_BITS_BUFFER = 0xD5,
_WRITE_BUFWORD_W = 0xD4,
_WRITE_BUFBYTE_W = 0xD3,
_CONST_WRITE_DL = 0xD2,
_WRITE_BITS_LIT_HLD = 0xD1,
_WRITE_BITS_BUF_HLD = 0xD0,
_SET_AUX = 0xCF,
_AUX_STATE_BUFFER = 0xCE,
_I2C_START = 0xCD,
_I2C_STOP = 0xCC,
_I2C_WR_BYTE_LIT = 0xCB,
_I2C_WR_BYTE_BUF = 0xCA,
_I2C_RD_BYTE_ACK = 0xC9,
_I2C_RD_BYTE_NACK = 0xC8,
_SPI_WR_BYTE_LIT = 0xC7,
_SPI_WR_BYTE_BUF = 0xC6,
_SPI_RD_BYTE_BUF = 0xC5,
_SPI_RDWR_BYTE_LIT = 0xC4,
_SPI_RDWR_BYTE_BUF = 0xC3,
_ICDSLAVE_RX_BL = 0xC2,
_ICDSLAVE_TX_LIT_BL = 0xC1,
_ICDSLAVE_TX_BUF_BL = 0xC0,
_MEASURE_PULSE = 0xBF,
_UNIO_TX = 0xBE,
_UNIO_TX_RX = 0xBD,
_JT2_SETMODE = 0xBC,
_JT2_SENDCMD = 0xBB,
_JT2_XFERDATA8_LIT = 0xBA,
_JT2_XFERDATA32_LIT = 0xB9,
_JT2_XFRFASTDAT_LIT = 0xB8,
_JT2_XFRFASTDAT_BUF = 0xB7,
_JT2_XFERINST_BUF = 0xB6,
_JT2_GET_PE_RESP = 0xB5,
_JT2_WAIT_PE_RESP = 0xB4,
}
public enum INST24
{
}
}