⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb.c

📁 yampp 7 USB firmware v 2.44 checked, working, latest
💻 C
字号:
/* ***********************************************************************
**
**  Copyright (C) 2002  Jesper Hansen <jesperh@telia.com> and 
**			Romuald Bialy (MIS) <romek_b@o2.pl>.
**
**
**  Yampp-7/USB - usb communication routines
**
**  File usb.c
**
*************************************************************************
**
**   This file is part of the yampp system.
**
**  This program is free software; you can redistribute it and/or
**  modify it under the terms of the GNU General Public License
**  as published by the Free Software Foundation; either version 2
**  of the License, or (at your option) any later version.
**
**  This program is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**  GNU General Public License for more details.
**
**  You should have received a copy of the GNU General Public License
**  along with this program; if not, write to the Free Software Foundation, 
**  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
**
*************************************************************************
**
**  Revision History
**
**  when         what  who	why
**
**  2002-03-21   0.9   Jesper   initial release
**  2002-07-06   1.0   MIS	added EEPROM R/W functions and PC link begin/end functions
**  2003-01-13   1.1   MIS	removed uart calls
**  2005-03-15   1.2   MIS	modified for compatibility with WinAVR-20050214
**
*********************************************************************** */

#include "yampp7_usb.h"

extern u32 filesize;
extern u32 fileplayed;
extern u08 usb_link;

void usb_response(u08 err)
{
	if (err)
		usb_writebyte(NAK);		// send NAK
	else
		usb_writebyte(ACK);		// send ACK

	usb_writebyte(0);	
}


void identify(usb_cmd_block *ucb)
{
	register u08 err;
	err = CARD_Identify();
	usb_writeblock(SectorBuffer,512);
	usb_response(err);	
}

void sectorread(usb_cmd_block *ucb)
{
	register u08 err;
	err = CARD_Read_USB(ucb->data.sector_rw.sector, ucb->data.sector_rw.nsectors);
	usb_response(err);	
}



void sectorfill(usb_cmd_block *ucb)
{
	register u08 err;
	memset(SectorBuffer,ucb->data.sector_fill.data,SECTORSIZE);
	err = CARD_Write(ucb->data.sector_rw.sector);
	usb_response(err);	
}



void sectorwrite(usb_cmd_block *ucb)
{
	register u08 err;
	err = CARD_Write_USB(ucb->data.sector_rw.sector, ucb->data.sector_rw.nsectors);
	usb_response(err);								
}


void eeread(usb_cmd_block *ucb)
{
	eeprom_read_block(SectorBuffer, (u08*)(u16)ucb->data.general.parm1, (u16)ucb->data.general.parm2);
	usb_writeblock(SectorBuffer,ucb->data.general.parm2);
}

void eewrite(usb_cmd_block *ucb)
{
	u16 adr;

	usb_readblock(SectorBuffer,ucb->data.general.parm2);
	usb_response(0);	
	for (adr=0; adr < (u16)ucb->data.general.parm2; adr++)
	{
		eeprom_write_byte((u08 *)((u16)ucb->data.general.parm1 + adr), SectorBuffer[adr]);
		wdt_reset();
	}
}

//void (*bootloader5)(void) =  (void*) 0x1F90;	// word address
//void (*bootloader3)(void) =  (void*) 0x1E10;	// word address

extern void eeprom_update(void);

void usb_handler(void)
{
	usb_cmd_block ucb;
	event_e event = EV_IDLE;
	
	if (usb_rxready)
	{
		ucb.command = 0;
		usb_readblock((char*)&ucb,sizeof(usb_cmd_block));
		switch ((u16)ucb.command)
		{
			case USB_TEST_POLL :					// Test command
				usb_response(0);	 				// echo OK
				break;
				
			case USB_ENTER_BOOT :				 // Boot Load
				eeprom_update();
				wdt_disable();
				if(pgm_read_byte(0x3F00) == 0x94)		// bootloader code at byte address of boot V5
//					bootloader5();					// if present - go to boot V5
					asm volatile ("jmp 0x3F20");		// byte address of boot v5 entry point
				else
//					bootloader3();					// else goto boot v3
					asm volatile ("jmp 0x3C20");		// byte address of boot v3 entry point
				break;				

			case USB_EEPROM_READ :				 // EEPROM Read
				eeread(&ucb);
				break;				

			case USB_EEPROM_WRITE :		 // EEPROM Write
				eewrite(&ucb);
				break;				
				
			case USB_SECTOR_READ :		 // Sector Read
				sectorread(&ucb);
				break;

			case USB_SECTOR_WRITE :		 // Sector Write
				sectorwrite(&ucb);
				break;
				
			case USB_SECTOR_FILL : 		// Sector Fill
				sectorfill(&ucb);
				break;

			case USB_IDENTIFY : 			// Identify drive
				identify(&ucb);
				break;

			case USB_ENTER_LINK :
				usb_link = 1;
				event = EV_STOP;
				break;

			case USB_EXIT_LINK :
				usb_response(0);
				wdt_enable(0x01);
				while(1);					// reset player by watchdog
				break;
				
			default :
				usb_writebyte(UNK);	
				usb_writebyte(0);	
				break;
		}
	}
	if (event != EV_IDLE)
		set_event(event);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -