#include "sample.h"
#include "stdarg.h"
#include "stdlib.h"
#include "DSO.h"
#include "unistd.h"
#include "system.h"

int speed_table[]={
		1,	//1S
		2,	//500ms
		5,	//200ms
		10,	//100ms
		20,
		50,
		100,
		200,
		500,
		1000,
		2000,
		5000,
		10000,
		20000,
		50000,
		100000,
		200000,
		500000,
		1000000,
		2000000,
		5000000,
		10000000,
		20000000,
		50000000,
		100000000
};


void set_sample_speed(int speed)
{
	int speed_word;

	if(speed == 100000000)
	{
		speed_word = 0;
	}
	else
	{
		speed_word = 100000000/speed - 1;
	}

	IOWR(PIO_SFREQ_BASE, 0, speed_word);	//òΪ50M
}


void sample_init(void)
{
	set_sample_speed(1*1000);	//òΪ500K
	IOWR(PIO_TRIG_SET_BASE, 0, 100 | 0x8000);	//ôģʽΪͨBѹΪ0V

	IOWR_MASTER_WR_CTRL_ADDR(MASTER_WR_CTRL_BASE, DATA_MEM_BASE);//ָݴ洢λΪƬRAM
	IOWR_MASTER_WR_CTRL_LENGTH(MASTER_WR_CTRL_BASE, 1024*2);	//ָΪ2048ֽ
}


void start_sample()
{
	//תʹź10һ壬ת
	IOWR(PIO_EN_BASE, 0, 1);
	IOWR(PIO_EN_BASE, 0, 0);
}

int get_sample_state()
{
	//ȡ״̬Ĵ
	return IORD(PIO_STATE_BASE, 0);
}
