updated command line 802.15.4 checksum calculator and added serClose to GoodFET to...
[goodfet] / firmware / include / pic.h
1 /*! \file dspic33f.h
2
3   \author Scott Livingston
4
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
8          GoodFET SPI routines.
9
10   \date March-June 2010
11
12 */
13
14 #ifndef PIC_H
15 #define PIC_H
16
17 #include "app.h"
18
19 #define PIC 0x34
20
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
25     LSb-first routines).
26
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
32
33 //! I/O (pin level); follows spi.h
34 #define PGD BIT1
35 #define PGC BIT3
36 #define MCLR BIT0
37
38 //Handle bidirectionality of PGD
39 #define DIR_PGD_RD P5DIR&=~PGD
40 #define DIR_PGD_WR P5DIR|=PGD
41
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
48
49 #define READ_PGD (P5IN&PGD?1:0)
50
51
52 //! Set pins as appropriate for dsPIC33F/PIC24H
53 void pic33f_setup();
54
55 //! Start ICSP with an attached dsPIC33F/PIC24H
56 void pic33f_connect();
57
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();
62
63 //! ICSP SIX command: execute single command on attached dsPIC33F/PIC24H.
64 void pic33f_six( unsigned int highb, unsigned int loww );
65
66 //! ICSP REGOUT command: read contents of VISI register
67 unsigned int pic33f_regout();
68
69 //! Execute a list of commands on attached dsPIC33F/PIC24H.
70 void pic33f_sixlist( unsigned int list_len );
71
72 //! Execute a list of ICSP commands on attached PIC
73 void pic33f_cmdlist(unsigned int list_len);
74
75 //! Start Enhanced ICSP session with dsPIC33F/PIC24H (assumes Programming Executive is present).
76 void pic33f_eicsp_connect();
77
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).
81
82     This function assumes no ICSP (or Enhanced ICSP) session is currently open!
83
84         Returns number of bytes written to cmddata buffer.
85 */
86 unsigned int pic33f_getid();
87
88 //! Write word
89 void pic33f_trans16( unsigned int word );
90
91 //! Write byte
92 void pic33f_trans8( unsigned char byte );
93
94  
95 //Command codes
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 */
103
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)
107
108 extern app_t const pic_app;
109
110 #endif // PIC_H