├── .gitignore ├── .travis.yml ├── CHANGELOG ├── COPYING ├── COPYING.LESSER ├── Makefile ├── NOTES ├── README ├── docs ├── docs.conf └── intro │ ├── .gitignore │ ├── Makefile │ └── intro.tex ├── examples ├── Makefile ├── NOTES ├── bulkloop │ ├── Makefile │ ├── bulkloop.c │ ├── dscr.a51 │ ├── load.py │ ├── test.cpp │ └── test.py ├── debugdevice │ ├── Makefile │ ├── debugdev.c │ └── dscr.a51 ├── debugdevice_full_duplex │ ├── .gitignore │ ├── Makefile │ ├── debugdev.c │ ├── download.sh │ ├── dscr.a51 │ ├── terminal.c │ └── test.cpp ├── eeprom │ ├── Makefile │ ├── client.py │ └── firmware │ │ ├── Makefile │ │ ├── dscr.a51 │ │ └── eeprom.c ├── fx2 │ ├── .gitignore │ ├── cpp │ │ ├── .gitignore │ │ ├── __init__.py │ │ ├── fx2.cpp │ │ ├── fx2.h │ │ └── fx2.i │ ├── fx2load │ │ └── __init__.py │ ├── scripts │ │ └── fx2load │ └── setup.py ├── i2c │ ├── Makefile │ ├── i2c.c │ └── load.py ├── lights │ ├── .gitignore │ ├── Makefile │ └── lights.c ├── reset │ ├── Makefile │ ├── fx2_c0.c │ └── reset.c ├── serial │ ├── Makefile │ └── serial.c ├── timers │ ├── .gitignore │ ├── Makefile │ └── timers.c └── usbmon_c │ ├── Makefile │ ├── download.sh │ ├── dscr.a51 │ ├── test.c │ └── usbmon.c ├── fw ├── .gitignore ├── Makefile ├── device.c ├── dscr.a51 ├── fw.c └── readme.txt ├── include ├── autovector.h ├── delay.h ├── eputils.h ├── fx2ints.h ├── fx2macros.h ├── fx2regs.h ├── fx2types.h ├── gpif.h ├── i2c.h ├── lights.h ├── serial.h └── setupdat.h ├── lib ├── .gitignore ├── Makefile ├── delay.c ├── eputils.c ├── fx2.mk ├── gpif.c ├── i2c.c ├── interrupts │ ├── ep0ack_isr.c │ ├── ep0in_isr.c │ ├── ep0out_isr.c │ ├── ep0ping_isr.c │ ├── ep1in_isr.c │ ├── ep1out_isr.c │ ├── ep1ping_isr.c │ ├── ep2_isr.c │ ├── ep2ef_isr.c │ ├── ep2ff_isr.c │ ├── ep2isoerr_isr.c │ ├── ep2pf_isr.c │ ├── ep2ping_isr.c │ ├── ep4_isr.c │ ├── ep4ef_isr.c │ ├── ep4ff_isr.c │ ├── ep4isoerr_isr.c │ ├── ep4pf_isr.c │ ├── ep4ping_isr.c │ ├── ep6_isr.c │ ├── ep6ef_isr.c │ ├── ep6ff_isr.c │ ├── ep6isoerr_isr.c │ ├── ep6pf_isr.c │ ├── ep6ping_isr.c │ ├── ep8_isr.c │ ├── ep8ef_isr.c │ ├── ep8ff_isr.c │ ├── ep8isoerr_isr.c │ ├── ep8pf_isr.c │ ├── ep8ping_isr.c │ ├── errlimit_isr.c │ ├── gpifdone_isr.c │ ├── gpifwf_isr.c │ ├── hispeed_isr.c │ ├── ibn_isr.c │ ├── sof_isr.c │ ├── spare_isr.c │ ├── sudav_isr.c │ ├── suspend_isr.c │ ├── sutok_isr.c │ └── usbreset_isr.c ├── serial.c ├── setupdat.c └── usbav.a51 └── utils ├── gpif2dat └── ihx2iic.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.asm 2 | *.rel 3 | *.lst 4 | *.sym 5 | *.adb 6 | *.cdb 7 | *.ihx 8 | *.bix 9 | *.rst 10 | *.mem 11 | *.map 12 | *.lnk 13 | *.kpf 14 | *.swp 15 | *.iic 16 | docs/html 17 | build 18 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | sudo: required 3 | 4 | install: 5 | - # Add PPA with newer version of sdcc backported to precise. 6 | - sudo add-apt-repository -y ppa:mithro/sdcc-precise 7 | - sudo apt-get update 8 | - # Need libusb-dev for fx2loader and other tools 9 | - sudo apt-get install -y libusb-1.0-0-dev 10 | - # Install sdcc 11 | - sudo apt-get install --force-yes -y sdcc 12 | - sdcc --version 13 | 14 | script: 15 | - make 16 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 0.2 2 | * Change I2C routines to return FALSE intead of infinite loop possibility. 3 | * Addition of fx2load script to load eeprom information. 4 | * EEprom upload/download example. 5 | * New SETUP_TYPE macro 6 | * Removed printfs from setupdat module. 7 | * Add usb "other speed" descriptor handling to setupdat 8 | * Support for usb suspend/wakeup 9 | * Enhanced renumerate macro to handle properly when loading from eeprom 10 | * Addition of framework files. Allows quick starting of new firmware projects. 11 | * ihx2iic helper script. Allows easy converting of ihx files to iic for 12 | loading to eeprom. 13 | * New GPIF macros to set TC with 16 or 32 bit values. 14 | * Addtional enable/disable macros for endpoint interrupts. 15 | * Additional ep0 utilities (writeep0) 16 | * Additional i2c write functionality for i2c parts requiring different 17 | address width's or even no address data. 18 | * Correct fx2 register documentation. 19 | * Addition of serial io example. 20 | * Added cancel_i2c_trans extern bool to allow canceling a blocked i2c transaction. 21 | * FX1 development board debug light addresses. 22 | * Various other minor bug fixes/optimizations. 23 | * remove usbjt.h. In place, use autovector.h. jump table routines no longer 24 | need defined in your firmware. fx2.lib contains default routines. Override 25 | them with interrupt handlers you want to handle. 26 | * added fx2ints.h. Interrupt numbers/macros for standard fx2 interrupts. 27 | * added timer example 28 | * Moved examples and firmwware framework to use common lib/fx2.mk Makefile. 29 | fx2.mk can be easily adapted for any firmware project. 30 | 31 | 0.1 32 | * Initial Release. 33 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | VER=devel 4 | TAG=HEAD 5 | 6 | .PHONY: all docs 7 | 8 | all: 9 | make -C lib 10 | make -C examples 11 | 12 | clean: 13 | make -C lib clean 14 | make -C examples clean 15 | 16 | docs: 17 | doxygen docs/docs.conf 18 | make -C docs/intro 19 | 20 | dist: all docs 21 | mkdir -p build 22 | git archive --prefix=fx2lib/ $(TAG) > build/fx2-$(VER).tar 23 | tar -C .. -rf build/fx2-$(VER).tar \ 24 | fx2lib/docs/html \ 25 | fx2lib/lib/fx2.lib \ 26 | fx2lib/docs/intro/intro.pdf 27 | cat build/fx2-$(VER).tar | gzip > build/fx2-$(VER).tgz 28 | 29 | 30 | -------------------------------------------------------------------------------- /NOTES: -------------------------------------------------------------------------------- 1 | Notes on Various things I've learned about SDCC and the FX2 2 | 3 | * libusb on Linux 4 | * cycfx2prog: http://www.triplespark.net/elec/periph/USB-FX2/software/index.html 5 | - most of this functionality is now in the fx2load package for python 6 | - which is in examples/fx2 7 | * sdcc has sdcc/support/scripts/keil2sdcc.pl which I used to create the fx2regs.h file from the keil header. 8 | * sdcc is little endian, keil is big endian (important if doing usb communication) 9 | * xdata can go up to 64k on the EZ-USB development board but 10 | - the fx2 chip itself only has 16k (end at 0x4000) Firmware written for other than the dev board 11 | - should use --xram-size --xram-loc etc to make sure it isn't using memory beyond 16k. 12 | * linux has objcopy, which can be used in place of Hex2bix for bix files 13 | - objcopy -I ihex -O binary --pad-to=8192 input [output] 14 | 15 | 16 | Memory 17 | * 256 bytes internal 18 | - lower 128=registers/bits (direct or indirect) 19 | - upper 128=stack (or whatever but only indirect addressing) 20 | - sfs occupy upper 128 space only direct addressing 21 | 22 | * external 23 | - 16k on chip 0-0x3fff 24 | - 512 bytes on chip scratch ram 0xe000 - 0xe1ff (data memory only) 25 | - epbuffers and control at 0xe200-0xffff (data memory only) 26 | 27 | Only the on chip 16k and 512 bytes can be uploaded w/ eeprom or downloaded to host with SETUPPTR 28 | Might be possible to load the descriptors to the scratch ram instead of code ram area? 29 | 30 | sdcc data types 31 | data/near=direct addressable internal memory (default for model-small) 32 | xdata/far=external ram (default for model-large) 33 | idata=indirect addressable internal memory 34 | pdata=access to xdata area, but uses sfr to get to address (sdcc 4.1) 35 | code=code memory, study this more. 36 | bit=uses lower 128 bit area 37 | 38 | 39 | TODO: 40 | * Possibly add CKCON and bmSTRETCH customization 41 | * IN2CLR and INT4CLR registers can be used intead of explicitly clearing int2 and int4 interrupts. (Faster) 42 | See (15.5) 43 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Before building this library, you need have sdcc installed and in your path. 2 | 3 | http://sdcc.sf.net 4 | 5 | To build this library, run make 6 | 7 | > make 8 | 9 | This produces lib/fx2.lib. You can also run make in the lib folder. 10 | 11 | You can also build the documentation if you have doxygen installed. 12 | 13 | > make docs 14 | 15 | ** Firmware framework Quickstart 16 | 17 | > cd fw 18 | > make 19 | 20 | You can copy the fw directory to your own directory and customize it as needed. 21 | 22 | ** More custom firmware 23 | 24 | To use routines included with this library in your own firmware, 25 | add the include files to your include path and the lib file to your compile command: 26 | 27 | > sdcc -mmcs51 -I fx2.lib -L 28 | 29 | fx2lib also includes an example program for loading firmware onto your device. 30 | See examples/fx2. 31 | 32 | 33 | Enjoy! 34 | Comments, Patches, all welcome. 35 | 36 | Contributors 37 | Dennis Muhlestein 38 | Ubixum, Inc 39 | Steve Calfee 40 | Sven Schnelle 41 | Tim 'mithro' Ansell 42 | -------------------------------------------------------------------------------- /docs/intro/.gitignore: -------------------------------------------------------------------------------- 1 | *.aux 2 | *.log 3 | *.toc 4 | html 5 | *.pdf 6 | *.out 7 | -------------------------------------------------------------------------------- /docs/intro/Makefile: -------------------------------------------------------------------------------- 1 | 2 | .PHONY: pdf html 3 | 4 | 5 | pdf: intro.pdf 6 | intro.pdf: intro.tex 7 | rubber -d intro 8 | 9 | html: intro.tex 10 | mkdir -p html 11 | latex2html -dir html intro.tex 12 | -------------------------------------------------------------------------------- /docs/intro/intro.tex: -------------------------------------------------------------------------------- 1 | 2 | \documentclass[12pt]{article} 3 | \usepackage[pdftex,bookmarks=true,linktocpage=true,pdfborder={0 0 0 0}]{hyperref} 4 | \usepackage{amsmath} 5 | 6 | \newcommand{\itwoc}{$\text{I}^{2}\text{C}$ } 7 | 8 | 9 | \title{Fx2lib Introduction} 10 | \begin{document} 11 | \maketitle 12 | \tableofcontents 13 | \section{Introduction} 14 | Fx2lib is an open source library for the Cypress EZ-USB Fx2 8051 and variants. 15 | It is written in C and can be compiled with \href{http://sdcc.sourceforge.net}{SDCC}. 16 | Fx2lib contains libraries for performing common tasks with the Fx2 chip as well as a framework for starting new firmware projects. 17 | There are also a number of utilities for performing common firmware development tasks. 18 | 19 | \section{Fx2lib Features} 20 | 21 | Fx2lib provides libaries for the following common firmware tasks: 22 | 23 | \begin{itemize} 24 | \item Serial IO. Ease of setting BAUD rate and reading and writing from serial ports. 25 | \item Vendor Commands. Handling of required USB vendor commands and ease of implementing your own vendor command handlers. 26 | \item USB interrupts. Ease of enabling/disabling USB interrupts and adding your own interrupt handlers. 27 | \item \itwoc IO. Ease of reading and writing to \itwoc devices. EEprom functions are also included. 28 | \item GPIF. Functions for setting up the GPIF as well as performing single and fifo reads/writes. 29 | \item Endpoints. Simplify reading/writing with endpoint 0. 30 | \item Other definitions and macros. All Fx2 SFR, sbit and registers defined as well as other macros for common fx2 tasks. 31 | \end{itemize} 32 | 33 | Detailed documentation for the library API is available online or with your downloaded fx2lib copy. 34 | 35 | \section{Fx2lib Utilities} 36 | 37 | \begin{itemize} 38 | \item gpif2dat. Takes the output from the Cypress GPIF designer (the .c file) and creates an sdcc compatible c file with only the waveforms and initialization structures needed for use with the Fx2lib GPIF functions. 39 | \item ihx2iic. Creates a compressed iic from your firmware ihx file. Used for storing your firmware on an eeprom. 40 | \item fx2load. Command line interface and Python bindings for loading firmware onto an Fx2 device and for doing basic device IO. 41 | \end{itemize} 42 | 43 | \section{Getting Started} 44 | 45 | \begin{enumerate} 46 | \item Obtain Fx2lib. 47 | 48 | Fx2lib can be compiled from sources or is available as a pre-compiled library. 49 | If you choose to compile Fx2lib from sources, simply make sure sdcc is in your path and run make in the fx2lib root folder. 50 | Whether you have downloaded a pre-compiled version or build your own Fx2lib library, you should have fx2lib/lib/fx2.lib available for the examples and your own firmware. 51 | \item Install the drivers. 52 | 53 | Fx2lib uses \href{http://libusb.sourceforge.net}{libusb} to handle low level USB communication with the underlying operating system. 54 | Each operating system has different requirements for driver installation. 55 | See the Fx2lib driver guide for details on installing USB drivers for your specific operating system. 56 | You'll need to install the drivers specifically for the device you plan on doing the Fx2 development with. 57 | 58 | \item Running Example Firmware. 59 | 60 | Each firmware example has a Makefile and a load script. 61 | Simply run make to create the associated .ihx file and then run make load to load the firmware onto your device. 62 | The examples/NOTES contains more details on each examples firmware. 63 | 64 | The default load targets use the Cypress vendor id with the development board product ID. 65 | Depending on your hardware, you'll need to change these appropriately. 66 | \item Starting your own firmware. 67 | 68 | Fx2lib provides a quick start firmware framework in the fx2lib/fw directory. 69 | Simply copy this directory to your own location and begin modifying the files to start your own firmware. 70 | 71 | \end{enumerate} 72 | 73 | 74 | \section{Where Next} 75 | 76 | \begin{itemize} 77 | \item \href{http://fx2lib.sourceforge.net/docs/}{Fx2lib API documentation} 78 | \end{itemize} 79 | 80 | \end{document} 81 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | DIRS= bulkloop debugdevice debugdevice_full_duplex eeprom i2c lights reset serial timers usbmon_c 2 | 3 | .PHONY: dirs $(DIRS) clean 4 | 5 | dirs: $(DIRS) 6 | clean: $(DIRS) 7 | 8 | $(DIRS): 9 | $(MAKE) -C $@ $(MAKECMDGOALS) 10 | 11 | -------------------------------------------------------------------------------- /examples/NOTES: -------------------------------------------------------------------------------- 1 | The examples here show various firmware examples and also various ways to 2 | start new firmware projects as well as various ways to start communicating with your device. 3 | In addition, you can look at the fx2.mk include and the example project Makefiles 4 | to see how you might set up your own project. 5 | 6 | For simple examples, you can ignore the link warnings. (Those pertain to the usb jump table 7 | and device descriptor areas and are not used for all examples) 8 | 9 | You can move up the food chain of programming languages pretty quickly if you like: 10 | 11 | C: Program Your Firmware 12 | C++: Write a libusb driver 13 | Python: Write Bindings for your driver so you can test things interactively! 14 | 15 | fx2: 16 | An example firmware loader and basic firmware terminal using the above strategy. 17 | Requires libusb-1.0, Python 2.5 18 | 19 | Installation: 20 | cd fx2 21 | python setup.py install 22 | 23 | 24 | Use the fx2load w/ reset_bix function to load firmware onto a device. 25 | Example: 26 | python 27 | > from fx2load import * 28 | > openfx2() 29 | > reset_bix('') 30 | > f.do_usb_command (..... 31 | > f.ep_bulk(...... 32 | 33 | There is also an fx2load script for doing the same thing with the command line. 34 | 35 | 36 | eeprom: 37 | Simple firmware for reading and writing information from the eeprom. The client.py 38 | file contains a function to read an existing prom image. 39 | 40 | 41 | lights: 42 | A really simple program that cycles the lights on the CY3864 development board. 43 | 44 | 45 | bulkloop: 46 | Demonstrations: 47 | * looping data on endpoints. 48 | * Custom device descriptor. 49 | * Vendor commands. 50 | * Usb jump table. 51 | * serial IO 52 | 53 | 54 | debugdevice: 55 | This firmware implements a half-duplex version of the EHCI defined "debug 56 | device", which is used for low level hardware debugging in the USB stack. 57 | 58 | 59 | debugdevice_full_duplex: 60 | This firmware implements a full-duplex version of the EHCI defined "debug 61 | device", which is used for low level hardware debugging in the USB stack. 62 | 63 | 64 | i2c: 65 | A port of the Cypress i2c example. 66 | 67 | 68 | reset: 69 | Shows writing to the eeprom on the dev board. The included iic data is the default data 70 | on the dev board and you can use this program to reset your board back to the default 71 | state if you happen to write a non-working iic file to the device. You shouldn't 72 | probably use this on a real board unless you really know what you're doing :) 73 | 74 | 75 | serial: 76 | A simple terminal echo firmware. Echos whatever you type back to the serial terminal. 77 | 78 | 79 | timers: 80 | Demonstrates setting up timers t0, t1, and t2 to be 16 bit counters and also demonstrates 81 | installing interrupts to process the timer overlow. 82 | 83 | 84 | usbmon_c: 85 | Firmware used to test usbmon 86 | (https://www.kernel.org/doc/Documentation/usb/usbmon.txt) collected traces of 87 | the I/O on the USB bus. 88 | 89 | -------------------------------------------------------------------------------- /examples/bulkloop/Makefile: -------------------------------------------------------------------------------- 1 | FX2LIBDIR=../../ 2 | BASENAME = bulkloop 3 | SOURCES=bulkloop.c 4 | A51_SOURCES=dscr.a51 5 | PID=0x1004 6 | 7 | include $(FX2LIBDIR)lib/fx2.mk 8 | 9 | 10 | test: test.cpp 11 | g++ -o test test.cpp -lusb-1.0 12 | 13 | -------------------------------------------------------------------------------- /examples/bulkloop/bulkloop.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | #define SYNCDELAY SYNCDELAY4 31 | #define REARMVAL 0x80 32 | #define REARM() EP2BCL=REARMVAL 33 | 34 | 35 | 36 | volatile WORD bytes; 37 | volatile __bit gotbuf; 38 | volatile BYTE icount; 39 | volatile __bit got_sud; 40 | DWORD lcount; 41 | __bit on; 42 | 43 | void main(void) { 44 | 45 | REVCTL=0; // not using advanced endpoint controls 46 | 47 | d2off(); 48 | on=0; 49 | lcount=0; 50 | got_sud=FALSE; 51 | icount=0; 52 | gotbuf=FALSE; 53 | bytes=0; 54 | 55 | // renumerate 56 | RENUMERATE_UNCOND(); 57 | 58 | 59 | SETCPUFREQ(CLK_48M); 60 | SETIF48MHZ(); 61 | sio0_init(57600); 62 | 63 | 64 | USE_USB_INTS(); 65 | ENABLE_SUDAV(); 66 | ENABLE_SOF(); 67 | ENABLE_HISPEED(); 68 | ENABLE_USBRESET(); 69 | 70 | 71 | // only valid endpoints are 2/6 72 | EP2CFG = 0xA2; // 10100010 73 | SYNCDELAY; 74 | EP6CFG = 0xE2; // 11100010 75 | SYNCDELAY; 76 | EP1INCFG &= ~bmVALID; 77 | SYNCDELAY; 78 | EP1OUTCFG &= ~bmVALID; 79 | SYNCDELAY; 80 | EP4CFG &= ~bmVALID; 81 | SYNCDELAY; 82 | EP8CFG &= ~bmVALID; 83 | SYNCDELAY; 84 | 85 | 86 | // arm ep2 87 | EP2BCL = 0x80; // write once 88 | SYNCDELAY; 89 | EP2BCL = 0x80; // do it again 90 | 91 | 92 | // make it so we enumberate 93 | 94 | 95 | EA=1; // global interrupt enable 96 | printf ( "Done initializing stuff\n" ); 97 | 98 | 99 | d3off(); 100 | 101 | while(TRUE) { 102 | 103 | if ( got_sud ) { 104 | printf ( "Handle setupdata\n" ); 105 | handle_setupdata(); 106 | got_sud=FALSE; 107 | } 108 | 109 | if ( !(EP2468STAT & bmEP2EMPTY) ) { 110 | printf ( "ep2 out received data\n" ); 111 | if ( !(EP2468STAT & bmEP6FULL) ) { // wait for at least one empty in buffer 112 | WORD i; 113 | printf ( "Sending data to ep6 in\n"); 114 | 115 | bytes = MAKEWORD(EP2BCH,EP2BCL); 116 | 117 | for (i=0;i 19 | #include 20 | #include 21 | 22 | int main(int argc, char* argv[]) { 23 | 24 | libusb_context* ctx; 25 | libusb_init(&ctx); 26 | 27 | libusb_device_handle* hndl = libusb_open_device_with_vid_pid(ctx,0x04b4,0x1004); 28 | libusb_claim_interface(hndl,0); 29 | libusb_set_interface_alt_setting(hndl,0,0); 30 | 31 | unsigned short buf[100]; 32 | for (int i=0;i<100;++i) { 33 | buf[i]=i; 34 | } 35 | int transferred; 36 | int rv=libusb_bulk_transfer(hndl,0x02,(unsigned char*)buf,sizeof(buf),&transferred,100); 37 | if(rv) { 38 | printf ( "OUT Transfer failed: %d\n", rv ); 39 | return rv; 40 | } 41 | 42 | unsigned short buf2[100]; 43 | rv=libusb_bulk_transfer(hndl,0x86,(unsigned char*)buf2,sizeof(buf2),&transferred,100); 44 | if(rv) { 45 | printf ( "IN Transfer failed: %d\n", rv ); 46 | return rv; 47 | } 48 | for (int i=0;i<100;++i) { 49 | printf ( "%d ", buf2[i] ); 50 | } 51 | printf("\n"); 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /examples/bulkloop/test.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2009 Ubixum, Inc. 2 | # 3 | # This library is free software; you can redistribute it and/or 4 | # 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USAimport struct 17 | 18 | 19 | import struct 20 | 21 | from fx2load import * 22 | 23 | openfx2(0x04b4,0x1004) 24 | 25 | 26 | def do_bulk(): 27 | # send 100 shorts to ep2 28 | 29 | buf=struct.pack ( 'H'*100, *[i for i in range(100)] ) 30 | f.ep_bulk( buf, 0x02, 1000) 31 | 32 | # read them back out 33 | buf='\x00'*200 34 | f.ep_bulk( buf, 0x86, 1000) 35 | 36 | 37 | print struct.unpack ( 'H'*100, buf ) 38 | 39 | [do_bulk() for i in range(3)] 40 | -------------------------------------------------------------------------------- /examples/debugdevice/Makefile: -------------------------------------------------------------------------------- 1 | FX2LIBDIR=../../ 2 | BASENAME = debugdev 3 | SOURCES=debugdev.c 4 | A51_SOURCES=dscr.a51 5 | PID=0x1004 6 | 7 | include $(FX2LIBDIR)lib/fx2.mk 8 | 9 | -------------------------------------------------------------------------------- /examples/debugdevice/debugdev.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #define SYNCDELAY SYNCDELAY4 30 | #define REARMVAL 0x80 31 | #define REARM() EP2BCL=REARMVAL 32 | 33 | volatile WORD bytes; 34 | volatile __bit gotbuf; 35 | volatile BYTE icount; 36 | volatile __bit got_sud; 37 | DWORD lcount; 38 | __bit on; 39 | 40 | extern WORD debug_dscr; 41 | extern void _transchar(char c); 42 | void main(void) 43 | { 44 | REVCTL=0; // not using advanced endpoint controls 45 | 46 | d2off(); 47 | on=0; 48 | lcount=0; 49 | got_sud=FALSE; 50 | icount=0; 51 | gotbuf=FALSE; 52 | bytes=0; 53 | 54 | // renumerate 55 | RENUMERATE_UNCOND(); 56 | 57 | 58 | SETCPUFREQ(CLK_48M); 59 | SETIF48MHZ(); 60 | sio0_init(115200); 61 | 62 | 63 | USE_USB_INTS(); 64 | ENABLE_SUDAV(); 65 | ENABLE_SOF(); 66 | ENABLE_HISPEED(); 67 | ENABLE_USBRESET(); 68 | 69 | 70 | // only valid endpoints are 2/6 71 | EP2CFG = 0xA2; // 10100010 72 | SYNCDELAY; 73 | EP6CFG = 0xE2; // 11100010 74 | SYNCDELAY; 75 | EP1INCFG &= ~bmVALID; 76 | SYNCDELAY; 77 | EP1OUTCFG &= ~bmVALID; 78 | SYNCDELAY; 79 | EP4CFG &= ~bmVALID; 80 | SYNCDELAY; 81 | EP8CFG &= ~bmVALID; 82 | SYNCDELAY; 83 | 84 | 85 | // arm ep2 86 | EP2BCL = 0x80; // write once 87 | SYNCDELAY; 88 | EP2BCL = 0x80; // do it again 89 | 90 | 91 | // make it so we enumberate 92 | 93 | 94 | EA=1; // global __interrupt enable 95 | printf ( "USB DEBUG: Done initializing stuff\n" ); 96 | 97 | 98 | d3off(); 99 | 100 | while(TRUE) { 101 | 102 | if ( got_sud ) { 103 | handle_setupdata(); 104 | got_sud=FALSE; 105 | } 106 | 107 | if ( !(EP2468STAT & bmEP2EMPTY) ) { 108 | if ( !(EP2468STAT & bmEP6FULL) ) { // wait for at least one empty in buffer 109 | WORD i; 110 | 111 | bytes = MAKEWORD(EP2BCH,EP2BCL); 112 | 113 | for (i=0;i 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #define SYNCDELAY SYNCDELAY4 30 | #define REARMVAL 0x80 31 | #define REARM() EP2BCL=REARMVAL 32 | 33 | volatile __bit got_sud; 34 | extern __code WORD debug_dscr; 35 | 36 | #define INPUTDATA IOB 37 | #define OUTPUTDATA IOD 38 | 39 | #define DVALID_IN (1 << 0) 40 | #define DLAST_IN (1 << 2) 41 | #define DRDY_IN (1 << 3) 42 | 43 | #define DVALID_OUT (1 << 4) 44 | #define DLAST_OUT (1 << 6) 45 | #define DRDY_OUT (1 << 7) 46 | 47 | typedef enum { 48 | TX_STATE_IDLE=0, 49 | TX_STATE_DATA, 50 | TX_STATE_ACK, 51 | } tx_state_t; 52 | 53 | typedef enum { 54 | RX_STATE_IDLE=0, 55 | RX_STATE_DATA, 56 | RX_STATE_ACK, 57 | } rx_state_t; 58 | 59 | static void tx_state(void) 60 | { 61 | static int offset, last; 62 | static tx_state_t state = TX_STATE_IDLE; 63 | 64 | switch(state) { 65 | case TX_STATE_IDLE: 66 | if (EP2468STAT & bmEP6FULL) 67 | break; 68 | IOA |= DRDY_OUT; 69 | 70 | if(!(IOA & DVALID_IN)) 71 | break; 72 | state = TX_STATE_DATA; 73 | /* intentional fall through */ 74 | 75 | case TX_STATE_DATA: 76 | last = IOA & DLAST_IN; 77 | EP6FIFOBUF[offset] = INPUTDATA; 78 | IOA &= ~DRDY_OUT; 79 | state = TX_STATE_ACK; 80 | /* intentional fall through */ 81 | 82 | case TX_STATE_ACK: 83 | if (IOA & DVALID_IN) 84 | break; 85 | offset++; 86 | if (last) { 87 | EP6BCH = MSB(offset); 88 | SYNCDELAY; 89 | EP6BCL = LSB(offset); 90 | state = TX_STATE_IDLE; 91 | offset = 0; 92 | break; 93 | } 94 | state = TX_STATE_IDLE;; 95 | break; 96 | default: 97 | state = TX_STATE_IDLE; 98 | } 99 | } 100 | 101 | static void rx_state(void) 102 | { 103 | static int offset, remaining; 104 | static rx_state_t state = RX_STATE_IDLE; 105 | 106 | switch(state) { 107 | case RX_STATE_IDLE: 108 | if (EP2468STAT & bmEP2EMPTY) 109 | break; 110 | 111 | state = RX_STATE_DATA; 112 | offset = 0; 113 | remaining = MAKEWORD(EP2BCH, EP2BCL); 114 | break; 115 | 116 | case RX_STATE_DATA: 117 | if (!(IOA & DRDY_IN)) 118 | break; 119 | 120 | OUTPUTDATA = EP2FIFOBUF[offset++]; 121 | 122 | if (--remaining) 123 | IOA &= ~DLAST_OUT; 124 | else 125 | IOA |= DLAST_OUT; 126 | 127 | IOA |= DVALID_OUT; 128 | 129 | state = RX_STATE_ACK; 130 | break; 131 | 132 | case RX_STATE_ACK: 133 | if (IOA & DRDY_IN) 134 | break; 135 | 136 | IOA &= ~DVALID_OUT; 137 | 138 | if (remaining) { 139 | state = RX_STATE_DATA; 140 | } else { 141 | state = RX_STATE_IDLE; 142 | REARM(); 143 | } 144 | break; 145 | default: 146 | state = RX_STATE_IDLE; 147 | } 148 | } 149 | 150 | static void mainloop(void) 151 | { 152 | while(TRUE) { 153 | if (got_sud) { 154 | handle_setupdata(); 155 | got_sud=FALSE; 156 | } 157 | tx_state(); 158 | rx_state(); 159 | } 160 | } 161 | 162 | static void clock_setup(void) 163 | { 164 | SETCPUFREQ(CLK_48M); 165 | SETIF48MHZ(); 166 | } 167 | 168 | static void usb_setup(void) 169 | { 170 | RENUMERATE_UNCOND(); 171 | 172 | USE_USB_INTS(); 173 | ENABLE_SUDAV(); 174 | ENABLE_SOF(); 175 | ENABLE_HISPEED(); 176 | ENABLE_USBRESET(); 177 | 178 | /* INT endpoint */ 179 | EP1INCFG = bmVALID | (3 << 4); 180 | SYNCDELAY; 181 | 182 | /* BULK IN endpoint EP2 */ 183 | EP2CFG = 0xA2; // 10100010 184 | SYNCDELAY; 185 | 186 | /* BULK OUT endpoint EP6 */ 187 | EP6CFG = 0xE2; 188 | SYNCDELAY; 189 | 190 | /* disable all other endpoints */ 191 | 192 | EP1OUTCFG &= ~bmVALID; 193 | SYNCDELAY; 194 | 195 | EP4CFG &= ~bmVALID; 196 | SYNCDELAY; 197 | 198 | EP8CFG &= ~bmVALID; 199 | SYNCDELAY; 200 | 201 | // arm ep2 202 | EP2BCL = 0x80; // write once 203 | SYNCDELAY; 204 | EP2BCL = 0x80; // do it again 205 | } 206 | 207 | static void port_setup(void) 208 | { 209 | IOA = 0; 210 | IOB = 0xff; 211 | IOD = 0xff; 212 | 213 | OEA = 0xf0; /* [3:0] INPUT, [7:4] OUTPUT */ 214 | OEB = 0; /* INPUTDATA */ 215 | OED = 0xff; /* OUTPUTDATA */ 216 | } 217 | 218 | void main(void) 219 | { 220 | REVCTL=0; // not using advanced endpoint controls 221 | 222 | port_setup(); 223 | 224 | clock_setup(); 225 | 226 | usb_setup(); 227 | 228 | delay(10); 229 | 230 | EA=1; // global __interrupt enable 231 | 232 | mainloop(); 233 | } 234 | 235 | #define VC_EPSTAT 0xB1 236 | 237 | BOOL handle_vendorcommand(BYTE cmd) 238 | { 239 | __xdata BYTE* pep; 240 | switch ( cmd ) { 241 | case 6: 242 | return TRUE; 243 | case VC_EPSTAT: 244 | 245 | pep = ep_addr(SETUPDAT[2]); 246 | if (pep) { 247 | EP0BUF[0] = *pep; 248 | EP0BCH=0; 249 | EP0BCL=1; 250 | return TRUE; 251 | } 252 | default: 253 | } 254 | return FALSE; 255 | } 256 | 257 | // this firmware only supports 0,0 258 | BOOL handle_get_interface(BYTE ifc, BYTE *alt_ifc) 259 | { 260 | if (ifc) 261 | return FALSE; 262 | *alt_ifc=0; 263 | return TRUE; 264 | } 265 | 266 | BOOL handle_set_interface(BYTE ifc, BYTE alt_ifc) 267 | { 268 | if (ifc==0&&alt_ifc==0) { 269 | // SEE TRM 2.3.7 270 | // reset toggles 271 | RESETTOGGLE(0x02); 272 | RESETTOGGLE(0x86); 273 | // restore endpoints to default condition 274 | RESETFIFO(0x02); 275 | EP2BCL=0x80; 276 | SYNCDELAY; 277 | EP2BCL=0X80; 278 | SYNCDELAY; 279 | RESETFIFO(0x86); 280 | return TRUE; 281 | } else 282 | return FALSE; 283 | } 284 | 285 | // get/set configuration 286 | BYTE handle_get_configuration(void) 287 | { 288 | return 1; 289 | } 290 | 291 | BOOL handle_get_descriptor(void) 292 | { 293 | BYTE desc = SETUPDAT[3]; 294 | if (desc != DSCR_DEBUG_TYPE) 295 | return FALSE; 296 | 297 | SUDPTRH = MSB((WORD)&debug_dscr); 298 | SUDPTRL = LSB((WORD)&debug_dscr); 299 | return TRUE; 300 | } 301 | 302 | BOOL handle_set_configuration(BYTE cfg) 303 | { 304 | 305 | return cfg==1 ? TRUE : FALSE; // we only handle cfg 1 306 | } 307 | 308 | 309 | // copied usb jt routines from usbjt.h 310 | void sudav_isr(void) __interrupt (SUDAV_ISR) 311 | { 312 | got_sud = TRUE; 313 | CLEAR_SUDAV(); 314 | } 315 | 316 | void sof_isr (void) __interrupt (SOF_ISR) __using (1) 317 | { 318 | CLEAR_SOF(); 319 | } 320 | 321 | void usbreset_isr(void) __interrupt (USBRESET_ISR) 322 | { 323 | handle_hispeed(FALSE); 324 | CLEAR_USBRESET(); 325 | } 326 | 327 | void hispeed_isr(void) __interrupt (HISPEED_ISR) 328 | { 329 | handle_hispeed(TRUE); 330 | CLEAR_HISPEED(); 331 | } 332 | -------------------------------------------------------------------------------- /examples/debugdevice_full_duplex/download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | DEVS=$(lsusb|grep 04b4:8613|sed 's/:.*//;s/Bus //;s/Device //;s/ /\//') 4 | 5 | if [ -z "$1" ]; then 6 | echo "$0: usage: $0 " 7 | exit 1; 8 | fi 9 | 10 | for dev in $DEVS;do 11 | echo "Downloading $1 to $dev" 12 | sudo /sbin/fxload -D /dev/bus/usb/$dev -t fx2lp -I $1 13 | done 14 | 15 | exit 0 -------------------------------------------------------------------------------- /examples/debugdevice_full_duplex/terminal.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Sven Schnelle 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | void tp_diff(struct timespec *diff, struct timespec *start, struct timespec *end) 26 | { 27 | if (end->tv_nsec - start->tv_nsec < 0) { 28 | diff->tv_sec = end->tv_sec - start->tv_sec - 1; 29 | diff->tv_nsec = 1000000000 + end->tv_nsec - start->tv_nsec; 30 | } else { 31 | diff->tv_sec = end->tv_sec - start->tv_sec; 32 | diff->tv_nsec = end->tv_nsec - start->tv_nsec; 33 | } 34 | } 35 | 36 | static int format_timediff(struct timespec *diff, char *out, int outlen) 37 | { 38 | if (diff->tv_sec > 1) 39 | return snprintf(out, outlen, "%d.%02lds", (int)diff->tv_sec, 40 | diff->tv_nsec / 10000000); 41 | 42 | if (diff->tv_nsec > 1000000) 43 | return snprintf(out, outlen, "%ldms", diff->tv_nsec / 1000000); 44 | 45 | if (diff->tv_nsec > 1000) 46 | return snprintf(out, outlen, "%ldus", diff->tv_nsec / 1000); 47 | 48 | return snprintf(out, outlen, "%ldns", diff->tv_nsec); 49 | 50 | } 51 | 52 | static int terminal_loop(libusb_device_handle *hndl, FILE *outfile) 53 | { 54 | unsigned char buf[512]; 55 | char timebuf[32]; 56 | 57 | struct timespec tp, oldtp, diff, lastlinetp, linediff; 58 | unsigned char c; 59 | int print_time = 1; 60 | int len, ret, i; 61 | 62 | if (clock_gettime(CLOCK_MONOTONIC, &oldtp) == -1) { 63 | fprintf(stderr, "clock_gettime: %s\n", strerror(errno)); 64 | return -1; 65 | } 66 | 67 | memcpy(&lastlinetp, &oldtp, sizeof(lastlinetp)); 68 | for(;;) { 69 | ret = libusb_bulk_transfer(hndl, 0x86, (unsigned char*)buf ,sizeof(buf), &len, sizeof(buf)); 70 | 71 | if (ret == -4) { 72 | fprintf(stderr, "device disappeared\n"); 73 | return -1; 74 | } 75 | 76 | if(ret != -7 && ret != 0) { 77 | printf("IN Transfer failed: %d\n", ret); 78 | return -1; 79 | } 80 | 81 | for (i = 0; i < len; i++) { 82 | 83 | if (print_time) { 84 | print_time = 0; 85 | if (clock_gettime(CLOCK_MONOTONIC, &tp) == -1) { 86 | fprintf(stderr, "clock_gettime: %s\n", strerror(errno)); 87 | return -1; 88 | } 89 | 90 | tp_diff(&diff, &oldtp, &tp); 91 | tp_diff(&linediff, &lastlinetp, &tp); 92 | 93 | format_timediff(&linediff, timebuf, sizeof(timebuf)-1); 94 | 95 | printf("%3d.%03ld [%5s]: ", (int)diff.tv_sec, diff.tv_nsec / 1000000, timebuf); 96 | fprintf(outfile, "%3d.%03ld [%5s]: ", (int)diff.tv_sec, diff.tv_nsec / 1000000, timebuf); 97 | 98 | memcpy(&lastlinetp, &tp, sizeof(lastlinetp)); 99 | } 100 | 101 | c = buf[i]; 102 | 103 | if (c == '\r') 104 | continue; 105 | 106 | printf ("%c", c); 107 | 108 | print_time = !!(c == '\n'); 109 | 110 | 111 | if (outfile) 112 | fputc(buf[i], outfile); 113 | } 114 | } 115 | } 116 | 117 | int main(int argc __attribute__((unused)), 118 | char **argv __attribute__((unused))) 119 | { 120 | FILE *outfile; 121 | libusb_context* ctx; 122 | libusb_device_handle *hndl; 123 | 124 | libusb_init(&ctx); 125 | 126 | restart: 127 | hndl = libusb_open_device_with_vid_pid(ctx, 0x4b4, 0x8613); 128 | if (!hndl) { 129 | // fprintf(stderr, "failed to open device\n"); 130 | sleep(1); 131 | goto restart; 132 | } 133 | 134 | libusb_claim_interface(hndl, 0); 135 | libusb_set_interface_alt_setting(hndl, 0, 0); 136 | 137 | printf("Device opened\n"); 138 | 139 | outfile = fopen("debuglog.txt", "w+"); 140 | if (!outfile) { 141 | fprintf(stderr, "fopen: debuglog.txt: %s", strerror(errno)); 142 | goto out; 143 | } 144 | 145 | if (terminal_loop(hndl, outfile) == -1) 146 | goto restart; 147 | 148 | out: 149 | if (outfile) 150 | fclose(outfile); 151 | libusb_close(hndl); 152 | return 0; 153 | } 154 | -------------------------------------------------------------------------------- /examples/debugdevice_full_duplex/test.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | int main(int argc __attribute__((unused)), 24 | char **argv __attribute__((unused))) 25 | { 26 | int transferred, rv, i, hdlidx; 27 | libusb_context* ctx; 28 | unsigned char buf[256]; 29 | libusb_device_handle *hndl[2]; 30 | ssize_t devcount; 31 | struct libusb_device_descriptor desc; 32 | 33 | libusb_device **devlist; 34 | libusb_init(&ctx); 35 | 36 | devcount = libusb_get_device_list(ctx, &devlist); 37 | 38 | for(i = 0, hdlidx = 0; i < devcount && hdlidx < 2; i++) { 39 | if (libusb_get_device_descriptor(devlist[i], &desc) != 0) 40 | continue; 41 | 42 | if (desc.idVendor == 0x04b4 && desc.idProduct == 0x8613) { 43 | if (!(libusb_open(devlist[i], &hndl[hdlidx]))) { 44 | printf("opened device %d\n", hdlidx); 45 | hdlidx++; 46 | } 47 | } 48 | 49 | } 50 | 51 | if (hdlidx != 2) { 52 | fprintf(stderr, "Need two devices, have %d\n", hdlidx); 53 | return 1; 54 | } 55 | 56 | libusb_claim_interface(hndl[0],0); 57 | libusb_claim_interface(hndl[1],0); 58 | 59 | libusb_set_interface_alt_setting(hndl[0], 0, 0); 60 | libusb_set_interface_alt_setting(hndl[1], 0, 0); 61 | 62 | for (i = 0; i < (int)sizeof(buf); i++) 63 | buf[i] = i; 64 | 65 | printf("OUT transfer to device 0, PIPE 2\n"); 66 | rv = libusb_bulk_transfer(hndl[0], 0x02, buf, sizeof(buf), &transferred, sizeof(buf)); 67 | 68 | if(rv) 69 | printf("OUT Transfer failed: %d\n", rv); 70 | 71 | printf("IN transfer to device 1, PIPE 6\n"); 72 | 73 | memset(buf, 0, sizeof(buf)); 74 | transferred = 0; 75 | 76 | rv=libusb_bulk_transfer(hndl[1], 0x86, (unsigned char*)buf ,sizeof(buf), &transferred, sizeof(buf)); 77 | if(rv) 78 | printf("IN Transfer failed: %d\n", rv); 79 | 80 | printf("received %d bytes:\n", transferred); 81 | 82 | for (i = 0; i < transferred; i++) 83 | printf ("%02x ", buf[i]); 84 | printf("\n"); 85 | 86 | printf("OUT transfer to device 1, PIPE 2\n"); 87 | rv = libusb_bulk_transfer(hndl[1], 0x02, buf, sizeof(buf), &transferred, sizeof(buf)); 88 | 89 | if(rv) 90 | printf("OUT Transfer failed: %d\n", rv); 91 | 92 | printf("IN transfer to device 0, PIPE 6\n"); 93 | 94 | memset(buf, 0, sizeof(buf)); 95 | transferred = 0; 96 | 97 | rv=libusb_bulk_transfer(hndl[0], 0x86, (unsigned char*)buf ,sizeof(buf), &transferred, sizeof(buf)); 98 | if(rv) 99 | printf("IN Transfer failed: %d\n", rv); 100 | 101 | printf("received %d bytes:\n", transferred); 102 | 103 | for (i = 0; i < transferred; i++) 104 | printf ("%02x ", buf[i]); 105 | printf("\n"); 106 | 107 | libusb_free_device_list(devlist, 1); 108 | libusb_close(hndl[0]); 109 | return 0; 110 | } 111 | -------------------------------------------------------------------------------- /examples/eeprom/Makefile: -------------------------------------------------------------------------------- 1 | DIRS= firmware 2 | 3 | .PHONY: dirs $(DIRS) clean 4 | 5 | dirs: $(DIRS) 6 | clean: $(DIRS) 7 | 8 | $(DIRS): 9 | $(MAKE) -C $@ $(MAKECMDGOALS) 10 | 11 | -------------------------------------------------------------------------------- /examples/eeprom/client.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2009 Ubixum, Inc. 2 | # 3 | # This library is free software; you can redistribute it and/or 4 | # 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | import sys 19 | from fx2load import * 20 | 21 | 22 | def get_eeprom(addr,length): 23 | assert f.isopen() 24 | 25 | prom_val = ''; 26 | while len(prom_val) 1024 and 1024 or length-len(prom_val) 29 | ret=f.do_usb_command ( buf, 30 | 0xc0, 31 | 0xb1, 32 | addr+len(prom_val),0,transfer_len ) 33 | if (ret>=0): 34 | prom_val += buf[:ret] 35 | else: 36 | raise Exception("eeprom read didn't work: %d" % ret ) 37 | return prom_val 38 | 39 | 40 | def hexchartoint(c): 41 | return int(c.encode('hex'),16) 42 | 43 | 44 | def fetch_eeprom(): 45 | """ 46 | See TRM 3.4.2, 3.4,3. 47 | This function dynamically determines how much data to read for c2 eeprom data and downloads 48 | the eeprom iic file. 49 | """ 50 | assert f.isopen() 51 | # fetch 1st 8 bytes 52 | prom=get_eeprom(0,8) 53 | if prom[0] == '\xc0': 54 | return prom # c0 blocks are 8 bytes long 55 | if prom[0] != '\xc2': raise Exception ( "Envalid eeprom (%s)" % prom[0].encode('hex') ) 56 | # the length of the 1st data block is bytes 8,9 (0 based) 57 | read_addr=8 58 | while True: 59 | size_read = get_eeprom(read_addr,4) # get the data length and start address 60 | prom += size_read 61 | read_addr+=4 62 | # if this is the end 0x80 0x01 0xe6 0x00, then break 63 | if size_read == '\x80\x01\xe6\x00': break 64 | # else it is a data block 65 | size = (hexchartoint(size_read[0]) << 8) + hexchartoint(size_read[1]) 66 | print "Next eeprom data size %d" % size 67 | prom += get_eeprom(read_addr,size) 68 | read_addr+=size 69 | # one last byte 70 | prom += get_eeprom(read_addr,1) # should always be 0 71 | assert prom[-1] == '\x00' 72 | return prom 73 | 74 | 75 | def set_eeprom(prom): 76 | assert f.isopen() 77 | bytes_written=0; 78 | while bytes_written 1024 and 1024 or len(prom)-bytes_written 81 | print "Writing %d Bytes.." % to_write 82 | ret=f.do_usb_command(prom[bytes_written:bytes_written+to_write], 0x40,0xb1,bytes_written, 0, to_write, 10000) 83 | if ret>0: 84 | bytes_written += ret; 85 | else: 86 | raise Exception ( "eeprom write didn't work: %d" % ret ) 87 | 88 | 89 | if __name__=='__main__': 90 | 91 | openfx2(0x04b4,0x0083) # vid/pid of eeprom firmware 92 | 93 | -------------------------------------------------------------------------------- /examples/eeprom/firmware/Makefile: -------------------------------------------------------------------------------- 1 | FX2LIBDIR=../../.. 2 | BASENAME = eeprom 3 | SOURCES=eeprom.c 4 | A51_SOURCES=dscr.a51 5 | 6 | include $(FX2LIBDIR)/lib/fx2.mk 7 | -------------------------------------------------------------------------------- /examples/eeprom/firmware/eeprom.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #define SYNCDELAY SYNCDELAY4; 33 | 34 | volatile __bit dosud; 35 | __bit on; 36 | WORD count; 37 | 38 | 39 | void main(void) { 40 | 41 | REVCTL = 0; // not using advanced endpoint controls 42 | 43 | dosud=FALSE; 44 | on=FALSE; 45 | 46 | REVCTL = 0x03; // DYN_OUT=1, ENH_PKT=1 47 | 48 | RENUMERATE_UNCOND(); 49 | 50 | 51 | SETCPUFREQ(CLK_48M); 52 | sio0_init(57600); // needed for printf on sio0 53 | 54 | 55 | USE_USB_INTS(); 56 | 57 | ENABLE_SUDAV(); 58 | ENABLE_USBRESET(); 59 | ENABLE_HISPEED(); 60 | 61 | EA=1; 62 | 63 | 64 | while(TRUE) { 65 | 66 | //printf ( "sud is %d\n" , dosud ); 67 | if (dosud) { 68 | handle_setupdata(); 69 | dosud=FALSE; 70 | } 71 | 72 | } 73 | 74 | 75 | } 76 | 77 | BOOL handle_get_descriptor(void) { 78 | return FALSE; 79 | } 80 | 81 | #define VC_EEPROM 0xb1 82 | 83 | BOOL handle_vendorcommand(BYTE cmd) { 84 | WORD addr=SETUP_VALUE(),len=SETUP_LENGTH(); 85 | printf ( "Handle Vendor Command %02x, addr %d, len %d\n" , cmd, addr, len ); 86 | switch (cmd) { 87 | case VC_EEPROM: 88 | { 89 | // wait for ep0 not busy 90 | switch (SETUP_TYPE) { 91 | case 0xc0: 92 | while (len) { // still have bytes to read 93 | BYTE cur_read = len > 64 ? 64 : len; // can't read more than 64 bytes at a time 94 | while (EP0CS&bmEPBUSY); // can't do this until EP0 is ready 95 | eeprom_read(0x51, addr, cur_read, EP0BUF ); 96 | EP0BCH=0; 97 | SYNCDELAY; 98 | EP0BCL=cur_read; 99 | len -= cur_read; 100 | addr += cur_read; 101 | } 102 | break; 103 | case 0x40: 104 | while (len) { 105 | BYTE cur_write, c; 106 | // printf ( "Len More Bytes %d\n" , len ); 107 | EP0BCL = 0; // allow pc transfer in 108 | while(EP0CS & bmEPBUSY); // wait 109 | cur_write=EP0BCL; 110 | // printf ( "Writing %d Bytes to %d..\n", cur_write, addr ); 111 | if ( !eeprom_write(0x51, addr, cur_write, EP0BUF ) ) return FALSE; 112 | addr += cur_write; 113 | len -= cur_write; 114 | } 115 | break; 116 | default: 117 | return FALSE; // bad type 118 | } 119 | 120 | printf ( "All OK\n" ); 121 | return TRUE; 122 | } 123 | } 124 | return FALSE; 125 | } 126 | 127 | 128 | // set *alt_ifc to the current alt interface for ifc 129 | BOOL handle_get_interface(BYTE ifc, BYTE* alt_ifc) { 130 | *alt_ifc=0; 131 | return TRUE; 132 | } 133 | // return TRUE if you set the interface requested 134 | // NOTE this function should reconfigure and reset the endpoints 135 | // according to the interface descriptors you provided. 136 | BOOL handle_set_interface(BYTE ifc,BYTE alt_ifc) { 137 | //return ifc==0&&alt_ifc==0; 138 | printf ( "Host wants to set interface: %d\n", alt_ifc ); 139 | 140 | return TRUE; 141 | } 142 | // handle getting and setting the configuration 143 | // 0 is the default. If you support more than one config 144 | // keep track of the config number and return the correct number 145 | // config numbers are set int the dscr file. 146 | volatile BYTE config=1; 147 | BYTE handle_get_configuration(void) { 148 | return config; 149 | } 150 | // return TRUE if you handle this request 151 | // NOTE changing config requires the device to reset all the endpoints 152 | BOOL handle_set_configuration(BYTE cfg) { 153 | printf ( "host wants config: %d\n" , cfg ); 154 | config=cfg; 155 | return TRUE; 156 | } 157 | 158 | 159 | void sudav_isr(void) __interrupt (SUDAV_ISR) { 160 | dosud=TRUE; 161 | CLEAR_SUDAV(); 162 | } 163 | 164 | void usbreset_isr(void) __interrupt (USBRESET_ISR) { 165 | handle_hispeed(FALSE); 166 | CLEAR_USBRESET(); 167 | } 168 | void hispeed_isr(void) __interrupt (HISPEED_ISR) { 169 | handle_hispeed(TRUE); 170 | CLEAR_HISPEED(); 171 | } 172 | 173 | -------------------------------------------------------------------------------- /examples/fx2/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *.pyc 3 | -------------------------------------------------------------------------------- /examples/fx2/cpp/.gitignore: -------------------------------------------------------------------------------- 1 | fx2.py 2 | fx2_wrap.cpp 3 | -------------------------------------------------------------------------------- /examples/fx2/cpp/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djmuhlestein/fx2lib/caa3e156cb636b3d525047ed48bdf5f6deb8e56b/examples/fx2/cpp/__init__.py -------------------------------------------------------------------------------- /examples/fx2/cpp/fx2.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | #include 21 | 22 | #include "fx2.h" 23 | 24 | 25 | fx2::fx2():dev_handle(NULL) { 26 | 27 | int rv=libusb_init(&libusb_ctx); 28 | assert(!rv); 29 | libusb_set_debug(libusb_ctx,0); 30 | } 31 | 32 | void fx2::set_debug_level(int n) { 33 | libusb_set_debug(libusb_ctx,n); 34 | } 35 | 36 | fx2::~fx2() { 37 | 38 | if (isopen()) close(); 39 | 40 | libusb_exit(libusb_ctx); 41 | } 42 | 43 | #define CHECK_OPEN(r) if (!dev_handle) {\ 44 | printf ( "Device not opened.\n" ); \ 45 | return r;\ 46 | } 47 | 48 | 49 | void fx2::open(int vid,int pid,int idx) { 50 | 51 | libusb_device **list; 52 | int devices = libusb_get_device_list( libusb_ctx, &list ); 53 | int cur_idx=0; 54 | for ( int i=0;iinterface=iface; 93 | } 94 | int rv=libusb_set_interface_alt_setting(dev_handle,interface,alt); 95 | assert(!rv); 96 | alt_setting=alt; 97 | } 98 | void fx2::close() { 99 | CHECK_OPEN() 100 | libusb_release_interface(dev_handle,interface); 101 | libusb_close(dev_handle); 102 | dev_handle=NULL; 103 | interface=0;alt_setting=0; 104 | } 105 | 106 | 107 | int fx2::do_usb_command(char* buf, int size, unsigned char type, unsigned char request, unsigned short value, unsigned short index, unsigned short length, int timeout ) { 108 | CHECK_OPEN(-1) 109 | return libusb_control_transfer ( 110 | dev_handle, 111 | type, 112 | request, 113 | value, 114 | index, 115 | (unsigned char*)buf, 116 | length, 117 | timeout); 118 | } 119 | 120 | int fx2::clear_halt(char ep) { 121 | CHECK_OPEN(-1) 122 | return libusb_clear_halt(dev_handle,(unsigned char)ep); 123 | } 124 | 125 | int fx2::reset() { 126 | CHECK_OPEN(-1) 127 | int rv=libusb_reset_device(dev_handle); 128 | if (rv==LIBUSB_ERROR_NO_DEVICE) { 129 | printf ( "Device Changed. Closing\n"); 130 | libusb_close(dev_handle); 131 | interface=0;alt_setting=0; 132 | } 133 | return rv; 134 | } 135 | 136 | int fx2::set_configuration(int configuration) { 137 | CHECK_OPEN(-1) 138 | libusb_release_interface(dev_handle,interface); 139 | int rv=libusb_set_configuration(dev_handle,configuration); 140 | if (!rv) { 141 | libusb_claim_interface(dev_handle,interface); 142 | } 143 | } 144 | 145 | 146 | bool fx2::ep_bulk(char* buf, int size, unsigned char ep, int timeout) { 147 | CHECK_OPEN(-1) 148 | int transferred; 149 | int rv=libusb_bulk_transfer ( dev_handle, ep, (unsigned char*)buf, size, &transferred, timeout ); 150 | 151 | if (!rv) return true; 152 | 153 | if (rv==LIBUSB_ERROR_TIMEOUT) { 154 | printf ( "Transfer Timeout. %d bytes transferred.\n", transferred ); 155 | } else if (rv<0) { 156 | printf ( "Transfer Error: %d\n", rv ); 157 | } 158 | 159 | return false; 160 | 161 | } 162 | -------------------------------------------------------------------------------- /examples/fx2/cpp/fx2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #ifndef FX2_H 20 | #define FX2_H 21 | 22 | #include 23 | 24 | const int VID=0x04b4; 25 | const int PID=0x0082; 26 | 27 | class fx2 { 28 | 29 | private: 30 | libusb_context* libusb_ctx; 31 | libusb_device_handle* dev_handle; 32 | int interface,alt_setting; 33 | 34 | public: 35 | fx2(); 36 | ~fx2(); 37 | /** 38 | * open 39 | * vid = vendor id 40 | * pid = product id 41 | * idx = nth device if there are more than one. 42 | * 43 | * Opens device with vid,pid and claims alt 0 of interface 0 44 | **/ 45 | void open(int vid=VID,int pid=PID, int idx=0); 46 | void set_interface(int interface, int alt_setting); 47 | bool isopen() { return dev_handle != NULL; } 48 | void close(); 49 | /** 50 | * level n = 0-3 51 | */ 52 | void set_debug_level(int n); 53 | int do_usb_command(char* buf, int size, unsigned char type, unsigned char request, unsigned short value, unsigned short index, unsigned short length, int timeout=1000 ); 54 | int clear_halt(char ep); 55 | int reset(); 56 | int set_configuration(int config); 57 | bool ep_bulk(char* buf, int size, unsigned char ep, int timeout); 58 | 59 | }; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /examples/fx2/cpp/fx2.i: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | /* interface file for python/swig */ 20 | 21 | %module fx2 22 | //%include "typemaps.i" 23 | %include "cdata.i" 24 | %apply (char* STRING, int LENGTH) { (char* buf, int size) } 25 | 26 | %{ 27 | #include "fx2.h" 28 | %} 29 | 30 | %include "fx2.h" 31 | -------------------------------------------------------------------------------- /examples/fx2/fx2load/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2009 Ubixum, Inc. 2 | # 3 | # This library is free software; you can redistribute it and/or 4 | # 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | from time import sleep 19 | from fx2 import fx2 20 | 21 | f=fx2.fx2() 22 | 23 | # use this functions 1st 24 | 25 | def openfx2(vid=0x04b4,pid=0x0082,idx=0): 26 | f.open(vid,pid,idx) 27 | 28 | def reset_device(reset): 29 | print reset and "Put device in reset" or "Set device to run" 30 | write_ram (0xe600,reset and '\x01' or '\x00', 1) 31 | 32 | def write_ram(addr,data,length): 33 | transferred=0 34 | while(transferred1024 and 1024 or length-transferred 36 | buf=data[transferred:] 37 | ret=f.do_usb_command( buf, 38 | 0x40, 39 | 0xa0, 40 | addr+transferred, 0, 41 | this_transfer_size ) 42 | if (ret>0): 43 | print "wrote %d bytes" % ret 44 | transferred+=ret 45 | else: 46 | print "Error: %d" % ret 47 | return 48 | 49 | def reset_bix(filename): 50 | """ 51 | Use this function to reset your firmware. You'll need to reopen the device afterward. 52 | """ 53 | reset_device(True) 54 | bix=open(filename).read() 55 | print "loading bix file of length: %d" % len(bix) 56 | write_ram( 0, bix,len(bix) ); 57 | reset_device(False) 58 | f.close() 59 | 60 | -------------------------------------------------------------------------------- /examples/fx2/scripts/fx2load: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | 3 | # Copyright (C) 2009 Ubixum, Inc. 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # 7 | # modify it under the terms of the GNU Lesser General Public 8 | # License as published by the Free Software Foundation; either 9 | # version 2.1 of the License, or (at your option) any later version. 10 | # 11 | # This library is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this library; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | 21 | import optparse 22 | 23 | parser=optparse.OptionParser (usage="Usage: %prog [options] bixfile") 24 | parser.add_option( "-v", "--vid", type='int', default=0x04b4,help='Vendor ID (0x04b4)') 25 | parser.add_option( "-p", '--pid', type='int', default=0x0082,help='Product Id (0x0082)') 26 | 27 | opts,args=parser.parse_args() 28 | 29 | if len(args) < 1: 30 | parser.error("Specify the path to your firmware bix file as the first argument") 31 | 32 | from fx2load import * 33 | openfx2(opts.vid,opts.pid) 34 | reset_bix(args[0]) 35 | -------------------------------------------------------------------------------- /examples/fx2/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup, Extension 2 | 3 | fx2_mod = Extension ( 4 | '_fx2', 5 | sources=['cpp/fx2.cpp', 'cpp/fx2.i'], 6 | swig_opts=['-c++'], 7 | include_dirs = ['/usr/include/python2.5'], 8 | libraries = ['usb-1.0'] 9 | ) 10 | 11 | 12 | setup( 13 | name='fx2', 14 | version='0.2', 15 | ext_modules=[fx2_mod], 16 | scripts=['scripts/fx2load'], 17 | packages=['fx2load','fx2'], 18 | package_dir={'fx2':'cpp'} 19 | ) 20 | -------------------------------------------------------------------------------- /examples/i2c/Makefile: -------------------------------------------------------------------------------- 1 | FX2LIBDIR=../.. 2 | BASENAME = i2c 3 | SOURCES=i2c.c 4 | DSCR_AREA= 5 | INT2JT= 6 | include $(FX2LIBDIR)/lib/fx2.mk 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/i2c/i2c.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | 20 | 21 | #include 22 | 23 | #include 24 | 25 | #define LED_ADDR 0x21 26 | #define BTN_ADDR 0x20 27 | 28 | #define KEY_F1 0 29 | #define KEY_F2 1 30 | #define KEY_F3 2 31 | #define KEY_F4 3 32 | 33 | 34 | BYTE digits[] = { 0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x98, 0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e }; 35 | 36 | 37 | /** 38 | * This is pretty much the same function that is provided as the dev_io example from Cypress 39 | * Except is uses i2c read and write functions not from their library 40 | **/ 41 | void main(void) { 42 | 43 | BYTE num = 0; 44 | //BYTE xdata buttons; 45 | BYTE buttons; 46 | BYTE kstates = 0xff; 47 | BYTE kdeltas; 48 | BYTE key; 49 | BYTE display = 1; 50 | 51 | while(1) 52 | { 53 | i2c_read ( BTN_ADDR, 1, &buttons ); 54 | 55 | kdeltas = kstates ^ buttons; // 56 | kstates = buttons; 57 | key = 0; 58 | 59 | while(kdeltas) 60 | { 61 | if(kdeltas & 0x01) 62 | { 63 | if(!((kstates >> key) & 0x01)) 64 | switch(key) 65 | { 66 | case KEY_F1: // wakeup? 67 | num = 0; 68 | break; 69 | case KEY_F2: 70 | if(--num > 0x0f) 71 | num = 0x0f; 72 | break; 73 | case KEY_F3: 74 | if(++num > 0x0f) 75 | num = 0; 76 | break; 77 | case KEY_F4: 78 | num = 0x0f; 79 | } 80 | display = 1; 81 | } 82 | kdeltas = kdeltas >> 1; 83 | ++key; 84 | } 85 | if(display) 86 | { 87 | i2c_write ( LED_ADDR, 1, &digits[num], 0, NULL ); 88 | display = 0; 89 | } 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /examples/i2c/load.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2009 Ubixum, Inc. 2 | # 3 | # This library is free software; you can redistribute it and/or 4 | # 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USAimport struct 17 | from fx2load import * 18 | 19 | openfx2() 20 | reset_bix('i2c.bix') 21 | -------------------------------------------------------------------------------- /examples/lights/.gitignore: -------------------------------------------------------------------------------- 1 | lights 2 | -------------------------------------------------------------------------------- /examples/lights/Makefile: -------------------------------------------------------------------------------- 1 | FX2LIBDIR=../.. 2 | BASENAME = lights 3 | SOURCES=lights.c 4 | DSCR_AREA= 5 | INT2JT= 6 | include $(FX2LIBDIR)/lib/fx2.mk 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/lights/lights.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | volatile __xdata BYTE* bytes[] = { &D2ON, &D3ON, &D4ON, &D5ON, &D2OFF, &D3OFF, &D4OFF, &D5OFF }; 25 | 26 | void main(void) 27 | { 28 | volatile BYTE tmp; 29 | BYTE cur=0; 30 | 31 | // loop endlessly 32 | for(;;) { 33 | tmp=*bytes[cur]; 34 | delay(50); 35 | cur = cur == 7 ? 0 : cur+1; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /examples/reset/Makefile: -------------------------------------------------------------------------------- 1 | FX2LIBDIR=../.. 2 | BASENAME = reset 3 | SOURCES=reset.c fx2_c0.c 4 | DSCR_AREA= 5 | INT2JT= 6 | include $(FX2LIBDIR)/lib/fx2.mk 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/reset/fx2_c0.c: -------------------------------------------------------------------------------- 1 | __xdata unsigned char fx2_c0[] = { 2 | 0xc0, 0xb4, 0x04, 0x82, 3 | 0x00, 0x00, 0x00, 0x00 4 | }; 5 | -------------------------------------------------------------------------------- /examples/reset/reset.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #define LG_PROM 0x51 // large prom ( is 16 bit addr mode) 30 | 31 | #define READ_SIZE 100 32 | 33 | __xdata BYTE buf[READ_SIZE]; 34 | 35 | #define IIC_SIZE 8 36 | extern __xdata BYTE fx2_c0[]; 37 | 38 | /* 39 | Modified eeprom_write that always uses two byte buffer. 40 | So can write to LG_PROM w/ out recompiling lib. 41 | (The library dynamically detects the prom based on the startup state. 42 | On the dev board, you can switch the prom with EEPROM select while 43 | the firmware is running.) 44 | */ 45 | void eeprom_write_local(BYTE prom_addr, WORD addr, WORD length, BYTE* buf) { 46 | BYTE addr_len=0; 47 | // 1st bytes of buffer are address and next byte is value 48 | BYTE data_buffer[3]; 49 | BYTE cur_byte=0; 50 | 51 | while ( cur_byte 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | 27 | 28 | volatile BYTE ctr=0; 29 | BYTE ctr_repeat=200; 30 | volatile BOOL on=FALSE; 31 | 32 | 33 | void timer1_isr(void) __interrupt (3) __critical { 34 | 35 | if (ctr == 0) { // timer overflowed ctr_repeat times 36 | if (on) { 37 | d2on(); 38 | } else { 39 | d2off(); 40 | } 41 | on = !on; 42 | } 43 | 44 | ctr = ctr >= ctr_repeat ? 0 : ctr + 1; 45 | 46 | } 47 | 48 | 49 | 50 | void main(void) 51 | { 52 | 53 | SETCPUFREQ(CLK_48M); 54 | 55 | // if this image is loaded to as iic to 56 | // the eeprom 57 | // the C2 bit will turn this on 58 | // turn it back off so the device can 59 | // handle usb requests 60 | USBCS &= ~bmRENUM; 61 | 62 | EA=1; // enable interrupts 63 | 64 | sio0_init(57600); 65 | 66 | // timer 0 setup 67 | 68 | TL1=TH1=0; // start at 0 69 | ET1=1; // timer 1 interrupts 70 | TR1=1; // start timer 1 71 | 72 | 73 | d5off(); // end init 74 | 75 | while (1) { 76 | char r=getchar(); 77 | putchar(r); 78 | } 79 | 80 | 81 | } 82 | -------------------------------------------------------------------------------- /examples/timers/.gitignore: -------------------------------------------------------------------------------- 1 | timers 2 | -------------------------------------------------------------------------------- /examples/timers/Makefile: -------------------------------------------------------------------------------- 1 | FX2LIBDIR=../.. 2 | BASENAME = timers 3 | SOURCES=timers.c 4 | DSCR_AREA= 5 | INT2JT= 6 | include $(FX2LIBDIR)/lib/fx2.mk 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/timers/timers.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | volatile __bit d2; 25 | volatile __bit d3; 26 | volatile __bit d4; 27 | volatile __bit d5; 28 | 29 | void timer0_isr(void) __interrupt (TF0_ISR) { 30 | d2 = !d2; 31 | if (d2) { d2on(); } else { d2off(); } 32 | } 33 | 34 | void timer1_isr(void) __interrupt (TF1_ISR) { 35 | d3 = !d3; 36 | if (d3) { d3on(); } else { d3off(); } 37 | } 38 | 39 | void timer2_isr(void) __interrupt (TF2_ISR) { 40 | d4 = !d4; 41 | if (d4) { d4on(); } else { d4off(); } 42 | 43 | CLEAR_TIMER2(); // This one is not done automatically! 44 | } 45 | 46 | 47 | void main(void) 48 | { 49 | WORD counter=0; 50 | 51 | SETCPUFREQ(CLK_12M); 52 | 53 | // enable timer 0 and timer 1 to be 16 bit counters 54 | TMOD = 0x11; 55 | 56 | // enable timer 2 to also be a 16 bit counter 57 | T2CON = 0; 58 | RCAP2L = 0; // reload values for t2 59 | RCAP2H = 0; 60 | 61 | EA=1; // enable interrupts 62 | ENABLE_TIMER0(); 63 | ENABLE_TIMER1(); 64 | ENABLE_TIMER2(); 65 | TR0=1; // start t0 66 | TR1=1; // start t1 67 | TR2=1; // start t2 68 | 69 | // and blink d5 70 | while (TRUE) { 71 | ++counter; 72 | if (!counter) { 73 | d5 = !d5; 74 | if (d5) { d5off(); } else { d5on(); } 75 | } 76 | } 77 | } 78 | 79 | 80 | -------------------------------------------------------------------------------- /examples/usbmon_c/Makefile: -------------------------------------------------------------------------------- 1 | FX2LIBDIR=../../ 2 | BASENAME = usbmon 3 | SOURCES=usbmon.c 4 | A51_SOURCES=dscr.a51 5 | PID=0x1004 6 | 7 | HOSTCC=gcc 8 | CFLAGS=-Wall -Wextra -Os -lusb-1.0 9 | 10 | include $(FX2LIBDIR)lib/fx2.mk 11 | 12 | download: build/$(BASENAME).ihx 13 | ./download.sh $< 14 | 15 | clean: 16 | rm -rf build 17 | 18 | test: test.c 19 | $(HOSTCC) $(CFLAGS) -o $@ $< -------------------------------------------------------------------------------- /examples/usbmon_c/download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | DEVS=$(lsusb|grep 04b4:8613|sed 's/:.*//;s/Bus //;s/Device //;s/ /\//') 4 | 5 | if [ -z "$1" ]; then 6 | echo "$0: usage: $0 " 7 | exit 1; 8 | fi 9 | 10 | for dev in $DEVS;do 11 | echo "Downloading $1 to $dev" 12 | sudo /sbin/fxload -D /dev/bus/usb/$dev -t fx2lp -I $1 13 | done 14 | 15 | exit 0 16 | -------------------------------------------------------------------------------- /examples/usbmon_c/dscr.a51: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2009 Ubixum, Inc. 2 | ; 3 | ; This library is free software; you can redistribute it and/or 4 | ; modify it under the terms of the GNU Lesser General Public 5 | ; License as published by the Free Software Foundation; either 6 | ; version 2.1 of the License, or (at your option) any later version. 7 | ; 8 | ; This library is distributed in the hope that it will be useful, 9 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | ; Lesser General Public License for more details. 12 | ; 13 | ; You should have received a copy of the GNU Lesser General Public 14 | ; License along with this library; if not, write to the Free Software 15 | ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | ; this is a the default 18 | ; full speed and high speed 19 | ; descriptors found in the TRM 20 | ; change however you want but leave 21 | ; the descriptor pointers so the setupdat.c file works right 22 | 23 | 24 | .module DEV_DSCR 25 | 26 | ; descriptor types 27 | ; same as setupdat.h 28 | DSCR_DEVICE_TYPE=1 29 | DSCR_CONFIG_TYPE=2 30 | DSCR_STRING_TYPE=3 31 | DSCR_INTERFACE_TYPE=4 32 | DSCR_ENDPOINT_TYPE=5 33 | DSCR_DEVQUAL_TYPE=6 34 | 35 | ; for the repeating interfaces 36 | DSCR_INTERFACE_LEN=9 37 | DSCR_ENDPOINT_LEN=7 38 | 39 | ; endpoint types 40 | ENDPOINT_TYPE_CONTROL=0 41 | ENDPOINT_TYPE_ISO=1 42 | ENDPOINT_TYPE_BULK=2 43 | ENDPOINT_TYPE_INT=3 44 | 45 | .globl _dev_dscr, _dev_qual_dscr, _highspd_dscr, _fullspd_dscr, _debug_dscr, _dev_strings, _dev_strings_end 46 | ; These need to be in code memory. If 47 | ; they aren't you'll have to manully copy them somewhere 48 | ; in code memory otherwise SUDPTRH:L don't work right 49 | .area DSCR_AREA (CODE) 50 | 51 | _dev_dscr: 52 | .db dev_dscr_end-_dev_dscr ; len 53 | .db DSCR_DEVICE_TYPE ; type 54 | .dw 0x0002 ; usb 2.0 55 | .db 0xff ; class (vendor specific) 56 | .db 0 ; subclass (vendor specific) 57 | .db 0 ; protocol (vendor specific) 58 | .db 64 ; packet size (ep0) 59 | .dw 0xb404 ; vendor id 60 | .dw 0x1386 ; product id 61 | .dw 0x0100 ; version id 62 | .db 1 ; manufacturure str idx 63 | .db 2 ; product str idx 64 | .db 0 ; serial str idx 65 | .db 1 ; n configurations 66 | dev_dscr_end: 67 | 68 | _dev_qual_dscr: 69 | .db dev_qualdscr_end-_dev_qual_dscr 70 | .db DSCR_DEVQUAL_TYPE 71 | .dw 0x0002 ; usb 2.0 72 | .db 0xff 73 | .db 0x00 74 | .db 0x0 75 | .db 64 ; max packet 76 | .db 1 ; n configs 77 | .db 0 ; extra reserved byte 78 | dev_qualdscr_end: 79 | 80 | _debug_dscr: 81 | .db _debug_dscr_end - _debug_dscr 82 | .db 10 83 | .db 0x86 84 | .db 0x02 85 | _debug_dscr_end: 86 | 87 | 88 | _highspd_dscr: 89 | .db highspd_dscr_end-_highspd_dscr ; dscr len ;; Descriptor length 90 | .db DSCR_CONFIG_TYPE 91 | ; can't use .dw because byte order is different 92 | .db (highspd_dscr_realend-_highspd_dscr) % 256 ; total length of config lsb 93 | .db (highspd_dscr_realend-_highspd_dscr) / 256 ; total length of config msb 94 | .db 1 ; n interfaces 95 | .db 1 ; config number 96 | .db 0 ; config string 97 | .db 0x80 ; attrs = bus powered, no wakeup 98 | .db 0x32 ; max power = 100ma 99 | highspd_dscr_end: 100 | 101 | ; all the interfaces next 102 | ; NOTE the default TRM actually has more alt interfaces 103 | ; but you can add them back in if you need them. 104 | ; here, we just use the default alt setting 1 from the trm 105 | .db DSCR_INTERFACE_LEN 106 | .db DSCR_INTERFACE_TYPE 107 | .db 0 ; index 108 | .db 0 ; alt setting idx 109 | .db 2 ; n endpoints 110 | .db 0xff ; class 111 | .db 0 112 | .db 0 113 | .db 3 ; string index 114 | 115 | ; endpoint 2 out 116 | .db DSCR_ENDPOINT_LEN 117 | .db DSCR_ENDPOINT_TYPE 118 | .db 0x02 ; ep2 dir=OUT and address 119 | .db ENDPOINT_TYPE_BULK ; type 120 | .db 0x00 ; max packet LSB 121 | .db 0x02 ; max packet size=512 bytes 122 | .db 0x00 ; polling interval 123 | 124 | ; endpoint 6 in 125 | .db DSCR_ENDPOINT_LEN 126 | .db DSCR_ENDPOINT_TYPE 127 | .db 0x86 ; ep6 dir=in and address 128 | .db ENDPOINT_TYPE_BULK ; type 129 | .db 0x00 ; max packet LSB 130 | .db 0x02 ; max packet size=512 bytes 131 | .db 0x00 ; polling interval 132 | 133 | highspd_dscr_realend: 134 | 135 | .even 136 | _fullspd_dscr: 137 | .db fullspd_dscr_end-_fullspd_dscr ; dscr len 138 | .db DSCR_CONFIG_TYPE 139 | ; can't use .dw because byte order is different 140 | .db (fullspd_dscr_realend-_fullspd_dscr) % 256 ; total length of config lsb 141 | .db (fullspd_dscr_realend-_fullspd_dscr) / 256 ; total length of config msb 142 | .db 1 ; n interfaces 143 | .db 1 ; config number 144 | .db 0 ; config string 145 | .db 0x80 ; attrs = bus powered, no wakeup 146 | .db 0x32 ; max power = 100ma 147 | fullspd_dscr_end: 148 | 149 | ; all the interfaces next 150 | ; NOTE the default TRM actually has more alt interfaces 151 | ; but you can add them back in if you need them. 152 | ; here, we just use the default alt setting 1 from the trm 153 | .db DSCR_INTERFACE_LEN 154 | .db DSCR_INTERFACE_TYPE 155 | .db 0 ; index 156 | .db 0 ; alt setting idx 157 | .db 2 ; n endpoints 158 | .db 0xff ; class 159 | .db 0xff 160 | .db 0xff 161 | .db 3 ; string index 162 | 163 | ; endpoint 2 out 164 | .db DSCR_ENDPOINT_LEN 165 | .db DSCR_ENDPOINT_TYPE 166 | .db 0x02 ; ep2 dir=OUT and address 167 | .db ENDPOINT_TYPE_BULK ; type 168 | .db 0x40 ; max packet LSB 169 | .db 0x00 ; max packet size=64 bytes 170 | .db 0x00 ; polling interval 171 | 172 | ; endpoint 6 in 173 | .db DSCR_ENDPOINT_LEN 174 | .db DSCR_ENDPOINT_TYPE 175 | .db 0x86 ; ep6 dir=in and address 176 | .db ENDPOINT_TYPE_BULK ; type 177 | .db 0x40 ; max packet LSB 178 | .db 0x00 ; max packet size=64 bytes 179 | .db 0x00 ; polling interval 180 | 181 | fullspd_dscr_realend: 182 | 183 | .even 184 | _dev_strings: 185 | ; sample string 186 | _string0: 187 | .db string0end-_string0 ; len 188 | .db DSCR_STRING_TYPE 189 | .db 0x09, 0x04 ; who knows 190 | string0end: 191 | ; add more strings here 192 | 193 | _string1: 194 | .db string1end-_string1 195 | .db DSCR_STRING_TYPE 196 | .ascii 'I' 197 | .db 0 198 | .ascii 'O' 199 | .db 0 200 | .ascii 'D' 201 | .db 0 202 | .ascii 'e' 203 | .db 0 204 | .ascii 'v' 205 | .db 0 206 | string1end: 207 | 208 | _string2: 209 | .db string2end-_string2 210 | .db DSCR_STRING_TYPE 211 | .ascii 'U' 212 | .db 0 213 | .ascii 'S' 214 | .db 0 215 | .ascii 'B' 216 | .db 0 217 | .ascii 'M' 218 | .db 0 219 | .ascii 'O' 220 | .db 0 221 | .ascii 'N' 222 | .db 0 223 | string2end: 224 | 225 | _string3: 226 | .db string3end-_string3 227 | .db DSCR_STRING_TYPE 228 | .ascii 'i' 229 | .db 0 230 | .ascii 'F' 231 | .db 0 232 | .ascii 'a' 233 | .db 0 234 | .ascii 'c' 235 | .db 0 236 | .ascii 'e' 237 | .db 0 238 | string3end: 239 | 240 | _dev_strings_end: 241 | .dw 0x0000 ; just in case someone passes an index higher than the end to the firmware 242 | -------------------------------------------------------------------------------- /examples/usbmon_c/test.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | 26 | int main(int argc __attribute__((unused)), 27 | char **argv __attribute__((unused))) 28 | { 29 | int transferred, rv, i, ret = 1;; 30 | libusb_device_handle *hndl; 31 | libusb_context *ctx; 32 | unsigned char buf[512]; 33 | 34 | 35 | libusb_init(&ctx); 36 | 37 | hndl = libusb_open_device_with_vid_pid(ctx, 0x4b4, 0x8613); 38 | 39 | if (!hndl) { 40 | fprintf(stderr, "failed to open device\n"); 41 | goto out; 42 | } 43 | 44 | libusb_claim_interface(hndl, 0); 45 | 46 | libusb_set_interface_alt_setting(hndl, 0, 0); 47 | 48 | for(;;) { 49 | for (i = 0; i < (int)sizeof(buf); i++) 50 | buf[i] = i; 51 | 52 | printf("OUT transfer to device\n"); 53 | transferred = 0; 54 | rv = libusb_bulk_transfer(hndl, 0x02, bufl, 32, &transferred, 500); 55 | if(rv) { 56 | fprintf(stderr, "OUT Transfer failed: %d (%d transferred)\n", rv, transferred); 57 | // goto out; 58 | } 59 | 60 | rv = libusb_bulk_transfer(hndl, 0x02, buf, 0, &transferred, 500); 61 | if(rv) { 62 | fprintf(stderr, "OUT0 Transfer failed: %d (%d transferred)\n", rv, transferred); 63 | // goto out; 64 | } 65 | 66 | printf("IN transfer to device\n"); 67 | 68 | memset(buf, 0, sizeof(buf)); 69 | transferred = 0; 70 | 71 | rv=libusb_bulk_transfer(hndl, 0x86, (unsigned char*)buf ,sizeof(buf), &transferred, 500); 72 | if(rv) { 73 | fprintf(stderr, "IN Transfer failed: %d (%d transferred)\n", rv, transferred); 74 | // goto out; 75 | } else { 76 | printf("received %d bytes:\n", transferred); 77 | 78 | for (i = 0; i < transferred; i++) 79 | printf ("%02x ", buf[i]); 80 | printf("\n"); 81 | } 82 | sleep(1); 83 | } 84 | ret = 0; 85 | out: 86 | libusb_close(hndl); 87 | return ret; 88 | } 89 | -------------------------------------------------------------------------------- /examples/usbmon_c/usbmon.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #define SYNCDELAY() SYNCDELAY4 30 | 31 | volatile __bit got_sud; 32 | 33 | static void setup_usb(void) 34 | { 35 | USE_USB_INTS(); 36 | ENABLE_SUDAV(); 37 | ENABLE_SOF(); 38 | ENABLE_HISPEED(); 39 | ENABLE_USBRESET(); 40 | 41 | CPUCS = 0x12; 42 | REVCTL = bmBIT0 | bmBIT1; 43 | 44 | IFCONFIG = 0xe3; 45 | SYNCDELAY(); 46 | 47 | PINFLAGSAB = 0xe8; /* FLAGA = EP2EF, FLAGB = EP6FF */ 48 | SYNCDELAY(); 49 | 50 | PORTACFG |= 0x80; 51 | SYNCDELAY(); 52 | 53 | // only valid endpoints are 2/6 54 | EP1INCFG &= ~bmVALID; 55 | SYNCDELAY(); 56 | 57 | EP1OUTCFG &= ~bmVALID; 58 | SYNCDELAY(); 59 | 60 | EP2CFG = 0xa0; /* EP2 OUT, 4x buffer */ 61 | SYNCDELAY(); 62 | 63 | EP4CFG = 0x02; 64 | SYNCDELAY(); 65 | 66 | EP6CFG = 0xe0; /* EP6 IN, 4x buffer */ 67 | SYNCDELAY(); 68 | 69 | EP8CFG = 0x02; 70 | SYNCDELAY(); 71 | 72 | FIFORESET = 0x80; 73 | SYNCDELAY(); 74 | 75 | FIFORESET = 0x02; 76 | SYNCDELAY(); 77 | 78 | FIFORESET = 0x04; 79 | SYNCDELAY(); 80 | 81 | FIFORESET = 0x06; 82 | SYNCDELAY(); 83 | 84 | FIFORESET = 0x08; 85 | SYNCDELAY(); 86 | 87 | FIFORESET = 0x00; 88 | SYNCDELAY(); 89 | 90 | OUTPKTEND = 0x82; 91 | SYNCDELAY(); 92 | OUTPKTEND = 0x82; 93 | SYNCDELAY(); 94 | OUTPKTEND = 0x82; 95 | SYNCDELAY(); 96 | OUTPKTEND = 0x82; 97 | SYNCDELAY(); 98 | 99 | 100 | EP2FIFOCFG = 0; 101 | SYNCDELAY(); 102 | 103 | EP2FIFOCFG = bmAUTOOUT | bmWORDWIDE; 104 | SYNCDELAY(); 105 | 106 | EP6FIFOCFG = 0; 107 | SYNCDELAY(); 108 | 109 | EP6FIFOCFG = bmAUTOIN | bmWORDWIDE; 110 | SYNCDELAY(); 111 | 112 | EP6AUTOINLENH = 0x02; 113 | SYNCDELAY(); 114 | 115 | EP6AUTOINLENL = 0x00; 116 | SYNCDELAY(); 117 | 118 | } 119 | 120 | void main(void) 121 | { 122 | got_sud=FALSE; 123 | 124 | // renumerate 125 | RENUMERATE_UNCOND(); 126 | 127 | setup_usb(); 128 | 129 | EA=1; // global __interrupt enable 130 | 131 | while(TRUE) { 132 | if (got_sud) { 133 | handle_setupdata(); 134 | got_sud=FALSE; 135 | } 136 | } 137 | } 138 | 139 | // copied routines from setupdat.h 140 | 141 | // value (low byte) = ep 142 | #define VC_EPSTAT 0xB1 143 | 144 | 145 | BOOL handle_vendorcommand(BYTE cmd) 146 | { 147 | __xdata BYTE* pep; 148 | switch ( cmd ) { 149 | case 6: 150 | return TRUE; 151 | case VC_EPSTAT: 152 | 153 | pep = ep_addr(SETUPDAT[2]); 154 | if (pep) { 155 | EP0BUF[0] = *pep; 156 | EP0BCH=0; 157 | EP0BCL=1; 158 | return TRUE; 159 | } 160 | default: 161 | break; 162 | } 163 | return FALSE; 164 | } 165 | 166 | // this firmware only supports 0,0 167 | BOOL handle_get_interface(BYTE ifc, BYTE* alt_ifc) 168 | { 169 | if (ifc==0) { 170 | *alt_ifc=0; 171 | return TRUE; 172 | } else { 173 | return FALSE; 174 | } 175 | } 176 | BOOL handle_set_interface(BYTE ifc, BYTE alt_ifc) 177 | { 178 | RESETTOGGLE(0x02); 179 | RESETTOGGLE(0x86); 180 | OUTPKTEND=0x82; 181 | OUTPKTEND=0x82; 182 | OUTPKTEND=0x82; 183 | OUTPKTEND=0x82; 184 | return ifc == 0 && alt_ifc == 0; 185 | } 186 | 187 | // get/set configuration 188 | BYTE handle_get_configuration(void) 189 | { 190 | return 1; 191 | } 192 | 193 | BOOL handle_get_descriptor(BYTE desc) 194 | { 195 | (void)desc; 196 | return FALSE; 197 | } 198 | 199 | BOOL handle_set_configuration(BYTE cfg) 200 | { 201 | 202 | return cfg==1 ? TRUE : FALSE; // we only handle cfg 1 203 | } 204 | 205 | void sudav_isr(void) __interrupt (SUDAV_ISR) 206 | { 207 | 208 | got_sud=TRUE; 209 | CLEAR_SUDAV(); 210 | } 211 | 212 | void sof_isr(void) __interrupt (SOF_ISR) __using (1) 213 | { 214 | CLEAR_SOF(); 215 | } 216 | 217 | void usbreset_isr(void) __interrupt (USBRESET_ISR) 218 | { 219 | handle_hispeed(FALSE); 220 | CLEAR_USBRESET(); 221 | } 222 | void hispeed_isr(void) __interrupt (HISPEED_ISR) 223 | { 224 | handle_hispeed(TRUE); 225 | CLEAR_HISPEED(); 226 | } 227 | -------------------------------------------------------------------------------- /fw/.gitignore: -------------------------------------------------------------------------------- 1 | *.asm 2 | *.lst 3 | *.rel 4 | *.rst 5 | *.sym 6 | *.map 7 | *.mem 8 | *.bix 9 | *.iic 10 | -------------------------------------------------------------------------------- /fw/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2010 Ubixum, Inc. 2 | # 3 | # This library is free software; you can redistribute it and/or 4 | # modify it under the terms of the GNU Lesser General Public 5 | # License as published by the Free Software Foundation; either 6 | # version 2.1 of the License, or (at your option) any later version. 7 | # 8 | # This library is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | # Lesser General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Lesser General Public 14 | # License along with this library; if not, write to the Free Software 15 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | 18 | 19 | # change location of fx2libdir if needed 20 | SOURCES=fw.c device.c 21 | A51_SOURCES=dscr.a51 22 | BASENAME=firmware 23 | 24 | 25 | include ../lib/fx2.mk 26 | 27 | -------------------------------------------------------------------------------- /fw/device.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | #ifdef DEBUG_FIRMWARE 22 | #include 23 | #else 24 | #define printf(...) 25 | #endif 26 | 27 | BOOL handle_get_descriptor(void) { 28 | 29 | } 30 | 31 | //************************** Configuration Handlers ***************************** 32 | 33 | // change to support as many interfaces as you need 34 | //volatile xdata BYTE interface=0; 35 | //volatile xdata BYTE alt=0; // alt interface 36 | 37 | // set *alt_ifc to the current alt interface for ifc 38 | BOOL handle_get_interface(BYTE ifc, BYTE* alt_ifc) { 39 | // *alt_ifc=alt; 40 | return TRUE; 41 | } 42 | // return TRUE if you set the interface requested 43 | // NOTE this function should reconfigure and reset the endpoints 44 | // according to the interface descriptors you provided. 45 | BOOL handle_set_interface(BYTE ifc,BYTE alt_ifc) { 46 | printf ( "Set Interface.\n" ); 47 | //interface=ifc; 48 | //alt=alt_ifc; 49 | return TRUE; 50 | } 51 | 52 | // handle getting and setting the configuration 53 | // 1 is the default. If you support more than one config 54 | // keep track of the config number and return the correct number 55 | // config numbers are set int the dscr file. 56 | //volatile BYTE config=1; 57 | BYTE handle_get_configuration(void) { 58 | return 1; 59 | } 60 | 61 | // NOTE changing config requires the device to reset all the endpoints 62 | BOOL handle_set_configuration(BYTE cfg) { 63 | printf ( "Set Configuration.\n" ); 64 | //config=cfg; 65 | return TRUE; 66 | } 67 | 68 | 69 | //******************* VENDOR COMMAND HANDLERS ************************** 70 | 71 | 72 | BOOL handle_vendorcommand(BYTE cmd) { 73 | // your custom vendor handler code here.. 74 | return FALSE; // not handled by handlers 75 | } 76 | 77 | 78 | //******************** INIT *********************** 79 | 80 | void main_init(void) { 81 | 82 | REVCTL=3; 83 | SETIF48MHZ(); 84 | 85 | // set IFCONFIG 86 | // config your endpoints etc. 87 | // config gpif 88 | 89 | printf ( "Initialization Done.\n" ); 90 | 91 | } 92 | 93 | 94 | void main_loop(void) { 95 | // do some work 96 | } 97 | 98 | 99 | -------------------------------------------------------------------------------- /fw/fw.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #ifdef DEBUG_FIRMWARE 26 | #include 27 | #include 28 | #else 29 | #define printf(...) 30 | #endif 31 | 32 | 33 | 34 | 35 | volatile __bit dosud=FALSE; 36 | volatile __bit dosuspend=FALSE; 37 | 38 | // custom functions 39 | extern void main_loop(void); 40 | extern void main_init(void); 41 | 42 | 43 | void main(void) { 44 | 45 | #ifdef DEBUG_FIRMWARE 46 | SETCPUFREQ(CLK_48M); // required for sio0_init 47 | // main_init can still set this to whatever you want. 48 | sio0_init(57600); // needed for printf if debug defined 49 | #endif 50 | 51 | main_init(); 52 | 53 | // set up interrupts. 54 | USE_USB_INTS(); 55 | 56 | ENABLE_SUDAV(); 57 | ENABLE_USBRESET(); 58 | ENABLE_HISPEED(); 59 | ENABLE_SUSPEND(); 60 | ENABLE_RESUME(); 61 | 62 | EA=1; 63 | 64 | // iic files (c2 load) don't need to renumerate/delay 65 | // trm 3.6 66 | #ifndef NORENUM 67 | RENUMERATE(); 68 | #else 69 | USBCS &= ~bmDISCON; 70 | #endif 71 | 72 | while(TRUE) { 73 | 74 | main_loop(); 75 | 76 | if (dosud) { 77 | dosud=FALSE; 78 | handle_setupdata(); 79 | } 80 | 81 | if (dosuspend) { 82 | dosuspend=FALSE; 83 | do { 84 | printf ( "I'm going to Suspend.\n" ); 85 | WAKEUPCS |= bmWU|bmWU2; // make sure ext wakeups are cleared 86 | SUSPEND=1; 87 | PCON |= 1; 88 | __asm 89 | nop 90 | nop 91 | nop 92 | nop 93 | nop 94 | nop 95 | nop 96 | __endasm; 97 | } while ( !remote_wakeup_allowed && REMOTE_WAKEUP()); 98 | printf ( "I'm going to wake up.\n"); 99 | 100 | // resume 101 | // trm 6.4 102 | if ( REMOTE_WAKEUP() ) { 103 | delay(5); 104 | USBCS |= bmSIGRESUME; 105 | delay(15); 106 | USBCS &= ~bmSIGRESUME; 107 | } 108 | 109 | } 110 | 111 | } // end while 112 | 113 | } // end main 114 | 115 | void resume_isr(void) __interrupt (RESUME_ISR) { 116 | CLEAR_RESUME(); 117 | } 118 | 119 | void sudav_isr(void) __interrupt (SUDAV_ISR) { 120 | dosud=TRUE; 121 | CLEAR_SUDAV(); 122 | } 123 | void usbreset_isr(void) __interrupt (USBRESET_ISR) { 124 | handle_hispeed(FALSE); 125 | CLEAR_USBRESET(); 126 | } 127 | void hispeed_isr(void) __interrupt (HISPEED_ISR) { 128 | handle_hispeed(TRUE); 129 | CLEAR_HISPEED(); 130 | } 131 | 132 | void suspend_isr(void) __interrupt (SUSPEND_ISR) { 133 | dosuspend=TRUE; 134 | CLEAR_SUSPEND(); 135 | } 136 | -------------------------------------------------------------------------------- /fw/readme.txt: -------------------------------------------------------------------------------- 1 | Starting a new firmware is easy. 2 | 3 | 1) The fw should build without modification. 4 | 5 | > make # builds firmware.ihx 6 | > make bix # builds firmware.bix 7 | > make iic # builds firmware.iic 8 | 9 | 2) modify device.c to initialize your device and 10 | handle data according to your needs. 11 | 12 | 13 | 3) add more sources, gpif data etc. 14 | 15 | 4) modify the device descriptor (dscr.a51) 16 | 17 | 18 | For a fast way to deploy, you can use the fx2load 19 | package provided in examples/fx2 20 | 21 | -------------------------------------------------------------------------------- /include/autovector.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 Ubixum, Inc. 2 | // 3 | // This library is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU Lesser General Public 5 | // License as published by the Free Software Foundation; either 6 | // version 2.1 of the License, or (at your option) any later version. 7 | // 8 | // This library is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | // Lesser General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Lesser General Public 14 | // License along with this library; if not, write to the Free Software 15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | 18 | 19 | /** \file usbjt.h 20 | * 21 | * To use usbjt, you must tell the linker where to put the IN2JT. 22 | * It must lie on a page boundary or your interrupts won't work right. 23 | * 24 | * example: 25 | * -Wl"-b INT2JT = 0x1A00" 26 | * 27 | * Make sure that INT2JT doesn't overlap your other code! 28 | * 29 | * Unlike the standard fx2 interrupts (\ref fx2ints.h), the autovectored 30 | * interrupts are defined in assemply and have pre-written function names. 31 | * Be sure to override the functions defined in this header or your 32 | * interrupt handler will not be called. 33 | **/ 34 | 35 | #ifndef USBJT_H 36 | #define USBJT_H 37 | 38 | #include "fx2regs.h" 39 | 40 | 41 | /** 42 | * Enable all interrupts (EA=1) separate from this macro. 43 | * This macro causes the autovector assembly for int2 interrupts 44 | * to be overlayed at 0x43. In addition, the jump table for the 45 | * interrupts will be included in the firmware. The jump table 46 | * must lie on a page boundary. This is done by passing the linker 47 | * arguments to sdcc. 48 | * 49 | * \code 50 | * sdcc -Wl"-b INT2JT = 0xaddr" 51 | * \endcode 52 | **/ 53 | #define USE_USB_INTS() {EUSB=1;\ 54 | INTSETUP|=bmAV2EN;} 55 | /** This macro causes the autovector assemby for int4 to be overlayed 56 | * at 0x53. Don't use this if you want external pin generated int4 interrupts 57 | * and want to define your own interrupt handler. It is possible to use 58 | * usb interrupts with autovectoring and not use GPIF interrupts but GPIF 59 | * interrupts require the USB jump table. (You can't USE your own usb interrupt 60 | * handler if you want to enable GPIF interrupts.) 61 | **/ 62 | #define USE_GPIF_INTS() {EIEX4=1;\ 63 | INTSETUP|=bmAV4EN|INT4IN;} 64 | 65 | 66 | #define CLEAR_USBINT() EXIF &= ~0x10 67 | #define CLEAR_GPIF() EXIF &= ~0x40 68 | 69 | #define ENABLE_SUDAV() USBIE|=bmSUDAV 70 | #define CLEAR_SUDAV() CLEAR_USBINT(); USBIRQ=bmSUDAV 71 | 72 | #define ENABLE_SUTOK() USBIE|=bmSUTOK; 73 | #define CLEAR_SUTOK() CLEAR_USBINT(); USBIRQ=bmSUTOK 74 | 75 | #define ENABLE_SOF() USBIE|=bmSOF 76 | #define CLEAR_SOF() CLEAR_USBINT(); USBIRQ=bmSOF 77 | 78 | #define ENABLE_SUSPEND() USBIE|=bmSUSP 79 | #define CLEAR_SUSPEND() CLEAR_USBINT(); USBIRQ=bmSUSP 80 | 81 | #define ENABLE_USBRESET() USBIE|= bmURES 82 | #define CLEAR_USBRESET() CLEAR_USBINT(); USBIRQ=bmURES 83 | 84 | #define ENABLE_HISPEED() USBIE|=bmHSGRANT 85 | #define CLEAR_HISPEED() CLEAR_USBINT(); USBIRQ=bmHSGRANT 86 | 87 | #define ENABLE_EP0IN() EPIE|=bmEP0IN 88 | #define CLEAR_EP0IN() CLEAR_USBINT(); EPIRQ=bmEP0IN 89 | 90 | #define ENABLE_EP0OUT() EPIE|=bmEP0OUT 91 | #define CLEAR_EP0OUT() CLEAR_USBINT(); EPIRQ=bmEP0OUT 92 | 93 | #define ENABLE_EP1IN() EPIE|=bmEP1IN 94 | #define CLEAR_EP1IN() CLEAR_USBINT(); EPIRQ=bmEP1IN 95 | 96 | #define ENABLE_EP1OUT() EPIE|=bmEP1OUT 97 | #define CLEAR_EP1OUT() CLEAR_USBINT(); EPIRQ=bmEP1OUT 98 | 99 | #define ENABLE_EP2() EPIE|=bmEP2 100 | #define CLEAR_EP2() CLEAR_USBINT(); EPIRQ=bmEP2 101 | 102 | #define ENABLE_EP4() EPIE|=bmEP4 103 | #define CLEAR_EP4() CLEAR_USBINT(); EPIRQ=bmEP4 104 | 105 | #define ENABLE_EP6() EPIE|=bmEP6 106 | #define CLEAR_EP6() CLEAR_USBINT(); EPIRQ=bmEP6 107 | 108 | #define ENABLE_EP8() EPIE|=bmEP8 109 | #define CLEAR_EP8() CLEAR_USBINT(); EPIRQ=bmEP8 110 | 111 | #define ENABLE_EP2ISOERR() USBERRIE |= bmISOEP2 112 | #define CLEAR_EP2ISOERR() CLEAR_USBINT(); USBERRIRQ = bmISOEP2 113 | 114 | #define ENABLE_EP6PF() EP6FIFOIE |= bmBIT2 115 | #define CLEAR_EP6PF() CLEAR_GPIF(); EP6FIFOIRQ=bmBIT2 116 | 117 | #define ENABLE_EP6FF() EP6FIFOIE |= bmBIT0 118 | #define CLEAR_EP6FF() CLEAR_GPIF(); EP6FIFOIRQ=bmBIT0 119 | 120 | #define ENABLE_GPIFDONE() GPIFIE |= 0x01; 121 | #define CLEAR_GPIFDONE() CLEAR_GPIF(); GPIFIRQ = 0x01; 122 | 123 | #define ENABLE_GPIFWF() GPIFIE |= 0x02; 124 | #define CLEAR_GPIFWF() GLEAR_GPIF(); GPIFIRQ = 0x02; 125 | 126 | /** 127 | * ez-usb has 12 built in ISRs, to get 128 | * sdcc to put these USB ISRs immediately 129 | * after the other ISRs (and not waste space) 130 | * we start at 13 131 | **/ 132 | typedef enum { 133 | SUDAV_ISR=13, 134 | SOF_ISR, 135 | SUTOK_ISR, 136 | SUSPEND_ISR, 137 | USBRESET_ISR, 138 | HISPEED_ISR, 139 | EP0ACK_ISR, 140 | EP0IN_ISR, 141 | EP0OUT_ISR, 142 | EP1IN_ISR, 143 | EP1OUT_ISR, 144 | EP2_ISR, 145 | EP4_ISR, 146 | EP6_ISR, 147 | EP8_ISR, 148 | IBN_ISR, 149 | EP0PING_ISR, 150 | EP1PING_ISR, 151 | EP2PING_ISR, 152 | EP4PING_ISR, 153 | EP6PING_ISR, 154 | EP8PING_ISR, 155 | ERRLIMIT_ISR, 156 | EP2ISOERR_ISR, 157 | EP4ISOERR_ISR, 158 | EP6ISOERR_ISR, 159 | EP8ISOERR_ISR, 160 | RESERVED_ISR, 161 | EP2PF_ISR, 162 | EP4PF_ISR, 163 | EP6PF_ISR, 164 | EP8PF_ISR, 165 | EP2EF_ISR, 166 | EP4EF_ISR, 167 | EP6EF_ISR, 168 | EP8EF_ISR, 169 | EP2FF_ISR, 170 | EP4FF_ISR, 171 | EP6FF_ISR, 172 | EP8FF_ISR, 173 | GPIFDONE_ISR, 174 | GPIFWF_ISR 175 | } USB_ISR; 176 | 177 | // you must include the predef of these in the file with your main 178 | // so lets just define them here 179 | 180 | void usb_isr(void) __interrupt (8); 181 | void sudav_isr(void) __interrupt; 182 | void sof_isr(void) __interrupt; 183 | void sutok_isr(void) __interrupt; 184 | void suspend_isr(void) __interrupt; 185 | void usbreset_isr(void) __interrupt; 186 | void hispeed_isr(void) __interrupt; 187 | void ep0ack_isr(void) __interrupt; 188 | void ep0in_isr(void) __interrupt; 189 | void ep0out_isr(void) __interrupt; 190 | void ep1in_isr(void) __interrupt; 191 | void ep1out_isr(void) __interrupt; 192 | void ep2_isr(void) __interrupt; 193 | void ep4_isr(void) __interrupt; 194 | void ep6_isr(void) __interrupt; 195 | void ep8_isr(void) __interrupt; 196 | void ibn_isr(void) __interrupt; 197 | void ep0ping_isr(void) __interrupt; 198 | void ep1ping_isr(void) __interrupt; 199 | void ep2ping_isr(void) __interrupt; 200 | void ep4ping_isr(void) __interrupt; 201 | void ep6ping_isr(void) __interrupt; 202 | void ep8ping_isr(void) __interrupt; 203 | void errlimit_isr(void) __interrupt; 204 | void ep2isoerr_isr(void) __interrupt; 205 | void ep4isoerr_isr(void) __interrupt; 206 | void ep6isoerr_isr(void) __interrupt; 207 | void ep8isoerr_isr(void) __interrupt; 208 | void spare_isr(void) __interrupt; // not used 209 | // gpif ints 210 | void gpif_isr(void) __interrupt (10); 211 | void ep2pf_isr(void) __interrupt; 212 | void ep4pf_isr(void) __interrupt; 213 | void ep6pf_isr(void) __interrupt; 214 | void ep8pf_isr(void) __interrupt; 215 | void ep2ef_isr(void) __interrupt; 216 | void ep4ef_isr(void) __interrupt; 217 | void ep6ef_isr(void) __interrupt; 218 | void ep8ef_isr(void) __interrupt; 219 | void ep2ff_isr(void) __interrupt; 220 | void ep4ff_isr(void) __interrupt; 221 | void ep6ff_isr(void) __interrupt; 222 | void ep8ff_isr(void) __interrupt; 223 | void gpifdone_isr(void) __interrupt; 224 | void gpifwf_isr(void) __interrupt; 225 | 226 | #endif 227 | 228 | -------------------------------------------------------------------------------- /include/delay.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Ubixum, Inc. 2 | // 3 | // This library is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU Lesser General Public 5 | // License as published by the Free Software Foundation; either 6 | // version 2.1 of the License, or (at your option) any later version. 7 | // 8 | // This library is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | // Lesser General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Lesser General Public 14 | // License along with this library; if not, write to the Free Software 15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | /*! \file 18 | * Functions for causing delays. 19 | * */ 20 | 21 | 22 | #ifndef DELAY_H 23 | #define DELAY_H 24 | 25 | #include "fx2types.h" 26 | 27 | /** 28 | * 0-65536 millis 29 | **/ 30 | void delay(WORD millis); 31 | 32 | /** 33 | * See TRM 15-14,15-15 34 | * some registers (r/w) require syncdelay after 35 | * 36 | * up to the programmer to determine which sync is needed. 37 | * for standard 48mhz clock w/ 48mhz IFCONFIG 3 nops is sufficient. 38 | * 39 | * slower clock and faster ifclock require more delay 40 | * 41 | * min delay = roof ( 1.5 x (ifclock/clkout + 1) ) 42 | * 43 | * Minimum IFCLOCK is 5mhz but you have to use an 44 | * external clock source to go below 30mhz 45 | * 46 | * IFCLKSRC 1 = internal, 0=external 47 | * 3048mhz 0 = 30mhz, 1 = 48mzh 48 | * 49 | * Figure your own sync delay out if IFCLKSRC=0. 50 | **/ 51 | 52 | #define NOP __asm nop __endasm 53 | 54 | /** 55 | * SYNCDELAY2 can work for the following clock speeds 56 | * 57 | * ifclk/clk 58 | * \li 48/12 59 | * 60 | * ceil(1.5 * (20.8 / 83.3 + 1)) = 2 61 | * 62 | * \see NOP 63 | * 64 | **/ 65 | #define SYNCDELAY2 NOP; NOP 66 | 67 | /** 68 | * SYNCDELAY3 can work for the following clock speeds 69 | * 70 | * ifcfg/clk 71 | * \li 48/24 72 | * \li 48/48 73 | * \li 30/12 74 | * \li 30/24 75 | * 76 | * \see NOP 77 | **/ 78 | #define SYNCDELAY3 NOP; NOP; NOP 79 | 80 | /** 81 | * SYNCDELAY4 should be used for the following speeds 82 | * 83 | * ifcfg/clk 84 | * \li 30/48 85 | * 86 | * \see NOP 87 | **/ 88 | #define SYNCDELAY4 NOP; NOP; NOP; NOP 89 | 90 | /** 91 | * All the SYNCDELAYs you could possibly want for other speeds 92 | * 93 | * \see NOP 94 | **/ 95 | #define SYNCDELAY5 NOP; NOP; NOP; NOP; NOP 96 | #define SYNCDELAY6 NOP; NOP; NOP; NOP; NOP; NOP 97 | #define SYNCDELAY7 NOP; NOP; NOP; NOP; NOP; NOP; NOP 98 | #define SYNCDELAY8 NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP 99 | #define SYNCDELAY9 NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP 100 | #define SYNCDELAY10 NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP 101 | #define SYNCDELAY11 NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP 102 | #define SYNCDELAY12 NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP 103 | #define SYNCDELAY13 NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP 104 | #define SYNCDELAY14 NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP 105 | #define SYNCDELAY15 NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP 106 | #define SYNCDELAY16 NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP 107 | 108 | #endif 109 | 110 | -------------------------------------------------------------------------------- /include/eputils.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Ubixum, Inc. 2 | // 3 | // This library is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU Lesser General Public 5 | // License as published by the Free Software Foundation; either 6 | // version 2.1 of the License, or (at your option) any later version. 7 | // 8 | // This library is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | // Lesser General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Lesser General Public 14 | // License along with this library; if not, write to the Free Software 15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | /*! \file 18 | * Functions and macros for working with endpoints. 19 | * */ 20 | 21 | #ifndef EPUTILS_H 22 | #define EPUTILS_H 23 | 24 | #include "fx2types.h" 25 | 26 | /** 27 | * NOTE you can't use these unless you define SYNCDELAY 28 | * as a macro or function. The reason is that SYNCDELAY 29 | * needs to be longer or shorter depending on your IFCONFIG 30 | * settings. 31 | * See delay.h 32 | * 33 | * Example: 34 | * \code 35 | * #define SYNCDELAY SYNCDELAY4 // SYNCDELAY4 from delay.h 36 | * \endcode 37 | * 38 | * 39 | **/ 40 | 41 | /** 42 | * Stalls EP0. 43 | **/ 44 | #define STALLEP0() EP0CS |= bmEPSTALL 45 | 46 | /** 47 | * \brief Reset the toggle on an endpoint. 48 | * To use this, the endpoint needs bit 8 to be IN=1,OUT=0 49 | **/ 50 | #define RESETTOGGLE(ep) do {\ 51 | BYTE x = ep; \ 52 | if (x&0x80) { x |= 0x10; } \ 53 | x &= 0x1F; \ 54 | TOGCTL = x; \ 55 | TOGCTL = x | bmRESETTOGGLE; \ 56 | } while (0) 57 | 58 | 59 | /** 60 | * RESETFIFO should not use 0x80|epnum for IN endpoints 61 | * Only use 0x02, 0x04, 0x06, 0x06 for ep value 62 | **/ 63 | #define RESETFIFO(ep) {FIFORESET=0x80; SYNCDELAY;\ 64 | FIFORESET=0x80 | ep; SYNCDELAY;\ 65 | FIFORESET=0x00; SYNCDELAY;} 66 | /** 67 | * Quickly reset all endpoint FIFOS. 68 | **/ 69 | #define RESETFIFOS() {FIFORESET=0x80; SYNCDELAY;\ 70 | FIFORESET=0x82; SYNCDELAY;\ 71 | FIFORESET=0x84; SYNCDELAY;\ 72 | FIFORESET=0x86; SYNCDELAY;\ 73 | FIFORESET=0x88; SYNCDELAY;\ 74 | FIFORESET=0x00; SYNCDELAY;} 75 | 76 | /** 77 | * Continually read available bytes from endpoint0 into dst, wait 78 | * until more bytes are available, and loop until len bytes have 79 | * been read. 80 | **/ 81 | void readep0( BYTE* dst, WORD len ); 82 | 83 | 84 | /** 85 | * Write bytes from src to ep0, allowing host to transfer data 86 | * between 64 byte blocks. 87 | **/ 88 | void writeep0 ( BYTE* src, WORD len ); 89 | 90 | 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /include/fx2ints.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 Ubixum, Inc. 2 | // 3 | // This library is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU Lesser General Public 5 | // License as published by the Free Software Foundation; either 6 | // version 2.1 of the License, or (at your option) any later version. 7 | // 8 | // This library is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | // Lesser General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Lesser General Public 14 | // License along with this library; if not, write to the Free Software 15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | /*! \file 18 | * Define the standard fx2 interrupts. For int2 and int4 autovector 19 | * interrupts see \ref autovector.h 20 | * 21 | * To enable an interrupt, simply define an interrupt handler function 22 | * and use the appropriate ENABLE_* macro. Interrupt enable macros 23 | * do not enable interrupts globally. Use EA=1 to enable interrupts. 24 | * 25 | * \code 26 | * void main() { 27 | * ENABLE_RESUME(); 28 | * EA=1; 29 | * ... 30 | * } 31 | * 32 | * void handle_resume() interrupt RESUME_ISR { 33 | * CLEAR_RESUME(); 34 | * } 35 | * \endcode 36 | * 37 | * */ 38 | 39 | 40 | /** 41 | * \brief interrupt numbers for standard fx2 interrupts 42 | 43 | **/ 44 | typedef enum { 45 | IE0_ISR=0, ///< External interrupt 0 46 | TF0_ISR, ///< Timer 0 interrupt 47 | IE1_ISR, ///< External interrupt 1 48 | TF1_ISR, ///< Timer 1 interrupt 49 | TI_0_ISR, ///< Serial port 0 transmit or receive interrupt 50 | TF2_ISR, ///< Timer 2 interrupt 51 | RESUME_ISR, ///< Resume interrupt 52 | TI_1_ISR, ///< Serial port 1 transmit or receive interrupt 53 | USBINT_ISR, ///< Usb Interrupt. An interrupt handler for this should only be used if not using auto vectored interrupts with int2 54 | I2CINT_ISR, ///< I2C Bus interrupt 55 | IE4_ISR, ///< External interrupt 4. An interrupt handler for this should only be used if not using auto vectored interrupts with int4 56 | IE5_ISR, ///< External interrupt 5 57 | IE6_ISR, ///< External interrupt 6 58 | } FX2_ISR; 59 | 60 | 61 | /** 62 | * \brief Enable the timer 0 interrupt. 63 | * 64 | * There is not CLEAR_TIMER0 because the timer interrupt flag 65 | * is automatically cleared when the isr is called. 66 | **/ 67 | #define ENABLE_TIMER0() ET0=1 68 | 69 | /** 70 | * \brief Enable timer 1 interrupt 71 | * There is no CLEAR_TIMER1 because the timer interrupt flag 72 | * is automatically cleared when the isr is called. 73 | **/ 74 | #define ENABLE_TIMER1() ET1=1 75 | 76 | 77 | /** 78 | * \brief Enable timer 2 interrupt 79 | * 80 | * This is the same interrupt whether timer 2 overflowed or 81 | * for the external EXF2 flag. 82 | **/ 83 | #define ENABLE_TIMER2() ET2=1 84 | /** 85 | * \brief Clear timer 2 interrupt 86 | * 87 | * Clears both the TF2 AND EXF2 flag 88 | **/ 89 | #define CLEAR_TIMER2() TF2=0;EXF2=0; 90 | 91 | /** 92 | * \brief Enable the Resume Interrupt. Requires EA=1 separately. 93 | **/ 94 | #define ENABLE_RESUME() ERESI = 1 95 | 96 | /** 97 | * \brief Clear the resume interrupt. Use within the resume 98 | * interrupt handler. 99 | **/ 100 | #define CLEAR_RESUME() RESI=0 101 | 102 | 103 | #define ENABLE_INT4() 104 | 105 | /** 106 | * \brief 107 | * Enable external interupt for int5# 108 | **/ 109 | #define ENABLE_INT5() EIEX5=1 110 | 111 | /** 112 | * \brief 113 | * Clear int5# interrupt 114 | **/ 115 | #define CLEAR_INT5() EXIF &= ~0x80 116 | 117 | -------------------------------------------------------------------------------- /include/fx2macros.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Ubixum, Inc. 2 | // 3 | // This library is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU Lesser General Public 5 | // License as published by the Free Software Foundation; either 6 | // version 2.1 of the License, or (at your option) any later version. 7 | // 8 | // This library is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | // Lesser General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Lesser General Public 14 | // License along with this library; if not, write to the Free Software 15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | /*! \file 18 | * Macros for simple common tasks in fx2 firmware. 19 | * */ 20 | 21 | #ifndef FX2MACROS_H 22 | #define FX2MACROS_H 23 | 24 | #include "fx2regs.h" 25 | #include "fx2types.h" 26 | 27 | #define MSB(addr) (BYTE)(((WORD)(addr) >> 8) & 0xff) 28 | #define LSB(addr) (BYTE)((WORD)(addr) & 0xff) 29 | #define MAKEWORD(msb,lsb) (((WORD)msb << 8) | lsb) 30 | 31 | #define MSW(dword) (WORD)((dword >> 16) & 0xffff) 32 | #define LSW(dword) (WORD)(dword & 0xffff) 33 | #define MAKEDWORD(msw,lsw) (((DWORD)msw << 16) | lsw) 34 | 35 | // clock stuff 36 | 37 | /** 38 | * \brief Used for getting and setting the CPU clock speed. 39 | **/ 40 | typedef enum { CLK_12M =0, CLK_24M, CLK_48M} CLK_SPD; 41 | 42 | /** 43 | * \brief Evaluates to a CLK_SPD enum. 44 | **/ 45 | #define CPUFREQ (CLK_SPD)((CPUCS & bmCLKSPD) >> 3) 46 | /** 47 | * \brief Sets the cpu to operate at a specific 48 | * clock speed. 49 | **/ 50 | #define SETCPUFREQ(SPD) CPUCS = (CPUCS & ~bmCLKSPD) | (SPD << 3) 51 | 52 | /** 53 | * \brief Evaluates to a DWORD value representing 54 | * the clock speed in cycles per second. 55 | * 56 | * Speeds: 57 | * 58 | * \li 12000000L 59 | * \li 24000000L 60 | * \li 48000000L 61 | * 62 | **/ 63 | #define XTAL (CPUFREQ==CLK_12M ? 12000000L :\ 64 | CPUFREQ==CLK_24M ? 24000000L : 48000000L) 65 | 66 | 67 | /** 68 | * \brief Evaluates to the i2c bus frequency in cyles per 69 | * second. 70 | * 71 | * Speeds: 72 | * 73 | * \li 400000L 74 | * \li 100000L 75 | * 76 | **/ 77 | #define I2CFREQ ((I2CTL & bm400KHZ) ? 400000L : 100000L) 78 | 79 | 80 | #define IFFREQ (IFCONFIG & bm3048MHZ ? 48000000L : 30000000L) 81 | #define SETIF30MHZ() IFCONFIG &= ~bm3048MHZ 82 | #define SETIF48MHZ() IFCONFIG |= bm3048MHZ 83 | 84 | 85 | // eeprom stuff 86 | #define EEPROM_TWO_BYTE (I2CS & bmBIT4) 87 | 88 | /** 89 | * \brief Cause the device to disconnect and reconnect to USB. This macro 90 | * unconditionally renumerates the device no matter how the firmware is loaded. 91 | * 92 | * NOTE Windows really doesn't like this if the firmware is loaded 93 | * from an eeprom. You'll see information messages about the device not 94 | * working properly. On the other hand, if you are changing the device 95 | * descriptor, e.g., the vendor and product id, when downloading firmware to the device, 96 | * you'll need to use this macro instead of the 97 | * standard RENUMERATE macro. 98 | **/ 99 | #define RENUMERATE_UNCOND() USBCS|=bmDISCON|bmRENUM;delay(1500);USBCS&=~bmDISCON 100 | /** 101 | * \brief Cause the device to disconnect and reconnect to the USB bus. This macro 102 | * doesn't do anything if the firmware is loaded from an eeprom. 103 | **/ 104 | #define RENUMERATE() if(!(USBCS&bmRENUM)) {USBCS|=bmDISCON|bmRENUM;delay(1500);USBCS &= ~bmDISCON;} 105 | 106 | 107 | // interrupts 108 | // USB interrupts are in usbjt.h 109 | 110 | 111 | 112 | 113 | /** 114 | * \brief TRUE if the FX2 has transitioned to high speed on the USB bus.. 115 | **/ 116 | #define HISPEED (USBCS&bmHSM) 117 | 118 | 119 | 120 | 121 | /** 122 | * \brief Evaluates to TRUE if a remote wakeup event has occurred. 123 | **/ 124 | #define REMOTE_WAKEUP() (((WAKEUPCS & bmWU) && (WAKEUPCS & bmWUEN)) || ((WAKEUPCS & bmWU2) && (WAKEUPCS & bmWU2EN))) 125 | 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /include/fx2types.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Ubixum, Inc. 2 | // 3 | // This library is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU Lesser General Public 5 | // License as published by the Free Software Foundation; either 6 | // version 2.1 of the License, or (at your option) any later version. 7 | // 8 | // This library is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | // Lesser General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Lesser General Public 14 | // License along with this library; if not, write to the Free Software 15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | /*! \file 18 | * define standard types of fixed widths. 19 | * */ 20 | 21 | #ifndef FXTYPES_H 22 | #define FXTYPES_H 23 | 24 | typedef unsigned int WORD; 25 | typedef unsigned char BYTE; 26 | typedef unsigned long DWORD; 27 | typedef unsigned char BOOL; 28 | typedef enum { 29 | FALSE=0, 30 | TRUE 31 | } BOOL_VALS; 32 | 33 | #ifndef NULL 34 | #define NULL (void*)0 35 | #endif 36 | 37 | /*----------------------------------------------------------------------------- 38 | Bit Masks 39 | -----------------------------------------------------------------------------*/ 40 | 41 | #define bmBIT0 1 42 | #define bmBIT1 2 43 | #define bmBIT2 4 44 | #define bmBIT3 8 45 | #define bmBIT4 16 46 | #define bmBIT5 32 47 | #define bmBIT6 64 48 | #define bmBIT7 128 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /include/gpif.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Ubixum, Inc. 2 | // 3 | // This library is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU Lesser General Public 5 | // License as published by the Free Software Foundation; either 6 | // version 2.1 of the License, or (at your option) any later version. 7 | // 8 | // This library is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | // Lesser General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Lesser General Public 14 | // License along with this library; if not, write to the Free Software 15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | /*! \file 18 | * 19 | * These functions do the same thing that the Cypress gpif designer expored c file does. 20 | * Instead of including their file directly in your project, you include just the 21 | * generated waveform data. The gpif2dat script in the utils folder will export your 22 | * waveform data to a file that can be included in your project. 23 | * */ 24 | 25 | #ifndef GPIF_H 26 | #define GPIF_H 27 | 28 | #include "fx2types.h" 29 | 30 | #define GPIFDONE (GPIFTRIG&0x80) 31 | #define GPIFTC16 (MAKEWORD(GPIFTCB1,GPIFTCB0)) 32 | #define GPIFTC32 (MAKEDWORD(MAKEWORD(GPIFTCB3,GPIFTCB2),MAKEWORD(GPIFTCB1,GPIFTCB0))) 33 | 34 | 35 | /** 36 | * Gpif designer generates a c file with waveform data. 37 | * Copy the WaveData[128] array 38 | * and the InitData[7] to your code somewhere 39 | * Then this function is pretty much the reset of the generated 40 | * code but ported to sdcc. 41 | * 42 | * uses syncdelay of 4 which might not be long enough if peripheral 43 | * runs slower than 30mhz. May not affect anything. 44 | * 45 | * IFCONFIG is set with IFCFG[1:0] = 10 for GPIF master but you still 46 | * have to set the ifclk, polarity, and the rest of the bits 47 | **/ 48 | 49 | void gpif_init( BYTE* waveform, BYTE* initdata ); 50 | 51 | /** 52 | * Uses the correct bytes from your flowstates array. 53 | * This may or may not be needed depending on whether 54 | * your waveform data uses flowstates. If you don't 55 | * know if you need them or not, you probably don't. 56 | * 57 | * flowstates should have 36 elements. 58 | * bank should be 0-3 59 | **/ 60 | void gpif_setflowstate( BYTE* flowstates, BYTE bank); 61 | 62 | 63 | 64 | //! These defines/functions pretty much out of the TRM 10.4 65 | #define GPIFTRGWR 0 66 | #define GPIFTRGRD 4 67 | typedef enum { 68 | GPIF_EP2 = 0, 69 | GPIF_EP4 = 1, 70 | GPIF_EP6 = 2, 71 | GPIF_EP8 = 3 72 | } GPIF_EP_NUM; 73 | 74 | /** 75 | * \brief Simple function to help set the transaction count for gpif 76 | * transactions. 77 | * \param tc 32 bit Transaction Count 78 | **/ 79 | void gpif_set_tc32(DWORD tc); 80 | /** 81 | * \brief Simple function to set transaction count for gpif transactions. 82 | * \param tc 16 bit Transaction Count 83 | **/ 84 | void gpif_set_tc16(WORD tc); 85 | 86 | 87 | /** 88 | * Use the gpif to read a single word at a time. 89 | * Read len words and store in res 90 | * 91 | * At least one EPxFIFOCFG has to have wordwide=1 or this 92 | * functions won't transfer both bytes. 93 | **/ 94 | 95 | void gpif_single_read16( WORD* res , WORD len); 96 | 97 | /** 98 | * Use the gpif to write a single word at a time. 99 | * Write len words from data 100 | * 101 | * At leat one EPxFIFOCFG has to have wordwide=1 or this 102 | * function won't transfer both bytes. 103 | **/ 104 | void gpif_single_write16( WORD* dat, WORD len); 105 | 106 | void gpif_fifo_read ( GPIF_EP_NUM ep_num ); 107 | 108 | void gpif_fifo_write( GPIF_EP_NUM ep_num ); 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /include/i2c.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Ubixum, Inc. 2 | // 3 | // This library is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU Lesser General Public 5 | // License as published by the Free Software Foundation; either 6 | // version 2.1 of the License, or (at your option) any later version. 7 | // 8 | // This library is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | // Lesser General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Lesser General Public 14 | // License along with this library; if not, write to the Free Software 15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | /** \file i2c.h 18 | * Utilities for reading and writing to i2c devices and as eeproms. 19 | **/ 20 | 21 | #ifndef I2C_H 22 | #define I2C_H 23 | 24 | #include "fx2types.h" 25 | 26 | /** 27 | * i2c_write and i2c_read set this to FALSE at the beginning of a 28 | * transaction. If for some reason, the read/write is taking too 29 | * long or not returning, firmware can set this to TRUE to cause the 30 | * routine to abort. (Usually done via an interrupt). 31 | **/ 32 | extern volatile __xdata BOOL cancel_i2c_trans; 33 | 34 | /** 35 | * \brief write data to i2c bus. 36 | * 37 | * Writes data from addr buffer 1st, then data buffer. 38 | * Either buffer can be NULL (as long as you set lenN to 0). 39 | * 40 | * Two buffers allows writing data all in one i2c write command without 41 | * having to write a hardware address and a data byte with each 42 | * i2c transaction. 43 | * 44 | * \param addr i2c address 45 | * \param len1 length of addr data 46 | * \param addr_buf addr data 47 | * \param len2 length of data 48 | * \param data_buf data bytes 49 | **/ 50 | BOOL i2c_write ( BYTE addr, WORD len1, BYTE* addr_buf, WORD len2, BYTE* data_buf ); 51 | 52 | /** 53 | * \brief read data on the i2c bus. 54 | * 55 | * \param addr i2c address 56 | * \param len number of bytes to read 57 | * \param buf buffer to store data 58 | **/ 59 | BOOL i2c_read ( BYTE addr, WORD len, BYTE* buf); 60 | 61 | /** 62 | * \brief read data from an attached eeprom. 63 | * 64 | * Writes the address of the data to read then reads len bytes into buf. 65 | * This function checks the I2CS register to determine if a one or two 66 | * byte address eepom was detected on the i2c bus. Reading from proms 67 | * at non-standard addresses my require using the i2c_read/write commands 68 | * explicitly. 69 | * 70 | * \param prom_addr eeprom i2c address 71 | * \param addr address of bytes to start reading 72 | * \param len number of bytes to read 73 | * \param buf data buffer 74 | **/ 75 | BOOL eeprom_read( BYTE prom_addr, WORD addr, WORD len, BYTE* buf); 76 | 77 | /** 78 | * \brief write data to the eeprom 79 | * 80 | * This function checks the I2CS register to determin if a one or two 81 | * two byte eeprom is detected. If the prom is not detected at boot time 82 | * or is connected to alternate addresses, the i2c_read/write commands should 83 | * be used explicitly insread of using this function. 84 | * 85 | * For each byte in buf, the address is written and then the data byte. Many 86 | * proms support writing multiple bytes at the same time. For these, it is 87 | * also better to use i2c_read/write explicitly. This function is rather slow 88 | * but is effective. 89 | * 90 | * \param prom_addr eeprom i2c address 91 | * \param addr address of bytes to start writing 92 | * \param len number of bytes to write 93 | * \param buf data buffer 94 | **/ 95 | BOOL eeprom_write( BYTE prom_addr, WORD addr, WORD len, BYTE* buf); 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /include/lights.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Ubixum, Inc. 2 | // 3 | // This library is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU Lesser General Public 5 | // License as published by the Free Software Foundation; either 6 | // version 2.1 of the License, or (at your option) any later version. 7 | // 8 | // This library is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | // Lesser General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Lesser General Public 14 | // License along with this library; if not, write to the Free Software 15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | /** \file lights.h 18 | * macros for turning lights on the EZ-USB development board on and off. 19 | **/ 20 | 21 | #ifndef LIGHTS_H 22 | #define LIGHTS_H 23 | 24 | #include "fx2types.h" 25 | 26 | #ifndef FX1 27 | // FX2 Dev board lights 28 | #define D2ONH #0x88 // assembly high byte of light addr 29 | #define D2OFFH #0x80 30 | #define D3ONH #0x98 31 | #define D3OFFH #0x90 32 | #define D4ONH #0xA8 33 | #define D4OFFH #0xA0 34 | #define D5ONH #0xB8 35 | #define D5OFFH #0xB0 36 | volatile __xdata __at(0x8800) BYTE D2ON; 37 | volatile __xdata __at(0x8000) BYTE D2OFF; 38 | volatile __xdata __at(0x9800) BYTE D3ON; 39 | volatile __xdata __at(0x9000) BYTE D3OFF; 40 | volatile __xdata __at(0xA800) BYTE D4ON; 41 | volatile __xdata __at(0xA000) BYTE D4OFF; 42 | volatile __xdata __at(0xB800) BYTE D5ON; 43 | volatile __xdata __at(0xB000) BYTE D5OFF; 44 | #else 45 | // FX1 dev board lights 46 | #define D2ONH #0x80 // assembly high byte of light addr 47 | #define D2OFFH #0x81 48 | #define D3ONH #0x90 49 | #define D3OFFH #0x91 50 | #define D4ONH #0xA0 51 | #define D4OFFH #0xA1 52 | #define D5ONH #0xB0 53 | #define D5OFFH #0xB1 54 | volatile __xdata __at(0x8000) BYTE D2ON; 55 | volatile __xdata __at(0x8100) BYTE D2OFF; 56 | volatile __xdata __at(0x9000) BYTE D3ON; 57 | volatile __xdata __at(0x9100) BYTE D3OFF; 58 | volatile __xdata __at(0xA000) BYTE D4ON; 59 | volatile __xdata __at(0xA100) BYTE D4OFF; 60 | volatile __xdata __at(0xB000) BYTE D5ON; 61 | volatile __xdata __at(0xB100) BYTE D5OFF; 62 | #endif 63 | 64 | /** 65 | * Easier to use macros defined below 66 | **/ 67 | #define activate_light(LIGHT_ADDR) __asm \ 68 | mov __XPAGE, LIGHT_ADDR \ 69 | __endasm; __asm \ 70 | movx a, @r0 \ 71 | __endasm \ 72 | 73 | /** 74 | * Easy to make lights blink with these macros: 75 | * \code 76 | * WORD ct=0; 77 | * BOOL on=FALSE; 78 | * while (TRUE) { 79 | * if (!ct) { 80 | * on=!on; 81 | * if (on) d2on(); else d2off(); 82 | * } 83 | * ++ct; 84 | * } 85 | * \endcode 86 | **/ 87 | #define d2on() activate_light(D2ONH) 88 | #define d2off() activate_light(D2OFFH) 89 | #define d3on() activate_light(D3ONH) 90 | #define d3off() activate_light(D3OFFH) 91 | #define d4on() activate_light(D4ONH) 92 | #define d4off() activate_light(D4OFFH) 93 | #define d5on() activate_light(D5ONH) 94 | #define d5off() activate_light(D5OFFH) 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /include/serial.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Ubixum, Inc. 2 | // 3 | // This library is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU Lesser General Public 5 | // License as published by the Free Software Foundation; either 6 | // version 2.1 of the License, or (at your option) any later version. 7 | // 8 | // This library is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | // Lesser General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Lesser General Public 14 | // License along with this library; if not, write to the Free Software 15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | /** \file serial.h 18 | * defines functions to print to a serial console with SIO0 19 | **/ 20 | 21 | #include "fx2types.h" 22 | 23 | 24 | /** 25 | * This function inits sio0 to use T2CON (timer 2) 26 | * See TRM 14.3.4.1 (Table 14-16) 27 | * Certain baud rates have too high an error rate to work. All baud rates are .16% 28 | * except: 29 | * 30 | * 12MHZ 24MHZ 31 | * \li 57600 -6.99% 32 | * \li 38400 -2.34% -2.34% 33 | * \li 19200 -2.34% 34 | * 35 | * Possible Baud rates: 36 | * \li 2400 37 | * \li 4800 38 | * \li 9600 39 | * \li 19200 40 | * \li 28800 41 | * \li 38400 42 | * \li 57600 43 | * 44 | * Any of these rates should work except 57600 at 12mhz. -2.34% is pushing 45 | * most hardware specs for working. All rates at 48mhz work at .16% 46 | **/ 47 | 48 | void sio0_init( DWORD baud_rate ) __critical ; // baud_rate max should be 57600 since int=2 bytes 49 | 50 | /** 51 | putchar('\\n') or putchar('\\r') both transmit \\r\\n 52 | Just use one or the other. (This makes terminal echo easy) 53 | **/ 54 | int putchar(char c); 55 | int getchar(void); 56 | -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | fx2.lib 2 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2009 Ubixum, Inc. 2 | # 3 | # This library is free software; you can redistribute it and/or 4 | # modify it under the terms of the GNU Lesser General Public 5 | # License as published by the Free Software Foundation; either 6 | # version 2.1 of the License, or (at your option) any later version. 7 | # 8 | # This library is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | # Lesser General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Lesser General Public 14 | # License along with this library; if not, write to the Free Software 15 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | AS8051?=sdas8051 18 | CC=sdcc 19 | SDAR?=sdar 20 | SOURCES = serial.c i2c.c delay.c setupdat.c gpif.c eputils.c $(wildcard interrupts/*.c) 21 | FX2_OBJS = $(patsubst %.c,%.rel, $(SOURCES)) usbav.rel 22 | INCLUDES = -I../include 23 | SDCC = $(CC) -mmcs51 $(SDCCFLAGS) 24 | LIBS = fx2.lib 25 | 26 | all: $(LIBS) 27 | 28 | $(LIBS): $(FX2_OBJS) 29 | $(SDAR) -rc fx2.lib $? 30 | 31 | usbav.rel: usbav.a51 32 | $(AS8051) -logs usbav.a51 33 | 34 | %.rel: %.c 35 | $(SDCC) $(INCLUDES) -c $< -o $@ 36 | 37 | clean: 38 | rm -f $(foreach ext, asm ihx lnk lst map mem rel rst sym adb cdb lib, *.${ext} interrupts/*.${ext}) 39 | 40 | -------------------------------------------------------------------------------- /lib/delay.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | void delay(WORD millis) { 24 | /** 25 | * It takes 12 crystal pulses to make 1 machine cycle (8051.com) 26 | * ez-usb trm 1.13 27 | * 83.3 ns at 48mhz per instruction cycle 28 | * (assume 166.6ns at 24mhz) 29 | * (assume 333.3ns at 12mhz) 30 | * ez-usb trm 12.1 31 | * Includes the cycles for each instruction 32 | **/ 33 | WORD loop_count; 34 | volatile WORD count; // NOTE perhaps use different solutions w/ out volatile 35 | 36 | 37 | // set count to the number of times we need to 38 | // go around a loop for 1 millisecond 39 | 40 | // then do that loop millis times. (1000 us=1ms) 41 | 42 | // 48mhz: 1000 us / (17 cycles * 83.3 ns / cycle / 1000 ns/us) = 706 43 | // 24mhz: 353 44 | // 12mhz: 177 45 | // recalculate if the number of cycles changes 46 | // like if you change the loop below 47 | loop_count = CPUFREQ == CLK_12M ? 177 : 48 | CPUFREQ == CLK_24M ? 353 : 706; 49 | 50 | // sdcc generated assembly 51 | /* cycles code 52 | ; delay.c:31: do { 53 | 00101$: 54 | ; delay.c:32: } while ( --count ); 55 | 2 dec _delay_count_1_1 56 | 2 mov a,#0xff 57 | 4 cjne a,_delay_count_1_1,00121$ 58 | 2 dec (_delay_count_1_1 + 1) 59 | 00121$: 60 | 2 mov a,_delay_count_1_1 61 | 2 orl a,(_delay_count_1_1 + 1) 62 | 3 jnz 00101$ 63 | 64 | Total 17 65 | */ 66 | 67 | do { 68 | count = loop_count; 69 | do { 70 | } while ( --count ); 71 | } while ( --millis ); 72 | 73 | } 74 | -------------------------------------------------------------------------------- /lib/eputils.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | 20 | 21 | 22 | #include 23 | 24 | #include 25 | 26 | #ifdef DEBUG_EPUTILS 27 | #include 28 | #else 29 | #define printf(...) 30 | #endif 31 | 32 | void readep0( BYTE* dst, WORD len) { 33 | WORD read = 0; // n bytes read 34 | BYTE c,avail; 35 | while (read < len) { 36 | EP0BCH = 0; 37 | // NOTE need syncdelay? 38 | EP0BCL = 0; // re-arm ep so host can send more 39 | while (EP0CS & bmEPBUSY); 40 | avail = EP0BCL; // max size fits in one byte (64 bytes) 41 | for (c=0;c 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #define SYNCDELAY SYNCDELAY16 // using most conservative SYNCDELAY 27 | 28 | void gpif_init( BYTE* wavedata, BYTE* initdata ) { 29 | 30 | BYTE i; 31 | 32 | // Registers which require a synchronization delay, see section 15.14 33 | // FIFORESET FIFOPINPOLAR 34 | // INPKTEND OUTPKTEND 35 | // EPxBCH:L REVCTL 36 | // GPIFTCB3 GPIFTCB2 37 | // GPIFTCB1 GPIFTCB0 38 | // EPxFIFOPFH:L EPxAUTOINLENH:L 39 | // EPxFIFOCFG EPxGPIFFLGSEL 40 | // PINFLAGSxx EPxFIFOIRQ 41 | // EPxFIFOIE GPIFIRQ 42 | // GPIFIE GPIFADRH:L 43 | // UDMACRCH:L EPxGPIFTRIG 44 | // GPIFTRIG 45 | 46 | // Note: The pre-REVE EPxGPIFTCH/L register are affected, as well... 47 | // ...these have been replaced by GPIFTC[B3:B0] registers 48 | 49 | // 8051 doesn't have access to waveform memories 'til 50 | // the part is in GPIF mode. 51 | 52 | // IFCLKSRC=1 , FIFOs executes on internal clk source 53 | // xMHz=1 , 48MHz internal clk rate 54 | // IFCLKOE=0 , Don't drive IFCLK pin signal at 48MHz 55 | // IFCLKPOL=0 , Don't invert IFCLK pin signal from internal clk 56 | // ASYNC=1 , master samples asynchronous 57 | // GSTATE=1 , Drive GPIF states out on PORTE[2:0], debug WF 58 | // IFCFG[1:0]=10, FX2 in GPIF master mode IFCONFIG 59 | IFCONFIG &= ~0x03; // turn off IFCFG[1:0] 60 | IFCONFIG |= 0x02; // set's IFCFG[1:0] to 10 to put in GPIF master mode. 61 | 62 | 63 | GPIFABORT = 0xFF; // abort any waveforms pending 64 | 65 | GPIFREADYCFG = initdata[ 0 ]; 66 | GPIFCTLCFG = initdata[ 1 ]; 67 | GPIFIDLECS = initdata[ 2 ]; 68 | GPIFIDLECTL = initdata[ 3 ]; 69 | GPIFWFSELECT = initdata[ 5 ]; 70 | GPIFREADYSTAT = initdata[ 6 ]; 71 | 72 | // use dual autopointer feature... 73 | AUTOPTRSETUP = 0x07; // inc both pointers, 74 | // ...warning: this introduces pdata hole(s) 75 | // ...at E67B (XAUTODAT1) and E67C (XAUTODAT2) 76 | 77 | // source 78 | AUTOPTRH1 = MSB( (WORD)wavedata ); 79 | AUTOPTRL1 = LSB( (WORD)wavedata ); 80 | 81 | // destination 82 | AUTOPTRH2 = 0xE4; 83 | AUTOPTRL2 = 0x00; 84 | 85 | // transfer 86 | for ( i = 0x00; i < 128; i++ ) 87 | { 88 | EXTAUTODAT2 = EXTAUTODAT1; 89 | } 90 | 91 | // Configure GPIF Address pins, output initial value, 92 | // these instructions don't do anything on the 93 | // smaller chips (e.g., 56 pin model only has ports a,b,d) 94 | PORTCCFG = 0xFF; // [7:0] as alt. func. GPIFADR[7:0] 95 | OEC = 0xFF; // and as outputs 96 | PORTECFG |= 0x80; // [8] as alt. func. GPIFADR[8] 97 | OEE |= 0x80; // and as output 98 | 99 | // ...OR... tri-state GPIFADR[8:0] pins 100 | // PORTCCFG = 0x00; // [7:0] as port I/O 101 | // OEC = 0x00; // and as inputs 102 | // PORTECFG &= 0x7F; // [8] as port I/O 103 | // OEE &= 0x7F; // and as input 104 | 105 | // GPIF address pins update when GPIFADRH/L written 106 | SYNCDELAY; // 107 | GPIFADRH = 0x00; // bits[7:1] always 0 108 | SYNCDELAY; // 109 | GPIFADRL = 0x00; // point to PERIPHERAL address 0x0000 110 | 111 | // set the initial flowstates to be all 0 in case flow states are not used 112 | 113 | FLOWSTATE = 0; 114 | FLOWLOGIC = 0; 115 | FLOWEQ0CTL = 0; 116 | FLOWEQ1CTL = 0; 117 | FLOWHOLDOFF = 0; 118 | FLOWSTB = 0; 119 | FLOWSTBEDGE = 0; 120 | FLOWSTBHPERIOD = 0; 121 | } 122 | 123 | void gpif_setflowstate( BYTE* flowstates, BYTE bank) { 124 | BYTE base = 9*bank; 125 | FLOWSTATE = flowstates[ base ]; 126 | FLOWLOGIC = flowstates[ base+1 ]; 127 | FLOWEQ0CTL = flowstates[ base+2 ]; 128 | FLOWEQ1CTL = flowstates[ base+3 ]; 129 | FLOWHOLDOFF = flowstates[ base+4 ]; 130 | FLOWSTB = flowstates[ base+5 ]; 131 | FLOWSTBEDGE = flowstates[ base+6 ]; 132 | FLOWSTBHPERIOD = flowstates[ base+7 ]; 133 | } 134 | 135 | void gpif_set_tc32(DWORD tc) { 136 | GPIFTCB3 = MSB(MSW(tc)); 137 | SYNCDELAY; 138 | GPIFTCB2 = LSB(MSW(tc)); 139 | SYNCDELAY; 140 | GPIFTCB1 = MSB(LSW(tc)); 141 | SYNCDELAY; 142 | GPIFTCB0 = LSB(LSW(tc)); 143 | } 144 | void gpif_set_tc16(WORD tc) { 145 | GPIFTCB1= MSB(tc); 146 | SYNCDELAY; 147 | GPIFTCB0= LSB(tc); 148 | } 149 | 150 | 151 | void gpif_single_read16( WORD* res, WORD len ){ 152 | BYTE c; 153 | while (!(GPIFTRIG & 0x80)); // wait done 154 | // dummy read to trigger real read 155 | res[0] = XGPIFSGLDATLX; 156 | for (c=0;c 20 | 21 | void ep0ack_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep0in_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep0in_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep0out_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep0out_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep0ping_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep0ping_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep1in_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep1in_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep1out_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep1out_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep1ping_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep1ping_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep2_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep2_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep2ef_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep2ef_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep2ff_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep2ff_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep2isoerr_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep2isoerr_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep2pf_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep2pf_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep2ping_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep2ping_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep4_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep4_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep4ef_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep4ef_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep4ff_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep4ff_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep4isoerr_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep4isoerr_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep4pf_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep4pf_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep4ping_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep4ping_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep6_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep6_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep6ef_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep6ef_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep6ff_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep6ff_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep6isoerr_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep6isoerr_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep6pf_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep6pf_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep6ping_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep6ping_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep8_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep8_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep8ef_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep8ef_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep8ff_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep8ff_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep8isoerr_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep8isoerr_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep8pf_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep8pf_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ep8ping_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ep8ping_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/errlimit_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void errlimit_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/gpifdone_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void gpifdone_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/gpifwf_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void gpifwf_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/hispeed_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void hispeed_isr(void)__interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/ibn_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void ibn_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/sof_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void sof_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/spare_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void spare_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/sudav_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void sudav_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/suspend_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void suspend_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/sutok_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void sutok_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/interrupts/usbreset_isr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | #include 20 | 21 | void usbreset_isr(void) __interrupt {} 22 | 23 | -------------------------------------------------------------------------------- /lib/serial.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Ubixum, Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | **/ 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | /** 26 | * using the comp port implies that timer 2 will be used as 27 | * a baud rate generator. (Don't use timer 2) 28 | **/ 29 | void sio0_init( DWORD baud_rate ) __critical { // baud_rate max should be 57600 since int=2 bytes 30 | 31 | WORD hl; // hl value for reload 32 | BYTE mult; // multiplier for clock speed 33 | DWORD tmp; // scratch for mult/divide 34 | 35 | // 0 = 12mhz, 1=24mhz, 2=48mhz 36 | mult = CPUFREQ == CLK_12M ? 1 : 37 | CPUFREQ == CLK_24M ? 2 : 4; // since only 3 clock speeds, fast switch instead of doing 2^clock speed pow(2,clkspd) 38 | 39 | // set the clock rate 40 | // use clock 2 41 | RCLK=1;TCLK=1; 42 | 43 | // RCAP2H:L = 0xFFFF - CLKOUT / 32 x baud_rate 44 | 45 | // in order to round to nearest value.. 46 | // tmp * 2 // double 47 | // tmp / rate // do the divide 48 | // tmp + 1 // add one (which is like adding 1/2) 49 | // tmp / 2 // back to original rounded 50 | tmp = mult * 375000L * 2 ; 51 | tmp /= baud_rate; 52 | tmp += 1; 53 | tmp /= 2; 54 | 55 | hl = 0xFFFF - (WORD)tmp; 56 | 57 | RCAP2H= MSB(hl); 58 | // seems that the 24/48mhz calculations are always one less than suggested values 59 | // trm table 14-16 60 | RCAP2L= LSB(hl) + (mult>0?1:0); 61 | TR2=1; // start the timer 62 | 63 | // set up the serial port 64 | SM0 = 0; SM1=1;// serial mode 1 (asyncronous) 65 | SM2 = 0 ; // has to do with receiving 66 | REN = 1 ; // to enable receiving 67 | PCON |= 0x80; // SET SMOD0, baud rate doubler 68 | TI = 1; // we send initial byte 69 | 70 | } 71 | 72 | int getchar(void) { 73 | char c; 74 | while (!RI) 75 | ; 76 | c=SBUF0; 77 | RI=0; 78 | return c; 79 | } 80 | 81 | void _transchar(char c) { 82 | while ( !TI ); // wait for TI=1 83 | TI=0; 84 | SBUF0=c; 85 | } 86 | 87 | int putchar (char c) { 88 | if (c=='\n') _transchar('\r'); // transmit \r\n 89 | _transchar(c); 90 | if (c == '\r' ) _transchar('\n'); // transmit \r\n 91 | return c; 92 | } 93 | 94 | -------------------------------------------------------------------------------- /lib/usbav.a51: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2010 Ubixum, Inc. 2 | ; 3 | ; This library is free software; you can redistribute it and/or 4 | ; modify it under the terms of the GNU Lesser General Public 5 | ; License as published by the Free Software Foundation; either 6 | ; version 2.1 of the License, or (at your option) any later version. 7 | ; 8 | ; This library is distributed in the hope that it will be useful, 9 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | ; Lesser General Public License for more details. 12 | ; 13 | ; You should have received a copy of the GNU Lesser General Public 14 | ; License along with this library; if not, write to the Free Software 15 | ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | .module INT2AV ; jump table for usb auto vector 18 | 19 | ; INT2 Jump Table 20 | .globl _usb_isr ; define jump target for interrupt 8 (USB) 21 | .globl _gpif_isr ; define jump target for interrupt 10 (GPIF) 22 | 23 | .area INT2JT ( CODE ) 24 | ;.org 0x1A00 ; needs to be on a page boundary 25 | 26 | _gpif_isr: 27 | _usb_isr: 28 | ljmp _sudav_isr 29 | .db 0 30 | ljmp _sof_isr 31 | .db 0 32 | ljmp _sutok_isr 33 | .db 0 34 | ljmp _suspend_isr 35 | .db 0 36 | ljmp _usbreset_isr 37 | .db 0 38 | ljmp _hispeed_isr 39 | .db 0 40 | ljmp _ep0ack_isr 41 | .db 0 42 | ljmp _spare_isr 43 | .db 0 44 | ljmp _ep0in_isr 45 | .db 0 46 | ljmp _ep0out_isr 47 | .db 0 48 | ljmp _ep1in_isr 49 | .db 0 50 | ljmp _ep1out_isr 51 | .db 0 52 | ljmp _ep2_isr 53 | .db 0 54 | ljmp _ep4_isr 55 | .db 0 56 | ljmp _ep6_isr 57 | .db 0 58 | ljmp _ep8_isr 59 | .db 0 60 | ljmp _ibn_isr 61 | .db 0 62 | ljmp _spare_isr 63 | .db 0 64 | ljmp _ep0ping_isr 65 | .db 0 66 | ljmp _ep1ping_isr 67 | .db 0 68 | ljmp _ep2ping_isr 69 | .db 0 70 | ljmp _ep4ping_isr 71 | .db 0 72 | ljmp _ep6ping_isr 73 | .db 0 74 | ljmp _ep8ping_isr 75 | .db 0 76 | ljmp _errlimit_isr 77 | .db 0 78 | ljmp _spare_isr 79 | .db 0 80 | ljmp _spare_isr 81 | .db 0 82 | ljmp _spare_isr 83 | .db 0 84 | ljmp _ep2isoerr_isr 85 | .db 0 86 | ljmp _ep4isoerr_isr 87 | .db 0 88 | ljmp _ep6isoerr_isr 89 | .db 0 90 | ljmp _ep8isoerr_isr 91 | .db 0 92 | ; INT4JT 93 | ljmp _ep2pf_isr 94 | .db 0 95 | ljmp _ep4pf_isr 96 | .db 0 97 | ljmp _ep6pf_isr 98 | .db 0 99 | ljmp _ep8pf_isr 100 | .db 0 101 | ljmp _ep2ef_isr 102 | .db 0 103 | ljmp _ep4ef_isr 104 | .db 0 105 | ljmp _ep6ef_isr 106 | .db 0 107 | ljmp _ep8ef_isr 108 | .db 0 109 | ljmp _ep2ff_isr 110 | .db 0 111 | ljmp _ep4ff_isr 112 | .db 0 113 | ljmp _ep6ff_isr 114 | .db 0 115 | ljmp _ep8ff_isr 116 | .db 0 117 | ljmp _gpifdone_isr 118 | .db 0 119 | ljmp _gpifwf_isr 120 | .db 0 121 | 122 | -------------------------------------------------------------------------------- /utils/gpif2dat: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | 3 | import sys,re 4 | 5 | if __name__=='__main__': 6 | if len(sys.argv)<3: 7 | print "Usage: %s " % sys.argv[0] 8 | sys.exit(-1) 9 | 10 | f=open(sys.argv[1],'r').read() 11 | o=open(sys.argv[2],'w') 12 | 13 | # write every thing between the wave data and the TODO 14 | datre = re.compile ( 'const char xdata .*?\};', re.S ) 15 | data = datre.findall(f) 16 | for dat in data: 17 | o.write(dat.replace('\r\n','\n')) 18 | o.write('\n') 19 | o.close() 20 | 21 | -------------------------------------------------------------------------------- /utils/ihx2iic.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2009, Ubixum, Inc 4 | # 5 | # This file copied and modified for fx2lib from the GnuRadio project 6 | # 7 | # Copyright 2004,2006 Free Software Foundation, Inc. 8 | # 9 | # This file is part of GNU Radio 10 | # 11 | # GNU Radio is free software; you can redistribute it and/or modify 12 | # it under the terms of the GNU General Public License as published by 13 | # the Free Software Foundation; either version 3, or (at your option) 14 | # any later version. 15 | # 16 | # GNU Radio is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with GNU Radio; see the file COPYING. If not, write to 23 | # the Free Software Foundation, Inc., 51 Franklin Street, 24 | # Boston, MA 02110-1301, USA. 25 | # 26 | 27 | import re 28 | import sys, struct 29 | import os, os.path 30 | from optparse import OptionParser 31 | from functools import reduce 32 | 33 | 34 | def hex_to_bytes (s): 35 | if len (s) & 0x1: 36 | raise ValueError("Length must be even") 37 | r = [] 38 | for i in range (0, len(s), 2): 39 | r.append (int (s[i:i+2], 16)) 40 | return r 41 | 42 | def msb (x): 43 | return (x >> 8) & 0xff 44 | 45 | def lsb (x): 46 | return x & 0xff 47 | 48 | class ihx_rec (object): 49 | def __init__ (self, addr, type, data): 50 | self.addr = addr 51 | self.type = type 52 | self.data = data 53 | 54 | class ihx_file (object): 55 | def __init__ (self): 56 | self.pat = re.compile (r':[0-9A-F]{10,}') 57 | def read (self, file): 58 | r = [] 59 | for line in file: 60 | line = line.strip().upper () 61 | if not self.pat.match (line): 62 | raise ValueError("Invalid hex record format") 63 | bytes = hex_to_bytes (line[1:]) 64 | sum = reduce (lambda x, y: x + y, bytes, 0) % 256 65 | if sum != 0: 66 | raise ValueError("Bad hex checksum") 67 | lenx = bytes[0] 68 | addr = (bytes[1] << 8) + bytes[2] 69 | type = bytes[3] 70 | data = bytes[4:-1] 71 | if lenx != len (data): 72 | raise ValueError("Invalid hex record (bad length)") 73 | if type != 0: 74 | break; 75 | r.append (ihx_rec (addr, type, data)) 76 | 77 | return r 78 | 79 | 80 | def build_eeprom_image (filename, outfile,vid,pid,devid,cb): 81 | """Build a ``C2 Load'' EEPROM image. 82 | 83 | For details on this format, see section 3.4.3 of 84 | the EZ-USB FX2 Technical Reference Manual 85 | """ 86 | 87 | image = [ 88 | 0xC2, # boot from EEPROM 89 | lsb (vid), 90 | msb (vid), 91 | lsb (pid), 92 | msb (pid), 93 | lsb (devid), 94 | msb (devid), 95 | cb # configuration byte 96 | ] 97 | 98 | # you could just append all the records.. 99 | # but that would most likely cause a lot of 100 | # extra headers/addrs to be written 101 | ihx = ihx_file(); 102 | records = ihx.read(open(filename)) 103 | 104 | # create image map of all values we're writing data too 105 | image_map={} 106 | for r in records: 107 | addr=r.addr 108 | c=0 109 | l=len(r.data) 110 | while c