o add first working draft of usb version
o having bad sync problems only can use 4 bytes buffer, supper slow
This commit is contained in:
parent
d481bd5061
commit
af48032798
92
list.txt
92
list.txt
@ -1,92 +0,0 @@
|
|||||||
/Volumes/MEDIA/games/snes/All-American Championship Football (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Arcade's Greatest Hits (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Arkanoid - Doh It Again (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Arkanoid - Doh it Again (E) [T+Ger1.00_Star].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Asterix (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Beethoven's 2nd (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Blazing Skies (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Blues Brothers, The (Beta) [h1].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Blues Brothers, The (Beta).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Blues Brothers, The (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Blues Brothers, The (E) [h1].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Blues Brothers, The (E) [t1].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Brainies, The (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Chessmaster, The (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Choplifter III (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Congo's Caper (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Dragon's Lair (E) [o1][h1].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Dragon's Lair (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Eric Cantona Football Challenge (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Euro Football Champ (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/First Samurai (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/First Samurai (E) [a1].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Goof Troop (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Gunforce - Battle Fire Engulfed Terror Island (E) [f1].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Gunforce - Battle Fire Engulfed Terror Island (E) [t1].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Gunforce - Battle Fire Engulfed Terror Island (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Hanna Barbera's Turbo Toons (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Harley's Humongous Adventure (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Hebereke's Popoitto (E) [f1].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Hebereke's Popoitto (E) [hI].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Hebereke's Popoitto (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Home Alone (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Home Alone 2 - Lost in New York (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Home Alone 2 - Lost in New York (E) [T+Spa].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Hunt for Red October, The (E) [f1].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Hunt for Red October, The (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Hunt for Red October, The (U) [T+Ita].smc
|
|
||||||
/Volumes/MEDIA/games/snes/HyperZone (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Incantation (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/James Bond Jr (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/James Pond's Crazy Sports (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Jimmy Connors Pro Tennis Tour (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/King Arthur's World (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Krusty's Super Fun House (E) [a1].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Lamborghini - American Challenge (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Magic Boy (Beta).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Magic Boy (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Micro Machines (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/NHLPA Hockey '93 (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Oscar (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Pac-Attack (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Paperboy 2 (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Pilotwings (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Pit Fighter (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Populous (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Push-Over (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Puzzle Bobble (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Race Drivin' (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Road Riot 4WD (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Sink or Swim (E) [t1].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Sink or Swim (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Spanky's Quest (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Striker (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Air Diver (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Air Diver (E) [b1].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Air Diver (E) [b2].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Battleship (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Battletank (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Bomberman (E) [f1].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Bomberman (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super James Pond II (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Off Road (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Pang (E) [T+Spa100_Ereza].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Pang (E) [T+Spa].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Pang (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Smash T.V. (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Soccer (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Soccer (E) [T+Spa].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Solitaire (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Tennis (E) (V1.0).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Tennis (E) (V1.1) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Troll Islands (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Super Turrican (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/TKO Super Championship Boxing (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Top Gear (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Top Gear (E) [T+Spa100%_Tanero].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Troddlers (Beta).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Troddlers (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/Ultraman - Towards the Future (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/World Class Rugby (E) [!].smc
|
|
||||||
/Volumes/MEDIA/games/snes/X Zone (E).smc
|
|
||||||
/Volumes/MEDIA/games/snes/Yoshi's Cookie (E).smc
|
|
||||||
@ -182,7 +182,7 @@ AVRDUDE_PROGRAMMER = stk500v2
|
|||||||
|
|
||||||
# com1 = serial port. Use lpt1 to connect to parallel port.
|
# com1 = serial port. Use lpt1 to connect to parallel port.
|
||||||
|
|
||||||
AVRDUDE_PORT = /dev/tty.PL2303-00001124
|
AVRDUDE_PORT =/dev/tty.PL2303-00001124
|
||||||
|
|
||||||
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
|
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ extern FILE uart_stdout;
|
|||||||
#define RAM_REG PINA
|
#define RAM_REG PINA
|
||||||
|
|
||||||
#define CTRL_PORT PORTB
|
#define CTRL_PORT PORTB
|
||||||
#define CTR_DIR DDRB
|
#define CTRL_DIR DDRB
|
||||||
#define LATCH_PORT PORTB
|
#define LATCH_PORT PORTB
|
||||||
#define LATCH_DIR DDRB
|
#define LATCH_DIR DDRB
|
||||||
|
|
||||||
@ -42,10 +42,10 @@ extern FILE uart_stdout;
|
|||||||
//#define FILENAME "sprite.raw" //ok
|
//#define FILENAME "sprite.raw" //ok
|
||||||
//#define FILENAME "ascii.smc" //ok
|
//#define FILENAME "ascii.smc" //ok
|
||||||
//#define FILENAME "rom.smc" //ok
|
//#define FILENAME "rom.smc" //ok
|
||||||
//#define FILENAME "supert.smc"
|
//#define FILENAME "supert.smc" //ok
|
||||||
//#define FILENAME "vortex.smc"
|
//#define FILENAME "vortex.smc" //failed
|
||||||
//#define FILENAME "mrdo.smc"
|
//#define FILENAME "mrdo.smc" //failed
|
||||||
//#define FILENAME "spacei.smc"
|
//#define FILENAME "spacei.smc" //ok ntsc
|
||||||
//#define FILENAME "bank01.smc" //ok
|
//#define FILENAME "bank01.smc" //ok
|
||||||
//#define FILENAME "bank02.smc" //ok
|
//#define FILENAME "bank02.smc" //ok
|
||||||
//#define FILENAME "bank03.smc" //ok
|
//#define FILENAME "bank03.smc" //ok
|
||||||
@ -56,9 +56,14 @@ extern FILE uart_stdout;
|
|||||||
//#define FILENAME "banklo.smc" //ok
|
//#define FILENAME "banklo.smc" //ok
|
||||||
//#define FILENAME "bankhi.smc" //ok
|
//#define FILENAME "bankhi.smc" //ok
|
||||||
//#define FILENAME "vram2.smc" //ok
|
//#define FILENAME "vram2.smc" //ok
|
||||||
//#define FILENAME "super02.smc"
|
//#define FILENAME "super02.smc" //ok
|
||||||
#define FILENAME "crc.smc"
|
//#define FILENAME "super01.smc"//ok
|
||||||
//#define FILENAME "banks.smc"
|
//#define FILENAME "crc.smc" //ok
|
||||||
|
//#define FILENAME "banks.smc" //ok
|
||||||
|
//#define FILENAME "hungry.smc" //ok
|
||||||
|
//#define FILENAME "arkanoid.smc"//ok
|
||||||
|
//#define FILENAME "eric.smc"
|
||||||
|
#define FILENAME "turrican.smc"
|
||||||
|
|
||||||
#define ROMSIZE 4
|
#define ROMSIZE 4
|
||||||
#define DUMPNAME "dump256.smc"
|
#define DUMPNAME "dump256.smc"
|
||||||
@ -233,18 +238,28 @@ void sram_init(void){
|
|||||||
RAM_DIR = 0x00;
|
RAM_DIR = 0x00;
|
||||||
RAM_PORT = 0x00;
|
RAM_PORT = 0x00;
|
||||||
|
|
||||||
CTR_DIR |= ((1<<R_WR) | (1<<R_RD));
|
CTRL_DIR |= ((1<<R_WR) | (1<<R_RD));
|
||||||
CTRL_PORT |= (1<<R_RD);
|
CTRL_PORT |= (1<<R_RD);
|
||||||
CTRL_PORT |= (1<<R_WR);
|
CTRL_PORT |= (1<<R_WR);
|
||||||
|
|
||||||
LED_PORT |= (1<<D_LED0);
|
LED_PORT |= (1<<D_LED0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sram_snes_mode(void){
|
void sram_snes_mode01(void){
|
||||||
CTRL_PORT |= (1<<R_WR);
|
CTRL_PORT |= (1<<R_WR);
|
||||||
CTRL_PORT &= ~(1<<R_RD);
|
CTRL_PORT &= ~(1<<R_RD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sram_snes_mode02(void){
|
||||||
|
CTRL_DIR |= (1<<R_WR);
|
||||||
|
CTRL_PORT |= (1<<R_WR);
|
||||||
|
//CTRL_PORT &= ~(1<<R_RD);
|
||||||
|
CTRL_DIR &= ~(1<<R_RD);
|
||||||
|
CTRL_PORT &= ~(1<<R_RD);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void sram_clear(uint32_t addr, uint32_t len){
|
void sram_clear(uint32_t addr, uint32_t len){
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
@ -426,8 +441,17 @@ int main(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sram_snes_mode();
|
#if 0
|
||||||
printf("\nEnter Snes mode\n");
|
sram_snes_mode01();
|
||||||
|
printf("\nEnter Snes mode 02\n");
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
|
sram_snes_mode02();
|
||||||
|
printf("\nEnter Snes mode 02\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
printf("\nUpload done.\n");
|
||||||
|
|
||||||
while(1);
|
while(1);
|
||||||
return 0 ;
|
return 0 ;
|
||||||
|
|
||||||
|
|||||||
@ -7,14 +7,14 @@
|
|||||||
# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
||||||
# This Revision: $Id: Makefile 692 2008-11-07 15:07:40Z cs $
|
# This Revision: $Id: Makefile 692 2008-11-07 15:07:40Z cs $
|
||||||
|
|
||||||
DEVICE = atmega168
|
DEVICE = atmega16
|
||||||
F_CPU = 16000000 # in Hz
|
F_CPU = 16000000 # in Hz
|
||||||
FUSE_L = # see below for fuse values for particular devices
|
FUSE_L = # see below for fuse values for particular devices
|
||||||
FUSE_H =
|
FUSE_H =
|
||||||
AVRDUDE = avrdude -c usbasp -p $(DEVICE) # edit this line for your programmer
|
AVRDUDE = avrdude -c stk500v2 -p $(DEVICE) -P /dev/tty.PL2303-00002006
|
||||||
|
|
||||||
CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0
|
CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0
|
||||||
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o
|
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o uart.o fifo.o sram.o crc.o debug.o
|
||||||
|
|
||||||
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
|
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
|
||||||
|
|
||||||
@ -107,6 +107,8 @@ help:
|
|||||||
@echo "make flash ..... to flash the firmware (use this on metaboard)"
|
@echo "make flash ..... to flash the firmware (use this on metaboard)"
|
||||||
@echo "make clean ..... to delete objects and hex file"
|
@echo "make clean ..... to delete objects and hex file"
|
||||||
|
|
||||||
|
all: hex
|
||||||
|
|
||||||
hex: main.hex
|
hex: main.hex
|
||||||
|
|
||||||
program: flash fuse
|
program: flash fuse
|
||||||
|
|||||||
@ -8,8 +8,8 @@
|
|||||||
# Revision: $Id: checksize 83 2006-01-05 22:20:53Z cs $
|
# Revision: $Id: checksize 83 2006-01-05 22:20:53Z cs $
|
||||||
|
|
||||||
error=0
|
error=0
|
||||||
codelimit=2048 # default value
|
codelimit=16384 # default value
|
||||||
datalimit=96 # default value; leave 32 bytes for stack
|
datalimit=992 # default value; leave 32 bytes for stack
|
||||||
|
|
||||||
if [ $# -gt 1 ]; then
|
if [ $# -gt 1 ]; then
|
||||||
codelimit="$2"
|
codelimit="$2"
|
||||||
|
|||||||
@ -22,7 +22,7 @@ EXE_SUFFIX =
|
|||||||
#USBLIBS = -L/usr/local/lib -lusb
|
#USBLIBS = -L/usr/local/lib -lusb
|
||||||
#EXE_SUFFIX = .exe
|
#EXE_SUFFIX = .exe
|
||||||
|
|
||||||
NAME = set-led
|
NAME = snesuploader
|
||||||
|
|
||||||
OBJECTS = opendevice.o $(NAME).o
|
OBJECTS = opendevice.o $(NAME).o
|
||||||
|
|
||||||
|
|||||||
@ -1,135 +0,0 @@
|
|||||||
/* Name: set-led.c
|
|
||||||
* Project: custom-class, a basic USB example
|
|
||||||
* Author: Christian Starkjohann
|
|
||||||
* Creation Date: 2008-04-10
|
|
||||||
* Tabsize: 4
|
|
||||||
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
|
||||||
* This Revision: $Id: set-led.c 692 2008-11-07 15:07:40Z cs $
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
General Description:
|
|
||||||
This is the host-side driver for the custom-class example device. It searches
|
|
||||||
the USB for the LEDControl device and sends the requests understood by this
|
|
||||||
device.
|
|
||||||
This program must be linked with libusb on Unix and libusb-win32 on Windows.
|
|
||||||
See http://libusb.sourceforge.net/ or http://libusb-win32.sourceforge.net/
|
|
||||||
respectively.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <usb.h> /* this is libusb */
|
|
||||||
#include "opendevice.h" /* common code moved to separate module */
|
|
||||||
|
|
||||||
#include "../requests.h" /* custom request numbers */
|
|
||||||
#include "../usbconfig.h" /* device's VID/PID and names */
|
|
||||||
|
|
||||||
static void usage(char *name)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "usage:\n");
|
|
||||||
fprintf(stderr, " %s on ....... turn on LED\n", name);
|
|
||||||
fprintf(stderr, " %s off ...... turn off LED\n", name);
|
|
||||||
fprintf(stderr, " %s status ... ask current status of LED\n", name);
|
|
||||||
#if ENABLE_TEST
|
|
||||||
fprintf(stderr, " %s test ..... run driver reliability test\n", name);
|
|
||||||
#endif /* ENABLE_TEST */
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
usb_dev_handle *handle = NULL;
|
|
||||||
const unsigned char rawVid[2] = {USB_CFG_VENDOR_ID}, rawPid[2] = {USB_CFG_DEVICE_ID};
|
|
||||||
char vendor[] = {USB_CFG_VENDOR_NAME, 0}, product[] = {USB_CFG_DEVICE_NAME, 0};
|
|
||||||
char buffer[4];
|
|
||||||
int cnt, vid, pid, isOn;
|
|
||||||
|
|
||||||
usb_init();
|
|
||||||
if(argc < 2){ /* we need at least one argument */
|
|
||||||
usage(argv[0]);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
/* compute VID/PID from usbconfig.h so that there is a central source of information */
|
|
||||||
vid = rawVid[1] * 256 + rawVid[0];
|
|
||||||
pid = rawPid[1] * 256 + rawPid[0];
|
|
||||||
/* The following function is in opendevice.c: */
|
|
||||||
if(usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){
|
|
||||||
fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
/* Since we use only control endpoint 0, we don't need to choose a
|
|
||||||
* configuration and interface. Reading device descriptor and setting a
|
|
||||||
* configuration and interface is done through endpoint 0 after all.
|
|
||||||
* However, newer versions of Linux require that we claim an interface
|
|
||||||
* even for endpoint 0. Enable the following code if your operating system
|
|
||||||
* needs it: */
|
|
||||||
#if 0
|
|
||||||
int retries = 1, usbConfiguration = 1, usbInterface = 0;
|
|
||||||
if(usb_set_configuration(handle, usbConfiguration) && showWarnings){
|
|
||||||
fprintf(stderr, "Warning: could not set configuration: %s\n", usb_strerror());
|
|
||||||
}
|
|
||||||
/* now try to claim the interface and detach the kernel HID driver on
|
|
||||||
* Linux and other operating systems which support the call. */
|
|
||||||
while((len = usb_claim_interface(handle, usbInterface)) != 0 && retries-- > 0){
|
|
||||||
#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
|
|
||||||
if(usb_detach_kernel_driver_np(handle, 0) < 0 && showWarnings){
|
|
||||||
fprintf(stderr, "Warning: could not detach kernel driver: %s\n", usb_strerror());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(strcasecmp(argv[1], "status") == 0){
|
|
||||||
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_STATUS, 0, 0, buffer, sizeof(buffer), 5000);
|
|
||||||
if(cnt < 1){
|
|
||||||
if(cnt < 0){
|
|
||||||
fprintf(stderr, "USB error: %s\n", usb_strerror());
|
|
||||||
}else{
|
|
||||||
fprintf(stderr, "only %d bytes received.\n", cnt);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
printf("LED is %s\n", buffer[0] ? "on" : "off");
|
|
||||||
}
|
|
||||||
}else if((isOn = (strcasecmp(argv[1], "on") == 0)) || strcasecmp(argv[1], "off") == 0){
|
|
||||||
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, isOn, 0, buffer, 0, 5000);
|
|
||||||
if(cnt < 0){
|
|
||||||
fprintf(stderr, "USB error: %s\n", usb_strerror());
|
|
||||||
}
|
|
||||||
#if ENABLE_TEST
|
|
||||||
}else if(strcasecmp(argv[1], "test") == 0){
|
|
||||||
int i;
|
|
||||||
srandomdev();
|
|
||||||
for(i = 0; i < 50000; i++){
|
|
||||||
int value = random() & 0xffff, index = random() & 0xffff;
|
|
||||||
int rxValue, rxIndex;
|
|
||||||
if((i+1) % 100 == 0){
|
|
||||||
fprintf(stderr, "\r%05d", i+1);
|
|
||||||
fflush(stderr);
|
|
||||||
}
|
|
||||||
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_ECHO, value, index, buffer, sizeof(buffer), 5000);
|
|
||||||
if(cnt < 0){
|
|
||||||
fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, usb_strerror());
|
|
||||||
break;
|
|
||||||
}else if(cnt != 4){
|
|
||||||
fprintf(stderr, "\nerror in iteration %d: %d bytes received instead of 4\n", i, cnt);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
rxValue = ((int)buffer[0] & 0xff) | (((int)buffer[1] & 0xff) << 8);
|
|
||||||
rxIndex = ((int)buffer[2] & 0xff) | (((int)buffer[3] & 0xff) << 8);
|
|
||||||
if(rxValue != value || rxIndex != index){
|
|
||||||
fprintf(stderr, "\ndata error in iteration %d:\n", i);
|
|
||||||
fprintf(stderr, "rxValue = 0x%04x value = 0x%04x\n", rxValue, value);
|
|
||||||
fprintf(stderr, "rxIndex = 0x%04x index = 0x%04x\n", rxIndex, index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(stderr, "\nTest completed.\n");
|
|
||||||
#endif /* ENABLE_TEST */
|
|
||||||
}else{
|
|
||||||
usage(argv[0]);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
usb_close(handle);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
162
poc/avr_usbload/commandline/snesuploader.c
Normal file
162
poc/avr_usbload/commandline/snesuploader.c
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
/* Name: set-led.c
|
||||||
|
* Project: custom-class, a basic USB example
|
||||||
|
* Author: Christian Starkjohann
|
||||||
|
* Creation Date: 2008-04-10
|
||||||
|
* Tabsize: 4
|
||||||
|
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
|
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
||||||
|
* This Revision: $Id: set-led.c 692 2008-11-07 15:07:40Z cs $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
General Description:
|
||||||
|
This is the host-side driver for the custom-class example device. It searches
|
||||||
|
the USB for the LEDControl device and sends the requests understood by this
|
||||||
|
device.
|
||||||
|
This program must be linked with libusb on Unix and libusb-win32 on Windows.
|
||||||
|
See http://libusb.sourceforge.net/ or http://libusb-win32.sourceforge.net/
|
||||||
|
respectively.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#define BUFFER_SIZE 8
|
||||||
|
#define BUFFER_CRC (1024 * 64)
|
||||||
|
#define BANK_SIZE (1<<15)
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <usb.h> /* this is libusb */
|
||||||
|
#include "opendevice.h" /* common code moved to separate module */
|
||||||
|
|
||||||
|
#include "../requests.h" /* custom request numbers */
|
||||||
|
#include "../usbconfig.h" /* device's VID/PID and names */
|
||||||
|
|
||||||
|
uint16_t crc_xmodem_update (uint16_t crc, uint8_t data){
|
||||||
|
int i;
|
||||||
|
crc = crc ^ ((uint16_t)data << 8);
|
||||||
|
for (i=0; i<8; i++)
|
||||||
|
{
|
||||||
|
if (crc & 0x8000)
|
||||||
|
crc = (crc << 1) ^ 0x1021;
|
||||||
|
else
|
||||||
|
crc <<= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t do_crc(uint8_t * data,uint16_t size){
|
||||||
|
uint16_t crc =0;
|
||||||
|
uint16_t i;
|
||||||
|
for (i=0; i<size; i++){
|
||||||
|
crc = crc_xmodem_update(crc,data[i]);
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t do_crc_update(uint16_t crc,uint8_t * data,uint16_t size){
|
||||||
|
uint16_t i;
|
||||||
|
for (i=0; i<size; i++)
|
||||||
|
crc = crc_xmodem_update(crc,data[i]);
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void usage(char *name)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "usage:\n");
|
||||||
|
fprintf(stderr, " %s upload filename.. upload\n", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
usb_dev_handle *handle = NULL;
|
||||||
|
const unsigned char rawVid[2] = {USB_CFG_VENDOR_ID}, rawPid[2] = {USB_CFG_DEVICE_ID};
|
||||||
|
char vendor[] = {USB_CFG_VENDOR_NAME, 0}, product[] = {USB_CFG_DEVICE_NAME, 0};
|
||||||
|
int cnt, vid, pid;
|
||||||
|
int cnt_crc = 0;
|
||||||
|
unsigned char *read_buffer;
|
||||||
|
unsigned char *crc_buffer;
|
||||||
|
unsigned char setup_buffer[8];
|
||||||
|
unsigned int addr = 0;
|
||||||
|
unsigned int bank_addr;
|
||||||
|
unsigned int bank_num;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
FILE *fp ;
|
||||||
|
|
||||||
|
usb_init();
|
||||||
|
if(argc < 2){ /* we need at least one argument */
|
||||||
|
usage(argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
/* compute VID/PID from usbconfig.h so that there is a central source of information */
|
||||||
|
vid = rawVid[1] * 256 + rawVid[0];
|
||||||
|
pid = rawPid[1] * 256 + rawPid[0];
|
||||||
|
/* The following function is in opendevice.c: */
|
||||||
|
if(usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){
|
||||||
|
fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strcasecmp(argv[1], "upload") == 0){
|
||||||
|
if(argc < 3){ /* we need at least one argument */
|
||||||
|
usage(argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
fp = fopen (argv[2],"r") ;
|
||||||
|
if (fp==NULL){
|
||||||
|
fprintf(stderr, "Cannot open file %s ", argv[2]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
read_buffer = (unsigned char*)malloc(BUFFER_SIZE);
|
||||||
|
crc_buffer = (unsigned char*)malloc(BUFFER_CRC);
|
||||||
|
memset(crc_buffer,0,BUFFER_CRC);
|
||||||
|
addr = 0x000000;
|
||||||
|
bank_addr = addr& 0xffff;
|
||||||
|
bank_num = (addr>>16) & 0xff;
|
||||||
|
|
||||||
|
while((cnt = fread(read_buffer, BUFFER_SIZE, 1, fp)) > 0){
|
||||||
|
bank_addr = addr& 0xffff;
|
||||||
|
bank_num = (addr>>16) & 0xff;
|
||||||
|
|
||||||
|
memcpy(crc_buffer + cnt_crc,read_buffer,BUFFER_SIZE);
|
||||||
|
cnt_crc += BUFFER_SIZE;
|
||||||
|
if (cnt_crc == BANK_SIZE){
|
||||||
|
crc = do_crc(crc_buffer,BANK_SIZE);
|
||||||
|
printf("Addr: 0x%06x Bank: 0x%02x Rom Addr: 0x%04x Addr: 0x%06x Cnt: 0x%04x\n",addr,bank_num, bank_addr, addr,crc);
|
||||||
|
memset(crc_buffer,0,BUFFER_CRC);
|
||||||
|
cnt_crc =0;
|
||||||
|
}
|
||||||
|
usb_control_msg(handle,
|
||||||
|
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,
|
||||||
|
CUSTOM_RQ_UPLOAD, bank_num, bank_addr,
|
||||||
|
(char*) read_buffer, BUFFER_SIZE,
|
||||||
|
5000);
|
||||||
|
addr += BUFFER_SIZE;
|
||||||
|
//printf("Addr: 0x%06x Bank: 0x%02x Rom Addr: 0x%04x Addr: 0x%06x Cnt: 0x%04x cnt: %i\n",addr,bank_num, bank_addr, addr,crc,cnt_crc);
|
||||||
|
}
|
||||||
|
cnt = usb_control_msg(handle,
|
||||||
|
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,
|
||||||
|
CUSTOM_RQ_CRC_CHECK, bank_num + 1, 0,
|
||||||
|
(char*) setup_buffer, sizeof(setup_buffer),
|
||||||
|
5000);
|
||||||
|
|
||||||
|
if(cnt < 1){
|
||||||
|
if(cnt < 0){
|
||||||
|
fprintf(stderr, "USB error: %s\n", usb_strerror());
|
||||||
|
}else{
|
||||||
|
fprintf(stderr, "only %d bytes received.\n", cnt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
usage(argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
usb_close(handle);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
43
poc/avr_usbload/crc.c
Normal file
43
poc/avr_usbload/crc.c
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "crc.h"
|
||||||
|
#include "uart.h"
|
||||||
|
|
||||||
|
extern FILE uart_stdout;
|
||||||
|
|
||||||
|
uint16_t crc_xmodem_update (uint16_t crc, uint8_t data)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
crc = crc ^ ((uint16_t)data << 8);
|
||||||
|
for (i=0; i<8; i++)
|
||||||
|
{
|
||||||
|
if (crc & 0x8000)
|
||||||
|
crc = (crc << 1) ^ 0x1021;
|
||||||
|
else
|
||||||
|
crc <<= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t do_crc(uint8_t * data,uint16_t size)
|
||||||
|
{
|
||||||
|
uint16_t crc =0;
|
||||||
|
uint16_t i;
|
||||||
|
for (i=0; i<size; i++){
|
||||||
|
crc = crc_xmodem_update(crc,data[i]);
|
||||||
|
//printf("%x : %x\n",crc,data[i]);
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t do_crc_update(uint16_t crc,uint8_t * data,uint16_t size)
|
||||||
|
{
|
||||||
|
uint16_t i;
|
||||||
|
for (i=0; i<size; i++)
|
||||||
|
crc = crc_xmodem_update(crc,data[i]);
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
7
poc/avr_usbload/crc.h
Normal file
7
poc/avr_usbload/crc.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t crc_xmodem_update (uint16_t crc, uint8_t data);
|
||||||
|
uint16_t do_crc(uint8_t * data,uint16_t size);
|
||||||
|
uint16_t do_crc_update(uint16_t crc,uint8_t * data,uint16_t size);
|
||||||
42
poc/avr_usbload/debug.c
Normal file
42
poc/avr_usbload/debug.c
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
#include "uart.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern FILE uart_stdout;
|
||||||
|
|
||||||
|
void dump_packet(uint32_t addr,uint32_t len,uint8_t *packet){
|
||||||
|
uint16_t i,j;
|
||||||
|
uint16_t sum = 0;
|
||||||
|
uint8_t clear=0;
|
||||||
|
|
||||||
|
for (i=0;i<len;i+=16) {
|
||||||
|
|
||||||
|
sum = 0;
|
||||||
|
for (j=0;j<16;j++) {
|
||||||
|
sum +=packet[i+j];
|
||||||
|
}
|
||||||
|
if (!sum){
|
||||||
|
clear=1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (clear){
|
||||||
|
printf("*\n");
|
||||||
|
clear = 0;
|
||||||
|
}
|
||||||
|
printf("%08lx:", addr + i);
|
||||||
|
for (j=0;j<16;j++) {
|
||||||
|
printf(" %02x", packet[i+j]);
|
||||||
|
}
|
||||||
|
printf(" |");
|
||||||
|
for (j=0;j<16;j++) {
|
||||||
|
if (packet[i+j]>=33 && packet[i+j]<=126 )
|
||||||
|
printf("%c", packet[i+j]);
|
||||||
|
else
|
||||||
|
printf(".");
|
||||||
|
}
|
||||||
|
printf("|\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
5
poc/avr_usbload/debug.h
Normal file
5
poc/avr_usbload/debug.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void dump_packet(uint32_t addr,uint32_t len,uint8_t *packet);
|
||||||
|
|
||||||
@ -1,95 +1,121 @@
|
|||||||
/* Name: main.c
|
|
||||||
* Project: custom-class, a basic USB example
|
|
||||||
* Author: Christian Starkjohann
|
|
||||||
* Creation Date: 2008-04-09
|
|
||||||
* Tabsize: 4
|
|
||||||
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
|
||||||
* This Revision: $Id: main.c 692 2008-11-07 15:07:40Z cs $
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
This example should run on most AVRs with only little changes. No special
|
|
||||||
hardware resources except INT0 are used. You may have to change usbconfig.h for
|
|
||||||
different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or
|
|
||||||
at least be connected to INT0 as well.
|
|
||||||
We assume that an LED is connected to port B bit 0. If you connect it to a
|
|
||||||
different port or bit, change the macros below:
|
|
||||||
*/
|
|
||||||
#define LED_PORT_DDR DDRB
|
|
||||||
#define LED_PORT_OUTPUT PORTB
|
|
||||||
#define LED_BIT 0
|
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <avr/wdt.h>
|
#include <avr/wdt.h>
|
||||||
#include <avr/interrupt.h> /* for sei() */
|
#include <avr/interrupt.h> /* for sei() */
|
||||||
#include <util/delay.h> /* for _delay_ms() */
|
#include <util/delay.h> /* for _delay_ms() */
|
||||||
|
#include <stdlib.h>
|
||||||
#include <avr/pgmspace.h> /* required by usbdrv.h */
|
#include <avr/pgmspace.h> /* required by usbdrv.h */
|
||||||
|
|
||||||
#include "usbdrv.h"
|
#include "usbdrv.h"
|
||||||
#include "oddebug.h" /* This is also an example for using debug macros */
|
#include "oddebug.h" /* This is also an example for using debug macros */
|
||||||
#include "requests.h" /* The custom request numbers we use */
|
#include "requests.h" /* The custom request numbers we use */
|
||||||
|
#include "uart.h"
|
||||||
|
#include "sram.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "crc.h"
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
/* ----------------------------- USB interface ----------------------------- */
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
usbMsgLen_t usbFunctionSetup(uchar data[8])
|
#define STATE_IDLE 0
|
||||||
{
|
#define STATE_WRITE 1
|
||||||
usbRequest_t *rq = (void *)data;
|
#define BUFFER_SIZE 512
|
||||||
static uchar dataBuffer[4]; /* buffer must stay valid when usbFunctionSetup returns */
|
|
||||||
|
|
||||||
if(rq->bRequest == CUSTOM_RQ_ECHO){ /* echo -- used for reliability tests */
|
extern FILE uart_stdout;
|
||||||
dataBuffer[0] = rq->wValue.bytes[0];
|
|
||||||
dataBuffer[1] = rq->wValue.bytes[1];
|
uint32_t rom_addr;
|
||||||
dataBuffer[2] = rq->wIndex.bytes[0];
|
uint32_t addr;
|
||||||
dataBuffer[3] = rq->wIndex.bytes[1];
|
uint8_t bytes_remaining = 0;
|
||||||
usbMsgPtr = dataBuffer; /* tell the driver which data to return */
|
uint16_t sync_errors = 0;
|
||||||
return 4;
|
uint8_t read_buffer[BUFFER_SIZE];
|
||||||
}else if(rq->bRequest == CUSTOM_RQ_SET_STATUS){
|
uint8_t dataBuffer[4]; /* buffer must stay valid when usbFunctionSetup returns */
|
||||||
if(rq->wValue.bytes[0] & 1){ /* set LED */
|
uint8_t state = STATE_IDLE;
|
||||||
LED_PORT_OUTPUT |= _BV(LED_BIT);
|
|
||||||
}else{ /* clear LED */
|
usbMsgLen_t usbFunctionSetup(uchar data[8]){
|
||||||
LED_PORT_OUTPUT &= ~_BV(LED_BIT);
|
|
||||||
|
usbRequest_t *rq = (void *)data;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
uint8_t len = 0;
|
||||||
|
if(rq->bRequest == CUSTOM_RQ_UPLOAD){ /* echo -- used for reliability tests */
|
||||||
|
rom_addr = rq->wValue.word;
|
||||||
|
rom_addr = rom_addr << 16;
|
||||||
|
rom_addr = rom_addr | rq->wIndex.word;
|
||||||
|
if (bytes_remaining){
|
||||||
|
sync_errors++;
|
||||||
|
printf("CUSTOM_RQ_UPLOAD Out of sync Addr=0x%lx remain=%i packet=%i sync_error=%i\n",rom_addr,bytes_remaining,rq->wLength.word,sync_errors );
|
||||||
|
len=0;
|
||||||
|
}
|
||||||
|
bytes_remaining = rq->wLength.word;
|
||||||
|
//printf("CUSTOM_RQ_UPLOAD Addr=0x%lx Len=%i\n", rom_addr,bytes_remaining);
|
||||||
|
state = STATE_WRITE;
|
||||||
|
len = 0xff;
|
||||||
|
}else if(rq->bRequest == CUSTOM_RQ_DOWNLOAD){
|
||||||
|
printf("CUSTOM_RQ_DOWNLOAD\n");
|
||||||
|
}else if(rq->bRequest == CUSTOM_RQ_CRC_CHECK){
|
||||||
|
rom_addr = rq->wValue.word;
|
||||||
|
rom_addr = rom_addr << 16;
|
||||||
|
rom_addr = rom_addr | rq->wIndex.word;
|
||||||
|
printf("CUSTOM_RQ_CRC_CHECK Addr 0x%lx \n", rom_addr);
|
||||||
|
crc = 0;
|
||||||
|
cli();
|
||||||
|
for (addr=0x000000; addr<rom_addr; addr+=BUFFER_SIZE) {
|
||||||
|
sram_read_buffer(addr,read_buffer,BUFFER_SIZE);
|
||||||
|
crc = do_crc_update(crc,read_buffer,BUFFER_SIZE);
|
||||||
|
//dump_packet(rom_addr,BUFFER_SIZE,read_buffer);
|
||||||
|
if (addr && addr%32768 == 0){
|
||||||
|
printf("Addr: 0x%08lx CRC: %04x\n",addr,crc);
|
||||||
|
crc = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else if(rq->bRequest == CUSTOM_RQ_GET_STATUS){
|
printf("Addr: 0x%08lx CRC: %04x\n",addr,crc);
|
||||||
dataBuffer[0] = ((LED_PORT_OUTPUT & _BV(LED_BIT)) != 0);
|
sei();
|
||||||
usbMsgPtr = dataBuffer; /* tell the driver which data to return */
|
|
||||||
return 1; /* tell the driver to send 1 byte */
|
|
||||||
}
|
}
|
||||||
return 0; /* default for not implemented requests: return no data back to host */
|
usbMsgPtr = dataBuffer;
|
||||||
|
return len; /* default for not implemented requests: return no data back to host */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t usbFunctionWrite(uint8_t *data, uint8_t len)
|
||||||
|
{
|
||||||
|
if (len > bytes_remaining)
|
||||||
|
len = bytes_remaining;
|
||||||
|
bytes_remaining -= len;
|
||||||
|
|
||||||
|
//printf("usbFunctionWrite addr=%lx len=%i remain=%i\n",rom_addr,len,bytes_remaining);
|
||||||
|
cli();
|
||||||
|
sram_copy(rom_addr,data,len);
|
||||||
|
sei();
|
||||||
|
rom_addr +=len;
|
||||||
|
//printf("usbFunctionWrite %lx %x\n",rom_addr,len);
|
||||||
|
//state=STATE_IDLE;
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
uchar i;
|
uint8_t i;
|
||||||
|
//wdt_enable(WDTO_1S);
|
||||||
wdt_enable(WDTO_1S);
|
uart_init();
|
||||||
/* Even if you don't use the watchdog, turn it off here. On newer devices,
|
stdout = &uart_stdout;
|
||||||
* the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
|
sram_init();
|
||||||
*/
|
printf("SRAM Init\n");
|
||||||
DBG1(0x00, 0, 0); /* debug output: main starts */
|
spi_init();
|
||||||
/* RESET status: all port bits are inputs without pull-up.
|
printf("SPI Init\n");
|
||||||
* That's the way we need D+ and D-. Therefore we don't need any
|
|
||||||
* additional hardware initialization.
|
|
||||||
*/
|
|
||||||
odDebugInit();
|
|
||||||
usbInit();
|
usbInit();
|
||||||
|
printf("USB Init\n");
|
||||||
usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
|
usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
|
||||||
i = 0;
|
printf("USB disconnect\n");
|
||||||
|
i = 10;
|
||||||
while(--i){ /* fake USB disconnect for > 250 ms */
|
while(--i){ /* fake USB disconnect for > 250 ms */
|
||||||
wdt_reset();
|
wdt_reset();
|
||||||
_delay_ms(1);
|
_delay_ms(1);
|
||||||
}
|
}
|
||||||
usbDeviceConnect();
|
usbDeviceConnect();
|
||||||
LED_PORT_DDR |= _BV(LED_BIT); /* make the LED bit an output */
|
printf("USB connect\n");
|
||||||
sei();
|
sei();
|
||||||
DBG1(0x01, 0, 0); /* debug output: main loop starts */
|
printf("USB poll\n");
|
||||||
for(;;){ /* main event loop */
|
for(;;){ /* main event loop */
|
||||||
DBG1(0x02, 0, 0); /* debug output: main loop iterates */
|
//wdt_reset();
|
||||||
wdt_reset();
|
|
||||||
usbPoll();
|
usbPoll();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -16,18 +16,18 @@
|
|||||||
#ifndef __REQUESTS_H_INCLUDED__
|
#ifndef __REQUESTS_H_INCLUDED__
|
||||||
#define __REQUESTS_H_INCLUDED__
|
#define __REQUESTS_H_INCLUDED__
|
||||||
|
|
||||||
#define CUSTOM_RQ_ECHO 0
|
#define CUSTOM_RQ_UPLOAD 0
|
||||||
/* Request that the device sends back wValue and wIndex. This is used with
|
/* Request that the device sends back wValue and wIndex. This is used with
|
||||||
* random data to test the reliability of the communication.
|
* random data to test the reliability of the communication.
|
||||||
*/
|
*/
|
||||||
#define CUSTOM_RQ_SET_STATUS 1
|
#define CUSTOM_RQ_DOWNLOAD 1
|
||||||
/* Set the LED status. Control-OUT.
|
/* Set the LED status. Control-OUT.
|
||||||
* The requested status is passed in the "wValue" field of the control
|
* The requested status is passed in the "wValue" field of the control
|
||||||
* transfer. No OUT data is sent. Bit 0 of the low byte of wValue controls
|
* transfer. No OUT data is sent. Bit 0 of the low byte of wValue controls
|
||||||
* the LED.
|
* the LED.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define CUSTOM_RQ_GET_STATUS 2
|
#define CUSTOM_RQ_CRC_CHECK 2
|
||||||
/* Get the current LED status. Control-IN.
|
/* Get the current LED status. Control-IN.
|
||||||
* This control transfer involves a 1 byte data phase where the device sends
|
* This control transfer involves a 1 byte data phase where the device sends
|
||||||
* the current status to the host. The status is in bit 0 of the byte.
|
* the current status to the host. The status is in bit 0 of the byte.
|
||||||
|
|||||||
157
poc/avr_usbload/sram.c
Normal file
157
poc/avr_usbload/sram.c
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
#include "sram.h"
|
||||||
|
#include "uart.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
void spi_init(void)
|
||||||
|
{
|
||||||
|
/* Set MOSI and SCK output, all others input */
|
||||||
|
SPI_DIR |= ((1<<S_MOSI) | (1<<S_SCK) | (1<<S_LATCH));
|
||||||
|
SPI_DIR &= ~(1<<S_MISO);
|
||||||
|
SPI_PORT |= (1<<S_MISO);
|
||||||
|
/* Enable SPI, Master*/
|
||||||
|
SPCR = ((1<<SPE) | (1<<MSTR));
|
||||||
|
}
|
||||||
|
|
||||||
|
void spi_master_transmit(unsigned char cData)
|
||||||
|
{
|
||||||
|
/* Start transmission */
|
||||||
|
SPDR = cData;
|
||||||
|
|
||||||
|
/* Wait for transmission complete */
|
||||||
|
while(!(SPSR & (1<<SPIF)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void sram_set_addr(uint32_t addr)
|
||||||
|
{
|
||||||
|
spi_master_transmit((uint8_t)(addr>>16));
|
||||||
|
spi_master_transmit((uint8_t)(addr>>8));
|
||||||
|
spi_master_transmit((uint8_t)(addr>>0));
|
||||||
|
|
||||||
|
LATCH_PORT |= (1<<S_LATCH);
|
||||||
|
LATCH_PORT &= ~(1<<S_LATCH);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t sram_read(uint32_t addr)
|
||||||
|
{
|
||||||
|
uint8_t byte;
|
||||||
|
|
||||||
|
RAM_DIR = 0x00;
|
||||||
|
RAM_PORT = 0xff;
|
||||||
|
|
||||||
|
CTRL_PORT |= (1<<R_RD);
|
||||||
|
CTRL_PORT |= (1<<R_WR);
|
||||||
|
|
||||||
|
spi_master_transmit((uint8_t)(addr>>16));
|
||||||
|
spi_master_transmit((uint8_t)(addr>>8));
|
||||||
|
spi_master_transmit((uint8_t)(addr>>0));
|
||||||
|
|
||||||
|
LATCH_PORT |= (1<<S_LATCH);
|
||||||
|
LATCH_PORT &= ~(1<<S_LATCH);
|
||||||
|
CTRL_PORT &= ~(1<<R_RD);
|
||||||
|
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
|
||||||
|
byte = RAM_REG;
|
||||||
|
CTRL_PORT |= (1<<R_RD);
|
||||||
|
RAM_DIR =0x00;
|
||||||
|
RAM_PORT =0x00;
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sram_write(uint32_t addr, uint8_t data)
|
||||||
|
{
|
||||||
|
RAM_DIR = 0xff;
|
||||||
|
|
||||||
|
CTRL_PORT |= (1<<R_RD);
|
||||||
|
CTRL_PORT |= (1<<R_WR);
|
||||||
|
|
||||||
|
spi_master_transmit((uint8_t)(addr>>16));
|
||||||
|
spi_master_transmit((uint8_t)(addr>>8));
|
||||||
|
spi_master_transmit((uint8_t)(addr>>0));
|
||||||
|
|
||||||
|
LATCH_PORT |= (1<<S_LATCH);
|
||||||
|
LATCH_PORT &= ~(1<<S_LATCH);
|
||||||
|
|
||||||
|
|
||||||
|
CTRL_PORT &= ~(1<<R_WR);
|
||||||
|
|
||||||
|
RAM_PORT = data;
|
||||||
|
CTRL_PORT |= (1<<R_WR);
|
||||||
|
|
||||||
|
RAM_DIR = 0x00;
|
||||||
|
RAM_PORT = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sram_init(void){
|
||||||
|
|
||||||
|
RAM_DIR = 0x00;
|
||||||
|
RAM_PORT = 0x00;
|
||||||
|
|
||||||
|
CTRL_DIR |= ((1<<R_WR) | (1<<R_RD));
|
||||||
|
CTRL_PORT |= (1<<R_RD);
|
||||||
|
CTRL_PORT |= (1<<R_WR);
|
||||||
|
|
||||||
|
LED_PORT |= (1<<D_LED0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sram_snes_mode01(void){
|
||||||
|
CTRL_PORT |= (1<<R_WR);
|
||||||
|
CTRL_PORT &= ~(1<<R_RD);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sram_snes_mode02(void){
|
||||||
|
CTRL_DIR |= (1<<R_WR);
|
||||||
|
CTRL_PORT |= (1<<R_WR);
|
||||||
|
//CTRL_PORT &= ~(1<<R_RD);
|
||||||
|
CTRL_DIR &= ~(1<<R_RD);
|
||||||
|
CTRL_PORT &= ~(1<<R_RD);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void sram_clear(uint32_t addr, uint32_t len){
|
||||||
|
|
||||||
|
uint32_t i;
|
||||||
|
for (i=addr; i<(addr + len);i++ ){
|
||||||
|
if (0==i%0xfff)
|
||||||
|
printf("sram_clear %lx\n\r",i);
|
||||||
|
sram_write(i, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sram_copy(uint32_t addr,uint8_t *src, uint32_t len){
|
||||||
|
|
||||||
|
uint32_t i;
|
||||||
|
uint8_t *ptr = src;
|
||||||
|
for (i=addr; i<(addr + len);i++ )
|
||||||
|
sram_write(i, *ptr++);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sram_read_buffer(uint32_t addr,uint8_t *dst, uint32_t len){
|
||||||
|
|
||||||
|
uint32_t i;
|
||||||
|
uint8_t *ptr = dst;
|
||||||
|
for (i=addr; i<(addr + len);i++ ){
|
||||||
|
*ptr = sram_read(i);
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uint8_t sram_check(uint8_t *buffer, uint32_t len){
|
||||||
|
uint16_t cnt;
|
||||||
|
for (cnt=0; cnt<len; cnt++)
|
||||||
|
if (buffer[cnt])
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
51
poc/avr_usbload/sram.h
Normal file
51
poc/avr_usbload/sram.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
|
||||||
|
//SREG defines
|
||||||
|
#define S_MOSI PB5
|
||||||
|
#define S_MISO PB6
|
||||||
|
#define S_SCK PB7
|
||||||
|
#define S_LATCH PB4
|
||||||
|
|
||||||
|
//DEBUG defines
|
||||||
|
#define D_LED0 PD6
|
||||||
|
|
||||||
|
//SRAM defines
|
||||||
|
#define R_WR PB1
|
||||||
|
#define R_RD PB0
|
||||||
|
|
||||||
|
#define RAM_PORT PORTA
|
||||||
|
#define RAM_DIR DDRA
|
||||||
|
#define RAM_REG PINA
|
||||||
|
|
||||||
|
#define CTRL_PORT PORTB
|
||||||
|
#define CTRL_DIR DDRB
|
||||||
|
#define LATCH_PORT PORTB
|
||||||
|
#define LATCH_DIR DDRB
|
||||||
|
|
||||||
|
#define SPI_PORT PORTB
|
||||||
|
#define SPI_DIR DDRB
|
||||||
|
|
||||||
|
#define LED_PORT PORTD
|
||||||
|
#define LED_DIR DDRD
|
||||||
|
|
||||||
|
#define ROMSIZE 4
|
||||||
|
#define BLOCKS (ROMSIZE << 8)
|
||||||
|
#define MEMSIZE 0x80000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void spi_init(void);
|
||||||
|
void spi_master_transmit(unsigned char cData);
|
||||||
|
void sram_set_addr(uint32_t addr);
|
||||||
|
uint8_t sram_read(uint32_t addr);
|
||||||
|
void sram_write(uint32_t addr, uint8_t data);
|
||||||
|
void sram_init(void);
|
||||||
|
void sram_snes_mode01(void);
|
||||||
|
void sram_snes_mode02(void);
|
||||||
|
void sram_clear(uint32_t addr, uint32_t len);
|
||||||
|
void sram_copy(uint32_t addr,uint8_t *src, uint32_t len);
|
||||||
|
void sram_read_buffer(uint32_t addr,uint8_t *dst, uint32_t len);
|
||||||
|
uint8_t sram_check(uint8_t *buffer, uint32_t len);
|
||||||
@ -56,13 +56,13 @@ section at the end of this file).
|
|||||||
|
|
||||||
/* ----------------------- Optional Hardware Config ------------------------ */
|
/* ----------------------- Optional Hardware Config ------------------------ */
|
||||||
|
|
||||||
/* #define USB_CFG_PULLUP_IOPORTNAME D */
|
#define USB_CFG_PULLUP_IOPORTNAME D
|
||||||
/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
|
/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
|
||||||
* V+, you can connect and disconnect the device from firmware by calling
|
* V+, you can connect and disconnect the device from firmware by calling
|
||||||
* the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
|
* the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
|
||||||
* This constant defines the port on which the pullup resistor is connected.
|
* This constant defines the port on which the pullup resistor is connected.
|
||||||
*/
|
*/
|
||||||
/* #define USB_CFG_PULLUP_BIT 4 */
|
#define USB_CFG_PULLUP_BIT 6
|
||||||
/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
|
/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
|
||||||
* above) where the 1.5k pullup resistor is connected. See description
|
* above) where the 1.5k pullup resistor is connected. See description
|
||||||
* above for details.
|
* above for details.
|
||||||
@ -119,7 +119,7 @@ section at the end of this file).
|
|||||||
* The value is in milliamperes. [It will be divided by two since USB
|
* The value is in milliamperes. [It will be divided by two since USB
|
||||||
* communicates power requirements in units of 2 mA.]
|
* communicates power requirements in units of 2 mA.]
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_IMPLEMENT_FN_WRITE 0
|
#define USB_CFG_IMPLEMENT_FN_WRITE 1
|
||||||
/* Set this to 1 if you want usbFunctionWrite() to be called for control-out
|
/* Set this to 1 if you want usbFunctionWrite() to be called for control-out
|
||||||
* transfers. Set it to 0 if you don't need it and want to save a couple of
|
* transfers. Set it to 0 if you don't need it and want to save a couple of
|
||||||
* bytes.
|
* bytes.
|
||||||
@ -216,8 +216,8 @@ section at the end of this file).
|
|||||||
#define USB_CFG_DEVICE_VERSION 0x00, 0x01
|
#define USB_CFG_DEVICE_VERSION 0x00, 0x01
|
||||||
/* Version number of the device: Minor number first, then major number.
|
/* Version number of the device: Minor number first, then major number.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_VENDOR_NAME 'o', 'b', 'd', 'e', 'v', '.', 'a', 't'
|
#define USB_CFG_VENDOR_NAME 'o', 'p', 't', 'i', 'x', 'x', '.', 'o', 'r', 'g'
|
||||||
#define USB_CFG_VENDOR_NAME_LEN 8
|
#define USB_CFG_VENDOR_NAME_LEN 10
|
||||||
/* These two values define the vendor name returned by the USB device. The name
|
/* These two values define the vendor name returned by the USB device. The name
|
||||||
* must be given as a list of characters under single quotes. The characters
|
* must be given as a list of characters under single quotes. The characters
|
||||||
* are interpreted as Unicode (UTF-16) entities.
|
* are interpreted as Unicode (UTF-16) entities.
|
||||||
@ -226,8 +226,8 @@ section at the end of this file).
|
|||||||
* obdev's free shared VID/PID pair. See the file USBID-License.txt for
|
* obdev's free shared VID/PID pair. See the file USBID-License.txt for
|
||||||
* details.
|
* details.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DEVICE_NAME 'L', 'E', 'D', 'C', 'o', 'n', 't', 'r', 'o', 'l'
|
#define USB_CFG_DEVICE_NAME 'S', 'N', 'E', 'S', 'R', 'A', 'M'
|
||||||
#define USB_CFG_DEVICE_NAME_LEN 10
|
#define USB_CFG_DEVICE_NAME_LEN 7
|
||||||
/* Same as above for the device name. If you don't want a device name, undefine
|
/* Same as above for the device name. If you don't want a device name, undefine
|
||||||
* the macros. See the file USBID-License.txt before you assign a name if you
|
* the macros. See the file USBID-License.txt before you assign a name if you
|
||||||
* use a shared VID/PID.
|
* use a shared VID/PID.
|
||||||
@ -254,7 +254,8 @@ section at the end of this file).
|
|||||||
* HID class is 3, no subclass and protocol required (but may be useful!)
|
* HID class is 3, no subclass and protocol required (but may be useful!)
|
||||||
* CDC class is 2, use subclass 2 and protocol 1 for ACM
|
* CDC class is 2, use subclass 2 and protocol 1 for ACM
|
||||||
*/
|
*/
|
||||||
/* #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 42 */
|
#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 0
|
||||||
|
|
||||||
/* Define this to the length of the HID report descriptor, if you implement
|
/* Define this to the length of the HID report descriptor, if you implement
|
||||||
* an HID device. Otherwise don't define it or define it to 0.
|
* an HID device. Otherwise don't define it or define it to 0.
|
||||||
* If you use this define, you must add a PROGMEM character array named
|
* If you use this define, you must add a PROGMEM character array named
|
||||||
|
|||||||
942
snesram.tmproj
942
snesram.tmproj
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user