3 \author Scott Livingston
5 \brief Definitions for the dsPIC33F programmer application. Note
6 that the programming for dsPIC33F/PIC24H chips is
7 non-standard 2-wire SPI; hence, I do not use the existing
10 \date March, April 2010
15 /*! Magic, device family specific constants (these are drawn from the
16 dsPIC33F/PIC24H Flash Programming Specification). Note that the
17 ICSP key is in bit-reversed order, since it is the only thing that
18 is sent MSb first (hence, we flip the bit order and use our usual
19 LSb-first routines). */
20 #define ICSP_KEY_LOW 0xC2B2
21 #define ICSP_KEY_HIGH 0x8A12
22 #define APPID_ADDR 0x8007F0
24 //! I/O (pin level); follows spi.h
29 //Handle bidirectionality of PGD
30 #define DIR_PGD_RD P5DIR&=~PGD
31 #define DIR_PGD_WR P5DIR|=PGD
33 #define SET_MCLR P5OUT|=MCLR
34 #define CLR_MCLR P5OUT&=~MCLR
35 #define SET_PGD P5OUT|=PGD
36 #define CLR_PGD P5OUT&=~PGD
37 #define SET_PGC P5OUT|=PGC
38 #define CLR_PGC P5OUT&=~PGC
40 #define READ_PGD (P5IN&PGD?1:0)
43 //! Set pins as appropriate for dsPIC33F/PIC24H
46 //! Start ICSP with an attached dsPIC33F/PIC24H
47 void pic33f_connect();
49 /*! Stop ICSP session; maybe not necessary, but cleaner since a
50 minimum delay is required before dropping MCLR pin after last
51 transmission to dsPIC33F/PIC24H chip. */
52 void pic33f_disconnect();
54 //! ICSP SIX command: execute single command on attached dsPIC33F/PIC24H.
55 void pic33f_six( unsigned int highb, unsigned int loww );
57 //! ICSP REGOUT command: read contents of VISI register
58 unsigned int pic33f_regout();
60 //! Execute a list of commands on attached dsPIC33F/PIC24H.
61 void pic33f_sixlist( unsigned int list_len );
63 //! Start Enhanced ICSP session with dsPIC33F/PIC24H (assumes Programming Executive is present).
64 void pic33f_eicsp_connect();
66 /*! Get Application ID (u8), Device ID (i.e. DEVID; u16) and hardware
67 revision (u16). Results are dumped to the host connection (a la
68 txdata, app is PIC and verb is PIC_DEVID33F).
70 This function assumes no ICSP (or Enhanced ICSP) session is currently open!
72 Returns number of bytes written to cmddata buffer.
74 unsigned int pic33f_getid();
77 void pic33f_trans16( unsigned int word );
80 void pic33f_trans8( unsigned char byte );
84 #define PIC_DEVID33F 0x81 //! Read Device and Application ID
85 #define PIC_SIX33F 0x82 //! ICSP six command; execute instruction on target.
86 #define PIC_REGOUT33F 0x83 //! Read out VISI register.
87 #define PIC_SIXLIST33F 0x86 /* Buffers list of instructions to MSP430,
88 then executes them over ICSP session
89 with target dsPIC33F/PIC24H chip. */
91 #define PIC_START33F 0x84 // Start ICSP session
92 #define PIC_STOP33F 0x85 // Stop ICSP (basically, drop !MCLR pin and pause briefly)