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

📄 usb.c

📁 yampp mp3 source code
💻 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
**
*********************************************************************** */



#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;

//	union u32convert cnv;
//	lcd_gotoxy(0,1);
//	cnv.value = ucb->data.sector_rw.sector;
//	printf("Read \nSec: %04x%04x", cnv.words.high, cnv.words.low); 
//	printf("\nCount: %04x", (u16)ucb->data.sector_rw.nsectors); 

	err = CARD_Read_USB(ucb->data.sector_rw.sector, ucb->data.sector_rw.nsectors);
	usb_response(err);	

//	printf("\nResult: %02x", 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)
{
	u16 err;

//	union u32convert cnv;
//	lcd_gotoxy(0,1);
//	cnv.value = ucb->data.sector_rw.sector;
//	printf("Write\nSec: %04x%04x", cnv.words.high, cnv.words.low); 
//	printf("\nCount: %04x", (u16)ucb->data.sector_rw.nsectors); 

	err = CARD_Write_USB(ucb->data.sector_rw.sector, ucb->data.sector_rw.nsectors);

//	printf("\nSec cnt: %02x\nByt cnt: %02x", err>>8 , (u08)err); 

	usb_response(err);								
}

/*

void bufferfill(usb_cmd_block *ucb)
{
	usb_readblock(SectorBuffer,ucb->data.general.parm1);
}


void songdata(usb_cmd_block *ucb)
{
	usb_readblock(SectorBuffer,ucb->data.general.parm1);
//	usb_readblock(SectorBuffer,ucb->data.general.parm2);
	filesize = ucb->data.general.parm3 / 32;
	fileplayed = 0;
}


void usb_volume(usb_cmd_block *ucb)
{
	vs1001_setvolume(ucb->data.volume.left, (s08)ucb->data.volume.right - (s08)ucb->data.volume.left);	
}

void bufferinfo(usb_cmd_block *ucb)
{
	ucb->data.buffer_info.buffersize = SECTORSIZE;
	usb_writeblock((u08*)ucb,sizeof(usb_cmd_block));
}

*/

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_wb((u16)ucb->data.general.parm1 + adr, SectorBuffer[adr]);
		wdt_reset();
	}
}

void (*bootloader)(void) =  (void*) 0x1E10;

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));

//		lcd_clrscr();
//		printf("CMD: %04x",(u16)ucb.command); 

		switch ((u16)ucb.command)
		{
			case USB_TEST_POLL :					// Test command
				usb_response(0);	 // echo OK
				break;
				
			case USB_ENTER_BOOT :		 // Boot Load
				wdt_disable();
				eeprom_update();
				bootloader();
				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_PLAY :			 // Start USB Play
				event = EV_PLAY_USB; 
				songdata(&ucb);
				usb_response(0);
				break;

			case USB_BUFFER :		// Incoming USB Play buffer
				bufferfill(&ucb);				
				break;

			case USB_STOP :			// Stop USB Play
				event = EV_STOP; 
				usb_response(0);	// send ACK
				break;

			case USB_SETVOLUME : 		// Set Playback Volume
				usb_volume(&ucb);
				break;
				
			case USB_BUFFERINFO :	
				bufferinfo(&ucb);
				break;
*/
			case USB_ENTER_LINK :
//				wdt_disable();
				usb_link = 1;
				event = EV_STOP;
				break;

			case USB_EXIT_LINK :
				usb_response(0);
				wdt_enable(0x02);
				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 + -