No changes between revisions
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/CleanUp.bat |
---|
0,0 → 1,92 |
@echo off |
REM Remove files generated by compiler in this directory |
REM and all subdirectories. |
echo Removing *.$$$ files... |
del *.$$$ /f /q /s |
echo. |
echo Removing *.bkx files... |
del *.bkx /f /q /s |
echo. |
echo Removing *.cce files... |
del *.cce /f /q /s |
echo. |
echo Removing *.cod files... |
del *.cod /f /q /s |
echo. |
echo Removing *.cof files... |
del *.cof /f /q /s |
echo. |
echo Removing *.err files... |
del *.err /f /q /s |
echo. |
echo Removing *.hex files... |
del *.hex /f /q /s |
echo. |
echo Removing *.i files... |
del *.i /f /q /s |
echo. |
echo Removing *.lde files... |
del *.lde /f /q /s |
echo. |
echo Removing *.lst files... |
del *.lst /f /q /s |
echo. |
echo Removing *.obj files... |
del *.obj /f /q /s |
echo. |
echo Removing *.o files... |
del *.o /f /q /s |
echo. |
echo Removing *.rlf files... |
del *.rlf /f /q /s |
echo. |
echo Removing *.sym files... |
del *.sym /f /q /s |
echo. |
echo Removing *.sdb files... |
del *.sdb /f /q /s |
echo. |
echo Removing *.wat files... |
del *.wat /f /q /s |
echo. |
echo Removing *.mcs files... |
del *.mcs /f /q /s |
echo. |
echo Removing *.mptags files... |
del *.mptags /f /q /s |
echo. |
echo Removing *.tagsrc files... |
del *.tagsrc /f /q /s |
echo. |
echo Removing *.map files... |
del *.map /f /q /s |
echo. |
echo Removing *.elf files... |
del *.elf /f /q /s |
echo. |
rd Objects /S /Q |
echo Done. |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/HardwareProfile - Low Pin Count USB Development Kit.h |
---|
0,0 → 1,135 |
/******************************************************************** |
FileName: HardwareProfile - Low Pin Count USB Development Kit.h |
Dependencies: See INCLUDES section |
Processor: PIC18 or PIC24 USB Microcontrollers |
Hardware: Low Pin Count USB Development Kit |
Compiler: Microchip C18 |
Company: Microchip Technology, Inc. |
Software License Agreement: |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
Any use in violation of the foregoing restrictions may subject the |
user to criminal sanctions under applicable laws, as well as to |
civil liability for the breach of the terms and conditions of this |
license. |
THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
******************************************************************** |
File Description: |
Change History: |
Rev Date Description |
1.0 11/19/2004 Initial release |
2.1 02/26/2007 Updated for simplicity and to use common |
coding style |
2.3 09/15/2008 Broke out each hardware platform into its own |
"HardwareProfile - xxx.h" file |
********************************************************************/ |
#ifndef HARDWARE_PROFILE_LOW_PIN_COUNT_USB_DEVELOPMENT_KIT_H |
#define HARDWARE_PROFILE_LOW_PIN_COUNT_USB_DEVELOPMENT_KIT_H |
/*******************************************************************/ |
/******** USB stack hardware selection options *********************/ |
/*******************************************************************/ |
//This section is the set of definitions required by the MCHPFSUSB |
// framework. These definitions tell the firmware what mode it is |
// running in, and where it can find the results to some information |
// that the stack needs. |
//These definitions are required by every application developed with |
// this revision of the MCHPFSUSB framework. Please review each |
// option carefully and determine which options are desired/required |
// for your application. |
//#define USE_SELF_POWER_SENSE_IO |
#define tris_self_power TRISAbits.TRISA2 // Input |
#if defined(USE_SELF_POWER_SENSE_IO) |
#define self_power PORTAbits.RA2 |
#else |
#define self_power 1 |
#endif |
//#define USE_USB_BUS_SENSE_IO |
#define tris_usb_bus_sense TRISAbits.TRISA1 // Input |
#if defined(USE_USB_BUS_SENSE_IO) |
#define USB_BUS_SENSE PORTAbits.RA1 |
#else |
#define USB_BUS_SENSE 1 |
#endif |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/******** Application specific definitions *************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
//Uncomment the following line to make the output HEX of this |
// project work with the HID Bootloader |
#define PROGRAMMABLE_WITH_USB_HID_BOOTLOADER |
/** Board definition ***********************************************/ |
//These defintions will tell the main() function which board is |
// currently selected. This will allow the application to add |
// the correct configuration bits as wells use the correct |
// initialization functions for the board. These defitions are only |
// required in the stack provided demos. They are not required in |
// final application design. |
#define DEMO_BOARD LOW_PIN_COUNT_USB_DEVELOPMENT_KIT |
#define LOW_PIN_COUNT_USB_DEVELOPMENT_KIT |
#define CLOCK_FREQ 48000000 |
/** LED ************************************************************/ |
#define mInitAllLEDs() LATC &= 0xF0; TRISC &= 0xF0; |
#define mLED_1 LATCbits.LATC0 |
#define mLED_2 LATCbits.LATC1 |
#define mLED_3 LATCbits.LATC2 |
#define mLED_4 LATCbits.LATC3 |
#define mGetLED_1() mLED_1 |
#define mGetLED_2() mLED_2 |
#define mGetLED_3() mLED_3 |
#define mGetLED_4() mLED_4 |
#define mLED_1_On() mLED_1 = 1; |
#define mLED_2_On() mLED_2 = 1; |
#define mLED_3_On() mLED_3 = 1; |
#define mLED_4_On() mLED_4 = 1; |
#define mLED_1_Off() mLED_1 = 0; |
#define mLED_2_Off() mLED_2 = 0; |
#define mLED_3_Off() mLED_3 = 0; |
#define mLED_4_Off() mLED_4 = 0; |
#define mLED_1_Toggle() mLED_1 = !mLED_1; |
#define mLED_2_Toggle() mLED_2 = !mLED_2; |
#define mLED_3_Toggle() mLED_3 = !mLED_3; |
#define mLED_4_Toggle() mLED_4 = !mLED_4; |
/** SWITCH *********************************************************/ |
#define mInitSwitch2() //TRISAbits.TRISA3=1 |
//only one switch available so double duty |
#define mInitSwitch3() //TRISAbits.TRISA3=1 |
#define sw2 PORTAbits.RA3 |
#define sw3 PORTAbits.RA3 |
#define mInitAllSwitches() mInitSwitch2(); |
/** POT ************************************************************/ |
#define mInitPOT() {TRISBbits.TRISB4=1;ADCON0=0x29;ADCON1=0;ADCON2=0x3E;ADCON2bits.ADFM = 1;} |
#endif //HARDWARE_PROFILE_LOW_PIN_COUNT_USB_DEVELOPMENT_KIT_H |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/HardwareProfile - PIC18F46J50 PIM.h |
---|
0,0 → 1,130 |
/******************************************************************** |
FileName: HardwareProfile - PIC18F46J50 PIM.h |
Dependencies: See INCLUDES section |
Processor: PIC18 USB Microcontrollers |
Hardware: PIC18F46J50 PIM |
Compiler: Microchip C18 |
Company: Microchip Technology, Inc. |
Software License Agreement: |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
Any use in violation of the foregoing restrictions may subject the |
user to criminal sanctions under applicable laws, as well as to |
civil liability for the breach of the terms and conditions of this |
license. |
THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
******************************************************************** |
File Description: |
Change History: |
Rev Date Description |
1.0 11/19/2004 Initial release |
2.1 02/26/2007 Updated for simplicity and to use common |
coding style |
2.3 09/15/2008 Broke out each hardware platform into its own |
"HardwareProfile - xxx.h" file |
********************************************************************/ |
#ifndef HARDWARE_PROFILE_PIC18F46J50_PIM_H |
#define HARDWARE_PROFILE_PIC18F46J50_PIM_H |
/*******************************************************************/ |
/******** USB stack hardware selection options *********************/ |
/*******************************************************************/ |
//This section is the set of definitions required by the MCHPFSUSB |
// framework. These definitions tell the firmware what mode it is |
// running in, and where it can find the results to some information |
// that the stack needs. |
//These definitions are required by every application developed with |
// this revision of the MCHPFSUSB framework. Please review each |
// option carefully and determine which options are desired/required |
// for your application. |
//#define USE_SELF_POWER_SENSE_IO |
#define tris_self_power TRISCbits.TRISC2 // Input |
#define self_power 1 |
//#define USE_USB_BUS_SENSE_IO |
#define tris_usb_bus_sense TRISCbits.TRISC2 // Input |
#define USB_BUS_SENSE 1 |
//Uncomment this to make the output HEX of this project |
// to be able to be bootloaded using the HID bootloader |
#define PROGRAMMABLE_WITH_USB_HID_BOOTLOADER |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/******** Application specific definitions *************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/** Board definition ***********************************************/ |
//These defintions will tell the main() function which board is |
// currently selected. This will allow the application to add |
// the correct configuration bits as wells use the correct |
// initialization functions for the board. These defitions are only |
// required in the stack provided demos. They are not required in |
// final application design. |
#define DEMO_BOARD PIC18F46J50_PIM |
#define PIC18F46J50_PIM |
#define CLOCK_FREQ 48000000 |
#define GetSystemClock() CLOCK_FREQ |
#define GetInstructionClock() GetSystemClock() |
/** LED ************************************************************/ |
#define mInitAllLEDs() LATE &= 0xFC; TRISE &= 0xFC; |
#define mLED_1 LATEbits.LATE0 |
#define mLED_2 LATEbits.LATE1 |
#define mLED_3 mLED_1 |
#define mLED_4 mLED_2 |
#define mGetLED_1() mLED_1 |
#define mGetLED_2() mLED_2 |
#define mGetLED_3() mLED_3 |
#define mGetLED_4() mLED_4 |
#define mLED_1_On() mLED_1 = 1; |
#define mLED_2_On() mLED_2 = 1; |
#define mLED_3_On() mLED_3 = 1; |
#define mLED_4_On() mLED_4 = 1; |
#define mLED_1_Off() mLED_1 = 0; |
#define mLED_2_Off() mLED_2 = 0; |
#define mLED_3_Off() mLED_3 = 0; |
#define mLED_4_Off() mLED_4 = 0; |
#define mLED_1_Toggle() mLED_1 = !mLED_1; |
#define mLED_2_Toggle() mLED_2 = !mLED_2; |
#define mLED_3_Toggle() mLED_3 = !mLED_3; |
#define mLED_4_Toggle() mLED_4 = !mLED_4; |
/** SWITCH *********************************************************/ |
#define mInitSwitch2() TRISBbits.TRISB2=1; |
#define mInitSwitch3() mInitSwitch2(); |
#define mInitAllSwitches() mInitSwitch2(); |
#define sw2 PORTBbits.RB2 |
#define sw3 PORTBbits.RB2 |
/** POT ************************************************************/ |
#define mInitPOT() {TRISAbits.TRISA0=1; \ |
ANCON0bits.PCFG0 = 0; \ |
ADCON0=0x01; \ |
ADCON1=0xBE;} // POT on HPC Explorer |
#endif //HARDWARE_PROFILE_PIC18F46J50_PIM_H |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/HardwareProfile - PIC18F87J50 PIM.h |
---|
0,0 → 1,150 |
/******************************************************************** |
FileName: HardwareProfile - PIC18F87J50 PIM.h |
Dependencies: See INCLUDES section |
Processor: PIC18 USB Microcontrollers |
Hardware: PIC18F87J50 PIM |
Compiler: Microchip C18 |
Company: Microchip Technology, Inc. |
Software License Agreement: |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
Any use in violation of the foregoing restrictions may subject the |
user to criminal sanctions under applicable laws, as well as to |
civil liability for the breach of the terms and conditions of this |
license. |
THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
******************************************************************** |
File Description: |
Change History: |
Rev Date Description |
1.0 11/19/2004 Initial release |
2.1 02/26/2007 Updated for simplicity and to use common |
coding style |
2.3 09/15/2008 Broke out each hardware platform into its own |
"HardwareProfile - xxx.h" file |
********************************************************************/ |
#ifndef HARDWARE_PROFILE_PIC18F87J50_PIM_H |
#define HARDWARE_PROFILE_PIC18F87J50_PIM_H |
/*******************************************************************/ |
/******** USB stack hardware selection options *********************/ |
/*******************************************************************/ |
//This section is the set of definitions required by the MCHPFSUSB |
// framework. These definitions tell the firmware what mode it is |
// running in, and where it can find the results to some information |
// that the stack needs. |
//These definitions are required by every application developed with |
// this revision of the MCHPFSUSB framework. Please review each |
// option carefully and determine which options are desired/required |
// for your application. |
/** USB ************************************************************/ |
//The PIC18F87J50 FS USB Plug-In Module supports the USE_USB_BUS_SENSE_IO |
//feature. The USE_SELF_POWER_SENSE_IO feature is not implemented on the |
//circuit board, so the USE_SELF_POWER_SENSE_IO define should always be |
//commented for this hardware platform. |
//#define USE_SELF_POWER_SENSE_IO |
#define tris_self_power TRISAbits.TRISA2 // Input |
#if defined(USE_SELF_POWER_SENSE_IO) |
#define self_power PORTAbits.RA2 |
#else |
#define self_power 1 |
#endif |
//#define USE_USB_BUS_SENSE_IO //JP1 must be in R-U position to use this feature on this board |
#define tris_usb_bus_sense TRISBbits.TRISB5 // Input |
#if defined(USE_USB_BUS_SENSE_IO) |
#define USB_BUS_SENSE PORTBbits.RB5 |
#else |
#define USB_BUS_SENSE 1 |
#endif |
//Uncomment this to make the output HEX of this project |
// to be able to be bootloaded using the HID bootloader |
#define PROGRAMMABLE_WITH_USB_HID_BOOTLOADER |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/******** Application specific definitions *************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/** Board definition ***********************************************/ |
//These defintions will tell the main() function which board is |
// currently selected. This will allow the application to add |
// the correct configuration bits as wells use the correct |
// initialization functions for the board. These defitions are only |
// required in the stack provided demos. They are not required in |
// final application design. |
#define DEMO_BOARD PIC18F87J50_PIM |
#define PIC18F87J50_PIM |
#define CLOCK_FREQ 48000000 |
#define GetSystemClock() CLOCK_FREQ |
#define GetInstructionClock() CLOCK_FREQ |
/** LED ************************************************************/ |
#define mInitAllLEDs() {LATE &= 0xFC; TRISE &= 0xFC; LATD &= 0xF3; TRISD &= 0xF3;} |
#define mLED_1 LATEbits.LATE0 |
#define mLED_2 LATEbits.LATE1 |
#define mLED_3 LATDbits.LATD2 |
#define mLED_4 LATDbits.LATD3 |
#define mGetLED_1() mLED_1 |
#define mGetLED_2() mLED_2 |
#define mGetLED_3() mLED_3 |
#define mGetLED_4() mLED_4 |
#define mLED_1_On() mLED_1 = 1; |
#define mLED_2_On() mLED_2 = 1; |
#define mLED_3_On() mLED_3 = 1; |
#define mLED_4_On() mLED_4 = 1; |
#define mLED_1_Off() mLED_1 = 0; |
#define mLED_2_Off() mLED_2 = 0; |
#define mLED_3_Off() mLED_3 = 0; |
#define mLED_4_Off() mLED_4 = 0; |
#define mLED_1_Toggle() mLED_1 = !mLED_1; |
#define mLED_2_Toggle() mLED_2 = !mLED_2; |
#define mLED_3_Toggle() mLED_3 = !mLED_3; |
#define mLED_4_Toggle() mLED_4 = !mLED_4; |
/** SWITCH *********************************************************/ |
#define mInitAllSwitches() TRISBbits.TRISB4=1; |
#define mInitSwitch2() TRISBbits.TRISB4=1; |
#define mInitSwitch3() TRISBbits.TRISB4=1; |
#define sw2 PORTBbits.RB4 |
#define sw3 PORTBbits.RB4 |
/** POT ************************************************************/ |
#define mInitPOT() {TRISAbits.TRISA0=1; \ |
WDTCONbits.ADSHR = 1; \ |
ANCON0bits.PCFG0 = 1; \ |
WDTCONbits.ADSHR = 0; \ |
ADCON0=0x01; \ |
ADCON1=0xBE;} // POT on HPC Explorer |
/** I 2 C T E M P S E N S E *************************************/ |
#define mInitI2CPins() TRISC |= 0x18; // RC3 and RC4 are I2C |
#endif //HARDWARE_PROFILE_PIC18F87J50_PIM_H |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/HardwareProfile - PIC24F Starter Kit.h |
---|
0,0 → 1,129 |
/******************************************************************** |
FileName: HardwareProfile - PIC24F Starter Kit.h |
Dependencies: See INCLUDES section |
Processor: PIC24FJ256GB106 |
Hardware: PIC24F Starter Kit |
Compiler: Microchip C30 |
Company: Microchip Technology, Inc. |
Software License Agreement: |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
Any use in violation of the foregoing restrictions may subject the |
user to criminal sanctions under applicable laws, as well as to |
civil liability for the breach of the terms and conditions of this |
license. |
THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
******************************************************************** |
File Description: |
Change History: |
Rev Date Description |
1.0 11/19/2004 Initial release |
2.1 02/26/2007 Updated for simplicity and to use common |
coding style |
2.3 09/15/2008 Broke out each hardware platform into its own |
"HardwareProfile - xxx.h" file |
********************************************************************/ |
#ifndef HARDWARE_PROFILE_PIC24F_STARTER_KIT_H |
#define HARDWARE_PROFILE_PIC24F_STARTER_KIT_H |
/*******************************************************************/ |
/******** USB stack hardware selection options *********************/ |
/*******************************************************************/ |
//This section is the set of definitions required by the MCHPFSUSB |
// framework. These definitions tell the firmware what mode it is |
// running in, and where it can find the results to some information |
// that the stack needs. |
//These definitions are required by every application developed with |
// this revision of the MCHPFSUSB framework. Please review each |
// option carefully and determine which options are desired/required |
// for your application. |
//#define USE_SELF_POWER_SENSE_IO |
#define tris_self_power TRISAbits.TRISA2 // Input |
#define self_power 1 |
//#define USE_USB_BUS_SENSE_IO |
#define tris_usb_bus_sense U1OTGSTATbits.SESVD //TRISBbits.TRISB5 // Input |
#define USB_BUS_SENSE U1OTGSTATbits.SESVD |
//Uncomment this to make the output HEX of this project |
// to be able to be bootloaded using the HID bootloader |
#define PROGRAMMABLE_WITH_USB_HID_BOOTLOADER |
//If the application is going to be used with the HID bootloader |
// then this will provide a function for the application to |
// enter the bootloader from the application (optional) |
#if defined(PROGRAMMABLE_WITH_USB_HID_BOOTLOADER) |
#define EnterBootloader() __asm__("goto 0x400") |
#endif |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/******** Application specific definitions *************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/** Board definition ***********************************************/ |
//These defintions will tell the main() function which board is |
// currently selected. This will allow the application to add |
// the correct configuration bits as wells use the correct |
// initialization functions for the board. These defitions are only |
// required in the stack provided demos. They are not required in |
// final application design. |
#define DEMO_BOARD PIC24F_STARTER_KIT |
#define PIC24F_STARTER_KIT |
#define CLOCK_FREQ 32000000 |
/** LED ************************************************************/ |
#define mInitAllLEDs() LATG &= 0xFE1F; TRISG &= 0xFE1F; LATF &= 0xFFCF; TRISF &= 0xFFCF; //G6,7,8,9 and F4,5 |
#define mGetLED_1() (TRISG & ~0x0180?1:0) |
#define mGetLED_2() (TRISG & ~0x0060?1:0) |
#define mGetLED_3() (TRISF & ~0x0030?1:0) |
#define mGetLED_4() |
#define mLED_1_On() TRISG |= 0x0180; |
#define mLED_2_On() TRISG |= 0x0060; |
#define mLED_3_On() TRISF |= 0x0030; |
#define mLED_4_On() |
#define mLED_1_Off() TRISG &= ~0x0180; |
#define mLED_2_Off() TRISG &= ~0x0060; |
#define mLED_3_Off() TRISF &= ~0x0030; |
#define mLED_4_Off() |
#define mLED_1_Toggle() TRISG ^= 0x0180; |
#define mLED_2_Toggle() TRISG ^= 0x0060; |
#define mLED_3_Toggle() TRISF ^= 0x0030; |
#define mLED_4_Toggle() |
/** SWITCH *********************************************************/ |
#define mInitSwitch2() TRISDbits.TRISD6=1; |
#define mInitSwitch3() TRISDbits.TRISD7=1; |
#define mInitAllSwitches() mInitSwitch2();mInitSwitch3(); |
#define sw2 PORTDbits.RD6 |
#define sw3 PORTDbits.RD7 |
/** POT ************************************************************/ |
#define mInitPOT() {AD1PCFGLbits.PCFG0 = 0; AD1CON2bits.VCFG = 0x0; AD1CON3bits.ADCS = 0xFF; AD1CON1bits.SSRC = 0x0; AD1CON3bits.SAMC = 0b00001; AD1CON1bits.FORM = 0b00; AD1CON2bits.SMPI = 0x0; AD1CON1bits.ADON = 1;} |
#endif //HARDWARE_PROFILE_PIC24F_STARTER_KIT_H |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/HardwareProfile - PIC24FJ256GB110 PIM.h |
---|
0,0 → 1,136 |
/******************************************************************** |
FileName: HardwareProfile - PIC24FJ256GB110 PIM.h |
Dependencies: See INCLUDES section |
Processor: PIC24FJ256GB110 |
Hardware: PIC24FJ256GB110 PIM |
Compiler: Microchip C30 |
Company: Microchip Technology, Inc. |
Software License Agreement: |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
Any use in violation of the foregoing restrictions may subject the |
user to criminal sanctions under applicable laws, as well as to |
civil liability for the breach of the terms and conditions of this |
license. |
THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
******************************************************************** |
File Description: |
Change History: |
Rev Date Description |
1.0 11/19/2004 Initial release |
2.1 02/26/2007 Updated for simplicity and to use common |
coding style |
2.3 09/15/2008 Broke out each hardware platform into its own |
"HardwareProfile - xxx.h" file |
********************************************************************/ |
#ifndef HARDWARE_PROFILE_PIC24FJ256GB110_PIM_H |
#define HARDWARE_PROFILE_PIC24FJ256GB110_PIM_H |
/*******************************************************************/ |
/******** USB stack hardware selection options *********************/ |
/*******************************************************************/ |
//This section is the set of definitions required by the MCHPFSUSB |
// framework. These definitions tell the firmware what mode it is |
// running in, and where it can find the results to some information |
// that the stack needs. |
//These definitions are required by every application developed with |
// this revision of the MCHPFSUSB framework. Please review each |
// option carefully and determine which options are desired/required |
// for your application. |
//#define USE_SELF_POWER_SENSE_IO |
#define tris_self_power TRISAbits.TRISA2 // Input |
#define self_power 1 |
//#define USE_USB_BUS_SENSE_IO |
#define tris_usb_bus_sense TRISBbits.TRISB5 // Input |
#define USB_BUS_SENSE 1 |
//Uncomment this to make the output HEX of this project |
// to be able to be bootloaded using the HID bootloader |
#define PROGRAMMABLE_WITH_USB_HID_BOOTLOADER |
//If the application is going to be used with the HID bootloader |
// then this will provide a function for the application to |
// enter the bootloader from the application (optional) |
#if defined(PROGRAMMABLE_WITH_USB_HID_BOOTLOADER) |
#define EnterBootloader() __asm__("goto 0x400") |
#endif |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/******** Application specific definitions *************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/** Board definition ***********************************************/ |
//These defintions will tell the main() function which board is |
// currently selected. This will allow the application to add |
// the correct configuration bits as wells use the correct |
// initialization functions for the board. These defitions are only |
// required in the stack provided demos. They are not required in |
// final application design. |
#define DEMO_BOARD PIC24FJ256GB110_PIM |
#define EXPLORER_16 |
#define PIC24FJ256GB110_PIM |
#define CLOCK_FREQ 32000000 |
#define GetSystemClock() CLOCK_FREQ |
#define GetInstructionClock() GetSystemClock() |
/** LED ************************************************************/ |
#define mInitAllLEDs() LATA &= 0xF0; TRISA &= 0xF0; |
#define mLED_1 LATAbits.LATA0 |
#define mLED_2 LATAbits.LATA1 |
#define mLED_3 LATAbits.LATA2 |
#define mLED_4 LATAbits.LATA3 |
#define mGetLED_1() mLED_1 |
#define mGetLED_2() mLED_2 |
#define mGetLED_3() mLED_3 |
#define mGetLED_4() mLED_4 |
#define mLED_1_On() mLED_1 = 1; |
#define mLED_2_On() mLED_2 = 1; |
#define mLED_3_On() mLED_3 = 1; |
#define mLED_4_On() mLED_4 = 1; |
#define mLED_1_Off() mLED_1 = 0; |
#define mLED_2_Off() mLED_2 = 0; |
#define mLED_3_Off() mLED_3 = 0; |
#define mLED_4_Off() mLED_4 = 0; |
#define mLED_1_Toggle() mLED_1 = !mLED_1; |
#define mLED_2_Toggle() mLED_2 = !mLED_2; |
#define mLED_3_Toggle() mLED_3 = !mLED_3; |
#define mLED_4_Toggle() mLED_4 = !mLED_4; |
/** SWITCH *********************************************************/ |
#define mInitSwitch2() TRISDbits.TRISD6=1; |
#define mInitSwitch3() TRISDbits.TRISD7=1; |
#define mInitAllSwitches() mInitSwitch2();mInitSwitch3(); |
#define sw2 PORTDbits.RD6 |
#define sw3 PORTDbits.RD7 |
/** POT ************************************************************/ |
#define mInitPOT() {AD1PCFGLbits.PCFG5 = 0; AD1CON2bits.VCFG = 0x0; AD1CON3bits.ADCS = 0xFF; AD1CON1bits.SSRC = 0x0; AD1CON3bits.SAMC = 0b10000; AD1CON1bits.FORM = 0b00; AD1CON2bits.SMPI = 0x0; AD1CON1bits.ADON = 1;} |
#endif //HARDWARE_PROFILE_PIC24FJ256GB110_PIM_H |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/HardwareProfile - PIC32MX460F512L PIM.h |
---|
0,0 → 1,121 |
/******************************************************************** |
FileName: HardwareProfile - PIC32MX460F512L PIM.h |
Dependencies: See INCLUDES section |
Processor: PIC32 USB Microcontrollers |
Hardware: PIC32MX460F512L PIM |
Compiler: Microchip C32 (for PIC32) |
Company: Microchip Technology, Inc. |
Software License Agreement: |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
Any use in violation of the foregoing restrictions may subject the |
user to criminal sanctions under applicable laws, as well as to |
civil liability for the breach of the terms and conditions of this |
license. |
THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
******************************************************************** |
File Description: |
Change History: |
Rev Date Description |
1.0 11/19/2004 Initial release |
2.1 02/26/2007 Updated for simplicity and to use common |
coding style |
2.3 09/15/2008 Broke out each hardware platform into its own |
"HardwareProfile - xxx.h" file |
********************************************************************/ |
#ifndef HARDWARE_PROFILE_PIC32MX460F512L_PIM_H |
#define HARDWARE_PROFILE_PIC32MX460F512L_PIM_H |
/*******************************************************************/ |
/******** USB stack hardware selection options *********************/ |
/*******************************************************************/ |
//This section is the set of definitions required by the MCHPFSUSB |
// framework. These definitions tell the firmware what mode it is |
// running in, and where it can find the results to some information |
// that the stack needs. |
//These definitions are required by every application developed with |
// this revision of the MCHPFSUSB framework. Please review each |
// option carefully and determine which options are desired/required |
// for your application. |
//#define USE_SELF_POWER_SENSE_IO |
#define tris_self_power TRISAbits.TRISA2 // Input |
#define self_power 1 |
//#define USE_USB_BUS_SENSE_IO |
#define tris_usb_bus_sense TRISBbits.TRISB5 // Input |
#define USB_BUS_SENSE 1 |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/******** Application specific definitions *************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/** Board definition ***********************************************/ |
//These defintions will tell the main() function which board is |
// currently selected. This will allow the application to add |
// the correct configuration bits as wells use the correct |
// initialization functions for the board. These defitions are only |
// required in the stack provided demos. They are not required in |
// final application design. |
#define DEMO_BOARD PIC32MX460F512L_PIM |
#define EXPLORER_16 |
#define PIC32MX460F512L_PIM |
/** LED ************************************************************/ |
#define mInitAllLEDs() LATA &= 0xFF03; TRISA &= 0xFF03; |
#define mLED_1 LATAbits.LATA2 |
#define mLED_2 LATAbits.LATA3 |
#define mLED_3 LATAbits.LATA6 |
#define mLED_4 LATAbits.LATA7 |
#define mGetLED_1() mLED_1 |
#define mGetLED_2() mLED_2 |
#define mGetLED_3() mLED_3 |
#define mGetLED_4() mLED_4 |
#define mLED_1_On() mLED_1 = 1; |
#define mLED_2_On() mLED_2 = 1; |
#define mLED_3_On() mLED_3 = 1; |
#define mLED_4_On() mLED_4 = 1; |
#define mLED_1_Off() mLED_1 = 0; |
#define mLED_2_Off() mLED_2 = 0; |
#define mLED_3_Off() mLED_3 = 0; |
#define mLED_4_Off() mLED_4 = 0; |
#define mLED_1_Toggle() mLED_1 = !mLED_1; |
#define mLED_2_Toggle() mLED_2 = !mLED_2; |
#define mLED_3_Toggle() mLED_3 = !mLED_3; |
#define mLED_4_Toggle() mLED_4 = !mLED_4; |
/** SWITCH *********************************************************/ |
#define mInitSwitch2() TRISDbits.TRISD6=1; |
#define mInitSwitch3() TRISDbits.TRISD7=1; |
#define mInitAllSwitches() mInitSwitch2();mInitSwitch3(); |
#define sw2 PORTDbits.RD6 |
#define sw3 PORTDbits.RD7 |
/** POT ************************************************************/ |
#define mInitPOT() {AD1PCFGbits.PCFG5 = 0; AD1CON2bits.VCFG = 0x0; AD1CON3bits.ADCS = 0xFF; AD1CON1bits.SSRC = 0x0; AD1CON3bits.SAMC = 0x10; AD1CON1bits.FORM = 0x0; AD1CON2bits.SMPI = 0x0; AD1CON1bits.ADON = 1;} |
#endif //HARDWARE_PROFILE_PIC32MX460F512L_PIM_H |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/HardwareProfile - PICDEM FSUSB.bak |
---|
0,0 → 1,207 |
/******************************************************************** |
FileName: HardwareProfile - PICDEM FSUSB.h |
Dependencies: See INCLUDES section |
Processor: PIC18 USB Microcontrollers |
Hardware: PICDEM FSUSB |
Compiler: Microchip C18 |
Company: Microchip Technology, Inc. |
Software License Agreement: |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
Any use in violation of the foregoing restrictions may subject the |
user to criminal sanctions under applicable laws, as well as to |
civil liability for the breach of the terms and conditions of this |
license. |
THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
******************************************************************** |
File Description: |
Change History: |
Rev Date Description |
1.0 11/19/2004 Initial release |
2.1 02/26/2007 Updated for simplicity and to use common |
coding style |
2.3 09/15/2008 Broke out each hardware platform into its own |
"HardwareProfile - xxx.h" file |
********************************************************************/ |
#ifndef HARDWARE_PROFILE_PICDEM_FSUSB_H |
#define HARDWARE_PROFILE_PICDEM_FSUSB_H |
/*******************************************************************/ |
/******** USB stack hardware selection options *********************/ |
/*******************************************************************/ |
//This section is the set of definitions required by the MCHPFSUSB |
// framework. These definitions tell the firmware what mode it is |
// running in, and where it can find the results to some information |
// that the stack needs. |
//These definitions are required by every application developed with |
// this revision of the MCHPFSUSB framework. Please review each |
// option carefully and determine which options are desired/required |
// for your application. |
//The PICDEM FS USB Demo Board platform supports the USE_SELF_POWER_SENSE_IO |
//and USE_USB_BUS_SENSE_IO features. Uncomment the below line(s) if |
//it is desireable to use one or both of the features. |
//#define USE_SELF_POWER_SENSE_IO |
#define tris_self_power TRISAbits.TRISA2 // Input |
#if defined(USE_SELF_POWER_SENSE_IO) |
#define self_power PORTAbits.RA2 |
#else |
#define self_power 1 |
#endif |
//#define USE_USB_BUS_SENSE_IO |
#define tris_usb_bus_sense TRISAbits.TRISA1 // Input |
#if defined(USE_USB_BUS_SENSE_IO) |
#define USB_BUS_SENSE PORTAbits.RA1 |
#else |
#define USB_BUS_SENSE 1 |
#endif |
//Uncomment the following line to make the output HEX of this |
// project work with the MCHPUSB Bootloader |
//#define PROGRAMMABLE_WITH_USB_MCHPUSB_BOOTLOADER |
//Uncomment the following line to make the output HEX of this |
// project work with the HID Bootloader |
#define PROGRAMMABLE_WITH_USB_HID_BOOTLOADER |
/*******************************************************************/ |
/******** MDD File System selection options ************************/ |
/*******************************************************************/ |
#define USE_PIC18 |
#define ERASE_BLOCK_SIZE 64 |
#define WRITE_BLOCK_SIZE 32 |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/******** Application specific definitions *************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/** Board definition ***********************************************/ |
//These defintions will tell the main() function which board is |
// currently selected. This will allow the application to add |
// the correct configuration bits as wells use the correct |
// initialization functions for the board. These defitions are only |
// required in the stack provided demos. They are not required in |
// final application design. |
#define DEMO_BOARD PICDEM_FS_USB |
#define PICDEM_FS_USB |
#define CLOCK_FREQ 48000000 |
/** LED ************************************************************/ |
#define mInitAllLEDs() LATD &= 0xF0; TRISD &= 0xF0; |
#define mLED_1 LATDbits.LATD0 |
#define mLED_2 LATDbits.LATD1 |
#define mLED_3 LATDbits.LATD2 |
#define mLED_4 LATDbits.LATD3 |
#define mGetLED_1() mLED_1 |
#define mGetLED_2() mLED_2 |
#define mGetLED_3() mLED_3 |
#define mGetLED_4() mLED_4 |
#define mLED_1_On() mLED_1 = 1; |
#define mLED_2_On() mLED_2 = 1; |
#define mLED_3_On() mLED_3 = 1; |
#define mLED_4_On() mLED_4 = 1; |
#define mLED_1_Off() mLED_1 = 0; |
#define mLED_2_Off() mLED_2 = 0; |
#define mLED_3_Off() mLED_3 = 0; |
#define mLED_4_Off() mLED_4 = 0; |
#define mLED_1_Toggle() mLED_1 = !mLED_1; |
#define mLED_2_Toggle() mLED_2 = !mLED_2; |
#define mLED_3_Toggle() mLED_3 = !mLED_3; |
#define mLED_4_Toggle() mLED_4 = !mLED_4; |
/** SWITCH *********************************************************/ |
#define mInitAllSwitches() TRISBbits.TRISB4=1;TRISBbits.TRISB5=1; |
#define mInitSwitch2() TRISBbits.TRISB4=1; |
#define mInitSwitch3() TRISBbits.TRISB5=1; |
#define sw2 PORTBbits.RB4 |
#define sw3 PORTBbits.RB5 |
/** POT ************************************************************/ |
#define mInitPOT() {TRISAbits.TRISA0=1;ADCON0=0x01;ADCON2=0x3C;ADCON2bits.ADFM = 1;} |
/** SPI : Chip Select Lines ****************************************/ |
#define tris_cs_temp_sensor TRISBbits.TRISB2 // Output |
#define cs_temp_sensor LATBbits.LATB2 |
/** USB external transceiver interface (optional) ******************/ |
#define tris_usb_vpo TRISBbits.TRISB3 // Output |
#define tris_usb_vmo TRISBbits.TRISB2 // Output |
#define tris_usb_rcv TRISAbits.TRISA4 // Input |
#define tris_usb_vp TRISCbits.TRISC5 // Input |
#define tris_usb_vm TRISCbits.TRISC4 // Input |
#define tris_usb_oe TRISCbits.TRISC1 // Output |
#define tris_usb_suspnd TRISAbits.TRISA3 // Output |
/** TRIS ***********************************************************/ |
#define INPUT_PIN 1 |
#define OUTPUT_PIN 0 |
#if defined(YAS) |
#define RXTX LATBbits.LATB5 |
#else |
#define RXTX LATAbits.LATA2 |
#endif |
#define BPF_S0 LATAbits.LATA0 |
#define BPF_S1 LATAbits.LATA1 |
#if defined(YAS) |
#define BPF_S2 LATAbits.LATA2 |
#endif |
#define BPF_S0_STATE PORTAbits.RA0 |
#define BPF_S1_STATE PORTAbits.RA1 |
#if defined(YAS) |
#define BPF_S2_STATE PORTAbits.RA2 |
#endif |
#define LPF_0 LATAbits.LATA3 |
#define LPF_1 LATAbits.LATA4 |
#define LPF_2 LATAbits.LATA5 |
#if defined(YAS) |
#else |
#define LPF_3 LATBbits.LATB2 |
#define LPF_4 LATBbits.LATB3 |
#define LPF_5 LATBbits.LATB4 |
#define LPF_6 LATBbits.LATB5 |
#endif |
/** S W I T C H *****************************************************/ |
#define mInitSwitch() TRISCbits.TRISC2 = 1; |
#define UserSW PORTCbits.RC2 |
#define mLED_Both_Off() {mLED_1_Off(); mLED_2_Off();} |
#define mLED_Both_On() {mLED_1_On(); mLED_2_On();} |
#define mLED_Only_1_On() {mLED_1_On(); mLED_2_Off();} |
#define mLED_Only_2_On() {mLED_1_Off(); mLED_2_On();} |
#endif //HARDWARE_PROFILE_PICDEM_FSUSB_H |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/HardwareProfile - PICDEM FSUSB.h |
---|
0,0 → 1,210 |
/******************************************************************** |
FileName: HardwareProfile - PICDEM FSUSB.h |
Dependencies: See INCLUDES section |
Processor: PIC18 USB Microcontrollers |
Hardware: PICDEM FSUSB |
Compiler: Microchip C18 |
Company: Microchip Technology, Inc. |
Software License Agreement: |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
Any use in violation of the foregoing restrictions may subject the |
user to criminal sanctions under applicable laws, as well as to |
civil liability for the breach of the terms and conditions of this |
license. |
THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
******************************************************************** |
File Description: |
Change History: |
Rev Date Description |
1.0 11/19/2004 Initial release |
2.1 02/26/2007 Updated for simplicity and to use common |
coding style |
2.3 09/15/2008 Broke out each hardware platform into its own |
"HardwareProfile - xxx.h" file |
********************************************************************/ |
#ifndef HARDWARE_PROFILE_PICDEM_FSUSB_H |
#define HARDWARE_PROFILE_PICDEM_FSUSB_H |
/*******************************************************************/ |
/******** USB stack hardware selection options *********************/ |
/*******************************************************************/ |
//This section is the set of definitions required by the MCHPFSUSB |
// framework. These definitions tell the firmware what mode it is |
// running in, and where it can find the results to some information |
// that the stack needs. |
//These definitions are required by every application developed with |
// this revision of the MCHPFSUSB framework. Please review each |
// option carefully and determine which options are desired/required |
// for your application. |
//The PICDEM FS USB Demo Board platform supports the USE_SELF_POWER_SENSE_IO |
//and USE_USB_BUS_SENSE_IO features. Uncomment the below line(s) if |
//it is desireable to use one or both of the features. |
//#define USE_SELF_POWER_SENSE_IO |
#define tris_self_power TRISAbits.TRISA2 // Input |
#if defined(USE_SELF_POWER_SENSE_IO) |
#define self_power PORTAbits.RA2 |
#else |
#define self_power 1 |
#endif |
//#define USE_USB_BUS_SENSE_IO |
#define tris_usb_bus_sense TRISAbits.TRISA1 // Input |
#if defined(USE_USB_BUS_SENSE_IO) |
#define USB_BUS_SENSE PORTAbits.RA1 |
#else |
#define USB_BUS_SENSE 1 |
#endif |
//Uncomment the following line to make the output HEX of this |
// project work with the MCHPUSB Bootloader |
//#define PROGRAMMABLE_WITH_USB_MCHPUSB_BOOTLOADER |
//Uncomment the following line to make the output HEX of this |
// project work with the HID Bootloader |
#define PROGRAMMABLE_WITH_USB_HID_BOOTLOADER |
/*******************************************************************/ |
/******** MDD File System selection options ************************/ |
/*******************************************************************/ |
#define USE_PIC18 |
#define ERASE_BLOCK_SIZE 64 |
#define WRITE_BLOCK_SIZE 32 |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/******** Application specific definitions *************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/** Board definition ***********************************************/ |
//These defintions will tell the main() function which board is |
// currently selected. This will allow the application to add |
// the correct configuration bits as wells use the correct |
// initialization functions for the board. These defitions are only |
// required in the stack provided demos. They are not required in |
// final application design. |
#define DEMO_BOARD PICDEM_FS_USB |
#define PICDEM_FS_USB |
#define CLOCK_FREQ 48000000 |
/** LED ************************************************************/ |
#define mInitAllLEDs() LATD &= 0xF0; TRISD &= 0xF0; |
#define mLED_1 LATDbits.LATD0 |
#define mLED_2 LATDbits.LATD1 |
#define mLED_3 LATDbits.LATD2 |
#define mLED_4 LATDbits.LATD3 |
#define mGetLED_1() mLED_1 |
#define mGetLED_2() mLED_2 |
#define mGetLED_3() mLED_3 |
#define mGetLED_4() mLED_4 |
#define mLED_1_On() mLED_1 = 1; |
#define mLED_2_On() mLED_2 = 1; |
#define mLED_3_On() mLED_3 = 1; |
#define mLED_4_On() mLED_4 = 1; |
#define mLED_1_Off() mLED_1 = 0; |
#define mLED_2_Off() mLED_2 = 0; |
#define mLED_3_Off() mLED_3 = 0; |
#define mLED_4_Off() mLED_4 = 0; |
#define mLED_1_Toggle() mLED_1 = !mLED_1; |
#define mLED_2_Toggle() mLED_2 = !mLED_2; |
#define mLED_3_Toggle() mLED_3 = !mLED_3; |
#define mLED_4_Toggle() mLED_4 = !mLED_4; |
/** SWITCH *********************************************************/ |
#define mInitAllSwitches() TRISBbits.TRISB4=1;TRISBbits.TRISB5=1; |
#define mInitSwitch2() TRISBbits.TRISB4=1; |
#define mInitSwitch3() TRISBbits.TRISB5=1; |
#define sw2 PORTBbits.RB4 |
#define sw3 PORTBbits.RB5 |
/** POT ************************************************************/ |
#define mInitPOT() {TRISAbits.TRISA0=1;ADCON0=0x01;ADCON2=0x3C;ADCON2bits.ADFM = 1;} |
/** SPI : Chip Select Lines ****************************************/ |
#define tris_cs_temp_sensor TRISBbits.TRISB2 // Output |
#define cs_temp_sensor LATBbits.LATB2 |
/** USB external transceiver interface (optional) ******************/ |
#define tris_usb_vpo TRISBbits.TRISB3 // Output |
#define tris_usb_vmo TRISBbits.TRISB2 // Output |
#define tris_usb_rcv TRISAbits.TRISA4 // Input |
#define tris_usb_vp TRISCbits.TRISC5 // Input |
#define tris_usb_vm TRISCbits.TRISC4 // Input |
#define tris_usb_oe TRISCbits.TRISC1 // Output |
#define tris_usb_suspnd TRISAbits.TRISA3 // Output |
/** TRIS ***********************************************************/ |
#define INPUT_PIN 1 |
#define OUTPUT_PIN 0 |
#if defined(YAS) |
#define RXTX LATBbits.LATB5 |
#else |
#define RXTX LATAbits.LATA2 |
#endif |
#define BPF_S0 LATAbits.LATA0 |
#define BPF_S1 LATAbits.LATA1 |
#if defined(YAS) |
#define BPF_S2 LATAbits.LATA2 |
#endif |
#define BPF_S0_STATE PORTAbits.RA0 |
#define BPF_S1_STATE PORTAbits.RA1 |
#if defined(YAS) |
#define BPF_S2_STATE PORTAbits.RA2 |
#endif |
#define PADDLE_DIT PORTBbits.RB6 |
#define PADDLE_DAH PORTBbits.RB7 |
#define LPF_0 LATAbits.LATA3 |
#define LPF_1 LATAbits.LATA4 |
#define LPF_2 LATAbits.LATA5 |
#if defined(YAS) |
#else |
#define LPF_3 LATBbits.LATB2 |
#define LPF_4 LATBbits.LATB3 |
#define LPF_5 LATBbits.LATB4 |
#define LPF_6 LATBbits.LATB5 |
#endif |
/** S W I T C H *****************************************************/ |
#define mInitSwitch() TRISCbits.TRISC2 = 1; |
#define UserSW PORTCbits.RC2 |
#define mLED_Both_Off() {mLED_1_Off(); mLED_2_Off();} |
#define mLED_Both_On() {mLED_1_On(); mLED_2_On();} |
#define mLED_Only_1_On() {mLED_1_On(); mLED_2_Off();} |
#define mLED_Only_2_On() {mLED_1_Off(); mLED_2_On();} |
#endif //HARDWARE_PROFILE_PICDEM_FSUSB_H |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/HardwareProfile - UBW.h |
---|
0,0 → 1,182 |
/******************************************************************** |
FileName: HardwareProfile - UBW.h |
Dependencies: See INCLUDES section |
Processor: PIC18 USB Microcontrollers |
Hardware: PICDEM FSUSB |
Compiler: Microchip C18 |
Company: Microchip Technology, Inc. |
Software License Agreement: |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
Any use in violation of the foregoing restrictions may subject the |
user to criminal sanctions under applicable laws, as well as to |
civil liability for the breach of the terms and conditions of this |
license. |
THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
******************************************************************** |
File Description: |
Change History: |
Rev Date Description |
1.0 11/19/2004 Initial release |
2.1 02/26/2007 Updated for simplicity and to use common |
coding style |
2.3 09/15/2008 Broke out each hardware platform into its own |
"HardwareProfile - xxx.h" file |
01/15/2009 UBW support |
********************************************************************/ |
#ifndef HARDWARE_PROFILE_UBW_H |
#define HARDWARE_PROFILE_UBW_H |
/*******************************************************************/ |
/******** USB stack hardware selection options *********************/ |
/*******************************************************************/ |
//This section is the set of definitions required by the MCHPFSUSB |
// framework. These definitions tell the firmware what mode it is |
// running in, and where it can find the results to some information |
// that the stack needs. |
//These definitions are required by every application developed with |
// this revision of the MCHPFSUSB framework. Please review each |
// option carefully and determine which options are desired/required |
// for your application. |
//The PICDEM FS USB Demo Board platform supports the USE_SELF_POWER_SENSE_IO |
//and USE_USB_BUS_SENSE_IO features. Uncomment the below line(s) if |
//it is desireable to use one or both of the features. |
//#define USE_SELF_POWER_SENSE_IO |
#define tris_self_power TRISAbits.TRISA2 // Input |
#if defined(USE_SELF_POWER_SENSE_IO) |
#define self_power PORTAbits.RA2 |
#else |
#define self_power 1 |
#endif |
//#define USE_USB_BUS_SENSE_IO |
#define tris_usb_bus_sense TRISAbits.TRISA1 // Input |
#if defined(USE_USB_BUS_SENSE_IO) |
#define USB_BUS_SENSE PORTAbits.RA1 |
#else |
#define USB_BUS_SENSE 1 |
#endif |
//Uncomment the following line to make the output HEX of this |
// project work with the MCHPUSB Bootloader |
#define PROGRAMMABLE_WITH_USB_MCHPUSB_BOOTLOADER |
//Uncomment the following line to make the output HEX of this |
// project work with the HID Bootloader |
//#define PROGRAMMABLE_WITH_USB_HID_BOOTLOADER |
/*******************************************************************/ |
/******** MDD File System selection options ************************/ |
/*******************************************************************/ |
#define USE_PIC18 |
#define ERASE_BLOCK_SIZE 64 |
#define WRITE_BLOCK_SIZE 32 |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/******** Application specific definitions *************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/** Board definition ***********************************************/ |
//These defintions will tell the main() function which board is |
// currently selected. This will allow the application to add |
// the correct configuration bits as wells use the correct |
// initialization functions for the board. These defitions are only |
// required in the stack provided demos. They are not required in |
// final application design. |
#define DEMO_BOARD UBW |
#define UBW |
#define CLOCK_FREQ 48000000 |
// Special UBW emu board by YAS |
// #define YAS |
/** LED ************************************************************/ |
/* On UBW, LED1 = RC0, LED2 = RC1, SW = RC2 */ |
#define mInitAllLEDs() LATC &= 0xFC; TRISC &= 0xFC; |
#define mLED_1 LATCbits.LATC0 |
#define mLED_2 LATCbits.LATC1 |
#define mLED_1_On() mLED_1 = 1; |
#define mLED_2_On() mLED_2 = 1; |
#define mLED_1_Off() mLED_1 = 0; |
#define mLED_2_Off() mLED_2 = 0; |
#define mLED_1_Toggle() mLED_1 = !mLED_1; |
#define mLED_2_Toggle() mLED_2 = !mLED_2; |
#if defined(YAS) |
#define RXTX LATBbits.LATB5 |
#else |
#define RXTX LATAbits.LATA2 |
#endif |
#define BPF_S0 LATAbits.LATA0 |
#define BPF_S1 LATAbits.LATA1 |
#if defined(YAS) |
#define BPF_S2 LATAbits.LATA2 |
#endif |
#define BPF_S0_STATE PORTAbits.RA0 |
#define BPF_S1_STATE PORTAbits.RA1 |
#if defined(YAS) |
#define BPF_S2_STATE PORTAbits.RA2 |
#endif |
#define PADDLE_DIT PORTBbits.RB6 |
#define PADDLE_DAH PORTBbits.RB7 |
#define LPF_0 LATAbits.LATA3 |
#define LPF_1 LATAbits.LATA4 |
#define LPF_2 LATAbits.LATA5 |
#if defined(YAS) |
#else |
#define LPF_3 LATBbits.LATB2 |
#define LPF_4 LATBbits.LATB3 |
#define LPF_5 LATBbits.LATB4 |
#define LPF_6 LATBbits.LATB5 |
#endif |
/** S W I T C H *****************************************************/ |
#define mInitSwitch() TRISCbits.TRISC2 = 1; |
#define UserSW PORTCbits.RC2 |
#define mLED_Both_Off() {mLED_1_Off(); mLED_2_Off();} |
#define mLED_Both_On() {mLED_1_On(); mLED_2_On();} |
#define mLED_Only_1_On() {mLED_1_On(); mLED_2_Off();} |
#define mLED_Only_2_On() {mLED_1_Off(); mLED_2_On();} |
#endif //HARDWARE_PROFILE_UBW_H |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/HardwareProfile - UBW32.h |
---|
0,0 → 1,203 |
/******************************************************************** |
FileName: HardwareProfile - PIC32MX460F512L PIM.h |
Dependencies: See INCLUDES section |
Processor: PIC18 or PIC24 USB Microcontrollers |
Hardware: The code is natively intended to be used on the following |
hardware platforms: PICDEM FS USB Demo Board, |
PIC18F87J50 FS USB Plug-In Module, or |
Explorer 16 + PIC24 USB PIM. The firmware may be |
modified for use on other USB platforms by editing this |
file (HardwareProfile.h). |
Complier: Microchip C18 (for PIC18) or C30 (for PIC24) |
Company: Microchip Technology, Inc. |
Software License Agreement: |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
Any use in violation of the foregoing restrictions may subject the |
user to criminal sanctions under applicable laws, as well as to |
civil liability for the breach of the terms and conditions of this |
license. |
THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
******************************************************************** |
File Description: |
Change History: |
Rev Date Description |
1.0 11/19/2004 Initial release |
2.1 02/26/2007 Updated for simplicity and to use common |
coding style |
********************************************************************/ |
#ifndef HARDWARE_PROFILE_UBW32_H |
#define HARDWARE_PROFILE_UBW32_H |
#include "Compiler.h" |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/******** Application specific definitions *************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/** Board definition ***********************************************/ |
//These defintions will tell the main() function which board is |
// currently selected. This will allow the application to add |
// the correct configuration bits as wells use the correct |
// initialization functions for the board. These defitions are only |
// required in the stack provided demos. They are not required in |
// final application design. |
/** CPU Clock Speed Assignment *************************************/ |
//#define RUN_AT_48MHZ |
//#define RUN_AT_24MHZ |
//#define RUN_AT_60MHZ |
#define RUN_AT_80MHZ |
// Various clock values |
#if defined(RUN_AT_48MHZ) |
#define GetSystemClock() 48000000UL |
#define GetPeripheralClock() 48000000UL |
#define GetInstructionClock() (GetSystemClock()) |
#elif defined(RUN_AT_24MHZ) |
#define GetSystemClock() 24000000UL |
#define GetPeripheralClock() 24000000UL |
#define GetInstructionClock() (GetSystemClock()) |
#elif defined(RUN_AT_60MHZ) |
#define GetSystemClock() (60000000ul) |
#define GetPeripheralClock() (GetSystemClock()) |
#define GetInstructionClock() (GetSystemClock()) |
#elif defined(RUN_AT_80MHZ) |
#define GetSystemClock() (80000000ul) |
#define GetPeripheralClock() (GetSystemClock()) |
#define GetInstructionClock() (GetSystemClock()) |
#else |
#error Choose a speed |
#endif |
#define PROGRAMMABLE_WITH_USB_HID_BOOTLOADER |
/*******************************************************************/ |
/******** USB stack hardware selection options *********************/ |
/*******************************************************************/ |
//This section is the set of definitions required by the MCHPFSUSB |
// framework. These definitions tell the firmware what mode it is |
// running in, and where it can find the results to some information |
// that the stack needs. |
//These definitions are required by every application developed with |
// this revision of the MCHPFSUSB framework. Please review each |
// option carefully and determine which options are desired/required |
// for your application. |
//#define USE_SELF_POWER_SENSE_IO |
#define tris_self_power TRISAbits.TRISA2 // Input |
#define self_power 1 |
//#define USE_USB_BUS_SENSE_IO |
#define tris_usb_bus_sense TRISBbits.TRISB5 // Input |
#define USB_BUS_SENSE 1 |
/*******************************************************************/ |
/******** Device revision workarounds ******************************/ |
/*******************************************************************/ |
//Uncomment this definition to allow for revision B3 silicon to work |
// with this firmware. |
#define PIC32MX460F512L_REV_B3_WORKAROUND |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/******** Application specific definitions *************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/*******************************************************************/ |
/** Board definition ***********************************************/ |
//These defintions will tell the main() function which board is |
// currently selected. This will allow the application to add |
// the correct configuration bits as wells use the correct |
// initialization functions for the board. These defitions are only |
// required in the stack provided demos. They are not required in |
// final application design. |
#define DEMO_BOARD UBW32 |
#define UBW32 |
/** LED ************************************************************/ |
#define mInitAllLEDs() LATE |= 0x000F; TRISE &= 0xFFF0; |
#define mLED_1 LATEbits.LATE3 |
#define mLED_2 LATEbits.LATE2 |
#define mLED_3 LATEbits.LATE1 |
#define mLED_4 LATEbits.LATE0 |
#define mGetLED_1() mLED_1 |
#define mGetLED_USB() mLED_1 |
#define mGetLED_2() mLED_2 |
#define mGetLED_3() mLED_3 |
#define mGetLED_4() mLED_4 |
#define mLED_1_On() mLED_1 = 0; |
#define mLED_USB_On() mLED_1 = 0; |
#define mLED_2_On() mLED_2 = 0; |
#define mLED_3_On() mLED_3 = 0; |
#define mLED_4_On() mLED_4 = 0; |
#define mLED_1_Off() mLED_1 = 1; |
#define mLED_USB_Off() mLED_1 = 1; |
#define mLED_2_Off() mLED_2 = 1; |
#define mLED_3_Off() mLED_3 = 1; |
#define mLED_4_Off() mLED_4 = 1; |
#define mLED_1_Toggle() mLED_1 = !mLED_1; |
#define mLED_USB_Toggle() mLED_1 = !mLED_1; |
#define mLED_2_Toggle() mLED_2 = !mLED_2; |
#define mLED_3_Toggle() mLED_3 = !mLED_3; |
#define mLED_4_Toggle() mLED_4 = !mLED_4; |
#define mLED_Both_Off() {mLED_1_Off(); mLED_2_Off();} |
/** SWITCH *********************************************************/ |
#define mInitSwitch2() TRISEbits.TRISE7=1; |
#define mInitSwitch3() TRISEbits.TRISE6=1; |
#define mInitAllSwitches() mInitSwitch2();mInitSwitch3(); |
#define swProgram PORTEbits.RE7 |
#define swUser PORTEbits.RE6 |
#define UserSW swUser |
#define sw2 swUser |
#define RXTX LATAbits.LATA2 |
#define BPF_S0 LATAbits.LATA0 |
#define BPF_S1 LATAbits.LATA1 |
#define BPF_S0_STATE PORTAbits.RA0 |
#define BPF_S1_STATE PORTAbits.RA1 |
#define PADDLE_DIT PORTFbits.RF4 |
#define PADDLE_DAH PORTFbits.RF5 |
#define LPF_0 LATAbits.LATA3 |
#define LPF_1 LATAbits.LATA4 |
#define LPF_2 LATAbits.LATA5 |
#define LPF_3 LATAbits.LATA6 |
#define LPF_4 LATAbits.LATA7 |
#define LPF_5 LATAbits.LATA9 |
#define LPF_6 LATAbits.LATA10 |
#endif |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/HardwareProfile.h |
---|
0,0 → 1,103 |
/******************************************************************** |
FileName: HardwareProfile.h |
Dependencies: See INCLUDES section |
Processor: PIC18, PIC24, or PIC32 USB Microcontrollers |
Hardware: The code is natively intended to be used on the |
following hardware platforms: |
PICDEM FS USB Demo Board |
PIC18F46J50 FS USB Plug-In Module |
PIC18F87J50 FS USB Plug-In Module |
Explorer 16 + PIC24 or PIC32 USB PIMs |
PIC24F Starter Kit |
Low Pin Count USB Development Kit |
The firmware may be modified for use on other USB |
platforms by editing this file (HardwareProfile.h) |
Compiler: Microchip C18 (for PIC18), C30 (for PIC24), |
or C32 (for PIC32) |
Company: Microchip Technology, Inc. |
Software License Agreement: |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
Any use in violation of the foregoing restrictions may subject the |
user to criminal sanctions under applicable laws, as well as to |
civil liability for the breach of the terms and conditions of this |
license. |
THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
******************************************************************** |
File Description: |
Change History: |
Rev Date Description |
1.0 11/19/2004 Initial release |
2.1 02/26/2007 Updated for simplicity and to use common |
coding style |
2.3 09/15/2008 Broke out each hardware platform into its own |
"HardwareProfile - xxx.h" file |
********************************************************************/ |
#ifndef HARDWARE_PROFILE_H |
#define HARDWARE_PROFILE_H |
//#define DEMO_BOARD USER_DEFINED_BOARD |
#if !defined(DEMO_BOARD) |
#if defined(__C32__) |
#if defined(__32MX460F512L__) |
#if defined(PIC32MX460F512L_PIM) |
#include "HardwareProfile - PIC32MX460F512L PIM.h" |
#elif defined(PIC32_USB_STARTER_KIT) |
#include "HardwareProfile - PIC32 USB Starter Kit.h" |
#else |
#include "HardwareProfile - UBW32.h" |
#endif |
#elif defined(__32MX795F512L__) |
#if defined(PIC32MX795F512L_PIM) |
#include "HardwareProfile - PIC32MX795F512L PIM.h" |
#elif defined(PIC32_USB_STARTER_KIT) |
//PIC32 USB Starter Kit II |
#include "HardwareProfile - PIC32 USB Starter Kit.h" |
#endif |
#endif |
#endif |
#if defined(__C30__) |
#if defined(__PIC24FJ256GB110__) |
#include "HardwareProfile - PIC24FJ256GB110 PIM.h" |
#elif defined(__PIC24FJ256GB106__) |
#include "HardwareProfile - PIC24F Starter Kit.h" |
#endif |
#endif |
#if defined(__18CXX) |
#if defined(__18F4550) |
#include "HardwareProfile - PICDEM FSUSB.h" |
#elif defined(__18F87J50) |
#include "HardwareProfile - PIC18F87J50 PIM.h" |
#elif defined(__18F14K50) |
#include "HardwareProfile - Low Pin Count USB Development Kit.h" |
#elif defined(__18F46J50) |
#include "HardwareProfile - PIC18F46J50 PIM.h" |
#elif defined(__18F2550) |
#include "HardwareProfile - UBW.h" |
#endif |
#endif |
#endif |
#if !defined(DEMO_BOARD) |
#error "Demo board not defined. Either define DEMO_BOARD for a custom board or select the correct processor for the demo board." |
#endif |
#endif //HARDWARE_PROFILE_H |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/README.txt |
---|
0,0 → 1,260 |
News |
==== |
14 Apr 2009 |
The UBW has 1 power indicator LED, and 2 blinking LED's usually used to indicate the |
status of USB connections with the PC. |
Charles (and maybe some of you) finds the blinking LED's to be too bright and |
distracting. |
So I have implemented a toggle switch (the PRG button) function for you to turn |
the blinking on or off. |
Once turned on or off, the setting is stored in EEPROM, so it will continue to |
behave this way when you power off and next power on the UBW. |
The default setting is LED blinking ON. So when you (re)flash the firmware, the |
default is active. |
14 Mar 2009 |
I have just released the latest version of my UBW Emulator firmware. It now |
has (almost) all the functionalities of Fred (PE0FKO)'s v15.10 firmware for |
ATTINY45 and ATTINY85. All the functions are accessible with Winrad with Fred's |
ExtIO_Si570_v0.8.dll, including the wonderful option of setting of the |
filter crossover points from the software. The crossover points are stored |
in the UBW EEPROM so it will persist until changed again. Another new feature |
is the setting of floating point offset and multiplier in the firmware. This |
complements the setting of offset and (usually) integer multiplier in the PC |
SDR software. |
Winrad/ExtIO can be used to calibrate the UBW/Si570 (2 methods are available - |
calibrating the default freq, or against a known station freq, eg. WWV). |
Once calibrated, there is no need to calibrate other software - both set |
freq by value and set freq by register will give the correct calibrated |
freq now. In PowerSDR, leave the fxtal freq at the default 114.285 Mhz. |
The new UBW Emulator works perfectly with Rocky v3.6, PowerSDR-sr40, |
and PowerSDR-IQ. (set the Fxtal freq in the setup tab to the default 114.285 Mhz). |
With Fred's v15.10 firmware in the ATTINY, users can use the ATTINY based USB |
interfaces to do auto band switching of the mobo for Rx. To be able to do both Rx |
and Tx BPF switching, Rx/Tx switching (PTT), and external LPF switching, from a |
single USB connection, there are only 3 uC solutions that I know of: |
1. The UBW (or UBW32) with this UBW firmware |
2. Dave Brainerd's HSUSB, with firmware by Christos |
3. Arduino board (or clone), with PE0FKO firmware modified by Loftur TF3LJ. |
See Message #31623 |
UBW EMULATOR |
============ |
This is the UBW emulator firmware for emulating the AVR based |
DG8SAQ USB Si570 synthesiser, and Tony's USB-i2C Interface. |
It emulates most of the functions of the orginal DG8SAQ firmware. |
In addition, it emulates the new functions of the PE0FKO firmware (v15.10) |
by Fred, with smooth tune, calibration, setting of Auto BPF crossover |
points, setting of startup freq etc. After calibration of the UBW, |
both set freq by value (used by Rocky) and set freq by register (used by |
PowerSDR-sr40, with the fxtal freq set to the default 114.285 Mhz) will |
give the correct calibrated freq output from the Si570. No further |
calibration with the PC software is required. |
I would like to thank Joe Hopster who wrote the original UBW Si570 |
code, Tom DG8SAQ for the AVR synthesiser code, Mike Collins who has |
been invaluable in helping with the debugging and testing, John Fisher |
for the code example on Si570 slide, Edson for advice on BPF selection coding, |
bug fixing and testing, Fred for help to emulate his v15.7 firmware, |
and others who have contributed so much to Softrock and Si570. |
The emulator firmware HEX file is loaded in the UBW (either PIC |
18F2455, 18F2550 or 18F2553 version) by the Microchip USB bootloader. |
See UBW website for more details about the bootloader. |
Before starting the firmware (via the reset button, or on power up by |
plugging in the USB), the UBW should be connected via i2c interface to |
an Si570. Power up the Si570 before the UBW. |
There are several ways for connecting the UBW with the Si570. |
(1) Connection is with 4 wires, +5V, Gnd, SCL, SDA, to an i2c |
level converter, and then to Si570 with 4 wires, +3V3, Gnd, SCL, and |
SDA. If you use the WB6DHW Si570 board, it has the level converter built-in. So |
You can just connect the 4 wires to the header pins on the WB6DHW board. Note |
that the order of the 4 wires on the UBW is: GND, VCC, RB0, RB1. The order |
of the 4 header pins on WB6DHW board is: +5V, GND, SDA, SCL. |
(2) If you are not using an IC such as GTL2002 for +5V to +3V3 conversion, you |
can use discretes with the Philips (see AN97055 from Philips) |
i2c level converter circuit using 2 BS170's. |
(3) The UBW Emulator firmware sets up the SCL and SDA pins as open collector outputs. |
So you can just connect 3 wires from the UBW to the +3v3 Si570 on the Softrock: |
GND, SCL and SDA. The SCL and SDA lines will have pullup resistors to +3V3 on the |
Softrock pcb. This has been tested to work. HOwever, there is the risk that |
if the UBW firmware malfunctions for some reason (eg loading the wrong firmware instead |
of the Emulator firmware), the RB0 and RB1 (SDA and SCL) pins may go to output high of |
+5V, which may damage the Si570 or other +3V3 chips. |
The PC will detect the new USB device as a DG8SAQ-I2C device and as |
far as the PC is concerned, the UBW behaves almost exactly like the |
USB Si570 synthesiser (which is based on the AVR uController). When |
prompted by the PC to install the driver for this device, you install |
the AVR USB driver (from the USB Si570 synthesiser software download). |
You will also need the libusb0.dll and libusb0.sys files installed |
for the PC software to work (available also from the USB Si570 synthesiser |
software package). |
The following PC software programs have been tested with the UBW emulation so far: |
1. SI570_USB_Test.exe from the USB Si570 synthesiser software package |
2. USB_Synth.exe from the USB Si570 synthesiser software package |
2. Rocky v3.6 |
3. Guido's PowerSDR v1.9.0 sr40 |
4. WinRad with Fred's ExtIO_Si570_v0.8.dll |
5. Christos's PowerSDR-IQ v1.12.20 |
SI570_USB_Test.exe can be used test the USB communication and UBW |
functions,and for calibrating the UBW-Si570 ie. |
(1) Click "Read Si570 Register" - the default Si570 startup frequency |
and register values will be displayed |
(2) If you know the actual startup frequency of your Si570 (which is |
close to but generally not equal to the nominal startup freq of 56.32 |
Mhz), you can do the calibration now by inputting the actual freq in the |
text box to the left of the "cal on startup freq", and then hit "cal |
on startup freq". The UBW-Si570 is now calibrated for "set freq by |
value". The calibration is stored in the EEPROM of the UBW and you do |
not need to re-calibrate again unless you reload the UBW firmware from |
the .hex file. |
(3) Now you can input any freq desired in the text box and hit either |
"set freq by value" or "set freq by register". The si570 should now |
output the freq set by you. It should be accurate as set, and can be |
confirmed with an external freq counter. |
Many of the functions of the SI570_USB_Test.exe have been implemented, |
including Paddle input, RXTX level, etc. |
Both the "old" and "new" (with new icon) versions of USB_Synth.exe work in setting |
the Si570 freq. The old version uses set freq by value, and the new version |
(with enhancements) uses set freq by register. |
If the SI570_USB_Test run is OK, you can fire up Rocky v3.6 to use the |
Si570-USB functionality. Rocky uses the "set freq by value" method. You can use |
the Rocky calibration function with the UBW, but it should not be necessary and should |
be avoided. Use the calibration method in WinRad (see below under Calibration) or |
the SI570_USB_Test.exe method (see above). |
PowerSDR works by "set Freq by Register" method. You can change freq by the band buttons |
or sliding the freq up and down with the mouse. Leave the Fxtal |
freq in PowerSDR "Setup" to the default 114.285 Mhz. There is no need for |
further calibration. |
To use Winrad, you have to download the ExtIO_Si570.dll by Fred PE0FKO. Put the v0.8 |
dll in the same directory as Winrad (usually installed in "c:\Program Files\Winrad" directory). |
Calibration |
=========== |
You can use Winrad (with ExtIO_Si570_v0.8.dll by Fred) to do the calibration. This is the |
easier (and preferred method). There are two calibration methods in ExtIO_Si570.dll. One is |
calibrating to the factory default freq of the Si570 (a value close to 56.32 Mhz). The |
other method is to tune Winrad to a known frequency station, eg. the WWV stations broadcasting |
at 2.5 Mhz, 5.0 Mhz, 10.0 Mhz, 15.0 Mhz etc., and then put in the actual frequencies. For |
example, you may find a good signal of WWV at 10.023 Mhz. So the "tuned" freq is 10.023 Mhz, |
but the "real" freq is 10.000 Mhz. So you enter this real freq in the box and the hit "calibrate" |
botton. |
Si570 calibration can also be done with SI570_USB_Test.exe software, |
to calibrate the startup freq accurately once after loading (or reloading) |
of the firmware .hex file. The calibration data are then stored in the UBW EEPROM. |
If UBW is not connected to the Si570 |
==================================== |
I have eliminated the readstartupconfiguration() step. So now the UBW will NOT hang |
when it is not connected to the i2c bus on startup. On connection to USB it will be |
recognized by the PC. |
Of course, if you try to communicate with the Si570 it will hang and disconnect from |
the USB if you don't have the Si570 connected at this time. |
Restoring EEPROM to factory default condition |
============================================= |
After the UBW EEPROM is corrupted (eg. by mis-calibration), you can restore the factory default |
by reloading the .hex file. (Thanks to Mike for the suggestion.). Alternatively, you can use |
SI570_USB_Test.exe to sent 41 (hex) in the "request" box, and ff (hex) in the "Value" box, |
then click "USB ctrl msg Data to Host". This then clears the EEPROM in the UBW to the default |
condition and when you reset the UBW (hit the reset botton on the uBW, or by powering off |
and then on again). |
Using Winrad, there is a "reset" botton at the "calibrate" tab which will do the same thing. |
Download |
======== |
The UBW emulation firmware and the source files can be found in |
Files->9V1AL->UBW emulation. |
IO Port Pin assignment |
====================== |
Pin assignments for the UBW are as follows: |
Pin Name Input/Output Active Remarks |
RA0 BPF_SO O H BPF select S0 |
RA1 BPF_S1 O H BPF select S1 |
S1,S0 selects 1 of 4 BPF's for Softrock |
RA2 RXTX O H PTT, H = Transmit |
RB0 SDA Open Collector For i2c connection to Si570 |
RB1 SCL Open Collector may need conversion to +3v3 |
in case of firmware failure |
(eg wrong firmware loaded) |
then RB0 and RB1 may be set |
to logic high output of +5V |
RB6 PADDLE_DIT I L Paddle DIT Input, active low |
RB7 PADDLE_DAH I L Paddle DAH Input, active low |
As internal pullup is enabled, |
there is no need to add external |
pullup resistors. Just ground the pin |
to activate. |
RA3-5, RB2-5 LPF_x O H LPF select pins |
This has to be customised for |
the LPF bank you use. |
Email me (lee188@singnet.com.sg) |
and I will sent you a customised hex file |
Connections to SR v6.3 and Mobo v3.6 |
===================================== |
UBW SRv6.3 Mobo v3.6 External Paddle |
RA0 - P7 Pin 1 - |
RA1 - P7 Pin 2 - |
RA2 PTT_I K6 Pin 1 - |
RB0 SDA - - |
RB1 SCL - - |
GND GND P10 Pin 2 Paddle Common |
RB6 - - Paddle dot (dit) |
RB7 - - Paddle dash (dah) |
- +5V P10 Pin 1 - |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/UBW-I2C.c |
---|
0,0 → 1,413 |
/** INCLUDES *******************************************************/ |
#include "GenericTypeDefs.h" |
#include "Compiler.h" |
#include "HardwareProfile.h" |
#include "USB/usb.h" |
#include "usbavrcmd.h" |
#include "user.h" |
#include <math.h> |
#include <stdlib.h> |
#include <string.h> |
#include <ctype.h> |
#if defined (UBW) |
#include <delays.h> |
#include <i2c.h> |
#include <EEP.h> |
#elif defined (UBW32) |
#include <peripheral/i2c.h> |
#include <dee_emulation/dee_emulation_pic32.h> |
#endif |
/******************************************************************** |
* Section B: EP0 Buffer Space |
*******************************************************************/ |
extern volatile CTRL_TRF_SETUP SetupPkt; // 8-byte only |
extern volatile BYTE CtrlTrfData[USB_EP0_BUFF_SIZE]; |
#pragma udata |
WORD_VAL FilterCrossOver[8]; |
float FilterSwitchOver[7]; |
WORD_VAL LPFCrossOver[8]; |
float LPFSwitchOver[7]; |
#pragma code |
void USBCheckUBWRequest(void) |
{ |
unsigned char paddle_byte; |
unsigned int eep_adr; |
WORD_VAL w; |
unsigned int i, j; |
unsigned char IO_data; |
#if defined (UBW32) |
unsigned int value; |
unsigned int number_of_filter_bytes; |
#else |
unsigned char number_of_filter_bytes; |
#endif |
if(SetupPkt.RequestType == USB_SETUP_TYPE_STANDARD_BITFIELD) return; // only deals with non-standard, ie user requests |
command = SetupPkt.bRequest; // save the command of the user request from the setuppacket |
// it will be used for subsequent data transfer |
switch(command) |
{ |
case CMD_GET_CW_KEY: |
paddle_byte = 0x22; // 00100010 |
if (!PADDLE_DIT) paddle_byte &= 0xdf; // 11011111 |
if (!PADDLE_DAH) paddle_byte &= 0xfd; // 11111101 |
if (RXTX) paddle_byte |= 0x10; // PB4 is the ATTINY PTT_OUT pin 00010000 |
else paddle_byte &= 0xef; // 11101111 |
replybuf[0] = paddle_byte; |
inPipes[0].pSrc.bRam = (BYTE*)&replybuf[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 1; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_SET_USRP1: // Set RxTx and get Paddle status |
paddle_byte = 0x22; // 00100010 |
if ( SetupPkt.W_Value.v[0] ){ |
RXTX = 1; // Set PTT |
paddle_byte |= 0x10; // 00010000 |
} |
else{ |
RXTX = 0; |
paddle_byte &= 0xef; // 11101111 |
}; |
if (!PADDLE_DIT) paddle_byte &= 0xdf; // 11011111 |
if (!PADDLE_DAH) paddle_byte &= 0xfd; // 11111101 |
replybuf[0] = paddle_byte; |
inPipes[0].pSrc.bRam = (BYTE*)&replybuf[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 1; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_SET_FREQ_REG: // Control Transfer Rx of data from HOST->UBW |
case CMD_SET_LO_SM: |
case CMD_SET_FREQ: |
case CMD_SET_XTAL: |
case CMD_SET_STARTUP: |
case CMD_SET_PPM: |
wCount = SetupPkt.wLength; |
outPipes[0].wCount.Val = SetupPkt.wLength; |
outPipes[0].pFunc = &Read_Command_Into_Buffer; |
outPipes[0].pDst.bRam = (BYTE*) &command_buffer[current_command_in].data[0]; |
outPipes[0].info.bits.busy = 1; |
break; |
case CMD_GET_PIN: // read ports |
IO_data = 0x0d; // 00001101 |
if (PADDLE_DAH) IO_data |= 0x02; // PB1 |
if (BPF_S0_STATE) IO_data |= 0x10; // PB4 |
if (BPF_S1_STATE) IO_data |= 0x20; // PB5 |
replybuf[0] = IO_data; |
inPipes[0].pSrc.bRam = (BYTE*)&replybuf[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 1; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_SET_PORT: // set ports |
IO_data = SetupPkt.W_Value.v[0]; |
if (!abpf_flag){ |
if (IO_data & 0x10) BPF_S0 = 1; |
else BPF_S0 = 0; |
if (IO_data & 0x20) BPF_S1 = 1; |
else BPF_S1 = 0; |
}; |
break; |
case CMD_SET_IO: // set i/o bits |
IO_data = SetupPkt.W_Index.v[0] & 0x03; // only 2 bits active 00000011 |
if (!abpf_flag) { // abpf inactive |
if (IO_data & 0x01) BPF_S0 = 1; // Simulate IO_PIN1 in ATTINY |
else BPF_S0 = 0; |
if (IO_data & 0x02) BPF_S1 = 1; // Simulate IO_PIN2 in ATTINY |
else BPF_S1 = 0; |
} |
IO_data = BPF_S0_STATE; // read back status of BPF select pins |
if (BPF_S1_STATE) IO_data |= 0x02; |
else IO_data &= 0x01; |
replybuf[0] = IO_data; |
replybuf[1] = 0x00; |
inPipes[0].pSrc.bRam = (BYTE*)&replybuf[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 2; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_GET_IO: |
IO_data = BPF_S0_STATE; // status of BPF select pins |
if (BPF_S1_STATE) IO_data |= 0x02; |
else IO_data &= 0x01; |
replybuf[0] = IO_data; |
replybuf[1] = 0x00; |
inPipes[0].pSrc.bRam = (BYTE*)&replybuf[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 2; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_SET_FILTER: // Set and Read filter crossover points |
i = SetupPkt.W_Index.Val; |
if (i < 256){ // Rx Filter |
number_of_filter_bytes = NUM_BPF * 2; |
inPipes[0].pSrc.bRam = (BYTE*)&FilterCrossOver[0]; // Set source |
if (i < NUM_BPF) { |
FilterCrossOver[i].Val = SetupPkt.W_Value.Val; |
if (i != (NUM_BPF-1)) FilterSwitchOver[i] = Cross2Switch(FilterCrossOver[i]); |
else abpf_flag = SetupPkt.W_Value.Val; |
} |
} |
else{ // Tx filter |
number_of_filter_bytes = 16; |
inPipes[0].pSrc.bRam = (BYTE*)&LPFCrossOver[0]; // Set source |
j = i - 256; |
if ( j < 8){ |
LPFCrossOver[j].Val = SetupPkt.W_Value.Val; |
if (j != 7) LPFSwitchOver[j] = Cross2Switch(LPFCrossOver[j]); |
}; |
}; |
// now that a filter value of filter enable/disable value is set, update the EEPROM |
#if defined (UBW) |
for (i = 0; i < NUM_BPF; i++){ |
Write_b_eep((i * 2 + F_CROSS_OVER +1), FilterCrossOver[i].v[0]); |
Busy_eep(); |
Write_b_eep((i * 2 + F_CROSS_OVER + 1 + 1), FilterCrossOver[i].v[1]); |
Busy_eep(); |
} |
#elif defined (UBW32) |
for (i =0; i < NUM_BPF; i++) DataEEWrite( FilterCrossOver[i].Val , (i + F_CROSS_OVER +1)); |
#endif |
#if defined (UBW) |
for (j = 0; j < 8; j++){ |
Write_b_eep(( j * 2 + F_CROSS_OVER +17), LPFCrossOver[j].v[0]); |
Busy_eep(); |
Write_b_eep(( j * 2 + F_CROSS_OVER +17 + 1), LPFCrossOver[j].v[1]); |
Busy_eep(); |
} |
Write_b_eep(F_CROSS_OVER, F_CROSS_OVER_VALUE); |
Busy_eep(); |
#elif defined (UBW32) |
for (j = 0; j < 8; j++){ |
DataEEWrite( (unsigned int)LPFCrossOver[j].Val , (j + F_CROSS_OVER +9)); |
}; |
DataEEWrite(F_CROSS_OVER_VALUE, F_CROSS_OVER); |
#endif |
inPipes[0].wCount.v[0] = number_of_filter_bytes; // Set data count |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_SET_SI570: // SI570: write byte from register index |
i2c_adr = SetupPkt.W_Value.v[0]; |
#if defined (UBW) |
IdleI2C(); |
StartI2C(); |
IdleI2C(); |
WriteI2C( i2c_adr <<1); |
WriteI2C( SetupPkt.W_Value.v[1]); // register = byte 3 |
WriteI2C( SetupPkt.W_Index.v[0]); // value to write to register |
StopI2C(); |
IdleI2C(); |
#elif defined (UBW32) |
IdleI2C1(); |
StartI2C1(); |
IdleI2C1(); |
MasterWriteI2C1( i2c_adr <<1); |
MasterWriteI2C1( SetupPkt.W_Value.v[1]); // register = byte 3 |
MasterWriteI2C1( SetupPkt.W_Index.v[0]); // value to write to register |
StopI2C1(); |
IdleI2C1(); |
#endif |
replybuf[0] = 0; // just say no errors |
inPipes[0].pSrc.bRam = (BYTE*)&replybuf[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 1; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_GET_LO_SM: // return sub mul |
for (i=0; i<4; i++) replybuf[i] = f_sub.bytes[i]; |
for (i=0; i<4; i++) replybuf[i+4] = f_mul.bytes[i]; |
inPipes[0].pSrc.bRam = (BYTE*)&replybuf[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 8; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_GET_FREQ: // return set freq, ie no offset/mul |
avr_freq.qw = set_frequency * (double)(1L << 21); |
inPipes[0].pSrc.bRam = (BYTE*)&avr_freq.bytes[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 4; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_GET_PPM: // return smooth tune in ppm |
w.Val = Smooth_double * 1000000L; |
inPipes[0].pSrc.bRam = (BYTE*)&w.v[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 2; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_GET_STARTUP: // return init startup freq |
#if defined(UBW) |
for (i=0; i<4; i++) avr_freq.bytes[i] = Read_b_eep(i + F_INIT_FREQ +1); |
#elif defined(UBW32) |
for (i=0; i<4; i++) { |
DataEERead(&value, (i + F_INIT_FREQ +1)); |
avr_freq.bytes[i] = value; |
}; |
#endif |
inPipes[0].pSrc.bRam = (BYTE*)&avr_freq.bytes[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 4; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_GET_XTAL: // return fcryst |
inPipes[0].pSrc.bRam = (BYTE*)&fcryst_freq.bytes[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 4; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_GET_SI570: // SI570: read out frequency control registers |
i2c_adr = SetupPkt.W_Value.v[0]; |
ReadRegs(); |
inPipes[0].pSrc.bRam = (BYTE*)®isters[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 6; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_GET_I2C_ERR: // return # of i2c errors, set to zero always |
replybuf[0] = 0; // No errors :) |
inPipes[0].pSrc.bRam = (BYTE*)&replybuf[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 1; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_SET_I2C_ADDR: // Reset EEPROM to default values if 255 |
// Otherwise just set i2c address |
if (SetupPkt.W_Value.v[0] == 0xff){ |
#if defined (UBW) |
Write_b_eep(F_CAL_DONE, 0xff); |
Busy_eep(); |
Write_b_eep(F_INIT_FREQ, 0xff); |
Busy_eep(); |
Write_b_eep(F_SMOOTH, 0xff); |
Busy_eep(); |
Write_b_eep(F_SUB_MUL, 0xff); |
Busy_eep(); |
Write_b_eep(F_CROSS_OVER, 0xff); |
Busy_eep(); |
#elif defined (UBW32) |
DataEEWrite( (unsigned int) 0xff, F_CAL_DONE); |
DataEEWrite( (unsigned int) 0xff, F_INIT_FREQ); |
DataEEWrite( (unsigned int) 0xff, F_SMOOTH); |
DataEEWrite( (unsigned int) 0xff, F_SUB_MUL); |
DataEEWrite( (unsigned int) 0xff, F_CROSS_OVER); |
#endif |
i2c_adr = 0x55; |
} |
else { |
i2c_adr = SetupPkt.W_Value.v[0]; |
}; |
replybuf[0] = 0x00; |
inPipes[0].pSrc.bRam = (BYTE*)&replybuf[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 1; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
case CMD_GET_VERSION: // return version 15.10 |
replybuf[0] = VERSION_MINOR; |
replybuf[1] = VERSION_MAJOR; |
inPipes[0].pSrc.bRam = (BYTE*)&replybuf[0]; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 2; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
default: // Command not supported |
replybuf[0] = 0xff; |
inPipes[0].pSrc.bRam = (BYTE*)&replybuf[0] ; // Set Source |
inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type |
inPipes[0].wCount.v[0] = 1; // Set data count |
inPipes[0].info.bits.busy = 1; |
break; |
}//end switch |
} |
void Read_Command_Into_Buffer(void) |
{ |
if (command_count >= COMMAND_BUFFER_SIZE){ // buffer full |
current_command_out++; // discards oldest command |
if (current_command_out >= COMMAND_BUFFER_SIZE) current_command_out = 0; |
command_count--; // now one command less (discarded) |
}; |
command_buffer[current_command_in].command = command; |
command_buffer[current_command_in].wCount = wCount; |
// data already copied to command_buffer before this outpipe pFunc is called |
current_command_in++; |
if (current_command_in >= COMMAND_BUFFER_SIZE) current_command_in = 0; |
command_count++; |
} |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/USB Device - MCHPUSB - Generic Driver - C18 - PIC18F4550.mcp |
---|
0,0 → 1,130 |
[HEADER] |
magic_cookie={66E99B07-E706-4689-9E80-9B2582898A13} |
file_version=1.0 |
device=PIC18F4550 |
[PATH_INFO] |
BuildDirPolicy=BuildDirIsProjectDir |
dir_src= |
dir_bin= |
dir_tmp=.\Objects\USB Device - Generic Driver Demo - C18 - PICDEM FSUSB |
dir_sin= |
dir_inc=C:\library\Microchip\Include\USB;C:\library\Microchip\USB;C:\library\Microchip\Include;. |
dir_lib=C:\Program Files\Microchip\MCC18\lib |
dir_lkr= |
[CAT_FILTERS] |
filter_src=*.asm;*.c |
filter_inc=*.h;*.inc |
filter_obj=*.o |
filter_lib=*.lib |
filter_lkr=*.lkr |
[CAT_SUBFOLDERS] |
subfolder_src=USB Stack |
subfolder_inc=Common;USB Stack |
subfolder_obj= |
subfolder_lib= |
subfolder_lkr= |
[FILE_SUBFOLDERS] |
file_000=. |
file_001=. |
file_002=. |
file_003=. |
file_004=USB Stack |
file_005=USB Stack |
file_006=USB Stack |
file_007=. |
file_008=. |
file_009=. |
file_010=Common |
file_011=Common |
file_012=USB Stack |
file_013=USB Stack |
file_014=USB Stack |
file_015=USB Stack |
file_016=USB Stack |
file_017=USB Stack |
file_018=USB Stack |
file_019=. |
file_020=. |
[GENERATED_FILES] |
file_000=no |
file_001=no |
file_002=no |
file_003=no |
file_004=no |
file_005=no |
file_006=no |
file_007=no |
file_008=no |
file_009=no |
file_010=no |
file_011=no |
file_012=no |
file_013=no |
file_014=no |
file_015=no |
file_016=no |
file_017=no |
file_018=no |
file_019=no |
file_020=no |
[OTHER_FILES] |
file_000=no |
file_001=no |
file_002=no |
file_003=no |
file_004=no |
file_005=no |
file_006=no |
file_007=no |
file_008=no |
file_009=no |
file_010=no |
file_011=no |
file_012=no |
file_013=no |
file_014=no |
file_015=no |
file_016=no |
file_017=no |
file_018=no |
file_019=no |
file_020=no |
[FILE_INFO] |
file_000=user.c |
file_001=main.c |
file_002=usb_descriptors.c |
file_003=UBW-I2C.c |
file_004=C:\library\Microchip\USB\usb_device.c |
file_005=C:\library\Microchip\Include\USB\usb_device.h |
file_006=C:\library\Microchip\Include\USB\usb_function_generic.h |
file_007=HardwareProfile.h |
file_008=user.h |
file_009=usb_config.h |
file_010=C:\library\Microchip\Include\GenericTypeDefs.h |
file_011=C:\library\Microchip\Include\Compiler.h |
file_012=C:\library\Microchip\Include\USB\usb_hal_pic18.h |
file_013=C:\library\Microchip\Include\USB\usb.h |
file_014=C:\library\Microchip\Include\USB\usb_ch9.h |
file_015=C:\library\Microchip\Include\USB\usb_common.h |
file_016=C:\library\Microchip\Include\USB\usb_device.h |
file_017=C:\library\Microchip\Include\USB\usb_function_generic.h |
file_018=C:\library\Microchip\Include\USB\usb_hal.h |
file_019=HardwareProfile - UBW.h |
file_020=rm18f4550.lkr |
[SUITE_INFO] |
suite_guid={5B7D72DD-9861-47BD-9F60-2BE967BF8416} |
suite_state= |
[TOOL_SETTINGS] |
TS{DD2213A8-6310-47B1-8376-9430CDFC013F}= |
TS{BFD27FBA-4A02-4C0E-A5E5-B812F3E7707C}=/m"$(BINDIR_)$(TARGETBASE).map" /w /o"$(TARGETBASE).cof" |
TS{C2AF05E7-1416-4625-923D-E114DB6E2B96}=-Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa- |
TS{ADE93A55-C7C7-4D4D-A4BA-59305F7D0391}= |
[INSTRUMENTED_TRACE] |
enable=0 |
transport=0 |
format=0 |
[CUSTOM_BUILD] |
Pre-Build= |
Pre-BuildEnabled=1 |
Post-Build= |
Post-BuildEnabled=1 |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/USB Device - MCHPUSB - Generic Driver - C18 - PIC18F4550.mcw |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/main.c |
---|
0,0 → 1,980 |
/******************************************************************** |
FileName: main.c |
Dependencies: See INCLUDES section |
Processor: PIC18 or PIC24 USB Microcontrollers |
Hardware: The code is natively intended to be used on the following |
hardware platforms: PICDEM FS USB Demo Board, |
PIC18F87J50 FS USB Plug-In Module, or |
Explorer 16 + PIC24 USB PIM. The firmware may be |
modified for use on other USB platforms by editing the |
HardwareProfile.h file. |
Complier: Microchip C18 (for PIC18) or C30 (for PIC24) |
Company: Microchip Technology, Inc. |
Software License Agreement: |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
Any use in violation of the foregoing restrictions may subject the |
user to criminal sanctions under applicable laws, as well as to |
civil liability for the breach of the terms and conditions of this |
license. |
THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
******************************************************************** |
File Description: |
Change History: |
Rev Date Description |
1.0 11/19/2004 Initial release |
2.1 02/26/2007 Updated for simplicity and to use common |
coding style |
********************************************************************/ |
/** INCLUDES *******************************************************/ |
#include "USB/usb.h" |
#include "USB/usb_function_generic.h" |
#include "user.h" // Modifiable |
#include "HardwareProfile.h" |
/** CONFIGURATION **************************************************/ |
#if defined(PICDEM_FS_USB) // Configuration bits for PICDEM FS USB Demo Board (based on PIC18F4550) |
#pragma config PLLDIV = 5 // (20 MHz crystal on PICDEM FS USB board) |
#pragma config CPUDIV = OSC1_PLL2 |
#pragma config USBDIV = 2 // Clock source from 96MHz PLL/2 |
#pragma config FOSC = HSPLL_HS |
#pragma config FCMEN = OFF |
#pragma config IESO = OFF |
#pragma config PWRT = OFF |
#pragma config BOR = ON |
#pragma config BORV = 3 |
#pragma config VREGEN = ON //USB Voltage Regulator |
#pragma config WDT = OFF |
#pragma config WDTPS = 32768 |
#pragma config MCLRE = ON |
#pragma config LPT1OSC = OFF |
#pragma config PBADEN = OFF |
// #pragma config CCP2MX = ON |
#pragma config STVREN = ON |
#pragma config LVP = OFF |
// #pragma config ICPRT = OFF // Dedicated In-Circuit Debug/Programming |
#pragma config XINST = OFF // Extended Instruction Set |
#pragma config CP0 = OFF |
#pragma config CP1 = OFF |
// #pragma config CP2 = OFF |
// #pragma config CP3 = OFF |
#pragma config CPB = OFF |
// #pragma config CPD = OFF |
#pragma config WRT0 = OFF |
#pragma config WRT1 = OFF |
// #pragma config WRT2 = OFF |
// #pragma config WRT3 = OFF |
#pragma config WRTB = OFF // Boot Block Write Protection |
#pragma config WRTC = OFF |
// #pragma config WRTD = OFF |
#pragma config EBTR0 = OFF |
#pragma config EBTR1 = OFF |
// #pragma config EBTR2 = OFF |
// #pragma config EBTR3 = OFF |
#pragma config EBTRB = OFF |
#elif defined(PIC18F87J50_PIM) // Configuration bits for PIC18F87J50 FS USB Plug-In Module board |
#pragma config XINST = OFF // Extended instruction set |
#pragma config STVREN = ON // Stack overflow reset |
#pragma config PLLDIV = 3 // (12 MHz crystal used on this board) |
#pragma config WDTEN = OFF // Watch Dog Timer (WDT) |
#pragma config CP0 = OFF // Code protect |
#pragma config CPUDIV = OSC1 // OSC1 = divide by 1 mode |
#pragma config IESO = OFF // Internal External (clock) Switchover |
#pragma config FCMEN = OFF // Fail Safe Clock Monitor |
#pragma config FOSC = HSPLL // Firmware must also set OSCTUNE<PLLEN> to start PLL! |
#pragma config WDTPS = 32768 |
// #pragma config WAIT = OFF // Commented choices are |
// #pragma config BW = 16 // only available on the |
// #pragma config MODE = MM // 80 pin devices in the |
// #pragma config EASHFT = OFF // family. |
#pragma config MSSPMSK = MSK5 |
// #pragma config PMPMX = DEFAULT |
// #pragma config ECCPMX = DEFAULT |
#pragma config CCP2MX = DEFAULT |
#elif defined(PIC18F46J50_PIM) || defined(PIC18F_STARTER_KIT_1) |
#pragma config WDTEN = OFF //WDT disabled (enabled by SWDTEN bit) |
#pragma config PLLDIV = 3 //Divide by 3 (12 MHz oscillator input) |
#pragma config STVREN = ON //stack overflow/underflow reset enabled |
#pragma config XINST = OFF //Extended instruction set disabled |
#pragma config CPUDIV = OSC1 //No CPU system clock divide |
#pragma config CP0 = OFF //Program memory is not code-protected |
#pragma config OSC = HSPLL //HS oscillator, PLL enabled, HSPLL used by USB |
#pragma config T1DIG = ON //Sec Osc clock source may be selected |
#pragma config LPT1OSC = OFF //high power Timer1 mode |
#pragma config FCMEN = OFF //Fail-Safe Clock Monitor disabled |
#pragma config IESO = OFF //Two-Speed Start-up disabled |
#pragma config WDTPS = 32768 //1:32768 |
#pragma config DSWDTOSC = INTOSCREF //DSWDT uses INTOSC/INTRC as clock |
#pragma config RTCOSC = T1OSCREF //RTCC uses T1OSC/T1CKI as clock |
#pragma config DSBOREN = OFF //Zero-Power BOR disabled in Deep Sleep |
#pragma config DSWDTEN = OFF //Disabled |
#pragma config DSWDTPS = 8192 //1:8,192 (8.5 seconds) |
#pragma config IOL1WAY = OFF //IOLOCK bit can be set and cleared |
#pragma config MSSP7B_EN = MSK7 //7 Bit address masking |
#pragma config WPFP = PAGE_1 //Write Protect Program Flash Page 0 |
#pragma config WPEND = PAGE_0 //Start protection at page 0 |
#pragma config WPCFG = OFF //Write/Erase last page protect Disabled |
#pragma config WPDIS = OFF //WPFP[5:0], WPEND, and WPCFG bits ignored |
#elif defined(LOW_PIN_COUNT_USB_DEVELOPMENT_KIT) |
// PIC18F14K50 |
#pragma config CPUDIV = NOCLKDIV |
#pragma config USBDIV = OFF |
#pragma config FOSC = HS |
#pragma config PLLEN = ON |
#pragma config FCMEN = OFF |
#pragma config IESO = OFF |
#pragma config PWRTEN = OFF |
#pragma config BOREN = OFF |
#pragma config BORV = 30 |
#pragma config WDTEN = OFF |
#pragma config WDTPS = 32768 |
#pragma config MCLRE = OFF |
#pragma config HFOFST = OFF |
#pragma config STVREN = ON |
#pragma config LVP = OFF |
#pragma config XINST = OFF |
#pragma config BBSIZ = OFF |
#pragma config CP0 = OFF |
#pragma config CP1 = OFF |
#pragma config CPB = OFF |
#pragma config WRT0 = OFF |
#pragma config WRT1 = OFF |
#pragma config WRTB = OFF |
#pragma config WRTC = OFF |
#pragma config EBTR0 = OFF |
#pragma config EBTR1 = OFF |
#pragma config EBTRB = OFF |
#elif defined(EXPLORER_16) |
#ifdef __PIC24FJ256GB110__ //Defined by MPLAB when using 24FJ256GB110 device |
_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) |
_CONFIG2( 0xF7FF & IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_ON & POSCMOD_HS & FNOSC_PRIPLL & PLLDIV_DIV2 & IOL1WAY_ON) |
#elif defined(__PIC24FJ64GB004__) |
_CONFIG1(WDTPS_PS1 & FWPSA_PR32 & WINDIS_OFF & FWDTEN_OFF & ICS_PGx1 & GWRP_OFF & GCP_OFF & JTAGEN_OFF) |
_CONFIG2(POSCMOD_HS & I2C1SEL_PRI & IOL1WAY_OFF & OSCIOFNC_ON & FCKSM_CSDCMD & FNOSC_PRIPLL & PLL96MHZ_ON & PLLDIV_DIV2 & IESO_ON) |
_CONFIG3(WPFP_WPFP0 & SOSCSEL_SOSC & WUTSEL_LEG & WPDIS_WPDIS & WPCFG_WPCFGDIS & WPEND_WPENDMEM) |
_CONFIG4(DSWDTPS_DSWDTPS3 & DSWDTOSC_LPRC & RTCOSC_SOSC & DSBOREN_OFF & DSWDTEN_OFF) |
#elif defined(__32MX460F512L__) || defined(__32MX795F512L__) |
#pragma config UPLLEN = ON // USB PLL Enabled |
#pragma config FPLLMUL = MUL_15 // PLL Multiplier |
#pragma config UPLLIDIV = DIV_2 // USB PLL Input Divider |
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider |
#pragma config FPLLODIV = DIV_1 // PLL Output Divider |
#pragma config FPBDIV = DIV_1 // Peripheral Clock divisor |
#pragma config FWDTEN = OFF // Watchdog Timer |
#pragma config WDTPS = PS1 // Watchdog Timer Postscale |
#pragma config FCKSM = CSDCMD // Clock Switching & Fail Safe Clock Monitor |
#pragma config OSCIOFNC = OFF // CLKO Enable |
#pragma config POSCMOD = HS // Primary Oscillator |
#pragma config IESO = OFF // Internal/External Switch-over |
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable (KLO was off) |
#pragma config FNOSC = PRIPLL // Oscillator Selection |
#pragma config CP = OFF // Code Protect |
#pragma config BWP = OFF // Boot Flash Write Protect |
#pragma config PWP = OFF // Program Flash Write Protect |
#pragma config ICESEL = ICS_PGx2 // ICE/ICD Comm Channel Select |
#pragma config DEBUG = ON // Background Debugger Enable |
#else |
#error No hardware board defined, see "HardwareProfile.h" and __FILE__ |
#endif |
#elif defined(PIC24F_STARTER_KIT) |
_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) |
_CONFIG2( 0xF7FF & IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_ON & POSCMOD_HS & FNOSC_PRIPLL & PLLDIV_DIV3 & IOL1WAY_ON) |
#elif defined(PIC24FJ256DA210_DEV_BOARD) |
//_CONFIG1(FWDTEN_OFF & ICS_PGx2 & COE_OFF & GWRP_OFF & GCP_OFF & JTAGEN_OFF) |
//_CONFIG2(POSCMOD_HS & IOL1WAY_ON & OSCIOFNC_ON & FCKSM_CSDCMD & FNOSC_PRIPLL & PLL96MHZ_ON & PLLDIV_DIV2 & IESO_OFF) |
#elif defined(PIC32_USB_STARTER_KIT) |
#pragma config UPLLEN = ON // USB PLL Enabled |
#pragma config FPLLMUL = MUL_15 // PLL Multiplier |
#pragma config UPLLIDIV = DIV_2 // USB PLL Input Divider |
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider |
#pragma config FPLLODIV = DIV_1 // PLL Output Divider |
#pragma config FPBDIV = DIV_1 // Peripheral Clock divisor |
#pragma config FWDTEN = OFF // Watchdog Timer |
#pragma config WDTPS = PS1 // Watchdog Timer Postscale |
#pragma config FCKSM = CSDCMD // Clock Switching & Fail Safe Clock Monitor |
#pragma config OSCIOFNC = OFF // CLKO Enable |
#pragma config POSCMOD = HS // Primary Oscillator |
#pragma config IESO = OFF // Internal/External Switch-over |
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable (KLO was off) |
#pragma config FNOSC = PRIPLL // Oscillator Selection |
#pragma config CP = OFF // Code Protect |
#pragma config BWP = OFF // Boot Flash Write Protect |
#pragma config PWP = OFF // Program Flash Write Protect |
#pragma config ICESEL = ICS_PGx2 // ICE/ICD Comm Channel Select |
#pragma config DEBUG = ON // Background Debugger Enable |
#elif defined(UBW) |
#elif defined(UBW32) |
#else |
#error No hardware board defined, see "HardwareProfile.h" and __FILE__ |
#endif |
/** VARIABLES ******************************************************/ |
#pragma udata |
/** PRIVATE PROTOTYPES *********************************************/ |
static void InitializeSystem(void); |
void USBDeviceTasks(void); |
void YourHighPriorityISRCode(void); |
void YourLowPriorityISRCode(void); |
/** VECTOR REMAPPING ***********************************************/ |
#if defined(__18CXX) |
//On PIC18 devices, addresses 0x00, 0x08, and 0x18 are used for |
//the reset, high priority interrupt, and low priority interrupt |
//vectors. However, the current Microchip USB bootloader |
//examples are intended to occupy addresses 0x00-0x7FF or |
//0x00-0xFFF depending on which bootloader is used. Therefore, |
//the bootloader code remaps these vectors to new locations |
//as indicated below. This remapping is only necessary if you |
//wish to program the hex file generated from this project with |
//the USB bootloader. If no bootloader is used, edit the |
//usb_config.h file and comment out the following defines: |
//#define PROGRAMMABLE_WITH_USB_HID_BOOTLOADER |
//#define PROGRAMMABLE_WITH_USB_LEGACY_CUSTOM_CLASS_BOOTLOADER |
#if defined(PROGRAMMABLE_WITH_USB_HID_BOOTLOADER) |
#define REMAPPED_RESET_VECTOR_ADDRESS 0x1000 |
#define REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS 0x1008 |
#define REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS 0x1018 |
#elif defined(PROGRAMMABLE_WITH_USB_MCHPUSB_BOOTLOADER) |
#define REMAPPED_RESET_VECTOR_ADDRESS 0x800 |
#define REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS 0x808 |
#define REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS 0x818 |
#else |
#define REMAPPED_RESET_VECTOR_ADDRESS 0x00 |
#define REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS 0x08 |
#define REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS 0x18 |
#endif |
#if defined(PROGRAMMABLE_WITH_USB_HID_BOOTLOADER)||defined(PROGRAMMABLE_WITH_USB_MCHPUSB_BOOTLOADER) |
extern void _startup (void); // See c018i.c in your C18 compiler dir |
#pragma code REMAPPED_RESET_VECTOR = REMAPPED_RESET_VECTOR_ADDRESS |
void _reset (void) |
{ |
_asm goto _startup _endasm |
} |
#endif |
#pragma code REMAPPED_HIGH_INTERRUPT_VECTOR = REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS |
void Remapped_High_ISR (void) |
{ |
_asm goto YourHighPriorityISRCode _endasm |
} |
#pragma code REMAPPED_LOW_INTERRUPT_VECTOR = REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS |
void Remapped_Low_ISR (void) |
{ |
_asm goto YourLowPriorityISRCode _endasm |
} |
#if defined(PROGRAMMABLE_WITH_USB_HID_BOOTLOADER)||defined(PROGRAMMABLE_WITH_USB_MCHPUSB_BOOTLOADER) |
//Note: If this project is built while one of the bootloaders has |
//been defined, but then the output hex file is not programmed with |
//the bootloader, addresses 0x08 and 0x18 would end up programmed with 0xFFFF. |
//As a result, if an actual interrupt was enabled and occured, the PC would jump |
//to 0x08 (or 0x18) and would begin executing "0xFFFF" (unprogrammed space). This |
//executes as nop instructions, but the PC would eventually reach the REMAPPED_RESET_VECTOR_ADDRESS |
//(0x1000 or 0x800, depending upon bootloader), and would execute the "goto _startup". This |
//would effective reset the application. |
//To fix this situation, we should always deliberately place a |
//"goto REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS" at address 0x08, and a |
//"goto REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS" at address 0x18. When the output |
//hex file of this project is programmed with the bootloader, these sections do not |
//get bootloaded (as they overlap the bootloader space). If the output hex file is not |
//programmed using the bootloader, then the below goto instructions do get programmed, |
//and the hex file still works like normal. The below section is only required to fix this |
//scenario. |
#pragma code HIGH_INTERRUPT_VECTOR = 0x08 |
void High_ISR (void) |
{ |
_asm goto REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS _endasm |
} |
#pragma code LOW_INTERRUPT_VECTOR = 0x18 |
void Low_ISR (void) |
{ |
_asm goto REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS _endasm |
} |
#endif //end of "#if defined(PROGRAMMABLE_WITH_USB_HID_BOOTLOADER)||defined(PROGRAMMABLE_WITH_USB_LEGACY_CUSTOM_CLASS_BOOTLOADER)" |
#pragma code |
//These are your actual interrupt handling routines. |
#pragma interrupt YourHighPriorityISRCode |
void YourHighPriorityISRCode() |
{ |
//Check which interrupt flag caused the interrupt. |
//Service the interrupt |
//Clear the interrupt flag |
//Etc. |
#if defined(USB_INTERRUPT) |
USBDeviceTasks(); |
#endif |
} //This return will be a "retfie fast", since this is in a #pragma interrupt section |
#pragma interruptlow YourLowPriorityISRCode |
void YourLowPriorityISRCode() |
{ |
//Check which interrupt flag caused the interrupt. |
//Service the interrupt |
//Clear the interrupt flag |
//Etc. |
} //This return will be a "retfie", since this is in a #pragma interruptlow section |
#elif defined(__C30__) |
#if defined(PROGRAMMABLE_WITH_USB_HID_BOOTLOADER) |
/* |
* ISR JUMP TABLE |
* |
* It is necessary to define jump table as a function because C30 will |
* not store 24-bit wide values in program memory as variables. |
* |
* This function should be stored at an address where the goto instructions |
* line up with the remapped vectors from the bootloader's linker script. |
* |
* For more information about how to remap the interrupt vectors, |
* please refer to AN1157. An example is provided below for the T2 |
* interrupt with a bootloader ending at address 0x1400 |
*/ |
// void __attribute__ ((address(0x1404))) ISRTable(){ |
// |
// asm("reset"); //reset instruction to prevent runaway code |
// asm("goto %0"::"i"(&_T2Interrupt)); //T2Interrupt's address |
// } |
#endif |
#endif |
/** DECLARATIONS ***************************************************/ |
#pragma code |
/****************************************************************************** |
* Function: void main(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: Main program entry point. |
* |
* Note: None |
*******************************************************************/ |
#if defined(__18CXX) |
void main(void) |
#else |
int main(void) |
#endif |
{ |
InitializeSystem(); |
#if defined(USB_INTERRUPT) |
USBDeviceAttach(); |
#endif |
while(1) |
{ |
#if defined(USB_POLLING) |
// Check bus status and service USB interrupts. |
USBDeviceTasks(); // Interrupt or polling method. If using polling, must call |
// this function periodically. This function will take care |
// of processing and responding to SETUP transactions |
// (such as during the enumeration process when you first |
// plug in). USB hosts require that USB devices should accept |
// and process SETUP packets in a timely fashion. Therefore, |
// when using polling, this function should be called |
// frequently (such as once about every 100 microseconds) at any |
// time that a SETUP packet might reasonably be expected to |
// be sent by the host to your device. In most cases, the |
// USBDeviceTasks() function does not take very long to |
// execute (~50 instruction cycles) before it returns. |
#endif |
// Application-specific tasks. |
// Application related code may be added here, or in the ProcessIO() function. |
ProcessIO(); |
}//end while |
}//end main |
/******************************************************************** |
* Function: static void InitializeSystem(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: InitializeSystem is a centralize initialization |
* routine. All required USB initialization routines |
* are called from here. |
* |
* User application initialization routine should |
* also be called from here. |
* |
* Note: None |
*******************************************************************/ |
static void InitializeSystem(void) |
{ |
#if (defined(__18CXX) & !defined(PIC18F87J50_PIM)) |
ADCON1 |= 0x0F; // Default all pins to digital |
#elif defined(__C30__) |
#if defined(PIC24FJ256DA210_DEV_BOARD) |
ANSA = 0x0000; |
ANSB = 0x0000; |
ANSC = 0x0000; |
ANSD = 0x0000; |
ANSE = 0x0000; |
ANSF = 0x0000; |
ANSG = 0x0000; |
#else |
AD1PCFGL = 0xFFFF; |
#endif |
#elif defined(__C32__) |
AD1PCFG = 0xFFFF; |
#endif |
#if defined(PIC18F87J50_PIM) || defined(PIC18F46J50_PIM) || defined(PIC18F_STARTER_KIT_1) |
//On the PIC18F87J50 Family of USB microcontrollers, the PLL will not power up and be enabled |
//by default, even if a PLL enabled oscillator configuration is selected (such as HS+PLL). |
//This allows the device to power up at a lower initial operating frequency, which can be |
//advantageous when powered from a source which is not gauranteed to be adequate for 48MHz |
//operation. On these devices, user firmware needs to manually set the OSCTUNE<PLLEN> bit to |
//power up the PLL. |
{ |
unsigned int pll_startup_counter = 600; |
OSCTUNEbits.PLLEN = 1; //Enable the PLL and wait 2+ms until the PLL locks before enabling USB module |
while(pll_startup_counter--); |
} |
//Device switches over automatically to PLL output after PLL is locked and ready. |
#endif |
#if defined(PIC18F87J50_PIM) |
//Configure all I/O pins to use digital input buffers. The PIC18F87J50 Family devices |
//use the ANCONx registers to control this, which is different from other devices which |
//use the ADCON1 register for this purpose. |
WDTCONbits.ADSHR = 1; // Select alternate SFR location to access ANCONx registers |
ANCON0 = 0xFF; // Default all pins to digital |
ANCON1 = 0xFF; // Default all pins to digital |
WDTCONbits.ADSHR = 0; // Select normal SFR locations |
#endif |
#if defined(PIC18F46J50_PIM) || defined(PIC18F_STARTER_KIT_1) |
//Configure all I/O pins to use digital input buffers. |
ANCON0 = 0x7F; // all pins to digital except AN7 |
ANCON1 = 0xBF; // Default all pins to digital. Bandgap on. |
#endif |
#if defined(PIC24FJ64GB004_PIM) || defined(PIC24FJ256DA210_DEV_BOARD) |
//On the PIC24FJ64GB004 Family of USB microcontrollers, the PLL will not power up and be enabled |
//by default, even if a PLL enabled oscillator configuration is selected (such as HS+PLL). |
//This allows the device to power up at a lower initial operating frequency, which can be |
//advantageous when powered from a source which is not gauranteed to be adequate for 32MHz |
//operation. On these devices, user firmware needs to manually set the CLKDIV<PLLEN> bit to |
//power up the PLL. |
{ |
unsigned int pll_startup_counter = 600; |
CLKDIVbits.PLLEN = 1; |
while(pll_startup_counter--); |
} |
//Device switches over automatically to PLL output after PLL is locked and ready. |
#endif |
// The USB specifications require that USB peripheral devices must never source |
// current onto the Vbus pin. Additionally, USB peripherals should not source |
// current on D+ or D- when the host/hub is not actively powering the Vbus line. |
// When designing a self powered (as opposed to bus powered) USB peripheral |
// device, the firmware should make sure not to turn on the USB module and D+ |
// or D- pull up resistor unless Vbus is actively powered. Therefore, the |
// firmware needs some means to detect when Vbus is being powered by the host. |
// A 5V tolerant I/O pin can be connected to Vbus (through a resistor), and |
// can be used to detect when Vbus is high (host actively powering), or low |
// (host is shut down or otherwise not supplying power). The USB firmware |
// can then periodically poll this I/O pin to know when it is okay to turn on |
// the USB module/D+/D- pull up resistor. When designing a purely bus powered |
// peripheral device, it is not possible to source current on D+ or D- when the |
// host is not actively providing power on Vbus. Therefore, implementing this |
// bus sense feature is optional. This firmware can be made to use this bus |
// sense feature by making sure "USE_USB_BUS_SENSE_IO" has been defined in the |
// HardwareProfile.h file. |
#if defined(USE_USB_BUS_SENSE_IO) |
tris_usb_bus_sense = INPUT_PIN; // See HardwareProfile.h |
#endif |
// If the host PC sends a GetStatus (device) request, the firmware must respond |
// and let the host know if the USB peripheral device is currently bus powered |
// or self powered. See chapter 9 in the official USB specifications for details |
// regarding this request. If the peripheral device is capable of being both |
// self and bus powered, it should not return a hard coded value for this request. |
// Instead, firmware should check if it is currently self or bus powered, and |
// respond accordingly. If the hardware has been configured like demonstrated |
// on the PICDEM FS USB Demo Board, an I/O pin can be polled to determine the |
// currently selected power source. On the PICDEM FS USB Demo Board, "RA2" |
// is used for this purpose. If using this feature, make sure "USE_SELF_POWER_SENSE_IO" |
// has been defined in HardwareProfile - (platform).h, and that an appropriate I/O pin |
// has been mapped to it. |
#if defined(USE_SELF_POWER_SENSE_IO) |
tris_self_power = INPUT_PIN; // See HardwareProfile |
#endif |
UserInit(); |
USBDeviceInit(); //usb_device.c. Initializes USB module SFRs and firmware |
//variables to known states. |
}//end InitializeSystem |
// ****************************************************************************************************** |
// ************** USB Callback Functions **************************************************************** |
// ****************************************************************************************************** |
// The USB firmware stack will call the callback functions USBCBxxx() in response to certain USB related |
// events. For example, if the host PC is powering down, it will stop sending out Start of Frame (SOF) |
// packets to your device. In response to this, all USB devices are supposed to decrease their power |
// consumption from the USB Vbus to <2.5mA each. The USB module detects this condition (which according |
// to the USB specifications is 3+ms of no bus activity/SOF packets) and then calls the USBCBSuspend() |
// function. You should modify these callback functions to take appropriate actions for each of these |
// conditions. For example, in the USBCBSuspend(), you may wish to add code that will decrease power |
// consumption from Vbus to <2.5mA (such as by clock switching, turning off LEDs, putting the |
// microcontroller to sleep, etc.). Then, in the USBCBWakeFromSuspend() function, you may then wish to |
// add code that undoes the power saving things done in the USBCBSuspend() function. |
// The USBCBSendResume() function is special, in that the USB stack will not automatically call this |
// function. This function is meant to be called from the application firmware instead. See the |
// additional comments near the function. |
/****************************************************************************** |
* Function: void USBCBSuspend(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: Call back that is invoked when a USB suspend is detected |
* |
* Note: None |
*****************************************************************************/ |
void USBCBSuspend(void) |
{ |
//Example power saving code. Insert appropriate code here for the desired |
//application behavior. If the microcontroller will be put to sleep, a |
//process similar to that shown below may be used: |
//ConfigureIOPinsForLowPower(); |
//SaveStateOfAllInterruptEnableBits(); |
//DisableAllInterruptEnableBits(); |
//EnableOnlyTheInterruptsWhichWillBeUsedToWakeTheMicro(); //should enable at least USBActivityIF as a wake source |
//Sleep(); |
//RestoreStateOfAllPreviouslySavedInterruptEnableBits(); //Preferrably, this should be done in the USBCBWakeFromSuspend() function instead. |
//RestoreIOPinsToNormal(); //Preferrably, this should be done in the USBCBWakeFromSuspend() function instead. |
//IMPORTANT NOTE: Do not clear the USBActivityIF (ACTVIF) bit here. This bit is |
//cleared inside the usb_device.c file. Clearing USBActivityIF here will cause |
//things to not work as intended. |
#if defined(__C30__) |
#if 0 |
U1EIR = 0xFFFF; |
U1IR = 0xFFFF; |
U1OTGIR = 0xFFFF; |
IFS5bits.USB1IF = 0; |
IEC5bits.USB1IE = 1; |
U1OTGIEbits.ACTVIE = 1; |
U1OTGIRbits.ACTVIF = 1; |
Sleep(); |
#endif |
#endif |
} |
/****************************************************************************** |
* Function: void _USB1Interrupt(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: This function is called when the USB interrupt bit is set |
* In this example the interrupt is only used when the device |
* goes to sleep when it receives a USB suspend command |
* |
* Note: None |
*****************************************************************************/ |
#if 0 |
void __attribute__ ((interrupt)) _USB1Interrupt(void) |
{ |
#if !defined(self_powered) |
if(U1OTGIRbits.ACTVIF) |
{ |
IEC5bits.USB1IE = 0; |
U1OTGIEbits.ACTVIE = 0; |
IFS5bits.USB1IF = 0; |
//USBClearInterruptFlag(USBActivityIFReg,USBActivityIFBitNum); |
USBClearInterruptFlag(USBIdleIFReg,USBIdleIFBitNum); |
//USBSuspendControl = 0; |
} |
#endif |
} |
#endif |
/****************************************************************************** |
* Function: void USBCBWakeFromSuspend(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: The host may put USB peripheral devices in low power |
* suspend mode (by "sending" 3+ms of idle). Once in suspend |
* mode, the host may wake the device back up by sending non- |
* idle state signalling. |
* |
* This call back is invoked when a wakeup from USB suspend |
* is detected. |
* |
* Note: None |
*****************************************************************************/ |
void USBCBWakeFromSuspend(void) |
{ |
// If clock switching or other power savings measures were taken when |
// executing the USBCBSuspend() function, now would be a good time to |
// switch back to normal full power run mode conditions. The host allows |
// a few milliseconds of wakeup time, after which the device must be |
// fully back to normal, and capable of receiving and processing USB |
// packets. In order to do this, the USB module must receive proper |
// clocking (IE: 48MHz clock must be available to SIE for full speed USB |
// operation). |
} |
/******************************************************************** |
* Function: void USBCB_SOF_Handler(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: The USB host sends out a SOF packet to full-speed |
* devices every 1 ms. This interrupt may be useful |
* for isochronous pipes. End designers should |
* implement callback routine as necessary. |
* |
* Note: None |
*******************************************************************/ |
void USBCB_SOF_Handler(void) |
{ |
// No need to clear UIRbits.SOFIF to 0 here. |
// Callback caller is already doing that. |
} |
/******************************************************************* |
* Function: void USBCBErrorHandler(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: The purpose of this callback is mainly for |
* debugging during development. Check UEIR to see |
* which error causes the interrupt. |
* |
* Note: None |
*******************************************************************/ |
void USBCBErrorHandler(void) |
{ |
// No need to clear UEIR to 0 here. |
// Callback caller is already doing that. |
// Typically, user firmware does not need to do anything special |
// if a USB error occurs. For example, if the host sends an OUT |
// packet to your device, but the packet gets corrupted (ex: |
// because of a bad connection, or the user unplugs the |
// USB cable during the transmission) this will typically set |
// one or more USB error interrupt flags. Nothing specific |
// needs to be done however, since the SIE will automatically |
// send a "NAK" packet to the host. In response to this, the |
// host will normally retry to send the packet again, and no |
// data loss occurs. The system will typically recover |
// automatically, without the need for application firmware |
// intervention. |
// Nevertheless, this callback function is provided, such as |
// for debugging purposes. |
} |
/******************************************************************* |
* Function: void USBCBCheckOtherReq(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: When SETUP packets arrive from the host, some |
* firmware must process the request and respond |
* appropriately to fulfill the request. Some of |
* the SETUP packets will be for standard |
* USB "chapter 9" (as in, fulfilling chapter 9 of |
* the official USB specifications) requests, while |
* others may be specific to the USB device class |
* that is being implemented. For example, a HID |
* class device needs to be able to respond to |
* "GET REPORT" type of requests. This |
* is not a standard USB chapter 9 request, and |
* therefore not handled by usb_device.c. Instead |
* this request should be handled by class specific |
* firmware, such as that contained in usb_function_hid.c. |
* |
* Note: None |
*****************************************************************************/ |
void USBCBCheckOtherReq(void) |
{ |
USBCheckUBWRequest(); |
}//end |
/******************************************************************* |
* Function: void USBCBStdSetDscHandler(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: The USBCBStdSetDscHandler() callback function is |
* called when a SETUP, bRequest: SET_DESCRIPTOR request |
* arrives. Typically SET_DESCRIPTOR requests are |
* not used in most applications, and it is |
* optional to support this type of request. |
* |
* Note: None |
*****************************************************************************/ |
void USBCBStdSetDscHandler(void) |
{ |
// Must claim session ownership if supporting this request |
}//end |
/****************************************************************************** |
* Function: void USBCBInitEP(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: This function is called when the device becomes |
* initialized, which occurs after the host sends a |
* SET_CONFIGURATION (wValue not = 0) request. This |
* callback function should initialize the endpoints |
* for the device's usage according to the current |
* configuration. |
* |
* Note: None |
*****************************************************************************/ |
void USBCBInitEP(void) |
{ |
} |
/******************************************************************** |
* Function: void USBCBSendResume(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: The USB specifications allow some types of USB |
* peripheral devices to wake up a host PC (such |
* as if it is in a low power suspend to RAM state). |
* This can be a very useful feature in some |
* USB applications, such as an Infrared remote |
* control receiver. If a user presses the "power" |
* button on a remote control, it is nice that the |
* IR receiver can detect this signalling, and then |
* send a USB "command" to the PC to wake up. |
* |
* The USBCBSendResume() "callback" function is used |
* to send this special USB signalling which wakes |
* up the PC. This function may be called by |
* application firmware to wake up the PC. This |
* function should only be called when: |
* |
* 1. The USB driver used on the host PC supports |
* the remote wakeup capability. |
* 2. The USB configuration descriptor indicates |
* the device is remote wakeup capable in the |
* bmAttributes field. |
* 3. The USB host PC is currently sleeping, |
* and has previously sent your device a SET |
* FEATURE setup packet which "armed" the |
* remote wakeup capability. |
* |
* This callback should send a RESUME signal that |
* has the period of 1-15ms. |
* |
* Note: Interrupt vs. Polling |
* -Primary clock |
* -Secondary clock ***** MAKE NOTES ABOUT THIS ******* |
* > Can switch to primary first by calling USBCBWakeFromSuspend() |
* The modifiable section in this routine should be changed |
* to meet the application needs. Current implementation |
* temporary blocks other functions from executing for a |
* period of 1-13 ms depending on the core frequency. |
* |
* According to USB 2.0 specification section 7.1.7.7, |
* "The remote wakeup device must hold the resume signaling |
* for at lest 1 ms but for no more than 15 ms." |
* The idea here is to use a delay counter loop, using a |
* common value that would work over a wide range of core |
* frequencies. |
* That value selected is 1800. See table below: |
* ========================================================== |
* Core Freq(MHz) MIP RESUME Signal Period (ms) |
* ========================================================== |
* 48 12 1.05 |
* 4 1 12.6 |
* ========================================================== |
* * These timing could be incorrect when using code |
* optimization or extended instruction mode, |
* or when having other interrupts enabled. |
* Make sure to verify using the MPLAB SIM's Stopwatch |
* and verify the actual signal on an oscilloscope. |
*******************************************************************/ |
void USBCBSendResume(void) |
{ |
static WORD delay_count; |
USBResumeControl = 1; // Start RESUME signaling |
delay_count = 1800U; // Set RESUME line for 1-13 ms |
do |
{ |
delay_count--; |
}while(delay_count); |
USBResumeControl = 0; |
} |
/******************************************************************* |
* Function: BOOL USER_USB_CALLBACK_EVENT_HANDLER( |
* USB_EVENT event, void *pdata, WORD size) |
* |
* PreCondition: None |
* |
* Input: USB_EVENT event - the type of event |
* void *pdata - pointer to the event data |
* WORD size - size of the event data |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: This function is called from the USB stack to |
* notify a user application that a USB event |
* occured. This callback is in interrupt context |
* when the USB_INTERRUPT option is selected. |
* |
* Note: None |
*******************************************************************/ |
BOOL USER_USB_CALLBACK_EVENT_HANDLER(USB_EVENT event, void *pdata, WORD size) |
{ |
switch(event) |
{ |
case EVENT_CONFIGURED: |
USBCBInitEP(); |
break; |
case EVENT_SET_DESCRIPTOR: |
USBCBStdSetDscHandler(); |
break; |
case EVENT_EP0_REQUEST: |
USBCBCheckOtherReq(); |
break; |
case EVENT_SOF: |
USBCB_SOF_Handler(); |
break; |
case EVENT_SUSPEND: |
USBCBSuspend(); |
break; |
case EVENT_RESUME: |
USBCBWakeFromSuspend(); |
break; |
case EVENT_BUS_ERROR: |
USBCBErrorHandler(); |
break; |
case EVENT_TRANSFER: |
Nop(); |
break; |
default: |
break; |
} |
return TRUE; |
} |
/** EOF main.c ***************************************************************/ |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/rm18f4550 - HID Bootload.lkr |
---|
0,0 → 1,44 |
// File: Application_18f4550.lkr |
// Use this linker for the USB application that will be self programmed by the HID bootloader. |
// The HID bootloader project itself uses the BootModified.18f4450.lkr file instead. |
// THIS LINKER SCRIPT HAS BEEN MODIFIED... This version is intended to be used |
// with the "PROGRAMMABLE_WITH_USB_HID_BOOTLOADER" bootloader. The HID |
// bootloader occupies memory ranges 0x000-0xFFF. In order for the code generated |
// by this project to work with the bootloader, the linker must not put any code |
// in the 0x00-0xFFF address range. |
// This linker script was originated from the 18f4550.lkr file provided by |
// the MCC18 distribution. |
LIBPATH . |
FILES c018i.o |
FILES clib.lib |
FILES p18f4550.lib |
CODEPAGE NAME=bootloader START=0x0 END=0xFFF PROTECTED |
CODEPAGE NAME=vectors START=0x1000 END=0x1029 PROTECTED |
CODEPAGE NAME=page START=0x102A END=0x7FFF |
CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED |
CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED |
CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED |
CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED |
ACCESSBANK NAME=accessram START=0x0 END=0x5F |
DATABANK NAME=gpr0 START=0x60 END=0xFF |
DATABANK NAME=gpr1 START=0x100 END=0x1FF |
DATABANK NAME=gpr2 START=0x200 END=0x2FF |
DATABANK NAME=gpr3 START=0x300 END=0x3FF |
DATABANK NAME=usb4 START=0x400 END=0x4FF PROTECTED |
DATABANK NAME=usb5 START=0x500 END=0x5FF PROTECTED |
DATABANK NAME=usb6 START=0x600 END=0x6FF PROTECTED |
DATABANK NAME=usb7 START=0x700 END=0x7FF PROTECTED |
ACCESSBANK NAME=accesssfr START=0xF60 END=0xFFF PROTECTED |
SECTION NAME=CONFIG ROM=config |
STACK SIZE=0x100 RAM=gpr3 |
SECTION NAME=USB_VARS RAM=usb4 |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/rm18f4550 - MCHPUSB Bootload.lkr |
---|
0,0 → 1,37 |
// FileName: rm18f4550.lkr |
// Sample linker command file for 18F4550 with Bootloader |
// |
//Change History: |
// Rev Date Description |
// 1.0 10/30/2004 Initial release |
LIBPATH . |
FILES c018i.o |
FILES clib.lib |
FILES p18f4550.lib |
CODEPAGE NAME=boot START=0x0 END=0x7FF PROTECTED |
CODEPAGE NAME=vectors START=0x800 END=0x0x829 PROTECTED |
CODEPAGE NAME=page START=0x82A END=0x7FFF |
CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED |
CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED |
CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED |
CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED |
ACCESSBANK NAME=accessram START=0x0 END=0x5F |
DATABANK NAME=gpr0 START=0x60 END=0xFF |
DATABANK NAME=gpr1 START=0x100 END=0x1FF |
DATABANK NAME=gpr2 START=0x200 END=0x2FF |
DATABANK NAME=gpr3 START=0x300 END=0x3FF |
DATABANK NAME=usb4 START=0x400 END=0x4FF PROTECTED |
DATABANK NAME=usb5 START=0x500 END=0x5FF PROTECTED |
DATABANK NAME=usb6 START=0x600 END=0x6FF PROTECTED |
DATABANK NAME=usb7 START=0x700 END=0x7FF PROTECTED |
ACCESSBANK NAME=accesssfr START=0xF60 END=0xFFF PROTECTED |
SECTION NAME=CONFIG ROM=config |
STACK SIZE=0x100 RAM=gpr3 |
SECTION NAME=USB_VARS RAM=usb4 |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/rm18f4550.lkr |
---|
0,0 → 1,37 |
// FileName: rm18f4550.lkr |
// Sample linker command file for 18F4550 with Bootloader |
// |
//Change History: |
// Rev Date Description |
// 1.0 10/30/2004 Initial release |
LIBPATH . |
FILES c018i.o |
FILES clib.lib |
FILES p18f4550.lib |
CODEPAGE NAME=boot START=0x0 END=0x7FF PROTECTED |
CODEPAGE NAME=vectors START=0x800 END=0x0x829 PROTECTED |
CODEPAGE NAME=page START=0x82A END=0x7FFF |
CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED |
CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED |
CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED |
CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED |
ACCESSBANK NAME=accessram START=0x0 END=0x5F |
DATABANK NAME=gpr0 START=0x60 END=0xFF |
DATABANK NAME=gpr1 START=0x100 END=0x1FF |
DATABANK NAME=gpr2 START=0x200 END=0x2FF |
DATABANK NAME=gpr3 START=0x300 END=0x3FF |
DATABANK NAME=usb4 START=0x400 END=0x4FF PROTECTED |
DATABANK NAME=usb5 START=0x500 END=0x5FF PROTECTED |
DATABANK NAME=usb6 START=0x600 END=0x6FF PROTECTED |
DATABANK NAME=usb7 START=0x700 END=0x7FF PROTECTED |
ACCESSBANK NAME=accesssfr START=0xF60 END=0xFFF PROTECTED |
SECTION NAME=CONFIG ROM=config |
STACK SIZE=0x100 RAM=gpr3 |
SECTION NAME=USB_VARS RAM=usb4 |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/temperature.c |
---|
0,0 → 1,412 |
/********************************************************************* |
* |
* Thermo Sensor |
* |
********************************************************************* |
* FileName: temperature.c |
* Dependencies: See INCLUDES section below |
* Processor: PIC18 |
* Compiler: C18 2.30.01+ |
* Company: Microchip Technology, Inc. |
* |
* Software License Agreement |
* |
* The software supplied herewith by Microchip Technology Incorporated |
* (the Company) for its PICmicro® Microcontroller is intended and |
* supplied to you, the Companys customer, for use solely and |
* exclusively on Microchip PICmicro Microcontroller products. The |
* software is owned by the Company and/or its supplier, and is |
* protected under applicable copyright laws. All rights are reserved. |
* Any use in violation of the foregoing restrictions may subject the |
* user to criminal sanctions under applicable laws, as well as to |
* civil liability for the breach of the terms and conditions of this |
* license. |
* |
* THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
* TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
* PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
* |
********************************************************************/ |
/** I N C L U D E S **********************************************************/ |
#include "Compiler.h" |
#include "GenericTypeDefs.h" |
#include "HardwareProfile.h" |
#include "temperature.h" |
#if defined(__18CXX) |
#include <spi.h> |
#endif |
/** V A R I A B L E S ********************************************************/ |
#pragma udata |
unsigned int I2CStateVariable; // Used for keeping track of the I2C state |
// machine when using the HPC Explorer board's |
// I2C based TC74 temperature sensor. |
signed char TempAccumulator; // Used for averaging temperature samples |
signed char TempSave; |
WORD_VAL temperature; // Raw data format |
char tempString[10]; // Buffer for storing data in ASCII format |
/** P R I V A T E P R O T O T Y P E S ***************************************/ |
/** D E C L A R A T I O N S **************************************************/ |
#pragma code |
/****************************************************************************** |
* Function: void InitTempSensor(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: Initializes SPI interface & chip select line |
* |
* Note: None |
*****************************************************************************/ |
void InitTempSensor(void) |
{ |
#if defined(PICDEM_FS_USB) |
cs_temp_sensor = 1; |
tris_cs_temp_sensor = OUTPUT_PIN; |
OpenSPI(SPI_FOSC_64, MODE_11, SMPMID); |
// Initialize readable values - default to room temperature |
temperature.Val = 0x0C87; // 25 degree celsius |
UpdateCelsiusASCII(); |
#elif defined(PIC18F87J50_PIM) |
temperature.Val = 0x0C87; // 25 degree celsius |
UpdateCelsiusASCII(); |
//Need to initialize I2C Module to prepare for communication with |
//TC74 temperature sensor on the HPC Explorer board. |
mInitI2CPins(); // See io_cfg.h |
SSP1STAT = 0xC0; // Slew rate control disabled, SMBus |
SSP1CON1 = 0x08; // I2C Master mode |
SSP1CON2 = 0x00; |
SSP1ADD = 0x7D; // Just under 100kHz at 48MHz core frequency |
SSP1CON1bits.SSPEN = 1; // Enable MSSP module |
I2CStateVariable = 0; // Initial state for I2C state machine |
#endif |
}//end InitTempSensor |
/****************************************************************************** |
* Function: void AcquireTemperature(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: None |
* |
* Note: None |
*****************************************************************************/ |
BOOL AcquireTemperature(void) |
{ |
#if defined(PICDEM_FS_USB) |
//The PICDEM FS USB Demo Board uses a TC77 (13 bit) temperature sensor and |
//communicates with it through the SPI interface. |
cs_temp_sensor = 0; |
temperature.v[1] = ReadSPI(); |
temperature.v[0] = ReadSPI(); |
cs_temp_sensor = 1; |
if(temperature.bits.b2 == 0) |
return FALSE; |
#elif defined(__C30__) || defined(__C32__) |
//Create temp variables to store the conversion data |
float temp; |
//get ready to sample the A/D |
#if defined(__C30__) |
AD1CHS = 0x4; //MUXA uses AN4 |
AD1PCFGLbits.PCFG4 = 0; |
for(temp=0;temp<1000;temp++); //Sample delay |
// Get an ADC sample |
AD1CON1bits.SAMP = 1; //Start sampling |
for(temp=0;temp<1000;temp++); //Sample delay, conversion start automatically |
AD1CON1bits.SAMP = 0; //Start sampling |
for(temp=0;temp<1000;temp++); //Sample delay, conversion start automatically |
while(!AD1CON1bits.DONE); //Wait for conversion to complete |
#else |
AD1PCFGbits.PCFG4 = 0; |
AD1CON1 = 0x0000; // SAMP bit = 0 ends sampling ... |
// and starts converting |
AD1CHS = 0x00040000; // Connect RB4/AN4 as CH0 input .. |
// in this example RB2/AN2 is the input |
AD1CSSL = 0; |
AD1CON3 = 0x0002; // Manual Sample, Tad = internal 6 TPB |
AD1CON2 = 0; |
AD1CON1SET = 0x8000; // turn ADC ON |
AD1CON1SET = 0x0002; // start sampling ... |
for(temp=0;temp<1000;temp++); //Sample delay, conversion start automatically |
AD1CON1CLR = 0x0002; // start Converting |
while (!(AD1CON1 & 0x0001));// conversion done? |
#endif |
//convert the results to a float |
temp = (float)ADC1BUF0; |
// voltage = A2D_reading * 3.3v / 1024 |
temp *= 3.3; |
temp /= 1024; |
// align to 0C (subtracting -.65v) |
temp -= .55; |
//convert to TC77 style output and store to temperature |
temp *= 12800; |
temperature.Val = (WORD)temp; |
temperature.Val |= 0x7; |
//#elif defined(__C32__) |
//#warning "TODO" |
#elif defined(PIC18F87J50_PIM) // Uses TC74 (8 bit) |
//The PIC18F87J50 FS USB Plug-In Module (PIM) does not have a temperature |
//sensor, but there is a TC74 (8 bit) I2C based temperature sensor on the |
//HPC Explorer demo board. In order for this temperature demo code to do |
//anything useful, the PIM should be used in conjunction with the HPC Explorer. |
//The TC74 comes in 5V and 3.3V optimized versions. If a 5V part is run at |
//3.3V (as with the PIM installed), it may have relatively large offsets. |
return TRUE; // Don't need to do anything in this function, temperature |
// polling with the PIC18F87J50 FS USB Plug-In Module is |
// done with the PollTempOnHPCExplorer() function. |
// This is done so the I2C communication can be done with |
// a non-blocking approach. |
#elif defined(LOW_PIN_COUNT_USB_DEVELOPMENT_KIT) |
temperature.Val = 0x0000; |
return TRUE; |
#elif defined(PIC18F46J50_PIM) |
//Create temp variables to store the conversion data |
float temp; |
//get ready to sample the A/D |
ADCON0bits.CHS = 0x07; |
for(temp=0;temp<1000;temp++){} |
ADCON0bits.GO = 1; // Start AD conversion |
while(ADCON0bits.NOT_DONE); // Wait for conversion |
//convert the results to a float |
temp = (float)ADRES; |
// voltage = A2D_reading * 3.3v / 1024 |
temp *= 3.3; |
temp /= 1024; |
// align to 0C (subtracting -.65v) |
temp -= .55; |
//convert to TC77 style output and store to temperature |
temp *= 12800; |
temperature.Val = (WORD)temp; |
temperature.Val |= 0x7; |
return TRUE; |
#else |
#error "Unknown temperature acquire configuration. See AcquireTemperature function in __FILE__" |
#endif |
return TRUE; |
}//end AcquireTemperature |
/****************************************************************************** |
* Function: void PollTempOnHPCExplorer(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: Temperature data from TC74 on HPC Explorer, but formatted |
* like the TC77, stored in the "temperature" variable. |
* Side Effects: None |
* |
* Overview: None |
* |
* Note: None |
*****************************************************************************/ |
#if defined(PIC18F87J50_PIM) |
void PollTempOnHPCExplorer(void) |
{ |
//The PIC18F87J50 FS USB Plug-In Module (PIM) does not have a temperature |
//sensor, but there is a TC74 (8 bit) I2C based temperature sensor on the |
//HPC Explorer demo board. In order for this temperature demo code to do |
//anything useful, the PIM must be used in conjunction with the HPC Explorer. |
//The TC74 comes in 5V and 3.3V optimized versions. If a 5V part is run at |
//3.3V (as with the PIM installed), it may have relatively large offsets. |
#define TC74AddressWrite 0b10011010 // This is the default address for the TC74, use this for writes |
#define TC74AddressRead 0b10011011 // This is the default address for the TC74, use this for reads |
#define RTR 0x00 // This is the read temp command for TC74 |
// Should not use blocking functions in USB code. Therefore, these I2C |
// communications are done with a state machine as shown below. |
switch(I2CStateVariable) |
{ |
case 0x00: |
PIR1bits.SSP1IF = 0; |
SSP1CON2bits.SEN = 1; // Send Start Bit |
I2CStateVariable = 0x01; |
break; |
case 0x01: |
if(PIR1bits.SSP1IF == 0) {break;} |
PIR1bits.SSP1IF = 0; |
SSP1BUF = TC74AddressWrite; // Begin sending the actual address |
I2CStateVariable = 0x02; |
break; |
case 0x02: |
if(PIR1bits.SSP1IF == 0) {break;} |
PIR1bits.SSP1IF = 0; |
SSP1BUF = RTR; // Send command to select the TEMP register |
I2CStateVariable = 0x03; |
break; |
case 0x03: |
if(PIR1bits.SSP1IF == 0) {break;} |
PIR1bits.SSP1IF = 0; |
SSP1CON2bits.SEN = 1; // Send another start bit |
I2CStateVariable = 0x04; |
break; |
case 0x04: |
if(PIR1bits.SSP1IF == 0) {break;} |
PIR1bits.SSP1IF = 0; |
SSP1BUF = TC74AddressRead; // Send the address again, but this time "read" |
I2CStateVariable = 0x05; |
break; |
case 0x05: |
if(PIR1bits.SSP1IF == 0) {break;} |
PIR1bits.SSP1IF = 0; |
SSP1CON2bits.RCEN = 1; // Initiate read from device |
I2CStateVariable = 0x06; |
break; |
case 0x06: |
if(PIR1bits.SSP1IF == 0) {break;} |
PIR1bits.SSP1IF = 0; |
TempSave = SSP1BUF; // Finally got the result, need to save it |
SSP1CON2bits.ACKDT = 1; // Prepare I2C NACK handshake |
SSP1CON2bits.ACKEN = 1; // Send the acknowledge bit |
I2CStateVariable = 0x07; |
break; |
case 0x07: |
if(PIR1bits.SSP1IF == 0) {break;} |
PIR1bits.SSP1IF = 0; |
SSP1CON2bits.PEN = 1; // Now send a stop bit |
I2CStateVariable = 0x08; |
break; |
case 0x08: |
if(PIR1bits.SSP1IF == 0) {break;} |
PIR1bits.SSP1IF = 0; |
I2CStateVariable = 0x09; |
break; |
case 0x09: |
TempAccumulator = ((TempAccumulator + TempSave) / 2); // Get an average |
I2CStateVariable = 0x10; |
break; |
case 0x10: |
//Now format data like that of the TC77, which is what the PC side code expects, |
//since it was originally intended to be used with the TC77. |
temperature.v[1] = TempAccumulator; |
if(temperature.bits.b15 == 0) // == 0 when positive temperature |
{ |
temperature.Val = temperature.Val >> 1; |
temperature.bits.b15 = 0; // Positive temperature, upper MSb clear |
} |
else |
{ |
temperature.Val = temperature.Val >> 1; |
temperature.bits.b15 = 1; // Negative temperature, upper MSb set |
} |
temperature.bits.b0 = 1; // Lower three LSbs = 1 on TC74 format |
temperature.bits.b1 = 1; // Lower three LSbs = 1 on TC74 format |
temperature.bits.b2 = 1; // Lower three LSbs = 1 on TC74 format |
I2CStateVariable = 0x11; // Could go back to 0, but don't want to poll that fast |
break; |
case 0x5000: // This slows down the sample rate of the device. |
I2CStateVariable = 0x00; // The temp sensor itself only updates around 8 times/sec. |
break; |
default: |
I2CStateVariable++; |
break; |
}//end switch |
}//end PollTempOnHPCExplorer |
#endif |
/****************************************************************************** |
* Function: void UpdateCelsiusASCII(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: This routine converts data output to ASCII string |
* |
* Note: None |
*****************************************************************************/ |
void UpdateCelsiusASCII(void) |
{ |
WORD_VAL temp; |
BYTE i; |
temp.Val = temperature.Val >> 3; |
if(temp.bits.b12 == 0) |
{ |
temp.byte.HB &= 0x1F; |
tempString[0] = '+'; |
} |
else |
{ |
temp.byte.HB |= 0xE0; |
tempString[0] = '-'; |
temp.Val = temp.Val ^ 0xFFFF; // Negate |
temp.Val++; |
}//end if |
temp.Val = (temp.Val*10U) >> 4; // Turn into celsius xx.x |
/* Populate string */ |
for(i=4;i>0;i--) |
{ |
tempString[i] = (((char)(temp.Val % 10)) & 0x0F) | 0x30; |
temp.Val /= 10; |
}//end for |
/* Turn leading zeros into spaces */ |
if(tempString[1] == '0') |
{ |
tempString[1] = ' '; |
if(tempString[2] == '0') |
tempString[2] = ' '; |
}//end if |
/* Adjust decimal digit */ |
tempString[5] = tempString[4]; |
tempString[4]='.'; |
tempString[6]=0xF8; // Degree symbol |
tempString[7]='C'; |
tempString[8]='\r'; |
tempString[9]=0x00; // Null-Terminated |
}//end UpdateCelsiusASCII |
/** EOF temperature.c ********************************************************/ |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/temperature.h |
---|
0,0 → 1,51 |
/********************************************************************* |
* |
* Thermo Sensor with SPI(TM) Interface |
* |
********************************************************************* |
* FileName: temperature.h |
* Dependencies: See INCLUDES section below |
* Processor: PIC18 |
* Compiler: C18 2.30.01+ |
* Company: Microchip Technology, Inc. |
* |
* Software License Agreement |
* |
* The software supplied herewith by Microchip Technology Incorporated |
* (the Company) for its PICmicro® Microcontroller is intended and |
* supplied to you, the Companys customer, for use solely and |
* exclusively on Microchip PICmicro Microcontroller products. The |
* software is owned by the Company and/or its supplier, and is |
* protected under applicable copyright laws. All rights are reserved. |
* Any use in violation of the foregoing restrictions may subject the |
* user to criminal sanctions under applicable laws, as well as to |
* civil liability for the breach of the terms and conditions of this |
* license. |
* |
* THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
* TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
* PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
* |
********************************************************************/ |
#ifndef TEMPERATURE_H |
#define TEMPERATURE_H |
/** E X T E R N S ************************************************************/ |
extern WORD_VAL temperature; |
extern char tempString[10]; |
/** P U B L I C P R O T O T Y P E S *****************************************/ |
void InitTempSensor(void); |
BOOL AcquireTemperature(void); |
void UpdateCelsiusASCII(void); |
#if defined(PIC18F87J50_PIM) |
void PollTempOnHPCExplorer(void); |
#else |
#define PollTempOnHPCExplorer() |
#endif |
#endif //TEMPERATURE_H |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/usb_config.h |
---|
0,0 → 1,125 |
/******************************************************************** |
FileName: usb_config.h |
Dependencies: Always: GenericTypeDefs.h, usb_device.h |
Situational: usb_function_hid.h, usb_function_cdc.h, usb_function_msd.h, etc. |
Processor: PIC18 or PIC24 USB Microcontrollers |
Hardware: The code is natively intended to be used on the following |
hardware platforms: PICDEM FS USB Demo Board, |
PIC18F87J50 FS USB Plug-In Module, or |
Explorer 16 + PIC24 USB PIM. The firmware may be |
modified for use on other USB platforms by editing the |
HardwareProfile.h file. |
Complier: Microchip C18 (for PIC18) or C30 (for PIC24) |
Company: Microchip Technology, Inc. |
Software License Agreement: |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
Any use in violation of the foregoing restrictions may subject the |
user to criminal sanctions under applicable laws, as well as to |
civil liability for the breach of the terms and conditions of this |
license. |
THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
******************************************************************** |
File Description: |
Change History: |
Rev Date Description |
1.0 11/19/2004 Initial release |
2.1 02/26/2007 Updated for simplicity and to use common |
coding style |
*******************************************************************/ |
/********************************************************************* |
* Descriptor specific type definitions are defined in: usbd.h |
********************************************************************/ |
#ifndef USBCFG_H |
#define USBCFG_H |
/** DEFINITIONS ****************************************************/ |
#define USB_EP0_BUFF_SIZE 8 // Valid Options: 8, 16, 32, or 64 bytes. |
// Using larger options take more SRAM, but |
// does not provide much advantage in most types |
// of applications. Exceptions to this, are applications |
// that use EP0 IN or OUT for sending large amounts of |
// application related data. |
#define USB_MAX_NUM_INT 1 // For tracking Alternate Setting |
#define USB_MAX_EP_NUMBER 1 |
//Device descriptor - if these two definitions are not defined then |
// a ROM USB_DEVICE_DESCRIPTOR variable by the exact name of device_dsc |
// must exist. |
#define USB_USER_DEVICE_DESCRIPTOR &device_dsc |
#define USB_USER_DEVICE_DESCRIPTOR_INCLUDE extern ROM USB_DEVICE_DESCRIPTOR device_dsc |
//Configuration descriptors - if these two definitions do not exist then |
// a ROM BYTE *ROM variable named exactly USB_CD_Ptr[] must exist. |
#define USB_USER_CONFIG_DESCRIPTOR USB_CD_Ptr |
#define USB_USER_CONFIG_DESCRIPTOR_INCLUDE extern ROM BYTE *ROM USB_CD_Ptr[] |
//Make sure only one of the below "#define USB_PING_PONG_MODE" |
//is uncommented. |
//#define USB_PING_PONG_MODE USB_PING_PONG__NO_PING_PONG |
#define USB_PING_PONG_MODE USB_PING_PONG__FULL_PING_PONG |
//#define USB_PING_PONG_MODE USB_PING_PONG__EP0_OUT_ONLY |
//#define USB_PING_PONG_MODE USB_PING_PONG__ALL_BUT_EP0 //NOTE: This mode is not supported in PIC18F4550 family rev A3 devices |
#define USB_POLLING |
//#define USB_INTERRUPT |
/* Parameter definitions are defined in usb_device.h */ |
#define USB_PULLUP_OPTION USB_PULLUP_ENABLE |
//#define USB_PULLUP_OPTION USB_PULLUP_DISABLED |
#define USB_TRANSCEIVER_OPTION USB_INTERNAL_TRANSCEIVER |
//External Transceiver support is not available on all product families. Please |
// refer to the product family datasheet for more information if this feature |
// is available on the target processor. |
//#define USB_TRANSCEIVER_OPTION USB_EXTERNAL_TRANSCEIVER |
#define USB_SPEED_OPTION USB_FULL_SPEED |
//#define USB_SPEED_OPTION USB_LOW_SPEED //(not valid option for PIC24F devices) |
#define USB_SUPPORT_DEVICE |
#define USB_NUM_STRING_DESCRIPTORS 4 |
//#define USB_INTERRUPT_LEGACY_CALLBACKS |
#define USB_ENABLE_ALL_HANDLERS |
//#define USB_ENABLE_SUSPEND_HANDLER |
//#define USB_ENABLE_WAKEUP_FROM_SUSPEND_HANDLER |
//#define USB_ENABLE_SOF_HANDLER |
//#define USB_ENABLE_ERROR_HANDLER |
//#define USB_ENABLE_OTHER_REQUEST_HANDLER |
//#define USB_ENABLE_SET_DESCRIPTOR_HANDLER |
//#define USB_ENABLE_INIT_EP_HANDLER |
//#define USB_ENABLE_EP0_DATA_HANDLER |
//#define USB_ENABLE_TRANSFER_COMPLETE_HANDLER |
/** DEVICE CLASS USAGE *********************************************/ |
#define USB_USE_GEN |
/** ENDPOINTS ALLOCATION *******************************************/ |
/* Generic */ |
#define USBGEN_EP_SIZE 64 |
#define USBGEN_EP_NUM 1 |
/** DEFINITIONS ****************************************************/ |
#endif //USBCFG_H |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/usb_descriptors.c |
---|
0,0 → 1,265 |
/******************************************************************** |
FileName: usb_descriptors.c |
Dependencies: See INCLUDES section |
Processor: PIC18 or PIC24 USB Microcontrollers |
Hardware: The code is natively intended to be used on the following |
hardware platforms: PICDEM FS USB Demo Board, |
PIC18F87J50 FS USB Plug-In Module, or |
Explorer 16 + PIC24 USB PIM. The firmware may be |
modified for use on other USB platforms by editing the |
HardwareProfile.h file. |
Complier: Microchip C18 (for PIC18) or C30 (for PIC24) |
Company: Microchip Technology, Inc. |
Software License Agreement: |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
Any use in violation of the foregoing restrictions may subject the |
user to criminal sanctions under applicable laws, as well as to |
civil liability for the breach of the terms and conditions of this |
license. |
THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
********************************************************************* |
-usb_descriptors.c- |
------------------------------------------------------------------- |
Filling in the descriptor values in the usb_descriptors.c file: |
------------------------------------------------------------------- |
[Device Descriptors] |
The device descriptor is defined as a USB_DEVICE_DESCRIPTOR type. |
This type is defined in usb_ch9.h Each entry into this structure |
needs to be the correct length for the data type of the entry. |
[Configuration Descriptors] |
The configuration descriptor was changed in v2.x from a structure |
to a BYTE array. Given that the configuration is now a byte array |
each byte of multi-byte fields must be listed individually. This |
means that for fields like the total size of the configuration where |
the field is a 16-bit value "64,0," is the correct entry for a |
configuration that is only 64 bytes long and not "64," which is one |
too few bytes. |
The configuration attribute must always have the _DEFAULT |
definition at the minimum. Additional options can be ORed |
to the _DEFAULT attribute. Available options are _SELF and _RWU. |
These definitions are defined in the usb_device.h file. The |
_SELF tells the USB host that this device is self-powered. The |
_RWU tells the USB host that this device supports Remote Wakeup. |
[Endpoint Descriptors] |
Like the configuration descriptor, the endpoint descriptors were |
changed in v2.x of the stack from a structure to a BYTE array. As |
endpoint descriptors also has a field that are multi-byte entities, |
please be sure to specify both bytes of the field. For example, for |
the endpoint size an endpoint that is 64 bytes needs to have the size |
defined as "64,0," instead of "64," |
Take the following example: |
// Endpoint Descriptor // |
0x07, //the size of this descriptor // |
USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor |
_EP02_IN, //EndpointAddress |
_INT, //Attributes |
0x08,0x00, //size (note: 2 bytes) |
0x02, //Interval |
The first two parameters are self-explanatory. They specify the |
length of this endpoint descriptor (7) and the descriptor type. |
The next parameter identifies the endpoint, the definitions are |
defined in usb_device.h and has the following naming |
convention: |
_EP<##>_<dir> |
where ## is the endpoint number and dir is the direction of |
transfer. The dir has the value of either 'OUT' or 'IN'. |
The next parameter identifies the type of the endpoint. Available |
options are _BULK, _INT, _ISO, and _CTRL. The _CTRL is not |
typically used because the default control transfer endpoint is |
not defined in the USB descriptors. When _ISO option is used, |
addition options can be ORed to _ISO. Example: |
_ISO|_AD|_FE |
This describes the endpoint as an isochronous pipe with adaptive |
and feedback attributes. See usb_device.h and the USB |
specification for details. The next parameter defines the size of |
the endpoint. The last parameter in the polling interval. |
------------------------------------------------------------------- |
Adding a USB String |
------------------------------------------------------------------- |
A string descriptor array should have the following format: |
rom struct{byte bLength;byte bDscType;word string[size];}sdxxx={ |
sizeof(sdxxx),DSC_STR,<text>}; |
The above structure provides a means for the C compiler to |
calculate the length of string descriptor sdxxx, where xxx is the |
index number. The first two bytes of the descriptor are descriptor |
length and type. The rest <text> are string texts which must be |
in the unicode format. The unicode format is achieved by declaring |
each character as a word type. The whole text string is declared |
as a word array with the number of characters equals to <size>. |
<size> has to be manually counted and entered into the array |
declaration. Let's study this through an example: |
if the string is "USB" , then the string descriptor should be: |
(Using index 02) |
rom struct{byte bLength;byte bDscType;word string[3];}sd002={ |
sizeof(sd002),DSC_STR,'U','S','B'}; |
A USB project may have multiple strings and the firmware supports |
the management of multiple strings through a look-up table. |
The look-up table is defined as: |
rom const unsigned char *rom USB_SD_Ptr[]={&sd000,&sd001,&sd002}; |
The above declaration has 3 strings, sd000, sd001, and sd002. |
Strings can be removed or added. sd000 is a specialized string |
descriptor. It defines the language code, usually this is |
US English (0x0409). The index of the string must match the index |
position of the USB_SD_Ptr array, &sd000 must be in position |
USB_SD_Ptr[0], &sd001 must be in position USB_SD_Ptr[1] and so on. |
The look-up table USB_SD_Ptr is used by the get string handler |
function. |
------------------------------------------------------------------- |
The look-up table scheme also applies to the configuration |
descriptor. A USB device may have multiple configuration |
descriptors, i.e. CFG01, CFG02, etc. To add a configuration |
descriptor, user must implement a structure similar to CFG01. |
The next step is to add the configuration descriptor name, i.e. |
cfg01, cfg02,.., to the look-up table USB_CD_Ptr. USB_CD_Ptr[0] |
is a dummy place holder since configuration 0 is the un-configured |
state according to the definition in the USB specification. |
********************************************************************/ |
/********************************************************************* |
* Descriptor specific type definitions are defined in: |
* usb_device.h |
* |
* Configuration options are defined in: |
* usb_config.h |
********************************************************************/ |
#ifndef __USB_DESCRIPTORS_C |
#define __USB_DESCRIPTORS_C |
/** INCLUDES *******************************************************/ |
/* |
#include "GenericTypeDefs.h" |
#include "Compiler.h" |
#include "usb_config.h" |
#include "USB/usb_device.h" |
*/ |
#include "./USB/usb.h" |
/** CONSTANTS ******************************************************/ |
#if defined(__18CXX) |
#pragma romdata |
#endif |
/* Device Descriptor */ |
ROM USB_DEVICE_DESCRIPTOR device_dsc= |
{ |
0x12, // Size of this descriptor in bytes |
USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type |
0x0200, // USB Spec Release Number in BCD format |
0x00, // Class Code |
0x00, // Subclass code |
0x00, // Protocol code |
USB_EP0_BUFF_SIZE, // Max packet size for EP0, see usb_config.h |
0x16C0, // Vendor ID VOTI AVR USB device |
0x05DC, // Product ID: obdev's free PID |
0x0000, // Device release number in BCD format |
0x01, // Manufacturer string index |
0x02, // Product string index |
0x03, // Device serial number string index |
0x01 // Number of possible configurations |
}; |
/* Configuration 1 Descriptor */ |
ROM BYTE configDescriptor1[]={ |
/* Configuration Descriptor */ |
0x09,//sizeof(USB_CFG_DSC), // Size of this descriptor in bytes |
USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type |
0x20,0x00, // Total length of data for this cfg |
1, // Number of interfaces in this cfg |
1, // Index value of this configuration |
0, // Configuration string index |
_DEFAULT | _SELF, // Attributes, see usb_device.h |
50, // Max power consumption (2X mA) |
/* Interface Descriptor */ |
0x09,//sizeof(USB_INTF_DSC), // Size of this descriptor in bytes |
USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type |
0, // Interface Number |
0, // Alternate Setting Number |
2, // Number of endpoints in this intf |
0x00, // Class code |
0x00, // Subclass code |
0x00, // Protocol code |
0, // Interface string index |
/* Endpoint Descriptor */ |
0x07, /*sizeof(USB_EP_DSC)*/ |
USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor |
_EP01_OUT, //EndpointAddress |
_BULK, //Attributes |
USBGEN_EP_SIZE,0x00, //size |
1, //Interval |
0x07, /*sizeof(USB_EP_DSC)*/ |
USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor |
_EP01_IN, //EndpointAddress |
_BULK, //Attributes |
USBGEN_EP_SIZE,0x00, //size |
1 //Interval |
}; |
//Language code string descriptor |
ROM struct{BYTE bLength;BYTE bDscType;WORD string[1];}sd000={ |
sizeof(sd000),USB_DESCRIPTOR_STRING,{0x0409}}; |
//Manufacturer string descriptor |
ROM struct{BYTE bLength;BYTE bDscType;WORD string[12];}sd001={ |
sizeof(sd001),USB_DESCRIPTOR_STRING, |
{'w','w','w','.','o','b','d','e','v','.', |
'a','t'}}; |
//Product string descriptor |
ROM struct{BYTE bLength;BYTE bDscType;WORD string[10];}sd002={ |
sizeof(sd002),USB_DESCRIPTOR_STRING, |
{'D','G','8','S','A','Q','-','I','2','C'}}; |
//Serial Number string descriptor |
ROM struct{BYTE bLength;BYTE bDscType;WORD string[9];}sd003={ |
sizeof(sd003),USB_DESCRIPTOR_STRING, |
{'T','F','3','L','J','-','1','.','0'}}; |
//Array of configuration descriptors |
ROM BYTE *ROM USB_CD_Ptr[]= |
{ |
(ROM BYTE *ROM)&configDescriptor1 |
}; |
//Array of string descriptors |
ROM BYTE *ROM USB_SD_Ptr[]= |
{ |
(ROM BYTE *ROM)&sd000, |
(ROM BYTE *ROM)&sd001, |
(ROM BYTE *ROM)&sd002, |
(ROM BYTE *ROM)&sd003 |
}; |
/** EOF usb_descriptors.c ***************************************************/ |
#endif |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/usbavrcmd.h |
---|
0,0 → 1,87 |
//************************************************************************ |
//** |
//** Project......: Firmware USB AVR Si570 controler. |
//** |
//** Platform.....: ATtiny45 @ 16.5 MHz |
//** |
//** Licence......: This software is freely available for non-commercial |
//** use - i.e. for research and experimentation only! |
//** |
//** Programmer...: F.W. Krom, PE0FKO |
//** |
//** Description..: USB commando codes |
//** |
//** History......: V15.12: First version |
//** |
//************************************************************************** |
// |
//#define CMD_ECHO_WORD 0x00 |
#define CMD_GET_VERSION 0x00 |
#define CMD_SET_DDR 0x01 |
#define CMD_GET_PIN 0x02 |
#define CMD_GET_PORT 0x03 |
#define CMD_SET_PORT 0x04 |
// 0x05 // Used in old V1.4 |
// 0x06 // Used in old V1.4 |
// 0x07 // Used in old V1.4 |
// 0x08 // Used in old V1.4 |
// 0x09 // Used in old V1.4 |
// 0x0A // Used in old V1.4 |
// 0x0B // Used in old V1.4 |
// 0x0C // Used in old V1.4 |
#define CMD_REBOOT 0x0F |
// 0x10 // Used in old V1.4 |
// 0x11 // Used in old V1.4 |
#define CMD_SET_IO 0x15 |
#define CMD_GET_IO 0x16 |
#define CMD_SET_FILTER 0x17 |
#define CMD_SET_RX_BAND_FILTER 0x18 // V15.12 |
#define CMD_GET_RX_BAND_FILTER 0x19 // V15.12 |
#define CMD_SET_TX_BAND_FILTER 0x1A // MOBO Only |
#define CMD_GET_TX_BAND_FILTER 0x1B // MOBO Only |
#define CMD_SET_SI570 0x20 // Write byte to Si570 register |
// 0x21 // Used in old V1.4 |
// 0x22 // Used in old V1.4 |
// 0x23 // Used in old V1.4 |
#define CMD_SET_FREQ_REG 0x30 |
#define CMD_SET_LO_SM 0x31 |
#define CMD_SET_FREQ 0x32 |
#define CMD_SET_XTAL 0x33 |
#define CMD_SET_STARTUP 0x34 |
#define CMD_SET_PPM 0x35 |
// 0x36 // Used in old V2.0 |
// 0x37 // Used in old V2.0 |
// 0x38 // Used in old V2.0 |
#define CMD_GET_LO_SM 0x39 |
#define CMD_GET_FREQ 0x3a |
#define CMD_GET_PPM 0x3b |
#define CMD_GET_STARTUP 0x3c |
#define CMD_GET_XTAL 0x3d |
#define CMD_GET_REGS 0x3e |
#define CMD_GET_SI570 0x3f |
#define CMD_GET_I2C_ERR 0x40 |
#define CMD_SET_I2C_ADDR 0x41 |
#define CMD_GET_CPU_TEMP 0x42 // |
#define CMD_SET_USRP1 0x50 |
#define CMD_GET_CW_KEY 0x51 |
// 0x52 // Used in old V2.0 |
// 0x53 // Used in old V2.0 |
// 0x54 // Used in old V2.0 |
// Mobo command's |
#define CMD_GET_FW_FEATURE 0x60 // Firmware Feature select |
#define CMD_GET_ADC_INPUTS 0x61 // Read analog inputs (Temp, PA current, P_out, P_ref, Vdd) |
#define CMD_RM_PA_HIGH_TEMP 0x64 // Read/Modify the PA High Temperature limit |
#define CMD_RM_PA_BIAS 0x65 // Read/Modify PA bias setting related values, 5 items |
#define CMD_RM_PA_SWR 0x66 // Read/Modify SWR measurement and SWR alarm related values 4 items |
#define CMD_RM_ROTARY 0x67 // Read/Modify Rotatry Encoder Resolution |
#define CMD_SET_BYTE_GPIO 0x6e // Write a Byte to (PCF8584) GPIO Extender |
#define CMD_GET_BYTE_GPIO 0x6f // Read a Byte from (PCF8584) GPIO Extender |
// 0xEE // Used in old V2.0 |
// 0xEF // Used in old V2.0 |
// 0xFF // Used in old V2.0 |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/user.bak |
---|
0,0 → 1,197 |
/********************************************************************* |
* |
* Microchip USB C18 Firmware Version 1.2 |
* |
********************************************************************* |
* FileName: user.h |
* Dependencies: See INCLUDES section below |
* Processor: PIC18 |
* Compiler: C18 3.11+ |
* Company: Microchip Technology, Inc. |
* |
* Software License Agreement |
* |
* The software supplied herewith by Microchip Technology Incorporated |
* (the Company) for its PICmicro® Microcontroller is intended and |
* supplied to you, the Companys customer, for use solely and |
* exclusively on Microchip PICmicro Microcontroller products. The |
* software is owned by the Company and/or its supplier, and is |
* protected under applicable copyright laws. All rights are reserved. |
* Any use in violation of the foregoing restrictions may subject the |
* user to criminal sanctions under applicable laws, as well as to |
* civil liability for the breach of the terms and conditions of this |
* license. |
* |
* THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
* TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
* PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
* |
* Author Date Comment |
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
* Rawin Rojvanit 11/19/04 Original. |
* Rawin Rojvanit 05/14/07 Minor updates. |
********************************************************************/ |
#ifndef PICDEM_FS_DEMO_H |
#define PICDEM_FS_DEMO_H |
/** I N C L U D E S **********************************************************/ |
/** D E F I N I T I O N S ****************************************************/ |
// For custom LPF switchover points |
#define ALEX |
//#define K5OOR |
//#define MARC |
// YAS is defined in the HardwareProfile - UBW.h, if needed |
#if defined(YAS) |
#define NUM_BPF 8 |
#else |
#define NUM_BPF 4 |
#endif |
#define INIT_SI570_ON_STARTUP |
#define VERSION_MAJOR 16 |
#define VERSION_MINOR 04 |
#define DEFAULT_I2C_ADDRESS 0x55 |
#define PCF8574 0x39 // A2 A1 A0 -> 0 0 1 |
#define F_CAL_DONE 0 // EEPROM position of F_CAL_DONE flag. 4 bytes follow. |
#define F_CAL_DONE_VALUE 0x55 |
#define DEFAULT_FCRYST 114.285 |
//#if defined(UBW) |
#define F_INIT_FREQ 5 // 4 bytes follow |
//#elif defined(UBW32) |
//#define F_INIT_FREQ 2 // fcryst 4 bytes all stored in one 32 bit slot |
#endif |
#define F_INIT_FREQ_VALUE 0x55 |
#define DEFAULT_INIT_FREQ 56.32 |
#if defined(UBW) |
#define F_SMOOTH 10 // 2 bytes follow |
#elif defined(UBW32) |
#define F_SMOOTH 4 // 1 slot follow |
#endif |
#define F_SMOOTH_VALUE 0x55 |
#define DEFAULT_SMOOTH 3500 // ppm |
#define F_SUB_MUL_VALUE 0x55 |
#define DEFAULT_SUB 0.0 |
#define DEFAULT_MUL 1.0 |
#if defined(UBW) |
#define F_SUB_MUL 13 // 8 bytes follow |
#elif defined(UBW32) |
#define F_SUB_MUL 6 // 2 slots follow |
#endif |
#if defined(UBW) |
#define F_CROSS_OVER 22 // 32 bytes follow |
#elif defined(UBW32) |
#define F_CROSS_OVER 9 // 16 words stored in 16 (unsigned int) slots |
#endif |
#define F_CROSS_OVER_VALUE 0x55 |
#if defined(UBW) |
#define F_BLINK_LED 55 |
#elif defined(UBW32) |
#define F_BLINK_LED 26 |
#endif |
/** S T R U C T U R E S ******************************************************/ |
extern BYTE i2c_adr; |
extern BYTE command; |
extern BYTE replybuf[8]; |
extern WORD wCount; |
#define COMMAND_BUFFER_SIZE 16 |
#define DATA_PACKET_SIZE 6 |
typedef struct COMMAND_BUFFER |
{ |
BYTE command; |
WORD wCount; |
BYTE data[DATA_PACKET_SIZE]; |
} COMMAND_BUFFER_t; |
extern COMMAND_BUFFER_t command_buffer[COMMAND_BUFFER_SIZE]; |
extern BYTE current_command_in, current_command_out; |
extern BYTE command_count; |
extern double set_frequency; |
extern unsigned char tempBuf[8]; |
typedef union _avr_freq |
{ |
unsigned long qw; |
unsigned char bytes[4]; |
} avr_freq_t; |
extern avr_freq_t avr_freq, fcryst_freq; //frequency [MHz]*2^21 |
// fcryst freq [MHz]*2^24 |
extern avr_freq_t f_mul; // mul for set freq in 11.21 format |
typedef union _offset |
{ |
long qw; // signed offset in 11.21 format |
unsigned char bytes[4]; |
} offset_t; |
extern offset_t f_sub; |
extern unsigned char registers[6]; |
extern BYTE abpf_flag; |
extern double Smooth_double; |
extern double fcryst_double; |
extern WORD_VAL FilterCrossOver[8]; // 11.5 bit value Mhz |
extern float FilterSwitchOver[7]; |
extern WORD_VAL LPFCrossOver[8]; |
extern float LPFSwitchOver[7]; |
/** P U B L I C P R O T O T Y P E S *****************************************/ |
void UserInit(void); |
void ProcessIO(void); |
void Set_Freq_Handler(void); |
void Set_Register_Handler(void); |
void Set_Cal_Handler(void); |
void Set_Init_Freq_Handler(void); |
void Set_Smooth_Handler(void); |
void Set_Sub_Mul_Handler(void); |
void Reset_Si570(void); |
void Freeze (void); |
void Unfreeze (void); |
void Prep_rd (unsigned short); |
void WriteBk (void); |
void NewF (void); |
void SetNewFreq(void); |
void ReadRegs(void); |
void ReadStartUpConfiguration(void); |
void RunFreqProg(double); |
void SetFrequency(double); |
void Set_BPF(float); |
void Set_LPF(float); |
float Cross2Switch(WORD_VAL); |
WORD_VAL Switch2Cross(float); |
double Freq_From_Register(double); |
void Read_Command_Into_Buffer(void); |
void USBCheckUserRequest(void); |
void USBCheckUBWRequest(void); |
#endif //PICDEM_FS_DEMO_H |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/user.c |
---|
0,0 → 1,1278 |
/******************************************************************** |
FileName: user.c |
Dependencies: See INCLUDES section |
Processor: PIC18 or PIC24 USB Microcontrollers |
Hardware: The code is natively intended to be used on the following |
hardware platforms: PICDEM FS USB Demo Board, |
PIC18F87J50 FS USB Plug-In Module, or |
Explorer 16 + PIC24 USB PIM. The firmware may be |
modified for use on other USB platforms by editing the |
HardwareProfile.h file. |
Complier: Microchip C18 (for PIC18) or C30 (for PIC24) |
* Company: Microchip Technology, Inc. |
* |
* Software License Agreement |
The software supplied herewith by Microchip Technology Incorporated |
(the Company) for its PIC® Microcontroller is intended and |
supplied to you, the Companys customer, for use solely and |
exclusively on Microchip PIC Microcontroller products. The |
software is owned by the Company and/or its supplier, and is |
protected under applicable copyright laws. All rights are reserved. |
* Any use in violation of the foregoing restrictions may subject the |
* user to criminal sanctions under applicable laws, as well as to |
* civil liability for the breach of the terms and conditions of this |
* license. |
* |
* THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
* TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
* PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
******************************************************************** |
File Description: |
Change History: |
Rev Date Description |
1.0 11/19/2004 Initial release |
2.1 02/26/2007 Updated for simplicity and to use common |
coding style |
********************************************************************/ |
/** INCLUDES *******************************************************/ |
#include "usb.h" |
#include "HardwareProfile.h" |
#include "user.h" |
#include "usbavrcmd.h" |
#include <math.h> |
#include <stdlib.h> |
#include <string.h> |
#include <ctype.h> |
#if defined(__18CXX) |
#include <delays.h> |
#include <i2c.h> |
#include <eep.h> |
#elif defined(__PIC32MX__) |
#include <peripheral/i2c.h> |
#include <dee_emulation/dee_emulation_pic32.h> |
#endif |
#if defined (UBW) |
#pragma romdata dataEEPROM=0xF00000 |
// F_CAL_DONE, 4 bytes cal data, F_INIT_FREQ, 4 bytes freq, F_SMOOTH, 2 bytes |
// F_SUB_MUL, 4 bytes sub and 4 bytes mul |
// F_CROSS_OVER, 16 bytes or 8 words of 7 cross over points and 1 flag for BPF |
// followed by 16 bytes or 8 words of 7 cross over points and 1 flag for LPF |
// F_BLINK_LED, 1 byte boolean |
rom unsigned char init_data[] = {0xff, 0,0,0,0, 0xff, 0,0,0,0, 0xff, 0,0, |
0xff, 0,0,0,0,0,0,0,0, |
0xff, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
TRUE}; |
#endif |
/** V A R I A B L E S ********************************************************/ |
#pragma udata |
BYTE old_SW; |
BYTE i2c_adr; |
BYTE command; |
BYTE replybuf[8]; |
WORD wCount; |
BYTE abpf_flag; |
COMMAND_BUFFER_t command_buffer[COMMAND_BUFFER_SIZE]; |
BYTE current_command_in, current_command_out; |
BYTE command_count; |
avr_freq_t avr_freq, fcryst_freq; // avr freq [MHz]*2^21 |
// fcryst freq [Mhz]*2^24 |
unsigned short R137, R135 = 0; |
unsigned char registers[6]; |
unsigned char tempBuf[8]; |
unsigned char counter; |
double delta_rfreq; |
double rfreq, Old_rfreq; |
double fcryst_double, Old_freq_double, Smooth_double; |
double set_frequency; |
avr_freq_t f_mul; |
offset_t f_sub; |
unsigned char validCombo; |
#if defined(__18F14K50) || defined(__18F13K50) || defined(__18LF14K50) || defined(__18LF13K50) |
#pragma udata usbram2 |
#elif defined(__18F2455) || defined(__18F2550) || defined(__18F4455) || defined(__18F4550)\ |
|| defined(__18F4450) || defined(__18F2450)\ |
|| defined(__18F2458) || defined(__18F2453) || defined(__18F4558) || defined(__18F4553) |
#pragma udata USB_VARIABLES=0x500 |
#else |
#pragma udata |
#endif |
#pragma udata |
BOOL blinkStatusValid = TRUE; |
/** P R I V A T E P R O T O T Y P E S ***************************************/ |
void BlinkUSBStatus(void); |
BOOL SwitchIsPressed(void); |
void ServiceRequests(void); |
/** D E C L A R A T I O N S **************************************************/ |
#pragma code |
float Cross2Switch(WORD_VAL val){ // convert from 11.5 bit format in [Mhz] |
float whole, fraction; |
whole = (float) (val.Val >> 5); |
fraction = ((float) (val.Val & 0x001f)) / 32.0; |
return (whole + fraction); |
} |
WORD_VAL Switch2Cross(float val){ // convert from float to 11.5 bit format [Mhz] |
WORD_VAL w; |
unsigned int i; |
i = val; |
w.Val = i * 32.0; |
w.Val += (val - (float) i) * 32.0; |
return (w); |
} |
void UserInit(void) |
{ |
WORD_VAL w; |
//#if defined (UBW) |
// unsigned char i; |
//#elif |
unsigned int i; |
unsigned int value; |
//#endif |
#if defined(UBW) |
// Port A - RA0 BPF_S0, RA1 BPF_S1, RA2 RXTX, RA3-5 LPF0-2 |
LATA = 0x00; |
TRISA = 0x00; // 00000000 |
// Turn all analog inputs into digital inputs |
ADCON1 = 0x0F; |
// Turn off the ADC |
ADCON0bits.ADON = 0; |
CMCON = 0x07; // Comparators as digital inputs |
// RB0-1 for i2c, RB6-7 Paddle dit/dah, RB2-5 LPF 3-6 |
LATB = 0x00; |
TRISB = 0xc3; // 11000011 |
INTCON2bits.RBPU = 0; // enable RB weak internal pullup |
// Make all of PORTC inputs |
LATC = 0x00; |
TRISC = 0xFF; |
mInitAllLEDs(); |
mInitSwitch(); |
old_SW = UserSW; |
#elif defined(UBW32) |
// gO through each I/O register, setting them all to digital i/o |
// and making none of them open drain and turning off all pullups and |
// setting all of the latches to zero. We have PORTA through PORTG on |
// this chip. That's 7 total. |
LATA = 0x0000; |
TRISA = 0x0000; |
ODCA = 0x0000; |
LATB = 0x0000; |
TRISB = 0x0000; |
ODCB = 0x0000; |
LATC = 0x0000; |
TRISC = 0x0000; |
ODCC = 0x0000; |
LATD = 0x0000; |
TRISD = 0x0000; |
ODCD = 0x0000; |
LATE = 0x0000; |
TRISE = 0x0000; |
ODCE = 0x0000; |
LATF = 0x0000; |
TRISF = 0x0030; // RF4-5 paddle input |
ODCF = 0x0000; |
CNPUE = 0x060000; // Pull up on CNPUE17-18, corresponding to RF4-5 |
LATG = 0x0000; |
TRISG = 0x0000; |
ODCG = 0x0000; |
//Initialize all of the LED pins |
mInitAllLEDs(); |
mInitAllSwitches(); |
old_SW = UserSW; |
// Initialize Data EEPROM Emulation |
if (DataEEInit()) { |
mLED_4_On(); // Error occured |
} |
else { |
mLED_4_Off(); |
}; |
#endif |
i2c_adr = DEFAULT_I2C_ADDRESS; |
// check for previous calibration, which sets fcryst, the actual crystal freq |
#if defined (UBW) |
if (Read_b_eep(F_CAL_DONE) != F_CAL_DONE_VALUE){ // cal not done before, use default |
fcryst_freq.qw = (double) DEFAULT_FCRYST * (double) (1L << 24); // 114.285 Mhz |
} |
else { // cal done before, read into fcryst |
for (i=0; i<4; i++) fcryst_freq.bytes[i] = Read_b_eep(i + F_CAL_DONE +1); |
}; |
#elif defined (UBW32) |
DataEERead(&value, F_CAL_DONE); |
if ( value != F_CAL_DONE_VALUE){ // cal not done before, use default |
fcryst_freq.qw = (double) DEFAULT_FCRYST * (double) (1L << 24); // 114.285 Mhz |
} |
else { // cal done before, read into fcryst |
DataEERead(&value, (F_CAL_DONE +1)); |
fcryst_freq.qw = value; |
}; |
#endif |
// Now that fcryst is checked, set it first so that it can be used by startup freq setting |
fcryst_double = (double) fcryst_freq.qw / (double) (1L << 24); |
validCombo = 1; |
command_count = 0; |
current_command_in = 0; |
current_command_out = 0; |
Old_freq_double = 0; |
// check for previous startup freq setting |
#if defined (UBW) |
if (Read_b_eep(F_INIT_FREQ) != F_INIT_FREQ_VALUE){ // not set before, use default |
avr_freq.qw = (double) DEFAULT_INIT_FREQ * (double) (1L << 21); |
} |
else { // startup freq set before, read into avr |
for (i=0; i<4; i++) avr_freq.bytes[i] = Read_b_eep(i + F_INIT_FREQ +1); |
}; |
#elif defined (UBW32) |
DataEERead(&value, F_INIT_FREQ); |
if ( value != F_INIT_FREQ_VALUE){ // not set before, use default |
avr_freq.qw = (double) DEFAULT_INIT_FREQ * (double) (1L << 21); |
} |
else { // set before, read |
DataEERead(&value, (F_INIT_FREQ +1)); |
avr_freq.qw = value; |
}; |
#endif |
// check for previous smooth setting |
#if defined (UBW) |
if (Read_b_eep(F_SMOOTH) != F_SMOOTH_VALUE){ // not set before, use default |
Smooth_double = (double) DEFAULT_SMOOTH / 1000000L; // in ppm |
} |
else { // set before, read |
for (i=0; i<2; i++) w.v[i] = Read_b_eep(i + F_SMOOTH +1); |
Smooth_double = (double) w.Val / 1000000L; |
}; |
#elif defined (UBW32) |
DataEERead(&value, F_SMOOTH); |
if ( value != F_SMOOTH_VALUE){ // not set before, use default |
Smooth_double = (double) DEFAULT_SMOOTH / 1000000L; |
} |
else { // set before, read |
DataEERead(&value, (F_SMOOTH +1)); |
w.Val = value; |
Smooth_double = (double) w.Val / 1000000L; |
} |
#endif |
// check for previous sub mul setting |
#if defined (UBW) |
if (Read_b_eep(F_SUB_MUL) != F_SUB_MUL_VALUE){ // not set before, use default |
f_sub.qw = (double) DEFAULT_SUB * (double) (1L << 21); |
f_mul.qw = (double) DEFAULT_MUL * (double) (1L << 21); |
} |
else { // startup freq set before, read into avr |
for (i=0; i<4; i++) f_sub.bytes[i] = Read_b_eep(i + F_SUB_MUL +1); |
for (i=0; i<4; i++) f_mul.bytes[i] = Read_b_eep(i + F_SUB_MUL +5); |
}; |
#elif defined (UBW32) |
DataEERead(&value, F_SUB_MUL); |
if ( value != F_SUB_MUL_VALUE){ // not set before, use default |
f_sub.qw = (double) DEFAULT_SUB * (double) (1L << 21); |
f_mul.qw = (double) DEFAULT_MUL * (double) (1L << 21); |
} |
else { // set before, read |
DataEERead(&value, (F_SUB_MUL +1)); |
f_sub.qw = value; |
DataEERead(&value, (F_SUB_MUL +2)); |
f_mul.qw = value; |
}; |
#endif |
// Check for Cross Over Points |
#if defined (UBW) |
if (Read_b_eep(F_CROSS_OVER) != F_CROSS_OVER_VALUE){ // not set before, use default |
#if defined (YAS) |
FilterSwitchOver[0] = (2.4 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; // default BPF switchover points |
FilterSwitchOver[1] = (8.5 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
FilterSwitchOver[2] = (19.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
FilterSwitchOver[3] = (19.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
FilterSwitchOver[4] = (19.0 - DEFAULT_SUB) * DEFAULT_MUL* 4.0; |
FilterSwitchOver[5] = (19.0 - DEFAULT_SUB) * DEFAULT_MUL* 4.0; |
FilterSwitchOver[6] = (19.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
#else |
FilterSwitchOver[0] = (2.4 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; // default BPF switchover points |
FilterSwitchOver[1] = (8.5 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
FilterSwitchOver[2] = (19.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
#endif |
for (i = 0; i < (NUM_BPF - 1); i++) FilterCrossOver[i] = Switch2Cross(FilterSwitchOver[i]); |
FilterCrossOver[(NUM_BPF-1)].Val = 1; // Enabled |
abpf_flag = 1; |
#if defined (K5OOR) |
LPFSwitchOver[0] = (2.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[1] = (4.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[2] = (7.45 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[3] = (15.0 - DEFAULT_SUB) * DEFAULT_MUL* 4.0; |
LPFSwitchOver[4] = (21.5 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[5] = (30.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[6] = (30.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
#elif defined (ALEX) |
LPFSwitchOver[0] = (2.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[1] = (4.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[2] = (9.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[3] = (11.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[4] = (14.5 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[5] = (20.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[6] = (30.0 - DEFAULT_SUB) * DEFAULT_MUL* 4.0; |
#elif defined (MARC) |
LPFSwitchOver[0] = (2.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[1] = (4.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[2] = (8.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[3] = (11.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[4] = (14.5 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[5] = (18.2 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[6] = (21.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
#else |
#error "Must define an LPF configuration." |
#endif |
for (i = 0; i < 7; i++) LPFCrossOver[i] = Switch2Cross(LPFSwitchOver[i]); |
LPFCrossOver[7].Val = 1; // Enabled |
} |
else { // set before, read |
for (i = 0; i < NUM_BPF; i++){ |
w.v[0] = Read_b_eep(2 * i + F_CROSS_OVER +1); |
w.v[1] = Read_b_eep(2 * i + 1 + F_CROSS_OVER + 1); |
FilterCrossOver[i].Val = w.Val; |
}; |
abpf_flag = FilterCrossOver[(NUM_BPF-1)].v[0]; |
for (i = 0; i < 8; i++){ |
w.v[0] = Read_b_eep(2 * i + F_CROSS_OVER +17); |
w.v[1] = Read_b_eep(2 * i + 1 + F_CROSS_OVER + 17); |
LPFCrossOver[i].Val = w.Val; |
}; |
} |
#elif defined (UBW32) |
DataEERead(&value, F_CROSS_OVER); |
if ( value != F_CROSS_OVER_VALUE){ // not set before, use default |
FilterSwitchOver[0] = (2.4 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; // default BPF switchover points |
FilterSwitchOver[1] = (8.5 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
FilterSwitchOver[2] = (19.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
for (i = 0; i < 3; i++) FilterCrossOver[i] = Switch2Cross(FilterSwitchOver[i]); |
FilterCrossOver[3].Val = 1; // Enabled |
abpf_flag = 1; |
#if defined (K5OOR) |
LPFSwitchOver[0] = (2.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[1] = (4.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[2] = (7.45 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[3] = (15.0 - DEFAULT_SUB) * DEFAULT_MUL* 4.0; |
LPFSwitchOver[4] = (21.5 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[5] = (30.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[6] = (30.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
#elif defined (ALEX) |
LPFSwitchOver[0] = (2.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[1] = (4.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[2] = (9.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[3] = (11.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[4] = (14.5 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[5] = (20.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[6] = (30.0 - DEFAULT_SUB) * DEFAULT_MUL* 4.0; |
#elif defined (MARC) |
LPFSwitchOver[0] = (2.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[1] = (4.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[2] = (8.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[3] = (11.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[4] = (14.5 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[5] = (18.2 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
LPFSwitchOver[6] = (21.0 - DEFAULT_SUB) * DEFAULT_MUL * 4.0; |
#else |
#error "Must define an LPF configuration." |
#endif |
for (i = 0; i < 7; i++) LPFCrossOver[i] = Switch2Cross(LPFSwitchOver[i]); |
LPFCrossOver[7].Val = 1; // Enabled |
} |
else { // set before, read |
for (i=0; i< NUM_BPF; i++) { |
DataEERead(&value, (i + F_CROSS_OVER +1)); |
FilterCrossOver[i].Val = value; |
}; |
abpf_flag = FilterCrossOver[(NUM_BPF-1)].Val; |
for (i=0; i<8; i++) { |
DataEERead(&value, (i + F_CROSS_OVER +9)); |
LPFCrossOver[i].Val = value; |
}; |
}; |
#endif // UBW32 |
for (i = 0; i < (NUM_BPF-1); i++) FilterSwitchOver[i] = Cross2Switch(FilterCrossOver[i]); |
for (i = 0; i < 7; i++) LPFSwitchOver[i] = Cross2Switch(LPFCrossOver[i]); |
// End initialising filter switchover points |
#if defined(UBW) |
blinkStatusValid = Read_b_eep(F_BLINK_LED); |
#elif defined (UBW32) |
DataEERead(&value, F_BLINK_LED); |
blinkStatusValid = value; |
#endif |
#if defined (UBW) |
OpenI2C(MASTER, SLEW_ON);// Initialize I2C module |
SSPADD = 48; //400kHz Baud clock(9) @16MHz |
//100kHz Baud clock(39) @16MHz |
#elif defined (UBW32) |
OpenI2C1(I2C_ON, ( GetPeripheralClock() / 400000UL - 2) ); |
#endif |
// IF we don't reset Si570 on startup, it will not hang if Si570 not connected |
#if defined (INIT_SI570_ON_STARTUP) |
Reset_Si570(); |
#endif |
// check for previous startup freq setting, if set, then set Si570 to startup freq |
#if defined (UBW32) |
DataEERead(&value, F_INIT_FREQ); |
if ( value == F_INIT_FREQ_VALUE){ |
#else |
if (Read_b_eep(F_INIT_FREQ) == F_INIT_FREQ_VALUE){ |
#endif |
// avr_freq has been setup by the reading of the startup freq |
set_frequency = (double) avr_freq.qw / (double)(1L << 21); |
SetFrequency(set_frequency); |
}; |
}//end UserInit |
/****************************************************************************** |
* Function: void ProcessIO(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: This function is a place holder for other user routines. |
* It is a mixture of both USB and non-USB tasks. |
* |
* Note: None |
*****************************************************************************/ |
void ProcessIO(void) |
{ |
if (SwitchIsPressed()){ |
blinkStatusValid = !blinkStatusValid; // toggle blink led |
#if defined(UBW) |
Write_b_eep(F_BLINK_LED, blinkStatusValid); |
#elif defined(UBW32) |
DataEEWrite(blinkStatusValid, F_BLINK_LED); |
#endif |
}; |
//Blink the LEDs according to the USB device status |
if(blinkStatusValid) BlinkUSBStatus(); |
else mLED_Both_Off(); |
// User Application USB tasks |
if((USBDeviceState < ADDRESS_STATE)||(USBSuspendControl==1)) return; |
//respond to any USB commands that might have come over the bus |
ServiceRequests(); |
}//end ProcessIO |
/****************************************************************************** |
* Function: void ServiceRequests(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: USB traffic can be generated |
* |
* Overview: This function takes in the commands from the PC from the |
* application and executes the commands requested |
* |
* Note: None |
*****************************************************************************/ |
void ServiceRequests(void) |
{ |
BYTE command_to_process; |
if (command_count > 0) { // there is command in buffer |
command_to_process = command_buffer[current_command_out].command; |
switch (command_to_process){ |
case CMD_SET_FREQ_REG: |
Set_Register_Handler(); |
break; |
case CMD_SET_LO_SM: |
Set_Sub_Mul_Handler(); |
break; |
case CMD_SET_FREQ: |
Set_Freq_Handler(); |
break; |
case CMD_SET_XTAL: |
Set_Cal_Handler(); |
break; |
case CMD_SET_STARTUP: |
Set_Init_Freq_Handler(); |
break; |
case CMD_SET_PPM: |
Set_Smooth_Handler(); |
break; |
}; |
// end switch |
current_command_out++; |
if (current_command_out >= COMMAND_BUFFER_SIZE) current_command_out = 0; |
command_count--; |
} // end command_count > 0 |
}//end ServiceRequests |
/******************************************************************** |
* Function: void BlinkUSBStatus(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: None |
* |
* Side Effects: None |
* |
* Overview: BlinkUSBStatus turns on and off LEDs |
* corresponding to the USB device state. |
* |
* Note: mLED macros can be found in HardwareProfile.h |
* USBDeviceState is declared and updated in |
* usb_device.c. |
*******************************************************************/ |
void BlinkUSBStatus(void) |
{ |
static WORD led_count=0; |
if(led_count == 0)led_count = 10000U; |
led_count--; |
if(USBSuspendControl == 1) |
{ |
if(led_count==0) |
{ |
mLED_1_Toggle(); |
mLED_2 = mLED_1; |
}//end if |
} |
else |
{ |
if(USBDeviceState == DETACHED_STATE) |
{ |
mLED_1_Off(); mLED_2_Off(); |
} |
else if(USBDeviceState == ATTACHED_STATE) |
{ |
mLED_1_On(); mLED_2_On(); |
} |
else if(USBDeviceState == POWERED_STATE) |
{ |
mLED_1_On(); mLED_2_Off(); |
} |
else if(USBDeviceState == DEFAULT_STATE) |
{ |
mLED_1_Off(); mLED_2_On(); |
} |
else if(USBDeviceState == ADDRESS_STATE) |
{ |
if(led_count == 0) |
{ |
mLED_1_Toggle(); |
mLED_2_Off(); |
}//end if |
} |
else if(USBDeviceState == CONFIGURED_STATE) |
{ |
if(led_count==0) |
{ |
mLED_1_Toggle(); |
mLED_2 = !mLED_1; |
}//end if |
}//end if(...) |
}//end if(UCONbits.SUSPND...) |
}//end BlinkUSBStatus |
/****************************************************************************** |
* Function: BOOL SwitchIsPressed(void) |
* |
* PreCondition: None |
* |
* Input: None |
* |
* Output: BOOL - TRUE if the SW2 was pressed and FALSE otherwise |
* |
* Side Effects: None |
* |
* Overview: returns TRUE if the SW2 was pressed and FALSE otherwise |
* |
* Note: None |
*****************************************************************************/ |
BOOL SwitchIsPressed(void) |
{ |
if(UserSW != old_SW) |
{ |
old_SW = UserSW; // Save new value |
if(UserSW == 0) // If pressed |
return TRUE; // Was pressed |
}//end if |
return FALSE; // Was not pressed |
}//end SwitchIsPressed |
void Reset_Si570() |
{ |
#if defined (UBW) |
StartI2C(); //Reset Si570 to Startup |
IdleI2C(); |
WriteI2C(i2c_adr << 1); |
WriteI2C(135); //REG 135 |
WriteI2C(0x01); // reset |
StopI2C(); |
IdleI2C(); |
#elif defined (UBW32) |
StartI2C1(); //Reset Si570 to Startup |
IdleI2C1(); |
MasterWriteI2C1(i2c_adr << 1); |
MasterWriteI2C1(135); //REG 135 |
MasterWriteI2C1(0x01); // reset |
StopI2C1(); |
IdleI2C1(); |
#endif |
} |
void ReadRegs() |
{ |
unsigned int i; |
for(i=0;i<6;i++) |
{ |
#if defined (UBW) |
StartI2C(); |
IdleI2C(); |
WriteI2C(i2c_adr << 1); |
WriteI2C(i+7); //specify register |
RestartI2C(); |
IdleI2C(); |
WriteI2C(i2c_adr << 1 | 0x01); |
registers[i] = ReadI2C(); |
StopI2C(); |
IdleI2C(); |
#elif defined (UBW32) |
StartI2C1(); |
IdleI2C1(); |
MasterWriteI2C1(i2c_adr << 1); |
MasterWriteI2C1(i+7); |
RestartI2C1(); |
IdleI2C1(); |
MasterWriteI2C1(i2c_adr << 1 | 0x01); |
registers[i] = MasterReadI2C1(); |
StopI2C1(); |
IdleI2C1(); |
#endif |
} |
} |
void Freeze () { |
Prep_rd(137); //get current value |
#if defined (UBW) |
R137 = ReadI2C(); |
#elif defined (UBW32) |
R137 = MasterReadI2C1(); |
#endif |
R137 = R137 | 0x10; //turn on freeze |
WriteBk(); |
} |
void Unfreeze () { |
Prep_rd(137); |
#if defined (UBW) |
R137 = ReadI2C(); |
#elif defined (UBW32) |
R137 = MasterReadI2C1(); |
#endif |
R137 = R137 & 0xEF; |
WriteBk(); |
} |
void WriteBk () { //Write back |
#if defined (UBW) |
StopI2C(); |
IdleI2C(); |
StartI2C(); |
IdleI2C(); |
WriteI2C(i2c_adr<<1); |
WriteI2C(137); //REG |
WriteI2C(R137); // new data |
StopI2C(); |
IdleI2C(); |
#elif defined (UBW32) |
StopI2C1(); |
IdleI2C1(); |
StartI2C1(); |
IdleI2C1(); |
MasterWriteI2C1(i2c_adr<<1); |
MasterWriteI2C1(137); //REG |
MasterWriteI2C1(R137); // new data |
StopI2C1(); |
IdleI2C1(); |
#endif |
} |
void Prep_rd (unsigned short r) { // get ready to read |
#if defined (UBW) |
StartI2C(); |
IdleI2C(); |
WriteI2C(i2c_adr<<1); |
WriteI2C(r); //REG |
RestartI2C(); |
IdleI2C(); |
WriteI2C(i2c_adr<<1 | 0x01); |
#elif defined (UBW32) |
StartI2C1(); |
IdleI2C1(); |
MasterWriteI2C1(i2c_adr<<1); |
MasterWriteI2C1(r); //REG |
RestartI2C1(); |
IdleI2C1(); |
MasterWriteI2C1(i2c_adr<<1 | 0x01); |
#endif |
} |
void NewF () { |
Prep_rd(135); |
#if defined (UBW) |
R135 = ReadI2C(); |
R135 |= 0x40; // set New Data bit |
StopI2C(); |
IdleI2C(); |
StartI2C(); |
IdleI2C(); |
WriteI2C(i2c_adr<<1); |
WriteI2C(135); //REG |
WriteI2C(R135); |
StopI2C(); |
IdleI2C(); |
#elif defined (UBW32) |
R135 = MasterReadI2C1(); |
R135 |= 0x40; // set New Data bit |
StopI2C1(); |
IdleI2C1(); |
StartI2C1(); |
IdleI2C1(); |
MasterWriteI2C1(i2c_adr<<1); |
MasterWriteI2C1(135); //REG |
MasterWriteI2C1(R135); |
StopI2C1(); |
IdleI2C1(); |
#endif |
} |
void RunFreqProg(double f) |
{ |
double rfreq_fraction; |
unsigned long rfreq_integer_part; |
unsigned long rfreq_fraction_part; |
const float FDCO_MAX = 5670; //MHz |
const float FDCO_MIN = 4850; |
// Register finding the lowest DCO frequenty - code from Fred |
unsigned char xHS_DIV; |
unsigned int xN1; |
unsigned int xN; |
// Registers to save the found dividers |
unsigned char sHS_DIV=0; |
unsigned char sN1=0; |
unsigned int sN=0; // Total dividing |
unsigned int N0; // Total divider needed (N1 * HS_DIV) |
// Find the total division needed. |
// It is always one too low (not in the case reminder is zero, reminder not used here). |
N0 = FDCO_MIN / (float) f; |
sN = 11*128; |
for(xHS_DIV = 11; xHS_DIV > 3; xHS_DIV--) |
{ |
// Skip the unavailable divider's |
if (xHS_DIV == 8 || xHS_DIV == 10) |
continue; |
// Calculate the needed low speed divider |
xN1 = N0 / xHS_DIV + 1; |
if (xN1 > 128) |
continue; |
// Skip the unavailable divider's |
if (xN1 != 1 && (xN1 & 1) == 1) |
xN1 += 1; |
xN = xHS_DIV * xN1; |
if (sN > xN) |
{ |
sN = xN; |
sN1 = xN1; |
sHS_DIV = xHS_DIV; |
} |
}; |
validCombo = 0; |
if (sHS_DIV == 0) return; // no valid dividers found |
rfreq = f * (double) sN; // DCO freq |
if ((float)rfreq > FDCO_MAX) return; // calculated DCO freq > max |
validCombo = 1; |
// rfreq is a 38 bit number, MSB 10 bits integer portion, and LSB 28 fraction |
// in the Si570 registers, tempBuf[1] has 6 bits, and tempBuf[2] has 4 bits of the integer portion |
rfreq /= fcryst_double; // DCO divided by fcryst |
rfreq_integer_part = rfreq; |
rfreq_fraction = rfreq - rfreq_integer_part; |
rfreq_fraction_part = rfreq_fraction * (1L << 28); |
sHS_DIV -= 4; |
sN1 -= 1; |
tempBuf[0] = (sHS_DIV << 5) | (sN1 >> 2); |
tempBuf[1] = (sN1 & 3) << 6; |
tempBuf[1] |= ((rfreq_integer_part >> 4) & 0x3f); |
tempBuf[2] = ((rfreq_integer_part & 0x0f) << 4) | (rfreq_fraction_part >> 24); |
tempBuf[3] = rfreq_fraction_part >> 16; |
tempBuf[4] = rfreq_fraction_part >> 8; |
tempBuf[5] = rfreq_fraction_part; |
} |
void SetNewFreq() |
{ int i; |
double freq_double; |
double delta_freq; |
if(validCombo) |
{ |
Freeze(); // freeze DCO |
for (i=7; i<=12; i++){ //Data to Si570 |
#if defined (UBW) |
StartI2C(); |
IdleI2C(); |
WriteI2C(i2c_adr<<1); |
WriteI2C(i); //specify register |
WriteI2C(tempBuf[i-7]); // new data to registers |
StopI2C(); |
IdleI2C(); |
#elif defined (UBW32) |
StartI2C1(); |
IdleI2C1(); |
MasterWriteI2C1(i2c_adr<<1); |
MasterWriteI2C1(i); //specify register |
MasterWriteI2C1(tempBuf[i-7]); // new data to registers |
StopI2C1(); |
IdleI2C1(); |
#endif |
} |
Unfreeze (); // thaw (unfreeze) |
// check for smooth tune range |
freq_double = Freq_From_Register(fcryst_double); |
if (freq_double >= Old_freq_double) delta_freq = freq_double - Old_freq_double; |
else delta_freq = Old_freq_double - freq_double; |
if (((delta_rfreq / Old_rfreq ) > Smooth_double) || (delta_freq > 0.5)){ |
NewF (); // indicate new freq. This will cause a pause in the Si570 output |
Old_rfreq = rfreq; |
Old_freq_double = freq_double; |
}; |
// set filters, using set freq without offset and multiplier |
if (abpf_flag) Set_BPF((float) set_frequency); |
Set_LPF((float)set_frequency); |
}; // valid combo |
} |
double Freq_From_Register(double fcryst){ // side effects: rfreq and delta_rfreq are set |
double freq_double; |
unsigned char n1; |
unsigned char hsdiv; |
unsigned long rfreq_integer_portion, rfreq_fraction_portion; |
// Now find out the current rfreq and freq |
hsdiv = ((tempBuf[0] & 0xE0) >> 5) + 4; |
n1 = ((tempBuf[0] & 0x1f ) << 2 ) + ((tempBuf[1] & 0xc0 ) >> 6 ); |
// if(n1 == 0) n1 = 1; |
// else if((n1 & 1) !=0) n1 += 1; |
n1 += 1; |
rfreq_integer_portion = ((unsigned long)(tempBuf[1] & 0x3f)) << 4 | |
((unsigned long)(tempBuf[2] & 0xf0)) >> 4; |
rfreq_fraction_portion = ((unsigned long) (tempBuf[2] & 0x0f)) << 24; |
rfreq_fraction_portion += ((unsigned long)(tempBuf[3])) << 16; |
rfreq_fraction_portion += ((unsigned long)(tempBuf[4])) << 8; |
rfreq_fraction_portion += ((unsigned long)(tempBuf[5])); |
rfreq = (double)rfreq_integer_portion + ((double)rfreq_fraction_portion / (1L << 28)); |
if (rfreq >= Old_rfreq) delta_rfreq = rfreq - Old_rfreq; |
else delta_rfreq = Old_rfreq - rfreq; |
freq_double = fcryst * rfreq / (double) hsdiv / (double) n1; |
return (freq_double); |
} |
void Set_BPF(float freq){ // note the freq used is the Si570 freq |
#if defined(YAS) |
if (freq < FilterSwitchOver[0]) {BPF_S2 = 0;BPF_S1 = 0; BPF_S0 = 0;} |
else if (freq < FilterSwitchOver[1]) {BPF_S2 = 0; BPF_S1=0;BPF_S0=1;} |
else if (freq < FilterSwitchOver[2]) {BPF_S2 = 0;BPF_S1=1;BPF_S0=0;} |
else if (freq < FilterSwitchOver[3]) {BPF_S2 = 0; BPF_S1 = 1; BPF_S0 = 1;} |
else if (freq < FilterSwitchOver[4]) {BPF_S2 = 1; BPF_S1 = 0; BPF_S0 = 0;} |
else if (freq < FilterSwitchOver[5]) {BPF_S2 = 1; BPF_S1 = 0; BPF_S0 = 1;} |
else if (freq < FilterSwitchOver[6]) {BPF_S2 = 1; BPF_S1 = 1; BPF_S0 = 0;} |
else {BPF_S2 = 1;BPF_S1=1; BPF_S0=1;}; |
#else |
if (freq < FilterSwitchOver[0]) {BPF_S1 = 0; BPF_S0 = 0;} |
else if (freq < FilterSwitchOver[1]) {BPF_S1=0;BPF_S0=1;} |
else if (freq < FilterSwitchOver[2]) {BPF_S1=1;BPF_S0=0;} |
else {BPF_S1=1; BPF_S0=1;}; |
#endif |
} |
void Set_LPF(float freq){ |
unsigned char LPF_select; |
LPF_0 = 0; |
LPF_1 = 0; |
LPF_2 = 0; |
#if defined(YAS) |
if (freq < LPFSwitchOver[0]) {LPF_0 = 0; LPF_1 = 0; LPF_2 = 0; LPF_select = 0x01;} |
else if (freq < LPFSwitchOver[1]) {LPF_0 = 1; LPF_1 = 0; LPF_2 = 0; LPF_select = 0x02;} |
else if (freq < LPFSwitchOver[2]) {LPF_0 = 0; LPF_1 = 1; LPF_2 = 0; LPF_select = 0x04;} |
else if (freq < LPFSwitchOver[3]) {LPF_0 = 1; LPF_1 = 1; LPF_2 = 0; LPF_select = 0x08;} |
else if (freq < LPFSwitchOver[4]) {LPF_0 = 0; LPF_1 = 0; LPF_2 = 1; LPF_select = 0x10;} |
else if (freq < LPFSwitchOver[5]) {LPF_0 = 1; LPF_1 = 0; LPF_2 =1; LPF_select = 0x20;} |
else if (freq < LPFSwitchOver[6]) {LPF_0 = 0; LPF_1 = 1; LPF_2 = 1; LPF_select = 0x40;} |
else {LPF_0 = 1; LPF_1 = 1; LPF_2 = 1; LPF_select = 0x80;}; |
#else |
LPF_3 = 0; |
LPF_4 = 0; |
LPF_5 = 0; |
LPF_6 = 0; |
if (freq < LPFSwitchOver[0]) {LPF_0 = 1; LPF_select = 0x01;} |
else if (freq < LPFSwitchOver[1]) {LPF_1 = 1; LPF_select = 0x02;} |
else if (freq <= LPFSwitchOver[2]) {LPF_2 = 1; LPF_select = 0x04;} |
else if (freq < LPFSwitchOver[3]) {LPF_3 = 1; LPF_select = 0x08;} |
else if (freq < LPFSwitchOver[4]) {LPF_4 = 1; LPF_select = 0x10;} |
else if (freq < LPFSwitchOver[5]) {LPF_5 = 1; LPF_select = 0x20;} |
else if (freq < LPFSwitchOver[6]) {LPF_6 = 1; LPF_select = 0x40;} |
else {LPF_6 = 1; LPF_select = 0x80;}; |
#endif |
// Now use i2c bus to switch LPF |
#if defined (UBW) |
StartI2C(); |
IdleI2C(); |
WriteI2C(PCF8574 << 1); |
WriteI2C(LPF_select); |
StopI2C(); |
IdleI2C(); |
#elif defined (UBW32) |
StartI2C1(); |
IdleI2C1(); |
MasterWriteI2C1(PCF8574 << 1); |
MasterWriteI2C1(LPF_select); |
StopI2C1(); |
IdleI2C1(); |
#endif |
} |
void SetFrequency(double f) |
{ |
// introduce the offset and mul here |
RunFreqProg((f - ((double)f_sub.qw / (double)(1L << 21))) * (double)f_mul.qw/(double)(1L <<21)); |
SetNewFreq(); |
} |
void Set_Freq_Handler(void){ // 4 byte freq value in avr_freq format |
BYTE i; |
if (command_buffer[current_command_out].wCount == 4){ |
for (i=0; i<4; i++) avr_freq.bytes[i] = command_buffer[current_command_out].data[i]; |
set_frequency = (double) avr_freq.qw / (double)(1L << 21); |
SetFrequency(set_frequency); |
} |
} |
void Set_Register_Handler(void){ // 6 byte register value |
unsigned char i; |
if (command_buffer[current_command_out].wCount == 6){ |
for (i=0; i<6; i++) tempBuf[i] = command_buffer[current_command_out].data[i]; |
set_frequency = Freq_From_Register(DEFAULT_FCRYST); |
SetFrequency(set_frequency); |
} |
} |
void Set_Cal_Handler(void){ |
// 4 bytes of fcryst freq in avr_freq format |
int i; |
if (command_buffer[current_command_out].wCount == 4){ |
for (i=0; i<4; i++)fcryst_freq.bytes[i] = command_buffer[current_command_out].data[i]; |
fcryst_double = (double) fcryst_freq.qw / (double)(1L << 24); |
#if defined(UBW) |
for (i=0; i<4; i++){ |
Write_b_eep (i+F_CAL_DONE+1, fcryst_freq.bytes[i]); |
Busy_eep (); |
}; |
#elif defined (UBW32) |
DataEEWrite( (unsigned int) fcryst_freq.qw, (F_CAL_DONE + 1)); |
#endif |
#if defined (UBW) |
Write_b_eep(F_CAL_DONE, F_CAL_DONE_VALUE); |
Busy_eep(); |
#elif defined (UBW32) |
DataEEWrite(F_CAL_DONE_VALUE, F_CAL_DONE); |
#endif |
}; |
} |
void Set_Init_Freq_Handler(void) |
{ |
#if defined (UBW) |
unsigned char i; |
#else |
unsigned int i; |
#endif |
if (command_buffer[current_command_out].wCount == 4){ |
for (i=0; i<4; i++) avr_freq.bytes[i] = command_buffer[current_command_out].data[i]; |
#if defined (UBW) |
for (i=0; i<4; i++){ |
Write_b_eep((i + F_INIT_FREQ +1), avr_freq.bytes[i]); |
Busy_eep(); |
}; |
#elif defined (UBW32) |
DataEEWrite( (unsigned int) avr_freq.qw, (F_INIT_FREQ +1)); |
#endif |
#if defined (UBW) |
Write_b_eep(F_INIT_FREQ, F_INIT_FREQ_VALUE); |
Busy_eep(); |
#elif defined (UBW32) |
DataEEWrite(F_INIT_FREQ_VALUE, F_INIT_FREQ); |
#endif |
}; |
} |
void Set_Sub_Mul_Handler(void) |
{ |
#if defined (UBW) |
unsigned char i; |
#else |
unsigned int i; |
#endif |
avr_freq_t old_f_mul; |
offset_t old_f_sub; |
double filter_value; |
if (command_buffer[current_command_out].wCount == 8){ |
old_f_sub = f_sub; // save old values first |
old_f_mul = f_mul; |
for (i=0; i<4; i++) f_sub.bytes[i] = command_buffer[current_command_out].data[i]; |
for (i=0; i<4; i++) f_mul.bytes[i] = command_buffer[current_command_out].data[i+4]; |
#if defined (UBW) |
for (i=0; i<4; i++){ |
Write_b_eep((i + F_SUB_MUL +1), f_sub.bytes[i]); |
Busy_eep(); |
}; |
for (i=0; i<4; i++){ |
Write_b_eep((i + F_SUB_MUL +5), f_mul.bytes[i]); |
Busy_eep(); |
}; |
#elif defined (UBW32) |
DataEEWrite( (unsigned int) f_sub.qw, (F_SUB_MUL +1)); |
DataEEWrite( (unsigned int) f_mul.qw, (F_SUB_MUL +5)); |
#endif |
#if defined (UBW) |
Write_b_eep(F_SUB_MUL, F_SUB_MUL_VALUE); |
Busy_eep(); |
#elif defined (UBW32) |
DataEEWrite(F_SUB_MUL_VALUE, F_SUB_MUL); |
#endif |
// Now update the filter switchover points as well |
for (i = 0; i < (NUM_BPF - 1); i++){ |
// get back filter_value in Mhz |
filter_value = FilterSwitchOver[i] / (old_f_mul.qw / ((double) (1L << 21))) / 4 + (old_f_sub.qw / ((double) (1L << 21))); |
// now convert to new translated values |
FilterSwitchOver[i] = (filter_value - (f_sub.qw / (double)(1L << 21))) * (f_mul.qw / (double)(1L << 21)) * 4; |
FilterCrossOver[i] = Switch2Cross(FilterSwitchOver[i]); |
}; |
for (i = 0; i < 7; i++){ |
// get back filter_value in Mhz |
filter_value = LPFSwitchOver[i] / (old_f_mul.qw / ((double) (1L << 21))) / 4 + (old_f_sub.qw / ((double) (1L << 21))); |
// now convert to new translated values |
LPFSwitchOver[i] = (filter_value - (f_sub.qw / (double)(1L << 21))) * (f_mul.qw / (double)(1L << 21)) * 4; |
LPFCrossOver[i] = Switch2Cross(LPFSwitchOver[i]); |
}; |
}; // if wCount == 8 |
} |
void Set_Smooth_Handler(void) |
{ |
WORD_VAL w; |
unsigned int i; |
if (command_buffer[current_command_out].wCount == 2){ // 2 bytes of Smooth Tune value in ppm |
w.v[0] = command_buffer[current_command_out].data[0]; |
w.v[1] = command_buffer[current_command_out].data[1]; |
Smooth_double = (double) w.Val / 1000000L; |
#if defined (UBW) |
for (i=0; i<2; i++){ |
Write_b_eep (i+F_SMOOTH+1, w.v[i]); |
Busy_eep (); |
}; |
#elif defined (UBW32) |
DataEEWrite( (unsigned int) w.Val, (i + F_SMOOTH + 1)); |
#endif |
#if defined (UBW) |
Write_b_eep(F_SMOOTH, F_SMOOTH_VALUE); |
Busy_eep(); |
#elif defined (UBW32) |
DataEEWrite( F_SMOOTH_VALUE, F_SMOOTH); |
#endif |
} |
} |
/** EOF user.c ***************************************************************/ |
/Modules/Clock/CLKGEN01A/SW/DG8SAQ synthesiser_Emulator/user.h |
---|
0,0 → 1,197 |
/********************************************************************* |
* |
* Microchip USB C18 Firmware Version 1.2 |
* |
********************************************************************* |
* FileName: user.h |
* Dependencies: See INCLUDES section below |
* Processor: PIC18 |
* Compiler: C18 3.11+ |
* Company: Microchip Technology, Inc. |
* |
* Software License Agreement |
* |
* The software supplied herewith by Microchip Technology Incorporated |
* (the Company) for its PICmicro® Microcontroller is intended and |
* supplied to you, the Companys customer, for use solely and |
* exclusively on Microchip PICmicro Microcontroller products. The |
* software is owned by the Company and/or its supplier, and is |
* protected under applicable copyright laws. All rights are reserved. |
* Any use in violation of the foregoing restrictions may subject the |
* user to criminal sanctions under applicable laws, as well as to |
* civil liability for the breach of the terms and conditions of this |
* license. |
* |
* THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
* TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
* PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
* |
* Author Date Comment |
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
* Rawin Rojvanit 11/19/04 Original. |
* Rawin Rojvanit 05/14/07 Minor updates. |
********************************************************************/ |
#ifndef PICDEM_FS_DEMO_H |
#define PICDEM_FS_DEMO_H |
/** I N C L U D E S **********************************************************/ |
/** D E F I N I T I O N S ****************************************************/ |
// For custom LPF switchover points |
#define ALEX |
//#define K5OOR |
//#define MARC |
// YAS is defined in the HardwareProfile - UBW.h, if needed |
#if defined(YAS) |
#define NUM_BPF 8 |
#else |
#define NUM_BPF 4 |
#endif |
#define INIT_SI570_ON_STARTUP |
#define VERSION_MAJOR 16 |
#define VERSION_MINOR 04 |
#define DEFAULT_I2C_ADDRESS 0x55 |
#define PCF8574 0x39 // A2 A1 A0 -> 0 0 1 |
#define F_CAL_DONE 0 // EEPROM position of F_CAL_DONE flag. 4 bytes follow. |
#define F_CAL_DONE_VALUE 0x55 |
#define DEFAULT_FCRYST 114.285 |
//#if defined(UBW) |
#define F_INIT_FREQ 5 // 4 bytes follow |
//#elif defined(UBW32) |
//#define F_INIT_FREQ 2 // fcryst 4 bytes all stored in one 32 bit slot |
//#endif |
#define F_INIT_FREQ_VALUE 0x55 |
#define DEFAULT_INIT_FREQ 56.32 |
#if defined(UBW) |
#define F_SMOOTH 10 // 2 bytes follow |
#elif defined(UBW32) |
#define F_SMOOTH 4 // 1 slot follow |
#endif |
#define F_SMOOTH_VALUE 0x55 |
#define DEFAULT_SMOOTH 3500 // ppm |
#define F_SUB_MUL_VALUE 0x55 |
#define DEFAULT_SUB 0.0 |
#define DEFAULT_MUL 1.0 |
#if defined(UBW) |
#define F_SUB_MUL 13 // 8 bytes follow |
#elif defined(UBW32) |
#define F_SUB_MUL 6 // 2 slots follow |
#endif |
#if defined(UBW) |
#define F_CROSS_OVER 22 // 32 bytes follow |
#elif defined(UBW32) |
#define F_CROSS_OVER 9 // 16 words stored in 16 (unsigned int) slots |
#endif |
#define F_CROSS_OVER_VALUE 0x55 |
#if defined(UBW) |
#define F_BLINK_LED 55 |
#elif defined(UBW32) |
#define F_BLINK_LED 26 |
#endif |
/** S T R U C T U R E S ******************************************************/ |
extern BYTE i2c_adr; |
extern BYTE command; |
extern BYTE replybuf[8]; |
extern WORD wCount; |
#define COMMAND_BUFFER_SIZE 16 |
#define DATA_PACKET_SIZE 6 |
typedef struct COMMAND_BUFFER |
{ |
BYTE command; |
WORD wCount; |
BYTE data[DATA_PACKET_SIZE]; |
} COMMAND_BUFFER_t; |
extern COMMAND_BUFFER_t command_buffer[COMMAND_BUFFER_SIZE]; |
extern BYTE current_command_in, current_command_out; |
extern BYTE command_count; |
extern double set_frequency; |
extern unsigned char tempBuf[8]; |
typedef union _avr_freq |
{ |
unsigned long qw; |
unsigned char bytes[4]; |
} avr_freq_t; |
extern avr_freq_t avr_freq, fcryst_freq; //frequency [MHz]*2^21 |
// fcryst freq [MHz]*2^24 |
extern avr_freq_t f_mul; // mul for set freq in 11.21 format |
typedef union _offset |
{ |
long qw; // signed offset in 11.21 format |
unsigned char bytes[4]; |
} offset_t; |
extern offset_t f_sub; |
extern unsigned char registers[6]; |
extern BYTE abpf_flag; |
extern double Smooth_double; |
extern double fcryst_double; |
extern WORD_VAL FilterCrossOver[8]; // 11.5 bit value Mhz |
extern float FilterSwitchOver[7]; |
extern WORD_VAL LPFCrossOver[8]; |
extern float LPFSwitchOver[7]; |
/** P U B L I C P R O T O T Y P E S *****************************************/ |
void UserInit(void); |
void ProcessIO(void); |
void Set_Freq_Handler(void); |
void Set_Register_Handler(void); |
void Set_Cal_Handler(void); |
void Set_Init_Freq_Handler(void); |
void Set_Smooth_Handler(void); |
void Set_Sub_Mul_Handler(void); |
void Reset_Si570(void); |
void Freeze (void); |
void Unfreeze (void); |
void Prep_rd (unsigned short); |
void WriteBk (void); |
void NewF (void); |
void SetNewFreq(void); |
void ReadRegs(void); |
void ReadStartUpConfiguration(void); |
void RunFreqProg(double); |
void SetFrequency(double); |
void Set_BPF(float); |
void Set_LPF(float); |
float Cross2Switch(WORD_VAL); |
WORD_VAL Switch2Cross(float); |
double Freq_From_Register(double); |
void Read_Command_Into_Buffer(void); |
void USBCheckUserRequest(void); |
void USBCheckUBWRequest(void); |
#endif //PICDEM_FS_DEMO_H |