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
21 /*! Magic, device family specific constants (these are drawn from the
22 dsPIC33F/PIC24H Flash Programming Specification). Note that the
23 ICSP key is in bit-reversed order, since it is the only thing that
24 is sent MSb first (hence, we flip the bit order and use our usual
27 Per the dsPIC33F/PIC24H and PIC24F flash programming
28 specifications, the ICSP key is 0x4D434851. */
29 #define ICSP_KEY_LOW 0xC2B2
30 #define ICSP_KEY_HIGH 0x8A12
31 #define APPID_ADDR 0x8007F0
33 //! I/O (pin level); follows spi.h
38 //Handle bidirectionality of PGD
39 #define DIR_PGD_RD P5DIR&=~PGD
40 #define DIR_PGD_WR P5DIR|=PGD
42 #define SET_MCLR P5OUT|=MCLR
43 #define CLR_MCLR P5OUT&=~MCLR
44 #define SET_PGD P5OUT|=PGD
45 #define CLR_PGD P5OUT&=~PGD
46 #define SET_PGC P5OUT|=PGC
47 #define CLR_PGC P5OUT&=~PGC
49 #define READ_PGD (P5IN&PGD?1:0)
52 //! Set pins as appropriate for dsPIC33F/PIC24H
55 //! Start ICSP with an attached dsPIC33F/PIC24H
56 void pic33f_connect();
58 /*! Stop ICSP session; maybe not necessary, but cleaner since a
59 minimum delay is required before dropping MCLR pin after last
60 transmission to dsPIC33F/PIC24H chip. */
61 void pic33f_disconnect();
63 //! ICSP SIX command: execute single command on attached dsPIC33F/PIC24H.
64 void pic33f_six( unsigned int highb, unsigned int loww );
66 //! ICSP REGOUT command: read contents of VISI register
67 unsigned int pic33f_regout();
69 //! Execute a list of commands on attached dsPIC33F/PIC24H.
70 void pic33f_sixlist( unsigned int list_len );
72 //! Execute a list of ICSP commands on attached PIC
73 void pic33f_cmdlist(unsigned int list_len);
75 //! Start Enhanced ICSP session with dsPIC33F/PIC24H (assumes Programming Executive is present).
76 void pic33f_eicsp_connect();
78 /*! Get Application ID (u8), Device ID (i.e. DEVID; u16) and hardware
79 revision (u16). Results are dumped to the host connection (a la
80 txdata, app is PIC and verb is PIC_DEVID33F).
82 This function assumes no ICSP (or Enhanced ICSP) session is currently open!
84 Returns number of bytes written to cmddata buffer.
86 unsigned int pic33f_getid();
89 void pic33f_trans16( unsigned int word );
92 void pic33f_trans8( unsigned char byte );
96 #define PIC_DEVID33F 0x81 //! Read Device and Application ID
97 #define PIC_SIX33F 0x82 //! ICSP six command; execute instruction on target.
98 #define PIC_REGOUT33F 0x83 //! Read out VISI register.
99 #define PIC_SIXLIST33F 0x86 /* Buffers list of instructions to MSP430,
100 then executes them over ICSP session
101 with target dsPIC33F/PIC24H chip. */
102 #define PIC_CMDLIST 0x88 /* Similar to PIC_SIXLIST33F, but includes ICSP command */
104 #define PIC_RESET33F 0x87 // Reset attached dsPIC33F/PIC24H chip.
105 #define PIC_START33F 0x84 // Start ICSP session
106 #define PIC_STOP33F 0x85 // Stop ICSP (basically, drop !MCLR pin and pause briefly)
108 extern app_t const pic_app;