1 /*
2  * Copyright (C) 2005-2019 Darron Broad
3  * All rights reserved.
4  *
5  * This file is part of Pickle Microchip PIC ICSP.
6  *
7  * Pickle Microchip PIC ICSP is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as published
9  * by the Free Software Foundation.
10  *
11  * Pickle Microchip PIC ICSP is distributed in the hope that it will be
12  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with Pickle Microchip PIC ICSP. If not, see http://www.gnu.org/licenses/
18  */
19 
20 #ifndef _PIC16N_H
21 #define _PIC16N_H
22 
23 /******************************************************************************
24  * 16-bit CONFIGURATION
25  *****************************************************************************/
26 
27 #define PIC16N_WORD_MASK (0x0000FFFF)
28 #define PIC16N_DATA_MASK (0x000000FF)
29 #define PIC16N_USERID_MAX  (256)	/* 256 BYTES / 128 WORDS */
30 #define PIC16N_CONFIG_MAX  (12)		/* 12  BYTES / 6   WORDS */
31 #define PIC16N_DEVINFO_MAX (32)		/* WORDS */
32 #define PIC16N_DEVCONF_MAX (5)		/* WORDS */
33 
34 struct pic16n_config {
35 	uint8_t userid[PIC16N_USERID_MAX];	/* 200000 .. 2000FF */
36 	uint8_t config[PIC16N_CONFIG_MAX];	/* 300000 .. 30000B */
37 	uint16_t devinfo[PIC16N_DEVINFO_MAX];	/* 3F0000 .. 3F003F */
38 	uint16_t devconf[PIC16N_DEVCONF_MAX];	/* 3FFF00 .. 3FFF09 */
39 	uint16_t revisionid;			/* 3FFFFC           */
40 	uint16_t deviceid;			/* 3FFFFE           */
41 };
42 
43 struct pic16n_dsmap {
44 	char devicename[STRLEN];	/*                                    */
45 	uint16_t deviceid;		/*                                    */
46 	uint32_t datasheet;		/* programming specification          */
47 	uint32_t flash;			/* program flash size in words        */
48 	uint32_t config;		/* configuration size in bytes (even) */
49 	uint32_t eeprom;		/* nvm eeprom size in bytes           */
50 	uint32_t latches;		/* latch size                         */
51 #if 0
52 	uint32_t erase	;		/* erase size                         */
53 #endif
54 	uint32_t devinfo;		/* devinfo size in words              */
55 	uint32_t devconf;		/* devconf size in words              */
56 	uint32_t idsize;		/* user id size in bytes (even)       */
57 	uint8_t *masks;			/* config masks                       */
58 };
59 
60 /******************************************************************************
61  * MEMORY
62  *****************************************************************************/
63 
64 #define PIC16N_WORD(X) ((X) * 512) /* KB to words */
65 
66 #define PIC16N_USERID_ADDR  (0x200000)
67 #define PIC16N_CONFIG_ADDR  (0x300000)
68 #define PIC16N_EEPROM_ADDR  (0x310000) /* EEPROM physical address */
69 #define PIC16N_DEVINFO_ADDR (0x3F0000)
70 #define PIC16N_DEVCONF_ADDR (0x3FFF00)
71 #define PIC16N_REVID_ADDR   (0x3FFFFC)
72 #define PIC16N_DEVID_ADDR   (0x3FFFFE)
73 #define PIC16N_EEFAKE_ADDR  (0xF00000) /* EEPROM pseudo address (NOT USED) */
74 
75 #define PIC16N_ERASE        (0x3FFF00)
76 #define PIC16N_LATCHES      (0x3FFF02)
77 #define PIC16N_ROWS         (0x3FFF04)
78 #define PIC16N_EEPROM       (0x3FFF06)
79 #define PIC16N_PINS         (0x3FFF08)
80 
81 #define PIC16N_TPINT_CODE   (2800)	/*  2.8 ms */
82 #define PIC16N_TPINT_CONFIG (5600)	/*  5.6 ms */
83 #define PIC16N_TERAB        (25200)	/* 25.2 ms */
84 #define PIC16N_TERAR        (2800)	/*  2.8 ms */
85 
86 #define PIC16N_TPDFM_Q      (11000)	/* 11.0 ms */
87 #define PIC16N_TPINT_Q      (65)	/*   65 us */
88 #define PIC16N_TERAB_Q      (75000)	/* 75.0 ms */
89 
90 #define PIC16N_MAJOR_SHIFT  (6)
91 #define PIC16N_REV_MASK     (0x003F)
92 
93 /******************************************************************************
94  * PICMicro devices (8-bit data devices using new programming protocol)
95  *****************************************************************************/
96 
97 #define DS40001772B (40001772)
98 #define PIC18F47K40  (0x6900)
99 #define PIC18F46K40  (0x6920)
100 #define PIC18F45K40  (0x6940)
101 #define PIC18F27K40  (0x6960)
102 #define PIC18F26K40  (0x6980)
103 #define PIC18F25K40  (0x69A0)
104 #define PIC18F24K40  (0x69C0)
105 #define PIC18LF47K40 (0x69E0)
106 #define PIC18LF46K40 (0x6A00)
107 #define PIC18LF45K40 (0x6A20)
108 #define PIC18LF27K40 (0x6A40)
109 #define PIC18LF26K40 (0x6A60)
110 #define PIC18LF25K40 (0x6A80)
111 #define PIC18LF24K40 (0x6AA0)
112 
113 #define DS40001836A (40001836)
114 #define PIC18F25K42  (0x6C80)
115 #define PIC18F24K42  (0x6CA0)
116 #define PIC18LF25K42 (0x6DC0)
117 #define PIC18LF24K42 (0x6DE0)
118 
119 #define DS40001886B (40001886)
120 #define PIC18F26K42  (0x6C60)
121 #define PIC18F27K42  (0x6C40)
122 #define PIC18F45K42  (0x6C20)
123 #define PIC18F46K42  (0x6C00)
124 #define PIC18F47K42  (0x6BE0)
125 #define PIC18F55K42  (0x6BC0)
126 #define PIC18F56K42  (0x6BA0)
127 #define PIC18F57K42  (0x6B80)
128 #define PIC18LF26K42 (0x6DA0)
129 #define PIC18LF27K42 (0x6D80)
130 #define PIC18LF45K42 (0x6D60)
131 #define PIC18LF46K42 (0x6D40)
132 #define PIC18LF47K42 (0x6D20)
133 #define PIC18LF55K42 (0x6D00)
134 #define PIC18LF56K42 (0x6CE0)
135 #define PIC18LF57K42 (0x6CC0)
136 
137 #define DS40001927A (40001927)
138 #define PIC18F25K83  (0x6EE0)
139 #define PIC18F26K83  (0x6EC0)
140 #define PIC18LF25K83 (0x6F20)
141 #define PIC18LF26K83 (0x6F00)
142 
143 #define DS40001874F (40001874)
144 #define PIC18F46Q10 (0x7120)
145 #define PIC18F45Q10 (0x7140)
146 #define PIC18F26Q10 (0x7180)
147 #define PIC18F25Q10 (0x71A0)
148 #define PIC18F24Q10 (0x71C0)
149 #define PIC18F27Q10 (0x7100)
150 #define PIC18F47Q10 (0x70E0)
151 
152 /******************************************************************************/
153 
154 uint32_t pic16n_arch(void);
155 void pic16n_selector(void);
156 void pic16n_bootloader(void);
157 void pic16n_program_verify(void);
158 void pic16n_standby(void);
159 void pic16n_bulk_erase(void);
160 void pic16n_row_erase(uint32_t, uint32_t);
161 int pic16n_read_config_memory(void);
162 void pic16n_write_panel(uint32_t, uint32_t, uint32_t *, uint32_t);
163 uint32_t pic16n_get_program_count(void);
164 uint32_t pic16n_get_program_size(uint32_t *, uint32_t);
165 uint32_t pic16n_get_data_size(uint32_t *);
166 uint32_t pic16n_read_program_memory_block(uint32_t *, uint32_t, uint32_t);
167 uint32_t pic16n_read_data_memory_block(uint16_t *, uint32_t, uint16_t);
168 uint32_t pic16n_write_config(void);
169 uint16_t pic16n_getregion(uint32_t);
170 uint32_t pic16n_program_data(uint32_t, pic_data *);
171 void pic16n_program_begin(void);
172 void pic16n_program_end(int);
173 uint32_t pic16n_verify_data(uint32_t, pic_data *, uint32_t *);
174 void pic16n_view_data(pic_data *);
175 void pic16n_dumpdeviceid(void);
176 void pic16n_dumpconfig(uint32_t, uint32_t);
177 void pic16n_dumphexcode(uint32_t, uint32_t, uint32_t *);
178 void pic16n_dumpinhxcode(uint32_t, uint32_t, uint32_t *);
179 void pic16n_dumphexdata(uint32_t, uint32_t, uint16_t *);
180 void pic16n_dumpinhxdata(uint32_t, uint32_t, uint16_t *);
181 void pic16n_dumpdevice(void);
182 
183 #endif /* !_PIC16N_H */
184