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

📄 yampp3u_test.c

📁 yampp3 mp3 code
💻 C
📖 第 1 页 / 共 2 页
字号:

/*
  Copyright (C) 2002 Jesper Hansen <jesperh@telia.com>.

  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.
*/



#include <io.h>
#include <timer.h>
#include <progmem.h>
#include <eeprom.h>
#include <sig-avr.h>
#include <interrupt.h>
#include <wdt.h>
#include <string.h>
#include <stdarg.h>

#include "types.h"
#include "Constants.h"
#include "yampp3lib.h"
#include "printf.h"
#include "mem.h"
#include "memtest.h"
#include "usb.h"



static char firmware_scan_tag[] __attribute__ ((progmem)) = "yfwTAG";
static char model_txt[]         __attribute__ ((progmem)) = "yampp-3/U Test";
static char date_txt[]          __attribute__ ((progmem)) = __DATE__" / "__TIME__;
static char version_txt[]       __attribute__ ((progmem)) = "1.00";



u08 *buffer1;
u08 *buffer2;
u08 *buffer3;

u32 lbasect = 0;
u08 diskinit = 0;

#define IR_PORT		PORTE
#define IR_BIT		PE0
#define KBD_PIN		PIND
#define KBD_BIT		PD3


// 7.3728 MHz
// prescaler set to 34.72 uS
// 2880 ticks = 100 mS
#define TI1_H	(((u16)-2880) >> 8)
#define TI1_L	(((u16)-2880) & 0xff )

SIGNAL(SIG_OVERFLOW1)	//timer 1 overflow every 100 mS
{
	outp(TI1_H, TCNT1H);					//reload timer 
	outp(TI1_L, TCNT1L);
}



void HexDump( u08 *buffer, u16 len ) 
{
    u16 i,j,k = 0;

    printf("\n");
    for(i=0;i<len/16;i++,k+=16)
    {
    	printf("%04x ",k);
        for(j=0;j<16;j++)
        {
        	printf("%02x ",buffer[i*16+j]);
        }
        printf("    ");
        for(j=0;j<16;j++)
        {
            if (buffer[i*16+j] >= 0x20)
                putchar(buffer[i*16+j]);
            else
                putchar('.');
        }
        printf("\n");
    }

}

void sectordump(u32 sector)
{
	if (diskinit == 0)
	{
		puts("Must run ATA Test first !\n");
		return;
	}
	printf("SectorDump %x", sector & 0xffff);
	ATA_Read(sector,1,buffer1);
	HexDump(buffer1, 512);
}





/****************************************************************************************
*			INFRARED REMOTE RECEPTION FUNCTIONS				*
****************************************************************************************/

u08 rec80_active(void)
{
	register u08 i = 50;

	while (i-- != 0)
		if (bit_is_clear(IR_PORT-2, IR_BIT))
			return 1;
	return 0;
}

static inline void timer0_src(u08 src)
{
	outb (src, TCCR0);
}

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

/*
  if STD = 0
	The REC-80 format used by Panasonic is a space coded 48 bit code consisting 
	of a 32 bit group id, followed by a 16 bit commmand word.
	Leading this is a header consisting of a 10T signal and a 4T pause.
	All bits start with a pulse of length T. The length of the pause following
	indicates the bit value. A T pause for a 0-bit and a 3T pause for a 1-bit.

  if STD = 1
	The NEC format is a space coded 32 bit code consisting 
	of a 16 bit group id, followed by a 16 bit commmand word.
	Leading this is a header consisting of a 16T signal and a 8T pause.
	All bits start with a pulse of length T. The length of the pause following
	indicates the bit value. A T pause for a 0-bit and a 3T pause for a 1-bit.
	Modified REC80 format by Will Jenkins, wdj@cus.org.uk

  if STD = 2 or 3
	The SONY format is a pulse coded 15 or 12 bit code consisting 
	of a 6 bit device code, followed by a 6 or 9 bit commmand word.
	Leading this is a header consisting of a 4T signal pulse.
	All bits are composed of a pulse of either 1T or 2T in length followed by a
	1T pause. A 2T pulse indicates a 1 bit, and a 1T pulse is a 0 bit.

 if STD = 4
	The RC-5 format used by Philips is bi-phase coded 13 bit code consisting 
	of a 7 bit device code, followed by 6 bit commmand word. Highest two bits of
	device code is startbit and troggle bit. Troggle bit must be masked out 
	because	its change after any keypress.

*/

u16 get_rec80(u08 std)
{
		u08 i, T2, T4, time, tmp = 0;
		union u16convert code;

		code.value = 0;
		timer0_src(CK256);				//update every 32us
		timer0_start();
		loop_until_bit_is_set(IR_PORT-2, IR_BIT);	// skip leading signal


	if(std < 2)
	{	
		timer0_start();

		while (bit_is_set(IR_PORT-2, IR_BIT))
		{
			T2 = inp(TCNT0);
			if (T2 >= 140)				// max wait time
				return 0;
		}
	
		// measure time T

		timer0_start();
		loop_until_bit_is_set(IR_PORT-2, IR_BIT);
	
		T2 = inp(TCNT0);				// T is normally around 0E-10 hex = 15 -> 480 uS
		
		T2 = T2 * 2;
		// max time is 4T
		T4 = T2 * 2;
		
		for (i = 0; i < ((std == 0) ? 48 : 32); i++)
		{
			timer0_start();
			while(1)
			{
				time = inp(TCNT0);
				if (time > T4)
					return 0;
			
				// measure time on the lo flank
				if (bit_is_clear(IR_PORT-2, IR_BIT))
				{
					tmp <<= 1;
					if (time >= T2)
						tmp++;
					break;
				}
			}


			// save command data as we go
			if (std == 0)
			{
				if( i == 39)
					code.bytes.low = tmp;
				if( i == 47)
					code.bytes.high = tmp;
			}
			else
			{
				if( i == 15)
					code.bytes.high = tmp;
				if( i == 31)
					code.bytes.low = tmp;
			}

			// syncronize - wait for next hi flank
			loop_until_bit_is_set(IR_PORT - 2, IR_BIT);
		}
		return (code.value);
	}
	else if(std < 4)					// Format used by SONY remote controllers
	{
		if (inp(TCNT0) <= 60) 
			return 0;				// is it the leading Signal ?			

		// now looking for the Data-bits
		for(i=0; i < ((std == 3) ? 11 : 14); i++)
		{
			tmp = 0x01;
			while (bit_is_set(IR_PORT-2, IR_BIT))
			{
				T2 = inp(TCNT0);
				if (T2 >= 140)			// max wait time
					return 0;
			}
			timer0_start();
			while (bit_is_clear(IR_PORT-2, IR_BIT))
			{
				T2 = inp(TCNT0);
				if (T2 >= 140)			// max wait time
					return 0;
			}
			if (inp(TCNT0) >= 25)			// pulse longer than 1 ms? then logic "1"
				code.value += ((u16)tmp << i);	// the device code 
		}
		return (code.value);
	}

	else	// std=4 -> RC-5;

	{

		for(i=0; i<13; i++)
		{
			if(bit_is_clear(IR_PORT-2, IR_BIT) )
				T2 = 0;
			else
				T2 = 1;

			timer0_start();
			while(1)
			{
				time=inp(TCNT0);
				if(time > 0x21)
					return 0;

				if(bit_is_clear(IR_PORT-2, IR_BIT) && (T2==1) )
				{
					tmp <<= 1;
					tmp++;
					break;
				}
				else if(bit_is_set(IR_PORT-2, IR_BIT) && (T2==0) )
				{
					tmp <<= 1;
					break;
				}
			}

			//save address data
			if(i == 6)
			{
				code.bytes.high = (tmp & 0x5f);		// save address and cut troggle bit
				tmp=0;
			}

			//delay
			timer0_start();
			while(1)
			{
				time=inp(TCNT0);
				if(time > 0x21)
					break;
			}
		}
		code.bytes.low = tmp;
		return(code.value);
	}
}




/****************************************************************************************/




//
// turn on sinewave gerneration 
//
void sine_on(u08 freq)
{
	u08 i,buf[4];
	
	// sine on
	buf[0] = 0x53;	buf[1] = 0xEF;	buf[2] = 0x6E;	buf[3] = freq;

	for (i=0;i<4;i++)
		vs1001_send_data(buf[i]);
	vs1001_nulls(4);
}

//
// turn off sinewave gerneration 
//
void sine_off(void)
{
	u08 i,buf[4];

	// sine off
	buf[0] = 0x45;	buf[1] = 0x78;	buf[2] = 0x69;	buf[3] = 0x74;

	for (i=0;i<4;i++)
		vs1001_send_data(buf[i]);
	vs1001_nulls(4);
}

//
// send three 1kHz sinewave beeps
//
u08 send_beeps(void)
{
	unsigned char i;

	for (i=0;i<3;i++)
	{
		sine_on(62);		// 1 kHz sine
		delayms(100);
		sine_off();
		delayms(100);
	}
	return 0;	
}

//
// sweep through all possible sinewaves
//
u08 sine_sweep(void)
{
	unsigned char i;

	for (i=48;i<119;i++)
	{
		sine_off();
		sine_on(i);	
		delayms(25);
	}
	sine_off();
	return 0;	
}



/****************************************************************************
**
** Various Test stuff
**
****************************************************************************/


//
// 
//
u08 bus_test(void)
{
	u16 v;
	u16 j;

	for (j=0;j<12;j++)	// for each register
	{
		printf("Reg: %d", j);
		v = vs1001_read(j);
		printf(" Value: %04x\n", v);
	}
	printf("\n");
	return 0;	
}

//
// test registers, by writing a value and re-reading it
//
u08 reg_test(void)
{
	u16 buf[20];
	u16 j;

	for (j=0;j<20;j++)	// for each register
	{
		buf[0] = j*256+j;
		vs1001_write(3, buf[0]);
//		PRINT("Wrote: ");UART_Printfu08(j);
		buf[0] = 0xffff;
		buf[0] = vs1001_read(3);
//		PRINT(" Read:"); 
//		UART_Printfu16(buf[0]); EOL();
		if (buf[0] != j*256+j)
			return j;
	}
//	EOL();
	return 0;
}

//
// run the VS1001 built in memory test
//
u08 mem_test(void)
{
	u08 i, buf[4];
	u16 inbuf[2];

	// memtest
	buf[0] = 0x4D;	buf[1] = 0xEA;	buf[2] = 0x6D;	buf[3] = 0x54;

	for (i=0;i<4;i++)
		vs1001_send_data(buf[i]);
	vs1001_nulls(4);

	delayms(100);
	
	inbuf[0] = vs1001_read(8);
		
	if ((inbuf[0] & 0xFF) == 0x7F)
		return 0;
	else 
		return (inbuf[0] & 0xFF);
}

//
// play with volume settings
//
u08 volume_test(void)
{
	u08 i;
	
	sine_on(0x30);
	
	for (i=0;i<0x40;i++)
	{
		vs1001_setvolume(i,i);
		delayms(20);
	}

	vs1001_setvolume(20,20);

	for (i=0;i<21;i++)
	{
		vs1001_setvolume(20-i,20+i);
		delayms(20);
	}
	
	for (i=0;i<40;i++)
	{
		vs1001_setvolume(i,40-i);
		delayms(20);
	}
		
	sine_off();

	vs1001_setvolume(12,12);

	return 0;
}

//
// test the clock doubler by playing a sine wave 
// with and without the doubler active
//
u08 clock_doubler(void)
{
	u16 buf[2];

	// set CLOCKF to compensate for a x-tal and doubler

	// first test default 24.576 MHz clock

	buf[0] = 0;
	vs1001_write(3,buf[0]);	

	sine_on(62);
	delayms(500);
	sine_off();
	delayms(500);
	
	// now test clock doubler (12.288 MHz xtal assumed)

	buf[0] = 0x8000 + 6144;
	vs1001_write(3,buf[0]);	

	sine_on(62);
	delayms(500);
	sine_off();
	delayms(500);
	
	return 0;
}


u08 ata_status(u08 r)
{
	printf("Status: ");
	if (r)
		printf("Fail.\n\n");
	else

⌨️ 快捷键说明

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