Rev 1661 Rev 1711
1 /********************************************************************* 1 /*********************************************************************
2 * 2 *
3 * Microchip USB C18 Firmware Version 1.2 3 * Microchip USB C18 Firmware Version 1.2
4 * 4 *
5 ********************************************************************* 5 *********************************************************************
6 * FileName: user.h 6 * FileName: user.h
7 * Dependencies: See INCLUDES section below 7 * Dependencies: See INCLUDES section below
8 * Processor: PIC18 8 * Processor: PIC18
9 * Compiler: C18 3.11+ 9 * Compiler: C18 3.11+
10 * Company: Microchip Technology, Inc. 10 * Company: Microchip Technology, Inc.
11 * 11 *
12 * Software License Agreement 12 * Software License Agreement
13 * 13 *
14 * The software supplied herewith by Microchip Technology Incorporated 14 * The software supplied herewith by Microchip Technology Incorporated
15 * (the “Company”) for its PICmicro® Microcontroller is intended and 15 * (the “Company”) for its PICmicro® Microcontroller is intended and
16 * supplied to you, the Company’s customer, for use solely and 16 * supplied to you, the Company’s customer, for use solely and
17 * exclusively on Microchip PICmicro Microcontroller products. The 17 * exclusively on Microchip PICmicro Microcontroller products. The
18 * software is owned by the Company and/or its supplier, and is 18 * software is owned by the Company and/or its supplier, and is
19 * protected under applicable copyright laws. All rights are reserved. 19 * protected under applicable copyright laws. All rights are reserved.
20 * Any use in violation of the foregoing restrictions may subject the 20 * Any use in violation of the foregoing restrictions may subject the
21 * user to criminal sanctions under applicable laws, as well as to 21 * user to criminal sanctions under applicable laws, as well as to
22 * civil liability for the breach of the terms and conditions of this 22 * civil liability for the breach of the terms and conditions of this
23 * license. 23 * license.
24 * 24 *
25 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, 25 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
26 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED 26 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
27 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 27 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
28 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, 28 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
29 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR 29 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
30 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. 30 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
31 * 31 *
32 * Author Date Comment 32 * Author Date Comment
33 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 33 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34 * Rawin Rojvanit 11/19/04 Original. 34 * Rawin Rojvanit 11/19/04 Original.
35 * Rawin Rojvanit 05/14/07 Minor updates. 35 * Rawin Rojvanit 05/14/07 Minor updates.
36 ********************************************************************/ 36 ********************************************************************/
37   37  
38 #ifndef PICDEM_FS_DEMO_H 38 #ifndef PICDEM_FS_DEMO_H
39 #define PICDEM_FS_DEMO_H 39 #define PICDEM_FS_DEMO_H
40   40  
41 /** I N C L U D E S **********************************************************/ 41 /** I N C L U D E S **********************************************************/
42   42  
43 /** D E F I N I T I O N S ****************************************************/ 43 /** D E F I N I T I O N S ****************************************************/
44   44  
45 // For custom LPF switchover points 45 // For custom LPF switchover points
46 #define ALEX 46 #define ALEX
47 //#define K5OOR 47 //#define K5OOR
48 //#define MARC 48 //#define MARC
49   49  
50 // YAS is defined in the HardwareProfile - UBW.h, if needed 50 // YAS is defined in the HardwareProfile - UBW.h, if needed
51   51  
52 #if defined(YAS) 52 #if defined(YAS)
53 #define NUM_BPF 8 53 #define NUM_BPF 8
54 #else 54 #else
55 #define NUM_BPF 4 55 #define NUM_BPF 4
56 #endif 56 #endif
57   57  
58 #define INIT_SI570_ON_STARTUP 58 #define INIT_SI570_ON_STARTUP
59   59  
60 #define VERSION_MAJOR 16 60 #define VERSION_MAJOR 16
61 #define VERSION_MINOR 04 61 #define VERSION_MINOR 04
62   62  
63 #define DEFAULT_I2C_ADDRESS 0x55 63 #define DEFAULT_I2C_ADDRESS 0x55
64 #define PCF8574 0x39 // A2 A1 A0 -> 0 0 1 64 #define PCF8574 0x39 // A2 A1 A0 -> 0 0 1
65   65  
66 #define F_CAL_DONE 0 // EEPROM position of F_CAL_DONE flag. 4 bytes follow. 66 #define F_CAL_DONE 0 // EEPROM position of F_CAL_DONE flag. 4 bytes follow.
67 #define F_CAL_DONE_VALUE 0x55 67 #define F_CAL_DONE_VALUE 0x55
68 #define DEFAULT_FCRYST 114.285 68 #define DEFAULT_FCRYST 114.285
69   69  
70 //#if defined(UBW) 70 //#if defined(UBW)
71 #define F_INIT_FREQ 5 // 4 bytes follow 71 #define F_INIT_FREQ 5 // 4 bytes follow
72 //#elif defined(UBW32) 72 //#elif defined(UBW32)
73 //#define F_INIT_FREQ 2 // fcryst 4 bytes all stored in one 32 bit slot 73 //#define F_INIT_FREQ 2 // fcryst 4 bytes all stored in one 32 bit slot
74 //#endif 74 //#endif
75   75  
76 #define F_INIT_FREQ_VALUE 0x55 76 #define F_INIT_FREQ_VALUE 0x55
77 #define DEFAULT_INIT_FREQ 56.32 77 #define DEFAULT_INIT_FREQ 56.32
78   78  
79 #if defined(UBW) 79 #if defined(UBW)
80 #define F_SMOOTH 10 // 2 bytes follow 80 #define F_SMOOTH 10 // 2 bytes follow
81 #elif defined(UBW32) 81 #elif defined(UBW32)
82 #define F_SMOOTH 4 // 1 slot follow 82 #define F_SMOOTH 4 // 1 slot follow
83 #endif 83 #endif
84   84  
85 #define F_SMOOTH_VALUE 0x55 85 #define F_SMOOTH_VALUE 0x55
86 #define DEFAULT_SMOOTH 3500 // ppm 86 #define DEFAULT_SMOOTH 3500 // ppm
87   87  
88 #define F_SUB_MUL_VALUE 0x55 88 #define F_SUB_MUL_VALUE 0x55
89 #define DEFAULT_SUB 0.0 89 #define DEFAULT_SUB 0.0
90 #define DEFAULT_MUL 1.0 90 #define DEFAULT_MUL 1.0
91   91  
92 #if defined(UBW) 92 #if defined(UBW)
93 #define F_SUB_MUL 13 // 8 bytes follow 93 #define F_SUB_MUL 13 // 8 bytes follow
94 #elif defined(UBW32) 94 #elif defined(UBW32)
95 #define F_SUB_MUL 6 // 2 slots follow 95 #define F_SUB_MUL 6 // 2 slots follow
96 #endif 96 #endif
97   97  
98 #if defined(UBW) 98 #if defined(UBW)
99 #define F_CROSS_OVER 22 // 32 bytes follow 99 #define F_CROSS_OVER 22 // 32 bytes follow
100 #elif defined(UBW32) 100 #elif defined(UBW32)
101 #define F_CROSS_OVER 9 // 16 words stored in 16 (unsigned int) slots 101 #define F_CROSS_OVER 9 // 16 words stored in 16 (unsigned int) slots
102 #endif 102 #endif
103   103  
104 #define F_CROSS_OVER_VALUE 0x55 104 #define F_CROSS_OVER_VALUE 0x55
105   105  
106 #if defined(UBW) 106 #if defined(UBW)
107 #define F_BLINK_LED 55 107 #define F_BLINK_LED 55
108 #elif defined(UBW32) 108 #elif defined(UBW32)
109 #define F_BLINK_LED 26 109 #define F_BLINK_LED 26
110 #endif 110 #endif
111   111  
112 /** S T R U C T U R E S ******************************************************/ 112 /** S T R U C T U R E S ******************************************************/
113   113  
114   114  
115 extern BYTE i2c_adr; 115 extern BYTE i2c_adr;
116 extern BYTE command; 116 extern BYTE command;
117 extern BYTE replybuf[8]; 117 extern BYTE replybuf[8];
118 extern WORD wCount; 118 extern WORD wCount;
119   119  
120 #define COMMAND_BUFFER_SIZE 16 120 #define COMMAND_BUFFER_SIZE 16
121 #define DATA_PACKET_SIZE 6 121 #define DATA_PACKET_SIZE 6
122   122  
123 typedef struct COMMAND_BUFFER 123 typedef struct COMMAND_BUFFER
124 { 124 {
125 BYTE command; 125 BYTE command;
126 WORD wCount; 126 WORD wCount;
127 BYTE data[DATA_PACKET_SIZE]; 127 BYTE data[DATA_PACKET_SIZE];
128 } COMMAND_BUFFER_t; 128 } COMMAND_BUFFER_t;
129   129  
130 extern COMMAND_BUFFER_t command_buffer[COMMAND_BUFFER_SIZE]; 130 extern COMMAND_BUFFER_t command_buffer[COMMAND_BUFFER_SIZE];
131 extern BYTE current_command_in, current_command_out; 131 extern BYTE current_command_in, current_command_out;
132 extern BYTE command_count; 132 extern BYTE command_count;
133   133  
134 extern double set_frequency; 134 extern double set_frequency;
135   135  
136 extern unsigned char tempBuf[8]; 136 extern unsigned char tempBuf[8];
137   137  
138 typedef union _avr_freq 138 typedef union _avr_freq
139 { 139 {
140 unsigned long qw; 140 unsigned long qw;
141 unsigned char bytes[4]; 141 unsigned char bytes[4];
142 } avr_freq_t; 142 } avr_freq_t;
143   143  
144 extern avr_freq_t avr_freq, fcryst_freq; //frequency [MHz]*2^21 144 extern avr_freq_t avr_freq, fcryst_freq; //frequency [MHz]*2^21
145 // fcryst freq [MHz]*2^24 145 // fcryst freq [MHz]*2^24
146 extern avr_freq_t f_mul; // mul for set freq in 11.21 format 146 extern avr_freq_t f_mul; // mul for set freq in 11.21 format
147   147  
148 typedef union _offset 148 typedef union _offset
149 { 149 {
150 long qw; // signed offset in 11.21 format 150 long qw; // signed offset in 11.21 format
151 unsigned char bytes[4]; 151 unsigned char bytes[4];
152 } offset_t; 152 } offset_t;
153   153  
154 extern offset_t f_sub; 154 extern offset_t f_sub;
155   155  
156 extern unsigned char registers[6]; 156 extern unsigned char registers[6];
157   157  
158 extern BYTE abpf_flag; 158 extern BYTE abpf_flag;
159 extern double Smooth_double; 159 extern double Smooth_double;
160 extern double fcryst_double; 160 extern double fcryst_double;
161 extern WORD_VAL FilterCrossOver[8]; // 11.5 bit value Mhz 161 extern WORD_VAL FilterCrossOver[8]; // 11.5 bit value Mhz
162 extern float FilterSwitchOver[7]; 162 extern float FilterSwitchOver[7];
163 extern WORD_VAL LPFCrossOver[8]; 163 extern WORD_VAL LPFCrossOver[8];
164 extern float LPFSwitchOver[7]; 164 extern float LPFSwitchOver[7];
165   165  
166 /** P U B L I C P R O T O T Y P E S *****************************************/ 166 /** P U B L I C P R O T O T Y P E S *****************************************/
167 void UserInit(void); 167 void UserInit(void);
168 void ProcessIO(void); 168 void ProcessIO(void);
169 void Set_Freq_Handler(void); 169 void Set_Freq_Handler(void);
170 void Set_Register_Handler(void); 170 void Set_Register_Handler(void);
171 void Set_Cal_Handler(void); 171 void Set_Cal_Handler(void);
172 void Set_Init_Freq_Handler(void); 172 void Set_Init_Freq_Handler(void);
173 void Set_Smooth_Handler(void); 173 void Set_Smooth_Handler(void);
174 void Set_Sub_Mul_Handler(void); 174 void Set_Sub_Mul_Handler(void);
175   175  
176 void Reset_Si570(void); 176 void Reset_Si570(void);
177 void Freeze (void); 177 void Freeze (void);
178 void Unfreeze (void); 178 void Unfreeze (void);
179 void Prep_rd (unsigned short); 179 void Prep_rd (unsigned short);
180 void WriteBk (void); 180 void WriteBk (void);
181 void NewF (void); 181 void NewF (void);
182 void SetNewFreq(void); 182 void SetNewFreq(void);
183 void ReadRegs(void); 183 void ReadRegs(void);
184 void ReadStartUpConfiguration(void); 184 void ReadStartUpConfiguration(void);
185 void RunFreqProg(double); 185 void RunFreqProg(double);
186 void SetFrequency(double); 186 void SetFrequency(double);
187 void Set_BPF(float); 187 void Set_BPF(float);
188 void Set_LPF(float); 188 void Set_LPF(float);
189 float Cross2Switch(WORD_VAL); 189 float Cross2Switch(WORD_VAL);
190 WORD_VAL Switch2Cross(float); 190 WORD_VAL Switch2Cross(float);
191 double Freq_From_Register(double); 191 double Freq_From_Register(double);
192   192  
193 void Read_Command_Into_Buffer(void); 193 void Read_Command_Into_Buffer(void);
194 void USBCheckUserRequest(void); 194 void USBCheckUserRequest(void);
195 void USBCheckUBWRequest(void); 195 void USBCheckUBWRequest(void);
196   196  
197 #endif //PICDEM_FS_DEMO_H 197 #endif //PICDEM_FS_DEMO_H