Added initial support for board=apimote2
[goodfet] / firmware / include / slc2.h
1 /*! \file slc2.h
2   \author Alexey Borisenko <abori021@uottawa.ca>
3   \brief Definitions for Silicon Lab C2 debugging application
4   NOTE: FPDAT register address can be different, based on the device
5   Current address is meant for the 8051f34x
6 */
7
8 #ifndef SLC2_H
9 #define SLC2_H
10
11 #include "app.h"
12
13 #define SLC2 0x06
14
15 //Pins and I/O
16 #define C2CK BIT7
17 #define C2D BIT6
18
19 #define SETC2CK P3OUT |= C2CK
20 #define CLRC2CK P3OUT &= ~C2CK
21 #define SETC2D P3OUT |= C2D
22 #define CLRC2D P3OUT &= ~C2D
23
24 #define READC2D (P3IN&C2D?1:0)
25
26 #define C2CKOUTPUT P3DIR|=C2CK
27 #define C2D_DriverOff P3DIR&=~C2D
28 #define C2D_DriverOn P3DIR|=C2D
29
30 #define DATA_READ  0x00
31 #define ADDR_READ  0x02
32 #define DATA_WRITE 0x01
33 #define ADDR_WRITE 0x03
34
35 // FLASH information
36 #define FLASH_SIZE 65536 // FLASH size in bytes
37 #define NUM_PAGES FLASH_SIZE/512 // Number of 512-byte FLASH pages
38
39 // C2 status return codes
40 #define INVALID_COMMAND 0x00
41 #define COMMAND_FAILED 0x02
42 #define COMMAND_OK 0x0D
43
44 // C2 interface commands
45 #define GET_VERSION 0x01
46 #define BLOCK_READ 0x06
47 #define BLOCK_WRITE 0x07
48 #define PAGE_ERASE 0x08
49 #define DEVICE_ERASE 0x03
50
51 // C2 Registers
52 #define FPDAT 0xAD
53 #define FPCTL 0x02
54 #define DEVICEID 0x00
55 #define REVID 0x01
56
57 // Program MACROS
58 #define Poll_OutReady while(!(C2_ReadAR()&0x01))
59 #define Poll_InBusy while((C2_ReadAR()&0x02))
60 #define StrobeC2CK CLRC2CK; SETC2CK
61
62 // C2 verbs
63 #define GETDEVID 0x80
64 #define GETREVID 0x81
65 #define PERASE 0x82
66 #define DERASE 0x83
67 #define VRESET 0x84
68
69 void slc2_handle_fn( uint8_t const app,
70                                         uint8_t const verb,
71                                         uint32_t const len);
72
73 extern app_t const slc2_app;
74
75 // FLASH programming functions
76 void C2_Init();
77 unsigned char C2_GetDevID(void);
78 char C2_BlockRead(void);
79 char C2_BlockWrite(void);
80 char C2_PageErase(void);
81 char C2_DeviceErase(void);
82 // Primitive C2 functions
83 void C2_Reset(void);
84 void C2_WriteAR(unsigned char);
85 unsigned char C2_ReadAR(void);
86 void C2_WriteDR(unsigned char);
87 unsigned char C2_ReadDR(void);
88 unsigned char C2_ReadDeviceID(void);
89 unsigned char C2_ReadRevID(void);
90
91
92 #endif