📄 comms.lst
字号:
C51 COMPILER V7.07 COMMS 02/08/2007 14:49:17 PAGE 1
C51 COMPILER V7.07, COMPILATION OF MODULE COMMS
OBJECT MODULE PLACED IN Comms.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Comms.c OPTIMIZE(6,SPEED) BROWSE DEFINE(NO_RENUM) DEBUG OBJECTEXTEND
stmt level source
1 #pragma NOIV // Do not generate interrupt vectors
2 //-----------------------------------------------------------------------------
3 // File: periph.c
4 // Contents: Hooks required to implement USB peripheral function.
5 //
6 // Copyright (c) 1997 AnchorChips, Inc. All rights reserved
7 //-----------------------------------------------------------------------------
8 #include "fx2.h"
9 #include "fx2regs.h"
10
11 extern BOOL GotSUD; // Received setup data flag
12 extern BOOL Sleep;
13 extern BOOL Rwuen;
14 extern BOOL Selfpwr;
15
16 #define VR_UPLOAD 0xc0
17 #define VR_DOWNLOAD 0x40
18
19 #define VR_ANCHOR_DLD 0xa0 // handled by core
20 #define VR_EEPROM 0xa2 // loads (uploads) EEPROM
21 #define VR_RAM 0xa3 // loads (uploads) external ram
22 #define VR_RENUM 0xa8 // renum
23 #define VR_SETI2CADDR 0xa4
24 #define VR_GETI2C_TYPE 0xa5 // 8 or 16 byte address
25 #define VR_GET_CHIP_REV 0xa6 // Rev A, B = 0, Rev C = 2 // NOTE: New TNG Rev
26 #define VR_I2C_100 0xaa // put the i2c bus in 100Khz mode
27 #define VR_I2C_400 0xab // put the i2c bus in 400Khz mode
28
29 //***** My Vendor Requests *****//
30 #define VR_Heater 0xda
31 #define VR_ReadBlock 0xdc
32 #define VR_PORT_ACCESS 0xdd // Write/Read a byte to/from the i2c bus
33 #define VR_I2C_SMBUS 0xde
34 #define VR_I2C_SWITCH 0xdf
35 #define VR_I2C_SMBUS3DATA 0xe0
36
37 #define LED_ADDR 0x21
38 #define BTN_ADDR 0x20
39
40 #define SERIAL_ADDR 0x50
41 #define EP0BUFF_SIZE 0x40
42
43 //SPI interface definitions
44 #define SETDIN IOA = IOA | 0x01
45 #define CLRDIN IOA = IOA & 0xfe
46 #define SETCLK IOA = IOA | 0x02
47 #define CLRCLK IOA = IOA & 0xfd
48 #define SETCS IOA = IOA | 0x04
49 #define CLRCS IOA = IOA & 0xfb
50 #define READDOUT (IOA & 0x10)/0x10
51
52 //heater definitions
53 #define SetHeater1 IOB |= 1
54 #define ClrHeater1 IOB &= 0xfe
55 #define SetHeater2 IOB |= 2
C51 COMPILER V7.07 COMMS 02/08/2007 14:49:17 PAGE 2
56 #define ClrHeater2 IOB &= 0xfd
57 #define MAXHEAT 200
58
59 #define GET_CHIP_REV() ((CPUCS >> 4) & 0x00FF) // EzUSB Chip Rev Field
60
61 //*****New Lines Added*****
62 #define LED_ADDR 0x21
63 #define BTN_ADDR 0x20
64
65 //-----------------------------------------------------------------------------
66 // Global Variables
67 //-----------------------------------------------------------------------------
68 BYTE DB_Addr; //TPM Dual Byte Address stat
69 BYTE I2C_Addr, Heater1PWM=0, Heater2PWM=0; //TPM I2C address
70 BOOL DataRead, DataCollected, BlockReadEnabled=FALSE;
71
72 BYTE Configuration; // Current configuration
73 BYTE AlternateSetting; // Alternate settings
74 BYTE xdata BlockInfo[2][60] ;
75
76 BYTE xdata DataVals[2];// Gerard BYTE xdata DataVals[1];
77 BYTE xdata AddrPtr;
78 BYTE TstCntr=0;
79 //-----------------------------------------------------------------------------
80 // Prototypes
81 //-----------------------------------------------------------------------------
82 void EEPROMWrite(WORD addr, BYTE length, BYTE xdata *buf); //TPM EEPROM Write
83 void EEPROMRead(WORD addr, BYTE length, BYTE xdata *buf); //TPM EEPROM Read
84
85 void WriteSMBUSData(BYTE DevAddr, BYTE AddrPtr, BYTE DataOut);
86 void WriteSMBUS3Data(BYTE DevAddr, BYTE AddrPtr, BYTE DataOut, BYTE DataOut2);// Gerard
87 BYTE ReadSMBUSData(BYTE DevAddr, BYTE AddrPtr);
88 BYTE ReadSMBUS3Data(BYTE DevAddr, BYTE AddrPtr, BYTE DataOut);//Gerard
89
90 void WriteSWITCHData(BYTE DevAddr, BYTE DataOut);
91 BYTE ReadSWITCHData(BYTE DevAddr);
92 void ReadBlockData(BYTE DevAddr, BYTE Num, BYTE StartAddr);
93
94 //added for adm1032 test
95 //BYTE ReadSMBUSDataWithExtraClocks(BYTE DevAddr);
96
97
98 //-----------------------------------------------------------------------------
99 // Task Dispatcher hooks
100 // The following hooks are called by the task dispatcher.
101 //-----------------------------------------------------------------------------
102
103 void TD_Init(void) // Called once at startup
104 {
105 1
106 1 BREAKPT &= ~bmBPEN; // to see BKPT LED go out TGE
107 1 Rwuen = TRUE; // Enable remote-wakeup
108 1 EZUSB_InitI2C(); // Initialize I2C Bus
109 1 CPUCS = (CPUCS & 0xe7) | 0x10; // 48MHz
110 1 OEB = 0x33;
111 1 IOB = 0;
112 1 OED = 0;
113 1 //NumReads = 53;
114 1 //for(i=0 ; i<NumReads ; i++)
115 1 // BlockInfo[i][0]= 0x88+i;
116 1
117 1 }
C51 COMPILER V7.07 COMMS 02/08/2007 14:49:17 PAGE 3
118
119 void TD_Poll(void) // Called repeatedly while the device is idle
120 {
121 1 static BYTE i=0,j=0;
122 1
123 1 I2CTL |= bm400KHZ; //i2c interface runs at 400KHz
124 1
125 1 if(i<Heater1PWM)
126 1 SetHeater1;
127 1 else if(i<MAXHEAT)
128 1 ClrHeater1;
129 1 if(++i==MAXHEAT)
130 1 i=0;
131 1
132 1 if(j<Heater2PWM)
133 1 SetHeater2;
134 1 else if(j<MAXHEAT)
135 1 ClrHeater2;
136 1 if(++j==MAXHEAT)
137 1 j=0;
138 1
139 1
140 1 /* if(BlockReadEnabled == TRUE)
141 1 if(DataCollected == TRUE)
142 1 {
143 1 DataRead = FALSE;
144 1 ReadBlockData();
145 1 DataRead = TRUE;
146 1 DataCollected = FALSE;
147 1 }
148 1 */
149 1 }
150
151 BOOL TD_Suspend(void) // Called before the device goes into suspend mode
152 {
153 1 return(TRUE);
154 1 }
155
156 BOOL TD_Resume(void) // Called after the device resumes
157 {
158 1 return(TRUE);
159 1 }
160
161 //-----------------------------------------------------------------------------
162 // Device Request hooks
163 // The following hooks are called by the end point 0 device request parser.
164 //-----------------------------------------------------------------------------
165
166 BOOL DR_GetDescriptor(void)
167 {
168 1 return(TRUE);
169 1 }
170
171 BOOL DR_SetConfiguration(void) // Called when a Set Configuration command is received
172 {
173 1 Configuration = SETUPDAT[2];
174 1 return(TRUE); // Handled by user code
175 1 }
176
177 BOOL DR_GetConfiguration(void) // Called when a Get Configuration command is received
178 {
179 1 EP0BUF[0] = Configuration;
C51 COMPILER V7.07 COMMS 02/08/2007 14:49:17 PAGE 4
180 1 EP0BCH = 0;
181 1 EP0BCL = 1;
182 1 return(TRUE); // Handled by user code
183 1 }
184
185 BOOL DR_SetInterface(void) // Called when a Set Interface command is received
186 {
187 1 AlternateSetting = SETUPDAT[2];
188 1 return(TRUE); // Handled by user code
189 1 }
190
191 BOOL DR_GetInterface(void) // Called when a Set Interface command is received
192 {
193 1 EP0BUF[0] = AlternateSetting;
194 1 EP0BCH = 0;
195 1 EP0BCL = 1;
196 1 return(TRUE); // Handled by user code
197 1 }
198
199 BOOL DR_GetStatus(void)
200 {
201 1 return(TRUE);
202 1 }
203
204 BOOL DR_ClearFeature(void)
205 {
206 1 return(TRUE);
207 1 }
208
209 BOOL DR_SetFeature(void)
210 {
211 1 return(TRUE);
212 1 }
213
214 BOOL DR_VendorCmnd(void)
215 {
216 1 BYTE i2c_slad;
217 1
218 1 // Determine I2C boot eeprom device address; addr = 0x0 for 8 bit addr eeproms (24LC00)
219 1 I2C_Addr = SERIAL_ADDR | ((I2CS & 0x10) >> 4); // addr=0x01 for 16 bit addr eeprom (LC65)
220 1 // Indicate if it is a dual byte address part
221 1 DB_Addr = (BOOL)(I2C_Addr & 0x01); //TPM: ID1 is 16 bit addr bit - set by rocker sw or jumper
222 1 I2CTL &= ~bm400KHZ;
223 1
224 1 switch(SETUPDAT[1])
225 1 { //TPM handle new commands
226 2
227 2 case VR_I2C_SMBUS:
228 2 if (SETUPDAT[0] == VR_UPLOAD)
229 2 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -