Subversion Repositories svnkaklik

Compare Revisions

Ignore whitespace Rev 655 → Rev 656

/programy/C/PIC_C/mereni/inertial/main.lst/main.lst
0,0 → 1,11705
CCS PCH C Compiler, Version 4.090, 47914 30-IV-10 18:05
 
Filename: D:\svnKaklik\programy\C\PIC_C\mereni\inertial\main.lst
 
ROM used: 9680 bytes (30%)
Largest free fragment is 23084
RAM used: 1650 (81%) at main() level
1869 (91%) worst case
Stack: 17 worst case (8 in main + 9 for interrupts)
 
*
0000: GOTO 1F62
*
0008: MOVWF 05
000A: MOVFF FD8,06
000E: MOVFF FE0,07
0012: MOVLB 0
0014: MOVFF FE9,0D
0018: MOVFF FEA,08
001C: MOVFF FE1,09
0020: MOVFF FE2,0A
0024: MOVFF FD9,0B
0028: MOVFF FDA,0C
002C: MOVFF FF3,14
0030: MOVFF FF4,15
0034: MOVFF FFA,16
0038: MOVFF 00,0F
003C: MOVFF 01,10
0040: MOVFF 02,11
0044: MOVFF 03,12
0048: MOVFF 04,13
004C: BTFSS FF2.5
004E: GOTO 0058
0052: BTFSC FF2.2
0054: GOTO 025E
0058: BTFSS FA0.5
005A: GOTO 0064
005E: BTFSC FA1.5
0060: GOTO 1274
0064: MOVFF 0F,00
0068: MOVFF 10,01
006C: MOVFF 11,02
0070: MOVFF 12,03
0074: MOVFF 13,04
0078: MOVFF 0D,FE9
007C: MOVFF 08,FEA
0080: BSF 08.7
0082: MOVFF 09,FE1
0086: MOVFF 0A,FE2
008A: MOVFF 0B,FD9
008E: MOVFF 0C,FDA
0092: MOVFF 14,FF3
0096: MOVFF 15,FF4
009A: MOVFF 16,FFA
009E: MOVF 05,W
00A0: MOVFF 07,FE0
00A4: MOVFF 06,FD8
00A8: RETFIE 0
.................... #include "main.h"
.................... #include <18F4550.h>
.................... //////// Standard Header file for the PIC18F4550 device ////////////////
.................... #device PIC18F4550
.................... #list
....................
.................... #device adc=10
....................
.................... #FUSES NOWDT //No Watch Dog Timer
.................... #FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
.................... #FUSES HSPLL //Crystal/Resonator with PLL enabled
.................... #FUSES NOPROTECT //Code not protected from reading
.................... #FUSES NOBROWNOUT //No brownout reset
.................... #FUSES BORV20 //Brownout reset at 2.0V
.................... #FUSES NOPUT //No Power Up Timer
.................... #FUSES NOCPD //No EE protection
.................... #FUSES STVREN //Stack full/underflow will cause reset
.................... #FUSES NODEBUG //No Debug mode for ICD
.................... #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
.................... #FUSES NOWRT //Program memory not write protected
.................... #FUSES NOWRTD //Data EEPROM not write protected
.................... #FUSES IESO //Internal External Switch Over mode enabled
.................... #FUSES FCMEN //Fail-safe clock monitor enabled
.................... #FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
.................... #FUSES NOWRTC //configuration not registers write protected
.................... #FUSES NOWRTB //Boot block not write protected
.................... #FUSES NOEBTR //Memory not protected from table reads
.................... #FUSES NOEBTRB //Boot block not protected from table reads
.................... #FUSES NOCPB //No Boot Block code protection
.................... #FUSES MCLR //Master Clear pin enabled
.................... #FUSES LPT1OSC //Timer1 configured for low-power operation
.................... #FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
.................... #FUSES PLL5 //Divide By 5(20MHz oscillator input)
.................... #FUSES CPUDIV4 //System Clock by 4
.................... #FUSES USBDIV //USB clock source comes from PLL divide by 2
.................... #FUSES VREGEN //USB voltage regulator enabled
.................... #FUSES ICPRT //ICPRT enabled
....................
.................... #use delay(clock=24000000)
....................
....................
....................
.................... #define REV "$Rev$"
....................
.................... unsigned int32 time; // pocitadlo preteceni casovace
....................
.................... #define BUFLEN 100
....................
.................... #int_RTCC
.................... void RTCC_isr(void) // preruseni od pretekleho casovace
.................... {
.................... time++;
*
025E: MOVLW 01
0260: ADDWF 19,F
0262: BTFSC FD8.0
0264: INCF 1A,F
0266: BTFSC FD8.2
0268: INCF 1B,F
026A: BTFSC FD8.2
026C: INCF 1C,F
.................... }
....................
.................... // Includes all USB code and interrupts, as well as the CDC API
.................... #include <usb_cdc.h>
.................... /////////////////////////////////////////////////////////////////////////
.................... //// ////
.................... //// usb_cdc.h ////
.................... //// ////
.................... //// Library for adding a virtual COM port on your PC over USB using ////
.................... //// the standard Communication Device Class (CDC) specification. ////
.................... //// Including this file in your code will add all USB code, ////
.................... //// interrupts, descriptors and handlers required. No other ////
.................... //// modifications need to be made. ////
.................... //// ////
.................... //// This library creates a virtual RS232 link between the PC and ////
.................... //// the PIC, therefore the library provided will be familiar to ////
.................... //// anyone with standard UART stream I/O: ////
.................... //// ////
.................... //// usb_cdc_kbhit() - Returns TRUE if there is one or more ////
.................... //// character received and waiting in the receive buffer. ////
.................... //// ////
.................... //// usb_cdc_getc() - Gets a character from the receive buffer. If ////
.................... //// there is no data in the receive buffer it will wait until ////
.................... //// there is data in the receive buffer. If you do not want ////
.................... //// to wait in an infinit loop, use usb_cdc_kbhit() first to ////
.................... //// check if there is data before calling usb_cdc_getc(). ////
.................... //// ////
.................... //// usb_cdc_putc(char c) - Puts a character into the transmit ////
.................... //// buffer. If the transmit buffer is full it will wait until ////
.................... //// the transmit buffer is not full before putting the char ////
.................... //// into the transmit buffer. The transmit buffer is read by ////
.................... //// the PC very quickly, and therefore the buffer should only ////
.................... //// be full for a few milli-seconds. If you are concerned ////
.................... //// and don't want to be stuck in a long or infinite loop, ////
.................... //// use usb_cdc_putready() to see if there is space in the ////
.................... //// transmit buffer before putting data into the transmit ////
.................... //// buffer. ////
.................... //// ////
.................... //// usb_cdc_putready() - Returns TRUE if there is room left in the ////
.................... //// transmit buffer for another character. ////
.................... //// ////
.................... //// usb_cdc_connected() - Returns TRUE if we received a ////
.................... //// Set_Line_Coding. On most serial terminal programs (such ////
.................... //// as Hyperterminal), they will send a Set_Line_Coding ////
.................... //// message when the program starts and it opens the virtual ////
.................... //// COM port. This is a simple way to determine if the PC ////
.................... //// is ready to display data on a serial terminal program, ////
.................... //// but is not garaunteed to work all the time or on other ////
.................... //// terminal programs. ////
.................... //// ////
.................... //// usb_cdc_putc_fast(char c) - Similar to usb_cdc_putc(), except ////
.................... //// if the transmit buffer is full it will skip the char. ////
.................... //// ////
.................... //// usb_cdc_line_coding - A structure used for Set_Line_Coding and ////
.................... //// Get_Line_Coding. Most of the time you can ignore this. ////
.................... //// ////
.................... //// usb_cdc_break - If the PC has sent a break command, this will ////
.................... //// hold the break time (in milli-seconds). If the PC sends ////
.................... //// a value of 0xFFFF the device is supposed to hold the ////
.................... //// break until it sends a value of 0 ////
.................... //// ////
.................... //// usb_cdc_carrier - Where Set_Control_Line_State value is stored. ////
.................... //// Of most relevance is the field dte_present, which is the ////
.................... //// DTR setting. ////
.................... //// ////
.................... //// The following functions are also provided, and are ports of the ////
.................... //// I/O functions in input.c. See input.c and the CCS manual for ////
.................... //// documentation: ////
.................... //// get_float_usb() - Read a float number from the user ////
.................... //// get_long_usb() - Read a long number from the user ////
.................... //// get_int_usb() - Read an integer number from the user ////
.................... //// get_string_usb(char *s, int max) - Read a string from the user. ////
.................... //// gethex_usb() - Read a byte, in HEX, from the user ////
.................... //// gethex1_usb() - Read a HEX character ////
.................... //// ////
.................... //// This driver will load all the rest of the USB code, and a set ////
.................... //// of descriptors that will properly describe a CDC device for a ////
.................... //// virtual COM port (usb_desc_cdc.h) ////
.................... //// ////
.................... //// An .INF file is provided (cdc_NTXP.inf) that will load the ////
.................... //// standard CDC drivers for a virtual COM port in Windows ////
.................... //// NT/2000/XP and above. ////
.................... //// ////
.................... /////////////////////////////////////////////////////////////////////////
.................... //// ////
.................... //// VERSION HISTORY ////
.................... //// ////
.................... //// March 5th, 2009: ////
.................... //// Cleanup for Wizard. ////
.................... //// PIC24 Initial release. ////
.................... //// ////
.................... //// Nov 26th, 2007: ////
.................... //// usb_cdc_put_buffer_free() should be more stable. ////
.................... //// Fixed a hang-up that would happen if you sent ////
.................... //// exactly 64 bytes. ////
.................... //// ////
.................... //// Nov 6th, 2007: ////
.................... //// Compatabible with latest pic18_usb.h, which ////
.................... //// reduces RAM footprint of USB driver. ////
.................... //// This driver now fits on 18F4450/2450 PICs. ////
.................... //// ////
.................... //// October 27th, 2005: Changed the way incoming packets are ////
.................... //// handled in that CDC driver will not flush ////
.................... //// endpoint until user has handled all data. This ////
.................... //// will prevent overflows as the USB will NAK ////
.................... //// incoming packets until it is ready to receive ////
.................... //// more. ////
.................... //// When using 18F4550 family, the RX buffer is ////
.................... //// mapped directly to the endpoint buffer - this ////
.................... //// saves a chunk of RAM. ////
.................... //// When using the 18F4550 family, you can increase ////
.................... //// the TX and RX size over 64 bytes. ////
.................... //// No longer send 0len packets in the TBE interrupt. ////
.................... //// Hopefully fixed bugs that caused random crashes ////
.................... //// if you tried sending more than 64 bytes. ////
.................... //// ////
.................... //// July 6th, 2005: Global interrupts disabled when writing to TX ////
.................... //// buffer. ////
.................... //// ////
.................... //// July 1st, 2005: Initial Release. ////
.................... //// ////
.................... /////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2005 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS ////
.................... //// C compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, ////
.................... //// reproduction or distribution is permitted without written ////
.................... //// permission. Derivative programs created using this software ////
.................... //// in object code form are not restricted in any way. ////
.................... /////////////////////////////////////////////////////////////////////////
....................
....................
.................... //api for the user:
.................... #define usb_cdc_kbhit() (usb_cdc_get_buffer_status.got)
.................... #define usb_cdc_putready() (usb_cdc_put_buffer_nextin<USB_CDC_DATA_IN_SIZE)
.................... #define usb_cdc_connected() (usb_cdc_got_set_line_coding)
026E: BCF FF2.2
0270: GOTO 0064
.................... void usb_cdc_putc_fast(char c);
.................... char usb_cdc_getc(void);
.................... void usb_cdc_putc(char c);
....................
.................... //input.c ported to use CDC:
.................... float get_float_usb();
.................... signed long get_long_usb();
.................... signed int get_int_usb();
.................... void get_string_usb(char* s, unsigned int max);
.................... BYTE gethex_usb();
.................... BYTE gethex1_usb();
....................
.................... //functions automatically called by USB handler code
.................... void usb_isr_tkn_cdc(void);
.................... void usb_cdc_init(void);
.................... void usb_isr_tok_out_cdc_control_dne(void);
.................... void usb_isr_tok_in_cdc_data_dne(void);
.................... void usb_isr_tok_out_cdc_data_dne(void);
....................
.................... void usb_cdc_flush_out_buffer(void);
....................
.................... /////////////////////////////////////////////////////////////////////////////
.................... //
.................... // Include the CCS USB Libraries. See the comments at the top of these
.................... // files for more information
.................... //
.................... /////////////////////////////////////////////////////////////////////////////
.................... #ifndef __USB_PIC_PERIF__
.................... #define __USB_PIC_PERIF__ 1
.................... #endif
....................
.................... #if __USB_PIC_PERIF__
.................... #if defined(__PCH__)
.................... #include <pic18_usb.h> //Microchip 18Fxx5x hardware layer for usb.c
.................... /////////////////////////////////////////////////////////////////////////
.................... //// pic18_usb.h ////
.................... //// ////
.................... //// Hardware layer for CCS's USB library. This hardware layer ////
.................... //// supports the USB peripheral on the PIC18 family chips. Current ////
.................... //// supported families are: ////
.................... //// PIC18F2455/2550/4455/4550 ////
.................... //// PIC18F2450/4450 ////
.................... //// PIC18F2458/2553/4458/4553 ////
.................... //// PIC18F13K50/14K50 ////
.................... //// PIC18F65J50/66J50/66J55/67J50/85J50/86J50/86J55/87J50 ////
.................... //// ////
.................... //// This file is part of CCS's PIC USB driver code. See USB.H ////
.................... //// for more documentation and a list of examples. ////
.................... //// ////
.................... //// See the section labeled EXTRA USER FUNCTIONS for functions ////
.................... //// that are specific to only this HW peripheral that you may ////
.................... //// find useful to use in your application. ////
.................... //// ////
.................... //// *********** NOTE ABOUT 18F2450/4450 LIMITATIONS ********** ////
.................... //// Due to the limited USB RAM of this family, a limitation of ////
.................... //// this driver is that there are only 3 endpoints (0, 1 and 2). ////
.................... //// The HW actually supports more endpoints, but to simplify ////
.................... //// driver development this driver will only support the first 3 ////
.................... //// so there is an easier memory block to work with. ////
.................... //// ////
.................... //// USB_MAX_EP0_PACKET_LENGTH will also be set to 8 regardless ////
.................... //// of USB speed, to save RAM. ////
.................... //// ////
.................... //// ************** NOTE ABOUT HW REQUIREMENTS **************** ////
.................... //// If you are not using internal pullups, you will need to put ////
.................... //// an internal pullup resistor on D+ or D+ depending on if you ////
.................... //// want to use slow speed or full speed. This code configures ////
.................... //// the device to use internal pullups, see usb_init() if you ////
.................... //// want to change that. ////
.................... //// ////
.................... //// You need approximately 470nF cap on Vusb, even if you are ////
.................... //// using the internal 3.3V USB regulator. ////
.................... //// ////
.................... //// To run at full speed, you must use the oscillator ////
.................... //// configuration (PLLx) to set the PLL divide to 4MHz. You can ////
.................... //// configure the MCU clock to any speed (up to 48MHz) but the ////
.................... //// PLL must run at 4Mhz to provide the USB peripheral with a ////
.................... //// 96MHz clock. See the datasheet for details. ////
.................... //// ////
.................... //// To run at slow speed you must configure your MCU to run at ////
.................... //// 24Mhz. See the datasheet for details. ////
.................... //// ////
.................... //// **************** NOTE ABOUT INTERRUPTS ****************** ////
.................... //// This driver uses INT_USB. It requires INT_USB to interrupt the ////
.................... //// PIC when an event has happened on the USB Bus. Therfore ////
.................... //// this code enables interrupts. A user modification can be made ////
.................... //// to poll the USB interrupt flag instead of relying on an ////
.................... //// interrupt. ////
.................... //// ////
.................... /////////////////////////////////////////////////////////////////////////
.................... //// ////
.................... //// Version History: ////
.................... //// ////
.................... //// March 5th, 2009: ////
.................... //// 18F14K50 family added. ////
.................... //// Cleanup for Wizard. ////
.................... //// PIC24 Initial release. ////
.................... //// ////
.................... //// Nov 3rd, 2008: ////
.................... //// * 4553 family added. ////
.................... //// ////
.................... //// Dec 18, 2007: ////
.................... //// * usb_kbhit() moved to device driver. ////
.................... //// * USB Token handler changed to workaround a flaw in the USB ////
.................... //// peripheral to prevent the USB peripheral from ////
.................... //// inadvertantly STALLing the endpoint. Happened most often ////
.................... //// in bulk demo applications, especially CDC. ////
.................... //// ////
.................... //// 11-6-07: Fixed a bug where usb_data_buffer[] was reserving ////
.................... //// too much RAM. ////
.................... //// USB_MAX_EP0_PACKET_LENGTH value can be overwritten. ////
.................... //// For the 18F4450/2450 family this should be 8 ////
.................... //// because of limited RAM. Reducing this value ////
.................... //// frees RAM for application. ////
.................... //// Based upon which endpoints have been configured for ////
.................... //// use, will free up unused USB data RAM for ////
.................... //// application dynamically. This should free up ////
.................... //// at least 128 bytes of RAM. ////
.................... //// CDC now fits on a 18F4450/2450 ////
.................... //// ////
.................... //// 09-19-07: Fixed problems with 18F4450 family. ////
.................... //// ////
.................... //// 07-17-07: Added 18F4450,2450 support ////
.................... //// ////
.................... //// 07-13-07: Added 87J50 family support ////
.................... //// ////
.................... //// 11-01-05: usb_detach(), usb_attach() and usb_init_cs() ////
.................... //// changed for the better. ////
.................... //// ////
.................... //// 10-28-05: Added usb_rx_packet_size() ////
.................... //// ////
.................... //// 07-13-05: usb_put_packet() changed for 16bit packet sizes ////
.................... //// usb_flush_in() changed for 16bit packet sizes ////
.................... //// usb_get_packet() changed for 16bit packet sizes ////
.................... //// usb_flush_out() changed for 16bit packet sizes ////
.................... //// usb_set_configured() changed for 16bit packet sizes ////
.................... //// ////
.................... //// 06-30-05: usb_tbe() added ////
.................... //// The way endpoint 0 DTS is set has been changed. ////
.................... //// ////
.................... //// 06-20-05: Initial Release ////
.................... //// ////
.................... //// 05-13-05: Beta Release (Full Speed works) ////
.................... //// ////
.................... //// 03-21-05: Initial Alpha Release ////
.................... //// ////
.................... /////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2005 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS ////
.................... //// C compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, ////
.................... //// reproduction or distribution is permitted without written ////
.................... //// permission. Derivative programs created using this software ////
.................... //// in object code form are not restricted in any way. ////
.................... /////////////////////////////////////////////////////////////////////////
....................
.................... #IFNDEF __PIC18_USB_H__
.................... #DEFINE __PIC18_USB_H__
....................
.................... #DEFINE __USB_HARDWARE__
....................
.................... //let the USB Stack know that we are using a PIC with internal USB peripheral
.................... #DEFINE __PIC__ 1
....................
.................... #ifndef USB_USE_FULL_SPEED
.................... #define USB_USE_FULL_SPEED TRUE
.................... #endif
....................
.................... #ifndef USB_MAX_EP0_PACKET_LENGTH
.................... #if ((getenv("DEVICE")=="PIC18F2450") || (getenv("DEVICE")=="PIC18F4450"))
.................... //due to limited ram, force max packet length to 8 for this chip
.................... #define USB_MAX_EP0_PACKET_LENGTH 8
.................... #else
.................... #if USB_USE_FULL_SPEED==FALSE
.................... //slow speed requires 8byte max packet size for endpoint 0
.................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 8
.................... #else
.................... //for full speed you can still use 8bytes, but 64 will be faster
.................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 64
.................... #endif
.................... #endif
.................... #endif
....................
.................... #if (!USB_USE_FULL_SPEED && (USB_MAX_EP0_PACKET_LENGTH!=8))
.................... #error Slow speed devices must use a max packet size of 8 for endpoint 0!
.................... #endif
....................
.................... #if USB_MAX_EP0_PACKET_LENGTH < 8
.................... #error Max Endpoint 0 length can't be less than 8!
.................... #endif
....................
.................... #if USB_MAX_EP0_PACKET_LENGTH > 64
.................... #error Max Endpoint 0 length can't be greater than 64!
.................... #endif
....................
.................... #include <usb_hw_layer.h>
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// usb_hw_layer.h ////
.................... //// ////
.................... //// HW Layer for the USB Stack. ////
.................... //// ////
.................... //// HW drivers for the USB stack must support this API. ////
.................... //// ////
.................... //// The HW driver must also have a token handler that will call ////
.................... //// usb_token_reset() when the device is init/reset, will call ////
.................... //// usb_isr_tok_setup_dne() when it receives a setup packet, ////
.................... //// will call usb_isr_tok_out_dne() when a new packet is received, ////
.................... //// and will call usb_isr_tok_in_dne() when a new packet is sent. ////
.................... //// See usb.h for documentation of these functions. ////
.................... //// ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// ////
.................... //// Version History: ////
.................... //// ////
.................... //// March 5th, 2009: ////
.................... //// Cleanup for Wizard. ////
.................... //// PIC24 Initial release. ////
.................... //// ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2009 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS ////
.................... //// C compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, ////
.................... //// reproduction or distribution is permitted without written ////
.................... //// permission. Derivative programs created using this software ////
.................... //// in object code form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
....................
.................... #ifndef __USB_HW_LAYER_H__
.................... #define __USB_HW_LAYER_H__
....................
.................... enum USB_DTS_BIT {USB_DTS_DATA1=1, USB_DTS_TOGGLE=2, USB_DTS_DATA0=0,
.................... USB_DTS_STALL=3, USB_DTS_USERX=4};
....................
....................
.................... // USER LEVEL FUNCTIONS:
....................
.................... /*****************************************************************************
.................... /* usb_init()
.................... /*
.................... /* Summary: See API section of USB.H for documentation.
.................... /*
.................... /*****************************************************************************/
.................... void usb_init(void);
....................
.................... /*****************************************************************************
.................... /* usb_init_cs()
.................... /*
.................... /* Summary: See API section of USB.H for documentation.
.................... /*
.................... /*****************************************************************************/
.................... void usb_init_cs(void);
....................
.................... /*****************************************************************************
.................... /* usb_task()
.................... /*
.................... /* Summary: See API section of USB.H for documentation.
.................... /*
.................... /*****************************************************************************/
.................... void usb_task(void);
....................
.................... /******************************************************************************
.................... /* usb_attach()
.................... /*
.................... /* Summary: Attach the D+/D- lines to the USB bus. Enable the USB peripheral.
.................... /*
.................... /* You should wait until UCON_SE0 is clear before enabling reset/idle interrupt.
.................... /*
.................... /* Shouldn't be called by user, let usb_task() handle this.
.................... /*
.................... /* NOTE: If you are writing a new HW driver, this routine should call
.................... /* usb_token_reset() to reset the CH9 stack.
.................... /*
.................... /*****************************************************************************/
.................... void usb_attach(void);
....................
.................... /******************************************************************************
.................... /* usb_detach()
.................... /*
.................... /* Summary: Remove the D+/D- lines from the USB bus. Basically, disable USB.
.................... /*
.................... /* Shouldn't be called by user, let usb_task() handle this.
.................... /*
.................... /* If the user does call this function while USB is connected, the USB
.................... /* peripheral will be disabled only momentarily because usb_task() will
.................... /* reconnect. But this is a great way to cause the PC/HOST to cause a USB
.................... /* reset of the device.
.................... /*
.................... /* NOTE: If you are writing a new HW driver, this routine should call
.................... /* usb_token_reset() to reset the CH9 stack.
.................... /*
.................... /*****************************************************************************/
.................... void usb_detach(void);
....................
.................... /******************************************************************************
.................... /* usb_put_packet()
.................... /*
.................... /* Input: endpoint - endpoint to send packet to (0..15).
.................... /* ptr - points to data to send.
.................... /* len - amount of data to send.
.................... /* toggle - whether to send data with a DATA0 pid, a DATA1 pid,
.................... /* or toggle from the last DATAx pid.
.................... /*
.................... /* Output: TRUE if data was sent correctly, FALSE if it was not. The only
.................... /* reason it will return FALSE is if because the TX buffer is still full
.................... /* from the last time it tried to send a packet.
.................... /*
.................... /* Summary: Sends one packet out the EP to the host. Notice that there is a
.................... /* difference between a packet and a message. If you wanted to send a
.................... /* 512 byte message on an endpoint that only supported 64 byte packets,
.................... /* this would be accomplished this by sending 8 64-byte packets,
.................... /* followed by a 0 length packet. If the last (or only packet) being
.................... /* sent is less than the max packet size defined in your descriptor
.................... /* then you do not need to send a 0 length packet to identify
.................... /* an end of message.
.................... /*
.................... /* usb_puts() (provided in usb.c) will send a multi-packet message
.................... /* correctly and know if a 0 lenght packet needs to be sent.
.................... /*
.................... /* The result will be invalid if the specified input has not been configured for
.................... /* use by the API with USB_EPx_TX_SIZE
.................... /*
.................... /*****************************************************************************/
.................... int1 usb_put_packet(int8 endpoint, int8 * ptr, unsigned int16 len, USB_DTS_BIT tgl);
....................
.................... /*******************************************************************************
.................... /* usb_get_packet(endpoint, *ptr, max)
.................... /*
.................... /* Input: endpoint - endpoint to get data from
.................... /* ptr - where to save data to local PIC RAM
.................... /* max - max amount of data to receive from buffer
.................... /*
.................... /* Output: the amount of data taken from the buffer and saved to ptr.
.................... /*
.................... /* NOTE - IF THERE IS NO PACKET TO GET YOU WILL GET INVALID RESULTS!
.................... /* VERIFY WITH USB_KBHIT() BEFORE YOU CALL USB_GET_PACKET()!
.................... /*
.................... /* Summary: Gets a packet of data from the USB endpoint buffer.
.................... /* Until this is called, if there is data in the receive buffer the
.................... /* PC/HOST will be prevented from sending more data. Upon completion
.................... /* of this call, the endpoint will be freed and the PC/HOST will be
.................... /* allowed to send a new packet. Only receives one packet, if you need
.................... /* to receive multiple packets or handle 0-length terminator packets,
.................... /* then use usb_gets().
.................... /*
.................... /* The result will be invalid if the specified input has not been configured for
.................... /* use by the API with USB_EPx_RX_SIZE
.................... /*
.................... /********************************************************************************/
.................... unsigned int16 usb_get_packet(int8 endpoint, int8 * ptr, unsigned int16 max);
....................
.................... /****************************************************************************
.................... /* usb_kbhit(endpoint)
.................... /*
.................... /* Input: endpoint - endpoint to check (0..15)
.................... /*
.................... /* Output: TRUE if there is new data in RX buffer, FALSE if there is not.
.................... /*
.................... /* Summary: Similar to kbhit(), sees if there is new data in the RX USB buffers.
.................... /* See API section of USB.H for more information.
.................... /*
.................... /* The result will be invalid if the specified input has not been configured for
.................... /* use by the API with USB_EPx_RX_SIZE
.................... /*
.................... /*****************************************************************************/
.................... int1 usb_kbhit(int8 en);
....................
.................... /******************************************************************************
.................... /* usb_tbe(endpoint)
.................... /*
.................... /* Input: endpoint - endpoint to check
.................... /* ptr - where to save data to local PIC RAM
.................... /* max - max amount of data to receive from buffer
.................... /*
.................... /* Output: returns TRUE if this endpoint's IN buffer (PIC-PC) is empty and ready
.................... /* returns FALSE if this endpoint's IN buffer is still processing the last
.................... /* transmit or if this endpoint is invalid.
.................... /*
.................... /* The result will be invalid if the specified input has not been configured for
.................... /* use by the API with USB_EPx_TX_SIZE
.................... /*
.................... /*****************************************************************************/
.................... int1 usb_tbe(int8 en);
....................
.................... //////////////// END USER LEVEL FUNCTIONS /////////////////////////////////////
....................
....................
.................... ///
.................... /// BEGIN STACK LEVEL FUNCTIONS: These functions are meant to be called by
.................... /// the USB stack, and are not meant to be called by the
.................... /// user/application.
.................... ///
....................
.................... /*****************************************************************************
.................... /* usb_stall_ep()
.................... /*
.................... /* Input: endpoint - endpoint to stall.
.................... /* top most bit indicates direction (set is IN, clear is OUT)
.................... /*
.................... /* Summary: Stalls specified endpoint. If endpoint is stalled it will
.................... /* send STALL packet if the host tries to access this endpoint's
.................... /* buffer.
.................... /*
.................... /* NOTE: WE ASSUME ENDPOINT IS VALID. USB.C SHOULD CHECK IF VALID BEFORE
.................... /* CALLING THIS ROUTINE.
.................... /*
.................... /*****************************************************************************/
.................... void usb_stall_ep(int8 endpoint);
....................
....................
.................... /*****************************************************************************
.................... /* usb_unstall_ep(endpoint, direction)
.................... /*
.................... /* Input: endpoint - endpoint to un-stall.
.................... /* top most bit indicates direction (set is IN, clear is OUT)
.................... /*
.................... /* Summary: Un-stalls endpoint.
.................... /*
.................... /* NOTE: WE ASSUME ENDPOINT IS VALID. USB.C SHOULD CHECK IF VALID BEFORE
.................... /* CALLING THIS ROUTINE.
.................... /*
.................... /*****************************************************************************/
.................... void usb_unstall_ep(int8 endpoint);
....................
.................... /*****************************************************************************
.................... /* usb_endpoint_stalled()
.................... /*
.................... /* Input: endpoint - endpoint to check
.................... /* top most bit indicates direction (set is IN, clear is OUT)
.................... /*
.................... /* Output: returns a TRUE if endpoint is stalled, FALSE if it is not.
.................... /*
.................... /* Summary: Looks to see if an endpoint is stalled, or not. Does not look to
.................... /* see if endpoint has been issued a STALL, just whether or not it is
.................... /* configured to STALL on the next packet. See Set_Feature and
.................... /* Clear_Feature Chapter 9 requests.
.................... /*
.................... /* NOTE: WE ASSUME ENDPOINT IS VALID. USB.C SHOULD CHECK IF VALID BEFORE
.................... /* CALLING THIS ROUTINE.
.................... /*
.................... /*****************************************************************************/
.................... int1 usb_endpoint_stalled(int8 endpoint);
....................
.................... /*****************************************************************************
.................... /* usb_set_address(address)
.................... /*
.................... /* Input: address - address the host specified that we use
.................... /*
.................... /* Summary: Configures the USB Peripheral for the specified device address.
.................... /* The host will now talk to use with the following address.
.................... /*
.................... /*****************************************************************************/
.................... void usb_set_address(int8 address);
....................
.................... /******************************************************************************
.................... /* usb_set_configured()
.................... /*
.................... /* Input: config - Configuration to use. 0 to uncofigure device.
.................... /*
.................... /* Summary: Configures or unconfigures device. If configuring device it will
.................... /* enable all the endpoints the user specified for this configuration.
.................... /* If un-configuring device it will disable all endpoints.
.................... /*
.................... /* NOTE: CCS only provides code to handle 1 configuration.
.................... /*
.................... /*****************************************************************************/
.................... void usb_set_configured(int8 config);
....................
.................... /******************************************************************************
.................... /* usb_disable_endpoints()
.................... /*
.................... /* Summary: Disables endpoints (all endpoints but 0)
.................... /*
.................... /*****************************************************************************/
.................... void usb_disable_endpoints(void);
....................
....................
.................... /*******************************************************************************
.................... /* usb_disable_endpoint()
.................... /*
.................... /* Input: Endpoint to disable (0..15)
.................... /*
.................... /* Summary: Disables specified endpoint
.................... /*
.................... /********************************************************************************/
.................... void usb_disable_endpoint(int8 en);
....................
.................... /**************************************************************
.................... /* usb_request_send_response(len)
.................... /* usb_request_get_data()
.................... /* usb_request_stall()
.................... /*
.................... /* Input: len - size of packet to send
.................... /*
.................... /* Summary: One of these 3 functions will be called by the USB stack after
.................... /* handling a SETUP packet.
.................... /*
.................... /* After we process a SETUP request, we have 1 of three responses:
.................... /* 1.) send a response IN packet
.................... /* 2.) wait for followup OUT packet(s) with data
.................... /* 3.) stall because we don't support that SETUP request
.................... /*
.................... /* If we are sending data, the array usb_ep0_tx_buffer[] will hold
.................... /* the response and the USB Request handler code will call
.................... /* usb_request_send_response() to let us know how big the packet is.
.................... /*
.................... /* If we are waiting for more data, usb_request_get_data() will
.................... /* be called by the USB request handler code to configure the EP0 OUT
.................... /* endpoint to be ready for more data
.................... /*
.................... /* If we don't support a request, usb_request_stall() will be called
.................... /* by the USB request handler code to stall the endpoint 0.
.................... /*
.................... /* The operation of these functions depends on how SETUP packets
.................... /* are handled in the hardware layer.
.................... /*
.................... /***************************************************************/
.................... void usb_request_send_response(unsigned int8 len);
.................... void usb_request_get_data(void);
.................... void usb_request_stall(void);
....................
....................
.................... #endif
....................
....................
.................... //////////////////////// EXTRA USER FUNCTIONS /////////////////////////////////
....................
.................... /**************************************************************
.................... /* usb_flush_in()
.................... /*
.................... /* Input: endpoint - which endpoint to mark for transfer
.................... /* len - length of data that is being tramsferred
.................... /* tgl - Data toggle synchronization for this packet
.................... /*
.................... /* Output: TRUE if success, FALSE if error (we don't control the endpoint)
.................... /*
.................... /* Summary: Marks the endpoint ready for transmission. You must
.................... /* have already loaded the endpoint buffer with data.
.................... /* (IN is PIC -> PC).
.................... /* This routine is useful if you want to setup an endpoint by
.................... /* writing to the buffer directly.
.................... /* This routine is not necessary if you use usb_put_packet().
.................... /***************************************************************/
.................... int1 usb_flush_in(int8 endpoint, int16 len, USB_DTS_BIT tgl);
....................
.................... /**************************************************************
.................... /* usb_flush_out()
.................... /*
.................... /* Input: endpoint - which endpoint to mark for release
.................... /* tgl - Data toggle synchronization to expect in the next packet
.................... /*
.................... /* Output: NONE
.................... /*
.................... /* Summary: Clears the previously received packet, and then marks this
.................... /* endpoint's receive buffer as ready for more data.
.................... /* (OUT is PC -> PIC). This routine is useful if you do not
.................... /* want to use usb_get_packet(), instead you want to handle with
.................... /* the endpoint buffer directly. Also see usb_rx_packet_size().
.................... /* This routine is not necessary if you use usb_get_packet().
.................... /***************************************************************/
.................... void usb_flush_out(int8 endpoint, USB_DTS_BIT tgl);
....................
.................... /**************************************************************
.................... /* usb_rx_packet_size()
.................... /*
.................... /* Input: endpoint - which endpoint to mark to check
.................... /*
.................... /* Output: Returns the number of bytes in the endpoint's receive buffer.
.................... /*
.................... /* Summary: Read the number of data stored in the receive buffer. When you
.................... /* have handled the data, use usb_flush_out() to clear the buffer. The
.................... /* result may be invalid if usb_kbhit() returns false for this endpoint.
.................... /* This routine is not necessary if you use usb_get_packet().
.................... /***************************************************************/
.................... int16 usb_rx_packet_size(int8 endpoint);
....................
.................... #ENDIF
....................
.................... #else
.................... #include <pic24_usb.h> //Microchip 18Fxx5x hardware layer for usb.c
.................... #endif
.................... #else
.................... #include <usbn960x.h>
.................... #endif
.................... #include <usb_desc_cdc.h> //USB Configuration and Device descriptors for this UBS device
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// usb_desc_cdc.h ////
.................... //// ////
.................... //// An example set of device / configuration descriptors for use with ////
.................... //// CCS's CDC Virtual COM Port driver (see usb_cdc.h) ////
.................... //// ////
.................... //// This file is part of CCS's PIC USB driver code. See USB.H ////
.................... //// for more documentation and a list of examples. ////
.................... //// ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// ////
.................... //// Version History: ////
.................... //// ////
.................... //// March 5th, 2009: ////
.................... //// Cleanup for Wizard. ////
.................... //// PIC24 Initial release. ////
.................... //// ////
.................... //// 10/28/05: ////
.................... //// Bulk endpoint sizes updated to allow more than 255 byte ////
.................... //// packets. ////
.................... //// Changed device to USB 1.10 ////
.................... //// ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2005 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS ////
.................... //// C compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, ////
.................... //// reproduction or distribution is permitted without written ////
.................... //// permission. Derivative programs created using this software ////
.................... //// in object code form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
....................
.................... #IFNDEF __USB_DESCRIPTORS__
.................... #DEFINE __USB_DESCRIPTORS__
....................
.................... ///////// config options, although it's best to leave alone for this demo /////
.................... #define USB_CONFIG_PID 0x0033
.................... #define USB_CONFIG_VID 0x0461
.................... #define USB_CONFIG_BUS_POWER 100 //100mA (range is 0..500)
.................... #define USB_CONFIG_VERSION 0x0100 //01.00 //range is 00.00 to 99.99
.................... //////// end config ///////////////////////////////////////////////////////////
....................
.................... #DEFINE USB_HID_DEVICE FALSE
.................... #DEFINE USB_CDC_DEVICE TRUE
....................
.................... #define USB_CDC_COMM_IN_ENDPOINT 1
.................... #define USB_CDC_COMM_IN_SIZE 8
.................... #define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT
.................... #define USB_EP1_TX_SIZE USB_CDC_COMM_IN_SIZE
....................
.................... //pic to pc endpoint config
.................... #define USB_CDC_DATA_IN_ENDPOINT 2
.................... #define USB_CDC_DATA_IN_SIZE 64
.................... #define USB_EP2_TX_ENABLE USB_ENABLE_BULK
.................... #define USB_EP2_TX_SIZE USB_CDC_DATA_IN_SIZE
....................
.................... //pc to pic endpoint config
.................... #define USB_CDC_DATA_OUT_ENDPOINT 2
.................... #define USB_CDC_DATA_OUT_SIZE 64
.................... #define USB_EP2_RX_ENABLE USB_ENABLE_BULK
.................... #define USB_EP2_RX_SIZE USB_CDC_DATA_OUT_SIZE
....................
.................... #include <usb.h>
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// usb.h ////
.................... //// ////
.................... //// Function protypes, defintions and globals used by CCS USB driver ////
.................... //// ////
.................... //// This file is part of CCS's USB driver code ////
.................... //// ////
.................... //// The following USB examples are provided by CCS: ////
.................... //// ex_usb_mouse.c - A HID Mouse. ////
.................... //// ex_usb_hid.c - A custom application using HID protocol. ////
.................... //// ex_usb_kbmouse.c - A HID Mouse/Keyboard combo using multiple ////
.................... //// interfaces. ////
.................... //// ex_usb_kbmouse2.c - A HID Mouse/Keyboard combo using multiple ////
.................... //// HID Reports. ////
.................... //// ex_usb_scope.c - A digital oscilloscope using a custom ////
.................... //// protocol requiring custom Windows drivers. ////
.................... //// ex_usb_serial.c - ////
.................... //// ex_usb_serial2.c - Two examples of using the CDC driver for ////
.................... //// a virtual COM port. ////
.................... //// ex_usb_bootloader.c - CDC/Virtual COM port bootloader. ////
.................... //// ex_usb_loadmouse.c - A conversion of ex_usb_mouse.c that is ////
.................... //// compatible with ex_usb_mouse.c. ////
.................... //// ////
.................... //// ********************** API ********************* ////
.................... //// ////
.................... //// These are the functions that are meant to be called by the user: ////
.................... //// ////
.................... //// usb_init() - Initializes the USB stack, the USB peripheral and ////
.................... //// attaches the unit to the usb bus. Enables ////
.................... //// interrupts. Will wait in an infinite loop until ////
.................... //// the device enumerates - if you are using ////
.................... //// connection sense or if the processor should run ////
.................... //// even if it's not connected to USB then use ////
.................... //// usb_init_cs() instead. ////
.................... //// ////
.................... //// usb_init_cs() - A smaller usb_init(), does not attach unit ////
.................... //// to usb bus or enable interrupts. Since this does ////
.................... //// not attach to the USB, you must periodically call ////
.................... //// usb_task(). See usb_task() for more information. ////
.................... //// ////
.................... //// usb_task() - If usb_init_cs() was used to initiate the USB ////
.................... //// peripheral, usb_task() should then be called periodically ////
.................... //// to check the connection sense pin. If the connection ////
.................... //// sense pin denotes USB is connected and the USB peripheral ////
.................... //// is not attached, this will attach the USB peripheral ////
.................... //// so the PC can start the enumeration process (and it ////
.................... //// will enable interrupts). If the connection sense pin ////
.................... //// denotes USB is not attached and the USB peripheral is ////
.................... //// running, this will reset the USB peripheral and wait ////
.................... //// for USB to reconnect (and usb_enumerated() will start ////
.................... //// returning FALSE). If connection sense (USB_CON_SENSE_PIN) ////
.................... //// is not defined the usb_task() assumes that USB is always ////
.................... //// connected. ////
.................... //// ////
.................... //// usb_attached() - Returns TRUE if the device is attached to a ////
.................... //// USB cable. A macro that looks at the defined ////
.................... //// connection sense pin. If this returns TRUE ////
.................... //// it does not mean the PC has connected to it, ////
.................... //// you need to use usb_enumerated() to check this. ////
.................... //// ////
.................... //// usb_enumerated() - Returns TRUE if device has been enumerated ////
.................... //// (configured) by host, FALSE if it has not. ////
.................... //// Do not try to use the USB peripheral for ////
.................... //// sending and receiving packets until you ////
.................... //// are enumerated. ////
.................... //// ////
.................... //// usb_wait_for_enumeration() - Sits in an infinte loop until device ////
.................... //// is enumerated. ////
.................... //// ////
.................... //// usb_tbe(endpoint) - Returns TRUE if the endpoint transmit buffer ////
.................... //// is free and ready to accept a new packet for transmission. ////
.................... //// ////
.................... //// usb_put_packet(endpoint, ptr, len, tgl) - Sends one packet to the ////
.................... //// host. If you need to send a message that ////
.................... //// spans more than one packet then use ////
.................... //// usb_puts(). Fore more detailed documentation ////
.................... //// see usb_hw_layer.h ////
.................... //// ////
.................... //// usb_puts(endpoint, ptr, len, timeout) - Sends a multiple packet ////
.................... //// message to the host. If you only need to send one packet, ////
.................... //// it is more effecient to use usb_put_packet(). This is ////
.................... //// documented in more detail above the prototype in USB.H. ////
.................... //// ////
.................... //// usb_kbhit(endpoint) - Returns true if OUT endpoint contains data ////
.................... //// from host. This will remain TRUE until ////
.................... //// usb_put_packet() or usb_flush_out() used. ////
.................... //// This function will return an invalid response ////
.................... //// if specified endpoint is not enabled for ////
.................... //// receiving data. ////
.................... //// ////
.................... //// len = usb_get_packet(endpoint, ptr, max) - Gets one packet that ////
.................... //// from the host/PC. usb_kbhit() must return TRUE before you ////
.................... //// call this routine or your data may not be valid. This ////
.................... //// only receives one packet, if you are trying to receive a ////
.................... //// multi-packet message use usb_gets(). For more detailed ////
.................... //// documentation see usb_hw_layer.h. ////
.................... //// ////
.................... //// len = usb_gets(endpoint, ptr, max, timeout) - Gets multiple ////
.................... //// packets from the host, you would use this instead ////
.................... //// of usb_get_packet() if you wanted to handle multi-packet ////
.................... //// messages. This is documented in more detail above the ////
.................... //// prototype in USB.H. ////
.................... //// ////
.................... //// ////
.................... //// ********* DEFINITIONS / CONFIGURATION ********** ////
.................... //// ////
.................... //// The following definitions are declared here, but can be ////
.................... //// overwritten in your code. Unless needed otherwise, leave ////
.................... //// to default value. If confused about a definition read the ////
.................... //// comments at each defintion ////
.................... //// ////
.................... //// USB_HID_IDLE (TRUE) - Set to TRUE if your device supports ////
.................... //// Set_Idle HID class request. Set to ////
.................... //// False if you do not (device will ////
.................... //// send a Wrong-state if computer ////
.................... //// sends a Set_Idle / Get_Idle command) ////
.................... //// NOTE: If you set to TRUE you must ////
.................... //// provide your own code. See ////
.................... //// usb_isr_tkn_setup_ClassInterface() in ////
.................... //// usb.c ////
.................... //// ////
.................... //// USB_HID_BOOT_PROTOCOL (FALSE) - Set to TRUE if your device supports ////
.................... //// Set_Protocl HID class request. Set to ////
.................... //// False if you do not (device will ////
.................... //// send a Wrong-state if computer ////
.................... //// sends a Set_Protocl / Get_Protocol ////
.................... //// command). ////
.................... //// NOTE: If you set to TRUE you must ////
.................... //// provide your own code in the ////
.................... //// application that properly send boot ////
.................... //// or HID packets. ////
.................... //// ////
.................... //// USB_MAX_EP0_PACKET_LENGTH (8) - Max Packet size for Endpoint 0. ////
.................... //// The hardware level driver (ex ////
.................... //// pic18_usb.h will define this value if ////
.................... //// not already overwritten). Increasing ////
.................... //// this size will speed up the ////
.................... //// enumeration process. ////
.................... //// ////
.................... //// USB_EPx_RX_ENABLE (USB_ENABLE_DISABLED) - Where x is the ////
.................... //// endpoint number. Change this define ////
.................... //// to specify what kind of transfer method ////
.................... //// this RX (PC to device) endpoint uses. ////
.................... //// Here is the list of valid transfer methods: ////
.................... //// USB_ENABLE_CONTROL ////
.................... //// USB_ENABLE_ISOCHRONOUS ////
.................... //// USB_ENABLE_BULK ////
.................... //// USB_ENABLE_INTERRUPT ////
.................... //// USB_ENABLE_DISABLED ////
.................... //// Don't forget that you must specify the ////
.................... //// transfer method properly in your endpoint ////
.................... //// descriptor, too. ////
.................... //// ////
.................... //// USB_EPx_RX_SIZE (0) - For some hardware it is important to know ////
.................... //// how much memory to reserve for receiving ////
.................... //// packets. ////
.................... //// ////
.................... //// *** NOTE *** You must have both USB_EPx_RX_ENABLE defined and ////
.................... //// USB_EPx_RX_SIZE defined (non 0) to enable a RX ////
.................... //// endpoint. ////
.................... //// *** NOTE *** Endpoint 0 is always enabled. ////
.................... //// ////
.................... //// USB_EPx_TX_ENABLE (USB_ENABLE_DISABLED) - Where x is the ////
.................... //// endpoint number. Change this define ////
.................... //// to specify what kind of transfer method ////
.................... //// this TX (device to PC) endpoint uses. ////
.................... //// Here is the list of valid transfer methods: ////
.................... //// USB_ENABLE_CONTROL ////
.................... //// USB_ENABLE_ISOCHRONOUS ////
.................... //// USB_ENABLE_BULK ////
.................... //// USB_ENABLE_INTERRUPT ////
.................... //// USB_ENABLE_DISABLED ////
.................... //// Don't forget that you must specify the ////
.................... //// transfer method properly in your endpoint ////
.................... //// descriptor, too. ////
.................... //// ////
.................... //// USB_EPx_TX_SIZE (0) - For some hardware it is important to know ////
.................... //// how much memory to reserve for transmitting ////
.................... //// packets. ////
.................... //// ////
.................... //// *** NOTE *** You must have both USB_EPx_TX_ENABLE defined and ////
.................... //// USB_EPx_TX_SIZE defined (non 0) to enable a TX ////
.................... //// endpoint. ////
.................... //// ////
.................... //// ////
.................... //// USB_HID_DEVICE (TRUE) - HID devices require extra code to handle ////
.................... //// HID requests. You can disable to save ////
.................... //// ROM space if you are not using a HID ////
.................... //// device. If you are not using a HID ////
.................... //// device you must provide your own O/S ////
.................... //// (Windows) driver. ////
.................... //// ////
.................... //// The other definitions should not be changed. ////
.................... //// ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// ////
.................... //// Version History: ////
.................... //// ////
.................... //// March 5th, 2009: ////
.................... //// Cleanup for Wizard. ////
.................... //// PIC24 Initial release. ////
.................... //// ////
.................... //// July 13th, 2005: ////
.................... //// usb_ep_tx_size[] and usb_ep_rx_size[] changed to 16bits ////
.................... //// ////
.................... //// June 20th, 2005: ////
.................... //// Initial 18fxx5x release ////
.................... //// ////
.................... //// May 13th, 2005: ////
.................... //// Beta release, only works with 18Fxx5x hardware layer. ////
.................... //// Now supports multiple interfaces (many defines in descriptors ////
.................... //// will have to be changed, see examples) ////
.................... //// ////
.................... //// Mar 21st, 2005: ////
.................... //// Initial Alpha Release with PIC18Fxx5x support. (ONLY TESTED ////
.................... //// WITH 18F4550) ////
.................... //// usb_gets() and usb_puts() changed (see usb.c) ////
.................... //// ////
.................... //// June 24th, 2004: ////
.................... //// Optimization and cleanup. ////
.................... //// The following definitions changed: ////
.................... //// USB_EPx_TX_ENABLE and USB_EPx_RX_ENABLE have changed. See usb.h ////
.................... //// USB_CONFIG_DESCRIPTORS[] removed ////
.................... //// USB_CONFIG_DESC_LEN changed to USB_DESC_CONFIG_LEN ////
.................... //// USB_INTERFACE_DESC_LEN changed to USB_DESC_INTERFACE_LEN ////
.................... //// USB_CLASS_DESC_LEN changed to USB_DESC_CLASS_LEN ////
.................... //// USB_ENDPOINT_DESC_LEN changed to USB_DESC_ENDPOINT_LEN ////
.................... //// USB_CONFIG_DESC_KEY changed to USB_DESC_CONFIG_TYPE ////
.................... //// USB_INTERFACE_DESC_KEY changed to USB_DESC_INTERFACE_TYPE ////
.................... //// USB_CLASS_DESC_KEY changed to USB_DESC_CLASS_TYPE ////
.................... //// USB_ENDPOINT_DESC_KEY changed to USB_DESC_ENDPOINT_TYPE ////
.................... //// USB_STRING_X[] arrays removed, see USB_STRING_DESC[] and ////
.................... //// USB_STRING_DESC_OFFSET[] ////
.................... //// dev_req, curr_config, status_device and getdesc_type global ////
.................... //// variables moved into struct USB_stack_status ////
.................... //// ////
.................... //// October 15th, 2003: Support for boot protocol added. ////
.................... //// Set USB_HID_BOOT_PROTOCOL to TRUE to support this. ////
.................... //// The array hid_protocol[] saves which protocol mode each ////
.................... //// interface is in. It is your applications job to send ////
.................... //// data that either fit the boot protocol or HID protocol. ////
.................... //// ////
.................... //// May 6th, 2003: Fixed a potential stack overflow using PCM ////
.................... //// ////
.................... //// October 29th, 2002: New definition added to USB_STATES ////
.................... //// ////
.................... //// August 2nd, 2002: Initial Public Release ////
.................... //// ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2009 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS ////
.................... //// C compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, ////
.................... //// reproduction or distribution is permitted without written ////
.................... //// permission. Derivative programs created using this software ////
.................... //// in object code form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
....................
.................... #IFNDEF __USB_PROTOTYPES__
.................... #DEFINE __USB_PROTOTYPES__
....................
.................... //// CONFIGURATION ////////////////////////////////////////////////////////////
....................
.................... #ifndef USB_CON_SENSE_PIN
.................... #define USB_CON_SENSE_PIN 0
.................... #endif
....................
.................... #IFNDEF USB_HID_BOOT_PROTOCOL
.................... #DEFINE USB_HID_BOOT_PROTOCOL FALSE
.................... #ENDIF
....................
.................... #IFNDEF USB_HID_IDLE
.................... #DEFINE USB_HID_IDLE FALSE
.................... #ENDIF
....................
.................... //should the compiler add the extra HID handler code? Defaults to yes.
.................... #IFNDEF USB_HID_DEVICE
.................... #DEFINE USB_HID_DEVICE TRUE
.................... #ENDIF
....................
.................... #IFNDEF USB_CDC_DEVICE
.................... #DEFINE USB_CDC_DEVICE FALSE
.................... #ENDIF
....................
.................... //set to false to opt for less RAM, true to opt for less ROM
.................... #ifndef USB_OPT_FOR_ROM
.................... #define USB_OPT_FOR_ROM TRUE
.................... #endif
....................
.................... #IFNDEF USB_MAX_EP0_PACKET_LENGTH
.................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 8
.................... #ENDIF
....................
....................
.................... ////// USER-LEVEL API /////////////////////////////////////////////////////////
....................
.................... /**************************************************************
.................... /* usb_enumerated()
.................... /*
.................... /* Input: Global variable USB_Curr_Config
.................... /* Returns: Returns a 1 if device is configured / enumerated,
.................... /* Returns a 0 if device is un-configured / not enumerated.
.................... /*
.................... /* Summary: See API section of USB.H for more documentation.
.................... /***************************************************************/
.................... int1 usb_enumerated(void);
....................
.................... /**************************************************************
.................... /* usb_wait_for_enumeration()
.................... /*
.................... /* Input: Global variable USB_Curr_Config
.................... /*
.................... /* Summary: Waits in-definately until device is configured / enumerated.
.................... /* See API section of USB.H for more information.
.................... /***************************************************************/
.................... void usb_wait_for_enumeration(void);
....................
.................... /****************************************************************************
.................... /* usb_gets(endpoint, ptr, max, timeout)
.................... /*
.................... /* Input: endpoint - endpoint to get data from
.................... /* ptr - place / array to store data to
.................... /* max - max amount of data to get from USB and store into ptr
.................... /* timeout - time in milliseconds, for each packet, to wait before
.................... /* timeout. set to 0 for no timeout.
.................... /*
.................... /* Output: Amount of data returned. It may be less than max.
.................... /*
.................... /* Summary: Gets data from the host. Will get multiple-packet messages
.................... /* and finish when either it receives a 0-len packet or a packet
.................... /* of less size than maximum.
.................... /*
.................... /*****************************************************************************/
.................... unsigned int16 usb_gets(int8 endpoint, int8 * ptr, unsigned int16 max, unsigned int16 timeout);
....................
.................... /****************************************************************************
.................... /* usb_puts()
.................... /*
.................... /* Inputs: endpoint - endpoint to send data out
.................... /* ptr - points to array of data to send
.................... /* len - amount of data to send
.................... /* timeout - time in milli-seconds, for each packet, to wait before
.................... /* timeout. set to 0 for no timeout.
.................... /*
.................... /* Outputs: Returns TRUE if message sent succesfully, FALSE if it was not
.................... /* sent before timeout period expired.
.................... /*
.................... /* Summary: Used for sending multiple packets of data as one message. This
.................... /* function can still be used to send messages consiting of only one
.................... /* packet. See usb_put_packet() documentation for the rules about when
.................... /* multiple packet messages or 0-lenght packets are needed.
.................... /*
.................... /*****************************************************************************/
.................... int1 usb_puts(int8 endpoint, int8 * ptr, unsigned int16 len, unsigned int8 timeout);
....................
.................... /******************************************************************************
.................... /* usb_attached()
.................... /*
.................... /* Summary: Returns TRUE if the device is attached to a USB cable.
.................... /* See the API section of USB.H for more documentation.
.................... /*
.................... /*****************************************************************************/
.................... #if USB_CON_SENSE_PIN
.................... #define usb_attached() input(USB_CON_SENSE_PIN)
.................... #else
.................... #define usb_attached() TRUE
.................... #endif
....................
.................... ////// END USER-LEVEL API /////////////////////////////////////////////////////
....................
....................
.................... ////// STACK-LEVEL API USED BY HW DRIVERS ////////////////////////////////////
....................
.................... enum USB_STATES {GET_DESCRIPTOR=1,SET_ADDRESS=2,NONE=0};
....................
.................... enum USB_GETDESC_TYPES {USB_GETDESC_CONFIG_TYPE=0,USB_GETDESC_HIDREPORT_TYPE=1,USB_GETDESC_STRING_TYPE=2,USB_GETDESC_DEVICE_TYPE=3};
....................
.................... #if USB_OPT_FOR_ROM
.................... typedef struct {
.................... USB_STATES dev_req; //what did the last setup token set us up to do?. init at none
.................... int curr_config; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS)
.................... int status_device; //Holds our state for Set_Feature and Clear_Feature
.................... USB_GETDESC_TYPES getdesc_type; //which get_descriptor() we are handling
.................... } TYPE_USB_STACK_STATUS;
.................... #else
.................... typedef struct {
.................... USB_STATES dev_req:2; //what did the last setup token set us up to do?. init at none
.................... int Curr_config:2; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS)
.................... int status_device:2; //Holds our state for Set_Feature and Clear_Feature
.................... USB_GETDESC_TYPES getdesc_type:2; //which get_descriptor() we are handling
.................... } TYPE_USB_STACK_STATUS;
.................... #endif
....................
.................... extern TYPE_USB_STACK_STATUS USB_stack_status;
....................
.................... /**************************************************************
.................... /* usb_token_reset()
.................... /*
.................... /* Output: No output (but many global registers are modified)
.................... /*
.................... /* Summary: Resets the token handler to initial (unconfigured) state.
.................... /***************************************************************/
.................... void usb_token_reset(void);
....................
.................... /**************************************************************
.................... /* usb_isr_tok_setup_dne()
.................... /*
.................... /* Input: usb_ep0_rx_buffer[] contains the the setup packet.
.................... /*
.................... /* Output: None (many globals are changed)
.................... /*
.................... /* Summary: This function is that handles the setup token.
.................... /* We must handle all relevant requests, such as Set_Configuration,
.................... /* Get_Descriptor, etc.
.................... /*
.................... /* usb_ep0_rx_buffer[] contains setup data packet, which has the
.................... /* following records:
.................... /* -------------------------------------------------------------------------------------------
.................... /* usb_ep0_rx_buffer[ 0 ]=bmRequestType; Where the setup packet goes
.................... /* bit7 (0) host-to-device
.................... /* (1) device-to-host
.................... /* bit6-5 (00) usb standard request;
.................... /* (01) class request;
.................... /* (10) vendor request
.................... /* (11) reserved
.................... /* bit4-0 (0000) device
.................... /* (0001) interface
.................... /* (0010) endpoint
.................... /* (0011) other element
.................... /* (0100) to (1111) reserved
.................... /* usb_ep0_rx_buffer[ 1 ]=bRequest ; the request
.................... /* usb_ep0_rx_buffer[2,3]=wValue ; a value which corresponds to request
.................... /* usb_ep0_rx_buffer[4,5]=wIndex ; could correspond to interface or endpoint...
.................... /* usb_ep0_rx_buffer[6,7]=wLength ; number of bytes in next data packet;
.................... /* for host-to-device, this exactly how many bytes in data packet.
.................... /* for device-to-host, this is the maximum bytes that can fit one packet.
.................... /***************************************************************/
.................... void usb_isr_tok_setup_dne(void);
....................
.................... /**************************************************************
.................... /* usb_isr_tok_out_dne()
.................... /*
.................... /* Input: endpoint contains which endpoint we are receiving data (0..15)
.................... /*
.................... /* Summary: Processes out tokens (out is respective of the host, so actualy
.................... /* incoming to the pic), but not out setup tokens. Normally when
.................... /* data is received it is left in the buffer (user would use
.................... /* usb_kbhit() and usb_get_packet() to receive data), but certain
.................... /* libraries (like CDC) have to answer setup packets.
.................... /*
.................... /***************************************************************/
.................... void usb_isr_tok_out_dne(int8 endpoint);
....................
.................... /**************************************************************
.................... /* usb_isr_tok_in_dne(endpoint)
.................... /*
.................... /* Input: endpoint - which endpoint we are processing a setup token.
.................... /*
.................... /* Summary: This handles an IN packet (HOST <- PIC). For endpoint 0, this
.................... /* is usually to setup a response packet to a setup packet. Endpoints 1..15
.................... /* are generally ignored, and the user has to use usb_tbe() to determine if
.................... /* if the buffer is ready for a new transmit packet (there are special cases,
.................... /* like CDC which handles the CDC protocl).
.................... /*
.................... /***************************************************************/
.................... void usb_isr_tok_in_dne(int8 endpoint);
....................
.................... ////// END STACK-LEVEL API USED BY HW DRIVERS /////////////////////////////////
....................
....................
.................... //CCS only supports one configuration at this time
.................... #DEFINE USB_NUM_CONFIGURATIONS 1 //DO NOT CHANGE
....................
.................... //PID values for tokens (see page 48 of USB Complete ed.1)
.................... #define PID_IN 0x09 //device to host transactions
.................... #define PID_OUT 0x01 //host to device transactions
.................... #define PID_SETUP 0x0D //host to device setup transaction
.................... #define PID_ACK 0x02 //receiver accepts error-free data packet
.................... #define PID_DATA0 0x03 //data packet with even sync bit
.................... #define PID_SOF 0x05 //start of framer marker and frame number
.................... #define PID_NAK 0x0A //receiver can't accept data or sender cant send data or has no data to transmit
.................... #define PID_DATA1 0x0B //data packet with odd sync bit
.................... #define PID_PRE 0x0C //preamble issued by host. enables downstream traffic to low-speed device
.................... #define PID_STALL 0x0E //a control request isnt supported or the endpoint is halted
....................
.................... //Key which identifies descritpors
.................... #DEFINE USB_DESC_DEVICE_TYPE 0x01 //#DEFINE USB_DEVICE_DESC_KEY 0x01
.................... #DEFINE USB_DESC_CONFIG_TYPE 0x02 //#DEFINE USB_CONFIG_DESC_KEY 0x02
.................... #DEFINE USB_DESC_STRING_TYPE 0x03 //#DEFINE USB_STRING_DESC_KEY 0x03
.................... #DEFINE USB_DESC_INTERFACE_TYPE 0x04 //#DEFINE USB_INTERFACE_DESC_KEY 0x04
.................... #DEFINE USB_DESC_ENDPOINT_TYPE 0x05 //#DEFINE USB_ENDPOINT_DESC_KEY 0x05
.................... #DEFINE USB_DESC_CLASS_TYPE 0x21 //#DEFINE USB_CLASS_DESC_KEY 0x21
.................... #DEFINE USB_DESC_HIDREPORT_TYPE 0x22
....................
.................... //The length of each descriptor
.................... #DEFINE USB_DESC_DEVICE_LEN 18 //#DEFINE USB_DEVICE_DESC_LEN 18
.................... #DEFINE USB_DESC_CONFIG_LEN 9 //#DEFINE USB_CONFIG_DESC_LEN 9
.................... #DEFINE USB_DESC_INTERFACE_LEN 9 //#DEFINE USB_INTERFACE_DESC_LEN 9
.................... #DEFINE USB_DESC_CLASS_LEN 9 //#DEFINE USB_CLASS_DESC_LEN 9
.................... #DEFINE USB_DESC_ENDPOINT_LEN 7 //#DEFINE USB_ENDPOINT_DESC_LEN 7
....................
.................... //Standard USB Setup bRequest Codes
.................... #define USB_STANDARD_REQUEST_GET_STATUS 0x00
.................... #define USB_STANDARD_REQUEST_CLEAR_FEATURE 0x01
.................... #define USB_STANDARD_REQUEST_SET_FEATURE 0x03
.................... #define USB_STANDARD_REQUEST_SET_ADDRESS 0x05
.................... #define USB_STANDARD_REQUEST_GET_DESCRIPTOR 0x06
.................... #define USB_STANDARD_REQUEST_SET_DESCRIPTOR 0x07
.................... #define USB_STANDARD_REQUEST_GET_CONFIGURATION 0x08
.................... #define USB_STANDARD_REQUEST_SET_CONFIGURATION 0x09
.................... #define USB_STANDARD_REQUEST_GET_INTERFACE 0x0A
.................... #define USB_STANDARD_REQUEST_SET_INTERFACE 0x0B
.................... #define USB_STANDARD_REQUEST_SYNCH_FRAME 0x0C
....................
.................... //HID Class Setup bRequest Codes
.................... #define USB_HID_REQUEST_GET_REPORT 0x01
.................... #define USB_HID_REQUEST_GET_IDLE 0x02
.................... #define USB_HID_REQUEST_GET_PROTOCOL 0x03
.................... #define USB_HID_REQUEST_SET_REPORT 0x09
.................... #define USB_HID_REQUEST_SET_IDLE 0x0A
.................... #define USB_HID_REQUEST_SET_PROTOCOL 0x0B
....................
.................... //types of endpoints as defined in the descriptor
.................... #define USB_ENDPOINT_TYPE_CONTROL 0x00
.................... #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
.................... #define USB_ENDPOINT_TYPE_BULK 0x02
.................... #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
....................
.................... //types of endpoints used internally in this api
.................... #define USB_ENABLE_DISABLED -1
.................... #define USB_ENABLE_BULK USB_ENDPOINT_TYPE_BULK
.................... #define USB_ENABLE_ISOCHRONOUS USB_ENDPOINT_TYPE_ISOCHRONOUS
.................... #define USB_ENABLE_INTERRUPT USB_ENDPOINT_TYPE_INTERRUPT
.................... #define USB_ENABLE_CONTROL USB_ENDPOINT_TYPE_CONTROL
....................
....................
.................... //*** ENABLE RX ENDPOINTS AND BUFFERS
....................
.................... //--------- endpoint 0 defines ----------
.................... #define USB_EP0_TX_ENABLE USB_ENABLE_CONTROL
.................... #define USB_EP0_RX_ENABLE USB_ENABLE_CONTROL
.................... #define USB_EP0_RX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8
.................... #define USB_EP0_TX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8
....................
.................... //--------- endpoint 1 defines ----------
.................... #ifndef USB_EP1_TX_ENABLE
.................... #define USB_EP1_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP1_RX_ENABLE
.................... #define USB_EP1_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP1_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP1_RX_SIZE
.................... #undef USB_EP1_RX_SIZE
.................... #endif
.................... #define USB_EP1_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP1_RX_SIZE
.................... #error You enabled EP1 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP1_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP1_TX_SIZE
.................... #undef USB_EP1_TX_SIZE
.................... #endif
.................... #define USB_EP1_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP1_TX_SIZE
.................... #error You enabled EP1 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 2 defines ----------
.................... #ifndef USB_EP2_TX_ENABLE
.................... #define USB_EP2_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP2_RX_ENABLE
.................... #define USB_EP2_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP2_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP2_RX_SIZE
.................... #undef USB_EP2_RX_SIZE
.................... #endif
.................... #define USB_EP2_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP2_RX_SIZE
.................... #error You enabled EP2 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP2_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP2_TX_SIZE
.................... #undef USB_EP2_TX_SIZE
.................... #endif
.................... #define USB_EP2_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP2_TX_SIZE
.................... #error You enabled EP2 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 3 defines ----------
.................... #ifndef USB_EP3_TX_ENABLE
.................... #define USB_EP3_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP3_RX_ENABLE
.................... #define USB_EP3_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP3_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP3_RX_SIZE
.................... #undef USB_EP3_RX_SIZE
.................... #endif
.................... #define USB_EP3_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP3_RX_SIZE
.................... #error You enabled EP3 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP3_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP3_TX_SIZE
.................... #undef USB_EP3_TX_SIZE
.................... #endif
.................... #define USB_EP3_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP3_TX_SIZE
.................... #error You enabled EP3 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 4 defines ----------
.................... #ifndef USB_EP4_TX_ENABLE
.................... #define USB_EP4_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP4_RX_ENABLE
.................... #define USB_EP4_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP4_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP4_RX_SIZE
.................... #undef USB_EP4_RX_SIZE
.................... #endif
.................... #define USB_EP4_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP4_RX_SIZE
.................... #error You enabled EP4 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP4_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP4_TX_SIZE
.................... #undef USB_EP4_TX_SIZE
.................... #endif
.................... #define USB_EP4_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP4_TX_SIZE
.................... #error You enabled EP4 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 5 defines ----------
.................... #ifndef USB_EP5_TX_ENABLE
.................... #define USB_EP5_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP5_RX_ENABLE
.................... #define USB_EP5_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP5_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP5_RX_SIZE
.................... #undef USB_EP5_RX_SIZE
.................... #endif
.................... #define USB_EP5_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP5_RX_SIZE
.................... #error You enabled EP5 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP5_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP5_TX_SIZE
.................... #undef USB_EP5_TX_SIZE
.................... #endif
.................... #define USB_EP5_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP5_TX_SIZE
.................... #error You enabled EP5 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 6 defines ----------
.................... #ifndef USB_EP6_TX_ENABLE
.................... #define USB_EP6_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP6_RX_ENABLE
.................... #define USB_EP6_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP6_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP6_RX_SIZE
.................... #undef USB_EP6_RX_SIZE
.................... #endif
.................... #define USB_EP6_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP6_RX_SIZE
.................... #error You enabled EP6 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP6_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP6_TX_SIZE
.................... #undef USB_EP6_TX_SIZE
.................... #endif
.................... #define USB_EP6_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP6_TX_SIZE
.................... #error You enabled EP6 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 7 defines ----------
.................... #ifndef USB_EP7_TX_ENABLE
.................... #define USB_EP7_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP7_RX_ENABLE
.................... #define USB_EP7_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP7_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP7_RX_SIZE
.................... #undef USB_EP7_RX_SIZE
.................... #endif
.................... #define USB_EP7_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP7_RX_SIZE
.................... #error You enabled EP7 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP7_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP7_TX_SIZE
.................... #undef USB_EP7_TX_SIZE
.................... #endif
.................... #define USB_EP7_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP7_TX_SIZE
.................... #error You enabled EP7 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 8 defines ----------
.................... #ifndef USB_EP8_TX_ENABLE
.................... #define USB_EP8_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP8_RX_ENABLE
.................... #define USB_EP8_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP8_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP8_RX_SIZE
.................... #undef USB_EP8_RX_SIZE
.................... #endif
.................... #define USB_EP8_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP8_RX_SIZE
.................... #error You enabled EP8 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP8_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP8_TX_SIZE
.................... #undef USB_EP8_TX_SIZE
.................... #endif
.................... #define USB_EP8_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP8_TX_SIZE
.................... #error You enabled EP8 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 9 defines ----------
.................... #ifndef USB_EP9_TX_ENABLE
.................... #define USB_EP9_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP9_RX_ENABLE
.................... #define USB_EP9_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP9_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP9_RX_SIZE
.................... #undef USB_EP9_RX_SIZE
.................... #endif
.................... #define USB_EP9_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP9_RX_SIZE
.................... #error You enabled EP9 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP9_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP9_TX_SIZE
.................... #undef USB_EP9_TX_SIZE
.................... #endif
.................... #define USB_EP9_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP9_TX_SIZE
.................... #error You enabled EP9 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 10 defines ----------
.................... #ifndef USB_EP10_TX_ENABLE
.................... #define USB_EP10_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP10_RX_ENABLE
.................... #define USB_EP10_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP10_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP10_RX_SIZE
.................... #undef USB_EP10_RX_SIZE
.................... #endif
.................... #define USB_EP10_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP10_RX_SIZE
.................... #error You enabled EP10 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP10_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP10_TX_SIZE
.................... #undef USB_EP10_TX_SIZE
.................... #endif
.................... #define USB_EP10_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP10_TX_SIZE
.................... #error You enabled EP10 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 11 defines ----------
.................... #ifndef USB_EP11_TX_ENABLE
.................... #define USB_EP11_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP11_RX_ENABLE
.................... #define USB_EP11_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP11_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP11_RX_SIZE
.................... #undef USB_EP11_RX_SIZE
.................... #endif
.................... #define USB_EP11_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP11_RX_SIZE
.................... #error You enabled EP11 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP11_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP11_TX_SIZE
.................... #undef USB_EP11_TX_SIZE
.................... #endif
.................... #define USB_EP11_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP11_TX_SIZE
.................... #error You enabled EP11 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 12 defines ----------
.................... #ifndef USB_EP12_TX_ENABLE
.................... #define USB_EP12_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP12_RX_ENABLE
.................... #define USB_EP12_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP12_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP12_RX_SIZE
.................... #undef USB_EP12_RX_SIZE
.................... #endif
.................... #define USB_EP12_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP12_RX_SIZE
.................... #error You enabled EP12 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP12_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP12_TX_SIZE
.................... #undef USB_EP12_TX_SIZE
.................... #endif
.................... #define USB_EP12_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP12_TX_SIZE
.................... #error You enabled EP12 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 13 defines ----------
.................... #ifndef USB_EP13_TX_ENABLE
.................... #define USB_EP13_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP13_RX_ENABLE
.................... #define USB_EP13_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP13_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP13_RX_SIZE
.................... #undef USB_EP13_RX_SIZE
.................... #endif
.................... #define USB_EP13_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP13_RX_SIZE
.................... #error You enabled EP13 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP13_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP13_TX_SIZE
.................... #undef USB_EP13_TX_SIZE
.................... #endif
.................... #define USB_EP13_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP13_TX_SIZE
.................... #error You enabled EP13 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 14 defines ----------
.................... #ifndef USB_EP14_TX_ENABLE
.................... #define USB_EP14_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP14_RX_ENABLE
.................... #define USB_EP14_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP14_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP14_RX_SIZE
.................... #undef USB_EP14_RX_SIZE
.................... #endif
.................... #define USB_EP14_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP14_RX_SIZE
.................... #error You enabled EP14 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP14_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP14_TX_SIZE
.................... #undef USB_EP14_TX_SIZE
.................... #endif
.................... #define USB_EP14_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP14_TX_SIZE
.................... #error You enabled EP14 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 15 defines ----------
.................... #ifndef USB_EP15_TX_ENABLE
.................... #define USB_EP15_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP15_RX_ENABLE
.................... #define USB_EP15_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP15_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP15_RX_SIZE
.................... #undef USB_EP15_RX_SIZE
.................... #endif
.................... #define USB_EP15_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP15_RX_SIZE
.................... #error You enabled EP15 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP15_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP15_TX_SIZE
.................... #undef USB_EP15_TX_SIZE
.................... #endif
.................... #define USB_EP15_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP15_TX_SIZE
.................... #error You enabled EP15 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... const int8 usb_ep_tx_type[16]={
.................... USB_EP0_TX_ENABLE, USB_EP1_TX_ENABLE, USB_EP2_TX_ENABLE,
.................... USB_EP3_TX_ENABLE, USB_EP4_TX_ENABLE, USB_EP5_TX_ENABLE,
.................... USB_EP6_TX_ENABLE, USB_EP7_TX_ENABLE, USB_EP8_TX_ENABLE,
.................... USB_EP9_TX_ENABLE, USB_EP10_TX_ENABLE, USB_EP11_TX_ENABLE,
.................... USB_EP12_TX_ENABLE, USB_EP13_TX_ENABLE, USB_EP14_TX_ENABLE,
.................... USB_EP15_TX_ENABLE
.................... };
....................
.................... const int8 usb_ep_rx_type[16]={
.................... USB_EP0_RX_ENABLE, USB_EP1_RX_ENABLE, USB_EP2_RX_ENABLE,
.................... USB_EP3_RX_ENABLE, USB_EP4_RX_ENABLE, USB_EP5_RX_ENABLE,
.................... USB_EP6_RX_ENABLE, USB_EP7_RX_ENABLE, USB_EP8_RX_ENABLE,
.................... USB_EP9_RX_ENABLE, USB_EP10_RX_ENABLE, USB_EP11_RX_ENABLE,
.................... USB_EP12_RX_ENABLE, USB_EP13_RX_ENABLE, USB_EP14_RX_ENABLE,
.................... USB_EP15_RX_ENABLE
.................... };
....................
.................... const unsigned int16 usb_ep_tx_size[16]={
.................... USB_EP0_TX_SIZE, USB_EP1_TX_SIZE, USB_EP2_TX_SIZE,
.................... USB_EP3_TX_SIZE, USB_EP4_TX_SIZE, USB_EP5_TX_SIZE,
.................... USB_EP6_TX_SIZE, USB_EP7_TX_SIZE, USB_EP8_TX_SIZE,
.................... USB_EP9_TX_SIZE, USB_EP10_TX_SIZE, USB_EP11_TX_SIZE,
.................... USB_EP12_TX_SIZE, USB_EP13_TX_SIZE, USB_EP14_TX_SIZE,
.................... USB_EP15_TX_SIZE
.................... };
....................
.................... const unsigned int16 usb_ep_rx_size[16]={
.................... USB_EP0_RX_SIZE, USB_EP1_RX_SIZE, USB_EP2_RX_SIZE,
.................... USB_EP3_RX_SIZE, USB_EP4_RX_SIZE, USB_EP5_RX_SIZE,
.................... USB_EP6_RX_SIZE, USB_EP7_RX_SIZE, USB_EP8_RX_SIZE,
.................... USB_EP9_RX_SIZE, USB_EP10_RX_SIZE, USB_EP11_RX_SIZE,
.................... USB_EP12_RX_SIZE, USB_EP13_RX_SIZE, USB_EP14_RX_SIZE,
.................... USB_EP15_RX_SIZE
.................... };
....................
.................... #ENDIF
....................
....................
.................... //////////////////////////////////////////////////////////////////
.................... ///
.................... /// start config descriptor
.................... /// right now we only support one configuration descriptor.
.................... /// the config, interface, class, and endpoint goes into this array.
.................... ///
.................... //////////////////////////////////////////////////////////////////
....................
.................... #DEFINE USB_TOTAL_CONFIG_LEN 67 //config+interface+class+endpoint+endpoint (2 endpoints)
....................
.................... const char USB_CONFIG_DESC[] = {
.................... //IN ORDER TO COMPLY WITH WINDOWS HOSTS, THE ORDER OF THIS ARRAY MUST BE:
.................... // config(s)
.................... // interface(s)
.................... // class(es)
.................... // endpoint(s)
....................
.................... //config_descriptor for config index 1
.................... USB_DESC_CONFIG_LEN, //length of descriptor size ==0
.................... USB_DESC_CONFIG_TYPE, //constant CONFIGURATION (CONFIGURATION 0x02) ==1
.................... USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config ==2,3
.................... 2, //number of interfaces this device supports ==4
.................... 0x01, //identifier for this configuration. (IF we had more than one configurations) ==5
.................... 0x00, //index of string descriptor for this configuration ==6
.................... #if USB_CONFIG_BUS_POWER
.................... 0x80, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1 ==7
.................... #else
.................... 0xC0, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1 ==7
.................... #endif
.................... USB_CONFIG_BUS_POWER/2, //maximum bus power required (maximum milliamperes/2) (0x32 = 100mA) ==8
....................
....................
.................... //interface descriptor 0 (comm class interface)
.................... USB_DESC_INTERFACE_LEN, //length of descriptor =9
.................... USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =10
.................... 0x00, //number defining this interface (IF we had more than one interface) ==11
.................... 0x00, //alternate setting ==12
.................... 1, //number of endpoints ==13
.................... 0x02, //class code, 02 = Comm Interface Class ==14
.................... 0x02, //subclass code, 2 = Abstract ==15
.................... 0x01, //protocol code, 1 = v.25ter ==16
.................... 0x00, //index of string descriptor for interface ==17
....................
.................... //class descriptor [functional header]
.................... 5, //length of descriptor ==18
.................... 0x24, //dscriptor type (0x24 == ) ==19
.................... 0, //sub type (0=functional header) ==20
.................... 0x10,0x01, // ==21,22 //cdc version
....................
.................... //class descriptor [acm header]
.................... 4, //length of descriptor ==23
.................... 0x24, //dscriptor type (0x24 == ) ==24
.................... 2, //sub type (2=ACM) ==25
.................... 2, //capabilities ==26 //we support Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State.
....................
.................... //class descriptor [union header]
.................... 5, //length of descriptor ==27
.................... 0x24, //dscriptor type (0x24 == ) ==28
.................... 6, //sub type (6=union) ==29
.................... 0, //master intf ==30 //The interface number of the Communication or Dat a Cl ass interface, designated as the masteror controlling interface for the union.
.................... 1, //save intf0 ==31 //Interface number of first slave or associated interface in the union. *
....................
.................... //class descriptor [call mgmt header]
.................... 5, //length of descriptor ==32
.................... 0x24, //dscriptor type (0x24 == ) ==33
.................... 1, //sub type (1=call mgmt) ==34
.................... 0, //capabilities ==35 //device does not handle call management itself
.................... 1, //data interface ==36 //interface number of data class interface
....................
.................... //endpoint descriptor
.................... USB_DESC_ENDPOINT_LEN, //length of descriptor ==37
.................... USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==38
.................... USB_CDC_COMM_IN_ENDPOINT | 0x80, //endpoint number and direction
.................... 0x03, //transfer type supported (0x03 is interrupt) ==40
.................... USB_CDC_COMM_IN_SIZE,0x00, //maximum packet size supported ==41,42
.................... 250, //polling interval, in ms. (interrupt endpoint cant be smaller than 10 for slow speed devices) ==43
....................
.................... //interface descriptor 1 (data class interface)
.................... USB_DESC_INTERFACE_LEN, //length of descriptor =44
.................... USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =45
.................... 0x01, //number defining this interface (IF we had more than one interface) ==46
.................... 0x00, //alternate setting ==47
.................... 2, //number of endpoints ==48
.................... 0x0A, //class code, 0A = Data Interface Class ==49
.................... 0x00, //subclass code ==50
.................... 0x00, //protocol code ==51
.................... 0x00, //index of string descriptor for interface ==52
....................
.................... //endpoint descriptor
.................... USB_DESC_ENDPOINT_LEN, //length of descriptor ==53
.................... USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==54
.................... USB_CDC_DATA_OUT_ENDPOINT, //endpoint number and direction (0x02 = EP2 OUT) ==55
.................... 0x02, //transfer type supported (0x02 is bulk) ==56
.................... (USB_CDC_DATA_OUT_SIZE+1) & 0xFF, ((USB_CDC_DATA_OUT_SIZE+1) >> 8) & 0xFF, //maximum packet size supported ==57, 58
.................... 1, //polling interval, in ms. ==59
....................
.................... //endpoint descriptor
.................... USB_DESC_ENDPOINT_LEN, //length of descriptor ==60
.................... USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==61
.................... USB_CDC_DATA_IN_ENDPOINT | 0x80, //endpoint number and direction (0x82 = EP2 IN) ==62
.................... 0x02, //transfer type supported (0x02 is bulk) ==63
.................... (USB_CDC_DATA_IN_SIZE+1) & 0xFF, ((USB_CDC_DATA_IN_SIZE+1) >> 8) & 0xFF, //maximum packet size supported ==66, 67
.................... 1, //polling interval, in ms. ==68
.................... };
....................
.................... //****** BEGIN CONFIG DESCRIPTOR LOOKUP TABLES ********
.................... //since we can't make pointers to constants in certain pic16s, this is an offset table to find
.................... // a specific descriptor in the above table.
....................
.................... //the maximum number of interfaces seen on any config
.................... //for example, if config 1 has 1 interface and config 2 has 2 interfaces you must define this as 2
.................... #define USB_MAX_NUM_INTERFACES 2
....................
.................... //define how many interfaces there are per config. [0] is the first config, etc.
.................... const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={2};
....................
.................... //define where to find class descriptors
.................... //first dimension is the config number
.................... //second dimension specifies which interface
.................... //last dimension specifies which class in this interface to get, but most will only have 1 class per interface
.................... //if a class descriptor is not valid, set the value to 0xFFFF
.................... const int8 USB_CLASS_DESCRIPTORS[USB_NUM_CONFIGURATIONS][USB_MAX_NUM_INTERFACES][4]=
.................... {
.................... //config 1
.................... //interface 0
.................... //class 1-4
.................... 18,23,27,32,
.................... //interface 1
.................... //no classes for this interface
.................... 0xFF,0xFF,0xFF,0xFF
.................... };
....................
.................... #if (sizeof(USB_CONFIG_DESC) != USB_TOTAL_CONFIG_LEN)
.................... #error USB_TOTAL_CONFIG_LEN not defined correctly
.................... #endif
....................
....................
.................... //////////////////////////////////////////////////////////////////
.................... ///
.................... /// start device descriptors
.................... ///
.................... //////////////////////////////////////////////////////////////////
....................
.................... const char USB_DEVICE_DESC[USB_DESC_DEVICE_LEN] ={
.................... //starts of with device configuration. only one possible
.................... USB_DESC_DEVICE_LEN, //the length of this report ==0
.................... 0x01, //the constant DEVICE (DEVICE 0x01) ==1
.................... 0x10,0x01, //usb version in bcd ==2,3
.................... 0x02, //class code. 0x02=Communication Device Class ==4
.................... 0x00, //subclass code ==5
.................... 0x00, //protocol code ==6
.................... USB_MAX_EP0_PACKET_LENGTH, //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8) ==7
.................... USB_CONFIG_VID & 0xFF, ((USB_CONFIG_VID >> 8) & 0xFF), //vendor id ==9, 10
.................... USB_CONFIG_PID & 0xFF, ((USB_CONFIG_PID >> 8) & 0xFF), //product id, don't use 0xffff ==11, 12
.................... USB_CONFIG_VERSION & 0xFF, ((USB_CONFIG_VERSION >> 8) & 0xFF), //device release number ==13,14
.................... 0x01, //index of string description of manufacturer. therefore we point to string_1 array (see below) ==14
.................... 0x02, //index of string descriptor of the product ==15
.................... 0x00, //index of string descriptor of serial number ==16
.................... USB_NUM_CONFIGURATIONS //number of possible configurations ==17
.................... };
....................
....................
.................... //////////////////////////////////////////////////////////////////
.................... ///
.................... /// start string descriptors
.................... /// String 0 is a special language string, and must be defined. People in U.S.A. can leave this alone.
.................... ///
.................... /// You must define the length else get_next_string_character() will not see the string
.................... /// Current code only supports 10 strings (0 thru 9)
.................... ///
.................... //////////////////////////////////////////////////////////////////
....................
.................... #if !defined(USB_STRINGS_OVERWRITTEN)
.................... //the offset of the starting location of each string. offset[0] is the start of string 0, offset[1] is the start of string 1, etc.
.................... char USB_STRING_DESC_OFFSET[]={0,4,12};
....................
.................... // Here is where the "CCS" Manufacturer string and "SERIAL DEMO" are stored.
.................... // Strings are saved as unicode.
.................... // These strings are mostly only displayed during the add hardware wizard.
.................... // Once the operating system drivers have been installed it will usually display
.................... // the name from the drivers .INF.
.................... char const USB_STRING_DESC[]={
.................... //string 0
.................... 4, //length of string index
.................... USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
.................... 0x09,0x04, //Microsoft Defined for US-English
.................... //string 1 - manufacturer
.................... 8, //length of string index
.................... USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
.................... 'C',0,
.................... 'C',0,
.................... 'S',0,
.................... //string 2 - product
.................... 24, //length of string index
.................... USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
.................... 'S',0,
.................... 'E',0,
.................... 'R',0,
.................... 'I',0,
.................... 'A',0,
.................... 'L',0,
.................... ' ',0,
.................... 'D',0,
.................... 'E',0,
.................... 'M',0,
.................... 'O',0
.................... };
.................... #endif //!defined(USB_STRINGS_OVERWRITTEN)
....................
.................... #ENDIF
....................
.................... #include <usb.c> //handles usb setup tokens and get descriptor reports
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// usb.c ////
.................... //// ////
.................... //// Standard USB request and token handler code. ////
.................... //// ////
.................... //// This file is part of CCS's PIC USB driver code. See USB.H ////
.................... //// for more documentation and a list of examples. ////
.................... //// ////
.................... //// The majority of this code is called and used by the interrupt ////
.................... //// generated by the hardware level, and therefore it is not meant ////
.................... //// to be called by the user. The functions that are meant to be ////
.................... //// called by the user (init, put packet, get packet, etc) are ////
.................... //// documented in USB.H. ////
.................... //// ////
.................... //// ************************* NOTE ************************** ////
.................... //// This code will not create a multiple configuration device. ////
.................... //// If you wish to create a multiple configuration device then you ////
.................... //// will have to modify these drivers. ////
.................... //// ////
.................... //// ************************* NOTE ************************** ////
.................... //// This code does not support Get_Idle or Set_Idle HID-specific ////
.................... //// requests. These requests are optional. If you want to support ////
.................... //// these requests you must provide the code yourself. See ////
.................... //// usb_isr_tkn_setup_ClassInterface() if you wish to add this ////
.................... //// support. ////
.................... //// ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// ////
.................... //// If you wish to provide your own USB peripheral hardware layer, it ////
.................... //// must must provide the API as described in usb_hw_layer.h. ////
.................... //// ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// ////
.................... //// Version History: ////
.................... //// ////
.................... //// March 5th, 2009: ////
.................... //// Cleanup for Wizard. ////
.................... //// PIC24 Initial release. ////
.................... //// ////
.................... //// Dec 14, 2007: ////
.................... //// usb_kbhit() moved to device driver. ////
.................... //// ////
.................... //// July 13th, 2005: ////
.................... //// usb_puts() packet_size and this_packet_len changed to 16bits. ////
.................... //// usb_gets() len, packet_size and this_packet_len to 16bits. ////
.................... //// ////
.................... //// June 20th, 2005: ////
.................... //// Initial 18fxx5x release. ////
.................... //// usb_kbhit() removed, usb_kbhit() now implemented in hardware ////
.................... //// layer. ////
.................... //// ////
.................... //// May 13th, 2005: ////
.................... //// Beta release, only works with 18Fxx5x hardware layer. ////
.................... //// Now supports multiple interfaces (many defines in descriptors ////
.................... //// will have to be changed, see examples) ////
.................... //// TODO: alot of indexing and length handling for descriptors is ////
.................... //// only 8bit, so make sure all descriptor tables are less than ////
.................... //// 256 bytes long. ////
.................... //// ////
.................... //// Apr 21st, 2005: ////
.................... //// Initial Alpha Release with PIC18Fxx5x support. (ONLY TESTED ////
.................... //// WITH 18F4550) ////
.................... //// usb_puts() doesn't need max packet size as a paremeter, uses ////
.................... //// usb_ep_tx_size[] defined in usb.h ////
.................... //// usb_puts() timeout parameter now in ms, not seconds. ////
.................... //// USB Stack no longer buffers incoming data. If there is data to ////
.................... //// get usb_kbhit(en) will return TRUE and the data will sit in ////
.................... //// the endpoint buffer until you usb_get_packet(), which will ////
.................... //// then free the endpoint buffer for more data. This affects ////
.................... //// routines such as usb_gets() and usb_kbhit(). ////
.................... //// usb_gets() no longer reads buffered data (see above note), ////
.................... //// now it reads multiple packets in the same way usb_puts() ////
.................... //// writes multiple packets ////
.................... //// usb_kbhit() is hardware specific, so has been moved to hardware ////
.................... //// layer. ////
.................... //// ////
.................... //// Nov 11th, 2004: ////
.................... //// No longer includes wrong descriptor header. ////
.................... //// ////
.................... //// June 24th, 2004: ////
.................... //// Optimization and cleanup. ////
.................... //// The following definitions changed: ////
.................... //// USB_EPx_TX_ENABLE and USB_EPx_RX_ENABLE have changed. See usb.h ////
.................... //// USB_CONFIG_DESCRIPTORS[] removed ////
.................... //// USB_CONFIG_DESC_LEN changed to USB_DESC_CONFIG_LEN ////
.................... //// USB_INTERFACE_DESC_LEN changed to USB_DESC_INTERFACE_LEN ////
.................... //// USB_CLASS_DESC_LEN changed to USB_DESC_CLASS_LEN ////
.................... //// USB_ENDPOINT_DESC_LEN changed to USB_DESC_ENDPOINT_LEN ////
.................... //// USB_CONFIG_DESC_KEY changed to USB_DESC_CONFIG_TYPE ////
.................... //// USB_INTERFACE_DESC_KEY changed to USB_DESC_INTERFACE_TYPE ////
.................... //// USB_CLASS_DESC_KEY changed to USB_DESC_CLASS_TYPE ////
.................... //// USB_ENDPOINT_DESC_KEY changed to USB_DESC_ENDPOINT_TYPE ////
.................... //// USB_STRING_X[] arrays removed, see USB_STRING_DESC[] and ////
.................... //// USB_STRING_DESC_OFFSET[] ////
.................... //// dev_req, curr_config, status_device and getdesc_type global ////
.................... //// variables moved into struct USB_stack_status ////
.................... //// ////
.................... //// December 5th, 2003: Fixed a potential bug where descriptors are ////
.................... //// evenly dividable by 8 (MAX_EP0_PACKET_SIZE) ////
.................... //// ////
.................... //// October 15th, 2003: Support for boot protocol added. ////
.................... //// Set USB_HID_BOOT_PROTOCOL to TRUE to support this. ////
.................... //// The array hid_protocol[] saves which protocol mode each ////
.................... //// interface is in. It is your applications job to send ////
.................... //// data that either fit the boot protocol or HID protocol. ////
.................... //// ////
.................... //// May 6th, 2003: Fixed a potential stack overflow using PCM ////
.................... //// ////
.................... //// October 28th, 2002: Problem with usb_puts and timeout fixed. ////
.................... //// ////
.................... //// October 28th, 2002: Typo fixed in get_next_string_character(), ////
.................... //// although it didn't cause any serious problems ////
.................... //// ////
.................... //// October 25th, 2002: Another change to usb_puts() was made to fix ////
.................... //// problems with multiple packet messages ////
.................... //// October 29th, 2002: Fixed a problem with multiple packet string ////
.................... //// descriptors that require a 0 len packet to ////
.................... //// end message. ////
.................... //// ////
.................... //// October 23rd, 2002: usb_puts() will bomb out of error quicker ////
.................... //// ////
.................... //// August 2nd, 2002: Initial Public Release ////
.................... //// ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2005 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS ////
.................... //// C compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, ////
.................... //// reproduction or distribution is permitted without written ////
.................... //// permission. Derivative programs created using this software ////
.................... //// in object code form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
....................
.................... #IFNDEF __USB_DRIVER__
.................... #DEFINE __USB_DRIVER__
....................
.................... #include <usb.h>
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// usb.h ////
.................... //// ////
.................... //// Function protypes, defintions and globals used by CCS USB driver ////
.................... //// ////
.................... //// This file is part of CCS's USB driver code ////
.................... //// ////
.................... //// The following USB examples are provided by CCS: ////
.................... //// ex_usb_mouse.c - A HID Mouse. ////
.................... //// ex_usb_hid.c - A custom application using HID protocol. ////
.................... //// ex_usb_kbmouse.c - A HID Mouse/Keyboard combo using multiple ////
.................... //// interfaces. ////
.................... //// ex_usb_kbmouse2.c - A HID Mouse/Keyboard combo using multiple ////
.................... //// HID Reports. ////
.................... //// ex_usb_scope.c - A digital oscilloscope using a custom ////
.................... //// protocol requiring custom Windows drivers. ////
.................... //// ex_usb_serial.c - ////
.................... //// ex_usb_serial2.c - Two examples of using the CDC driver for ////
.................... //// a virtual COM port. ////
.................... //// ex_usb_bootloader.c - CDC/Virtual COM port bootloader. ////
.................... //// ex_usb_loadmouse.c - A conversion of ex_usb_mouse.c that is ////
.................... //// compatible with ex_usb_mouse.c. ////
.................... //// ////
.................... //// ********************** API ********************* ////
.................... //// ////
.................... //// These are the functions that are meant to be called by the user: ////
.................... //// ////
.................... //// usb_init() - Initializes the USB stack, the USB peripheral and ////
.................... //// attaches the unit to the usb bus. Enables ////
.................... //// interrupts. Will wait in an infinite loop until ////
.................... //// the device enumerates - if you are using ////
.................... //// connection sense or if the processor should run ////
.................... //// even if it's not connected to USB then use ////
.................... //// usb_init_cs() instead. ////
.................... //// ////
.................... //// usb_init_cs() - A smaller usb_init(), does not attach unit ////
.................... //// to usb bus or enable interrupts. Since this does ////
.................... //// not attach to the USB, you must periodically call ////
.................... //// usb_task(). See usb_task() for more information. ////
.................... //// ////
.................... //// usb_task() - If usb_init_cs() was used to initiate the USB ////
.................... //// peripheral, usb_task() should then be called periodically ////
.................... //// to check the connection sense pin. If the connection ////
.................... //// sense pin denotes USB is connected and the USB peripheral ////
.................... //// is not attached, this will attach the USB peripheral ////
.................... //// so the PC can start the enumeration process (and it ////
.................... //// will enable interrupts). If the connection sense pin ////
.................... //// denotes USB is not attached and the USB peripheral is ////
.................... //// running, this will reset the USB peripheral and wait ////
.................... //// for USB to reconnect (and usb_enumerated() will start ////
.................... //// returning FALSE). If connection sense (USB_CON_SENSE_PIN) ////
.................... //// is not defined the usb_task() assumes that USB is always ////
.................... //// connected. ////
.................... //// ////
.................... //// usb_attached() - Returns TRUE if the device is attached to a ////
.................... //// USB cable. A macro that looks at the defined ////
.................... //// connection sense pin. If this returns TRUE ////
.................... //// it does not mean the PC has connected to it, ////
.................... //// you need to use usb_enumerated() to check this. ////
.................... //// ////
.................... //// usb_enumerated() - Returns TRUE if device has been enumerated ////
.................... //// (configured) by host, FALSE if it has not. ////
.................... //// Do not try to use the USB peripheral for ////
.................... //// sending and receiving packets until you ////
.................... //// are enumerated. ////
.................... //// ////
.................... //// usb_wait_for_enumeration() - Sits in an infinte loop until device ////
.................... //// is enumerated. ////
.................... //// ////
.................... //// usb_tbe(endpoint) - Returns TRUE if the endpoint transmit buffer ////
.................... //// is free and ready to accept a new packet for transmission. ////
.................... //// ////
.................... //// usb_put_packet(endpoint, ptr, len, tgl) - Sends one packet to the ////
.................... //// host. If you need to send a message that ////
.................... //// spans more than one packet then use ////
.................... //// usb_puts(). Fore more detailed documentation ////
.................... //// see usb_hw_layer.h ////
.................... //// ////
.................... //// usb_puts(endpoint, ptr, len, timeout) - Sends a multiple packet ////
.................... //// message to the host. If you only need to send one packet, ////
.................... //// it is more effecient to use usb_put_packet(). This is ////
.................... //// documented in more detail above the prototype in USB.H. ////
.................... //// ////
.................... //// usb_kbhit(endpoint) - Returns true if OUT endpoint contains data ////
.................... //// from host. This will remain TRUE until ////
.................... //// usb_put_packet() or usb_flush_out() used. ////
.................... //// This function will return an invalid response ////
.................... //// if specified endpoint is not enabled for ////
.................... //// receiving data. ////
.................... //// ////
.................... //// len = usb_get_packet(endpoint, ptr, max) - Gets one packet that ////
.................... //// from the host/PC. usb_kbhit() must return TRUE before you ////
.................... //// call this routine or your data may not be valid. This ////
.................... //// only receives one packet, if you are trying to receive a ////
.................... //// multi-packet message use usb_gets(). For more detailed ////
.................... //// documentation see usb_hw_layer.h. ////
.................... //// ////
.................... //// len = usb_gets(endpoint, ptr, max, timeout) - Gets multiple ////
.................... //// packets from the host, you would use this instead ////
.................... //// of usb_get_packet() if you wanted to handle multi-packet ////
.................... //// messages. This is documented in more detail above the ////
.................... //// prototype in USB.H. ////
.................... //// ////
.................... //// ////
.................... //// ********* DEFINITIONS / CONFIGURATION ********** ////
.................... //// ////
.................... //// The following definitions are declared here, but can be ////
.................... //// overwritten in your code. Unless needed otherwise, leave ////
.................... //// to default value. If confused about a definition read the ////
.................... //// comments at each defintion ////
.................... //// ////
.................... //// USB_HID_IDLE (TRUE) - Set to TRUE if your device supports ////
.................... //// Set_Idle HID class request. Set to ////
.................... //// False if you do not (device will ////
.................... //// send a Wrong-state if computer ////
.................... //// sends a Set_Idle / Get_Idle command) ////
.................... //// NOTE: If you set to TRUE you must ////
.................... //// provide your own code. See ////
.................... //// usb_isr_tkn_setup_ClassInterface() in ////
.................... //// usb.c ////
.................... //// ////
.................... //// USB_HID_BOOT_PROTOCOL (FALSE) - Set to TRUE if your device supports ////
.................... //// Set_Protocl HID class request. Set to ////
.................... //// False if you do not (device will ////
.................... //// send a Wrong-state if computer ////
.................... //// sends a Set_Protocl / Get_Protocol ////
.................... //// command). ////
.................... //// NOTE: If you set to TRUE you must ////
.................... //// provide your own code in the ////
.................... //// application that properly send boot ////
.................... //// or HID packets. ////
.................... //// ////
.................... //// USB_MAX_EP0_PACKET_LENGTH (8) - Max Packet size for Endpoint 0. ////
.................... //// The hardware level driver (ex ////
.................... //// pic18_usb.h will define this value if ////
.................... //// not already overwritten). Increasing ////
.................... //// this size will speed up the ////
.................... //// enumeration process. ////
.................... //// ////
.................... //// USB_EPx_RX_ENABLE (USB_ENABLE_DISABLED) - Where x is the ////
.................... //// endpoint number. Change this define ////
.................... //// to specify what kind of transfer method ////
.................... //// this RX (PC to device) endpoint uses. ////
.................... //// Here is the list of valid transfer methods: ////
.................... //// USB_ENABLE_CONTROL ////
.................... //// USB_ENABLE_ISOCHRONOUS ////
.................... //// USB_ENABLE_BULK ////
.................... //// USB_ENABLE_INTERRUPT ////
.................... //// USB_ENABLE_DISABLED ////
.................... //// Don't forget that you must specify the ////
.................... //// transfer method properly in your endpoint ////
.................... //// descriptor, too. ////
.................... //// ////
.................... //// USB_EPx_RX_SIZE (0) - For some hardware it is important to know ////
.................... //// how much memory to reserve for receiving ////
.................... //// packets. ////
.................... //// ////
.................... //// *** NOTE *** You must have both USB_EPx_RX_ENABLE defined and ////
.................... //// USB_EPx_RX_SIZE defined (non 0) to enable a RX ////
.................... //// endpoint. ////
.................... //// *** NOTE *** Endpoint 0 is always enabled. ////
.................... //// ////
.................... //// USB_EPx_TX_ENABLE (USB_ENABLE_DISABLED) - Where x is the ////
.................... //// endpoint number. Change this define ////
.................... //// to specify what kind of transfer method ////
.................... //// this TX (device to PC) endpoint uses. ////
.................... //// Here is the list of valid transfer methods: ////
.................... //// USB_ENABLE_CONTROL ////
.................... //// USB_ENABLE_ISOCHRONOUS ////
.................... //// USB_ENABLE_BULK ////
.................... //// USB_ENABLE_INTERRUPT ////
.................... //// USB_ENABLE_DISABLED ////
.................... //// Don't forget that you must specify the ////
.................... //// transfer method properly in your endpoint ////
.................... //// descriptor, too. ////
.................... //// ////
.................... //// USB_EPx_TX_SIZE (0) - For some hardware it is important to know ////
.................... //// how much memory to reserve for transmitting ////
.................... //// packets. ////
.................... //// ////
.................... //// *** NOTE *** You must have both USB_EPx_TX_ENABLE defined and ////
.................... //// USB_EPx_TX_SIZE defined (non 0) to enable a TX ////
.................... //// endpoint. ////
.................... //// ////
.................... //// ////
.................... //// USB_HID_DEVICE (TRUE) - HID devices require extra code to handle ////
.................... //// HID requests. You can disable to save ////
.................... //// ROM space if you are not using a HID ////
.................... //// device. If you are not using a HID ////
.................... //// device you must provide your own O/S ////
.................... //// (Windows) driver. ////
.................... //// ////
.................... //// The other definitions should not be changed. ////
.................... //// ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// ////
.................... //// Version History: ////
.................... //// ////
.................... //// March 5th, 2009: ////
.................... //// Cleanup for Wizard. ////
.................... //// PIC24 Initial release. ////
.................... //// ////
.................... //// July 13th, 2005: ////
.................... //// usb_ep_tx_size[] and usb_ep_rx_size[] changed to 16bits ////
.................... //// ////
.................... //// June 20th, 2005: ////
.................... //// Initial 18fxx5x release ////
.................... //// ////
.................... //// May 13th, 2005: ////
.................... //// Beta release, only works with 18Fxx5x hardware layer. ////
.................... //// Now supports multiple interfaces (many defines in descriptors ////
.................... //// will have to be changed, see examples) ////
.................... //// ////
.................... //// Mar 21st, 2005: ////
.................... //// Initial Alpha Release with PIC18Fxx5x support. (ONLY TESTED ////
.................... //// WITH 18F4550) ////
.................... //// usb_gets() and usb_puts() changed (see usb.c) ////
.................... //// ////
.................... //// June 24th, 2004: ////
.................... //// Optimization and cleanup. ////
.................... //// The following definitions changed: ////
.................... //// USB_EPx_TX_ENABLE and USB_EPx_RX_ENABLE have changed. See usb.h ////
.................... //// USB_CONFIG_DESCRIPTORS[] removed ////
.................... //// USB_CONFIG_DESC_LEN changed to USB_DESC_CONFIG_LEN ////
.................... //// USB_INTERFACE_DESC_LEN changed to USB_DESC_INTERFACE_LEN ////
.................... //// USB_CLASS_DESC_LEN changed to USB_DESC_CLASS_LEN ////
.................... //// USB_ENDPOINT_DESC_LEN changed to USB_DESC_ENDPOINT_LEN ////
.................... //// USB_CONFIG_DESC_KEY changed to USB_DESC_CONFIG_TYPE ////
.................... //// USB_INTERFACE_DESC_KEY changed to USB_DESC_INTERFACE_TYPE ////
.................... //// USB_CLASS_DESC_KEY changed to USB_DESC_CLASS_TYPE ////
.................... //// USB_ENDPOINT_DESC_KEY changed to USB_DESC_ENDPOINT_TYPE ////
.................... //// USB_STRING_X[] arrays removed, see USB_STRING_DESC[] and ////
.................... //// USB_STRING_DESC_OFFSET[] ////
.................... //// dev_req, curr_config, status_device and getdesc_type global ////
.................... //// variables moved into struct USB_stack_status ////
.................... //// ////
.................... //// October 15th, 2003: Support for boot protocol added. ////
.................... //// Set USB_HID_BOOT_PROTOCOL to TRUE to support this. ////
.................... //// The array hid_protocol[] saves which protocol mode each ////
.................... //// interface is in. It is your applications job to send ////
.................... //// data that either fit the boot protocol or HID protocol. ////
.................... //// ////
.................... //// May 6th, 2003: Fixed a potential stack overflow using PCM ////
.................... //// ////
.................... //// October 29th, 2002: New definition added to USB_STATES ////
.................... //// ////
.................... //// August 2nd, 2002: Initial Public Release ////
.................... //// ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2009 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS ////
.................... //// C compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, ////
.................... //// reproduction or distribution is permitted without written ////
.................... //// permission. Derivative programs created using this software ////
.................... //// in object code form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
....................
.................... #IFNDEF __USB_PROTOTYPES__
.................... #DEFINE __USB_PROTOTYPES__
....................
.................... //// CONFIGURATION ////////////////////////////////////////////////////////////
....................
.................... #ifndef USB_CON_SENSE_PIN
.................... #define USB_CON_SENSE_PIN 0
.................... #endif
....................
.................... #IFNDEF USB_HID_BOOT_PROTOCOL
.................... #DEFINE USB_HID_BOOT_PROTOCOL FALSE
.................... #ENDIF
....................
.................... #IFNDEF USB_HID_IDLE
.................... #DEFINE USB_HID_IDLE FALSE
.................... #ENDIF
....................
.................... //should the compiler add the extra HID handler code? Defaults to yes.
.................... #IFNDEF USB_HID_DEVICE
.................... #DEFINE USB_HID_DEVICE TRUE
.................... #ENDIF
....................
.................... #IFNDEF USB_CDC_DEVICE
.................... #DEFINE USB_CDC_DEVICE FALSE
.................... #ENDIF
....................
.................... //set to false to opt for less RAM, true to opt for less ROM
.................... #ifndef USB_OPT_FOR_ROM
.................... #define USB_OPT_FOR_ROM TRUE
.................... #endif
....................
.................... #IFNDEF USB_MAX_EP0_PACKET_LENGTH
.................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 8
.................... #ENDIF
....................
....................
.................... ////// USER-LEVEL API /////////////////////////////////////////////////////////
....................
.................... /**************************************************************
.................... /* usb_enumerated()
.................... /*
.................... /* Input: Global variable USB_Curr_Config
.................... /* Returns: Returns a 1 if device is configured / enumerated,
.................... /* Returns a 0 if device is un-configured / not enumerated.
.................... /*
.................... /* Summary: See API section of USB.H for more documentation.
.................... /***************************************************************/
.................... int1 usb_enumerated(void);
....................
.................... /**************************************************************
.................... /* usb_wait_for_enumeration()
.................... /*
.................... /* Input: Global variable USB_Curr_Config
.................... /*
.................... /* Summary: Waits in-definately until device is configured / enumerated.
.................... /* See API section of USB.H for more information.
.................... /***************************************************************/
.................... void usb_wait_for_enumeration(void);
....................
.................... /****************************************************************************
.................... /* usb_gets(endpoint, ptr, max, timeout)
.................... /*
.................... /* Input: endpoint - endpoint to get data from
.................... /* ptr - place / array to store data to
.................... /* max - max amount of data to get from USB and store into ptr
.................... /* timeout - time in milliseconds, for each packet, to wait before
.................... /* timeout. set to 0 for no timeout.
.................... /*
.................... /* Output: Amount of data returned. It may be less than max.
.................... /*
.................... /* Summary: Gets data from the host. Will get multiple-packet messages
.................... /* and finish when either it receives a 0-len packet or a packet
.................... /* of less size than maximum.
.................... /*
.................... /*****************************************************************************/
.................... unsigned int16 usb_gets(int8 endpoint, int8 * ptr, unsigned int16 max, unsigned int16 timeout);
....................
.................... /****************************************************************************
.................... /* usb_puts()
.................... /*
.................... /* Inputs: endpoint - endpoint to send data out
.................... /* ptr - points to array of data to send
.................... /* len - amount of data to send
.................... /* timeout - time in milli-seconds, for each packet, to wait before
.................... /* timeout. set to 0 for no timeout.
.................... /*
.................... /* Outputs: Returns TRUE if message sent succesfully, FALSE if it was not
.................... /* sent before timeout period expired.
.................... /*
.................... /* Summary: Used for sending multiple packets of data as one message. This
.................... /* function can still be used to send messages consiting of only one
.................... /* packet. See usb_put_packet() documentation for the rules about when
.................... /* multiple packet messages or 0-lenght packets are needed.
.................... /*
.................... /*****************************************************************************/
.................... int1 usb_puts(int8 endpoint, int8 * ptr, unsigned int16 len, unsigned int8 timeout);
....................
.................... /******************************************************************************
.................... /* usb_attached()
.................... /*
.................... /* Summary: Returns TRUE if the device is attached to a USB cable.
.................... /* See the API section of USB.H for more documentation.
.................... /*
.................... /*****************************************************************************/
.................... #if USB_CON_SENSE_PIN
.................... #define usb_attached() input(USB_CON_SENSE_PIN)
.................... #else
.................... #define usb_attached() TRUE
.................... #endif
....................
.................... ////// END USER-LEVEL API /////////////////////////////////////////////////////
....................
....................
.................... ////// STACK-LEVEL API USED BY HW DRIVERS ////////////////////////////////////
....................
.................... enum USB_STATES {GET_DESCRIPTOR=1,SET_ADDRESS=2,NONE=0};
....................
.................... enum USB_GETDESC_TYPES {USB_GETDESC_CONFIG_TYPE=0,USB_GETDESC_HIDREPORT_TYPE=1,USB_GETDESC_STRING_TYPE=2,USB_GETDESC_DEVICE_TYPE=3};
....................
.................... #if USB_OPT_FOR_ROM
.................... typedef struct {
.................... USB_STATES dev_req; //what did the last setup token set us up to do?. init at none
.................... int curr_config; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS)
.................... int status_device; //Holds our state for Set_Feature and Clear_Feature
.................... USB_GETDESC_TYPES getdesc_type; //which get_descriptor() we are handling
.................... } TYPE_USB_STACK_STATUS;
.................... #else
.................... typedef struct {
.................... USB_STATES dev_req:2; //what did the last setup token set us up to do?. init at none
.................... int Curr_config:2; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS)
.................... int status_device:2; //Holds our state for Set_Feature and Clear_Feature
.................... USB_GETDESC_TYPES getdesc_type:2; //which get_descriptor() we are handling
.................... } TYPE_USB_STACK_STATUS;
.................... #endif
....................
.................... extern TYPE_USB_STACK_STATUS USB_stack_status;
....................
.................... /**************************************************************
.................... /* usb_token_reset()
.................... /*
.................... /* Output: No output (but many global registers are modified)
.................... /*
.................... /* Summary: Resets the token handler to initial (unconfigured) state.
.................... /***************************************************************/
.................... void usb_token_reset(void);
....................
.................... /**************************************************************
.................... /* usb_isr_tok_setup_dne()
.................... /*
.................... /* Input: usb_ep0_rx_buffer[] contains the the setup packet.
.................... /*
.................... /* Output: None (many globals are changed)
.................... /*
.................... /* Summary: This function is that handles the setup token.
.................... /* We must handle all relevant requests, such as Set_Configuration,
.................... /* Get_Descriptor, etc.
.................... /*
.................... /* usb_ep0_rx_buffer[] contains setup data packet, which has the
.................... /* following records:
.................... /* -------------------------------------------------------------------------------------------
.................... /* usb_ep0_rx_buffer[ 0 ]=bmRequestType; Where the setup packet goes
.................... /* bit7 (0) host-to-device
.................... /* (1) device-to-host
.................... /* bit6-5 (00) usb standard request;
.................... /* (01) class request;
.................... /* (10) vendor request
.................... /* (11) reserved
.................... /* bit4-0 (0000) device
.................... /* (0001) interface
.................... /* (0010) endpoint
.................... /* (0011) other element
.................... /* (0100) to (1111) reserved
.................... /* usb_ep0_rx_buffer[ 1 ]=bRequest ; the request
.................... /* usb_ep0_rx_buffer[2,3]=wValue ; a value which corresponds to request
.................... /* usb_ep0_rx_buffer[4,5]=wIndex ; could correspond to interface or endpoint...
.................... /* usb_ep0_rx_buffer[6,7]=wLength ; number of bytes in next data packet;
.................... /* for host-to-device, this exactly how many bytes in data packet.
.................... /* for device-to-host, this is the maximum bytes that can fit one packet.
.................... /***************************************************************/
.................... void usb_isr_tok_setup_dne(void);
....................
.................... /**************************************************************
.................... /* usb_isr_tok_out_dne()
.................... /*
.................... /* Input: endpoint contains which endpoint we are receiving data (0..15)
.................... /*
.................... /* Summary: Processes out tokens (out is respective of the host, so actualy
.................... /* incoming to the pic), but not out setup tokens. Normally when
.................... /* data is received it is left in the buffer (user would use
.................... /* usb_kbhit() and usb_get_packet() to receive data), but certain
.................... /* libraries (like CDC) have to answer setup packets.
.................... /*
.................... /***************************************************************/
.................... void usb_isr_tok_out_dne(int8 endpoint);
....................
.................... /**************************************************************
.................... /* usb_isr_tok_in_dne(endpoint)
.................... /*
.................... /* Input: endpoint - which endpoint we are processing a setup token.
.................... /*
.................... /* Summary: This handles an IN packet (HOST <- PIC). For endpoint 0, this
.................... /* is usually to setup a response packet to a setup packet. Endpoints 1..15
.................... /* are generally ignored, and the user has to use usb_tbe() to determine if
.................... /* if the buffer is ready for a new transmit packet (there are special cases,
.................... /* like CDC which handles the CDC protocl).
.................... /*
.................... /***************************************************************/
.................... void usb_isr_tok_in_dne(int8 endpoint);
....................
.................... ////// END STACK-LEVEL API USED BY HW DRIVERS /////////////////////////////////
....................
....................
.................... //CCS only supports one configuration at this time
.................... #DEFINE USB_NUM_CONFIGURATIONS 1 //DO NOT CHANGE
....................
.................... //PID values for tokens (see page 48 of USB Complete ed.1)
.................... #define PID_IN 0x09 //device to host transactions
.................... #define PID_OUT 0x01 //host to device transactions
.................... #define PID_SETUP 0x0D //host to device setup transaction
.................... #define PID_ACK 0x02 //receiver accepts error-free data packet
.................... #define PID_DATA0 0x03 //data packet with even sync bit
.................... #define PID_SOF 0x05 //start of framer marker and frame number
.................... #define PID_NAK 0x0A //receiver can't accept data or sender cant send data or has no data to transmit
.................... #define PID_DATA1 0x0B //data packet with odd sync bit
.................... #define PID_PRE 0x0C //preamble issued by host. enables downstream traffic to low-speed device
.................... #define PID_STALL 0x0E //a control request isnt supported or the endpoint is halted
....................
.................... //Key which identifies descritpors
.................... #DEFINE USB_DESC_DEVICE_TYPE 0x01 //#DEFINE USB_DEVICE_DESC_KEY 0x01
.................... #DEFINE USB_DESC_CONFIG_TYPE 0x02 //#DEFINE USB_CONFIG_DESC_KEY 0x02
.................... #DEFINE USB_DESC_STRING_TYPE 0x03 //#DEFINE USB_STRING_DESC_KEY 0x03
.................... #DEFINE USB_DESC_INTERFACE_TYPE 0x04 //#DEFINE USB_INTERFACE_DESC_KEY 0x04
.................... #DEFINE USB_DESC_ENDPOINT_TYPE 0x05 //#DEFINE USB_ENDPOINT_DESC_KEY 0x05
.................... #DEFINE USB_DESC_CLASS_TYPE 0x21 //#DEFINE USB_CLASS_DESC_KEY 0x21
.................... #DEFINE USB_DESC_HIDREPORT_TYPE 0x22
....................
.................... //The length of each descriptor
.................... #DEFINE USB_DESC_DEVICE_LEN 18 //#DEFINE USB_DEVICE_DESC_LEN 18
.................... #DEFINE USB_DESC_CONFIG_LEN 9 //#DEFINE USB_CONFIG_DESC_LEN 9
.................... #DEFINE USB_DESC_INTERFACE_LEN 9 //#DEFINE USB_INTERFACE_DESC_LEN 9
.................... #DEFINE USB_DESC_CLASS_LEN 9 //#DEFINE USB_CLASS_DESC_LEN 9
.................... #DEFINE USB_DESC_ENDPOINT_LEN 7 //#DEFINE USB_ENDPOINT_DESC_LEN 7
....................
.................... //Standard USB Setup bRequest Codes
.................... #define USB_STANDARD_REQUEST_GET_STATUS 0x00
.................... #define USB_STANDARD_REQUEST_CLEAR_FEATURE 0x01
.................... #define USB_STANDARD_REQUEST_SET_FEATURE 0x03
.................... #define USB_STANDARD_REQUEST_SET_ADDRESS 0x05
.................... #define USB_STANDARD_REQUEST_GET_DESCRIPTOR 0x06
.................... #define USB_STANDARD_REQUEST_SET_DESCRIPTOR 0x07
.................... #define USB_STANDARD_REQUEST_GET_CONFIGURATION 0x08
.................... #define USB_STANDARD_REQUEST_SET_CONFIGURATION 0x09
.................... #define USB_STANDARD_REQUEST_GET_INTERFACE 0x0A
.................... #define USB_STANDARD_REQUEST_SET_INTERFACE 0x0B
.................... #define USB_STANDARD_REQUEST_SYNCH_FRAME 0x0C
....................
.................... //HID Class Setup bRequest Codes
.................... #define USB_HID_REQUEST_GET_REPORT 0x01
.................... #define USB_HID_REQUEST_GET_IDLE 0x02
.................... #define USB_HID_REQUEST_GET_PROTOCOL 0x03
.................... #define USB_HID_REQUEST_SET_REPORT 0x09
.................... #define USB_HID_REQUEST_SET_IDLE 0x0A
.................... #define USB_HID_REQUEST_SET_PROTOCOL 0x0B
....................
.................... //types of endpoints as defined in the descriptor
.................... #define USB_ENDPOINT_TYPE_CONTROL 0x00
.................... #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
.................... #define USB_ENDPOINT_TYPE_BULK 0x02
.................... #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
....................
.................... //types of endpoints used internally in this api
.................... #define USB_ENABLE_DISABLED -1
.................... #define USB_ENABLE_BULK USB_ENDPOINT_TYPE_BULK
.................... #define USB_ENABLE_ISOCHRONOUS USB_ENDPOINT_TYPE_ISOCHRONOUS
.................... #define USB_ENABLE_INTERRUPT USB_ENDPOINT_TYPE_INTERRUPT
.................... #define USB_ENABLE_CONTROL USB_ENDPOINT_TYPE_CONTROL
....................
....................
.................... //*** ENABLE RX ENDPOINTS AND BUFFERS
....................
.................... //--------- endpoint 0 defines ----------
.................... #define USB_EP0_TX_ENABLE USB_ENABLE_CONTROL
.................... #define USB_EP0_RX_ENABLE USB_ENABLE_CONTROL
.................... #define USB_EP0_RX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8
.................... #define USB_EP0_TX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8
....................
.................... //--------- endpoint 1 defines ----------
.................... #ifndef USB_EP1_TX_ENABLE
.................... #define USB_EP1_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP1_RX_ENABLE
.................... #define USB_EP1_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP1_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP1_RX_SIZE
.................... #undef USB_EP1_RX_SIZE
.................... #endif
.................... #define USB_EP1_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP1_RX_SIZE
.................... #error You enabled EP1 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP1_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP1_TX_SIZE
.................... #undef USB_EP1_TX_SIZE
.................... #endif
.................... #define USB_EP1_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP1_TX_SIZE
.................... #error You enabled EP1 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 2 defines ----------
.................... #ifndef USB_EP2_TX_ENABLE
.................... #define USB_EP2_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP2_RX_ENABLE
.................... #define USB_EP2_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP2_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP2_RX_SIZE
.................... #undef USB_EP2_RX_SIZE
.................... #endif
.................... #define USB_EP2_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP2_RX_SIZE
.................... #error You enabled EP2 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP2_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP2_TX_SIZE
.................... #undef USB_EP2_TX_SIZE
.................... #endif
.................... #define USB_EP2_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP2_TX_SIZE
.................... #error You enabled EP2 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 3 defines ----------
.................... #ifndef USB_EP3_TX_ENABLE
.................... #define USB_EP3_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP3_RX_ENABLE
.................... #define USB_EP3_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP3_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP3_RX_SIZE
.................... #undef USB_EP3_RX_SIZE
.................... #endif
.................... #define USB_EP3_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP3_RX_SIZE
.................... #error You enabled EP3 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP3_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP3_TX_SIZE
.................... #undef USB_EP3_TX_SIZE
.................... #endif
.................... #define USB_EP3_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP3_TX_SIZE
.................... #error You enabled EP3 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 4 defines ----------
.................... #ifndef USB_EP4_TX_ENABLE
.................... #define USB_EP4_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP4_RX_ENABLE
.................... #define USB_EP4_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP4_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP4_RX_SIZE
.................... #undef USB_EP4_RX_SIZE
.................... #endif
.................... #define USB_EP4_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP4_RX_SIZE
.................... #error You enabled EP4 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP4_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP4_TX_SIZE
.................... #undef USB_EP4_TX_SIZE
.................... #endif
.................... #define USB_EP4_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP4_TX_SIZE
.................... #error You enabled EP4 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 5 defines ----------
.................... #ifndef USB_EP5_TX_ENABLE
.................... #define USB_EP5_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP5_RX_ENABLE
.................... #define USB_EP5_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP5_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP5_RX_SIZE
.................... #undef USB_EP5_RX_SIZE
.................... #endif
.................... #define USB_EP5_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP5_RX_SIZE
.................... #error You enabled EP5 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP5_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP5_TX_SIZE
.................... #undef USB_EP5_TX_SIZE
.................... #endif
.................... #define USB_EP5_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP5_TX_SIZE
.................... #error You enabled EP5 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 6 defines ----------
.................... #ifndef USB_EP6_TX_ENABLE
.................... #define USB_EP6_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP6_RX_ENABLE
.................... #define USB_EP6_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP6_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP6_RX_SIZE
.................... #undef USB_EP6_RX_SIZE
.................... #endif
.................... #define USB_EP6_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP6_RX_SIZE
.................... #error You enabled EP6 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP6_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP6_TX_SIZE
.................... #undef USB_EP6_TX_SIZE
.................... #endif
.................... #define USB_EP6_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP6_TX_SIZE
.................... #error You enabled EP6 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 7 defines ----------
.................... #ifndef USB_EP7_TX_ENABLE
.................... #define USB_EP7_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP7_RX_ENABLE
.................... #define USB_EP7_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP7_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP7_RX_SIZE
.................... #undef USB_EP7_RX_SIZE
.................... #endif
.................... #define USB_EP7_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP7_RX_SIZE
.................... #error You enabled EP7 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP7_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP7_TX_SIZE
.................... #undef USB_EP7_TX_SIZE
.................... #endif
.................... #define USB_EP7_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP7_TX_SIZE
.................... #error You enabled EP7 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 8 defines ----------
.................... #ifndef USB_EP8_TX_ENABLE
.................... #define USB_EP8_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP8_RX_ENABLE
.................... #define USB_EP8_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP8_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP8_RX_SIZE
.................... #undef USB_EP8_RX_SIZE
.................... #endif
.................... #define USB_EP8_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP8_RX_SIZE
.................... #error You enabled EP8 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP8_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP8_TX_SIZE
.................... #undef USB_EP8_TX_SIZE
.................... #endif
.................... #define USB_EP8_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP8_TX_SIZE
.................... #error You enabled EP8 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 9 defines ----------
.................... #ifndef USB_EP9_TX_ENABLE
.................... #define USB_EP9_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP9_RX_ENABLE
.................... #define USB_EP9_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP9_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP9_RX_SIZE
.................... #undef USB_EP9_RX_SIZE
.................... #endif
.................... #define USB_EP9_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP9_RX_SIZE
.................... #error You enabled EP9 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP9_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP9_TX_SIZE
.................... #undef USB_EP9_TX_SIZE
.................... #endif
.................... #define USB_EP9_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP9_TX_SIZE
.................... #error You enabled EP9 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 10 defines ----------
.................... #ifndef USB_EP10_TX_ENABLE
.................... #define USB_EP10_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP10_RX_ENABLE
.................... #define USB_EP10_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP10_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP10_RX_SIZE
.................... #undef USB_EP10_RX_SIZE
.................... #endif
.................... #define USB_EP10_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP10_RX_SIZE
.................... #error You enabled EP10 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP10_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP10_TX_SIZE
.................... #undef USB_EP10_TX_SIZE
.................... #endif
.................... #define USB_EP10_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP10_TX_SIZE
.................... #error You enabled EP10 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 11 defines ----------
.................... #ifndef USB_EP11_TX_ENABLE
.................... #define USB_EP11_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP11_RX_ENABLE
.................... #define USB_EP11_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP11_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP11_RX_SIZE
.................... #undef USB_EP11_RX_SIZE
.................... #endif
.................... #define USB_EP11_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP11_RX_SIZE
.................... #error You enabled EP11 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP11_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP11_TX_SIZE
.................... #undef USB_EP11_TX_SIZE
.................... #endif
.................... #define USB_EP11_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP11_TX_SIZE
.................... #error You enabled EP11 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 12 defines ----------
.................... #ifndef USB_EP12_TX_ENABLE
.................... #define USB_EP12_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP12_RX_ENABLE
.................... #define USB_EP12_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP12_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP12_RX_SIZE
.................... #undef USB_EP12_RX_SIZE
.................... #endif
.................... #define USB_EP12_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP12_RX_SIZE
.................... #error You enabled EP12 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP12_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP12_TX_SIZE
.................... #undef USB_EP12_TX_SIZE
.................... #endif
.................... #define USB_EP12_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP12_TX_SIZE
.................... #error You enabled EP12 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 13 defines ----------
.................... #ifndef USB_EP13_TX_ENABLE
.................... #define USB_EP13_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP13_RX_ENABLE
.................... #define USB_EP13_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP13_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP13_RX_SIZE
.................... #undef USB_EP13_RX_SIZE
.................... #endif
.................... #define USB_EP13_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP13_RX_SIZE
.................... #error You enabled EP13 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP13_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP13_TX_SIZE
.................... #undef USB_EP13_TX_SIZE
.................... #endif
.................... #define USB_EP13_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP13_TX_SIZE
.................... #error You enabled EP13 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 14 defines ----------
.................... #ifndef USB_EP14_TX_ENABLE
.................... #define USB_EP14_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP14_RX_ENABLE
.................... #define USB_EP14_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP14_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP14_RX_SIZE
.................... #undef USB_EP14_RX_SIZE
.................... #endif
.................... #define USB_EP14_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP14_RX_SIZE
.................... #error You enabled EP14 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP14_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP14_TX_SIZE
.................... #undef USB_EP14_TX_SIZE
.................... #endif
.................... #define USB_EP14_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP14_TX_SIZE
.................... #error You enabled EP14 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 15 defines ----------
.................... #ifndef USB_EP15_TX_ENABLE
.................... #define USB_EP15_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP15_RX_ENABLE
.................... #define USB_EP15_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP15_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP15_RX_SIZE
.................... #undef USB_EP15_RX_SIZE
.................... #endif
.................... #define USB_EP15_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP15_RX_SIZE
.................... #error You enabled EP15 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP15_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP15_TX_SIZE
.................... #undef USB_EP15_TX_SIZE
.................... #endif
.................... #define USB_EP15_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP15_TX_SIZE
.................... #error You enabled EP15 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... const int8 usb_ep_tx_type[16]={
.................... USB_EP0_TX_ENABLE, USB_EP1_TX_ENABLE, USB_EP2_TX_ENABLE,
.................... USB_EP3_TX_ENABLE, USB_EP4_TX_ENABLE, USB_EP5_TX_ENABLE,
.................... USB_EP6_TX_ENABLE, USB_EP7_TX_ENABLE, USB_EP8_TX_ENABLE,
.................... USB_EP9_TX_ENABLE, USB_EP10_TX_ENABLE, USB_EP11_TX_ENABLE,
.................... USB_EP12_TX_ENABLE, USB_EP13_TX_ENABLE, USB_EP14_TX_ENABLE,
.................... USB_EP15_TX_ENABLE
.................... };
....................
.................... const int8 usb_ep_rx_type[16]={
.................... USB_EP0_RX_ENABLE, USB_EP1_RX_ENABLE, USB_EP2_RX_ENABLE,
.................... USB_EP3_RX_ENABLE, USB_EP4_RX_ENABLE, USB_EP5_RX_ENABLE,
.................... USB_EP6_RX_ENABLE, USB_EP7_RX_ENABLE, USB_EP8_RX_ENABLE,
.................... USB_EP9_RX_ENABLE, USB_EP10_RX_ENABLE, USB_EP11_RX_ENABLE,
.................... USB_EP12_RX_ENABLE, USB_EP13_RX_ENABLE, USB_EP14_RX_ENABLE,
.................... USB_EP15_RX_ENABLE
.................... };
....................
.................... const unsigned int16 usb_ep_tx_size[16]={
.................... USB_EP0_TX_SIZE, USB_EP1_TX_SIZE, USB_EP2_TX_SIZE,
.................... USB_EP3_TX_SIZE, USB_EP4_TX_SIZE, USB_EP5_TX_SIZE,
.................... USB_EP6_TX_SIZE, USB_EP7_TX_SIZE, USB_EP8_TX_SIZE,
.................... USB_EP9_TX_SIZE, USB_EP10_TX_SIZE, USB_EP11_TX_SIZE,
.................... USB_EP12_TX_SIZE, USB_EP13_TX_SIZE, USB_EP14_TX_SIZE,
.................... USB_EP15_TX_SIZE
.................... };
....................
.................... const unsigned int16 usb_ep_rx_size[16]={
.................... USB_EP0_RX_SIZE, USB_EP1_RX_SIZE, USB_EP2_RX_SIZE,
.................... USB_EP3_RX_SIZE, USB_EP4_RX_SIZE, USB_EP5_RX_SIZE,
.................... USB_EP6_RX_SIZE, USB_EP7_RX_SIZE, USB_EP8_RX_SIZE,
.................... USB_EP9_RX_SIZE, USB_EP10_RX_SIZE, USB_EP11_RX_SIZE,
.................... USB_EP12_RX_SIZE, USB_EP13_RX_SIZE, USB_EP14_RX_SIZE,
.................... USB_EP15_RX_SIZE
.................... };
....................
.................... #ENDIF
....................
....................
.................... #if defined(__PIC16_USB_H__)
.................... #include <pic_usb.c>
.................... #endif
....................
.................... #if defined(__PIC18_USB_H__)
.................... #include <pic18_usb.c>
.................... /////////////////////////////////////////////////////////////////////////
.................... //// pic18_usb.c ////
.................... //// ////
.................... //// Hardware layer for CCS's USB library. See pic18_usb.h more ////
.................... //// documentation about the PIC18 hardware layer. ////
.................... //// ////
.................... //// This file is part of CCS's PIC USB driver code. See USB.H ////
.................... //// for more documentation and a list of examples. ////
.................... //// ////
.................... /////////////////////////////////////////////////////////////////////////
.................... //// ////
.................... //// Version History: ////
.................... //// ////
.................... //// March 5th, 2009: ////
.................... //// 18F14K50 family added. ////
.................... //// Cleanup for Wizard. ////
.................... //// PIC24 Initial release. ////
.................... //// ////
.................... //// Nov 3rd, 2008: ////
.................... //// * 4553 family added. ////
.................... //// ////
.................... //// Dec 18, 2007: ////
.................... //// * usb_kbhit() moved to device driver. ////
.................... //// * USB Token handler changed to workaround a flaw in the USB ////
.................... //// peripheral to prevent the USB peripheral from ////
.................... //// inadvertantly STALLing the endpoint. Happened most often ////
.................... //// in bulk demo applications, especially CDC. ////
.................... //// ////
.................... //// 11-6-07: Fixed a bug where usb_data_buffer[] was reserving ////
.................... //// too much RAM. ////
.................... //// USB_MAX_EP0_PACKET_LENGTH value can be overwritten. ////
.................... //// For the 18F4450/2450 family this should be 8 ////
.................... //// because of limited RAM. Reducing this value ////
.................... //// frees RAM for application. ////
.................... //// Based upon which endpoints have been configured for ////
.................... //// use, will free up unused USB data RAM for ////
.................... //// application dynamically. This should free up ////
.................... //// at least 128 bytes of RAM. ////
.................... //// CDC now fits on a 18F4450/2450 ////
.................... //// ////
.................... //// 09-19-07: Fixed problems with 18F4450 family. ////
.................... //// ////
.................... //// 07-17-07: Added 18F4450,2450 support ////
.................... //// ////
.................... //// 07-13-07: Added 87J50 family support ////
.................... //// ////
.................... //// 11-01-05: usb_detach(), usb_attach() and usb_init_cs() ////
.................... //// changed for the better. ////
.................... //// ////
.................... //// 10-28-05: Added usb_rx_packet_size() ////
.................... //// ////
.................... //// 07-13-05: usb_put_packet() changed for 16bit packet sizes ////
.................... //// usb_flush_in() changed for 16bit packet sizes ////
.................... //// usb_get_packet() changed for 16bit packet sizes ////
.................... //// usb_flush_out() changed for 16bit packet sizes ////
.................... //// usb_set_configured() changed for 16bit packet sizes ////
.................... //// ////
.................... //// 06-30-05: usb_tbe() added ////
.................... //// The way endpoint 0 DTS is set has been changed. ////
.................... //// ////
.................... //// 06-20-05: Initial Release ////
.................... //// ////
.................... //// 05-13-05: Beta Release (Full Speed works) ////
.................... //// ////
.................... //// 03-21-05: Initial Alpha Release ////
.................... //// ////
.................... /////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2009 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS ////
.................... //// C compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, ////
.................... //// reproduction or distribution is permitted without written ////
.................... //// permission. Derivative programs created using this software ////
.................... //// in object code form are not restricted in any way. ////
.................... /////////////////////////////////////////////////////////////////////////
....................
.................... #IFNDEF __PIC18_USB_C__
.................... #DEFINE __PIC18_USB_C__
....................
.................... #INCLUDE <usb.h>
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// usb.h ////
.................... //// ////
.................... //// Function protypes, defintions and globals used by CCS USB driver ////
.................... //// ////
.................... //// This file is part of CCS's USB driver code ////
.................... //// ////
.................... //// The following USB examples are provided by CCS: ////
.................... //// ex_usb_mouse.c - A HID Mouse. ////
.................... //// ex_usb_hid.c - A custom application using HID protocol. ////
.................... //// ex_usb_kbmouse.c - A HID Mouse/Keyboard combo using multiple ////
.................... //// interfaces. ////
.................... //// ex_usb_kbmouse2.c - A HID Mouse/Keyboard combo using multiple ////
.................... //// HID Reports. ////
.................... //// ex_usb_scope.c - A digital oscilloscope using a custom ////
.................... //// protocol requiring custom Windows drivers. ////
.................... //// ex_usb_serial.c - ////
.................... //// ex_usb_serial2.c - Two examples of using the CDC driver for ////
.................... //// a virtual COM port. ////
.................... //// ex_usb_bootloader.c - CDC/Virtual COM port bootloader. ////
.................... //// ex_usb_loadmouse.c - A conversion of ex_usb_mouse.c that is ////
.................... //// compatible with ex_usb_mouse.c. ////
.................... //// ////
.................... //// ********************** API ********************* ////
.................... //// ////
.................... //// These are the functions that are meant to be called by the user: ////
.................... //// ////
.................... //// usb_init() - Initializes the USB stack, the USB peripheral and ////
.................... //// attaches the unit to the usb bus. Enables ////
.................... //// interrupts. Will wait in an infinite loop until ////
.................... //// the device enumerates - if you are using ////
.................... //// connection sense or if the processor should run ////
.................... //// even if it's not connected to USB then use ////
.................... //// usb_init_cs() instead. ////
.................... //// ////
.................... //// usb_init_cs() - A smaller usb_init(), does not attach unit ////
.................... //// to usb bus or enable interrupts. Since this does ////
.................... //// not attach to the USB, you must periodically call ////
.................... //// usb_task(). See usb_task() for more information. ////
.................... //// ////
.................... //// usb_task() - If usb_init_cs() was used to initiate the USB ////
.................... //// peripheral, usb_task() should then be called periodically ////
.................... //// to check the connection sense pin. If the connection ////
.................... //// sense pin denotes USB is connected and the USB peripheral ////
.................... //// is not attached, this will attach the USB peripheral ////
.................... //// so the PC can start the enumeration process (and it ////
.................... //// will enable interrupts). If the connection sense pin ////
.................... //// denotes USB is not attached and the USB peripheral is ////
.................... //// running, this will reset the USB peripheral and wait ////
.................... //// for USB to reconnect (and usb_enumerated() will start ////
.................... //// returning FALSE). If connection sense (USB_CON_SENSE_PIN) ////
.................... //// is not defined the usb_task() assumes that USB is always ////
.................... //// connected. ////
.................... //// ////
.................... //// usb_attached() - Returns TRUE if the device is attached to a ////
.................... //// USB cable. A macro that looks at the defined ////
.................... //// connection sense pin. If this returns TRUE ////
.................... //// it does not mean the PC has connected to it, ////
.................... //// you need to use usb_enumerated() to check this. ////
.................... //// ////
.................... //// usb_enumerated() - Returns TRUE if device has been enumerated ////
.................... //// (configured) by host, FALSE if it has not. ////
.................... //// Do not try to use the USB peripheral for ////
.................... //// sending and receiving packets until you ////
.................... //// are enumerated. ////
.................... //// ////
.................... //// usb_wait_for_enumeration() - Sits in an infinte loop until device ////
.................... //// is enumerated. ////
.................... //// ////
.................... //// usb_tbe(endpoint) - Returns TRUE if the endpoint transmit buffer ////
.................... //// is free and ready to accept a new packet for transmission. ////
.................... //// ////
.................... //// usb_put_packet(endpoint, ptr, len, tgl) - Sends one packet to the ////
.................... //// host. If you need to send a message that ////
.................... //// spans more than one packet then use ////
.................... //// usb_puts(). Fore more detailed documentation ////
.................... //// see usb_hw_layer.h ////
.................... //// ////
.................... //// usb_puts(endpoint, ptr, len, timeout) - Sends a multiple packet ////
.................... //// message to the host. If you only need to send one packet, ////
.................... //// it is more effecient to use usb_put_packet(). This is ////
.................... //// documented in more detail above the prototype in USB.H. ////
.................... //// ////
.................... //// usb_kbhit(endpoint) - Returns true if OUT endpoint contains data ////
.................... //// from host. This will remain TRUE until ////
.................... //// usb_put_packet() or usb_flush_out() used. ////
.................... //// This function will return an invalid response ////
.................... //// if specified endpoint is not enabled for ////
.................... //// receiving data. ////
.................... //// ////
.................... //// len = usb_get_packet(endpoint, ptr, max) - Gets one packet that ////
.................... //// from the host/PC. usb_kbhit() must return TRUE before you ////
.................... //// call this routine or your data may not be valid. This ////
.................... //// only receives one packet, if you are trying to receive a ////
.................... //// multi-packet message use usb_gets(). For more detailed ////
.................... //// documentation see usb_hw_layer.h. ////
.................... //// ////
.................... //// len = usb_gets(endpoint, ptr, max, timeout) - Gets multiple ////
.................... //// packets from the host, you would use this instead ////
.................... //// of usb_get_packet() if you wanted to handle multi-packet ////
.................... //// messages. This is documented in more detail above the ////
.................... //// prototype in USB.H. ////
.................... //// ////
.................... //// ////
.................... //// ********* DEFINITIONS / CONFIGURATION ********** ////
.................... //// ////
.................... //// The following definitions are declared here, but can be ////
.................... //// overwritten in your code. Unless needed otherwise, leave ////
.................... //// to default value. If confused about a definition read the ////
.................... //// comments at each defintion ////
.................... //// ////
.................... //// USB_HID_IDLE (TRUE) - Set to TRUE if your device supports ////
.................... //// Set_Idle HID class request. Set to ////
.................... //// False if you do not (device will ////
.................... //// send a Wrong-state if computer ////
.................... //// sends a Set_Idle / Get_Idle command) ////
.................... //// NOTE: If you set to TRUE you must ////
.................... //// provide your own code. See ////
.................... //// usb_isr_tkn_setup_ClassInterface() in ////
.................... //// usb.c ////
.................... //// ////
.................... //// USB_HID_BOOT_PROTOCOL (FALSE) - Set to TRUE if your device supports ////
.................... //// Set_Protocl HID class request. Set to ////
.................... //// False if you do not (device will ////
.................... //// send a Wrong-state if computer ////
.................... //// sends a Set_Protocl / Get_Protocol ////
.................... //// command). ////
.................... //// NOTE: If you set to TRUE you must ////
.................... //// provide your own code in the ////
.................... //// application that properly send boot ////
.................... //// or HID packets. ////
.................... //// ////
.................... //// USB_MAX_EP0_PACKET_LENGTH (8) - Max Packet size for Endpoint 0. ////
.................... //// The hardware level driver (ex ////
.................... //// pic18_usb.h will define this value if ////
.................... //// not already overwritten). Increasing ////
.................... //// this size will speed up the ////
.................... //// enumeration process. ////
.................... //// ////
.................... //// USB_EPx_RX_ENABLE (USB_ENABLE_DISABLED) - Where x is the ////
.................... //// endpoint number. Change this define ////
.................... //// to specify what kind of transfer method ////
.................... //// this RX (PC to device) endpoint uses. ////
.................... //// Here is the list of valid transfer methods: ////
.................... //// USB_ENABLE_CONTROL ////
.................... //// USB_ENABLE_ISOCHRONOUS ////
.................... //// USB_ENABLE_BULK ////
.................... //// USB_ENABLE_INTERRUPT ////
.................... //// USB_ENABLE_DISABLED ////
.................... //// Don't forget that you must specify the ////
.................... //// transfer method properly in your endpoint ////
.................... //// descriptor, too. ////
.................... //// ////
.................... //// USB_EPx_RX_SIZE (0) - For some hardware it is important to know ////
.................... //// how much memory to reserve for receiving ////
.................... //// packets. ////
.................... //// ////
.................... //// *** NOTE *** You must have both USB_EPx_RX_ENABLE defined and ////
.................... //// USB_EPx_RX_SIZE defined (non 0) to enable a RX ////
.................... //// endpoint. ////
.................... //// *** NOTE *** Endpoint 0 is always enabled. ////
.................... //// ////
.................... //// USB_EPx_TX_ENABLE (USB_ENABLE_DISABLED) - Where x is the ////
.................... //// endpoint number. Change this define ////
.................... //// to specify what kind of transfer method ////
.................... //// this TX (device to PC) endpoint uses. ////
.................... //// Here is the list of valid transfer methods: ////
.................... //// USB_ENABLE_CONTROL ////
.................... //// USB_ENABLE_ISOCHRONOUS ////
.................... //// USB_ENABLE_BULK ////
.................... //// USB_ENABLE_INTERRUPT ////
.................... //// USB_ENABLE_DISABLED ////
.................... //// Don't forget that you must specify the ////
.................... //// transfer method properly in your endpoint ////
.................... //// descriptor, too. ////
.................... //// ////
.................... //// USB_EPx_TX_SIZE (0) - For some hardware it is important to know ////
.................... //// how much memory to reserve for transmitting ////
.................... //// packets. ////
.................... //// ////
.................... //// *** NOTE *** You must have both USB_EPx_TX_ENABLE defined and ////
.................... //// USB_EPx_TX_SIZE defined (non 0) to enable a TX ////
.................... //// endpoint. ////
.................... //// ////
.................... //// ////
.................... //// USB_HID_DEVICE (TRUE) - HID devices require extra code to handle ////
.................... //// HID requests. You can disable to save ////
.................... //// ROM space if you are not using a HID ////
.................... //// device. If you are not using a HID ////
.................... //// device you must provide your own O/S ////
.................... //// (Windows) driver. ////
.................... //// ////
.................... //// The other definitions should not be changed. ////
.................... //// ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// ////
.................... //// Version History: ////
.................... //// ////
.................... //// March 5th, 2009: ////
.................... //// Cleanup for Wizard. ////
.................... //// PIC24 Initial release. ////
.................... //// ////
.................... //// July 13th, 2005: ////
.................... //// usb_ep_tx_size[] and usb_ep_rx_size[] changed to 16bits ////
.................... //// ////
.................... //// June 20th, 2005: ////
.................... //// Initial 18fxx5x release ////
.................... //// ////
.................... //// May 13th, 2005: ////
.................... //// Beta release, only works with 18Fxx5x hardware layer. ////
.................... //// Now supports multiple interfaces (many defines in descriptors ////
.................... //// will have to be changed, see examples) ////
.................... //// ////
.................... //// Mar 21st, 2005: ////
.................... //// Initial Alpha Release with PIC18Fxx5x support. (ONLY TESTED ////
.................... //// WITH 18F4550) ////
.................... //// usb_gets() and usb_puts() changed (see usb.c) ////
.................... //// ////
.................... //// June 24th, 2004: ////
.................... //// Optimization and cleanup. ////
.................... //// The following definitions changed: ////
.................... //// USB_EPx_TX_ENABLE and USB_EPx_RX_ENABLE have changed. See usb.h ////
.................... //// USB_CONFIG_DESCRIPTORS[] removed ////
.................... //// USB_CONFIG_DESC_LEN changed to USB_DESC_CONFIG_LEN ////
.................... //// USB_INTERFACE_DESC_LEN changed to USB_DESC_INTERFACE_LEN ////
.................... //// USB_CLASS_DESC_LEN changed to USB_DESC_CLASS_LEN ////
.................... //// USB_ENDPOINT_DESC_LEN changed to USB_DESC_ENDPOINT_LEN ////
.................... //// USB_CONFIG_DESC_KEY changed to USB_DESC_CONFIG_TYPE ////
.................... //// USB_INTERFACE_DESC_KEY changed to USB_DESC_INTERFACE_TYPE ////
.................... //// USB_CLASS_DESC_KEY changed to USB_DESC_CLASS_TYPE ////
.................... //// USB_ENDPOINT_DESC_KEY changed to USB_DESC_ENDPOINT_TYPE ////
.................... //// USB_STRING_X[] arrays removed, see USB_STRING_DESC[] and ////
.................... //// USB_STRING_DESC_OFFSET[] ////
.................... //// dev_req, curr_config, status_device and getdesc_type global ////
.................... //// variables moved into struct USB_stack_status ////
.................... //// ////
.................... //// October 15th, 2003: Support for boot protocol added. ////
.................... //// Set USB_HID_BOOT_PROTOCOL to TRUE to support this. ////
.................... //// The array hid_protocol[] saves which protocol mode each ////
.................... //// interface is in. It is your applications job to send ////
.................... //// data that either fit the boot protocol or HID protocol. ////
.................... //// ////
.................... //// May 6th, 2003: Fixed a potential stack overflow using PCM ////
.................... //// ////
.................... //// October 29th, 2002: New definition added to USB_STATES ////
.................... //// ////
.................... //// August 2nd, 2002: Initial Public Release ////
.................... //// ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2009 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS ////
.................... //// C compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, ////
.................... //// reproduction or distribution is permitted without written ////
.................... //// permission. Derivative programs created using this software ////
.................... //// in object code form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
....................
.................... #IFNDEF __USB_PROTOTYPES__
.................... #DEFINE __USB_PROTOTYPES__
....................
.................... //// CONFIGURATION ////////////////////////////////////////////////////////////
....................
.................... #ifndef USB_CON_SENSE_PIN
.................... #define USB_CON_SENSE_PIN 0
.................... #endif
....................
.................... #IFNDEF USB_HID_BOOT_PROTOCOL
.................... #DEFINE USB_HID_BOOT_PROTOCOL FALSE
.................... #ENDIF
....................
.................... #IFNDEF USB_HID_IDLE
.................... #DEFINE USB_HID_IDLE FALSE
.................... #ENDIF
....................
.................... //should the compiler add the extra HID handler code? Defaults to yes.
.................... #IFNDEF USB_HID_DEVICE
.................... #DEFINE USB_HID_DEVICE TRUE
.................... #ENDIF
....................
.................... #IFNDEF USB_CDC_DEVICE
.................... #DEFINE USB_CDC_DEVICE FALSE
.................... #ENDIF
....................
.................... //set to false to opt for less RAM, true to opt for less ROM
.................... #ifndef USB_OPT_FOR_ROM
.................... #define USB_OPT_FOR_ROM TRUE
.................... #endif
....................
.................... #IFNDEF USB_MAX_EP0_PACKET_LENGTH
.................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 8
.................... #ENDIF
....................
....................
.................... ////// USER-LEVEL API /////////////////////////////////////////////////////////
....................
.................... /**************************************************************
.................... /* usb_enumerated()
.................... /*
.................... /* Input: Global variable USB_Curr_Config
.................... /* Returns: Returns a 1 if device is configured / enumerated,
.................... /* Returns a 0 if device is un-configured / not enumerated.
.................... /*
.................... /* Summary: See API section of USB.H for more documentation.
.................... /***************************************************************/
.................... int1 usb_enumerated(void);
....................
.................... /**************************************************************
.................... /* usb_wait_for_enumeration()
.................... /*
.................... /* Input: Global variable USB_Curr_Config
.................... /*
.................... /* Summary: Waits in-definately until device is configured / enumerated.
.................... /* See API section of USB.H for more information.
.................... /***************************************************************/
.................... void usb_wait_for_enumeration(void);
....................
.................... /****************************************************************************
.................... /* usb_gets(endpoint, ptr, max, timeout)
.................... /*
.................... /* Input: endpoint - endpoint to get data from
.................... /* ptr - place / array to store data to
.................... /* max - max amount of data to get from USB and store into ptr
.................... /* timeout - time in milliseconds, for each packet, to wait before
.................... /* timeout. set to 0 for no timeout.
.................... /*
.................... /* Output: Amount of data returned. It may be less than max.
.................... /*
.................... /* Summary: Gets data from the host. Will get multiple-packet messages
.................... /* and finish when either it receives a 0-len packet or a packet
.................... /* of less size than maximum.
.................... /*
.................... /*****************************************************************************/
.................... unsigned int16 usb_gets(int8 endpoint, int8 * ptr, unsigned int16 max, unsigned int16 timeout);
....................
.................... /****************************************************************************
.................... /* usb_puts()
.................... /*
.................... /* Inputs: endpoint - endpoint to send data out
.................... /* ptr - points to array of data to send
.................... /* len - amount of data to send
.................... /* timeout - time in milli-seconds, for each packet, to wait before
.................... /* timeout. set to 0 for no timeout.
.................... /*
.................... /* Outputs: Returns TRUE if message sent succesfully, FALSE if it was not
.................... /* sent before timeout period expired.
.................... /*
.................... /* Summary: Used for sending multiple packets of data as one message. This
.................... /* function can still be used to send messages consiting of only one
.................... /* packet. See usb_put_packet() documentation for the rules about when
.................... /* multiple packet messages or 0-lenght packets are needed.
.................... /*
.................... /*****************************************************************************/
.................... int1 usb_puts(int8 endpoint, int8 * ptr, unsigned int16 len, unsigned int8 timeout);
....................
.................... /******************************************************************************
.................... /* usb_attached()
.................... /*
.................... /* Summary: Returns TRUE if the device is attached to a USB cable.
.................... /* See the API section of USB.H for more documentation.
.................... /*
.................... /*****************************************************************************/
.................... #if USB_CON_SENSE_PIN
.................... #define usb_attached() input(USB_CON_SENSE_PIN)
.................... #else
.................... #define usb_attached() TRUE
.................... #endif
....................
.................... ////// END USER-LEVEL API /////////////////////////////////////////////////////
....................
....................
.................... ////// STACK-LEVEL API USED BY HW DRIVERS ////////////////////////////////////
....................
.................... enum USB_STATES {GET_DESCRIPTOR=1,SET_ADDRESS=2,NONE=0};
....................
.................... enum USB_GETDESC_TYPES {USB_GETDESC_CONFIG_TYPE=0,USB_GETDESC_HIDREPORT_TYPE=1,USB_GETDESC_STRING_TYPE=2,USB_GETDESC_DEVICE_TYPE=3};
....................
.................... #if USB_OPT_FOR_ROM
.................... typedef struct {
.................... USB_STATES dev_req; //what did the last setup token set us up to do?. init at none
.................... int curr_config; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS)
.................... int status_device; //Holds our state for Set_Feature and Clear_Feature
.................... USB_GETDESC_TYPES getdesc_type; //which get_descriptor() we are handling
.................... } TYPE_USB_STACK_STATUS;
.................... #else
.................... typedef struct {
.................... USB_STATES dev_req:2; //what did the last setup token set us up to do?. init at none
.................... int Curr_config:2; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS)
.................... int status_device:2; //Holds our state for Set_Feature and Clear_Feature
.................... USB_GETDESC_TYPES getdesc_type:2; //which get_descriptor() we are handling
.................... } TYPE_USB_STACK_STATUS;
.................... #endif
....................
.................... extern TYPE_USB_STACK_STATUS USB_stack_status;
....................
.................... /**************************************************************
.................... /* usb_token_reset()
.................... /*
.................... /* Output: No output (but many global registers are modified)
.................... /*
.................... /* Summary: Resets the token handler to initial (unconfigured) state.
.................... /***************************************************************/
.................... void usb_token_reset(void);
....................
.................... /**************************************************************
.................... /* usb_isr_tok_setup_dne()
.................... /*
.................... /* Input: usb_ep0_rx_buffer[] contains the the setup packet.
.................... /*
.................... /* Output: None (many globals are changed)
.................... /*
.................... /* Summary: This function is that handles the setup token.
.................... /* We must handle all relevant requests, such as Set_Configuration,
.................... /* Get_Descriptor, etc.
.................... /*
.................... /* usb_ep0_rx_buffer[] contains setup data packet, which has the
.................... /* following records:
.................... /* -------------------------------------------------------------------------------------------
.................... /* usb_ep0_rx_buffer[ 0 ]=bmRequestType; Where the setup packet goes
.................... /* bit7 (0) host-to-device
.................... /* (1) device-to-host
.................... /* bit6-5 (00) usb standard request;
.................... /* (01) class request;
.................... /* (10) vendor request
.................... /* (11) reserved
.................... /* bit4-0 (0000) device
.................... /* (0001) interface
.................... /* (0010) endpoint
.................... /* (0011) other element
.................... /* (0100) to (1111) reserved
.................... /* usb_ep0_rx_buffer[ 1 ]=bRequest ; the request
.................... /* usb_ep0_rx_buffer[2,3]=wValue ; a value which corresponds to request
.................... /* usb_ep0_rx_buffer[4,5]=wIndex ; could correspond to interface or endpoint...
.................... /* usb_ep0_rx_buffer[6,7]=wLength ; number of bytes in next data packet;
.................... /* for host-to-device, this exactly how many bytes in data packet.
.................... /* for device-to-host, this is the maximum bytes that can fit one packet.
.................... /***************************************************************/
.................... void usb_isr_tok_setup_dne(void);
....................
.................... /**************************************************************
.................... /* usb_isr_tok_out_dne()
.................... /*
.................... /* Input: endpoint contains which endpoint we are receiving data (0..15)
.................... /*
.................... /* Summary: Processes out tokens (out is respective of the host, so actualy
.................... /* incoming to the pic), but not out setup tokens. Normally when
.................... /* data is received it is left in the buffer (user would use
.................... /* usb_kbhit() and usb_get_packet() to receive data), but certain
.................... /* libraries (like CDC) have to answer setup packets.
.................... /*
.................... /***************************************************************/
.................... void usb_isr_tok_out_dne(int8 endpoint);
....................
.................... /**************************************************************
.................... /* usb_isr_tok_in_dne(endpoint)
.................... /*
.................... /* Input: endpoint - which endpoint we are processing a setup token.
.................... /*
.................... /* Summary: This handles an IN packet (HOST <- PIC). For endpoint 0, this
.................... /* is usually to setup a response packet to a setup packet. Endpoints 1..15
.................... /* are generally ignored, and the user has to use usb_tbe() to determine if
.................... /* if the buffer is ready for a new transmit packet (there are special cases,
.................... /* like CDC which handles the CDC protocl).
.................... /*
.................... /***************************************************************/
.................... void usb_isr_tok_in_dne(int8 endpoint);
....................
.................... ////// END STACK-LEVEL API USED BY HW DRIVERS /////////////////////////////////
....................
....................
.................... //CCS only supports one configuration at this time
.................... #DEFINE USB_NUM_CONFIGURATIONS 1 //DO NOT CHANGE
....................
.................... //PID values for tokens (see page 48 of USB Complete ed.1)
.................... #define PID_IN 0x09 //device to host transactions
.................... #define PID_OUT 0x01 //host to device transactions
.................... #define PID_SETUP 0x0D //host to device setup transaction
.................... #define PID_ACK 0x02 //receiver accepts error-free data packet
.................... #define PID_DATA0 0x03 //data packet with even sync bit
.................... #define PID_SOF 0x05 //start of framer marker and frame number
.................... #define PID_NAK 0x0A //receiver can't accept data or sender cant send data or has no data to transmit
.................... #define PID_DATA1 0x0B //data packet with odd sync bit
.................... #define PID_PRE 0x0C //preamble issued by host. enables downstream traffic to low-speed device
.................... #define PID_STALL 0x0E //a control request isnt supported or the endpoint is halted
....................
.................... //Key which identifies descritpors
.................... #DEFINE USB_DESC_DEVICE_TYPE 0x01 //#DEFINE USB_DEVICE_DESC_KEY 0x01
.................... #DEFINE USB_DESC_CONFIG_TYPE 0x02 //#DEFINE USB_CONFIG_DESC_KEY 0x02
.................... #DEFINE USB_DESC_STRING_TYPE 0x03 //#DEFINE USB_STRING_DESC_KEY 0x03
.................... #DEFINE USB_DESC_INTERFACE_TYPE 0x04 //#DEFINE USB_INTERFACE_DESC_KEY 0x04
.................... #DEFINE USB_DESC_ENDPOINT_TYPE 0x05 //#DEFINE USB_ENDPOINT_DESC_KEY 0x05
.................... #DEFINE USB_DESC_CLASS_TYPE 0x21 //#DEFINE USB_CLASS_DESC_KEY 0x21
.................... #DEFINE USB_DESC_HIDREPORT_TYPE 0x22
....................
.................... //The length of each descriptor
.................... #DEFINE USB_DESC_DEVICE_LEN 18 //#DEFINE USB_DEVICE_DESC_LEN 18
.................... #DEFINE USB_DESC_CONFIG_LEN 9 //#DEFINE USB_CONFIG_DESC_LEN 9
.................... #DEFINE USB_DESC_INTERFACE_LEN 9 //#DEFINE USB_INTERFACE_DESC_LEN 9
.................... #DEFINE USB_DESC_CLASS_LEN 9 //#DEFINE USB_CLASS_DESC_LEN 9
.................... #DEFINE USB_DESC_ENDPOINT_LEN 7 //#DEFINE USB_ENDPOINT_DESC_LEN 7
....................
.................... //Standard USB Setup bRequest Codes
.................... #define USB_STANDARD_REQUEST_GET_STATUS 0x00
.................... #define USB_STANDARD_REQUEST_CLEAR_FEATURE 0x01
.................... #define USB_STANDARD_REQUEST_SET_FEATURE 0x03
.................... #define USB_STANDARD_REQUEST_SET_ADDRESS 0x05
.................... #define USB_STANDARD_REQUEST_GET_DESCRIPTOR 0x06
.................... #define USB_STANDARD_REQUEST_SET_DESCRIPTOR 0x07
.................... #define USB_STANDARD_REQUEST_GET_CONFIGURATION 0x08
.................... #define USB_STANDARD_REQUEST_SET_CONFIGURATION 0x09
.................... #define USB_STANDARD_REQUEST_GET_INTERFACE 0x0A
.................... #define USB_STANDARD_REQUEST_SET_INTERFACE 0x0B
.................... #define USB_STANDARD_REQUEST_SYNCH_FRAME 0x0C
....................
.................... //HID Class Setup bRequest Codes
.................... #define USB_HID_REQUEST_GET_REPORT 0x01
.................... #define USB_HID_REQUEST_GET_IDLE 0x02
.................... #define USB_HID_REQUEST_GET_PROTOCOL 0x03
.................... #define USB_HID_REQUEST_SET_REPORT 0x09
.................... #define USB_HID_REQUEST_SET_IDLE 0x0A
.................... #define USB_HID_REQUEST_SET_PROTOCOL 0x0B
....................
.................... //types of endpoints as defined in the descriptor
.................... #define USB_ENDPOINT_TYPE_CONTROL 0x00
.................... #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
.................... #define USB_ENDPOINT_TYPE_BULK 0x02
.................... #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
....................
.................... //types of endpoints used internally in this api
.................... #define USB_ENABLE_DISABLED -1
.................... #define USB_ENABLE_BULK USB_ENDPOINT_TYPE_BULK
.................... #define USB_ENABLE_ISOCHRONOUS USB_ENDPOINT_TYPE_ISOCHRONOUS
.................... #define USB_ENABLE_INTERRUPT USB_ENDPOINT_TYPE_INTERRUPT
.................... #define USB_ENABLE_CONTROL USB_ENDPOINT_TYPE_CONTROL
....................
....................
.................... //*** ENABLE RX ENDPOINTS AND BUFFERS
....................
.................... //--------- endpoint 0 defines ----------
.................... #define USB_EP0_TX_ENABLE USB_ENABLE_CONTROL
.................... #define USB_EP0_RX_ENABLE USB_ENABLE_CONTROL
.................... #define USB_EP0_RX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8
.................... #define USB_EP0_TX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8
....................
.................... //--------- endpoint 1 defines ----------
.................... #ifndef USB_EP1_TX_ENABLE
.................... #define USB_EP1_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP1_RX_ENABLE
.................... #define USB_EP1_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP1_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP1_RX_SIZE
.................... #undef USB_EP1_RX_SIZE
.................... #endif
.................... #define USB_EP1_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP1_RX_SIZE
.................... #error You enabled EP1 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP1_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP1_TX_SIZE
.................... #undef USB_EP1_TX_SIZE
.................... #endif
.................... #define USB_EP1_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP1_TX_SIZE
.................... #error You enabled EP1 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 2 defines ----------
.................... #ifndef USB_EP2_TX_ENABLE
.................... #define USB_EP2_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP2_RX_ENABLE
.................... #define USB_EP2_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP2_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP2_RX_SIZE
.................... #undef USB_EP2_RX_SIZE
.................... #endif
.................... #define USB_EP2_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP2_RX_SIZE
.................... #error You enabled EP2 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP2_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP2_TX_SIZE
.................... #undef USB_EP2_TX_SIZE
.................... #endif
.................... #define USB_EP2_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP2_TX_SIZE
.................... #error You enabled EP2 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 3 defines ----------
.................... #ifndef USB_EP3_TX_ENABLE
.................... #define USB_EP3_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP3_RX_ENABLE
.................... #define USB_EP3_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP3_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP3_RX_SIZE
.................... #undef USB_EP3_RX_SIZE
.................... #endif
.................... #define USB_EP3_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP3_RX_SIZE
.................... #error You enabled EP3 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP3_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP3_TX_SIZE
.................... #undef USB_EP3_TX_SIZE
.................... #endif
.................... #define USB_EP3_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP3_TX_SIZE
.................... #error You enabled EP3 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 4 defines ----------
.................... #ifndef USB_EP4_TX_ENABLE
.................... #define USB_EP4_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP4_RX_ENABLE
.................... #define USB_EP4_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP4_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP4_RX_SIZE
.................... #undef USB_EP4_RX_SIZE
.................... #endif
.................... #define USB_EP4_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP4_RX_SIZE
.................... #error You enabled EP4 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP4_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP4_TX_SIZE
.................... #undef USB_EP4_TX_SIZE
.................... #endif
.................... #define USB_EP4_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP4_TX_SIZE
.................... #error You enabled EP4 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 5 defines ----------
.................... #ifndef USB_EP5_TX_ENABLE
.................... #define USB_EP5_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP5_RX_ENABLE
.................... #define USB_EP5_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP5_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP5_RX_SIZE
.................... #undef USB_EP5_RX_SIZE
.................... #endif
.................... #define USB_EP5_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP5_RX_SIZE
.................... #error You enabled EP5 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP5_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP5_TX_SIZE
.................... #undef USB_EP5_TX_SIZE
.................... #endif
.................... #define USB_EP5_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP5_TX_SIZE
.................... #error You enabled EP5 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 6 defines ----------
.................... #ifndef USB_EP6_TX_ENABLE
.................... #define USB_EP6_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP6_RX_ENABLE
.................... #define USB_EP6_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP6_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP6_RX_SIZE
.................... #undef USB_EP6_RX_SIZE
.................... #endif
.................... #define USB_EP6_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP6_RX_SIZE
.................... #error You enabled EP6 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP6_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP6_TX_SIZE
.................... #undef USB_EP6_TX_SIZE
.................... #endif
.................... #define USB_EP6_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP6_TX_SIZE
.................... #error You enabled EP6 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 7 defines ----------
.................... #ifndef USB_EP7_TX_ENABLE
.................... #define USB_EP7_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP7_RX_ENABLE
.................... #define USB_EP7_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP7_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP7_RX_SIZE
.................... #undef USB_EP7_RX_SIZE
.................... #endif
.................... #define USB_EP7_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP7_RX_SIZE
.................... #error You enabled EP7 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP7_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP7_TX_SIZE
.................... #undef USB_EP7_TX_SIZE
.................... #endif
.................... #define USB_EP7_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP7_TX_SIZE
.................... #error You enabled EP7 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 8 defines ----------
.................... #ifndef USB_EP8_TX_ENABLE
.................... #define USB_EP8_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP8_RX_ENABLE
.................... #define USB_EP8_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP8_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP8_RX_SIZE
.................... #undef USB_EP8_RX_SIZE
.................... #endif
.................... #define USB_EP8_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP8_RX_SIZE
.................... #error You enabled EP8 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP8_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP8_TX_SIZE
.................... #undef USB_EP8_TX_SIZE
.................... #endif
.................... #define USB_EP8_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP8_TX_SIZE
.................... #error You enabled EP8 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 9 defines ----------
.................... #ifndef USB_EP9_TX_ENABLE
.................... #define USB_EP9_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP9_RX_ENABLE
.................... #define USB_EP9_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP9_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP9_RX_SIZE
.................... #undef USB_EP9_RX_SIZE
.................... #endif
.................... #define USB_EP9_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP9_RX_SIZE
.................... #error You enabled EP9 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP9_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP9_TX_SIZE
.................... #undef USB_EP9_TX_SIZE
.................... #endif
.................... #define USB_EP9_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP9_TX_SIZE
.................... #error You enabled EP9 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 10 defines ----------
.................... #ifndef USB_EP10_TX_ENABLE
.................... #define USB_EP10_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP10_RX_ENABLE
.................... #define USB_EP10_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP10_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP10_RX_SIZE
.................... #undef USB_EP10_RX_SIZE
.................... #endif
.................... #define USB_EP10_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP10_RX_SIZE
.................... #error You enabled EP10 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP10_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP10_TX_SIZE
.................... #undef USB_EP10_TX_SIZE
.................... #endif
.................... #define USB_EP10_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP10_TX_SIZE
.................... #error You enabled EP10 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 11 defines ----------
.................... #ifndef USB_EP11_TX_ENABLE
.................... #define USB_EP11_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP11_RX_ENABLE
.................... #define USB_EP11_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP11_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP11_RX_SIZE
.................... #undef USB_EP11_RX_SIZE
.................... #endif
.................... #define USB_EP11_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP11_RX_SIZE
.................... #error You enabled EP11 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP11_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP11_TX_SIZE
.................... #undef USB_EP11_TX_SIZE
.................... #endif
.................... #define USB_EP11_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP11_TX_SIZE
.................... #error You enabled EP11 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 12 defines ----------
.................... #ifndef USB_EP12_TX_ENABLE
.................... #define USB_EP12_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP12_RX_ENABLE
.................... #define USB_EP12_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP12_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP12_RX_SIZE
.................... #undef USB_EP12_RX_SIZE
.................... #endif
.................... #define USB_EP12_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP12_RX_SIZE
.................... #error You enabled EP12 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP12_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP12_TX_SIZE
.................... #undef USB_EP12_TX_SIZE
.................... #endif
.................... #define USB_EP12_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP12_TX_SIZE
.................... #error You enabled EP12 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 13 defines ----------
.................... #ifndef USB_EP13_TX_ENABLE
.................... #define USB_EP13_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP13_RX_ENABLE
.................... #define USB_EP13_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP13_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP13_RX_SIZE
.................... #undef USB_EP13_RX_SIZE
.................... #endif
.................... #define USB_EP13_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP13_RX_SIZE
.................... #error You enabled EP13 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP13_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP13_TX_SIZE
.................... #undef USB_EP13_TX_SIZE
.................... #endif
.................... #define USB_EP13_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP13_TX_SIZE
.................... #error You enabled EP13 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 14 defines ----------
.................... #ifndef USB_EP14_TX_ENABLE
.................... #define USB_EP14_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP14_RX_ENABLE
.................... #define USB_EP14_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP14_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP14_RX_SIZE
.................... #undef USB_EP14_RX_SIZE
.................... #endif
.................... #define USB_EP14_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP14_RX_SIZE
.................... #error You enabled EP14 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP14_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP14_TX_SIZE
.................... #undef USB_EP14_TX_SIZE
.................... #endif
.................... #define USB_EP14_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP14_TX_SIZE
.................... #error You enabled EP14 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
....................
.................... //--------- endpoint 15 defines ----------
.................... #ifndef USB_EP15_TX_ENABLE
.................... #define USB_EP15_TX_ENABLE USB_ENABLE_DISABLED
.................... #endif
.................... #ifndef USB_EP15_RX_ENABLE
.................... #define USB_EP15_RX_ENABLE USB_ENABLE_DISABLED
.................... #endif
....................
.................... #if USB_EP15_RX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP15_RX_SIZE
.................... #undef USB_EP15_RX_SIZE
.................... #endif
.................... #define USB_EP15_RX_SIZE 0
.................... #else
.................... #ifndef USB_EP15_RX_SIZE
.................... #error You enabled EP15 for RX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... #if USB_EP15_TX_ENABLE==USB_ENABLE_DISABLED
.................... #ifdef USB_EP15_TX_SIZE
.................... #undef USB_EP15_TX_SIZE
.................... #endif
.................... #define USB_EP15_TX_SIZE 0
.................... #else
.................... #ifndef USB_EP15_TX_SIZE
.................... #error You enabled EP15 for TX but didn't specify endpoint size
.................... #endif
.................... #endif
....................
.................... const int8 usb_ep_tx_type[16]={
.................... USB_EP0_TX_ENABLE, USB_EP1_TX_ENABLE, USB_EP2_TX_ENABLE,
.................... USB_EP3_TX_ENABLE, USB_EP4_TX_ENABLE, USB_EP5_TX_ENABLE,
.................... USB_EP6_TX_ENABLE, USB_EP7_TX_ENABLE, USB_EP8_TX_ENABLE,
.................... USB_EP9_TX_ENABLE, USB_EP10_TX_ENABLE, USB_EP11_TX_ENABLE,
.................... USB_EP12_TX_ENABLE, USB_EP13_TX_ENABLE, USB_EP14_TX_ENABLE,
.................... USB_EP15_TX_ENABLE
.................... };
....................
.................... const int8 usb_ep_rx_type[16]={
.................... USB_EP0_RX_ENABLE, USB_EP1_RX_ENABLE, USB_EP2_RX_ENABLE,
.................... USB_EP3_RX_ENABLE, USB_EP4_RX_ENABLE, USB_EP5_RX_ENABLE,
.................... USB_EP6_RX_ENABLE, USB_EP7_RX_ENABLE, USB_EP8_RX_ENABLE,
.................... USB_EP9_RX_ENABLE, USB_EP10_RX_ENABLE, USB_EP11_RX_ENABLE,
.................... USB_EP12_RX_ENABLE, USB_EP13_RX_ENABLE, USB_EP14_RX_ENABLE,
.................... USB_EP15_RX_ENABLE
.................... };
....................
.................... const unsigned int16 usb_ep_tx_size[16]={
.................... USB_EP0_TX_SIZE, USB_EP1_TX_SIZE, USB_EP2_TX_SIZE,
.................... USB_EP3_TX_SIZE, USB_EP4_TX_SIZE, USB_EP5_TX_SIZE,
.................... USB_EP6_TX_SIZE, USB_EP7_TX_SIZE, USB_EP8_TX_SIZE,
.................... USB_EP9_TX_SIZE, USB_EP10_TX_SIZE, USB_EP11_TX_SIZE,
.................... USB_EP12_TX_SIZE, USB_EP13_TX_SIZE, USB_EP14_TX_SIZE,
.................... USB_EP15_TX_SIZE
.................... };
....................
.................... const unsigned int16 usb_ep_rx_size[16]={
.................... USB_EP0_RX_SIZE, USB_EP1_RX_SIZE, USB_EP2_RX_SIZE,
.................... USB_EP3_RX_SIZE, USB_EP4_RX_SIZE, USB_EP5_RX_SIZE,
.................... USB_EP6_RX_SIZE, USB_EP7_RX_SIZE, USB_EP8_RX_SIZE,
.................... USB_EP9_RX_SIZE, USB_EP10_RX_SIZE, USB_EP11_RX_SIZE,
.................... USB_EP12_RX_SIZE, USB_EP13_RX_SIZE, USB_EP14_RX_SIZE,
.................... USB_EP15_RX_SIZE
.................... };
....................
.................... #ENDIF
....................
....................
.................... //if you are worried that the PIC is not receiving packets because a bug in the
.................... //DATA0/DATA1 synch code, you can set this to TRUE to ignore the DTS on
.................... //receiving.
.................... #ifndef USB_IGNORE_RX_DTS
.................... #define USB_IGNORE_RX_DTS FALSE
.................... #endif
....................
.................... #ifndef USB_IGNORE_TX_DTS
.................... #define USB_IGNORE_TX_DTS FALSE
.................... #endif
....................
.................... #if ((getenv("DEVICE")=="PIC18F87J50") || (getenv("DEVICE")=="PIC18F86J55") || \
.................... (getenv("DEVICE")=="PIC18F86J50") || (getenv("DEVICE")=="PIC18F85J50") || \
.................... (getenv("DEVICE")=="PIC18F67J50") || (getenv("DEVICE")=="PIC18F66J55") || \
.................... (getenv("DEVICE")=="PIC18F66J50") || (getenv("DEVICE")=="PIC18F65J50"))
.................... #define __USB_87J50__
.................... #define USB_TOTAL_RAM_SPACE ((int16)getenv("RAM")-0x400)
.................... #define USB_RAM_START 0x400
.................... #define USB_LAST_ALLOWED_ENDPOINT 16
.................... #elif ((getenv("DEVICE")=="PIC18F2450") || (getenv("DEVICE")=="PIC18F4450"))
.................... #define __USB_4450__
.................... #define USB_TOTAL_RAM_SPACE ((int16)0x100)
.................... #define USB_RAM_START 0x400
.................... #define USB_LAST_ALLOWED_ENDPOINT 3
.................... #elif ((getenv("DEVICE")=="PIC18F13K50") || (getenv("DEVICE")=="PIC18F14K50"))
.................... #define __USB_K50__
.................... #define USB_TOTAL_RAM_SPACE ((int16)0x200)
.................... #define USB_RAM_START 0x200
.................... #define USB_LAST_ALLOWED_ENDPOINT 8
.................... #elif ((getenv("DEVICE")=="PIC18F2455") || (getenv("DEVICE")=="PIC18F2550") || \
.................... (getenv("DEVICE")=="PIC18F4455") || (getenv("DEVICE")=="PIC18F4550") || \
.................... (getenv("DEVICE")=="PIC18F2458") || (getenv("DEVICE")=="PIC18F2553") || \
.................... (getenv("DEVICE")=="PIC18F4458") || (getenv("DEVICE")=="PIC18F4553") \
.................... )
.................... #define __USB_4550__
.................... #define USB_TOTAL_RAM_SPACE ((int16)0x400)
.................... #define USB_RAM_START 0x400
.................... #define USB_LAST_ALLOWED_ENDPOINT 16
.................... #else
.................... #error Unknown PIC device, USB not supported in this library.
.................... #endif
....................
.................... #if USB_EP15_TX_SIZE || USB_EP15_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 15
.................... #elif USB_EP14_TX_SIZE || USB_EP14_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 14
.................... #elif USB_EP13_TX_SIZE || USB_EP13_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 13
.................... #elif USB_EP12_TX_SIZE || USB_EP12_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 12
.................... #elif USB_EP11_TX_SIZE || USB_EP11_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 11
.................... #elif USB_EP10_TX_SIZE || USB_EP10_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 10
.................... #elif USB_EP9_TX_SIZE || USB_EP9_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 9
.................... #elif USB_EP8_TX_SIZE || USB_EP8_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 8
.................... #elif USB_EP7_TX_SIZE || USB_EP7_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 7
.................... #elif USB_EP6_TX_SIZE || USB_EP6_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 6
.................... #elif USB_EP5_TX_SIZE || USB_EP5_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 5
.................... #elif USB_EP4_TX_SIZE || USB_EP4_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 4
.................... #elif USB_EP3_TX_SIZE || USB_EP3_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 3
.................... #elif USB_EP2_TX_SIZE || USB_EP2_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 2
.................... #elif USB_EP1_TX_SIZE || USB_EP1_RX_SIZE
.................... #define USB_LAST_DEFINED_ENDPOINT 1
.................... #else
.................... #define USB_LAST_DEFINED_ENDPOINT 0
.................... #endif
....................
.................... #define USB_CONTROL_REGISTER_SIZE ((USB_LAST_DEFINED_ENDPOINT+1)*8)
....................
.................... #define USB_DATA_BUFFER_NEEDED (USB_EP0_TX_SIZE+USB_EP0_RX_SIZE+USB_EP1_TX_SIZE+\
.................... USB_EP1_RX_SIZE+USB_EP2_TX_SIZE+USB_EP2_RX_SIZE+\
.................... USB_EP3_TX_SIZE+USB_EP3_RX_SIZE+USB_EP4_TX_SIZE+\
.................... USB_EP4_RX_SIZE+USB_EP5_TX_SIZE+USB_EP5_RX_SIZE+\
.................... USB_EP6_TX_SIZE+USB_EP6_RX_SIZE+USB_EP7_TX_SIZE+\
.................... USB_EP7_RX_SIZE+USB_EP8_TX_SIZE+USB_EP8_RX_SIZE+\
.................... USB_EP9_TX_SIZE+USB_EP9_RX_SIZE+USB_EP10_TX_SIZE+\
.................... USB_EP10_RX_SIZE+USB_EP11_TX_SIZE+USB_EP11_RX_SIZE+\
.................... USB_EP12_TX_SIZE+USB_EP12_RX_SIZE+USB_EP13_TX_SIZE+\
.................... USB_EP13_RX_SIZE+USB_EP14_TX_SIZE+USB_EP14_RX_SIZE+\
.................... USB_EP15_TX_SIZE+USB_EP15_RX_SIZE)
....................
.................... #if ((USB_DATA_BUFFER_NEEDED+USB_CONTROL_REGISTER_SIZE) > USB_TOTAL_RAM_SPACE)
.................... #error You are trying to allocate more memory for endpoints than the PIC can handle
.................... #endif
....................
.................... #if (USB_LAST_DEFINED_ENDPOINT > USB_LAST_ALLOWED_ENDPOINT)
.................... #error You are trying ot use an invalid endpoint for this hardware!
.................... #endif
....................
.................... #define USB_DATA_BUFFER_LOCATION ((int16)USB_RAM_START+USB_CONTROL_REGISTER_SIZE)
....................
.................... typedef struct
.................... {
.................... int8 stat;
.................... int8 cnt;
.................... int16 addr;
.................... } STRUCT_BD;
....................
.................... struct
.................... {
.................... struct
.................... {
.................... STRUCT_BD out; //pc -> pic
.................... STRUCT_BD in; //pc <- pic
.................... } bd[USB_LAST_DEFINED_ENDPOINT+1];
.................... union
.................... {
.................... struct
.................... {
.................... int8 ep0_rx_buffer[USB_MAX_EP0_PACKET_LENGTH];
.................... int8 ep0_tx_buffer[USB_MAX_EP0_PACKET_LENGTH];
....................
.................... //these buffer definitions needed for CDC library
.................... #if USB_EP1_RX_SIZE
.................... int8 ep1_rx_buffer[USB_EP1_RX_SIZE];
.................... #endif
.................... #if USB_EP1_TX_SIZE
.................... int8 ep1_tx_buffer[USB_EP1_TX_SIZE];
.................... #endif
.................... #if USB_EP2_RX_SIZE
.................... int8 ep2_rx_buffer[USB_EP2_RX_SIZE];
.................... #endif
.................... #if USB_EP2_TX_SIZE
.................... int8 ep2_tx_buffer[USB_EP2_TX_SIZE];
.................... #endif
.................... };
.................... int8 general[USB_DATA_BUFFER_NEEDED];
.................... } buffer;
.................... } g_USBRAM;
.................... #locate g_USBRAM=USB_RAM_START
....................
.................... #define usb_ep0_rx_buffer g_USBRAM.buffer.ep0_rx_buffer
.................... #define usb_ep0_tx_buffer g_USBRAM.buffer.ep0_tx_buffer
....................
.................... //these buffer definitions needed for CDC library
.................... #define usb_ep1_rx_buffer g_USBRAM.buffer.ep1_rx_buffer
.................... #define usb_ep1_tx_buffer g_USBRAM.buffer.ep1_tx_buffer
.................... #define usb_ep2_rx_buffer g_USBRAM.buffer.ep2_rx_buffer
.................... #define usb_ep2_tx_buffer g_USBRAM.buffer.ep2_tx_buffer
....................
.................... #define debug_usb(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z)
.................... //#define debug_usb printf
.................... //#define debug_putc putc_tbe
.................... #define debug_display_ram(x,y)
.................... /*
.................... void debug_display_ram(int8 len, int8 *ptr) {
.................... int8 max=16;
.................... debug_usb(debug_putc,"%U - ",len);
.................... if (max>len) {max=len;}
.................... while(max--) {
.................... debug_usb(debug_putc,"%X",*ptr);
.................... len--;
.................... ptr++;
.................... }
.................... if (len) {debug_usb(debug_putc,"...");}
.................... }
.................... */
....................
.................... //if you enable this it will keep a counter of the 6 possible errors the
.................... //pic can detect. disabling this will save you ROM, RAM and execution time.
.................... #if !defined(USB_USE_ERROR_COUNTER)
.................... #define USB_USE_ERROR_COUNTER FALSE
.................... #endif
....................
.................... #define USB_PING_PONG_MODE_OFF 0 //no ping pong
.................... #define USB_PING_PONG_MODE_E0 1 //ping pong endpoint 0 only
.................... #define USB_PING_PONG_MODE_ON 2 //ping pong all endpoints
....................
.................... //NOTE - PING PONG MODE IS NOT SUPPORTED BY CCS!
.................... #if !defined(USB_PING_PONG_MODE)
.................... #define USB_PING_PONG_MODE USB_PING_PONG_MODE_OFF
.................... #endif
....................
.................... #if USB_USE_ERROR_COUNTER
.................... int ERROR_COUNTER[6];
.................... #endif
....................
.................... //---pic18fxx5x memory locations
.................... #if defined(__USB_4550__) || defined(__USB_4450__)
.................... #byte UFRML = 0xF66
.................... #byte UFRMH = 0xF67
.................... #byte UIR = 0xF68
.................... #byte UIE = 0xF69
.................... #byte UEIR = 0xF6A
.................... #byte UEIE = 0xF6B
.................... #byte USTAT = 0xF6C
.................... #byte UCON = 0xF6D
.................... #byte UADDR = 0xF6E
.................... #byte UCFG = 0xF6F
.................... #define UEP0_LOC 0xF70
.................... #elif defined(__USB_K50__)
.................... #byte UFRML = 0xF5D
.................... #byte UFRMH = 0xF5E
.................... #byte UIR = 0xF62
.................... #byte UIE = 0xF60
.................... #byte UEIR = 0xF5F
.................... #byte UEIE = 0xF5B
.................... #byte USTAT = 0xF63
.................... #byte UCON = 0xF64
.................... #byte UADDR = 0xF5C
.................... #byte UCFG = 0xF61
.................... #define UEP0_LOC 0xF53
.................... #else
.................... #byte UFRML = 0xF60
.................... #byte UFRMH = 0xF61
.................... #byte UIR = 0xF62
.................... #byte UIE = 0xF5C
.................... #byte UEIR = 0xF63
.................... #byte UEIE = 0xF5D
.................... #byte USTAT = 0xF64
.................... #byte UCON = 0xF65
.................... #byte UADDR = 0xF5E
.................... #byte UCFG = 0xF5F
.................... #define UEP0_LOC 0xF4C
.................... #endif
....................
.................... int8 g_UEP[16];
.................... #locate g_UEP=UEP0_LOC
.................... #define UEP(x) g_UEP[x]
....................
.................... #BIT UIR_SOF = UIR.6
.................... #BIT UIR_STALL = UIR.5
.................... #BIT UIR_IDLE = UIR.4
.................... #BIT UIR_TRN = UIR.3
.................... #BIT UIR_ACTV = UIR.2
.................... #BIT UIR_UERR = UIR.1
.................... #BIT UIR_URST = UIR.0
....................
.................... #BIT UIE_SOF = UIE.6
.................... #BIT UIE_STALL = UIE.5
.................... #BIT UIE_IDLE = UIE.4
.................... #BIT UIE_TRN = UIE.3
.................... #BIT UIE_ACTV = UIE.2
.................... #BIT UIE_UERR = UIE.1
.................... #BIT UIE_URST = UIE.0
....................
.................... #bit UCON_PBRST=UCON.6
.................... #bit UCON_SE0=UCON.5
.................... #bit UCON_PKTDIS=UCON.4
.................... #bit UCON_USBEN=UCON.3
.................... #bit UCON_RESUME=UCON.2
.................... #bit UCON_SUSPND=UCON.1
....................
.................... #if (USB_PING_PONG_MODE==USB_PING_PONG_MODE_OFF)
.................... #define EP_BDxST_O(x) g_USBRAM.bd[x].out.stat
.................... #define EP_BDxCNT_O(x) g_USBRAM.bd[x].out.cnt
.................... #define EP_BDxADR_O(x) g_USBRAM.bd[x].out.addr
.................... #define EP_BDxST_I(x) g_USBRAM.bd[x].in.stat
.................... #define EP_BDxCNT_I(x) g_USBRAM.bd[x].in.cnt
.................... #define EP_BDxADR_I(x) g_USBRAM.bd[x].in.addr
.................... #else
.................... #error Right now this driver only supports no ping pong
.................... #endif
....................
.................... //See UEPn (0xF70-0xF7F)
.................... #define ENDPT_DISABLED 0x00 //endpoint not used
.................... #define ENDPT_IN_ONLY 0x02 //endpoint supports IN transactions only
.................... #define ENDPT_OUT_ONLY 0x04 //endpoint supports OUT transactions only
.................... #define ENDPT_CONTROL 0x06 //Supports IN, OUT and CONTROL transactions - Only use with EP0
.................... #define ENDPT_NON_CONTROL 0x0E //Supports both IN and OUT transactions
....................
.................... //Define the states that the USB interface can be in
.................... enum {USB_STATE_DETACHED=0, USB_STATE_ATTACHED=1, USB_STATE_POWERED=2, USB_STATE_DEFAULT=3,
.................... USB_STATE_ADDRESS=4, USB_STATE_CONFIGURED=5} usb_state=0;
....................
.................... //--BDendST has their PIDs upshifed 2
.................... #define USB_PIC_PID_IN 0x24 //device to host transactions
.................... #define USB_PIC_PID_OUT 0x04 //host to device transactions
.................... #define USB_PIC_PID_SETUP 0x34 //host to device setup transaction
....................
.................... #define USTAT_IN_E0 4
.................... #define USTAT_OUT_SETUP_E0 0
....................
.................... #define __USB_UIF_RESET 0x01
.................... #define __USB_UIF_ERROR 0x02
.................... #define __USB_UIF_ACTIVE 0x04
.................... #define __USB_UIF_TOKEN 0x08
.................... #define __USB_UIF_IDLE 0x10
.................... #define __USB_UIF_STALL 0x20
.................... #define __USB_UIF_SOF 0x40
....................
.................... #if USB_USE_ERROR_COUNTER
.................... #define STANDARD_INTS __USB_UIF_STALL|__USB_UIF_IDLE|__USB_UIF_TOKEN|__USB_UIF_ACTIVE|__USB_UIF_ERROR|__USB_UIF_RESET
.................... #else
.................... #define STANDARD_INTS __USB_UIF_STALL|__USB_UIF_IDLE|__USB_UIF_TOKEN|__USB_UIF_ACTIVE|__USB_UIF_RESET
.................... #endif
....................
.................... #define __USB_UCFG_UTEYE 0x80
.................... #if defined(__USB_4550__)
.................... #define __USB_UCFG_UOEMON 0x40
.................... #endif
.................... #define __USB_UCFG_UPUEN 0x10
.................... #define __USB_UCFG_UTRDIS 0x08
.................... #define __USB_UCFG_FSEN 0x04
....................
.................... #if USB_USE_FULL_SPEED
.................... #define __UCFG_VAL_ENABLED__ (__USB_UCFG_UPUEN | __USB_UCFG_FSEN | USB_PING_PONG_MODE)
.................... #else
.................... #define __UCFG_VAL_ENABLED__ (__USB_UCFG_UPUEN | USB_PING_PONG_MODE);
.................... #endif
....................
.................... #define __UCFG_VAL_DISABLED__ 0x08
....................
.................... int8 __setup_0_tx_size;
....................
.................... //interrupt handler, specific to PIC18Fxx5x peripheral only
.................... void usb_handle_interrupt();
.................... void usb_isr_rst();
.................... void usb_isr_uerr();
.................... void usb_isr_sof(void);
.................... void usb_isr_activity();
.................... void usb_isr_uidle();
.................... void usb_isr_tok_dne();
.................... void usb_isr_stall(void);
.................... void usb_init_ep0_setup(void);
....................
.................... //// BEGIN User Functions:
....................
.................... // see usb_hw_layer.h for more documentation
.................... int1 usb_kbhit(int8 en)
.................... {
.................... return((UEP(en)!=ENDPT_DISABLED)&&(!bit_test(EP_BDxST_O(en),7)));
.................... }
....................
.................... // see usb_hw_layer.h for documentation
.................... int1 usb_tbe(int8 en)
.................... {
.................... return((UEP(en)!=ENDPT_DISABLED)&&(!bit_test(EP_BDxST_I(en),7)));
*
0D06: CLRF 03
0D08: MOVLB 7
0D0A: MOVF x47,W
0D0C: ADDLW 70
0D0E: MOVWF FE9
0D10: MOVLW 0F
0D12: ADDWFC 03,W
0D14: MOVWF FEA
0D16: MOVF FEF,F
0D18: BZ 0D50
0D1A: CLRF x49
0D1C: MOVFF 747,748
0D20: CLRF x4B
0D22: MOVLW 08
0D24: MOVWF x4A
0D26: MOVLB 0
0D28: CALL 02BA
0D2C: MOVFF 02,749
0D30: MOVFF 01,748
0D34: MOVLW 04
0D36: MOVLB 7
0D38: ADDWF x48,F
0D3A: MOVLW 00
0D3C: ADDWFC x49,F
0D3E: MOVFF 748,FE9
0D42: MOVLW 04
0D44: ADDWF x49,W
0D46: MOVWF FEA
0D48: MOVFF FEF,748
0D4C: BTFSS x48.7
0D4E: BRA 0D54
0D50: MOVLW 00
0D52: BRA 0D56
0D54: MOVLW 01
0D56: MOVWF 01
.................... }
0D58: MOVLB 0
0D5A: RETLW 00
....................
.................... // see usb_hw_layer.h for documentation
.................... void usb_detach(void)
.................... {
.................... UCON = 0; //disable USB hardware
*
12F4: CLRF F6D
.................... UIE = 0; //disable USB interrupts
12F6: CLRF F69
.................... UCFG = __UCFG_VAL_DISABLED__;
12F8: MOVLW 08
12FA: MOVWF F6F
....................
.................... // set D+/D- to inputs
.................... #if defined(__USB_87J50__)
.................... set_tris_f(get_tris_f() | 0x18);
.................... #elif defined(__USB_K50__)
.................... set_tris_a(get_tris_a() | 0x3);
.................... #else
.................... set_tris_c(get_tris_c() | 0x30);
12FC: MOVF F94,W
12FE: IORLW 30
1300: MOVLB 6
1302: MOVWF F94
.................... #endif
....................
.................... usb_state = USB_STATE_DETACHED;
1304: CLRF 24
1306: CLRF 18
1308: BTFSC FF2.7
130A: BSF 18.7
130C: BCF FF2.7
....................
.................... usb_token_reset(); //clear the chapter9 stack
130E: MOVLB 0
1310: CALL 037E
1314: BTFSC 18.7
1316: BSF FF2.7
.................... //__usb_kbhit_status=0;
.................... }
1318: GOTO 131E (RETURN)
....................
.................... // see usb_hw_layer.h for documentation
.................... void usb_attach(void)
.................... {
*
1322: CLRF 18
1324: BTFSC FF2.7
1326: BSF 18.7
1328: BCF FF2.7
.................... usb_token_reset();
132A: CALL 037E
132E: BTFSC 18.7
1330: BSF FF2.7
.................... UCON = 0;
1332: CLRF F6D
.................... UCFG = __UCFG_VAL_ENABLED__;
1334: MOVLW 14
1336: MOVWF F6F
.................... UIE = 0; // Mask all USB interrupts
1338: CLRF F69
.................... UCON_USBEN = 1; // Enable module & attach to bus
133A: BSF F6D.3
.................... usb_state = USB_STATE_ATTACHED; // Defined in usbmmap.c & .h
133C: MOVLW 01
133E: MOVWF 24
.................... }
1340: GOTO 134A (RETURN)
....................
.................... // see usb_hw_layer.h for documentation
.................... void usb_init_cs(void)
.................... {
.................... usb_detach();
*
131C: BRA 12F4
.................... }
131E: GOTO 136A (RETURN)
....................
.................... // see usb_hw_layer.h for documentation
.................... void usb_task(void)
.................... {
.................... if (usb_attached())
.................... {
.................... if (UCON_USBEN==0)
*
1344: BTFSC F6D.3
1346: BRA 134A
.................... {
.................... debug_usb(debug_putc, "\r\n\nUSB TASK: ATTACH");
.................... usb_attach();
1348: BRA 1322
.................... }
.................... }
.................... else
.................... {
.................... if (UCON_USBEN==1)
.................... {
.................... debug_usb(debug_putc, "\r\n\nUSB TASK: DE-ATTACH");
.................... usb_detach();
.................... }
.................... }
....................
.................... if ((usb_state == USB_STATE_ATTACHED)&&(!UCON_SE0))
134A: DECFSZ 24,W
134C: BRA 1364
134E: BTFSC F6D.5
1350: BRA 1364
.................... {
.................... UIR=0;
1352: CLRF F68
.................... UIE=0;
1354: CLRF F69
.................... enable_interrupts(INT_USB);
1356: BSF FA0.5
.................... enable_interrupts(GLOBAL);
1358: MOVLW C0
135A: IORWF FF2,F
.................... UIE=__USB_UIF_IDLE | __USB_UIF_RESET; //enable IDLE and RESET USB ISR
135C: MOVLW 11
135E: MOVWF F69
.................... usb_state=USB_STATE_POWERED;
1360: MOVLW 02
1362: MOVWF 24
.................... debug_usb(debug_putc, "\r\n\nUSB TASK: POWERED");
.................... }
.................... }
1364: GOTO 136C (RETURN)
....................
.................... // see usb_hw_layer.h for documentation
.................... void usb_init(void)
.................... {
.................... usb_init_cs();
1368: BRA 131C
....................
.................... do
.................... {
.................... usb_task();
136A: BRA 1344
.................... } while (usb_state != USB_STATE_POWERED);
136C: MOVF 24,W
136E: SUBLW 02
1370: BNZ 136A
.................... }
1372: GOTO 1FE4 (RETURN)
....................
....................
.................... // see pic18_usb.h for documentation
.................... int1 usb_flush_in(int8 endpoint, int16 len, USB_DTS_BIT tgl)
.................... {
.................... int8 i;
....................
.................... debug_usb(debug_putc,"\r\nPUT %X %U %LU",endpoint, tgl, len);
....................
.................... if (usb_tbe(endpoint))
*
0D5C: MOVFF 742,747
0D60: RCALL 0D06
0D62: MOVF 01,F
0D64: BTFSC FD8.2
0D66: BRA 0E74
.................... {
.................... EP_BDxCNT_I(endpoint)=len;
0D68: MOVLB 7
0D6A: CLRF x49
0D6C: MOVFF 742,748
0D70: CLRF x4B
0D72: MOVLW 08
0D74: MOVWF x4A
0D76: MOVLB 0
0D78: CALL 02BA
0D7C: MOVFF 02,748
0D80: MOVFF 01,747
0D84: MOVLW 04
0D86: MOVLB 7
0D88: ADDWF x47,F
0D8A: MOVLW 00
0D8C: ADDWFC x48,F
0D8E: MOVLW 01
0D90: ADDWF x47,W
0D92: MOVWF 01
0D94: MOVLW 00
0D96: ADDWFC x48,W
0D98: MOVWF 03
0D9A: MOVFF 01,FE9
0D9E: MOVLW 04
0DA0: ADDWF 03,W
0DA2: MOVWF FEA
0DA4: MOVFF 743,FEF
....................
.................... debug_display_ram(len, EP_BDxADR_I(endpoint));
....................
.................... #if USB_IGNORE_TX_DTS
.................... i=0x80;
.................... #else
.................... if (tgl == USB_DTS_TOGGLE)
0DA8: MOVF x45,W
0DAA: SUBLW 02
0DAC: BNZ 0DEE
.................... {
.................... i = EP_BDxST_I(endpoint);
0DAE: CLRF x49
0DB0: MOVFF 742,748
0DB4: CLRF x4B
0DB6: MOVLW 08
0DB8: MOVWF x4A
0DBA: MOVLB 0
0DBC: CALL 02BA
0DC0: MOVFF 02,748
0DC4: MOVFF 01,747
0DC8: MOVLW 04
0DCA: MOVLB 7
0DCC: ADDWF x47,F
0DCE: MOVLW 00
0DD0: ADDWFC x48,F
0DD2: MOVFF 747,FE9
0DD6: MOVLW 04
0DD8: ADDWF x48,W
0DDA: MOVWF FEA
0DDC: MOVFF FEF,746
.................... if (bit_test(i,6))
0DE0: BTFSS x46.6
0DE2: BRA 0DE8
.................... tgl = USB_DTS_DATA0; //was DATA1, goto DATA0
0DE4: CLRF x45
.................... else
0DE6: BRA 0DEC
.................... tgl = USB_DTS_DATA1; //was DATA0, goto DATA1
0DE8: MOVLW 01
0DEA: MOVWF x45
.................... }
.................... else if (tgl == USB_DTS_USERX)
0DEC: BRA 0E22
0DEE: MOVF x45,W
0DF0: SUBLW 04
0DF2: BNZ 0E22
.................... {
.................... i = EP_BDxST_O(endpoint);
0DF4: CLRF x49
0DF6: MOVFF 742,748
0DFA: CLRF x4B
0DFC: MOVLW 08
0DFE: MOVWF x4A
0E00: MOVLB 0
0E02: CALL 02BA
0E06: MOVLB 7
0E08: MOVFF 01,FE9
0E0C: MOVLW 04
0E0E: ADDWF 02,W
0E10: MOVWF FEA
0E12: MOVFF FEF,746
.................... if (bit_test(i,6))
0E16: BTFSS x46.6
0E18: BRA 0E20
.................... tgl = USB_DTS_DATA1;
0E1A: MOVLW 01
0E1C: MOVWF x45
.................... else
0E1E: BRA 0E22
.................... tgl = USB_DTS_DATA0;
0E20: CLRF x45
.................... }
.................... if (tgl == USB_DTS_DATA1)
0E22: DECFSZ x45,W
0E24: BRA 0E2C
.................... i=0xC8; //DATA1, UOWN
0E26: MOVLW C8
0E28: MOVWF x46
.................... else //if (tgl == USB_DTS_DATA0)
0E2A: BRA 0E30
.................... i=0x88; //DATA0, UOWN
0E2C: MOVLW 88
0E2E: MOVWF x46
.................... #endif
....................
.................... //set BC8 and BC9
.................... if (bit_test(len,8)) {bit_set(i,0);}
0E30: BTFSC x44.0
0E32: BSF x46.0
.................... if (bit_test(len,9)) {bit_set(i,1);}
0E34: BTFSC x44.1
0E36: BSF x46.1
....................
.................... debug_usb(debug_putc, " %X", i);
....................
.................... EP_BDxST_I(endpoint) = i;//save changes
0E38: CLRF x49
0E3A: MOVFF 742,748
0E3E: CLRF x4B
0E40: MOVLW 08
0E42: MOVWF x4A
0E44: MOVLB 0
0E46: CALL 02BA
0E4A: MOVFF 02,748
0E4E: MOVFF 01,747
0E52: MOVLW 04
0E54: MOVLB 7
0E56: ADDWF x47,F
0E58: MOVLW 00
0E5A: ADDWFC x48,F
0E5C: MOVFF 747,FE9
0E60: MOVLW 04
0E62: ADDWF x48,W
0E64: MOVWF FEA
0E66: MOVFF 746,FEF
....................
.................... //putc('!');
....................
.................... return(1);
0E6A: MOVLW 01
0E6C: MOVWF 01
0E6E: BRA 0E7A
.................... }
.................... else
0E70: BRA 0E72
0E72: MOVLB 0
.................... {
.................... //putc('_');
.................... debug_usb(debug_putc,"\r\nPUT ERR");
.................... }
.................... return(0);
0E74: MOVLW 00
0E76: MOVWF 01
0E78: MOVLB 7
.................... }
0E7A: MOVLB 0
0E7C: RETLW 00
....................
.................... // see usb_hw_layer.h for documentation
.................... int1 usb_put_packet(int8 endpoint, int8 * ptr, int16 len, USB_DTS_BIT tgl)
.................... {
.................... int8 * buff_add;
....................
.................... if (usb_tbe(endpoint))
*
0F88: MOVFF 73A,747
0F8C: RCALL 0D06
0F8E: MOVF 01,F
0F90: BZ 1026
.................... {
.................... buff_add = EP_BDxADR_I(endpoint);
0F92: MOVLB 7
0F94: CLRF x49
0F96: MOVFF 73A,748
0F9A: CLRF x4B
0F9C: MOVLW 08
0F9E: MOVWF x4A
0FA0: MOVLB 0
0FA2: CALL 02BA
0FA6: MOVFF 02,743
0FAA: MOVFF 01,742
0FAE: MOVLW 04
0FB0: MOVLB 7
0FB2: ADDWF x42,F
0FB4: MOVLW 00
0FB6: ADDWFC x43,F
0FB8: MOVLW 02
0FBA: ADDWF x42,W
0FBC: MOVWF 01
0FBE: MOVLW 00
0FC0: ADDWFC x43,W
0FC2: MOVWF 03
0FC4: MOVFF 01,FE9
0FC8: MOVLW 04
0FCA: ADDWF 03,W
0FCC: MOVWF FEA
0FCE: MOVFF FEC,03
0FD2: MOVF FED,F
0FD4: MOVFF FEF,740
0FD8: MOVFF 03,741
.................... memcpy(buff_add, ptr, len);
0FDC: MOVFF 741,FEA
0FE0: MOVFF 740,FE9
0FE4: MOVFF 73C,FE2
0FE8: MOVFF 73B,FE1
0FEC: MOVFF 73E,02
0FF0: MOVFF 73D,01
0FF4: MOVF 01,F
0FF6: BZ 0FFC
0FF8: INCF 02,F
0FFA: BRA 1000
0FFC: MOVF 02,F
0FFE: BZ 100C
1000: MOVFF FE6,FEE
1004: DECFSZ 01,F
1006: BRA 1000
1008: DECFSZ 02,F
100A: BRA 1000
....................
.................... return(usb_flush_in(endpoint, len, tgl));
100C: MOVFF 73A,742
1010: MOVFF 73E,744
1014: MOVFF 73D,743
1018: MOVFF 73F,745
101C: MOVLB 0
101E: RCALL 0D5C
1020: MOVF 01,W
1022: BRA 102A
.................... }
.................... else
1024: BRA 1026
.................... {
.................... //putc('-');
.................... //printf("%X", EP_BDxST_I(endpoint));
.................... debug_usb(debug_putc,"\r\nPUT ERR");
.................... }
....................
.................... return(0);
1026: MOVLW 00
1028: MOVWF 01
.................... }
102A: RETLW 00
....................
.................... // see pic18_usb.h for documentation
.................... void usb_flush_out(int8 endpoint, USB_DTS_BIT tgl)
.................... {
.................... int8 i;
.................... int16 len;
....................
.................... #if USB_IGNORE_RX_DTS
.................... if (tgl == USB_DTS_STALL)
.................... {
.................... debug_usb(debug_putc, '*');
.................... EP_BDxCNT_O(endpoint) = 0x84;
.................... EP_BDxST_I(endpoint) = 0x84;
.................... return;
.................... }
.................... else
.................... i=0x80;
.................... #else
.................... i = EP_BDxST_O(endpoint);
*
0BEA: MOVLB 7
0BEC: CLRF x49
0BEE: MOVFF 6FD,748
0BF2: CLRF x4B
0BF4: MOVLW 08
0BF6: MOVWF x4A
0BF8: MOVLB 0
0BFA: CALL 02BA
0BFE: MOVLB 7
0C00: MOVFF 01,FE9
0C04: MOVLW 04
0C06: ADDWF 02,W
0C08: MOVWF FEA
0C0A: MOVFF FEF,6FF
0C0E: MOVLB 6
.................... if (tgl == USB_DTS_TOGGLE)
0C10: MOVF xFE,W
0C12: SUBLW 02
0C14: BNZ 0C22
.................... {
.................... if (bit_test(i,6))
0C16: BTFSS xFF.6
0C18: BRA 0C1E
.................... tgl = USB_DTS_DATA0; //was DATA1, goto DATA0
0C1A: CLRF xFE
.................... else
0C1C: BRA 0C22
.................... tgl = USB_DTS_DATA1; //was DATA0, goto DATA1
0C1E: MOVLW 01
0C20: MOVWF xFE
.................... }
.................... if (tgl == USB_DTS_STALL)
0C22: MOVF xFE,W
0C24: SUBLW 03
0C26: BNZ 0C64
.................... {
.................... i = 0x84;
0C28: MOVLW 84
0C2A: MOVWF xFF
.................... EP_BDxST_I(endpoint) = 0x84; //stall both in and out endpoints
0C2C: MOVLB 7
0C2E: CLRF x49
0C30: MOVFF 6FD,748
0C34: CLRF x4B
0C36: MOVLW 08
0C38: MOVWF x4A
0C3A: MOVLB 0
0C3C: CALL 02BA
0C40: MOVFF 02,703
0C44: MOVFF 01,702
0C48: MOVLW 04
0C4A: MOVLB 7
0C4C: ADDWF x02,F
0C4E: MOVLW 00
0C50: ADDWFC x03,F
0C52: MOVFF 702,FE9
0C56: MOVLW 04
0C58: ADDWF x03,W
0C5A: MOVWF FEA
0C5C: MOVLW 84
0C5E: MOVWF FEF
.................... }
.................... else if (tgl == USB_DTS_DATA1)
0C60: BRA 0C74
0C62: MOVLB 6
0C64: DECFSZ xFE,W
0C66: BRA 0C6E
.................... i = 0xC8; //DATA1, UOWN
0C68: MOVLW C8
0C6A: MOVWF xFF
.................... else //if (tgl == USB_DTS_DATA0)
0C6C: BRA 0C72
.................... i = 0x88; //DATA0, UOWN
0C6E: MOVLW 88
0C70: MOVWF xFF
0C72: MOVLB 7
.................... #endif
....................
.................... //bit_clear(__usb_kbhit_status,endpoint);
....................
.................... len = usb_ep_rx_size[endpoint];
0C74: BCF FD8.0
0C76: MOVLB 6
0C78: RLCF xFD,W
0C7A: CLRF 03
0C7C: MOVFF FF2,702
0C80: BCF FF2.7
0C82: MOVLB 0
0C84: CALL 011A
0C88: TBLRD*+
0C8A: MOVFF FF5,03
0C8E: MOVLB 7
0C90: BTFSC x02.7
0C92: BSF FF2.7
0C94: MOVWF x00
0C96: MOVFF 03,701
.................... EP_BDxCNT_O(endpoint) = len;
0C9A: CLRF x49
0C9C: MOVFF 6FD,748
0CA0: CLRF x4B
0CA2: MOVLW 08
0CA4: MOVWF x4A
0CA6: MOVLB 0
0CA8: CALL 02BA
0CAC: MOVFF 01,702
0CB0: MOVLW 01
0CB2: MOVLB 7
0CB4: ADDWF 01,W
0CB6: MOVWF 01
0CB8: MOVLW 00
0CBA: ADDWFC 02,W
0CBC: MOVWF 03
0CBE: MOVFF 01,FE9
0CC2: MOVLW 04
0CC4: ADDWF 03,W
0CC6: MOVWF FEA
0CC8: MOVFF 700,FEF
.................... if (bit_test(len,8)) {bit_set(i,0);}
0CCC: BTFSS x01.0
0CCE: BRA 0CD6
0CD0: MOVLB 6
0CD2: BSF xFF.0
0CD4: MOVLB 7
.................... if (bit_test(len,9)) {bit_set(i,1);}
0CD6: BTFSS x01.1
0CD8: BRA 0CE0
0CDA: MOVLB 6
0CDC: BSF xFF.1
0CDE: MOVLB 7
....................
.................... EP_BDxST_O(endpoint) = i;
0CE0: CLRF x49
0CE2: MOVFF 6FD,748
0CE6: CLRF x4B
0CE8: MOVLW 08
0CEA: MOVWF x4A
0CEC: MOVLB 0
0CEE: CALL 02BA
0CF2: MOVLB 7
0CF4: MOVFF 01,FE9
0CF8: MOVLW 04
0CFA: ADDWF 02,W
0CFC: MOVWF FEA
0CFE: MOVFF 6FF,FEF
.................... }
0D02: MOVLB 0
0D04: RETLW 00
....................
.................... // see pic18_usb.h for documentation
.................... int16 usb_rx_packet_size(int8 endpoint)
.................... {
.................... return(EP_BDxCNT_O(endpoint));
*
0EE6: MOVLB 7
0EE8: CLRF x49
0EEA: MOVFF 6FE,748
0EEE: CLRF x4B
0EF0: MOVLW 08
0EF2: MOVWF x4A
0EF4: MOVLB 0
0EF6: CALL 02BA
0EFA: MOVFF 02,700
0EFE: MOVFF 01,6FF
0F02: MOVLW 01
0F04: MOVLB 6
0F06: ADDWF 01,W
0F08: MOVWF 01
0F0A: MOVLW 00
0F0C: MOVLB 7
0F0E: ADDWFC 02,W
0F10: MOVWF 03
0F12: MOVFF 01,FE9
0F16: MOVLW 04
0F18: ADDWF 03,W
0F1A: MOVWF FEA
0F1C: CLRF 03
0F1E: MOVFF FEF,01
0F22: MOVFF 03,02
.................... }
0F26: MOVLB 0
0F28: GOTO 0F3A (RETURN)
....................
.................... /// END User Functions
....................
....................
.................... /// BEGIN Hardware layer functions required by USB.
....................
.................... /*****************************************************************************
.................... /* usb_get_packet_buffer(endpoint, *ptr, max)
.................... /*
.................... /* Input: endpoint - endpoint to get data from
.................... /* ptr - where to save data to local PIC RAM
.................... /* max - max amount of data to receive from buffer
.................... /*
.................... /* Output: the amount of data taken from the buffer.
.................... /*
.................... /* Summary: Gets a packet of data from the USB buffer and puts into local PIC
.................... /* RAM.
.................... /* Does not mark the endpoint as ready for more data. Once you are
.................... /* done with data, call usb_flush_out() to mark the endpoint ready
.................... /* to receive more data.
.................... /*
.................... /*****************************************************************************/
.................... static int16 usb_get_packet_buffer(int8 endpoint, int8 *ptr, int16 max)
.................... {
.................... int8 * al;
.................... int8 st;
.................... int16 i;
....................
.................... al = EP_BDxADR_O(endpoint);
.................... i = EP_BDxCNT_O(endpoint);
.................... st = EP_BDxST_O(endpoint);
....................
.................... //read BC8 and BC9
.................... if (bit_test(st,0)) {bit_set(i,8);}
.................... if (bit_test(st,1)) {bit_set(i,9);}
....................
.................... if (i < max) {max = i;}
....................
.................... memcpy(ptr, al ,max);
....................
.................... return(max);
.................... }
....................
.................... // see usb_hw_layer.h for documentation
.................... unsigned int16 usb_get_packet(int8 endpoint, int8 * ptr, unsigned int16 max)
.................... {
.................... max = usb_get_packet_buffer(endpoint, ptr, max);
.................... usb_flush_out(endpoint, USB_DTS_TOGGLE);
....................
.................... return(max);
.................... }
....................
.................... // see usb_hw_layer.h for documentation
.................... void usb_stall_ep(int8 endpoint)
.................... {
.................... int1 direction;
....................
.................... direction = bit_test(endpoint,7);
*
09B4: MOVLB 6
09B6: BCF xFE.0
09B8: BTFSC xFD.7
09BA: BSF xFE.0
.................... endpoint &= 0x7F;
09BC: BCF xFD.7
....................
.................... if (direction)
09BE: BTFSS xFE.0
09C0: BRA 09FC
.................... {
.................... EP_BDxST_I(endpoint) = 0x84;
09C2: MOVLB 7
09C4: CLRF x49
09C6: MOVFF 6FD,748
09CA: CLRF x4B
09CC: MOVLW 08
09CE: MOVWF x4A
09D0: MOVLB 0
09D2: RCALL 02BA
09D4: MOVFF 02,700
09D8: MOVFF 01,6FF
09DC: MOVLW 04
09DE: MOVLB 6
09E0: ADDWF xFF,F
09E2: MOVLW 00
09E4: MOVLB 7
09E6: ADDWFC x00,F
09E8: MOVFF 6FF,FE9
09EC: MOVLW 04
09EE: MOVLB 7
09F0: ADDWF x00,W
09F2: MOVWF FEA
09F4: MOVLW 84
09F6: MOVWF FEF
.................... }
.................... else
09F8: BRA 0A1E
09FA: MOVLB 6
.................... {
.................... EP_BDxST_O(endpoint) = 0x84;
09FC: MOVLB 7
09FE: CLRF x49
0A00: MOVFF 6FD,748
0A04: CLRF x4B
0A06: MOVLW 08
0A08: MOVWF x4A
0A0A: MOVLB 0
0A0C: RCALL 02BA
0A0E: MOVFF 01,FE9
0A12: MOVLW 04
0A14: MOVLB 7
0A16: ADDWF 02,W
0A18: MOVWF FEA
0A1A: MOVLW 84
0A1C: MOVWF FEF
.................... }
.................... }
0A1E: MOVLB 0
0A20: GOTO 0AD6 (RETURN)
....................
.................... // see usb_hw_layer.h for documentation
.................... void usb_unstall_ep(int8 endpoint)
.................... {
.................... int1 direction;
....................
.................... direction = bit_test(endpoint,7);
*
0946: MOVLB 6
0948: BCF xFE.0
094A: BTFSC xFD.7
094C: BSF xFE.0
.................... endpoint &= 0x7F;
094E: BCF xFD.7
....................
.................... if (direction)
0950: BTFSS xFE.0
0952: BRA 098E
.................... {
.................... #if USB_IGNORE_RX_DTS
.................... EP_BDxST_I(endpoint) = 0x80;
.................... #else
.................... EP_BDxST_I(endpoint) = 0x88;
0954: MOVLB 7
0956: CLRF x49
0958: MOVFF 6FD,748
095C: CLRF x4B
095E: MOVLW 08
0960: MOVWF x4A
0962: MOVLB 0
0964: RCALL 02BA
0966: MOVFF 02,700
096A: MOVFF 01,6FF
096E: MOVLW 04
0970: MOVLB 6
0972: ADDWF xFF,F
0974: MOVLW 00
0976: MOVLB 7
0978: ADDWFC x00,F
097A: MOVFF 6FF,FE9
097E: MOVLW 04
0980: MOVLB 7
0982: ADDWF x00,W
0984: MOVWF FEA
0986: MOVLW 88
0988: MOVWF FEF
.................... #endif
.................... }
.................... else
098A: BRA 09AE
098C: MOVLB 6
.................... {
.................... EP_BDxST_O(endpoint) = 0x00;
098E: MOVLB 7
0990: CLRF x49
0992: MOVFF 6FD,748
0996: CLRF x4B
0998: MOVLW 08
099A: MOVWF x4A
099C: MOVLB 0
099E: RCALL 02BA
09A0: MOVFF 01,FE9
09A4: MOVLW 04
09A6: MOVLB 7
09A8: ADDWF 02,W
09AA: MOVWF FEA
09AC: CLRF FEF
.................... }
.................... }
09AE: MOVLB 0
09B0: GOTO 0AC6 (RETURN)
....................
.................... // see usb_hw_layer.h for documentation
.................... int1 usb_endpoint_stalled(int8 endpoint)
.................... {
.................... int1 direction;
.................... int8 st;
....................
.................... direction = bit_test(endpoint,7);
*
0A24: MOVLB 6
0A26: BCF xFE.0
0A28: BTFSC xFD.7
0A2A: BSF xFE.0
.................... endpoint &= 0x7F;
0A2C: BCF xFD.7
....................
.................... if (direction)
0A2E: BTFSS xFE.0
0A30: BRA 0A68
.................... {
.................... st=EP_BDxST_I(endpoint);
0A32: MOVLB 7
0A34: CLRF x49
0A36: MOVFF 6FD,748
0A3A: CLRF x4B
0A3C: MOVLW 08
0A3E: MOVWF x4A
0A40: MOVLB 0
0A42: RCALL 02BA
0A44: MOVFF 02,701
0A48: MOVFF 01,700
0A4C: MOVLW 04
0A4E: MOVLB 7
0A50: ADDWF x00,F
0A52: MOVLW 00
0A54: ADDWFC x01,F
0A56: MOVFF 700,FE9
0A5A: MOVLW 04
0A5C: ADDWF x01,W
0A5E: MOVWF FEA
0A60: MOVFF FEF,6FF
0A64: MOVLB 6
.................... }
.................... else
0A66: BRA 0A8C
.................... {
.................... st=EP_BDxST_O(endpoint);
0A68: MOVLB 7
0A6A: CLRF x49
0A6C: MOVFF 6FD,748
0A70: CLRF x4B
0A72: MOVLW 08
0A74: MOVWF x4A
0A76: MOVLB 0
0A78: RCALL 02BA
0A7A: MOVLB 7
0A7C: MOVFF 01,FE9
0A80: MOVLW 04
0A82: ADDWF 02,W
0A84: MOVWF FEA
0A86: MOVFF FEF,6FF
0A8A: MOVLB 6
.................... }
....................
.................... return(bit_test(st,7) && bit_test(st,2));
0A8C: BTFSS xFF.7
0A8E: BRA 0A94
0A90: BTFSC xFF.2
0A92: BRA 0A98
0A94: MOVLW 00
0A96: BRA 0A9A
0A98: MOVLW 01
0A9A: MOVWF 01
.................... }
0A9C: MOVLB 0
0A9E: GOTO 0AEE (RETURN)
....................
.................... // see usb_hw_layer.h for documentation
.................... void usb_set_address(int8 address)
.................... {
.................... UADDR = address;
*
0F60: MOVFF 6FE,F6E
....................
.................... if (address)
0F64: MOVLB 6
0F66: MOVF xFE,F
0F68: BZ 0F70
.................... {
.................... usb_state = USB_STATE_ADDRESS;
0F6A: MOVLW 04
0F6C: MOVWF 24
.................... }
.................... else
0F6E: BRA 0F74
.................... {
.................... usb_state = USB_STATE_POWERED;
0F70: MOVLW 02
0F72: MOVWF 24
.................... }
.................... }
0F74: MOVLB 0
0F76: GOTO 0F84 (RETURN)
....................
.................... // see usb_hw_layer.h for documentation
.................... void usb_set_configured(int8 config)
.................... {
.................... int8 en;
.................... int16 addy;
.................... int8 new_uep;
.................... int16 len;
.................... int8 i;
....................
.................... if (config == 0)
*
055C: MOVLB 6
055E: MOVF xFD,F
0560: BNZ 056E
.................... {
.................... // if config=0 then set addressed state
.................... usb_state = USB_STATE_ADDRESS;
0562: MOVLW 04
0564: MOVWF 24
.................... usb_disable_endpoints();
0566: MOVLB 0
0568: RCALL 033E
.................... }
.................... else
056A: BRA 0786
056C: MOVLB 6
.................... {
.................... // else set configed state
.................... usb_state = USB_STATE_CONFIGURED;
056E: MOVLW 05
0570: MOVWF 24
.................... addy = (int16)USB_DATA_BUFFER_LOCATION+(2*USB_MAX_EP0_PACKET_LENGTH);
0572: MOVLW 04
0574: MOVLB 7
0576: MOVWF x00
0578: MOVLW 98
057A: MOVLB 6
057C: MOVWF xFF
.................... for (en=1; en<16; en++)
057E: MOVLW 01
0580: MOVWF xFE
0582: MOVF xFE,W
0584: SUBLW 0F
0586: BTFSS FD8.0
0588: BRA 0786
.................... {
.................... // enable and config endpoints based upon user configuration
.................... usb_disable_endpoint(en);
058A: MOVFF 6FE,706
058E: MOVLB 0
0590: RCALL 02DC
.................... new_uep = 0;
0592: MOVLB 7
0594: CLRF x01
.................... if (usb_ep_rx_type[en] != USB_ENABLE_DISABLED)
0596: CLRF 03
0598: MOVLB 6
059A: MOVF xFE,W
059C: MOVFF FF2,705
05A0: BCF FF2.7
05A2: MOVLB 0
05A4: RCALL 00CA
05A6: MOVLB 7
05A8: BTFSC x05.7
05AA: BSF FF2.7
05AC: SUBLW FF
05AE: BZ 0692
.................... {
.................... new_uep = 0x04;
05B0: MOVLW 04
05B2: MOVWF x01
.................... len = usb_ep_rx_size[en];
05B4: BCF FD8.0
05B6: MOVLB 6
05B8: RLCF xFE,W
05BA: CLRF 03
05BC: MOVFF FF2,705
05C0: BCF FF2.7
05C2: MOVLB 0
05C4: RCALL 011A
05C6: TBLRD*+
05C8: MOVFF FF5,03
05CC: MOVLB 7
05CE: BTFSC x05.7
05D0: BSF FF2.7
05D2: MOVWF x02
05D4: MOVFF 03,703
.................... EP_BDxCNT_O(en) = len;
05D8: CLRF x49
05DA: MOVFF 6FE,748
05DE: CLRF x4B
05E0: MOVLW 08
05E2: MOVWF x4A
05E4: MOVLB 0
05E6: RCALL 02BA
05E8: MOVFF 01,705
05EC: MOVLW 01
05EE: MOVLB 7
05F0: ADDWF 01,W
05F2: MOVWF 01
05F4: MOVLW 00
05F6: ADDWFC 02,W
05F8: MOVWF 03
05FA: MOVFF 01,FE9
05FE: MOVLW 04
0600: ADDWF 03,W
0602: MOVWF FEA
0604: MOVFF 702,FEF
.................... EP_BDxADR_O(en) = addy;
0608: CLRF x49
060A: MOVFF 6FE,748
060E: CLRF x4B
0610: MOVLW 08
0612: MOVWF x4A
0614: MOVLB 0
0616: RCALL 02BA
0618: MOVFF 01,705
061C: MOVLW 02
061E: MOVLB 7
0620: ADDWF 01,W
0622: MOVWF 01
0624: MOVLW 00
0626: ADDWFC 02,W
0628: MOVWF 03
062A: MOVFF 01,FE9
062E: MOVLW 04
0630: ADDWF 03,W
0632: MOVWF FEA
0634: MOVFF 700,FEC
0638: MOVF FED,F
063A: MOVFF 6FF,FEF
.................... addy += usb_ep_rx_size[en];
063E: BCF FD8.0
0640: MOVLB 6
0642: RLCF xFE,W
0644: CLRF 03
0646: MOVFF FF2,705
064A: BCF FF2.7
064C: MOVLB 0
064E: RCALL 011A
0650: TBLRD*+
0652: MOVFF FF5,03
0656: MOVLB 7
0658: BTFSC x05.7
065A: BSF FF2.7
065C: MOVLB 6
065E: ADDWF xFF,F
0660: MOVF 03,W
0662: MOVLB 7
0664: ADDWFC x00,F
.................... #if USB_IGNORE_RX_DTS
.................... i = 0x80;
.................... #else
.................... i = 0x88;
0666: MOVLW 88
0668: MOVWF x04
.................... #endif
.................... if (bit_test(len,8)) {bit_set(i,0);}
066A: BTFSC x03.0
066C: BSF x04.0
.................... if (bit_test(len,9)) {bit_set(i,1);}
066E: BTFSC x03.1
0670: BSF x04.1
.................... EP_BDxST_O(en) = i;
0672: CLRF x49
0674: MOVFF 6FE,748
0678: CLRF x4B
067A: MOVLW 08
067C: MOVWF x4A
067E: MOVLB 0
0680: RCALL 02BA
0682: MOVLB 7
0684: MOVFF 01,FE9
0688: MOVLW 04
068A: ADDWF 02,W
068C: MOVWF FEA
068E: MOVFF 704,FEF
.................... }
.................... if (usb_ep_tx_type[en] != USB_ENABLE_DISABLED)
0692: CLRF 03
0694: MOVLB 6
0696: MOVF xFE,W
0698: MOVFF FF2,705
069C: BCF FF2.7
069E: MOVLB 0
06A0: RCALL 00AA
06A2: MOVLB 7
06A4: BTFSC x05.7
06A6: BSF FF2.7
06A8: SUBLW FF
06AA: BZ 0748
.................... {
.................... new_uep |= 0x02;
06AC: BSF x01.1
.................... EP_BDxADR_I(en) = addy;
06AE: CLRF x49
06B0: MOVFF 6FE,748
06B4: CLRF x4B
06B6: MOVLW 08
06B8: MOVWF x4A
06BA: MOVLB 0
06BC: RCALL 02BA
06BE: MOVFF 02,706
06C2: MOVFF 01,705
06C6: MOVLW 04
06C8: MOVLB 7
06CA: ADDWF x05,F
06CC: MOVLW 00
06CE: ADDWFC x06,F
06D0: MOVLW 02
06D2: ADDWF x05,W
06D4: MOVWF 01
06D6: MOVLW 00
06D8: ADDWFC x06,W
06DA: MOVWF 03
06DC: MOVFF 01,FE9
06E0: MOVLW 04
06E2: ADDWF 03,W
06E4: MOVWF FEA
06E6: MOVFF 700,FEC
06EA: MOVF FED,F
06EC: MOVFF 6FF,FEF
.................... addy += usb_ep_tx_size[en];
06F0: BCF FD8.0
06F2: MOVLB 6
06F4: RLCF xFE,W
06F6: CLRF 03
06F8: MOVFF FF2,705
06FC: BCF FF2.7
06FE: MOVLB 0
0700: RCALL 00EA
0702: TBLRD*+
0704: MOVFF FF5,03
0708: MOVLB 7
070A: BTFSC x05.7
070C: BSF FF2.7
070E: MOVLB 6
0710: ADDWF xFF,F
0712: MOVF 03,W
0714: MOVLB 7
0716: ADDWFC x00,F
.................... EP_BDxST_I(en) = 0x40;
0718: CLRF x49
071A: MOVFF 6FE,748
071E: CLRF x4B
0720: MOVLW 08
0722: MOVWF x4A
0724: MOVLB 0
0726: RCALL 02BA
0728: MOVFF 02,706
072C: MOVFF 01,705
0730: MOVLW 04
0732: MOVLB 7
0734: ADDWF x05,F
0736: MOVLW 00
0738: ADDWFC x06,F
073A: MOVFF 705,FE9
073E: MOVLW 04
0740: ADDWF x06,W
0742: MOVWF FEA
0744: MOVLW 40
0746: MOVWF FEF
.................... }
.................... if (new_uep == 0x06) {new_uep = 0x0E;}
0748: MOVF x01,W
074A: SUBLW 06
074C: BNZ 0752
074E: MOVLW 0E
0750: MOVWF x01
.................... if (usb_ep_tx_type[en] != USB_ENABLE_ISOCHRONOUS) {new_uep |= 0x10;}
0752: CLRF 03
0754: MOVLB 6
0756: MOVF xFE,W
0758: MOVFF FF2,705
075C: BCF FF2.7
075E: MOVLB 0
0760: RCALL 00AA
0762: MOVLB 7
0764: BTFSC x05.7
0766: BSF FF2.7
0768: SUBLW 01
076A: BTFSS FD8.2
076C: BSF x01.4
....................
.................... UEP(en) = new_uep;
076E: CLRF 03
0770: MOVLB 6
0772: MOVF xFE,W
0774: ADDLW 70
0776: MOVWF FE9
0778: MOVLW 0F
077A: ADDWFC 03,W
077C: MOVWF FEA
077E: MOVFF 701,FEF
.................... }
0782: INCF xFE,F
0784: BRA 0582
0786: MOVLB 0
.................... }
.................... }
0788: GOTO 082C (RETURN)
....................
.................... // see usb_hw_layer.h for documentation
.................... void usb_disable_endpoint(int8 en)
.................... {
.................... UEP(en) = ENDPT_DISABLED;
*
02DC: CLRF 03
02DE: MOVLB 7
02E0: MOVF x06,W
02E2: ADDLW 70
02E4: MOVWF FE9
02E6: MOVLW 0F
02E8: ADDWFC 03,W
02EA: MOVWF FEA
02EC: CLRF FEF
.................... EP_BDxST_O(en) = 0; //clear state, deque if necessary
02EE: CLRF x49
02F0: MOVFF 706,748
02F4: CLRF x4B
02F6: MOVLW 08
02F8: MOVWF x4A
02FA: MOVLB 0
02FC: RCALL 02BA
02FE: MOVLB 7
0300: MOVFF 01,FE9
0304: MOVLW 04
0306: ADDWF 02,W
0308: MOVWF FEA
030A: CLRF FEF
.................... EP_BDxST_I(en) = 0; //clear state, deque if necessary
030C: CLRF x49
030E: MOVFF 706,748
0312: CLRF x4B
0314: MOVLW 08
0316: MOVWF x4A
0318: MOVLB 0
031A: RCALL 02BA
031C: MOVFF 02,708
0320: MOVFF 01,707
0324: MOVLW 04
0326: MOVLB 7
0328: ADDWF x07,F
032A: MOVLW 00
032C: ADDWFC x08,F
032E: MOVFF 707,FE9
0332: MOVLW 04
0334: ADDWF x08,W
0336: MOVWF FEA
0338: CLRF FEF
.................... }
033A: MOVLB 0
033C: RETLW 00
....................
.................... // see usb_hw_layer.h for documentation
.................... void usb_disable_endpoints(void)
.................... {
.................... int8 i;
....................
.................... for (i=1; i<16; i++)
033E: MOVLW 01
0340: MOVLB 7
0342: MOVWF x05
0344: MOVF x05,W
0346: SUBLW 0F
0348: BNC 0358
.................... usb_disable_endpoint(i);
034A: MOVFF 705,706
034E: MOVLB 0
0350: RCALL 02DC
0352: MOVLB 7
0354: INCF x05,F
0356: BRA 0344
....................
.................... //__usb_kbhit_status=0;
.................... }
0358: MOVLB 0
035A: RETLW 00
....................
.................... /// END Hardware layer functions required by USB.C
....................
....................
.................... /// BEGIN USB Interrupt Service Routine
....................
.................... static void usb_clear_trn(void)
.................... {
.................... UIR_TRN = 0;
*
03AA: BCF F68.3
.................... delay_cycles(6);
03AC: BRA 03AE
03AE: BRA 03B0
03B0: BRA 03B2
.................... }
03B2: RETLW 00
....................
.................... /*****************************************************************************
.................... /* usb_handle_interrupt()
.................... /*
.................... /* Summary: Checks the interrupt, and acts upon event. Processing finished
.................... /* tokens is the majority of this code, and is handled by usb.c
.................... /*
.................... /* NOTE: If you wish to change to a polling method (and not an interrupt
.................... /* method), then you must call this function rapidly. If there is more
.................... /* than 10ms latency the PC may think the USB device is stalled and
.................... /* disable it.
.................... /* To switch to a polling method, remove the #int_usb line above this
.................... /* fuction. Also, goto usb_init() and remove the code that enables the
.................... /* USB interrupt.
.................... /******************************************************************************/
.................... #int_usb
.................... void usb_isr()
.................... {
.................... int8 TRNAttempts;
....................
.................... if (usb_state == USB_STATE_DETACHED) return; //should never happen, though
*
1274: MOVF 24,F
1276: BNZ 127A
1278: BRA 12EE
.................... if (UIR)
127A: MOVF F68,F
127C: BZ 12EE
.................... {
.................... debug_usb(debug_putc,"\r\n\n[%X] ",UIR);
....................
.................... //activity detected. (only enable after sleep)
.................... if (UIR_ACTV && UIE_ACTV) {usb_isr_activity();}
127E: BTFSS F68.2
1280: BRA 128A
1282: BTFSS F69.2
1284: BRA 128A
1286: GOTO 0274
....................
.................... if (UCON_SUSPND) return;
128A: BTFSS F6D.1
128C: BRA 1290
128E: BRA 12EE
....................
.................... if (UIR_STALL && UIE_STALL) {usb_isr_stall();} //a stall handshake was sent
1290: BTFSS F68.5
1292: BRA 129C
1294: BTFSS F69.5
1296: BRA 129C
1298: GOTO 02A4
....................
.................... if (UIR_UERR && UIE_UERR) {usb_isr_uerr();} //error has been detected
129C: BTFSS F68.1
129E: BRA 12A8
12A0: BTFSS F69.1
12A2: BRA 12A8
12A4: GOTO 02B2
....................
.................... if (UIR_URST && UIE_URST) {usb_isr_rst();} //usb reset has been detected
12A8: BTFSS F68.0
12AA: BRA 12B4
12AC: BTFSS F69.0
12AE: BRA 12B4
12B0: GOTO 03B4
....................
.................... if (UIR_IDLE && UIE_IDLE) {usb_isr_uidle();} //idle time, we can go to sleep
12B4: BTFSS F68.4
12B6: BRA 12C0
12B8: BTFSS F69.4
12BA: BRA 12C0
12BC: GOTO 03DE
....................
.................... if (UIR_SOF && UIE_SOF) {usb_isr_sof();}
12C0: BTFSS F68.6
12C2: BRA 12CC
12C4: BTFSS F69.6
12C6: BRA 12CC
12C8: GOTO 03E8
....................
.................... TRNAttempts = 0;
12CC: MOVLB 6
12CE: CLRF xFA
.................... do
.................... {
.................... if (UIR_TRN && UIE_TRN)
12D0: BTFSS F68.3
12D2: BRA 12E0
12D4: BTFSS F69.3
12D6: BRA 12E0
.................... {
.................... usb_isr_tok_dne();
12D8: MOVLB 0
12DA: BRA 108A
.................... }
.................... else
12DC: BRA 12E2
12DE: MOVLB 6
.................... break;
12E0: BRA 12EC
.................... } while (TRNAttempts++ < 4);
12E2: MOVLB 6
12E4: MOVF xFA,W
12E6: INCF xFA,F
12E8: SUBLW 03
12EA: BC 12D0
12EC: MOVLB 0
.................... }
.................... }
....................
.................... // SOF interrupt not handled. user must add this depending on application
12EE: BCF FA1.5
12F0: GOTO 0064
.................... void usb_isr_sof(void)
.................... {
.................... debug_usb(debug_putc, "\r\nSOF");
....................
.................... UIR_SOF = 0;
*
03E8: BCF F68.6
.................... }
03EA: GOTO 12CC (RETURN)
....................
.................... /*****************************************************************************
.................... /* usb_isr_rst()
.................... /*
.................... /* Summary: The host (computer) sent us a RESET command. Reset USB device
.................... /* and token handler code to initial state.
.................... /*
.................... /******************************************************************************/
.................... void usb_isr_rst(void)
.................... {
.................... debug_usb(debug_putc,"R");
....................
.................... UEIR = 0;
*
03B4: CLRF F6A
.................... UIR = 0;
03B6: CLRF F68
.................... UEIE = 0x9F;
03B8: MOVLW 9F
03BA: MOVWF F6B
.................... UIE = STANDARD_INTS & ~__USB_UIF_ACTIVE;
03BC: MOVLW 3D
03BE: MOVWF F69
....................
.................... UADDR = 0;
03C0: CLRF F6E
....................
.................... usb_disable_endpoints();
03C2: RCALL 033E
....................
.................... usb_token_reset();
03C4: RCALL 037E
....................
.................... UEP(0) = ENDPT_CONTROL | 0x10;
03C6: MOVLW 16
03C8: MOVWF F70
....................
.................... while (UIR_TRN)
.................... {
03CA: BTFSS F68.3
03CC: BRA 03D2
.................... usb_clear_trn();
03CE: RCALL 03AA
.................... }
03D0: BRA 03CA
....................
.................... UCON_PKTDIS = 0; //SIE token and packet processing enabled
03D2: BCF F6D.4
....................
.................... usb_init_ep0_setup();
03D4: RCALL 0284
....................
.................... usb_state = USB_STATE_DEFAULT; //put usb mcu into default state
03D6: MOVLW 03
03D8: MOVWF 24
.................... }
03DA: GOTO 12B4 (RETURN)
....................
.................... /*****************************************************************************
.................... /* usb_init_ep0_setup()
.................... /*
.................... /* Summary: Configure EP0 to receive setup packets
.................... /*
.................... /*****************************************************************************/
.................... void usb_init_ep0_setup(void)
.................... {
.................... EP_BDxCNT_O(0) = USB_MAX_EP0_PACKET_LENGTH;
*
0284: MOVLW 40
0286: MOVLB 4
0288: MOVWF x01
.................... EP_BDxADR_O(0) = USB_DATA_BUFFER_LOCATION;
028A: MOVLW 04
028C: MOVWF x03
028E: MOVLW 18
0290: MOVWF x02
.................... #if USB_IGNORE_RX_DTS
.................... EP_BDxST_O(0) = 0x80; //give control to SIE, data toggle synch off
.................... #else
.................... EP_BDxST_O(0) = 0x88; //give control to SIE, DATA0, data toggle synch on
0292: MOVLW 88
0294: MOVWF x00
.................... #endif
....................
.................... EP_BDxST_I(0) = 0;
0296: CLRF x04
.................... EP_BDxADR_I(0) = USB_DATA_BUFFER_LOCATION + (int16)USB_MAX_EP0_PACKET_LENGTH;
0298: MOVLW 04
029A: MOVWF x07
029C: MOVLW 58
029E: MOVWF x06
.................... }
02A0: MOVLB 0
02A2: RETLW 00
....................
.................... /*******************************************************************************
.................... /* usb_isr_uerr()
.................... /*
.................... /* Summary: The USB peripheral had an error. If user specified, error counter
.................... /* will incerement. If having problems check the status of these 8 bytes.
.................... /*
.................... /* NOTE: This code is not enabled by default.
.................... /********************************************************************************/
.................... void usb_isr_uerr(void)
.................... {
.................... #if USB_USE_ERROR_COUNTER
.................... int ints;
.................... #endif
....................
.................... debug_usb(debug_putc,"E %X ",UEIR);
....................
.................... #if USB_USE_ERROR_COUNTER
.................... ints=UEIR & UEIE; //mask off the flags with the ones that are enabled
....................
.................... if ( bit_test(ints,0) )
.................... {
.................... //increment pid_error counter
.................... debug_usb(debug_putc,"PID ");
.................... ERROR_COUNTER[0]++;
.................... }
....................
.................... if ( bit_test(ints,1) )
.................... {
.................... //increment crc5 error counter
.................... debug_usb(debug_putc,"CRC5 ");
.................... ERROR_COUNTER[1]++;
.................... }
....................
.................... if ( bit_test(ints,2) )
.................... {
.................... //increment crc16 error counter
.................... debug_usb(debug_putc,"CRC16 ");
.................... ERROR_COUNTER[2]++;
.................... }
....................
.................... if ( bit_test(ints,3) )
.................... {
.................... //increment dfn8 error counter
.................... debug_usb(debug_putc,"DFN8 ");
.................... ERROR_COUNTER[3]++;
.................... }
....................
.................... if ( bit_test(ints,4) )
.................... {
.................... //increment bto error counter
.................... debug_usb(debug_putc,"BTO ");
.................... ERROR_COUNTER[4]++;
.................... }
....................
.................... if ( bit_test(ints,7) )
.................... {
.................... //increment bts error counter
.................... debug_usb(debug_putc,"BTS ");
.................... ERROR_COUNTER[5]++;
.................... }
.................... #endif
....................
.................... UEIR = 0;
*
02B2: CLRF F6A
.................... UIR_UERR = 0;
02B4: BCF F68.1
.................... }
02B6: GOTO 12A8 (RETURN)
....................
.................... /*****************************************************************************
.................... /* usb_isr_uidle()
.................... /*
.................... /* Summary: USB peripheral detected IDLE. Put the USB peripheral to sleep.
.................... /*
.................... /*****************************************************************************/
.................... void usb_isr_uidle(void)
.................... {
.................... debug_usb(debug_putc, "I");
....................
.................... UIE_ACTV = 1; //enable activity interrupt flag. (we are now suspended until we get an activity interrupt. nice)
*
03DE: BSF F69.2
.................... UIR_IDLE = 0; //clear idle interrupt flag
03E0: BCF F68.4
.................... UCON_SUSPND = 1; //set suspend. we are now suspended
03E2: BSF F6D.1
.................... }
03E4: GOTO 12C0 (RETURN)
....................
....................
.................... /******************************************************************************
.................... /* usb_isr_activity()
.................... /*
.................... /* Summary: USB peripheral detected activity on the USB device. Wake-up the USB
.................... /* peripheral.
.................... /*
.................... /*****************************************************************************/
.................... void usb_isr_activity(void)
.................... {
.................... debug_usb(debug_putc, "A");
....................
.................... UCON_SUSPND = 0; //turn off low power suspending
*
0274: BCF F6D.1
.................... UIE_ACTV = 0; //clear activity interupt enabling
0276: BCF F69.2
....................
.................... while(UIR_ACTV)
.................... UIR_ACTV = 0;
0278: BTFSS F68.2
027A: BRA 0280
027C: BCF F68.2
027E: BRA 0278
.................... }
0280: GOTO 128A (RETURN)
....................
.................... /******************************************************************************
.................... /* usb_isr_stall()
.................... /*
.................... /* Summary: Stall handshake detected.
.................... /*
.................... /*****************************************************************************/
.................... void usb_isr_stall(void)
.................... {
.................... debug_usb(debug_putc, "S");
....................
....................
.................... if (bit_test(UEP(0),0))
*
02A4: BTFSS F70.0
02A6: BRA 02AC
.................... {
.................... usb_init_ep0_setup();
02A8: RCALL 0284
.................... bit_clear(UEP(0), 0);
02AA: BCF F70.0
.................... }
....................
.................... UIR_STALL = 0;
02AC: BCF F68.5
.................... }
02AE: GOTO 129C (RETURN)
....................
.................... // see usb_hw_layer.h for documentation
.................... void usb_request_send_response(unsigned int8 len) {__setup_0_tx_size = len;}
*
03EE: MOVFF 700,25
03F2: RETLW 00
.................... void usb_request_get_data(void) {__setup_0_tx_size = 0xFE;}
*
0B0C: MOVLW FE
0B0E: MOVWF 25
0B10: RETLW 00
.................... void usb_request_stall(void) {__setup_0_tx_size = 0xFF;}
*
03F4: MOVLW FF
03F6: MOVWF 25
03F8: RETLW 00
....................
.................... /*****************************************************************************
.................... /* usb_isr_tok_dne()
.................... /*
.................... /* Summary: A Token (IN/OUT/SETUP) has been received by the USB peripheral.
.................... /* If a setup token on EP0 was received, run the chapter 9 code and
.................... /* handle the request.
.................... /* If an IN token on EP0 was received, continue transmitting any
.................... /* unfinished requests that may take more than one packet to transmit
.................... /* (if necessary).
.................... /* If an OUT token on any other EP was received, mark that EP as ready
.................... /* for a usb_get_packet().
.................... /* Does not handle any IN or OUT tokens on EP0.
.................... /*
.................... /*****************************************************************************/
.................... void usb_isr_tok_dne(void)
.................... {
.................... int8 en;
....................
.................... en = USTAT>>3;
*
108A: RRCF F6C,W
108C: MOVLB 6
108E: MOVWF xFB
1090: RRCF xFB,F
1092: RRCF xFB,F
1094: MOVLW 1F
1096: ANDWF xFB,F
....................
.................... debug_usb(debug_putc, "T ");
.................... debug_usb(debug_putc, "%X ", USTAT);
....................
.................... if (USTAT == USTAT_OUT_SETUP_E0)
1098: MOVF F6C,F
109A: BNZ 1138
.................... {
.................... //new out or setup token in the buffer
.................... int8 pidKey;
....................
.................... debug_usb(debug_putc,"%X ", EP_BDxST_O(0));
....................
.................... pidKey = EP_BDxST_O(0) & 0x3C; //save PID
109C: MOVLB 4
109E: MOVF x00,W
10A0: ANDLW 3C
10A2: MOVLB 6
10A4: MOVWF xFC
....................
.................... EP_BDxST_O(0) &= 0x43; //clear pid, prevent bdstal/pid confusion
10A6: MOVLW 43
10A8: MOVLB 4
10AA: ANDWF x00,F
.................... usb_clear_trn();
10AC: MOVLB 0
10AE: CALL 03AA
....................
.................... if (pidKey == USB_PIC_PID_SETUP)
10B2: MOVLB 6
10B4: MOVF xFC,W
10B6: SUBLW 34
10B8: BNZ 10FE
.................... {
.................... EP_BDxST_I(0)=0; // return the in buffer to us (dequeue any pending requests)
10BA: MOVLB 4
10BC: CLRF x04
....................
.................... debug_usb(debug_putc,"(%U) ", EP_BDxCNT_O(0));
.................... debug_display_ram(EP_BDxCNT_O(0), usb_ep0_rx_buffer);
....................
.................... usb_isr_tok_setup_dne();
10BE: MOVLB 0
10C0: BRA 0BC0
....................
.................... UCON_PKTDIS=0; // UCON,PKT_DIS ; Assuming there is nothing to dequeue, clear the packet disable bit
10C2: BCF F6D.4
....................
.................... //if setup_0_tx_size==0xFF - stall ep0 (unhandled request) (see usb_request_stall())
.................... //if setup_0_tx_size==0xFE - get EP0OUT ready for a data packet, leave EP0IN alone (see usb_request_get_data())
.................... //else setup_0_tx_size=size of response, get EP0OUT ready for a setup packet, mark EPOIN ready for transmit (see usb_request_send_response())
.................... if (__setup_0_tx_size == 0xFF)
10C4: INCFSZ 25,W
10C6: BRA 10D6
.................... usb_flush_out(0, USB_DTS_STALL);
10C8: MOVLB 6
10CA: CLRF xFD
10CC: MOVLW 03
10CE: MOVWF xFE
10D0: MOVLB 0
10D2: RCALL 0BEA
.................... else
10D4: BRA 10FA
.................... {
.................... usb_flush_out(0, USB_DTS_TOGGLE);
10D6: MOVLB 6
10D8: CLRF xFD
10DA: MOVLW 02
10DC: MOVWF xFE
10DE: MOVLB 0
10E0: RCALL 0BEA
.................... if (__setup_0_tx_size != 0xFE)
10E2: MOVF 25,W
10E4: SUBLW FE
10E6: BZ 10FA
.................... usb_flush_in(0 ,__setup_0_tx_size, USB_DTS_USERX);
10E8: MOVLB 7
10EA: CLRF x42
10EC: CLRF x44
10EE: MOVFF 25,743
10F2: MOVLW 04
10F4: MOVWF x45
10F6: MOVLB 0
10F8: RCALL 0D5C
.................... }
.................... //why was this here?
.................... //UCON_PKTDIS=0; // UCON,PKT_DIS ; Assuming there is nothing to dequeue, clear the packet disable bit
.................... }
.................... else if (pidKey == USB_PIC_PID_OUT)
10FA: BRA 1134
10FC: MOVLB 6
10FE: MOVF xFC,W
1100: SUBLW 04
1102: BNZ 1136
.................... {
.................... usb_isr_tok_out_dne(0);
1104: CLRF xFD
1106: MOVLB 0
1108: RCALL 0F42
.................... usb_flush_out(0, USB_DTS_TOGGLE);
110A: MOVLB 6
110C: CLRF xFD
110E: MOVLW 02
1110: MOVWF xFE
1112: MOVLB 0
1114: RCALL 0BEA
.................... if ((__setup_0_tx_size!=0xFE) && (__setup_0_tx_size!=0xFF))
1116: MOVF 25,W
1118: SUBLW FE
111A: BZ 1134
111C: INCFSZ 25,W
111E: BRA 1122
1120: BRA 1134
.................... {
.................... usb_flush_in(0,__setup_0_tx_size,USB_DTS_DATA1); //send response (usually a 0len)
1122: MOVLB 7
1124: CLRF x42
1126: CLRF x44
1128: MOVFF 25,743
112C: MOVLW 01
112E: MOVWF x45
1130: MOVLB 0
1132: RCALL 0D5C
1134: MOVLB 6
.................... }
.................... }
.................... }
.................... else if (USTAT == USTAT_IN_E0)
1136: BRA 126E
1138: MOVF F6C,W
113A: SUBLW 04
113C: BNZ 1178
.................... {
.................... //pic -> host transfer completed
.................... EP_BDxST_I(0) = EP_BDxST_I(0) & 0x43; //clear up any BDSTAL confusion
113E: MOVLW 43
1140: MOVLB 4
1142: ANDWF x04,F
.................... usb_clear_trn();
1144: MOVLB 0
1146: CALL 03AA
.................... __setup_0_tx_size = 0xFF;
114A: MOVLW FF
114C: MOVWF 25
.................... usb_isr_tok_in_dne(0);
114E: MOVLB 6
1150: CLRF xFD
1152: MOVLB 0
1154: RCALL 1058
.................... if (__setup_0_tx_size!=0xFF)
1156: INCFSZ 25,W
1158: BRA 115C
115A: BRA 1170
.................... usb_flush_in(0, __setup_0_tx_size, USB_DTS_TOGGLE);
115C: MOVLB 7
115E: CLRF x42
1160: CLRF x44
1162: MOVFF 25,743
1166: MOVLW 02
1168: MOVWF x45
116A: MOVLB 0
116C: RCALL 0D5C
.................... else
116E: BRA 1174
.................... usb_init_ep0_setup();
1170: CALL 0284
.................... }
.................... else
1174: BRA 126C
1176: MOVLB 6
.................... {
.................... if (!bit_test(USTAT, 2))
1178: BTFSC F6C.2
117A: BRA 11E6
.................... {
.................... EP_BDxST_O(en) = EP_BDxST_O(en) & 0x43; //clear up any BDSTAL confusion
117C: MOVLB 7
117E: CLRF x49
1180: MOVFF 6FB,748
1184: CLRF x4B
1186: MOVLW 08
1188: MOVWF x4A
118A: MOVLB 0
118C: CALL 02BA
1190: MOVFF 01,6FD
1194: MOVLB 6
1196: MOVFF 01,01
119A: MOVLW 04
119C: ADDWF 02,W
119E: MOVWF 03
11A0: MOVFF 01,6FD
11A4: MOVWF xFE
11A6: MOVLB 7
11A8: CLRF x49
11AA: MOVFF 6FB,748
11AE: CLRF x4B
11B0: MOVLW 08
11B2: MOVWF x4A
11B4: MOVLB 0
11B6: CALL 02BA
11BA: MOVFF 01,FE9
11BE: MOVLW 04
11C0: MOVLB 7
11C2: ADDWF 02,W
11C4: MOVWF FEA
11C6: MOVF FEF,W
11C8: ANDLW 43
11CA: MOVLB 6
11CC: MOVFF 6FE,FEA
11D0: MOVFF 6FD,FE9
11D4: MOVWF FEF
.................... usb_clear_trn();
11D6: MOVLB 0
11D8: CALL 03AA
.................... usb_isr_tok_out_dne(en);
11DC: MOVFF 6FB,6FD
11E0: RCALL 0F42
.................... }
.................... else
11E2: BRA 126C
11E4: MOVLB 6
.................... {
.................... EP_BDxST_I(en) = EP_BDxST_I(en) & 0x43; //clear up any BDSTAL confusion
11E6: MOVLB 7
11E8: CLRF x49
11EA: MOVFF 6FB,748
11EE: CLRF x4B
11F0: MOVLW 08
11F2: MOVWF x4A
11F4: MOVLB 0
11F6: CALL 02BA
11FA: MOVFF 02,6FE
11FE: MOVFF 01,6FD
1202: MOVLW 04
1204: MOVLB 6
1206: ADDWF xFD,F
1208: MOVLW 00
120A: ADDWFC xFE,F
120C: MOVFF 6FD,01
1210: MOVLW 04
1212: ADDWF xFE,W
1214: MOVWF 03
1216: MOVFF 6FD,6FD
121A: MOVWF xFE
121C: MOVLB 7
121E: CLRF x49
1220: MOVFF 6FB,748
1224: CLRF x4B
1226: MOVLW 08
1228: MOVWF x4A
122A: MOVLB 0
122C: CALL 02BA
1230: MOVFF 02,700
1234: MOVFF 01,6FF
1238: MOVLW 04
123A: MOVLB 6
123C: ADDWF xFF,F
123E: MOVLW 00
1240: MOVLB 7
1242: ADDWFC x00,F
1244: MOVFF 6FF,FE9
1248: MOVLW 04
124A: MOVLB 7
124C: ADDWF x00,W
124E: MOVWF FEA
1250: MOVF FEF,W
1252: ANDLW 43
1254: MOVLB 6
1256: MOVFF 6FE,FEA
125A: MOVFF 6FD,FE9
125E: MOVWF FEF
.................... usb_clear_trn();
1260: MOVLB 0
1262: CALL 03AA
.................... usb_isr_tok_in_dne(en);
1266: MOVFF 6FB,6FD
126A: RCALL 1058
126C: MOVLB 6
.................... }
.................... }
.................... }
126E: MOVLB 0
1270: GOTO 12DC (RETURN)
....................
.................... /// END USB Interrupt Service Routine
....................
.................... #ENDIF
....................
.................... #endif
....................
.................... #if defined(__PIC24_USB_H__)
.................... #include <pic24_usb.c>
.................... #endif
....................
.................... #if defined(__USBN960X_H__)
.................... #include <usbn960x.c>
.................... #endif
....................
....................
.................... #IFNDEF __USB_HARDWARE__
.................... #ERROR You must include USB hardware driver.
.................... #ENDIF
....................
.................... #IFNDEF __USB_DESCRIPTORS__
.................... #ERROR You must include USB descriptors.
.................... #ENDIF
....................
.................... TYPE_USB_STACK_STATUS USB_stack_status;
....................
.................... int8 USB_address_pending; //save previous state because packets can take several isrs
.................... int8 usb_getdesc_ptr; unsigned int8 usb_getdesc_len=0; //for reading string and config descriptors
....................
.................... #IF USB_HID_BOOT_PROTOCOL
.................... int8 hid_protocol[USB_NUM_HID_INTERFACES];
.................... #ENDIF
....................
.................... void usb_put_0len_0(void);
.................... void usb_match_registers(int8 endpoint, int16 *status, int16 *buffer, int8 *size);
....................
.................... void usb_isr_tkn_setup_StandardEndpoint(void);
.................... void usb_isr_tkn_setup_StandardDevice(void);
.................... void usb_isr_tkn_setup_StandardInterface(void);
.................... #IF USB_HID_DEVICE
.................... void usb_isr_tkn_setup_ClassInterface(void);
.................... #ENDIF
.................... void usb_Get_Descriptor(void);
.................... void usb_copy_desc_seg_to_ep(void);
.................... void usb_finish_set_address(void);
....................
.................... int8 USB_Interface[USB_MAX_NUM_INTERFACES]; //config state for all of our interfaces, NUM_INTERFACES defined with descriptors
....................
.................... /// BEGIN User Functions
....................
.................... // see usb.h for documentation
.................... int1 usb_enumerated(void)
.................... {
.................... return(USB_stack_status.curr_config);
.................... }
....................
.................... // see usb.h for documentation
.................... void usb_wait_for_enumeration(void)
.................... {
.................... while (USB_stack_status.curr_config == 0) {restart_wdt();}
.................... }
....................
.................... // see USB.H for documentation
.................... int1 usb_puts(int8 endpoint, int8 * ptr, unsigned int16 len, unsigned int8 timeout) {
.................... unsigned int16 i=0;
.................... int1 res;
.................... unsigned int16 this_packet_len;
.................... unsigned int16 packet_size;
.................... unsigned int32 timeout_1us;
....................
.................... packet_size = usb_ep_tx_size[endpoint];
....................
.................... //printf("\r\nUSB PUTS %U LEN=%LU MAX_PACK=%LU\r\n", endpoint, len, packet_size);
....................
.................... //send data packets until timeout or no more packets to send
.................... while (i < len)
.................... {
.................... timeout_1us = (int32)timeout*1000;
.................... if ((len - i) > packet_size) {this_packet_len = packet_size;}
.................... else {this_packet_len = len-i;}
.................... //putc('*');
.................... do
.................... {
.................... res = usb_put_packet(endpoint, ptr + i, this_packet_len, USB_DTS_TOGGLE); //send 64 byte packets
.................... //putc('.');
.................... if (!res)
.................... {
.................... delay_us(1);
.................... //delay_ms(500);
.................... timeout_1us--;
.................... }
.................... } while (!res && timeout_1us);
.................... i += packet_size;
.................... }
....................
....................
.................... //send 0len packet if needed
.................... if (i==len) {
.................... timeout_1us=(int32)timeout*1000;
.................... do {
.................... res = usb_put_packet(endpoint,0,0,USB_DTS_TOGGLE); //indicate end of message
.................... if (!res) {
.................... delay_us(1);
.................... timeout_1us--;
.................... }
.................... } while (!res && timeout_1us);
.................... }
....................
.................... return(res);
.................... }
....................
.................... // see usb.h for documentation
.................... unsigned int16 usb_gets(int8 endpoint, int8 * ptr, unsigned int16 max, unsigned int16 timeout) {
.................... unsigned int16 ret=0;
.................... unsigned int16 to;
.................... unsigned int16 len;
.................... unsigned int16 packet_size;
.................... unsigned int16 this_packet_max;
....................
.................... packet_size=usb_ep_rx_size[endpoint];
....................
.................... do {
.................... if (packet_size < max) {this_packet_max=packet_size;} else {this_packet_max=max;}
.................... to=0;
.................... do {
.................... if (usb_kbhit(endpoint)) {
.................... len=usb_get_packet(endpoint,ptr,this_packet_max);
.................... ptr+=len;
.................... max-=len;
.................... ret+=len;
.................... break;
.................... }
.................... else {
.................... to++;
.................... delay_ms(1);
.................... }
.................... } while (to!=timeout);
.................... } while ((len == packet_size) && (to!=timeout) && max);
....................
.................... return(ret);
.................... }
....................
.................... /// END User Functions
....................
....................
.................... /// BEGIN USB Token, standard and HID request handler (part of ISR)
....................
.................... // see usb.h for documentation
.................... void usb_token_reset(void)
.................... {
.................... unsigned int i;
....................
.................... for (i=0;i<USB_MAX_NUM_INTERFACES;i++)
*
037E: MOVLB 7
0380: CLRF x19
0382: MOVF x19,W
0384: SUBLW 01
0386: BNC 039C
.................... USB_Interface[i] = 0; //reset each interface to default
0388: CLRF 03
038A: MOVF x19,W
038C: ADDLW 29
038E: MOVWF FE9
0390: MOVLW 00
0392: ADDWFC 03,W
0394: MOVWF FEA
0396: CLRF FEF
....................
.................... #IF USB_HID_BOOT_PROTOCOL
.................... for (i=0;i<USB_NUM_HID_INTERFACES; i++)
.................... hid_protocol[i] = 1;
.................... #endif
....................
.................... #if USB_CDC_DEVICE
0398: INCF x19,F
039A: BRA 0382
.................... usb_cdc_init();
039C: MOVLB 0
039E: RCALL 035C
.................... #endif
....................
.................... USB_stack_status.curr_config = 0; //unconfigured device
03A0: CLRF 1E
....................
.................... USB_stack_status.status_device = 1; //previous state. init at none
03A2: MOVLW 01
03A4: MOVWF 1F
.................... USB_stack_status.dev_req = NONE; //previous token request state. init at none
03A6: CLRF 1D
.................... }
03A8: RETLW 00
....................
.................... //send a 0len packet to endpoint 0 (optimization)
.................... //notice that this doesnt return the status
.................... #define usb_put_0len_0() usb_request_send_response(0)
....................
.................... /**************************************************************
.................... /* usb_endpoint_is_valid(endpoint)
.................... /*
.................... /* Input: endpoint - endpoint to check.
.................... /* bit 7 is direction (set is IN, clear is OUT)
.................... /*
.................... /* Output: TRUE if endpoint is valid, FALSE if not
.................... /*
.................... /* Summary: Checks the dynamic configuration to see if requested
.................... /* endpoint is a valid endpoint.
.................... /***************************************************************/
.................... int1 usb_endpoint_is_valid(int8 endpoint)
.................... {
.................... int1 direction;
.................... direction = bit_test(endpoint,7);
*
08E8: MOVLB 6
08EA: BCF xFE.0
08EC: BTFSC xFD.7
08EE: BSF xFE.0
.................... endpoint &= 0x7F;
08F0: BCF xFD.7
.................... if (direction) { //IN
08F2: BTFSS xFE.0
08F4: BRA 091C
.................... return(usb_ep_tx_type[endpoint] != USB_ENABLE_DISABLED);
08F6: CLRF 03
08F8: MOVF xFD,W
08FA: MOVFF FF2,6FF
08FE: BCF FF2.7
0900: MOVLB 0
0902: CALL 00AA
0906: MOVLB 6
0908: BTFSC xFF.7
090A: BSF FF2.7
090C: SUBLW FF
090E: BNZ 0914
0910: MOVLW 00
0912: BRA 0916
0914: MOVLW 01
0916: MOVWF 01
0918: BRA 0940
.................... }
.................... else { //OUT
091A: BRA 0940
.................... return(usb_ep_rx_type[endpoint] != USB_ENABLE_DISABLED);
091C: CLRF 03
091E: MOVF xFD,W
0920: MOVFF FF2,6FF
0924: BCF FF2.7
0926: MOVLB 0
0928: CALL 00CA
092C: MOVLB 6
092E: BTFSC xFF.7
0930: BSF FF2.7
0932: SUBLW FF
0934: BNZ 093A
0936: MOVLW 00
0938: BRA 093C
093A: MOVLW 01
093C: MOVWF 01
093E: BRA 0940
.................... }
.................... }
0940: MOVLB 0
0942: GOTO 0AA8 (RETURN)
....................
.................... // see usb.h for documentation
.................... void usb_isr_tok_in_dne(int8 endpoint) {
.................... if (endpoint==0) {
*
1058: MOVLB 6
105A: MOVF xFD,F
105C: BNZ 107A
.................... if (USB_stack_status.dev_req == GET_DESCRIPTOR) {usb_copy_desc_seg_to_ep();} //check this, we are missing report descriptor?
105E: DECFSZ 1D,W
1060: BRA 106C
1062: MOVLB 0
1064: CALL 03FA
.................... else if (USB_stack_status.dev_req == SET_ADDRESS) {usb_finish_set_address();}
1068: BRA 1076
106A: MOVLB 6
106C: MOVF 1D,W
106E: SUBLW 02
1070: BNZ 1078
1072: MOVLB 0
1074: BRA 0F7A
1076: MOVLB 6
.................... }
.................... #if USB_CDC_DEVICE
.................... else if (endpoint==USB_CDC_DATA_IN_ENDPOINT) { //see ex_usb_serial.c example and usb_cdc.h driver
1078: BRA 1086
107A: MOVF xFD,W
107C: SUBLW 02
107E: BNZ 1086
.................... usb_isr_tok_in_cdc_data_dne();
1080: MOVLB 0
1082: BRA 104E
1084: MOVLB 6
.................... }
.................... #endif
.................... }
1086: MOVLB 0
1088: RETLW 00
....................
.................... // see usb.h for documentation
.................... void usb_isr_tok_out_dne(int8 endpoint)
.................... {
.................... //TODO:
.................... if (endpoint==0) {
*
0F42: MOVLB 6
0F44: MOVF xFD,F
0F46: BNZ 0F50
.................... debug_usb(debug_putc,"TOUT 0 ");
.................... #if USB_CDC_DEVICE
.................... usb_isr_tok_out_cdc_control_dne();
0F48: MOVLB 0
0F4A: BRA 0E7E
.................... #else
.................... usb_init_ep0_setup();
.................... #endif
.................... }
.................... #if USB_CDC_DEVICE
.................... else if (endpoint==USB_CDC_DATA_OUT_ENDPOINT) { //see ex_usb_serial.c example and usb_cdc.h driver
0F4C: BRA 0F5A
0F4E: MOVLB 6
0F50: MOVF xFD,W
0F52: SUBLW 02
0F54: BNZ 0F5C
.................... usb_isr_tok_out_cdc_data_dne();
0F56: MOVLB 0
0F58: BRA 0F2C
0F5A: MOVLB 6
.................... }
.................... #endif
.................... //else {
.................... // bit_set(__usb_kbhit_status,endpoint);
.................... //}
.................... }
0F5C: MOVLB 0
0F5E: RETLW 00
....................
....................
.................... //---- process setup message stage -----------//
....................
.................... // see usb.h for documentation
.................... void usb_isr_tok_setup_dne(void)
.................... {
.................... USB_stack_status.dev_req=NONE; // clear the device request..
*
0BC0: CLRF 1D
....................
.................... switch(usb_ep0_rx_buffer[0] & 0x7F) {
0BC2: MOVLB 4
0BC4: MOVF x18,W
0BC6: ANDLW 7F
0BC8: MOVLB 0
0BCA: BZ 0BDA
0BCC: XORLW 01
0BCE: BZ 0BDC
0BD0: XORLW 03
0BD2: BZ 0BDE
0BD4: XORLW 23
0BD6: BZ 0BE0
0BD8: BRA 0BE2
....................
.................... case 0x00: //standard to device
.................... debug_usb(debug_putc," d");
.................... usb_isr_tkn_setup_StandardDevice();
0BDA: BRA 078C
.................... break;
....................
.................... case 0x01: //standard to interface
.................... debug_usb(debug_putc," i");
.................... usb_isr_tkn_setup_StandardInterface();
0BDC: BRA 0840
.................... break;
....................
.................... case 0x02: //standard to endpoint
.................... debug_usb(debug_putc," e");
.................... usb_isr_tkn_setup_StandardEndpoint();
0BDE: BRA 0AA2
.................... break;
....................
.................... #IF USB_HID_DEVICE
.................... case 0x21: //class specific request. the only class this driver supports is HID
.................... debug_usb(debug_putc," hid");
.................... usb_isr_tkn_setup_ClassInterface();
.................... break;
.................... #endif
....................
.................... #if USB_CDC_DEVICE
.................... case 0x21:
.................... debug_usb(debug_putc," cdc");
.................... usb_isr_tkn_cdc();
0BE0: BRA 0B12
.................... break;
.................... #endif
.................... //TODO: IF YOU WANT VENDOR SPECIFC REQUEST SUPPORT YOU MUST ADD IT HERE
....................
.................... default:
.................... usb_request_stall();
0BE2: RCALL 03F4
.................... break;
0BE4: BRA 0BE6
.................... }
.................... }
0BE6: GOTO 10C2 (RETURN)
....................
.................... /**************************************************************
.................... /* usb_isr_tkn_setup_StandardDevice()
.................... /*
.................... /* Input: usb_ep0_rx_buffer[1] == bRequest
.................... /*
.................... /* Summary: bmRequestType told us it was a Standard Device request.
.................... /* bRequest says which request. Only certain requests are valid,
.................... /* if a non-valid request was made then return with an Wrong-Statue (IDLE)
.................... /*
.................... /* Part of usb_isr_tok_setup_dne()
.................... /***************************************************************/
.................... void usb_isr_tkn_setup_StandardDevice(void) {
.................... switch(usb_ep0_rx_buffer[1]) {
*
078C: MOVLB 4
078E: MOVF x19,W
0790: MOVLB 0
0792: BZ 07AE
0794: XORLW 01
0796: BZ 07C2
0798: XORLW 02
079A: BZ 07DC
079C: XORLW 06
079E: BZ 07F4
07A0: XORLW 03
07A2: BZ 0806
07A4: XORLW 0E
07A6: BZ 0808
07A8: XORLW 01
07AA: BZ 0818
07AC: BRA 0838
....................
.................... case USB_STANDARD_REQUEST_GET_STATUS: //0
.................... debug_usb(debug_putc,"GS");
.................... usb_ep0_tx_buffer[0]=USB_stack_status.status_device;
07AE: MOVFF 1F,458
.................... usb_ep0_tx_buffer[1]=0;
07B2: MOVLB 4
07B4: CLRF x59
.................... usb_request_send_response(2);
07B6: MOVLW 02
07B8: MOVLB 7
07BA: MOVWF x00
07BC: MOVLB 0
07BE: RCALL 03EE
.................... break;
07C0: BRA 083C
....................
.................... case USB_STANDARD_REQUEST_CLEAR_FEATURE: //1
.................... if (usb_ep0_rx_buffer[2] == 1) {
07C2: MOVLB 4
07C4: DECFSZ x1A,W
07C6: BRA 07D6
.................... debug_usb(debug_putc,"CF");
.................... USB_stack_status.status_device &= 1;
07C8: MOVLW 01
07CA: ANDWF 1F,F
.................... usb_put_0len_0();
07CC: MOVLB 7
07CE: CLRF x00
07D0: MOVLB 0
07D2: RCALL 03EE
.................... }
.................... else
07D4: BRA 07DA
.................... usb_request_stall();
07D6: MOVLB 0
07D8: RCALL 03F4
.................... break;
07DA: BRA 083C
....................
.................... case USB_STANDARD_REQUEST_SET_FEATURE: //3
.................... if (usb_ep0_rx_buffer[2] == 1) {
07DC: MOVLB 4
07DE: DECFSZ x1A,W
07E0: BRA 07EE
.................... debug_usb(debug_putc,"SF");
.................... USB_stack_status.status_device |= 2;
07E2: BSF 1F.1
.................... usb_put_0len_0();
07E4: MOVLB 7
07E6: CLRF x00
07E8: MOVLB 0
07EA: RCALL 03EE
.................... }
.................... else
07EC: BRA 07F2
.................... usb_request_stall();
07EE: MOVLB 0
07F0: RCALL 03F4
.................... break;
07F2: BRA 083C
....................
.................... case USB_STANDARD_REQUEST_SET_ADDRESS: //5
.................... debug_usb(debug_putc,"SA");
.................... USB_stack_status.dev_req=SET_ADDRESS; //currently processing set_address request
07F4: MOVLW 02
07F6: MOVWF 1D
.................... USB_address_pending=usb_ep0_rx_buffer[2];
07F8: MOVFF 41A,26
.................... #ifdef __USBN__ //NATIONAL part handles this differently than pic16c7x5
.................... USB_stack_status.dev_req=NONE; //currently processing set_address request
.................... usb_set_address(USB_address_pending);
.................... USB_stack_status.curr_config=0; // make sure current configuration is 0
.................... #endif
.................... usb_put_0len_0();
07FC: MOVLB 7
07FE: CLRF x00
0800: MOVLB 0
0802: RCALL 03EE
.................... break;
0804: BRA 083C
....................
.................... case USB_STANDARD_REQUEST_GET_DESCRIPTOR: //6
.................... debug_usb(debug_putc,"GD");
.................... usb_Get_Descriptor();
0806: BRA 049C
.................... break;
....................
.................... case USB_STANDARD_REQUEST_GET_CONFIGURATION: //8
.................... debug_usb(debug_putc,"GC");
.................... usb_ep0_tx_buffer[0]=USB_stack_status.curr_config;
0808: MOVFF 1E,458
.................... usb_request_send_response(1);
080C: MOVLW 01
080E: MOVLB 7
0810: MOVWF x00
0812: MOVLB 0
0814: RCALL 03EE
.................... break;
0816: BRA 083C
....................
.................... case USB_STANDARD_REQUEST_SET_CONFIGURATION: //9
.................... if (usb_ep0_rx_buffer[2] <= USB_NUM_CONFIGURATIONS) {
0818: MOVLB 4
081A: MOVF x1A,W
081C: SUBLW 01
081E: BNC 0834
.................... USB_stack_status.curr_config=usb_ep0_rx_buffer[2];
0820: MOVFF 41A,1E
.................... usb_set_configured(usb_ep0_rx_buffer[2]);
0824: MOVFF 41A,6FD
0828: MOVLB 0
082A: BRA 055C
.................... debug_usb(debug_putc,"SC%U", USB_stack_status.curr_config);
.................... usb_put_0len_0();
082C: MOVLB 7
082E: CLRF x00
0830: MOVLB 0
0832: RCALL 03EE
.................... }
.................... break;
0834: MOVLB 0
0836: BRA 083C
....................
.................... default:
.................... usb_request_stall();
0838: RCALL 03F4
.................... break;
083A: BRA 083C
.................... }
.................... }
083C: GOTO 0BE6 (RETURN)
....................
.................... /**************************************************************
.................... /* usb_isr_tkn_setup_StandardInterface()
.................... /*
.................... /* Input: usb_ep0_rx_buffer[1] == bRequest
.................... /*
.................... /* Summary: bmRequestType told us it was a Standard Interface request.
.................... /* bRequest says which request. Only certain requests are valid,
.................... /* if a non-valid request was made then return with an Wrong-Statue (IDLE)
.................... /*
.................... /* Part of usb_isr_tok_setup_dne()
.................... /***************************************************************/
.................... void usb_isr_tkn_setup_StandardInterface(void) {
.................... int8 curr_config;
....................
.................... curr_config=USB_stack_status.curr_config;
0840: MOVFF 1E,6FD
....................
.................... switch (usb_ep0_rx_buffer[1]) {
0844: MOVLB 4
0846: MOVF x19,W
0848: MOVLB 0
084A: BZ 0856
084C: XORLW 0A
084E: BZ 0868
0850: XORLW 01
0852: BZ 08B6
0854: BRA 08E0
.................... case USB_STANDARD_REQUEST_GET_STATUS:
.................... debug_usb(debug_putc,"GS");
.................... usb_ep0_tx_buffer[0]=0;
0856: MOVLB 4
0858: CLRF x58
.................... usb_ep0_tx_buffer[1]=0;
085A: CLRF x59
.................... usb_request_send_response(2);
085C: MOVLW 02
085E: MOVLB 7
0860: MOVWF x00
0862: MOVLB 0
0864: RCALL 03EE
.................... break;
0866: BRA 08E4
....................
.................... case USB_STANDARD_REQUEST_GET_INTERFACE:
.................... if ( curr_config && (usb_ep0_rx_buffer[4] < USB_NUM_INTERFACES[curr_config-1]) ) { //book says only supports configed state
0868: MOVLB 6
086A: MOVF xFD,F
086C: BZ 08B0
086E: MOVLW 01
0870: SUBWF xFD,W
0872: CLRF 03
0874: MOVFF FF2,6FE
0878: BCF FF2.7
087A: MOVLB 0
087C: RCALL 019E
087E: MOVLB 6
0880: BTFSC xFE.7
0882: BSF FF2.7
0884: MOVWF 01
0886: MOVLB 4
0888: SUBWF x1C,W
088A: BTFSS FD8.0
088C: BRA 0892
088E: MOVLB 6
0890: BRA 08B0
.................... debug_usb(debug_putc,"GI");
.................... usb_ep0_tx_buffer[0]=USB_Interface[usb_ep0_rx_buffer[4]];//our new outgoing byte
0892: CLRF 03
0894: MOVF x1C,W
0896: ADDLW 29
0898: MOVWF FE9
089A: MOVLW 00
089C: ADDWFC 03,W
089E: MOVWF FEA
08A0: MOVFF FEF,458
.................... usb_request_send_response(1);; //send byte back
08A4: MOVLW 01
08A6: MOVLB 7
08A8: MOVWF x00
08AA: MOVLB 0
08AC: RCALL 03EE
.................... }
.................... else
08AE: BRA 08B4
.................... usb_request_stall();
08B0: MOVLB 0
08B2: RCALL 03F4
.................... break;
08B4: BRA 08E4
....................
.................... case USB_STANDARD_REQUEST_SET_INTERFACE:
.................... if (curr_config) { //if configured state
08B6: MOVLB 6
08B8: MOVF xFD,F
08BA: BZ 08DA
.................... debug_usb(debug_putc,"SI");
.................... USB_Interface[usb_ep0_rx_buffer[4]]=usb_ep0_rx_buffer[2];
08BC: CLRF 03
08BE: MOVLB 4
08C0: MOVF x1C,W
08C2: ADDLW 29
08C4: MOVWF FE9
08C6: MOVLW 00
08C8: ADDWFC 03,W
08CA: MOVWF FEA
08CC: MOVFF 41A,FEF
.................... usb_put_0len_0();
08D0: MOVLB 7
08D2: CLRF x00
08D4: MOVLB 0
08D6: RCALL 03EE
.................... }
.................... else
08D8: BRA 08DE
.................... usb_request_stall();
08DA: MOVLB 0
08DC: RCALL 03F4
.................... break;
08DE: BRA 08E4
....................
.................... #IF USB_HID_DEVICE
.................... case USB_STANDARD_REQUEST_GET_DESCRIPTOR:
.................... debug_usb(debug_putc,"GD");
.................... usb_Get_Descriptor();
.................... break;
.................... #endif
....................
.................... // case USB_STANDARD_REQUEST_CLEAR_FEATURE:
.................... // case USB_STANDARD_REQUEST_SET_FEATURE:
.................... // let default take care of these, goto wrongstate
.................... default:
.................... usb_request_stall();
08E0: RCALL 03F4
.................... break;
08E2: BRA 08E4
.................... }
.................... }
08E4: GOTO 0BE6 (RETURN)
....................
.................... /**************************************************************
.................... /* usb_isr_tkn_setup_StandardEndpoint()
.................... /*
.................... /* Input: usb_ep0_rx_buffer[1] == bRequest
.................... /*
.................... /* Summary: bmRequestType told us it was a Standard Endpoint request.
.................... /* bRequest says which request. Only certain requests are valid,
.................... /* if a non-valid request was made then return with an Wrong-Statue (IDLE)
.................... /*
.................... /* Part of usb_isr_tok_setup_dne()
.................... /***************************************************************/
.................... void usb_isr_tkn_setup_StandardEndpoint(void) {
.................... if (usb_endpoint_is_valid(usb_ep0_rx_buffer[4])) {
*
0AA2: MOVFF 41C,6FD
0AA6: BRA 08E8
0AA8: MOVF 01,F
0AAA: BZ 0B08
.................... switch(usb_ep0_rx_buffer[1]) {
0AAC: MOVLB 4
0AAE: MOVF x19,W
0AB0: XORLW 01
0AB2: MOVLB 0
0AB4: BZ 0AC0
0AB6: XORLW 02
0AB8: BZ 0AD0
0ABA: XORLW 03
0ABC: BZ 0AE0
0ABE: BRA 0B04
....................
.................... case USB_STANDARD_REQUEST_CLEAR_FEATURE:
.................... debug_usb(debug_putc,"CF");
.................... usb_unstall_ep(usb_ep0_rx_buffer[4]);
0AC0: MOVFF 41C,6FD
0AC4: BRA 0946
.................... usb_put_0len_0();
0AC6: MOVLB 7
0AC8: CLRF x00
0ACA: MOVLB 0
0ACC: RCALL 03EE
.................... break;
0ACE: BRA 0B08
....................
.................... case USB_STANDARD_REQUEST_SET_FEATURE:
.................... debug_usb(debug_putc,"SF");
.................... usb_stall_ep(usb_ep0_rx_buffer[4]);
0AD0: MOVFF 41C,6FD
0AD4: BRA 09B4
.................... usb_put_0len_0();
0AD6: MOVLB 7
0AD8: CLRF x00
0ADA: MOVLB 0
0ADC: RCALL 03EE
.................... break;
0ADE: BRA 0B08
....................
.................... case USB_STANDARD_REQUEST_GET_STATUS:
.................... debug_usb(debug_putc,"GS");
.................... usb_ep0_tx_buffer[0]=0;
0AE0: MOVLB 4
0AE2: CLRF x58
.................... usb_ep0_tx_buffer[1]=0;
0AE4: CLRF x59
.................... if (usb_endpoint_stalled(usb_ep0_rx_buffer[4])) {
0AE6: MOVFF 41C,6FD
0AEA: MOVLB 0
0AEC: BRA 0A24
0AEE: MOVF 01,F
0AF0: BZ 0AF8
.................... usb_ep0_tx_buffer[0]=1;
0AF2: MOVLW 01
0AF4: MOVLB 4
0AF6: MOVWF x58
.................... }
.................... usb_request_send_response(2);
0AF8: MOVLW 02
0AFA: MOVLB 7
0AFC: MOVWF x00
0AFE: MOVLB 0
0B00: RCALL 03EE
.................... break;
0B02: BRA 0B08
....................
.................... default:
.................... usb_request_stall();
0B04: RCALL 03F4
.................... break;
0B06: BRA 0B08
.................... }
.................... }
.................... }
0B08: GOTO 0BE6 (RETURN)
....................
.................... /**************************************************************
.................... /* usb_isr_tkn_setup_ClassInterface()
.................... /*
.................... /* Input: usb_ep0_rx_buffer[1] == bRequest
.................... /*
.................... /* Summary: bmRequestType told us it was a Class request. The only Class this drivers supports is HID.
.................... /* bRequest says which request. Only certain requests are valid,
.................... /* if a non-valid request was made then return with an Wrong-Statue (IDLE)
.................... /*
.................... /* Part of usb_isr_tok_setup_dne()
.................... /* Only compiled if HID_DEVICE is TRUE
.................... /***************************************************************/
.................... #IF USB_HID_DEVICE
.................... void usb_isr_tkn_setup_ClassInterface(void) {
.................... switch(usb_ep0_rx_buffer[1]) {
....................
.................... #IF USB_HID_BOOT_PROTOCOL
.................... case USB_HID_REQUEST_GET_PROTOCOL: //03
.................... debug_usb(debug_putc,"GP");
.................... usb_ep0_tx_buffer[0]=hid_protocol[usb_ep0_rx_buffer[4]];
.................... usb_request_send_response(1);
.................... break;
.................... #ENDIF
....................
.................... #IF USB_HID_BOOT_PROTOCOL
.................... case USB_HID_REQUEST_SET_PROTOCOL: //0b
.................... debug_usb(debug_putc,"SP");
.................... hid_protocol[usb_ep0_rx_buffer[4]]=usb_ep0_rx_buffer[2];
.................... usb_put_0len_0(); //send 0len packet69
.................... break;
.................... #ENDIF
....................
.................... #IF USB_HID_IDLE
.................... case USB_HID_REQUEST_SET_IDLE: //0a
.................... #error TODO: if you want to support SET_IDLE, add code here
.................... #ENDIF
....................
.................... #IF USB_HID_IDLE
.................... case USB_HID_REQUEST_GET_IDLE: //02
.................... #error TODO: if you want to support GET_IDLE, add code here
.................... #ENDIF
....................
.................... default:
.................... usb_request_stall();
.................... break;
.................... }
.................... }
.................... #ENDIF
....................
.................... /**************************************************************
.................... /* usb_Get_Descriptor()
.................... /*
.................... /* Input: usb_ep0_rx_buffer[3] == wValue, which descriptor we want
.................... /* usb_ep0_rx_buffer[6,7] == Max length the host will accept
.................... /*
.................... /* Summary: Checks to see if we want a standard descriptor (Interface, Endpoint, Config, Device, String, etc.),
.................... /* or a class specific (HID) descriptor. Since some pics (especially the PIC167x5) doesn't have
.................... /* pointers to constants we must simulate or own by setting up global registers that say
.................... /* which constant array to deal with, which position to start in this array, and the length.
.................... /* Once these globals are setup the first packet is sent. If a descriptor takes more than one packet
.................... /* the PC will send an IN request to endpoint 0, and this will be handled by usb_isr_tok_in_dne()
.................... /* which will send the rest of the data.
.................... /*
.................... /* Part of usb_isr_tok_setup_dne()
.................... /***************************************************************/
.................... void usb_Get_Descriptor() {
.................... usb_getdesc_ptr=0;
*
049C: CLRF 27
.................... USB_stack_status.getdesc_type=USB_GETDESC_CONFIG_TYPE;
049E: CLRF 20
....................
.................... switch(usb_ep0_rx_buffer[3]) {
04A0: MOVLB 4
04A2: MOVF x1B,W
04A4: XORLW 01
04A6: MOVLB 0
04A8: BZ 04B8
04AA: XORLW 03
04AC: BZ 04C2
04AE: XORLW 01
04B0: BZ 04C8
04B2: XORLW 22
04B4: BZ 04FA
04B6: BRA 053C
.................... case USB_DESC_DEVICE_TYPE: //1
.................... usb_getdesc_len=USB_DESC_DEVICE_LEN;
04B8: MOVLW 12
04BA: MOVWF 28
.................... USB_stack_status.getdesc_type=USB_GETDESC_DEVICE_TYPE;
04BC: MOVLW 03
04BE: MOVWF 20
.................... break;
04C0: BRA 0540
....................
.................... //windows hosts will send a FF max len and expect you to send all configs without asking for them individually.
.................... case USB_DESC_CONFIG_TYPE: //2
.................... usb_getdesc_len=USB_TOTAL_CONFIG_LEN;
04C2: MOVLW 43
04C4: MOVWF 28
.................... break;
04C6: BRA 0540
....................
.................... case USB_DESC_STRING_TYPE: //3
.................... USB_stack_status.getdesc_type=USB_GETDESC_STRING_TYPE;
04C8: MOVLW 02
04CA: MOVWF 20
.................... usb_getdesc_ptr=USB_STRING_DESC_OFFSET[usb_ep0_rx_buffer[2]];
04CC: CLRF 03
04CE: MOVLB 4
04D0: MOVF x1A,W
04D2: ADDLW 21
04D4: MOVWF FE9
04D6: MOVLW 00
04D8: ADDWFC 03,W
04DA: MOVWF FEA
04DC: MOVFF FEF,27
.................... usb_getdesc_len=USB_STRING_DESC[usb_getdesc_ptr];
04E0: CLRF 03
04E2: MOVF 27,W
04E4: MOVFF FF2,6FD
04E8: BCF FF2.7
04EA: MOVLB 0
04EC: RCALL 01EA
04EE: MOVLB 6
04F0: BTFSC xFD.7
04F2: BSF FF2.7
04F4: MOVWF 28
.................... break;
04F6: MOVLB 0
04F8: BRA 0540
....................
.................... #IF USB_HID_DEVICE || USB_CDC_DEVICE
.................... case USB_DESC_CLASS_TYPE: //0x21
.................... //TODO does this work for multiple interfaces or multiple languages?
.................... //usb_getdesc_ptr=USB_CLASS_DESCRIPTORS[0][usb_ep0_rx_buffer[4]][usb_ep0_rx_buffer[2]];
.................... usb_getdesc_ptr=USB_CLASS_DESCRIPTORS[0][0][usb_ep0_rx_buffer[2]];
04FA: CLRF 03
04FC: MOVLB 4
04FE: MOVF x1A,W
0500: MOVFF FF2,6FD
0504: BCF FF2.7
0506: MOVLB 0
0508: RCALL 01B0
050A: MOVLB 6
050C: BTFSC xFD.7
050E: BSF FF2.7
0510: MOVWF 27
.................... if (usb_getdesc_ptr!=0xFF) {
0512: INCFSZ 27,W
0514: BRA 0518
0516: BRA 0536
.................... usb_getdesc_len=USB_CONFIG_DESC[usb_getdesc_ptr];
0518: CLRF 03
051A: MOVF 27,W
051C: MOVFF FF2,6FD
0520: BCF FF2.7
0522: MOVLB 0
0524: RCALL 014A
0526: MOVLB 6
0528: BTFSC xFD.7
052A: BSF FF2.7
052C: MOVWF 28
.................... break;
052E: MOVLB 0
0530: BRA 0540
.................... }
.................... else {
0532: BRA 053C
0534: MOVLB 6
.................... usb_request_stall();
0536: MOVLB 0
0538: RCALL 03F4
.................... return;
053A: BRA 0558
.................... }
.................... #endif
....................
.................... #IF USB_HID_DEVICE
.................... case USB_DESC_HIDREPORT_TYPE: //0x22
.................... usb_getdesc_ptr=USB_CLASS_SPECIFIC_DESC_LOOKUP[0][usb_ep0_rx_buffer[4]];
.................... if (usb_getdesc_ptr !=0xFF) {
.................... USB_stack_status.getdesc_type=USB_GETDESC_HIDREPORT_TYPE;
.................... usb_getdesc_len=USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[0][usb_ep0_rx_buffer[4]];
.................... break;
.................... }
.................... else {
.................... usb_request_stall();
.................... return;
.................... }
.................... #endif
....................
.................... default:
.................... usb_request_stall();
053C: RCALL 03F4
.................... return;
053E: BRA 0558
.................... }
.................... if (usb_ep0_rx_buffer[7]==0) {
0540: MOVLB 4
0542: MOVF x1F,F
0544: BNZ 0550
.................... if (usb_getdesc_len > usb_ep0_rx_buffer[6])
0546: MOVF 28,W
0548: SUBWF x1E,W
054A: BC 0550
.................... usb_getdesc_len = usb_ep0_rx_buffer[6];
054C: MOVFF 41E,28
.................... }
.................... USB_stack_status.dev_req=GET_DESCRIPTOR;
0550: MOVLW 01
0552: MOVWF 1D
.................... usb_copy_desc_seg_to_ep();
0554: MOVLB 0
0556: RCALL 03FA
.................... }
0558: GOTO 083C (RETURN)
....................
.................... /**************************************************************
.................... /* usb_finish_set_address()
.................... /*
.................... /* Input: USB_address_pending holds the address we were asked to set to.
.................... /*
.................... /* Summary: Sets the address.
.................... /*
.................... /* This code should only be run on the PIC USB peripheral, and not the
.................... /* National peripheral.
.................... /*
.................... /* Part of usb_isr_tok_setup_dne()
.................... /***************************************************************/
.................... void usb_finish_set_address() {
.................... debug_usb(debug_putc," FSA ");
.................... USB_stack_status.curr_config=0; // make sure current configuration is 0
*
0F7A: CLRF 1E
....................
.................... #ifdef __PIC__
.................... USB_stack_status.dev_req=NONE; // no request pending
0F7C: CLRF 1D
.................... usb_set_address(USB_address_pending);
0F7E: MOVFF 26,6FE
0F82: BRA 0F60
.................... #endif
.................... }
0F84: GOTO 1076 (RETURN)
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... ///
.................... /// The following function retrieve data from constant arrays. This may
.................... /// look un-optimized, but remember that you can't create a pointer to
.................... /// a constant array.
.................... ///
.................... ///////////////////////////////////////////////////////////////////////////
.................... void usb_copy_desc_seg_to_ep(void) {
.................... unsigned int i=0;
*
03FA: MOVLB 6
03FC: CLRF xFE
.................... char c;
....................
.................... while ((usb_getdesc_len)&&(i<USB_MAX_EP0_PACKET_LENGTH))
.................... {
03FE: MOVF 28,F
0400: BZ 0486
0402: MOVF xFE,W
0404: SUBLW 3F
0406: BNC 0486
.................... switch(USB_stack_status.getdesc_type) {
0408: MOVF 20,W
040A: MOVLB 0
040C: BZ 0418
040E: XORLW 02
0410: BZ 0432
0412: XORLW 01
0414: BZ 044C
0416: BRA 0466
.................... case USB_GETDESC_CONFIG_TYPE:
.................... c=USB_CONFIG_DESC[usb_getdesc_ptr];
0418: CLRF 03
041A: MOVF 27,W
041C: MOVFF FF2,700
0420: BCF FF2.7
0422: RCALL 014A
0424: MOVLB 7
0426: BTFSC x00.7
0428: BSF FF2.7
042A: MOVFF FE8,6FF
.................... break;
042E: MOVLB 0
0430: BRA 0466
....................
.................... #IF USB_HID_DEVICE
.................... case USB_GETDESC_HIDREPORT_TYPE:
.................... c=USB_CLASS_SPECIFIC_DESC[usb_getdesc_ptr];
.................... break;
.................... #endif
....................
.................... case USB_GETDESC_STRING_TYPE:
.................... c=USB_STRING_DESC[usb_getdesc_ptr];
0432: CLRF 03
0434: MOVF 27,W
0436: MOVFF FF2,700
043A: BCF FF2.7
043C: RCALL 01EA
043E: MOVLB 7
0440: BTFSC x00.7
0442: BSF FF2.7
0444: MOVFF FE8,6FF
.................... break;
0448: MOVLB 0
044A: BRA 0466
....................
.................... case USB_GETDESC_DEVICE_TYPE:
.................... c=USB_DEVICE_DESC[usb_getdesc_ptr];
044C: CLRF 03
044E: MOVF 27,W
0450: MOVFF FF2,700
0454: BCF FF2.7
0456: RCALL 01C8
0458: MOVLB 7
045A: BTFSC x00.7
045C: BSF FF2.7
045E: MOVFF FE8,6FF
.................... break;
0462: MOVLB 0
0464: BRA 0466
.................... }
.................... usb_getdesc_ptr++;
0466: INCF 27,F
.................... usb_getdesc_len--;
0468: DECF 28,F
.................... usb_ep0_tx_buffer[i++]=c;
046A: MOVLB 6
046C: MOVF xFE,W
046E: INCF xFE,F
0470: ADDLW 58
0472: CLRF 03
0474: BTFSC FD8.0
0476: INCF 03,F
0478: MOVWF FE9
047A: MOVLW 04
047C: ADDWF 03,W
047E: MOVWF FEA
0480: MOVFF 6FF,FEF
.................... }
0484: BRA 03FE
....................
.................... if ((!usb_getdesc_len)&&(i!=USB_MAX_EP0_PACKET_LENGTH)) {
0486: MOVF 28,F
0488: BNZ 0492
048A: MOVF xFE,W
048C: SUBLW 40
048E: BZ 0492
.................... USB_stack_status.dev_req = NONE;
0490: CLRF 1D
.................... }
....................
.................... usb_request_send_response(i);
0492: MOVFF 6FE,700
0496: MOVLB 0
0498: RCALL 03EE
.................... }
049A: RETLW 00
....................
.................... #ENDIF
....................
....................
.................... struct {
.................... unsigned int32 dwDTERrate; //data terminal rate, in bits per second
.................... unsigned int8 bCharFormat; //num of stop bits (0=1, 1=1.5, 2=2)
.................... unsigned int8 bParityType; //parity (0=none, 1=odd, 2=even, 3=mark, 4=space)
.................... unsigned int8 bDataBits; //data bits (5,6,7,8 or 16)
.................... } __attribute__((__packed__)) usb_cdc_line_coding;
....................
.................... //length of time, in ms, of break signal as we received in a SendBreak message.
.................... //if ==0xFFFF, send break signal until we receive a 0x0000.
.................... unsigned int16 usb_cdc_break;
....................
.................... unsigned int8 usb_cdc_encapsulated_cmd[8];
....................
.................... unsigned int8 usb_cdc_put_buffer[USB_CDC_DATA_IN_SIZE];
.................... #define usb_cdc_put_buffer_free() usb_tbe(USB_CDC_DATA_IN_ENDPOINT)
.................... #if USB_CDC_DATA_IN_SIZE>=0x100
.................... unsigned int16 usb_cdc_put_buffer_nextin=0;
.................... // int16 usb_cdc_last_data_packet_size;
.................... #else
.................... unsigned int8 usb_cdc_put_buffer_nextin=0;
.................... // int8 usb_cdc_last_data_packet_size;
.................... #endif
....................
.................... struct {
.................... int1 got;
.................... #if USB_CDC_DATA_OUT_SIZE>=0x100
.................... unsigned int16 len;
.................... unsigned int16 index;
.................... #else
.................... unsigned int8 len;
.................... unsigned int8 index;
.................... #endif
.................... } usb_cdc_get_buffer_status;
....................
.................... #if defined(__PIC__)
.................... #define usb_cdc_get_buffer_status_buffer usb_ep2_rx_buffer
.................... #else
.................... unsigned int8 usb_cdc_get_buffer_status_buffer[USB_CDC_DATA_OUT_SIZE];
.................... #endif
....................
.................... int1 usb_cdc_got_set_line_coding;
....................
.................... struct {
.................... int1 dte_present; //1=DTE present, 0=DTE not present
.................... int1 active; //1=activate carrier, 0=deactivate carrier
.................... unsigned int reserved:6;
.................... } usb_cdc_carrier;
....................
.................... unsigned int8 g_LastCDCDataPacketSize;
....................
.................... enum {USB_CDC_OUT_NOTHING=0, USB_CDC_OUT_COMMAND=1, USB_CDC_OUT_LINECODING=2, USB_CDC_WAIT_0LEN=3} __usb_cdc_state=0;
....................
.................... #if defined(__PCH__)
.................... #byte INTCON=0xFF2
.................... #bit INT_GIE=INTCON.7
.................... #else
.................... #word SR=0x42
.................... #endif
....................
.................... //handle OUT token done interrupt on endpoint 0 [read encapsulated cmd and line coding data]
.................... void usb_isr_tok_out_cdc_control_dne(void) {
.................... debug_usb(debug_putc,"CDC %X ",__usb_cdc_state);
....................
.................... switch (__usb_cdc_state) {
*
0E7E: MOVF x83,W
0E80: XORLW 01
0E82: BZ 0E8A
0E84: XORLW 03
0E86: BZ 0EB2
0E88: BRA 0EDA
.................... //printf(putc_tbe,"@%X@\r\n", __usb_cdc_state);
.................... case USB_CDC_OUT_COMMAND:
.................... //usb_get_packet(0, usb_cdc_encapsulated_cmd, 8);
.................... memcpy(usb_cdc_encapsulated_cmd, usb_ep0_rx_buffer,8);
0E8A: CLRF FEA
0E8C: MOVLW 34
0E8E: MOVWF FE9
0E90: MOVLW 04
0E92: MOVWF FE2
0E94: MOVLW 18
0E96: MOVWF FE1
0E98: MOVLW 08
0E9A: MOVWF 01
0E9C: MOVFF FE6,FEE
0EA0: DECFSZ 01,F
0EA2: BRA 0E9C
.................... #if USB_MAX_EP0_PACKET_LENGTH==8
.................... __usb_cdc_state=USB_CDC_WAIT_0LEN;
.................... usb_request_get_data();
.................... #else
.................... usb_put_0len_0();
0EA4: MOVLB 7
0EA6: CLRF x00
0EA8: MOVLB 0
0EAA: CALL 03EE
.................... __usb_cdc_state=0;
0EAE: CLRF x83
.................... #endif
.................... break;
0EB0: BRA 0EE2
....................
.................... #if USB_MAX_EP0_PACKET_LENGTH==8
.................... case USB_CDC_WAIT_0LEN:
.................... usb_put_0len_0();
.................... __usb_cdc_state=0;
.................... break;
.................... #endif
....................
.................... case USB_CDC_OUT_LINECODING:
.................... //usb_get_packet(0, &usb_cdc_line_coding, 7);
.................... //printf(putc_tbe,"\r\n!GSLC FIN!\r\n");
.................... memcpy(&usb_cdc_line_coding, usb_ep0_rx_buffer,7);
0EB2: CLRF FEA
0EB4: MOVLW 2B
0EB6: MOVWF FE9
0EB8: MOVLW 04
0EBA: MOVWF FE2
0EBC: MOVLW 18
0EBE: MOVWF FE1
0EC0: MOVLW 07
0EC2: MOVWF 01
0EC4: MOVFF FE6,FEE
0EC8: DECFSZ 01,F
0ECA: BRA 0EC4
.................... __usb_cdc_state=0;
0ECC: CLRF x83
.................... usb_put_0len_0();
0ECE: MOVLB 7
0ED0: CLRF x00
0ED2: MOVLB 0
0ED4: CALL 03EE
.................... break;
0ED8: BRA 0EE2
....................
.................... default:
.................... __usb_cdc_state=0;
0EDA: CLRF x83
.................... usb_init_ep0_setup();
0EDC: CALL 0284
.................... break;
0EE0: BRA 0EE2
.................... }
.................... }
0EE2: GOTO 0F4C (RETURN)
....................
.................... //handle IN token on 0 (setup packet)
.................... void usb_isr_tkn_cdc(void) {
.................... //make sure the request goes to a CDC interface
.................... if ((usb_ep0_rx_buffer[4] == 1) || (usb_ep0_rx_buffer[4] == 0)) {
*
0B12: MOVLB 4
0B14: DECFSZ x1C,W
0B16: BRA 0B1A
0B18: BRA 0B1E
0B1A: MOVF x1C,F
0B1C: BNZ 0BBA
.................... //printf(putc_tbe,"!%X!\r\n", usb_ep0_rx_buffer[1]);
.................... switch(usb_ep0_rx_buffer[1]) {
0B1E: MOVF x19,W
0B20: MOVLB 0
0B22: BZ 0B3A
0B24: XORLW 01
0B26: BZ 0B42
0B28: XORLW 21
0B2A: BZ 0B64
0B2C: XORLW 01
0B2E: BZ 0B6E
0B30: XORLW 03
0B32: BZ 0B94
0B34: XORLW 01
0B36: BZ 0BA2
0B38: BRA 0BB4
.................... case 0x00: //send_encapsulated_command
.................... __usb_cdc_state=USB_CDC_OUT_COMMAND;
0B3A: MOVLW 01
0B3C: MOVWF x83
.................... usb_request_get_data();
0B3E: RCALL 0B0C
.................... break;
0B40: BRA 0BB8
....................
.................... case 0x01: //get_encapsulated_command
.................... memcpy(usb_ep0_tx_buffer, usb_cdc_encapsulated_cmd, 8);
0B42: MOVLW 04
0B44: MOVWF FEA
0B46: MOVLW 58
0B48: MOVWF FE9
0B4A: CLRF FE2
0B4C: MOVLW 34
0B4E: MOVWF FE1
0B50: MOVLW 08
0B52: MOVWF 01
0B54: MOVFF FE6,FEE
0B58: DECFSZ 01,F
0B5A: BRA 0B54
.................... usb_request_send_response(usb_ep0_rx_buffer[6]); //send wLength bytes
0B5C: MOVFF 41E,700
0B60: RCALL 03EE
.................... break;
0B62: BRA 0BB8
....................
.................... case 0x20: //set_line_coding
.................... debug_usb(debug_putc,"!GSLC!");
.................... __usb_cdc_state=USB_CDC_OUT_LINECODING;
0B64: MOVLW 02
0B66: MOVWF x83
.................... usb_cdc_got_set_line_coding=TRUE;
0B68: BSF x80.0
.................... usb_request_get_data();
0B6A: RCALL 0B0C
.................... break;
0B6C: BRA 0BB8
....................
.................... case 0x21: //get_line_coding
.................... memcpy(usb_ep0_tx_buffer, &usb_cdc_line_coding, sizeof(usb_cdc_line_coding));
0B6E: MOVLW 04
0B70: MOVWF FEA
0B72: MOVLW 58
0B74: MOVWF FE9
0B76: CLRF FE2
0B78: MOVLW 2B
0B7A: MOVWF FE1
0B7C: MOVLW 07
0B7E: MOVWF 01
0B80: MOVFF FE6,FEE
0B84: DECFSZ 01,F
0B86: BRA 0B80
.................... usb_request_send_response(sizeof(usb_cdc_line_coding)); //send wLength bytes
0B88: MOVLW 07
0B8A: MOVLB 7
0B8C: MOVWF x00
0B8E: MOVLB 0
0B90: RCALL 03EE
.................... break;
0B92: BRA 0BB8
....................
.................... case 0x22: //set_control_line_state
.................... usb_cdc_carrier=usb_ep0_rx_buffer[2];
0B94: MOVFF 41A,81
.................... usb_put_0len_0();
0B98: MOVLB 7
0B9A: CLRF x00
0B9C: MOVLB 0
0B9E: RCALL 03EE
.................... break;
0BA0: BRA 0BB8
....................
.................... case 0x23: //send_break
.................... usb_cdc_break=make16(usb_ep0_rx_buffer[2],usb_ep0_rx_buffer[3]);
0BA2: MOVFF 41A,33
0BA6: MOVFF 41B,32
.................... usb_put_0len_0();
0BAA: MOVLB 7
0BAC: CLRF x00
0BAE: MOVLB 0
0BB0: RCALL 03EE
.................... break;
0BB2: BRA 0BB8
....................
.................... default:
.................... usb_request_stall();
0BB4: RCALL 03F4
.................... break;
0BB6: BRA 0BB8
0BB8: MOVLB 4
.................... }
.................... }
.................... }
0BBA: MOVLB 0
0BBC: GOTO 0BE6 (RETURN)
....................
.................... //handle OUT token done interrupt on endpoint 3 [buffer incoming received chars]
.................... void usb_isr_tok_out_cdc_data_dne(void) {
.................... usb_cdc_get_buffer_status.got=TRUE;
*
0F2C: BSF x7D.0
.................... usb_cdc_get_buffer_status.index=0;
0F2E: CLRF x7F
.................... #if (defined(__PIC__) && __PIC__)
.................... usb_cdc_get_buffer_status.len=usb_rx_packet_size(USB_CDC_DATA_OUT_ENDPOINT);
0F30: MOVLW 02
0F32: MOVLB 6
0F34: MOVWF xFE
0F36: MOVLB 0
0F38: BRA 0EE6
0F3A: MOVFF 01,7E
.................... #else
.................... usb_cdc_get_buffer_status.len=usb_get_packet_buffer(
.................... USB_CDC_DATA_OUT_ENDPOINT,&usb_cdc_get_buffer_status_buffer[0],USB_CDC_DATA_OUT_SIZE);
.................... #endif
.................... }
0F3E: GOTO 0F5A (RETURN)
....................
.................... //handle IN token done interrupt on endpoint 2 [transmit buffered characters]
.................... void usb_isr_tok_in_cdc_data_dne(void)
.................... {
.................... //putc('!');
.................... if (usb_cdc_put_buffer_nextin /* || (g_LastCDCDataPacketSize == USB_CDC_DATA_IN_SIZE)*/ )
*
104E: MOVF x7C,F
1050: BZ 1054
.................... {
.................... //printf("FL3 %LU\r\n", (int16)usb_cdc_put_buffer_nextin);
.................... usb_cdc_flush_out_buffer();
1052: RCALL 102C
.................... }
.................... }
1054: GOTO 1084 (RETURN)
....................
.................... void usb_cdc_flush_out_buffer(void)
.................... {
.................... //printf(putc_tbe, "FL %U\r\n", usb_cdc_put_buffer_nextin);
.................... usb_put_packet(USB_CDC_DATA_IN_ENDPOINT,usb_cdc_put_buffer,usb_cdc_put_buffer_nextin,USB_DTS_TOGGLE);
*
102C: MOVLW 02
102E: MOVLB 7
1030: MOVWF x3A
1032: CLRF x3C
1034: MOVLW 3C
1036: MOVWF x3B
1038: CLRF x3E
103A: MOVFF 7C,73D
103E: MOVLW 02
1040: MOVWF x3F
1042: MOVLB 0
1044: RCALL 0F88
.................... g_LastCDCDataPacketSize = usb_cdc_put_buffer_nextin;
1046: MOVFF 7C,82
.................... usb_cdc_put_buffer_nextin=0;
104A: CLRF x7C
.................... }
104C: RETLW 00
....................
.................... void usb_cdc_init(void)
.................... {
.................... usb_cdc_line_coding.dwDTERrate = 9600;
*
035C: CLRF 2E
035E: CLRF 2D
0360: MOVLW 25
0362: MOVWF 2C
0364: MOVLW 80
0366: MOVWF 2B
.................... usb_cdc_line_coding.bCharFormat = 0;
0368: CLRF 2F
.................... usb_cdc_line_coding.bParityType = 0;
036A: CLRF 30
.................... usb_cdc_line_coding.bDataBits = 8;
036C: MOVLW 08
036E: MOVWF 31
.................... (int8)usb_cdc_carrier = 0;
0370: CLRF x81
.................... usb_cdc_got_set_line_coding = FALSE;
0372: BCF x80.0
.................... usb_cdc_break = 0;
0374: CLRF 33
0376: CLRF 32
.................... usb_cdc_put_buffer_nextin = 0;
0378: CLRF x7C
.................... usb_cdc_get_buffer_status.got = 0;
037A: BCF x7D.0
.................... }
037C: RETLW 00
....................
.................... ////////////////// END USB CONTROL HANDLING //////////////////////////////////
....................
.................... ////////////////// BEGIN USB<->RS232 CDC LIBRARY /////////////////////////////
....................
.................... void usb_cdc_get_discard(void)
.................... {
.................... usb_cdc_get_buffer_status.got = FALSE;
.................... usb_flush_out(USB_CDC_DATA_OUT_ENDPOINT, USB_DTS_TOGGLE);
.................... }
....................
.................... char usb_cdc_getc(void)
.................... {
.................... char c;
....................
.................... while (!usb_cdc_kbhit()) {}
....................
.................... c=usb_cdc_get_buffer_status_buffer[usb_cdc_get_buffer_status.index++];
....................
.................... if (usb_cdc_get_buffer_status.index >= usb_cdc_get_buffer_status.len)
.................... {
.................... usb_cdc_get_discard();
.................... }
....................
.................... return(c);
.................... }
....................
.................... void usb_cdc_putc_fast(char c)
.................... {
.................... #if defined(__PCH__)
.................... int1 old_gie;
....................
.................... //disable global interrupts
.................... old_gie = INT_GIE;
*
1376: MOVLB 6
1378: BCF xDD.0
137A: BTFSC FF2.7
137C: BSF xDD.0
.................... INT_GIE = 0;
137E: BCF FF2.7
.................... #else
.................... int16 oldSR;
....................
.................... oldSR = SR;
.................... SR |= 0xE0;
.................... #endif
....................
.................... if (usb_cdc_put_buffer_nextin >= USB_CDC_DATA_IN_SIZE) {
1380: MOVLB 0
1382: MOVF x7C,W
1384: SUBLW 3F
1386: BC 138C
.................... usb_cdc_put_buffer_nextin = USB_CDC_DATA_IN_SIZE-1; //we just overflowed the buffer!
1388: MOVLW 3F
138A: MOVWF x7C
.................... }
.................... usb_cdc_put_buffer[usb_cdc_put_buffer_nextin++] = c;
138C: MOVF x7C,W
138E: INCF x7C,F
1390: CLRF 03
1392: ADDLW 3C
1394: MOVWF FE9
1396: MOVLW 00
1398: ADDWFC 03,W
139A: MOVWF FEA
139C: MOVFF 6DC,FEF
....................
.................... //renable global interrupts
.................... #if defined(__PCH__)
.................... INT_GIE = old_gie;
13A0: BCF FF2.7
13A2: MOVLB 6
13A4: BTFSC xDD.0
13A6: BSF FF2.7
13A8: CLRF 18
13AA: BTFSC FF2.7
13AC: BSF 18.7
13AE: BCF FF2.7
.................... #else
.................... SR = oldSR;
.................... #endif
....................
.................... /*
.................... if (usb_tbe(USB_CDC_DATA_IN_ENDPOINT)) {
.................... if (usb_cdc_put_buffer_nextin)
.................... usb_cdc_flush_out_buffer();
.................... }
.................... */
.................... if (usb_cdc_put_buffer_free()) {
13B0: MOVLW 02
13B2: MOVLB 7
13B4: MOVWF x47
13B6: MOVLB 0
13B8: RCALL 0D06
13BA: BTFSC 18.7
13BC: BSF FF2.7
13BE: MOVF 01,F
13C0: BZ 13D0
13C2: CLRF 18
13C4: BTFSC FF2.7
13C6: BSF 18.7
13C8: BCF FF2.7
.................... //printf("FL2 %LU\r\n", (int16)usb_cdc_put_buffer_nextin);
.................... usb_cdc_flush_out_buffer();
13CA: RCALL 102C
13CC: BTFSC 18.7
13CE: BSF FF2.7
.................... }
.................... //putc('*');
.................... }
13D0: GOTO 140A (RETURN)
....................
.................... void usb_cdc_putc(char c)
.................... {
.................... while (!usb_cdc_putready())
.................... {
13D4: MOVF x7C,W
13D6: SUBLW 3F
13D8: BC 1404
13DA: CLRF 18
13DC: BTFSC FF2.7
13DE: BSF 18.7
13E0: BCF FF2.7
.................... if (usb_cdc_put_buffer_free())
13E2: MOVLW 02
13E4: MOVLB 7
13E6: MOVWF x47
13E8: MOVLB 0
13EA: RCALL 0D06
13EC: BTFSC 18.7
13EE: BSF FF2.7
13F0: MOVF 01,F
13F2: BZ 1402
13F4: CLRF 18
13F6: BTFSC FF2.7
13F8: BSF 18.7
13FA: BCF FF2.7
.................... {
.................... //printf("FL1 %LU\r\n", (int16)usb_cdc_put_buffer_nextin);
.................... usb_cdc_flush_out_buffer();
13FC: RCALL 102C
13FE: BTFSC 18.7
1400: BSF FF2.7
.................... }
.................... //delay_ms(500);
.................... //printf(putc_tbe,"TBE=%U CNT=%U LST=%U\r\n",usb_tbe(USB_CDC_DATA_IN_ENDPOINT), usb_cdc_put_buffer_nextin, usb_cdc_last_data_packet_size);
.................... }
1402: BRA 13D4
.................... //putc('.');
.................... //putc(c);
.................... usb_cdc_putc_fast(c);
1404: MOVFF 6DB,6DC
1408: BRA 1376
.................... }
140A: RETLW 00
....................
.................... #include <ctype.h>
.................... ////////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2003 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ////////////////////////////////////////////////////////////////////////////
....................
.................... #ifndef _CTYPE
.................... #define _CTYPE
....................
.................... #define islower(x) isamong(x,"abcdefghijklmnopqrstuvwxyz")
.................... #define isupper(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZ")
.................... #define isalnum(x) isamong(x,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
.................... #define isalpha(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
.................... #define isdigit(x) isamong(x,"0123456789")
.................... #define isspace(x) ((x)==' ')
.................... #define isxdigit(x) isamong(x,"0123456789ABCDEFabcdef")
.................... #define iscntrl(x) ((x)<' ')
.................... #define isprint(x) ((x)>=' ')
.................... #define isgraph(x) ((x)>' ')
.................... #define ispunct(x) (((x)>' ')&&!isalnum(x))
....................
.................... #endif
....................
....................
....................
.................... BYTE gethex1_usb()
.................... {
.................... char digit;
....................
.................... digit = usb_cdc_getc();
....................
.................... usb_cdc_putc(digit);
....................
.................... if(digit<='9')
.................... return(digit-'0');
.................... else
.................... return((toupper(digit)-'A')+10);
.................... }
....................
.................... BYTE gethex_usb() {
.................... unsigned int8 lo,hi;
....................
.................... hi = gethex1_usb();
.................... lo = gethex1_usb();
.................... if(lo==0xdd)
.................... return(hi);
.................... else
.................... return( hi*16+lo );
.................... }
....................
.................... void get_string_usb(char* s, unsigned int max) {
.................... unsigned int len;
.................... char c;
....................
.................... --max;
.................... len=0;
.................... do {
.................... c=usb_cdc_getc();
.................... if(c==8) { // Backspace
.................... if(len>0) {
.................... len--;
.................... usb_cdc_putc(c);
.................... usb_cdc_putc(' ');
.................... usb_cdc_putc(c);
.................... }
.................... } else if ((c>=' ')&&(c<='~'))
.................... if(len<max) {
.................... s[len++]=c;
.................... usb_cdc_putc(c);
.................... }
.................... } while(c!=13);
.................... s[len]=0;
.................... }
....................
....................
.................... // stdlib.h is required for the ato_ conversions
.................... // in the following functions
.................... #ifdef _STDLIB
....................
.................... signed int get_int_usb() {
.................... char s[7];
.................... signed int i;
....................
.................... get_string_usb(s, 7);
....................
.................... i=atoi(s);
.................... return(i);
.................... }
....................
.................... signed long get_long_usb() {
.................... char s[13];
.................... signed long l;
....................
.................... get_string_usb(s, 13);
.................... l=atol(s);
.................... return(l);
.................... }
....................
.................... float get_float_usb() {
.................... char s[20];
.................... float f;
....................
.................... get_string_usb(s, 20);
.................... f = atof(s);
.................... return(f);
.................... }
....................
.................... #endif
....................
.................... #include <math.h>
.................... ////////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2008 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ////////////////////////////////////////////////////////////////////////////
.................... //// ////
.................... //// History: ////
.................... //// * 9/20/2001 : Improvments are made to sin/cos code. ////
.................... //// The code now is small, much faster, ////
.................... //// and more accurate. ////
.................... //// * 2/21/2007 : Compiler handles & operator differently and does
.................... //// not return generic (int8 *) so type cast is done ////
.................... //// ////
.................... ////////////////////////////////////////////////////////////////////////////
....................
.................... #ifndef MATH_H
.................... #define MATH_H
....................
.................... #ifdef PI
.................... #undef PI
.................... #endif
.................... #define PI 3.1415926535897932
....................
....................
.................... #define SQRT2 1.4142135623730950
....................
.................... //float const ps[4] = {5.9304945, 21.125224, 8.9403076, 0.29730279};
.................... //float const qs[4] = {1.0000000, 15.035723, 17.764134, 2.4934718};
....................
.................... ///////////////////////////// Round Functions //////////////////////////////
....................
.................... float32 CEIL_FLOOR(float32 x, unsigned int8 n)
.................... {
.................... float32 y, res;
.................... unsigned int16 l;
.................... int1 s;
....................
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y <= 32768.0)
.................... res = (float32)(unsigned int16)y;
....................
.................... else if (y < 10000000.0)
.................... {
.................... l = (unsigned int16)(y/32768.0);
.................... y = 32768.0*(y/32768.0 - (float32)l);
.................... res = 32768.0*(float32)l;
.................... res += (float32)(unsigned int16)y;
.................... }
....................
.................... else
.................... res = y;
....................
.................... y = y - (float32)(unsigned int16)y;
....................
.................... if (s)
.................... res = -res;
....................
.................... if (y != 0)
.................... {
.................... if (s == 1 && n == 0)
.................... res -= 1.0;
....................
.................... if (s == 0 && n == 1)
.................... res += 1.0;
.................... }
.................... if (x == 0)
.................... res = 0;
....................
.................... return (res);
.................... }
....................
.................... // Overloaded Functions to take care for new Data types in PCD
.................... // Overloaded function CEIL_FLOOR() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 CEIL_FLOOR(float48 x, unsigned int8 n)
.................... {
.................... float48 y, res;
.................... unsigned int16 l;
.................... int1 s;
....................
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y <= 32768.0)
.................... res = (float48)(unsigned int16)y;
....................
.................... else if (y < 10000000.0)
.................... {
.................... l = (unsigned int16)(y/32768.0);
.................... y = 32768.0*(y/32768.0 - (float48)l);
.................... res = 32768.0*(float32)l;
.................... res += (float48)(unsigned int16)y;
.................... }
....................
.................... else
.................... res = y;
....................
.................... y = y - (float48)(unsigned int16)y;
....................
.................... if (s)
.................... res = -res;
....................
.................... if (y != 0)
.................... {
.................... if (s == 1 && n == 0)
.................... res -= 1.0;
....................
.................... if (s == 0 && n == 1)
.................... res += 1.0;
.................... }
.................... if (x == 0)
.................... res = 0;
....................
.................... return (res);
.................... }
....................
....................
.................... // Overloaded function CEIL_FLOOR() for data type - Float64
.................... float64 CEIL_FLOOR(float64 x, unsigned int8 n)
.................... {
.................... float64 y, res;
.................... unsigned int16 l;
.................... int1 s;
....................
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y <= 32768.0)
.................... res = (float64)(unsigned int16)y;
....................
.................... else if (y < 10000000.0)
.................... {
.................... l = (unsigned int16)(y/32768.0);
.................... y = 32768.0*(y/32768.0 - (float64)l);
.................... res = 32768.0*(float64)l;
.................... res += (float64)(unsigned int16)y;
.................... }
....................
.................... else
.................... res = y;
....................
.................... y = y - (float64)(unsigned int16)y;
....................
.................... if (s)
.................... res = -res;
....................
.................... if (y != 0)
.................... {
.................... if (s == 1 && n == 0)
.................... res -= 1.0;
....................
.................... if (s == 0 && n == 1)
.................... res += 1.0;
.................... }
.................... if (x == 0)
.................... res = 0;
....................
.................... return (res);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float floor(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : rounds down the number x.
.................... // Date : N/A
.................... //
.................... float32 floor(float32 x)
.................... {
.................... return CEIL_FLOOR(x, 0);
.................... }
.................... // Following 2 functions are overloaded functions of floor() for PCD
.................... // Overloaded function floor() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 floor(float48 x)
.................... {
.................... return CEIL_FLOOR(x, 0);
.................... }
....................
.................... // Overloaded function floor() for data type - Float64
.................... float64 floor(float64 x)
.................... {
.................... return CEIL_FLOOR(x, 0);
.................... }
.................... #endif
....................
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float ceil(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : rounds up the number x.
.................... // Date : N/A
.................... //
.................... float32 ceil(float32 x)
.................... {
.................... return CEIL_FLOOR(x, 1);
.................... }
.................... // Following 2 functions are overloaded functions of ceil() for PCD
.................... // Overloaded function ceil() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 ceil(float48 x)
.................... {
.................... return CEIL_FLOOR(x, 1);
.................... }
....................
.................... // Overloaded function ceil() for data type - Float64
.................... float64 ceil(float64 x)
.................... {
.................... return CEIL_FLOOR(x, 1);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float fabs(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : Computes the absolute value of floating point number x
.................... // Returns : returns the absolute value of x
.................... // Date : N/A
.................... //
.................... #define fabs abs
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float fmod(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : Computes the floating point remainder of x/y
.................... // Returns : returns the value of x= i*y, for some integer i such that, if y
.................... // is non zero, the result has the same isgn of x na dmagnitude less than the
.................... // magnitude of y. If y is zero then a domain error occurs.
.................... // Date : N/A
.................... //
....................
.................... float fmod(float32 x,float32 y)
.................... {
.................... float32 i;
.................... if (y!=0.0)
.................... {
.................... i=(x/y < 0.0)? ceil(x/y): floor(x/y);
.................... return(x-(i*y));
.................... }
.................... else
.................... {
.................... #ifdef _ERRNO
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... }
.................... }
.................... //Overloaded function for fmod() for PCD
.................... // Overloaded function fmod() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 fmod(float48 x,float48 y)
.................... {
.................... float48 i;
.................... if (y!=0.0)
.................... {
.................... i=(x/y < 0.0)? ceil(x/y): floor(x/y);
.................... return(x-(i*y));
.................... }
.................... else
.................... {
.................... #ifdef _ERRNO
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... }
.................... }
.................... // Overloaded function fmod() for data type - Float64
.................... float64 fmod(float64 x,float64 y)
.................... {
.................... float64 i;
.................... if (y!=0.0)
.................... {
.................... i=(x/y < 0.0)? ceil(x/y): floor(x/y);
.................... return(x-(i*y));
.................... }
.................... else
.................... {
.................... #ifdef _ERRNO
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... }
.................... }
.................... #endif
.................... //////////////////// Exponential and logarithmic functions ////////////////////
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float exp(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the value (e^x)
.................... // Date : N/A
.................... //
.................... #define LN2 0.6931471805599453
....................
.................... float const pe[6] = {0.000207455774, 0.00127100575, 0.00965065093,
.................... 0.0554965651, 0.240227138, 0.693147172};
....................
....................
.................... float32 exp(float32 x)
.................... {
.................... float32 y, res, r;
.................... #if defined(__PCD__)
.................... int8 data1;
.................... #endif
.................... signed int8 n;
.................... int1 s;
.................... #ifdef _ERRNO
.................... if(x > 88.722838)
.................... {
.................... errno=ERANGE;
.................... return(0);
.................... }
.................... #endif
.................... n = (signed int16)(x/LN2);
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... n = -n;
.................... y = -y;
.................... }
....................
.................... res = 0.0;
.................... #if !defined(__PCD__)
.................... *((unsigned int8 *)(&res)) = n + 0x7F;
.................... #endif
....................
.................... #if defined(__PCD__) // Takes care of IEEE format for PCD
.................... data1 = n+0x7F;
.................... if(bit_test(data1,0))
.................... bit_set(*(((unsigned int8 *)(&res)+2)),7);
.................... rotate_right(&data1,1);
.................... bit_clear(data1,7);
.................... *(((unsigned int8 *)(&res)+3)) = data1;
.................... #endif
....................
.................... y = y/LN2 - (float32)n;
....................
.................... r = pe[0]*y + pe[1];
.................... r = r*y + pe[2];
.................... r = r*y + pe[3];
.................... r = r*y + pe[4];
.................... r = r*y + pe[5];
....................
.................... res = res*(1.0 + y*r);
....................
.................... if (s)
.................... res = 1.0/res;
.................... return(res);
.................... }
....................
....................
.................... //Overloaded function for exp() for PCD
.................... // Overloaded function exp() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 exp(float48 x)
.................... {
.................... float48 y, res, r;
.................... int8 data1;
.................... signed int8 n;
.................... int1 s;
.................... #ifdef _ERRNO
.................... if(x > 88.722838)
.................... {
.................... errno=ERANGE;
.................... return(0);
.................... }
.................... #endif
.................... n = (signed int16)(x/LN2);
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... n = -n;
.................... y = -y;
.................... }
....................
.................... res = 0.0;
....................
.................... data1 = n+0x7F;
.................... if(bit_test(data1,0))
.................... bit_set(*(((unsigned int8 *)(&res)+4)),7);
.................... rotate_right(&data1,1);
.................... bit_clear(data1,7);
.................... *(((unsigned int8 *)(&res)+5)) = data1;
....................
.................... y = y/LN2 - (float48)n;
....................
.................... r = pe[0]*y + pe[1];
.................... r = r*y + pe[2];
.................... r = r*y + pe[3];
.................... r = r*y + pe[4];
.................... r = r*y + pe[5];
....................
.................... res = res*(1.0 + y*r);
....................
.................... if (s)
.................... res = 1.0/res;
.................... return(res);
.................... }
....................
.................... // Overloaded function exp() for data type - Float64
.................... float64 exp(float64 x)
.................... {
.................... float64 y, res, r;
.................... unsigned int16 data1, data2;
.................... unsigned int16 *p;
.................... signed int16 n;
.................... int1 s;
.................... #ifdef _ERRNO
.................... if(x > 709.7827128)
.................... {
.................... errno=ERANGE;
.................... return(0);
.................... }
.................... #endif
.................... n = (signed int16)(x/LN2);
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... n = -n;
.................... y = -y;
.................... }
....................
.................... res = 0.0;
....................
.................... #if !defined(__PCD__)
.................... *((unsigned int16 *)(&res)) = n + 0x7F;
.................... #endif
.................... p= (((unsigned int16 *)(&res))+3);
.................... data1 = *p;
.................... data2 = *p;
.................... data1 = n + 0x3FF;
.................... data1 = data1 <<4;
.................... if(bit_test(data2,15))
.................... bit_set(data1,15);
.................... data2 = data2 & 0x000F;
.................... data1 ^= data2;
....................
.................... *(((unsigned int16 *)(&res)+3)) = data1;
....................
....................
.................... y = y/LN2 - (float64)n;
....................
.................... r = pe[0]*y + pe[1];
.................... r = r*y + pe[2];
.................... r = r*y + pe[3];
.................... r = r*y + pe[4];
.................... r = r*y + pe[5];
....................
.................... res = res*(1.0 + y*r);
....................
.................... if (s)
.................... res = 1.0/res;
.................... return(res);
.................... }
....................
.................... #ENDIF
....................
....................
.................... /************************************************************/
....................
.................... float32 const pl[4] = {0.45145214, -9.0558803, 26.940971, -19.860189};
.................... float32 const ql[4] = {1.0000000, -8.1354259, 16.780517, -9.9300943};
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float log(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the the natural log of x
.................... // Date : N/A
.................... //
.................... float32 log(float32 x)
.................... {
.................... float32 y, res, r, y2;
.................... #if defined(__PCD__)
.................... unsigned int8 data1,data2;
.................... #endif
.................... signed int8 n;
.................... #ifdef _ERRNO
.................... if(x <0)
.................... {
.................... errno=EDOM;
.................... }
.................... if(x ==0)
.................... {
.................... errno=ERANGE;
.................... return(0);
.................... }
.................... #endif
.................... y = x;
....................
.................... if (y != 1.0)
.................... {
.................... #if !defined(__PCD__)
.................... *((unsigned int8 *)(&y)) = 0x7E;
.................... #endif
....................
.................... #if defined(__PCD__) // Takes care of IEEE format
.................... data2 = *(((unsigned int8 *)(&y))+3);
.................... *(((unsigned int8 *)(&y))+3) = 0x3F;
.................... data1 = *(((unsigned int8 *)(&y))+2);
.................... bit_clear(data1,7);
.................... *(((unsigned int8 *)(&y))+2) = data1;
.................... if(bit_test(data2,7))
.................... bit_set(*(((unsigned int8 *)(&y))+3),7);
.................... #endif
....................
.................... y = (y - 1.0)/(y + 1.0);
....................
.................... y2=y*y;
....................
.................... res = pl[0]*y2 + pl[1];
.................... res = res*y2 + pl[2];
.................... res = res*y2 + pl[3];
....................
.................... r = ql[0]*y2 + ql[1];
.................... r = r*y2 + ql[2];
.................... r = r*y2 + ql[3];
....................
.................... res = y*res/r;
.................... #if !defined(__PCD__)
.................... n = *((unsigned int8 *)(&x)) - 0x7E;
.................... #endif
.................... #if defined(__PCD__)
.................... data1 = *(((unsigned int8 *)(&x)+3));
.................... rotate_left(&data1,1);
.................... data2 = *(((unsigned int8 *)(&x)+2));
.................... if(bit_test (data2,7))
.................... bit_set(data1,0);
.................... n = data1 - 0x7E;
.................... #endif
....................
.................... if (n<0)
.................... r = -(float32)-n;
.................... else
.................... r = (float32)n;
....................
.................... res += r*LN2;
.................... }
....................
.................... else
.................... res = 0.0;
....................
.................... return(res);
.................... }
....................
.................... //Overloaded function for log() for PCD
.................... // Overloaded function log() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 log(float48 x)
.................... {
.................... float48 y, res, r, y2;
.................... unsigned int8 data1,data2;
.................... signed int8 n;
.................... #ifdef _ERRNO
.................... if(x <0)
.................... {
.................... errno=EDOM;
.................... }
.................... if(x ==0)
.................... {
.................... errno=ERANGE;
.................... return(0);
.................... }
.................... #endif
.................... y = x;
....................
.................... if (y != 1.0)
.................... {
....................
.................... #if !defined(__PCD__)
.................... *((unsigned int8 *)(&y)) = 0x7E;
.................... #endif
.................... data2 = *(((unsigned int8 *)(&y))+5);
.................... *(((unsigned int8 *)(&y))+5) = 0x3F;
.................... data1 = *(((unsigned int8 *)(&y))+4);
.................... bit_clear(data1,7);
.................... *(((unsigned int8 *)(&y))+4) = data1;
....................
.................... if(bit_test(data2,7))
.................... bit_set(*(((unsigned int8 *)(&y))+4),7);
.................... y = (y - 1.0)/(y + 1.0);
....................
.................... y2=y*y;
....................
.................... res = pl[0]*y2 + pl[1];
.................... res = res*y2 + pl[2];
.................... res = res*y2 + pl[3];
....................
.................... r = ql[0]*y2 + ql[1];
.................... r = r*y2 + ql[2];
.................... r = r*y2 + ql[3];
....................
.................... res = y*res/r;
....................
.................... data1 = *(((unsigned int8 *)(&x)+5));
.................... rotate_left(&data1,1);
.................... data2 = *(((unsigned int8 *)(&x)+4));
.................... if(bit_test (data2,7))
.................... bit_set(data1,0);
....................
.................... n = data1 - 0x7E;
....................
.................... if (n<0)
.................... r = -(float48)-n;
.................... else
.................... r = (float48)n;
....................
.................... res += r*LN2;
.................... }
....................
.................... else
.................... res = 0.0;
....................
.................... return(res);
.................... }
....................
.................... // Overloaded function log() for data type - Float48
.................... #if defined(__PCD__)
.................... float32 const pl_64[4] = {0.45145214, -9.0558803, 26.940971, -19.860189};
.................... float32 const ql_64[4] = {1.0000000, -8.1354259, 16.780517, -9.9300943};
.................... #endif
.................... float64 log(float64 x)
.................... {
.................... float64 y, res, r, y2;
.................... unsigned int16 data1,data2;
.................... unsigned int16 *p;
.................... signed int16 n;
.................... #ifdef _ERRNO
.................... if(x <0)
.................... {
.................... errno=EDOM;
.................... }
.................... if(x ==0)
.................... {
.................... errno=ERANGE;
.................... return(0);
.................... }
.................... #endif
.................... y = x;
....................
.................... if (y != 1.0)
.................... {
.................... #if !defined(__PCD__)
.................... *((unsigned int8 *)(&y)) = 0x7E;
.................... #endif
.................... p= (((unsigned int16 *)(&y))+3);
.................... data1 = *p;
.................... data2 = *p;
.................... data1 = 0x3FE;
.................... data1 = data1 <<4;
.................... if(bit_test (data2,15))
.................... bit_set(data1,15);
.................... data2 = data2 & 0x000F;
.................... data1 ^=data2;
....................
.................... *p = data1;
....................
.................... y = (y - 1.0)/(y + 1.0);
....................
.................... y2=y*y;
....................
.................... res = pl_64[0]*y2 + pl_64[1];
.................... res = res*y2 + pl_64[2];
.................... res = res*y2 + pl_64[3];
....................
.................... r = ql_64[0]*y2 + ql_64[1];
.................... r = r*y2 + ql_64[2];
.................... r = r*y2 + ql_64[3];
....................
.................... res = y*res/r;
....................
.................... p= (((unsigned int16 *)(&x))+3);
.................... data1 = *p;
.................... bit_clear(data1,15);
.................... data1 = data1 >>4;
.................... n = data1 - 0x3FE;
....................
....................
.................... if (n<0)
.................... r = -(float64)-n;
.................... else
.................... r = (float64)n;
....................
.................... res += r*LN2;
.................... }
....................
.................... else
.................... res = 0.0;
....................
.................... return(res);
.................... }
.................... #endif
....................
....................
.................... #define LN10 2.3025850929940456
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float log10(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the the log base 10 of x
.................... // Date : N/A
.................... //
.................... float32 log10(float32 x)
.................... {
.................... float32 r;
....................
.................... r = log(x);
.................... r = r/LN10;
.................... return(r);
.................... }
....................
.................... //Overloaded functions for log10() for PCD
.................... // Overloaded function log10() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 log10(float48 x)
.................... {
.................... float48 r;
....................
.................... r = log(x);
.................... r = r/LN10;
.................... return(r);
.................... }
....................
.................... // Overloaded function log10() for data type - Float64
.................... float64 log10(float64 x)
.................... {
.................... float64 r;
....................
.................... r = log(x);
.................... r = r/LN10;
.................... return(r);
.................... }
.................... #endif
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float modf(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description :breaks the argument value int integral and fractional parts,
.................... // ach of which have the same sign as the argument. It stores the integral part
.................... // as a float in the object pointed to by the iptr
.................... // Returns : returns the signed fractional part of value.
.................... // Date : N/A
.................... //
....................
.................... float32 modf(float32 value,float32 *iptr)
.................... {
.................... *iptr=(value < 0.0)? ceil(value): floor(value);
.................... return(value - *iptr);
.................... }
.................... //Overloaded functions for modf() for PCD
.................... // Overloaded function modf() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 modf(float48 value,float48 *iptr)
.................... {
.................... *iptr=(value < 0.0)? ceil(value): floor(value);
.................... return(value - *iptr);
.................... }
.................... // Overloaded function modf() for data type - Float64
.................... float64 modf(float64 value,float64 *iptr)
.................... {
.................... *iptr=(value < 0.0)? ceil(value): floor(value);
.................... return(value - *iptr);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float pwr(float x,float y)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the value (x^y)
.................... // Date : N/A
.................... //
.................... float32 pwr(float32 x,float32 y)
.................... {
.................... if(x>=0)
.................... return( exp(y*log(x)) );
.................... else
.................... return( -exp(y*log(-x)) );
.................... }
.................... //Overloaded functions for pwr() for PCD
.................... // Overloaded function pwr() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 pwr(float48 x,float48 y)
.................... {
.................... if(x>=0)
.................... return( exp(y*log(x)) );
.................... else
.................... return( -exp(y*log(-x)) );
.................... }
.................... // Overloaded function pwr() for data type - Float64
.................... float64 pwr(float64 x,float64 y)
.................... {
.................... if(x>=0)
.................... return( exp(y*log(x)) );
.................... else
.................... return( -exp(y*log(-x)) );
.................... }
.................... #endif
....................
.................... //////////////////// Power functions ////////////////////
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float pow(float x,float y)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the value (x^y)
.................... // Date : N/A
.................... //
.................... float32 pow(float32 x,float32 y)
.................... {
.................... if(x>=0)
.................... return( exp(y*log(x)) );
.................... else
.................... return( -exp(y*log(-x)) );
.................... }
.................... //Overloaded functions for pow() for PCD
.................... // Overloaded function for pow() data type - Float48
.................... #if defined(__PCD__)
.................... float48 pow(float48 x,float48 y)
.................... {
.................... if(x>=0)
.................... return( exp(y*log(x)) );
.................... else
.................... return( -exp(y*log(-x)) );
.................... }
....................
.................... // Overloaded function pow() for data type - Float64
.................... float64 pow(float64 x,float64 y)
.................... {
.................... if(x>=0)
.................... return( exp(y*log(x)) );
.................... else
.................... return( -exp(y*log(-x)) );
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float sqrt(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the square root of x
.................... // Date : N/A
.................... //
.................... float32 sqrt(float32 x)
.................... {
.................... float32 y, res;
.................... #if defined(__PCD__)
.................... unsigned int16 data1,data2;
.................... #endif
.................... BYTE *p;
....................
.................... #ifdef _ERRNO
.................... if(x < 0)
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
....................
.................... if( x<=0.0)
*
19C2: MOVFF 6DF,6ED
19C6: MOVFF 6DE,6EC
19CA: MOVFF 6DD,6EB
19CE: MOVFF 6DC,6EA
19D2: MOVLB 6
19D4: CLRF xF1
19D6: CLRF xF0
19D8: CLRF xEF
19DA: CLRF xEE
19DC: MOVLB 0
19DE: RCALL 1948
19E0: BC 19E4
19E2: BNZ 19EE
.................... return(0.0);
19E4: CLRF 00
19E6: CLRF 01
19E8: CLRF 02
19EA: CLRF 03
19EC: BRA 1ADE
....................
.................... y=x;
19EE: MOVFF 6DF,6E3
19F2: MOVFF 6DE,6E2
19F6: MOVFF 6DD,6E1
19FA: MOVFF 6DC,6E0
....................
.................... #if !defined(__PCD__)
.................... p=&y;
19FE: MOVLW 06
1A00: MOVLB 6
1A02: MOVWF xE9
1A04: MOVLW E0
1A06: MOVWF xE8
.................... (*p)=(BYTE)((((unsigned int16)(*p)) + 127) >> 1);
1A08: MOVFF 6E8,FE9
1A0C: MOVFF 6E9,FEA
1A10: MOVF FEF,W
1A12: CLRF xED
1A14: MOVWF xEC
1A16: MOVLW 7F
1A18: ADDWF xEC,F
1A1A: MOVLW 00
1A1C: ADDWFC xED,F
1A1E: BCF FD8.0
1A20: RRCF xED,W
1A22: RRCF xEC,W
1A24: MOVFF 6E9,FEA
1A28: MOVFF 6E8,FE9
1A2C: MOVWF FEF
.................... #endif
....................
.................... #if defined(__PCD__)
.................... p = (((unsigned int8 *)(&y))+3);
.................... data1 = *(((unsigned int8 *)(&y))+3);
.................... data2 = *(((unsigned int8 *)(&y))+2);
.................... rotate_left(&data1,1);
.................... if(bit_test(data2,7))
.................... bit_set(data1,0);
.................... data1 = ((data1+127) >>1);
.................... bit_clear(data2,7);
.................... if(bit_test(data1,0))
.................... bit_set(data2,7);
.................... data1 = data1 >>1;
.................... *(((unsigned int8 *)(&y))+3) = data1;
.................... *(((unsigned int8 *)(&y))+2) = data2;
....................
.................... #endif
....................
.................... do {
.................... res=y;
1A2E: MOVFF 6E3,6E7
1A32: MOVFF 6E2,6E6
1A36: MOVFF 6E1,6E5
1A3A: MOVFF 6E0,6E4
.................... y+=(x/y);
1A3E: MOVFF 6DF,6ED
1A42: MOVFF 6DE,6EC
1A46: MOVFF 6DD,6EB
1A4A: MOVFF 6DC,6EA
1A4E: MOVFF 6E3,6F1
1A52: MOVFF 6E2,6F0
1A56: MOVFF 6E1,6EF
1A5A: MOVFF 6E0,6EE
1A5E: MOVLB 0
1A60: RCALL 16BA
1A62: BCF FD8.1
1A64: MOVFF 6E3,6ED
1A68: MOVFF 6E2,6EC
1A6C: MOVFF 6E1,6EB
1A70: MOVFF 6E0,6EA
1A74: MOVFF 03,6F1
1A78: MOVFF 02,6F0
1A7C: MOVFF 01,6EF
1A80: MOVFF 00,6EE
1A84: RCALL 1442
1A86: MOVFF 03,6E3
1A8A: MOVFF 02,6E2
1A8E: MOVFF 01,6E1
1A92: MOVFF 00,6E0
....................
.................... #if !defined(__PCD__)
.................... (*p)--;
1A96: MOVLB 6
1A98: MOVFF 6E8,FE9
1A9C: MOVFF 6E9,FEA
1AA0: DECF FEF,F
.................... #endif
....................
.................... #if defined(__PCD__)
.................... data1 = *(((unsigned int8 *)(&y))+3);
.................... data2 = *(((unsigned int8 *)(&y))+2);
.................... rotate_left(&data1,1);
.................... if(bit_test(data2,7))
.................... bit_set(data1,0);
.................... data1--;
.................... bit_clear(data2,7);
.................... if(bit_test(data1,0))
.................... bit_set(data2,7);
.................... data1 = data1 >>1;
.................... *(((unsigned int8 *)(&y))+3) = data1;
.................... *(((unsigned int8 *)(&y))+2) = data2;
....................
.................... #endif
.................... } while(res != y);
1AA2: MOVFF 6E7,6ED
1AA6: MOVFF 6E6,6EC
1AAA: MOVFF 6E5,6EB
1AAE: MOVFF 6E4,6EA
1AB2: MOVFF 6E3,6F1
1AB6: MOVFF 6E2,6F0
1ABA: MOVFF 6E1,6EF
1ABE: MOVFF 6E0,6EE
1AC2: MOVLB 0
1AC4: RCALL 1948
1AC6: BTFSC FD8.2
1AC8: BRA 1ACE
1ACA: MOVLB 6
1ACC: BRA 1A2E
....................
.................... return(res);
1ACE: MOVFF 6E4,00
1AD2: MOVFF 6E5,01
1AD6: MOVFF 6E6,02
1ADA: MOVFF 6E7,03
.................... }
1ADE: GOTO 1CCA (RETURN)
.................... //Overloaded functions for sqrt() for PCD
.................... // Overloaded function sqrt() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 sqrt(float48 x)
.................... {
.................... float48 y, res;
.................... unsigned int16 data1,data2;
.................... BYTE *p;
....................
.................... #ifdef _ERRNO
.................... if(x < 0)
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
....................
.................... if( x<=0.0)
.................... return(0.0);
....................
.................... y=x;
....................
.................... #if !defined(__PCD__)
.................... p=&y;
.................... (*p)=(BYTE)((((unsigned int16)(*p)) + 127) >> 1);
.................... #endif
....................
.................... #if defined(__PCD__)
.................... p = (((unsigned int8 *)(&y))+5);
.................... data1 = *(((unsigned int8 *)(&y))+5);
.................... data2 = *(((unsigned int8 *)(&y))+4);
.................... rotate_left(&data1,1);
.................... if(bit_test(data2,7))
.................... bit_set(data1,0);
.................... data1 = ((data1+127) >>1);
.................... bit_clear(data2,7);
.................... if(bit_test(data1,0))
.................... bit_set(data2,7);
.................... data1 = data1 >>1;
.................... *(((unsigned int8 *)(&y))+5) = data1;
.................... *(((unsigned int8 *)(&y))+4) = data2;
....................
.................... #endif
....................
.................... do {
.................... res=y;
.................... y+=(x/y);
....................
.................... #if !defined(__PCD__)
.................... (*p)--;
.................... #endif
....................
.................... data1 = *(((unsigned int8 *)(&y))+5);
.................... data2 = *(((unsigned int8 *)(&y))+4);
.................... rotate_left(&data1,1);
.................... if(bit_test(data2,7))
.................... bit_set(data1,0);
.................... data1--;
.................... bit_clear(data2,7);
.................... if(bit_test(data1,0))
.................... bit_set(data2,7);
.................... data1 = data1 >>1;
.................... *(((unsigned int8 *)(&y))+5) = data1;
.................... *(((unsigned int8 *)(&y))+4) = data2;
....................
.................... } while(res != y);
....................
.................... return(res);
.................... }
....................
.................... // Overloaded function sqrt() for data type - Float64
.................... float64 sqrt(float64 x)
.................... {
.................... float64 y, res;
.................... unsigned int16 *p;
.................... unsigned int16 temp1,temp2;
....................
.................... #ifdef _ERRNO
.................... if(x < 0)
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
....................
.................... if( x<=0.0)
.................... return(0.0);
....................
.................... y=x;
.................... p= (((unsigned int16 *)(&y))+3);
.................... temp1 = *p;
.................... temp2 = *p;
.................... bit_clear(temp1,15);
.................... temp1 = (temp1>>4)+1023;
.................... temp1 = temp1 >> 1;
.................... temp1 = (temp1<<4) & 0xFFF0;
.................... if(bit_test(temp2,15))
.................... bit_set(temp1,15);
.................... temp2 = temp2 & 0x000F;
.................... temp1 ^= temp2;
....................
.................... (*p) = temp1;
....................
.................... do {
.................... res=y;
.................... y+=(x/y);
.................... temp1 = *p;
.................... temp2 = *p;
.................... bit_clear(temp1,15);
.................... temp1 = (temp1>>4);
.................... temp1--;
.................... temp1 = (temp1<<4) & 0xFFF0;
.................... if(bit_test(temp2,15))
.................... bit_set(temp1,15);
.................... temp2 = temp2 & 0x000F;
.................... temp1 ^= temp2;
.................... (*p) = temp1;
....................
.................... } while(res != y);
....................
.................... return(res);
.................... }
.................... #endif
....................
.................... ////////////////////////////// Trig Functions //////////////////////////////
.................... #ifdef PI_DIV_BY_TWO
.................... #undef PI_DIV_BY_TWO
.................... #endif
.................... #define PI_DIV_BY_TWO 1.5707963267948966
.................... #ifdef TWOBYPI
.................... #undef TWOBYPI
.................... #define TWOBYPI 0.6366197723675813
.................... #endif
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float cos(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the cosine value of the angle x, which is in radian
.................... // Date : 9/20/2001
.................... //
.................... float32 cos(float32 x)
.................... {
.................... float32 y, t, t2 = 1.0;
.................... unsigned int8 quad, i;
.................... float32 frac;
.................... float32 p[4] = {
.................... -0.499999993585,
.................... 0.041666636258,
.................... -0.0013888361399,
.................... 0.00002476016134
.................... };
....................
.................... if (x < 0) x = -x; // absolute value of input
....................
.................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant
.................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input
.................... quad = quad % 4; // quadrant (0 to 3)
....................
.................... if (quad == 0 || quad == 2)
.................... t = frac * PI_DIV_BY_TWO;
.................... else if (quad == 1)
.................... t = (1-frac) * PI_DIV_BY_TWO;
.................... else // should be 3
.................... t = (frac-1) * PI_DIV_BY_TWO;
....................
.................... y = 0.999999999781;
.................... t = t * t;
.................... for (i = 0; i <= 3; i++)
.................... {
.................... t2 = t2 * t;
.................... y = y + p[i] * t2;
.................... }
....................
.................... if (quad == 2 || quad == 1)
.................... y = -y; // correct sign
....................
.................... return (y);
.................... }
....................
....................
.................... //Overloaded functions for cos() for PCD
.................... // Overloaded function cos() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 cos(float48 x)
.................... {
.................... float48 y, t, t2 = 1.0;
.................... unsigned int8 quad, i;
.................... float48 frac;
.................... float48 p[4] = {
.................... -0.499999993585,
.................... 0.041666636258,
.................... -0.0013888361399,
.................... 0.00002476016134
.................... };
....................
.................... if (x < 0) x = -x; // absolute value of input
....................
.................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant
.................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input
.................... quad = quad % 4; // quadrant (0 to 3)
....................
.................... if (quad == 0 || quad == 2)
.................... t = frac * PI_DIV_BY_TWO;
.................... else if (quad == 1)
.................... t = (1-frac) * PI_DIV_BY_TWO;
.................... else // should be 3
.................... t = (frac-1) * PI_DIV_BY_TWO;
....................
.................... y = 0.999999999781;
.................... t = t * t;
.................... for (i = 0; i <= 3; i++)
.................... {
.................... t2 = t2 * t;
.................... y = y + p[i] * t2;
.................... }
....................
.................... if (quad == 2 || quad == 1)
.................... y = -y; // correct sign
....................
.................... return (y);
.................... }
....................
.................... // Overloaded function cos() for data type - Float48
.................... float64 cos(float64 x)
.................... {
.................... float64 y, t, t2 = 1.0;
.................... unsigned int8 quad, i;
.................... float64 frac;
.................... float64 p[4] = {
.................... -0.499999993585,
.................... 0.041666636258,
.................... -0.0013888361399,
.................... 0.00002476016134
.................... };
....................
.................... if (x < 0) x = -x; // absolute value of input
....................
.................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant
.................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input
.................... quad = quad % 4; // quadrant (0 to 3)
....................
.................... if (quad == 0 || quad == 2)
.................... t = frac * PI_DIV_BY_TWO;
.................... else if (quad == 1)
.................... t = (1-frac) * PI_DIV_BY_TWO;
.................... else // should be 3
.................... t = (frac-1) * PI_DIV_BY_TWO;
....................
.................... y = 0.999999999781;
.................... t = t * t;
.................... for (i = 0; i <= 3; i++)
.................... {
.................... t2 = t2 * t;
.................... y = y + p[i] * t2;
.................... }
....................
.................... if (quad == 2 || quad == 1)
.................... y = -y; // correct sign
....................
.................... return (y);
.................... }
....................
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float sin(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the sine value of the angle x, which is in radian
.................... // Date : 9/20/2001
.................... //
.................... float32 sin(float32 x)
.................... {
.................... return cos(x - PI_DIV_BY_TWO);
.................... }
....................
.................... //Overloaded functions for sin() for PCD
.................... // Overloaded function sin() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 sin(float48 x)
.................... {
.................... return cos(x - PI_DIV_BY_TWO);
.................... }
....................
.................... // Overloaded function sin() for data type - Float48
.................... float64 sin(float64 x)
.................... {
.................... return cos(x - PI_DIV_BY_TWO);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float tan(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the tangent value of the angle x, which is in radian
.................... // Date : 9/20/2001
.................... //
.................... float32 tan(float32 x)
.................... {
.................... float32 c, s;
....................
.................... c = cos(x);
.................... if (c == 0.0)
.................... return (1.0e+36);
....................
.................... s = sin(x);
.................... return(s/c);
.................... }
.................... //Overloaded functions for tan() for PCD
.................... // Overloaded function tan() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 tan(float48 x)
.................... {
.................... float48 c, s;
....................
.................... c = cos(x);
.................... if (c == 0.0)
.................... return (1.0e+36);
....................
.................... s = sin(x);
.................... return(s/c);
.................... }
....................
.................... // Overloaded function tan() for data type - Float48
.................... float64 tan(float64 x)
.................... {
.................... float64 c, s;
....................
.................... c = cos(x);
.................... if (c == 0.0)
.................... return (1.0e+36);
....................
.................... s = sin(x);
.................... return(s/c);
.................... }
.................... #endif
....................
.................... float32 const pas[3] = {0.49559947, -4.6145309, 5.6036290};
.................... float32 const qas[3] = {1.0000000, -5.5484666, 5.6036290};
....................
.................... float32 ASIN_COS(float32 x, unsigned int8 n)
.................... {
.................... float32 y, res, r, y2;
.................... int1 s;
.................... #ifdef _ERRNO
.................... if(x <-1 || x > 1)
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y > 0.5)
.................... {
.................... y = sqrt((1.0 - y)/2.0);
.................... n += 2;
.................... }
....................
.................... y2=y*y;
....................
.................... res = pas[0]*y2 + pas[1];
.................... res = res*y2 + pas[2];
....................
.................... r = qas[0]*y2 + qas[1];
.................... r = r*y2 + qas[2];
....................
.................... res = y*res/r;
....................
.................... if (n & 2) // |x| > 0.5
.................... res = PI_DIV_BY_TWO - 2.0*res;
.................... if (s)
.................... res = -res;
.................... if (n & 1) // take arccos
.................... res = PI_DIV_BY_TWO - res;
....................
.................... return(res);
.................... }
....................
.................... //Overloaded functions for ASIN_COS() for PCD
.................... // Overloaded function ASIN_COS() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 ASIN_COS(float48 x, unsigned int8 n)
.................... {
.................... float48 y, res, r, y2;
.................... int1 s;
.................... #ifdef _ERRNO
.................... if(x <-1 || x > 1)
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y > 0.5)
.................... {
.................... y = sqrt((1.0 - y)/2.0);
.................... n += 2;
.................... }
....................
.................... y2=y*y;
....................
.................... res = pas[0]*y2 + pas[1];
.................... res = res*y2 + pas[2];
....................
.................... r = qas[0]*y2 + qas[1];
.................... r = r*y2 + qas[2];
....................
.................... res = y*res/r;
....................
.................... if (n & 2) // |x| > 0.5
.................... res = PI_DIV_BY_TWO - 2.0*res;
.................... if (s)
.................... res = -res;
.................... if (n & 1) // take arccos
.................... res = PI_DIV_BY_TWO - res;
....................
.................... return(res);
.................... }
....................
.................... // Overloaded function ASIN_COS() for data type - Float64
.................... float64 ASIN_COS(float64 x, unsigned int8 n)
.................... {
.................... float64 y, res, r, y2;
.................... int1 s;
.................... #ifdef _ERRNO
.................... if(x <-1 || x > 1)
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y > 0.5)
.................... {
.................... y = sqrt((1.0 - y)/2.0);
.................... n += 2;
.................... }
....................
.................... y2=y*y;
....................
.................... res = pas[0]*y2 + pas[1];
.................... res = res*y2 + pas[2];
....................
.................... r = qas[0]*y2 + qas[1];
.................... r = r*y2 + qas[2];
....................
.................... res = y*res/r;
....................
.................... if (n & 2) // |x| > 0.5
.................... res = PI_DIV_BY_TWO - 2.0*res;
.................... if (s)
.................... res = -res;
.................... if (n & 1) // take arccos
.................... res = PI_DIV_BY_TWO - res;
....................
.................... return(res);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float asin(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the arcsine value of the value x.
.................... // Date : N/A
.................... //
.................... float32 asin(float32 x)
.................... {
.................... float32 r;
....................
.................... r = ASIN_COS(x, 0);
.................... return(r);
.................... }
.................... //Overloaded functions for asin() for PCD
.................... // Overloaded function asin() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 asin(float48 x)
.................... {
.................... float48 r;
....................
.................... r = ASIN_COS(x, 0);
.................... return(r);
.................... }
....................
.................... // Overloaded function asin() for data type - Float64
.................... float64 asin(float64 x)
.................... {
.................... float64 r;
....................
.................... r = ASIN_COS(x, 0);
.................... return(r);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float acos(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the arccosine value of the value x.
.................... // Date : N/A
.................... //
.................... float32 acos(float32 x)
.................... {
.................... float32 r;
....................
.................... r = ASIN_COS(x, 1);
.................... return(r);
.................... }
.................... //Overloaded functions for acos() for PCD
.................... // Overloaded function acos() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 acos(float48 x)
.................... {
.................... float48 r;
....................
.................... r = ASIN_COS(x, 1);
.................... return(r);
.................... }
....................
.................... // Overloaded function acos() for data type - Float64
.................... float64 acos(float64 x)
.................... {
.................... float64 r;
....................
.................... r = ASIN_COS(x, 1);
.................... return(r);
.................... }
.................... #endif
....................
.................... float32 const pat[4] = {0.17630401, 5.6710795, 22.376096, 19.818457};
.................... float32 const qat[4] = {1.0000000, 11.368190, 28.982246, 19.818457};
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float atan(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the arctangent value of the value x.
.................... // Date : N/A
.................... //
.................... float32 atan(float32 x)
.................... {
.................... float32 y, res, r;
.................... int1 s, flag;
....................
.................... s = 0;
.................... flag = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y > 1.0)
.................... {
.................... y = 1.0/y;
.................... flag = 1;
.................... }
....................
.................... res = pat[0]*y*y + pat[1];
.................... res = res*y*y + pat[2];
.................... res = res*y*y + pat[3];
....................
.................... r = qat[0]*y*y + qat[1];
.................... r = r*y*y + qat[2];
.................... r = r*y*y + qat[3];
....................
.................... res = y*res/r;
....................
....................
.................... if (flag) // for |x| > 1
.................... res = PI_DIV_BY_TWO - res;
.................... if (s)
.................... res = -res;
....................
.................... return(res);
.................... }
.................... //Overloaded functions for atan() for PCD
.................... // Overloaded function atan() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 atan(float48 x)
.................... {
.................... float48 y, res, r;
.................... int1 s, flag;
....................
.................... s = 0;
.................... flag = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y > 1.0)
.................... {
.................... y = 1.0/y;
.................... flag = 1;
.................... }
....................
.................... res = pat[0]*y*y + pat[1];
.................... res = res*y*y + pat[2];
.................... res = res*y*y + pat[3];
....................
.................... r = qat[0]*y*y + qat[1];
.................... r = r*y*y + qat[2];
.................... r = r*y*y + qat[3];
....................
.................... res = y*res/r;
....................
....................
.................... if (flag) // for |x| > 1
.................... res = PI_DIV_BY_TWO - res;
.................... if (s)
.................... res = -res;
....................
.................... return(res);
.................... }
....................
.................... // Overloaded function atan() for data type - Float64
.................... float64 atan(float64 x)
.................... {
.................... float64 y, res, r;
.................... int1 s, flag;
....................
.................... s = 0;
.................... flag = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y > 1.0)
.................... {
.................... y = 1.0/y;
.................... flag = 1;
.................... }
....................
.................... res = pat[0]*y*y + pat[1];
.................... res = res*y*y + pat[2];
.................... res = res*y*y + pat[3];
....................
.................... r = qat[0]*y*y + qat[1];
.................... r = r*y*y + qat[2];
.................... r = r*y*y + qat[3];
....................
.................... res = y*res/r;
....................
....................
.................... if (flag) // for |x| > 1
.................... res = PI_DIV_BY_TWO - res;
.................... if (s)
.................... res = -res;
....................
.................... return(res);
.................... }
.................... #endif
....................
.................... /////////////////////////////////////////////////////////////////////////////
.................... // float atan2(float y, float x)
.................... /////////////////////////////////////////////////////////////////////////////
.................... // Description :computes the principal value of arc tangent of y/x, using the
.................... // signs of both the arguments to determine the quadrant of the return value
.................... // Returns : returns the arc tangent of y/x.
.................... // Date : N/A
.................... //
....................
.................... float32 atan2(float32 y,float32 x)
.................... {
.................... float32 z;
.................... int1 sign;
.................... unsigned int8 quad;
.................... sign=0;
.................... quad=0; //quadrant
.................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1));
.................... if(y<0.0)
.................... {
.................... sign=1;
.................... y=-y;
.................... }
.................... if(x<0.0)
.................... {
.................... x=-x;
.................... }
.................... if (x==0.0)
.................... {
.................... if(y==0.0)
.................... {
.................... #ifdef _ERRNO
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... }
.................... else
.................... {
.................... if(sign)
.................... {
.................... return (-(PI_DIV_BY_TWO));
.................... }
.................... else
.................... {
.................... return (PI_DIV_BY_TWO);
.................... }
.................... }
.................... }
.................... else
.................... {
.................... z=y/x;
.................... switch(quad)
.................... {
.................... case 1:
.................... {
.................... return atan(z);
.................... break;
.................... }
.................... case 2:
.................... {
.................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122
.................... return (PI-atan(z));
.................... break;
.................... }
.................... case 3:
.................... {
.................... return (atan(z)-PI);
.................... break;
.................... }
.................... case 4:
.................... {
.................... return (-atan(z));
.................... break;
.................... }
.................... }
.................... }
.................... }
....................
.................... //Overloaded functions for atan2() for PCD
.................... // Overloaded function atan2() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 atan2(float48 y,float48 x)
.................... {
.................... float48 z;
.................... int1 sign;
.................... unsigned int8 quad;
.................... sign=0;
.................... quad=0; //quadrant
.................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1));
.................... if(y<0.0)
.................... {
.................... sign=1;
.................... y=-y;
.................... }
.................... if(x<0.0)
.................... {
.................... x=-x;
.................... }
.................... if (x==0.0)
.................... {
.................... if(y==0.0)
.................... {
.................... #ifdef _ERRNO
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... }
.................... else
.................... {
.................... if(sign)
.................... {
.................... return (-(PI_DIV_BY_TWO));
.................... }
.................... else
.................... {
.................... return (PI_DIV_BY_TWO);
.................... }
.................... }
.................... }
.................... else
.................... {
.................... z=y/x;
.................... switch(quad)
.................... {
.................... case 1:
.................... {
.................... return atan(z);
.................... break;
.................... }
.................... case 2:
.................... {
.................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122
.................... return (PI-atan(z));
.................... break;
.................... }
.................... case 3:
.................... {
.................... return (atan(z)-PI);
.................... break;
.................... }
.................... case 4:
.................... {
.................... return (-atan(z));
.................... break;
.................... }
.................... }
.................... }
.................... }
....................
.................... // Overloaded function atan2() for data type - Float64
.................... float64 atan2(float64 y,float64 x)
.................... {
.................... float64 z;
.................... int1 sign;
.................... unsigned int8 quad;
.................... sign=0;
.................... quad=0; //quadrant
.................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1));
.................... if(y<0.0)
.................... {
.................... sign=1;
.................... y=-y;
.................... }
.................... if(x<0.0)
.................... {
.................... x=-x;
.................... }
.................... if (x==0.0)
.................... {
.................... if(y==0.0)
.................... {
.................... #ifdef _ERRNO
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... }
.................... else
.................... {
.................... if(sign)
.................... {
.................... return (-(PI_DIV_BY_TWO));
.................... }
.................... else
.................... {
.................... return (PI_DIV_BY_TWO);
.................... }
.................... }
.................... }
.................... else
.................... {
.................... z=y/x;
.................... switch(quad)
.................... {
.................... case 1:
.................... {
.................... return atan(z);
.................... break;
.................... }
.................... case 2:
.................... {
.................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122
.................... return (PI-atan(z));
.................... break;
.................... }
.................... case 3:
.................... {
.................... return (atan(z)-PI);
.................... break;
.................... }
.................... case 4:
.................... {
.................... return (-atan(z));
.................... break;
.................... }
.................... }
.................... }
.................... }
.................... #endif
....................
.................... //////////////////// Hyperbolic functions ////////////////////
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float cosh(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : Computes the hyperbolic cosine value of x
.................... // Returns : returns the hyperbolic cosine value of x
.................... // Date : N/A
.................... //
....................
.................... float32 cosh(float32 x)
.................... {
.................... return ((exp(x)+exp(-x))/2);
.................... }
.................... //Overloaded functions for cosh() for PCD
.................... // Overloaded function cosh() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 cosh(float48 x)
.................... {
.................... return ((exp(x)+exp(-x))/2);
.................... }
....................
.................... // Overloaded function cosh() for data type - Float64
.................... float64 cosh(float64 x)
.................... {
.................... return ((exp(x)+exp(-x))/2);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float sinh(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : Computes the hyperbolic sine value of x
.................... // Returns : returns the hyperbolic sine value of x
.................... // Date : N/A
.................... //
....................
.................... float32 sinh(float32 x)
.................... {
....................
.................... return ((exp(x) - exp(-x))/2);
.................... }
.................... //Overloaded functions for sinh() for PCD
.................... // Overloaded function sinh() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 sinh(float48 x)
.................... {
....................
.................... return ((exp(x) - exp(-x))/2);
.................... }
....................
.................... // Overloaded function sinh() for data type - Float48
.................... float64 sinh(float64 x)
.................... {
....................
.................... return ((exp(x) - exp(-x))/2);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float tanh(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : Computes the hyperbolic tangent value of x
.................... // Returns : returns the hyperbolic tangent value of x
.................... // Date : N/A
.................... //
....................
.................... float32 tanh(float32 x)
.................... {
.................... return(sinh(x)/cosh(x));
.................... }
.................... //Overloaded functions for tanh() for PCD
.................... // Overloaded function tanh() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 tanh(float48 x)
.................... {
.................... return(sinh(x)/cosh(x));
.................... }
....................
.................... // Overloaded function tanh() for data type - Float64
.................... float64 tanh(float64 x)
.................... {
.................... return(sinh(x)/cosh(x));
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float frexp(float x, signed int *exp)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : breaks a floating point number into a normalized fraction and an integral
.................... // power of 2. It stores the integer in the signed int object pointed to by exp.
.................... // Returns : returns the value x, such that x is a double with magnitude in the interval
.................... // [1/2,1) or zero, and value equals x times 2 raised to the power *exp.If value is zero,
.................... // both parts of the result are zero.
.................... // Date : N/A
.................... //
....................
.................... #define LOG2 .30102999566398119521
.................... float32 frexp(float32 x, signed int8 *exp)
.................... {
.................... float32 res;
.................... int1 sign = 0;
.................... if(x == 0.0)
.................... {
.................... *exp=0;
.................... return (0.0);
.................... }
.................... if(x < 0.0)
.................... {
.................... x=-x;
.................... sign=1;
.................... }
.................... if (x > 1.0)
.................... {
.................... *exp=(ceil(log10(x)/LOG2));
.................... res=x/(pow(2, *exp));
.................... if (res == 1)
.................... {
.................... *exp=*exp+1;
.................... res=.5;
.................... }
.................... }
.................... else
.................... {
.................... if(x < 0.5)
.................... {
.................... *exp=-1;
.................... res=x*2;
.................... }
.................... else
.................... {
.................... *exp=0;
.................... res=x;
.................... }
.................... }
.................... if(sign)
.................... {
.................... res=-res;
.................... }
.................... return res;
.................... }
....................
.................... //Overloaded functions for frexp() for PCD
.................... // Overloaded function frexp() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 frexp(float48 x, signed int8 *exp)
.................... {
.................... float48 res;
.................... int1 sign = 0;
.................... if(x == 0.0)
.................... {
.................... *exp=0;
.................... return (0.0);
.................... }
.................... if(x < 0.0)
.................... {
.................... x=-x;
.................... sign=1;
.................... }
.................... if (x > 1.0)
.................... {
.................... *exp=(ceil(log10(x)/LOG2));
.................... res=x/(pow(2, *exp));
.................... if (res == 1)
.................... {
.................... *exp=*exp+1;
.................... res=.5;
.................... }
.................... }
.................... else
.................... {
.................... if(x < 0.5)
.................... {
.................... *exp=-1;
.................... res=x*2;
.................... }
.................... else
.................... {
.................... *exp=0;
.................... res=x;
.................... }
.................... }
.................... if(sign)
.................... {
.................... res=-res;
.................... }
.................... return res;
.................... }
....................
.................... // Overloaded function frexp() for data type - Float64
.................... float64 frexp(float64 x, signed int8 *exp)
.................... {
.................... float64 res;
.................... int1 sign = 0;
.................... if(x == 0.0)
.................... {
.................... *exp=0;
.................... return (0.0);
.................... }
.................... if(x < 0.0)
.................... {
.................... x=-x;
.................... sign=1;
.................... }
.................... if (x > 1.0)
.................... {
.................... *exp=(ceil(log10(x)/LOG2));
.................... res=x/(pow(2, *exp));
.................... if (res == 1)
.................... {
.................... *exp=*exp+1;
.................... res=.5;
.................... }
.................... }
.................... else
.................... {
.................... if(x < 0.5)
.................... {
.................... *exp=-1;
.................... res=x*2;
.................... }
.................... else
.................... {
.................... *exp=0;
.................... res=x;
.................... }
.................... }
.................... if(sign)
.................... {
.................... res=-res;
.................... }
.................... return res;
.................... }
.................... #endif
....................
.................... //////////////////////////////////////////////////////////////////////////////
.................... // float ldexp(float x, signed int *exp)
.................... //////////////////////////////////////////////////////////////////////////////
.................... // Description : multiplies a floating point number by an integral power of 2.
.................... // Returns : returns the value of x times 2 raised to the power exp.
.................... // Date : N/A
.................... //
....................
.................... float32 ldexp(float32 value, signed int8 exp)
.................... {
.................... return (value * pow(2,exp));
.................... }
.................... //Overloaded functions for ldexp() for PCD
.................... // Overloaded function ldexp() for data type - Float48
....................
.................... #if defined(__PCD__)
.................... float48 ldexp(float48 value, signed int8 exp)
.................... {
.................... return (value * pow(2,exp));
.................... }
.................... // Overloaded function ldexp() for data type - Float64
.................... float64 ldexp(float64 value, signed int8 exp)
.................... {
.................... return (value * pow(2,exp));
.................... }
.................... #endif
....................
.................... #endif
....................
....................
.................... float quadraticerror(float average, float buf[], int16 size) // compute average quadratic error
.................... {
.................... int16 i;
.................... float err=0;
1AE2: MOVLB 6
1AE4: CLRF xD4
1AE6: CLRF xD5
1AE8: CLRF xD6
1AEA: CLRF xD7
....................
.................... for(i=0; i<size; i++) err += (buf[i]-average)*(buf[i]-average); // sum quadratic errors
1AEC: CLRF xD3
1AEE: CLRF xD2
1AF0: MOVF xD3,W
1AF2: SUBWF xD1,W
1AF4: BTFSS FD8.0
1AF6: BRA 1C48
1AF8: BNZ 1B02
1AFA: MOVF xD0,W
1AFC: SUBWF xD2,W
1AFE: BTFSC FD8.0
1B00: BRA 1C48
1B02: RLCF xD2,W
1B04: MOVWF 02
1B06: RLCF xD3,W
1B08: MOVWF 03
1B0A: RLCF 02,F
1B0C: RLCF 03,F
1B0E: MOVLW FC
1B10: ANDWF 02,F
1B12: MOVF 02,W
1B14: ADDWF xCE,W
1B16: MOVWF FE9
1B18: MOVF xCF,W
1B1A: ADDWFC 03,W
1B1C: MOVWF FEA
1B1E: MOVFF FEF,6D8
1B22: MOVFF FEC,6D9
1B26: MOVFF FEC,6DA
1B2A: MOVFF FEC,6DB
1B2E: MOVFF FEA,6DD
1B32: MOVFF FE9,6DC
1B36: BSF FD8.1
1B38: MOVFF 6DB,6ED
1B3C: MOVFF 6DA,6EC
1B40: MOVFF 6D9,6EB
1B44: MOVFF 6D8,6EA
1B48: MOVFF 6CD,6F1
1B4C: MOVFF 6CC,6F0
1B50: MOVFF 6CB,6EF
1B54: MOVFF 6CA,6EE
1B58: MOVLB 0
1B5A: RCALL 1442
1B5C: MOVFF 6DD,FEA
1B60: MOVFF 6DC,FE9
1B64: MOVFF 00,6D8
1B68: MOVFF 01,6D9
1B6C: MOVFF 02,6DA
1B70: MOVFF 03,6DB
1B74: MOVLB 6
1B76: RLCF xD2,W
1B78: MOVWF 02
1B7A: RLCF xD3,W
1B7C: MOVWF 03
1B7E: RLCF 02,F
1B80: RLCF 03,F
1B82: MOVLW FC
1B84: ANDWF 02,F
1B86: MOVF 02,W
1B88: ADDWF xCE,W
1B8A: MOVWF FE9
1B8C: MOVF xCF,W
1B8E: ADDWFC 03,W
1B90: MOVWF FEA
1B92: MOVFF FEF,6DE
1B96: MOVFF FEC,6DF
1B9A: MOVFF FEC,6E0
1B9E: MOVFF FEC,6E1
1BA2: MOVFF FEA,6E3
1BA6: MOVFF FE9,6E2
1BAA: BSF FD8.1
1BAC: MOVFF 6E1,6ED
1BB0: MOVFF 6E0,6EC
1BB4: MOVFF 6DF,6EB
1BB8: MOVFF 6DE,6EA
1BBC: MOVFF 6CD,6F1
1BC0: MOVFF 6CC,6F0
1BC4: MOVFF 6CB,6EF
1BC8: MOVFF 6CA,6EE
1BCC: MOVLB 0
1BCE: RCALL 1442
1BD0: MOVFF 6E3,FEA
1BD4: MOVFF 6E2,FE9
1BD8: MOVFF 6DB,6E7
1BDC: MOVFF 6DA,6E6
1BE0: MOVFF 6D9,6E5
1BE4: MOVFF 6D8,6E4
1BE8: MOVFF 03,6EB
1BEC: MOVFF 02,6EA
1BF0: MOVFF 01,6E9
1BF4: MOVFF 00,6E8
1BF8: RCALL 1852
1BFA: MOVFF FEA,6D9
1BFE: MOVFF FE9,6D8
1C02: BCF FD8.1
1C04: MOVFF 6D7,6ED
1C08: MOVFF 6D6,6EC
1C0C: MOVFF 6D5,6EB
1C10: MOVFF 6D4,6EA
1C14: MOVFF 03,6F1
1C18: MOVFF 02,6F0
1C1C: MOVFF 01,6EF
1C20: MOVFF 00,6EE
1C24: RCALL 1442
1C26: MOVFF 6D9,FEA
1C2A: MOVFF 6D8,FE9
1C2E: MOVFF 03,6D7
1C32: MOVFF 02,6D6
1C36: MOVFF 01,6D5
1C3A: MOVFF 00,6D4
1C3E: MOVLB 6
1C40: INCF xD2,F
1C42: BTFSC FD8.2
1C44: INCF xD3,F
1C46: BRA 1AF0
.................... err = sqrt((1/(float)size)*err);
1C48: MOVFF 6D1,6D9
1C4C: MOVFF 6D0,6D8
1C50: MOVLB 0
1C52: CALL 140C
1C56: MOVLB 6
1C58: CLRF xED
1C5A: CLRF xEC
1C5C: CLRF xEB
1C5E: MOVLW 7F
1C60: MOVWF xEA
1C62: MOVFF 03,6F1
1C66: MOVFF 02,6F0
1C6A: MOVFF 01,6EF
1C6E: MOVFF 00,6EE
1C72: MOVLB 0
1C74: RCALL 16BA
1C76: MOVFF 00,6D8
1C7A: MOVFF 01,6D9
1C7E: MOVFF 02,6DA
1C82: MOVFF 03,6DB
1C86: MOVFF 03,6E7
1C8A: MOVFF 02,6E6
1C8E: MOVFF 01,6E5
1C92: MOVFF 00,6E4
1C96: MOVFF 6D7,6EB
1C9A: MOVFF 6D6,6EA
1C9E: MOVFF 6D5,6E9
1CA2: MOVFF 6D4,6E8
1CA6: RCALL 1852
1CA8: MOVFF 00,6D8
1CAC: MOVFF 01,6D9
1CB0: MOVFF 02,6DA
1CB4: MOVFF 03,6DB
1CB8: MOVFF 03,6DF
1CBC: MOVFF 02,6DE
1CC0: MOVFF 01,6DD
1CC4: MOVFF 00,6DC
1CC8: BRA 19C2
1CCA: MOVFF 03,6D7
1CCE: MOVFF 02,6D6
1CD2: MOVFF 01,6D5
1CD6: MOVFF 00,6D4
.................... return err;
1CDA: MOVFF 6D4,00
1CDE: MOVFF 6D5,01
1CE2: MOVFF 6D6,02
1CE6: MOVFF 6D7,03
.................... }
1CEA: RETLW 00
....................
.................... void main()
.................... {
*
1F62: CLRF FF8
1F64: BCF FD0.7
1F66: BSF 08.7
1F68: CLRF FEA
1F6A: CLRF FE9
1F6C: MOVF FC1,W
1F6E: ANDLW C0
1F70: IORLW 0F
1F72: MOVWF FC1
1F74: MOVLW 07
1F76: MOVWF FB4
1F78: CLRF 21
1F7A: MOVLW 04
1F7C: MOVWF 22
1F7E: MOVLW 0C
1F80: MOVWF 23
1F82: CLRF 24
1F84: CLRF 28
1F86: CLRF x7C
1F88: CLRF x83
....................
.................... float x[BUFLEN], y[BUFLEN], z[BUFLEN];
.................... float xavg, yavg, zavg;
.................... int i;
.................... port_b_pullups(FALSE);
1F8A: BSF FF1.7
.................... setup_psp(PSP_DISABLED);
1F8C: BCF FB0.4
.................... setup_spi(SPI_SS_DISABLED);
1F8E: BCF FC6.5
1F90: BCF F94.7
1F92: BSF F93.0
1F94: BCF F93.1
1F96: MOVLW 01
1F98: MOVWF FC6
1F9A: MOVLW 00
1F9C: MOVWF FC7
.................... setup_wdt(WDT_OFF);
1F9E: BCF FD1.0
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
1FA0: MOVLW 87
1FA2: MOVWF FD5
.................... setup_timer_1(T1_DISABLED);
1FA4: CLRF FCD
.................... setup_timer_2(T2_DISABLED,0,1);
1FA6: MOVLW 00
1FA8: MOVWF FCA
1FAA: MOVLW 00
1FAC: MOVWF FCB
.................... setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
1FAE: CLRF FB1
.................... setup_comparator(NC_NC_NC_NC);
1FB0: MOVLW 07
1FB2: MOVWF FB4
1FB4: MOVF F92,W
1FB6: MOVWF F92
1FB8: MOVLW 13
1FBA: MOVWF 00
1FBC: DECFSZ 00,F
1FBE: BRA 1FBC
1FC0: BRA 1FC2
1FC2: MOVF FB4,W
1FC4: BCF FA1.6
.................... setup_vref(FALSE);
1FC6: CLRF FB5
.................... enable_interrupts(INT_TIMER0);
1FC8: BSF FF2.5
.................... enable_interrupts(GLOBAL);
1FCA: MOVLW C0
1FCC: IORWF FF2,F
....................
.................... setup_adc_ports(AN0_TO_AN2|VSS_VDD);
1FCE: MOVF FC1,W
1FD0: ANDLW C0
1FD2: IORLW 0C
1FD4: MOVWF FC1
.................... setup_adc(ADC_CLOCK_DIV_64);
1FD6: BCF FC0.0
1FD8: BSF FC0.1
1FDA: BSF FC0.2
1FDC: BSF FC0.7
1FDE: BSF FC2.0
....................
.................... usb_init(); // initialise USB module
1FE0: GOTO 1368
....................
.................... while (TRUE)
.................... {
....................
.................... while(!usb_cdc_connected());
1FE4: BTFSS x80.0
1FE6: BRA 1FE4
.................... printf(usb_cdc_putc,"time[s] x xerr y yerr z zerr \nr");
1FE8: MOVLB 3
1FEA: CLRF xB1
1FEC: MOVF xB1,W
1FEE: MOVLB 0
1FF0: CALL 021E
1FF4: MOVLB 3
1FF6: INCF xB1,F
1FF8: MOVWF 00
1FFA: MOVFF FE8,6DB
1FFE: MOVLB 0
2000: CALL 13D4
2004: MOVLW 25
2006: MOVLB 3
2008: SUBWF xB1,W
200A: BNZ 1FEC
....................
.................... while(usb_cdc_connected()) // pockej nez se pripoji seriovy port PC
.................... {
200C: MOVLB 0
200E: BTFSS x80.0
2010: BRA 25D0
.................... for(i=0; i <BUFLEN; i++)
2012: MOVLB 3
2014: CLRF xB0
2016: MOVF xB0,W
2018: SUBLW 63
201A: BTFSS FD8.0
201C: BRA 22F4
.................... {
.................... set_adc_channel(1);
201E: MOVLW 04
2020: MOVWF 01
2022: MOVF FC2,W
2024: ANDLW C3
2026: IORWF 01,W
2028: MOVWF FC2
.................... delay_us(10);
202A: MOVLW 13
202C: MOVWF 00
202E: DECFSZ 00,F
2030: BRA 202E
2032: BRA 2034
2034: CLRF 18
2036: BTFSC FF2.7
2038: BSF 18.7
203A: BCF FF2.7
.................... x[i]=read_adc();
203C: MOVLB 7
203E: CLRF x49
2040: MOVFF 3B0,748
2044: CLRF x4B
2046: MOVLW 04
2048: MOVWF x4A
204A: MOVLB 0
204C: CALL 02BA
2050: BTFSC 18.7
2052: BSF FF2.7
2054: MOVFF 02,03
2058: MOVF 01,W
205A: ADDLW 84
205C: MOVWF FE9
205E: MOVLW 00
2060: ADDWFC 02,W
2062: MOVWF FEA
2064: BSF FC2.1
2066: BTFSC FC2.1
2068: BRA 2066
206A: MOVFF FC4,6D9
206E: MOVFF FC3,6D8
2072: MOVLB 0
2074: CALL 140C
2078: MOVFF 00,FEF
207C: MOVFF 01,FEC
2080: MOVFF 02,FEC
2084: MOVFF 03,FEC
2088: CLRF 18
208A: BTFSC FF2.7
208C: BSF 18.7
208E: BCF FF2.7
.................... xavg+=x[i];
2090: MOVLB 7
2092: CLRF x49
2094: MOVFF 3B0,748
2098: CLRF x4B
209A: MOVLW 04
209C: MOVWF x4A
209E: MOVLB 0
20A0: CALL 02BA
20A4: BTFSC 18.7
20A6: BSF FF2.7
20A8: MOVFF 02,03
20AC: MOVF 01,W
20AE: ADDLW 84
20B0: MOVWF FE9
20B2: MOVLW 00
20B4: ADDWFC 02,W
20B6: MOVWF FEA
20B8: MOVFF FEF,00
20BC: MOVFF FEC,01
20C0: MOVFF FEC,02
20C4: MOVFF FEC,03
20C8: MOVFF FEA,3B2
20CC: MOVFF FE9,3B1
20D0: BCF FD8.1
20D2: MOVFF 3A7,6ED
20D6: MOVFF 3A6,6EC
20DA: MOVFF 3A5,6EB
20DE: MOVFF 3A4,6EA
20E2: MOVFF 03,6F1
20E6: MOVFF 02,6F0
20EA: MOVFF 01,6EF
20EE: MOVFF 00,6EE
20F2: CALL 1442
20F6: MOVFF 3B2,FEA
20FA: MOVFF 3B1,FE9
20FE: MOVFF 03,3A7
2102: MOVFF 02,3A6
2106: MOVFF 01,3A5
210A: MOVFF 00,3A4
....................
.................... set_adc_channel(1);
210E: MOVLW 04
2110: MOVWF 01
2112: MOVF FC2,W
2114: ANDLW C3
2116: IORWF 01,W
2118: MOVWF FC2
.................... delay_us(10);
211A: MOVLW 13
211C: MOVWF 00
211E: DECFSZ 00,F
2120: BRA 211E
2122: BRA 2124
2124: CLRF 18
2126: BTFSC FF2.7
2128: BSF 18.7
212A: BCF FF2.7
.................... y[i]=read_adc();
212C: MOVLB 7
212E: CLRF x49
2130: MOVFF 3B0,748
2134: CLRF x4B
2136: MOVLW 04
2138: MOVWF x4A
213A: MOVLB 0
213C: CALL 02BA
2140: BTFSC 18.7
2142: BSF FF2.7
2144: MOVFF 02,03
2148: MOVF 01,W
214A: ADDLW 14
214C: MOVWF FE9
214E: MOVLW 02
2150: ADDWFC 02,W
2152: MOVWF FEA
2154: BSF FC2.1
2156: BTFSC FC2.1
2158: BRA 2156
215A: MOVFF FC4,6D9
215E: MOVFF FC3,6D8
2162: MOVLB 0
2164: CALL 140C
2168: MOVFF 00,FEF
216C: MOVFF 01,FEC
2170: MOVFF 02,FEC
2174: MOVFF 03,FEC
2178: CLRF 18
217A: BTFSC FF2.7
217C: BSF 18.7
217E: BCF FF2.7
.................... yavg+=y[i];
2180: MOVLB 7
2182: CLRF x49
2184: MOVFF 3B0,748
2188: CLRF x4B
218A: MOVLW 04
218C: MOVWF x4A
218E: MOVLB 0
2190: CALL 02BA
2194: BTFSC 18.7
2196: BSF FF2.7
2198: MOVFF 02,03
219C: MOVF 01,W
219E: ADDLW 14
21A0: MOVWF FE9
21A2: MOVLW 02
21A4: ADDWFC 02,W
21A6: MOVWF FEA
21A8: MOVFF FEF,00
21AC: MOVFF FEC,01
21B0: MOVFF FEC,02
21B4: MOVFF FEC,03
21B8: MOVFF FEA,3B2
21BC: MOVFF FE9,3B1
21C0: BCF FD8.1
21C2: MOVFF 3AB,6ED
21C6: MOVFF 3AA,6EC
21CA: MOVFF 3A9,6EB
21CE: MOVFF 3A8,6EA
21D2: MOVFF 03,6F1
21D6: MOVFF 02,6F0
21DA: MOVFF 01,6EF
21DE: MOVFF 00,6EE
21E2: CALL 1442
21E6: MOVFF 3B2,FEA
21EA: MOVFF 3B1,FE9
21EE: MOVFF 03,3AB
21F2: MOVFF 02,3AA
21F6: MOVFF 01,3A9
21FA: MOVFF 00,3A8
....................
.................... set_adc_channel(1);
21FE: MOVLW 04
2200: MOVWF 01
2202: MOVF FC2,W
2204: ANDLW C3
2206: IORWF 01,W
2208: MOVWF FC2
.................... delay_us(10);
220A: MOVLW 13
220C: MOVWF 00
220E: DECFSZ 00,F
2210: BRA 220E
2212: BRA 2214
2214: CLRF 18
2216: BTFSC FF2.7
2218: BSF 18.7
221A: BCF FF2.7
.................... z[i]=read_adc();
221C: MOVLB 7
221E: CLRF x49
2220: MOVFF 3B0,748
2224: CLRF x4B
2226: MOVLW 04
2228: MOVWF x4A
222A: MOVLB 0
222C: CALL 02BA
2230: BTFSC 18.7
2232: BSF FF2.7
2234: MOVFF 02,03
2238: MOVF 01,W
223A: ADDLW 20
223C: MOVWF FE9
223E: MOVLW 05
2240: ADDWFC 02,W
2242: MOVWF FEA
2244: BSF FC2.1
2246: BTFSC FC2.1
2248: BRA 2246
224A: MOVFF FC4,6D9
224E: MOVFF FC3,6D8
2252: MOVLB 0
2254: CALL 140C
2258: MOVFF 00,FEF
225C: MOVFF 01,FEC
2260: MOVFF 02,FEC
2264: MOVFF 03,FEC
2268: CLRF 18
226A: BTFSC FF2.7
226C: BSF 18.7
226E: BCF FF2.7
.................... zavg+=z[i];
2270: MOVLB 7
2272: CLRF x49
2274: MOVFF 3B0,748
2278: CLRF x4B
227A: MOVLW 04
227C: MOVWF x4A
227E: MOVLB 0
2280: CALL 02BA
2284: BTFSC 18.7
2286: BSF FF2.7
2288: MOVFF 02,03
228C: MOVF 01,W
228E: ADDLW 20
2290: MOVWF FE9
2292: MOVLW 05
2294: ADDWFC 02,W
2296: MOVWF FEA
2298: MOVFF FEF,00
229C: MOVFF FEC,01
22A0: MOVFF FEC,02
22A4: MOVFF FEC,03
22A8: MOVFF FEA,3B2
22AC: MOVFF FE9,3B1
22B0: BCF FD8.1
22B2: MOVFF 3AF,6ED
22B6: MOVFF 3AE,6EC
22BA: MOVFF 3AD,6EB
22BE: MOVFF 3AC,6EA
22C2: MOVFF 03,6F1
22C6: MOVFF 02,6F0
22CA: MOVFF 01,6EF
22CE: MOVFF 00,6EE
22D2: CALL 1442
22D6: MOVFF 3B2,FEA
22DA: MOVFF 3B1,FE9
22DE: MOVFF 03,3AF
22E2: MOVFF 02,3AE
22E6: MOVFF 01,3AD
22EA: MOVFF 00,3AC
.................... }
22EE: MOVLB 3
22F0: INCF xB0,F
22F2: BRA 2016
....................
.................... xavg=xavg/BUFLEN;
22F4: MOVFF 3A7,6ED
22F8: MOVFF 3A6,6EC
22FC: MOVFF 3A5,6EB
2300: MOVFF 3A4,6EA
2304: MOVLB 6
2306: CLRF xF1
2308: CLRF xF0
230A: MOVLW 48
230C: MOVWF xEF
230E: MOVLW 85
2310: MOVWF xEE
2312: MOVLB 0
2314: CALL 16BA
2318: MOVFF 03,3A7
231C: MOVFF 02,3A6
2320: MOVFF 01,3A5
2324: MOVFF 00,3A4
.................... yavg=yavg/BUFLEN;
2328: MOVFF 3AB,6ED
232C: MOVFF 3AA,6EC
2330: MOVFF 3A9,6EB
2334: MOVFF 3A8,6EA
2338: MOVLB 6
233A: CLRF xF1
233C: CLRF xF0
233E: MOVLW 48
2340: MOVWF xEF
2342: MOVLW 85
2344: MOVWF xEE
2346: MOVLB 0
2348: CALL 16BA
234C: MOVFF 03,3AB
2350: MOVFF 02,3AA
2354: MOVFF 01,3A9
2358: MOVFF 00,3A8
.................... zavg=zavg/BUFLEN;
235C: MOVFF 3AF,6ED
2360: MOVFF 3AE,6EC
2364: MOVFF 3AD,6EB
2368: MOVFF 3AC,6EA
236C: MOVLB 6
236E: CLRF xF1
2370: CLRF xF0
2372: MOVLW 48
2374: MOVWF xEF
2376: MOVLW 85
2378: MOVWF xEE
237A: MOVLB 0
237C: CALL 16BA
2380: MOVFF 03,3AF
2384: MOVFF 02,3AE
2388: MOVFF 01,3AD
238C: MOVFF 00,3AC
....................
.................... // odesli namerene hodnoty
.................... printf(usb_cdc_putc, "%7.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f \n\r",((time << 16) + get_timer0())/15625.0, xavg, quadraticerror(xavg,x,BUFLEN), yavg, quadraticerror(yavg,y,BUFLEN), zavg, quadraticerror(zavg,z,BUFLEN)); //konstanta k je kvuli prevodu do rozzumnych jednotek [s]
2390: MOVFF 1A,3B5
2394: MOVFF 19,3B4
2398: MOVLB 3
239A: CLRF xB2
239C: CLRF xB3
239E: MOVF FD6,W
23A0: MOVFF FD7,03
23A4: ADDWF xB2,F
23A6: MOVF FD7,W
23A8: ADDWFC xB3,F
23AA: MOVLW 00
23AC: ADDWFC xB4,F
23AE: ADDWFC xB5,F
23B0: MOVFF 3B5,6C5
23B4: MOVFF 3B4,6C4
23B8: MOVFF 3B3,6C3
23BC: MOVFF 3B2,6C2
23C0: MOVLB 0
23C2: GOTO 1818
23C6: MOVFF 03,6ED
23CA: MOVFF 02,6EC
23CE: MOVFF 01,6EB
23D2: MOVFF 00,6EA
23D6: MOVLB 6
23D8: CLRF xF1
23DA: MOVLW 24
23DC: MOVWF xF0
23DE: MOVLW 74
23E0: MOVWF xEF
23E2: MOVLW 8C
23E4: MOVWF xEE
23E6: MOVLB 0
23E8: CALL 16BA
23EC: MOVFF 00,3B2
23F0: MOVFF 01,3B3
23F4: MOVFF 02,3B4
23F8: MOVFF 03,3B5
23FC: MOVFF 3A7,6CD
2400: MOVFF 3A6,6CC
2404: MOVFF 3A5,6CB
2408: MOVFF 3A4,6CA
240C: MOVLB 6
240E: CLRF xCF
2410: MOVLW 84
2412: MOVWF xCE
2414: CLRF xD1
2416: MOVLW 64
2418: MOVWF xD0
241A: MOVLB 0
241C: CALL 1AE2
2420: MOVFF 00,3B6
2424: MOVFF 01,3B7
2428: MOVFF 02,3B8
242C: MOVFF 03,3B9
2430: MOVFF 3AB,6CD
2434: MOVFF 3AA,6CC
2438: MOVFF 3A9,6CB
243C: MOVFF 3A8,6CA
2440: MOVLW 02
2442: MOVLB 6
2444: MOVWF xCF
2446: MOVLW 14
2448: MOVWF xCE
244A: CLRF xD1
244C: MOVLW 64
244E: MOVWF xD0
2450: MOVLB 0
2452: CALL 1AE2
2456: MOVFF 00,3BA
245A: MOVFF 01,3BB
245E: MOVFF 02,3BC
2462: MOVFF 03,3BD
2466: MOVFF 3AF,6CD
246A: MOVFF 3AE,6CC
246E: MOVFF 3AD,6CB
2472: MOVFF 3AC,6CA
2476: MOVLW 05
2478: MOVLB 6
247A: MOVWF xCF
247C: MOVLW 20
247E: MOVWF xCE
2480: CLRF xD1
2482: MOVLW 64
2484: MOVWF xD0
2486: MOVLB 0
2488: CALL 1AE2
248C: MOVFF 00,3BE
2490: MOVFF 01,3BF
2494: MOVFF 02,3C0
2498: MOVFF 03,3C1
249C: MOVLW 06
249E: MOVWF FE9
24A0: MOVFF 3B5,6D1
24A4: MOVFF 3B4,6D0
24A8: MOVFF 3B3,6CF
24AC: MOVFF 3B2,6CE
24B0: MOVLW 03
24B2: MOVLB 6
24B4: MOVWF xD2
24B6: MOVLB 0
24B8: RCALL 1DB0
24BA: MOVLW 20
24BC: MOVLB 6
24BE: MOVWF xDB
24C0: MOVLB 0
24C2: CALL 13D4
24C6: MOVLW 03
24C8: MOVWF FE9
24CA: MOVFF 3A7,6D1
24CE: MOVFF 3A6,6D0
24D2: MOVFF 3A5,6CF
24D6: MOVFF 3A4,6CE
24DA: MOVLB 6
24DC: MOVWF xD2
24DE: MOVLB 0
24E0: RCALL 1DB0
24E2: MOVLW 20
24E4: MOVLB 6
24E6: MOVWF xDB
24E8: MOVLB 0
24EA: CALL 13D4
24EE: MOVLW 03
24F0: MOVWF FE9
24F2: MOVFF 3B9,6D1
24F6: MOVFF 3B8,6D0
24FA: MOVFF 3B7,6CF
24FE: MOVFF 3B6,6CE
2502: MOVLB 6
2504: MOVWF xD2
2506: MOVLB 0
2508: RCALL 1DB0
250A: MOVLW 20
250C: MOVLB 6
250E: MOVWF xDB
2510: MOVLB 0
2512: CALL 13D4
2516: MOVLW 03
2518: MOVWF FE9
251A: MOVFF 3AB,6D1
251E: MOVFF 3AA,6D0
2522: MOVFF 3A9,6CF
2526: MOVFF 3A8,6CE
252A: MOVLB 6
252C: MOVWF xD2
252E: MOVLB 0
2530: RCALL 1DB0
2532: MOVLW 20
2534: MOVLB 6
2536: MOVWF xDB
2538: MOVLB 0
253A: CALL 13D4
253E: MOVLW 03
2540: MOVWF FE9
2542: MOVFF 3BD,6D1
2546: MOVFF 3BC,6D0
254A: MOVFF 3BB,6CF
254E: MOVFF 3BA,6CE
2552: MOVLB 6
2554: MOVWF xD2
2556: MOVLB 0
2558: RCALL 1DB0
255A: MOVLW 20
255C: MOVLB 6
255E: MOVWF xDB
2560: MOVLB 0
2562: CALL 13D4
2566: MOVLW 03
2568: MOVWF FE9
256A: MOVFF 3AF,6D1
256E: MOVFF 3AE,6D0
2572: MOVFF 3AD,6CF
2576: MOVFF 3AC,6CE
257A: MOVLB 6
257C: MOVWF xD2
257E: MOVLB 0
2580: RCALL 1DB0
2582: MOVLW 20
2584: MOVLB 6
2586: MOVWF xDB
2588: MOVLB 0
258A: CALL 13D4
258E: MOVLW 03
2590: MOVWF FE9
2592: MOVFF 3C1,6D1
2596: MOVFF 3C0,6D0
259A: MOVFF 3BF,6CF
259E: MOVFF 3BE,6CE
25A2: MOVLB 6
25A4: MOVWF xD2
25A6: MOVLB 0
25A8: RCALL 1DB0
25AA: MOVLW 20
25AC: MOVLB 6
25AE: MOVWF xDB
25B0: MOVLB 0
25B2: CALL 13D4
25B6: MOVLW 0A
25B8: MOVLB 6
25BA: MOVWF xDB
25BC: MOVLB 0
25BE: CALL 13D4
25C2: MOVLW 0D
25C4: MOVLB 6
25C6: MOVWF xDB
25C8: MOVLB 0
25CA: CALL 13D4
.................... }
25CE: BRA 200E
.................... }
25D0: BRA 1FE4
.................... }
25D2: SLEEP
 
Configuration Fuses:
Word 1: CE3C IESO FCMEN HSPLL PLL5 CPUDIV4 USBDIV
Word 2: 0E39 NOBROWNOUT WDT128 NOWDT BORV20 NOPUT VREGEN
Word 3: 8700 PBADEN CCP2C1 MCLR LPT1OSC
Word 4: 00A1 STVREN NODEBUG NOLVP NOXINST ICPRT
Word 5: C00F NOPROTECT NOCPD NOCPB
Word 6: E00F NOWRT NOWRTD NOWRTC NOWRTB
Word 7: 400F NOEBTR NOEBTRB