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

void sample_init(void)
{
	set_sample_speed(500000);	//òΪ50M
	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 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 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);
}
