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

📄 yampp3u_test.c

📁 yampp3 mp3 code
💻 C
📖 第 1 页 / 共 2 页
字号:
		printf("Ok.\n\n");
	return r;	
}

void ATA_SW_Reset2(void)		// ATA Reset
{
	WriteBYTE(ATAPI_DevCtrl, 0x06);				// SRST and nIEN bits
	delay10();						// 10uS delay
	WriteBYTE(ATAPI_DevCtrl, 0x02);				// nIEN bit
	delay10();						// 10 uS delay
	while ( (ATA_WaitBusy() & SR_DRDY) != SR_DRDY ); 	// Wait for DRDY
  	ATA_ReadStat();
}



u08 ata_test(void)
{
	u08 c;
	u16 i;
	u32 maxlba;

	// Init and wait for drive
  	puts("Disk Init... ");
	ATA_SetDrive(0);
	ATA_SW_Reset2();
   	puts("Ready!\n");

	printf("Identify ");

	if (ata_status( IdentifyDrive(buffer1) ))
		return 2;

	// save and display some data
	//display model number at Word 27-46
	for (i=27;i<47;i++)
	{
		if ( (c = buffer1[i*2+1]))	printf("%c",c);	
		if ( (c = buffer1[i*2]))	printf("%c",c);	
	}

	// get max LBA sector number at Word 60-61

	maxlba  = ((u32*)buffer1)[30];
	printf("\nMax LBA = 0x%lx,  Drivesize = ",maxlba);
	printf("%u MB\n", (u16) ((u32) maxlba >> 11));


	//
	// read boot sector
	//
    ATA_Read(0, 1, buffer1);
				
	HexDump( buffer1, 512);				

	diskinit = 1;
	
	return 0;
}


u08 ram_test(void)
{
	u08 c = memory_test();
	
//	printf("RAM Test return %d\n",c);
	
	switch (c)
	{
		case 0: break;
		case 1: printf("Databus failure with pattern %x\n", getfail()); break;
		case 2: printf("Addressbus failure at address: %x\n", getfail()); break;
		case 3: printf("Chip failure at address: %x\n", getfail()); break;
	}	
	
	return c;
}


u08 databus_test(void)
{
	u08 i;	
	
	outp((0<<SRE)|(1<<SRW10), MCUCR);
	outp(0xFF, DDRA);

	i = 1;
	while (1)
	{
		outp(i,PORTA);
		
		i <<= 1;
		if (i == 0)
			i = 1;
		
		if ( uart_haschar() )
		{
			uart_getchar();
			break;			
		}
	}

	outp((1<<SRE)|(1<<SRW10), MCUCR);
	return 0;
}


u08 addressbus_test(void)
{
	u16 i;	
	
	outp((0<<SRE)|(1<<SRW10), MCUCR);
	outp(0xFF, DDRA);
	outp(0xFF, DDRC);
	
	sbi(DDRE,PE1); 		// ALE
	cbi(PORTE,PE1); 	// ALE low
	
	i = 1;
	while (1)
	{
		outp(i & 0xff,PORTA);
		outp(i >> 8,PORTC);
		sbi(PORTE,PE1); 	// ALE high
		cbi(PORTE,PE1); 	// ALE low
		
		
		i <<= 1;
		if (i == 0)
			i = 1;
		
		if ( uart_haschar() )
		{
			uart_getchar();
			break;			
		}
	}
	
	outp((1<<SRE)|(1<<SRW10), MCUCR);
	return 0;
}

static u08 str1[]  __attribute__ ((progmem)) = "USB <-> Serial link up\nEnter some characters.\nPress ESC to end test.\n";

u08 usb_test(void)
{
	u08 c;

	if (!usb_txfree)
	{
		printf("Is the USB cable connected ?\n");
		return 1;
	}
	
	_p_fputs(usb_writebyte, str1);
	_p_puts(str1);
	
	while (1)
	{
		if ( usb_rxready )
			putchar( c = usb_readbyte() );
		if (c == 0x1b)
			break;			

		if ( uart_haschar() )
			usb_writebyte( c = uart_getchar() );
		if (c == 0x1b)
			break;			
	}
	
	return 0;
}

u08 key_test(void)
{
	u08 i;
	
	printf("Press yampp keys\n");
	printf("Exit with ESC.\n");


	ramdisable();			// disable ExtRAM
	outp(0xff, DDRA);		// set port as output
	
	while (1)
	{
		// check keys
		for (i = 0; i < 8; i++)
		{
			outp(~(1 << i), PORTA);			// write bit mask
			asm volatile("nop");			// wait a while
			asm volatile("nop");
			if (bit_is_clear(KBD_PIN, KBD_BIT)) 	// this bit ?
				printf("DOWN");
			else
				printf("UP  ");
			printf("  ");
		}
		printf("\n");
		delayms(500);

		if ( uart_haschar() )
			if (uart_getchar() == 0x1b)
				break;			
	}
	
	ramenable();
	return 0;
}



static u08 ir0[]  __attribute__ ((progmem)) = "REC80 ";
static u08 ir1[]  __attribute__ ((progmem)) = "NEC80 ";
static u08 ir2[]  __attribute__ ((progmem)) = "SONY15";
static u08 ir3[]  __attribute__ ((progmem)) = "SONY12";
static u08 ir4[]  __attribute__ ((progmem)) = "RC-5  ";

u08 *standard_name[] = { (u08*)&ir0, (u08*)&ir1, (u08*)&ir2, (u08*)&ir3, (u08*)&ir4 };

u08 ir_test(void)
{
	u08 stand = 0;
	u16 i=4;
	

	printf("\nRemote test\n");
	printf("Exit with ESC.\n\n");
	printf("Testing Standard: %d\n",stand);
	
	while(1)					// Recognize IR standard
	{
		if (rec80_active())
		{
			if (get_rec80(stand))		// If != 0 - found standard
			{
					uart_EOL();
					printf("Found Standard: %p\n",standard_name[stand]);
					delayms(100);
					break;
			}
			else
			{
				if(--i == 0)
				{
					stand = (stand+1) % (sizeof(standard_name)/sizeof(standard_name[0]));
					i=4;
					printf("Testing Standard: %d\n",stand);
				}
			}
			
		}
		if (uart_haschar())
			if (uart_getchar() == 0x1b)
				return 0;
	}
	
	uart_EOL();
	
	printf("Receiving codes :\n");
	
	while (1)
	{
		if (rec80_active())
		{	
			i = get_rec80(stand);
			if (i != 0)
				printf("Code: 0x%x\n",i);
		}
		if (uart_haschar())
		{
			if (uart_getchar() == 0x1b)
				return 0;
		}
	}
	return 0;

}

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


u08 boot_test(void)
{
	printf("Entering bootloader...");
	lcd_clrscr();
	lcd_puts("Download code");
	bootloader();
	return 0;
}


/****************************************************************************
**
** Test helpers
**
****************************************************************************/

struct TEST
{
	u08 (*fn)(void);
	char *description;
} tests[] = 
{
	{reg_test,		"VS1001 SDI R/W Test"},
	{mem_test,		"VS1001 Memory Test"},
	{bus_test,		"VS1001 Dump Registers"},
	{send_beeps,	"VS1001 Sine Test"},
	{sine_sweep,	"VS1001 Sweep Test"},
	{volume_test,	"VS1001 Volume Test"},
	{clock_doubler,	"VS1001 Clock Doubler"},
	{ata_test,		"ATA Test"},
	{ram_test,		"RAM Test"},
	{databus_test,	"Databus Walk"},
	{addressbus_test,"Address Walk"},
	{usb_test,		"USB Test"},
	{key_test,		"Keyboard Test"},
	{ir_test,		"IR Test"},
	{boot_test,		"Start Bootloader"},
};



void run_test(u08 test_number)
{
	u08 result;	
	
	if (test_number < sizeof(tests)/sizeof(tests[0]) )
	{
		printf("%s Running....\n",tests[test_number].description);
		result = tests[test_number].fn();
	}
	else
	{
		printf("Invalid Test #\n");	
		return; 
	}

	printf("%s",tests[test_number].description);
	
	if (result != 0)
	{
		printf(" Fail, code = %d\n", result);
	}
	else
		printf(" Pass\n");
}



void help(void)
{
	u08 i;
	printf("\nTest list :\n");
	for (i=0;i<sizeof(tests)/sizeof(tests[0]);i++)
		printf("%c: %s\n", i <= 9 ? i + '0' : i - 10 + 'a', tests[i].description);
}



//----------------------------------------------------------------------------
// Main part
//----------------------------------------------------------------------------
int main(void) 
{
	u08	i,c;
	u16 j;



//////////////////////////////////////////////////////////////////
// B - Port
//////////////////////////////////////////////////////////////////

	sbi(PORTB, 0);	// DIOW- hi
	sbi(DDRB, 0);	// pin PB0 is output, DIOW- 
	
	sbi(PORTB, 1);	// DIOR- hi
	sbi(DDRB, 1);	// pin PB1 is output, DIOR- 
	
	cbi(DDRB, 2);	// pin PB2 is input, DEMAND
	sbi(PORTB, 2);	// activate pullup
	
	// PB3 and PB4 is used for BSYNC and MP3 signals to VS1001
	// PB5 (MOSI) is used for SPI
	// PB6 (MISO) is used for SPI
	// PB7 (SCK) is used for SPI
	

//////////////////////////////////////////////////////////////////
// D - Port
//////////////////////////////////////////////////////////////////

	// PD0 and PD1 are TX and RX signals

	sbi(PORTD,PD3);		// pin PD3 is keyboard input, enable pullup

	sbi(PORTD,PD4);		// PD4 is available but need a pullup to avoid noise
	
	sbi(PORTD,PD5);		// PD5
	
	// PD6 and PD7 are RD and WR signals
	// but we need to set their default states used
	// when the external memory interface is disabled
	// they should then both be high to avoid disturbing
	// RAM contents
	
	sbi(DDRD, 6);		// as outputs
	sbi(DDRD, 7);

	sbi(PORTD, 6);		// and both hi
	sbi(PORTD, 7);


	// PORTE need setup of ALE in idle mode

	cbi(DDRE, PE0);		// PE0 is IR input
	sbi(PORTE, PE0);	// activate pullup

	sbi(DDRE, PE1);		// set ALE pin as output
	cbi(PORTE, PE1);	// and set it low (inactive)

//////////////////////////////////////////////////////////////////
// USB
//////////////////////////////////////////////////////////////////

	usb_init();


//////////////////////////////////////////////////////////////////
// Timer 1
//////////////////////////////////////////////////////////////////

	//
	// setup timer1 for a 100mS periodic interrupt
	//	
	
	outp(0, TCCR1A);
	outp(4, TCCR1B);		// prescaler /256  tPeriod = 32 uS
	outp(TI1_H, TCNT1H);	// load counter value hi
	outp(TI1_L, TCNT1L);	// load counter value lo

	// enable timer1 interrupt
	sbi(TIMSK, TOIE1);	 	
	

 //----------------------------------------------------------------------------
 // 
 //----------------------------------------------------------------------------

	
    // enable external SRAM and wait states 

	outp((1<<SRE)|(1<<SRW10), MCUCR);
	delayms(10);

	lcd_init(0, LCD_FUNCTION_DEFAULT, (LCD_LINES<<8)+LCD_LINE_LENGTH); 		// does clrscr too

	uart_init(UART_BAUD_SELECT);		// init RS-232 link
	setputchar(uart_putchar);

	both_progputs(PSTR("\n\n\n   Hi, MP3 world!\nyampp3/USB Alive\n"));

	uart_init(UART_BAUD_SELECT);		// init RS-232 link

	usb_init();


	// setup some buffers
	buffer1 = (u08 *) BUFFERSTART;				// 8 k
	buffer2 = (u08 *) buffer1 + BUFFERSIZE;		// 8 k
	buffer3 = (u08 *) buffer2 + BUFFERSIZE;		// end pointer

	delayms(500);


	// say hello
  	printf("\nyampp-3/U test code   %s %s\n" ,__DATE__, __TIME__);

	//
	// show a '*' in all display positions, then clear
	// screen and display a welcome message
	//
	for (i=0;i<LCD_LINES;i++)
		for (c=0;c<LCD_LINE_LENGTH;c++)
		{
			lcd_gotoxy(c,i);
			lcd_putchar('*');
			delayms(10);
		}


	lcd_clrscr();	
    lcd_progputs(PSTR("Hi there !\nYour LCD is okay"));
#if (LCD_LINES > 2)
	lcd_progputs(PSTR("\nLine 3\n"));
	lcd_progputs(PSTR("Line 4"));
#endif	



	//
	// init VS1001
	//
	vs1001_init_io();				// init VS1001
	vs1001_setcomp(F_VS1001);
	vs1001_reset(0);				// Init VS1001


	printf("Press '?' for menu.\n");


	while (1)
	{
		if (uart_haschar())
		{
			c = uart_getchar();
		
			if (c >= '0' && c <= '9')
				run_test(c-'0');
			else
			if (c >= 'a' && c <= 'z')
				run_test(c-'a' + 10);
			else
			
				switch (c)
				{
					case '?' : 	
						help();	
						printf("-: Dump Prev sector\n");
						printf("+: Dump Next sector\n");
						break;
					case '+' : sectordump(++lbasect); break;
					case '-' : if (lbasect > 0) sectordump(--lbasect); break;
								
					default	:	break;
				}

		}
			
	}	

}



⌨️ 快捷键说明

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