Ejemplo n.º 1
0
static int
socle_lcm_t6963c_test_sub(void)
{
	int i;

	if (socle_lcm_init())
		return -1;

	if (t6963c_write_ext_char_gen_data(extcg, 0x80, DATA_NUM(extcg)))
		return -1;

	// write text diaplay data (internal CG)
		// set address pointer 1 line, 1 column
	if (t6963c_write_multi_display_data(TXT_HOME_ADDR + 1 * COLUMN + 1, intcg1, DATA_NUM(intcg1)))
		return -1;

	// write text diaplay data (internal CG)
		// set address pointer 3 line, 2 column
	if (t6963c_write_multi_display_data(TXT_HOME_ADDR + 3 * COLUMN + 2, intcg2, DATA_NUM(intcg2)))
		return -1;

	// write text diaplay data (externel CG upper part)
		// set address pointer 5 line, 8 column
	if (t6963c_write_multi_display_data(TXT_HOME_ADDR + 5 * COLUMN + 8, expart1, DATA_NUM(expart1)))
		return -1;

	// write text diaplay data (externel CG lower part)
		// set address pointer 6 line, 8 column
	if (t6963c_write_multi_display_data(TXT_HOME_ADDR + 6 * COLUMN + 8, expart2, DATA_NUM(expart2)))
		return -1;

	for (i = 0; i < 5; i++) {
		// write text diaplay data (1 ~ 5)
			// set address pointer 6 line, 4 column
		if (t6963c_write_single_display_data(TXT_HOME_ADDR + 6 * COLUMN + 4, 0x11 + i, 1))
			return -1;

		if (t6963c_write_single_display_data(GRA_HOME_ADDR, 0x3f, COLUMN * GRA_LINE))
			return -1;
		MSDELAY(100);

		if (t6963c_write_single_display_data(GRA_HOME_ADDR, 0x00, COLUMN * GRA_LINE))
			return -1;
		MSDELAY(100);
	}

	return 0;
}
Ejemplo n.º 2
0
void process_vbus_intr()
{
	;//printf("\n USB VBus Interrupt");

SOFT_DISCONNECT();
MSDELAY(3);
SOFT_CONNECT();
MSDELAY(3);

	bIsConnected = VBUS_OK();

	if (bIsConnected)
		;//printf(" -> USB VBus connect\n");
	else
		;//printf(" -> USB VBus disconnect");
}
Ejemplo n.º 3
0
static int
socle_audio_dac_mute(void)
{
	int ret;

	MSDELAY(1000);
	ret = audio_dac_mute(true);
	if (ret)
		return -1;
	MSDELAY(1000);
	ret = audio_dac_mute(false);
	if (ret)
		return -1;

	return 0;
}
Ejemplo n.º 4
0
static int 
socle_audio_adc_mixer_dc_filter(void)
{
	int ret;

	MSDELAY(3000);
	ret = audio_mixer_dc_filter(true);
	if (ret)
		return -1;
	MSDELAY(3000);
	ret = audio_mixer_dc_filter(false);
	if (ret)
		return -1;

	return 0;
}
Ejemplo n.º 5
0
extern int
RTCTesting(int autotest)
{
	int result = 0;
	
#if defined(CONFIG_LDK5) || defined(CONFIG_PDK) || defined(CONFIG_PC7210)
	u32 check;
	check = ioread32(SOCLE_RTC_TIME);
	RESET_RTC_CIRCUIT();
	MSDELAY(1000);
	if(ioread32(SOCLE_RTC_TIME) == check)
        	RESET_RTC_COUNTER();       
	 if (RTC_IS_PWFAIL) {
                printf("Warning: RTC Power Fail!!\n");
                printf("\tPlease change your battery and then reset RTC again...\n");
        }
        if(!RTC_IS_GOOD){
                printf("RTC is not Power Good\n");
        }
#endif	//CONFIG_LDK5

	RTC_SET_DIVIDER(RTC_DIVIDER);
	
	RTC_EN();
	
	result = test_item_ctrl(&rtc_main_container, autotest);
	
	RTC_DIS();
	
	return result;
}
Ejemplo n.º 6
0
extern void
vopReset()
{
	socle_vop_write(VOP_CTRL_RESET | VOP_CTRL_DISPLAY_DIS, SOCLE_VOP_CTRL);
	MSDELAY(260);
	socle_vop_write(VOP_INT_DISABLE, SOCLE_VOP_INTE);
	socle_vop_write(VOP_CTRL_NO_RESET | VOP_CTRL_DISPLAY_DIS, SOCLE_VOP_CTRL);
}
Ejemplo n.º 7
0
extern int cat6613_init(void)
{
	int ret=0;
	u8 buf[3];
	i2c_master_initialize(SOCLE_I2C0, SOCLE_INTC_I2C0);
	cat6613_client.addr = 0x4d;
	
	buf[0]=cat6613_read(0x00);
	buf[1]=cat6613_read(0x01);
	buf[2]=cat6613_read(0x02);
	buf[3]=cat6613_read(0x03);
	
	printf("vid=%x %x did=%x %x\n",buf[0],buf[1],buf[2],buf[3]);
	
		//reset
		cat6613_write( 0x0F , 0x00);
		cat6613_write( 0x04 , 0x3d);
		MSDELAY(2);
		cat6613_write( 0x04 , 0x1d);
		//set init int
		//cat6613_write(0x09,0xfc);
		//cat6613_write(0x0a,0xf8);
		//cat6613_write(0x0b,0xf7);
		//disable out
		cat6613_write(0xc0, 0x00);
		cat6613_write(0xc1, 0x03);
   
   cat6613_write( 0x04 , 0x14);
   MSDELAY(2);
   cat6613_write( 0x04 , 0x00);
   
   cat6613_write(0x61,0x03);
	cat6613_write(0x62,0x18);
	cat6613_write(0x63,0x10);
	cat6613_write(0x64,0x04);
	
   
   
	cat6613_write(0x90,0x6);
	cat6613_write(0x72,0x80);
	cat6613_write(0xc1,0);
	cat6613_write(0xc6,0x3);
	
	return ret;
}
Ejemplo n.º 8
0
static int
socle_audio_dac_de_emphasis(void)
{
	int ret;

	MSDELAY(1000);
	ret = audio_dac_de_emphasis(UDA1342TS_FUNC_DAC_FEATURES_DE_EMPHASIS_44_1KHZ);
	if (ret)
		return -1;

	return 0;
}
Ejemplo n.º 9
0
extern void
vipReset()
{
#ifdef CONFIG_PC9220
	socle_vip_write(VIP_RESET, SOCLE_VIP_RESET);
#else
	socle_vip_write(VIP_CTRL_RESET, SOCLE_VIP_CTRL);
#endif
	MSDELAY(260);
	socle_vip_write(VIP_INT_MASK_DISABLE, SOCLE_VIP_INT_MASK);
	socle_vip_write(VIP_CTRL_CAPTURE_DIS, SOCLE_VIP_CTRL);
}
Ejemplo n.º 10
0
static int
socle_audio_adc_input_amplifier_gain_increment(void)
{
	int i, ret;

	/* Audio codec input amplifier gain up */
	for (i = 0; i <= 8 ; i++) {
		ret = audio_adc_input_amplifier_gain(UDA1342TS_FUNC_ADC_INPUT_MIXER_GAIN_CH1, i);
		if (ret)
			return -1;
		MSDELAY(1000);
	}

	return 0;
}
Ejemplo n.º 11
0
static int
socle_audio_dac_treble_decrement(void)
{
	int i, ret;

	/* Audio codec bass boost up */
	for (i = 3; i >= 0 ; i--) {
		ret = audio_dac_treble(i);
		if (ret)
			return -1;
		MSDELAY(1000);
	}

	return 0;
}
Ejemplo n.º 12
0
int clcd_brightness_increment(int autotest)
{
	if (autotest)
	{
		while((readl (PWMT0_HRC) + DUTY_ALL/10) < readl (PWMT0_LRC)) {
			writel (readl (PWMT0_HRC) + DUTY_ALL/10, PWMT0_HRC);
			MSDELAY(5);	/* 1 second delay */
		}
	}
	else
	{
		if (readl (PWMT0_HRC) + DUTY_ALL/10 < readl (PWMT0_LRC))
			writel (readl (PWMT0_HRC) + DUTY_ALL/10, PWMT0_HRC);
	}
	return 0;

}
Ejemplo n.º 13
0
static int
socle_audio_dac_mixer_volume_decrement(void)
{
	int i, ret;

	/* Audio codec mixer volume down */
	for (i = 0; i < 200; i += 20) {
		ret = audio_dac_mixer_volume(i);
		if (ret)
			return -1;
		MSDELAY(1000);
	}
	ret = audio_dac_mixer_volume(200);
	if (ret)
		return -1;

	return 0;
}
Ejemplo n.º 14
0
static int
socle_audio_adc_mixer_gain_decrement(void)
{
	int i, ret;

	/* Audio codec mixer gain down */
	for (i = 255; i > 128; i -= 13) {
		ret = audio_adc_mixer_gain(UDA1342TS_FUNC_ADC_INPUT_MIXER_GAIN_CH1, i);
		if (ret)
			return -1;
		MSDELAY(1000);
	}

	ret = audio_adc_mixer_gain(UDA1342TS_FUNC_ADC_INPUT_MIXER_GAIN_CH1, 128);
	if (ret)
		return -1;
	return 0;
}
Ejemplo n.º 15
0
static int
socle_audio_adc_mixer_gain_increment(void)
{
	int i, ret;

	/* Audio codec mixer gain up */
	for (i = 0; i < 48; i += 5) {
		ret = audio_adc_mixer_gain(UDA1342TS_FUNC_ADC_INPUT_MIXER_GAIN_CH1, i);
		if (ret)
			return -1;
		MSDELAY(1000);
	}

	ret = audio_adc_mixer_gain(UDA1342TS_FUNC_ADC_INPUT_MIXER_GAIN_CH1, 48);
	if (ret)
		return -1;
	return 0;
}
Ejemplo n.º 16
0
static int
socle_audio_dac_bass_boost_decrement(void)
{
	int i, ret;

	/* Audio codec bass boost up */
	for (i = 15; i > 0 ; i-= 3) {
		ret = audio_dac_bass_boost(i);
		if (ret)
			return -1;
		MSDELAY(1000);
	}
	ret = audio_dac_bass_boost(0);
	if (ret)
		return -1;

	return 0;
}
Ejemplo n.º 17
0
static int
socle_audio_dac_bass_boost_increment(void)
{
	int i, ret;

	/* Audio codec bass boost up */
	for (i = 0; i < 16; i+= 3) {
		ret = audio_dac_bass_boost(i);
		if (ret)
			return -1;
		MSDELAY(1000);
	}
	ret = audio_dac_bass_boost(15);
	if (ret)
		return -1;

	return 0;
}
Ejemplo n.º 18
0
int USBTesting()
{
	UINT	ch;		// channel number
	UINT	TX_Status;
	CHAR	*dma_src_addr;
#ifdef	UDC_SOCLE_PHY
		ASSERT_SOFT_POR();
#if 0
		isr_time_value   = 0;
		isr_waiting_time = 1;
		setup_1ms_timer(1);
#else
		MSDELAY(1);
#endif

		while (isr_time_value != isr_waiting_time);

		DEASSERT_SOFT_POR();
#endif

#ifdef	UDC_SOCLE_PHY
#if 0
		isr_time_value   = 0;
		isr_waiting_time = 8;
		setup_1ms_timer(8);
#else
		MSDELAY(8);
#endif

		while (isr_time_value != isr_waiting_time);

//		SET_PHY_16_BIT();
#endif

	ResetFlag = 0;
	bIsConnected = VBUS_OK();
//	if (bIsConnected)
//		printf(" -> USB VBus connect\n");
//	else
//		printf(" -> USB VBus disconnect");

	// enable interrupt
	INT0_ENABLE(LDK_INTC_UDC);

	// setup interrupt handler
	connectInterrupt( LDK_INTC_UDC, UDCIintHandler, NULL);

	INT0_SET_MASK(LDK_INTC_UDC);

	while (1) {
//		;printf("\n USB cable disconnected!\n");

		SOFT_DISCONNECT();

		// wait for plugin stable on vbus
		printf("\nWait for USB Host connect...");
//		while ( !bIsConnected );
//CY++ for checking USB Host connect waiting
		int wait=0;
		while ( !bIsConnected ){
          		MSDELAY(60);
			printf("%4d", wait);			
          		wait++;
          		if(wait > 100)
             			return USB_NO_CONNECT_ERROR;
			printf("\b\b\b\b");
        	}

#ifdef	UDC_SOCLE_PHY
		ASSERT_SOFT_POR();
#if 0
		isr_time_value   = 0;
		isr_waiting_time = 1;
		setup_1ms_timer(1);
#else
		MSDELAY(1);
#endif

		while (isr_time_value != isr_waiting_time);

		DEASSERT_SOFT_POR();
#endif

#ifdef	UDC_SOCLE_PHY
#if 0
		isr_time_value   = 0;
		isr_waiting_time = 8;
		setup_1ms_timer(8);
#else
		MSDELAY(8);
#endif

		while (isr_time_value != isr_waiting_time);

//		SET_PHY_16_BIT();
#endif
		initUDCController();	// initialize UDC Controller
		initUDCTestingEnv();	// initialize UDC testing environment

		SOFT_CONNECT();

		;//printf("\n USB cable connected!\n");

		uNeedDoProcCtrlBlockNum = 0;
		for (ch = 0; ch < NUM_OF_USB_CHANNEL; ch++) {
			ChannelSet[ch].uLoopbackCount = 0;
			ChannelSet[ch].uIntrINCount   = 0;

			// start receive from Bulk_OUT pipe
			writew(virt_to_phy( (u32_t)ChannelSet[ch].pBulkOutBuffer), UDC_DMALM_OADDR(ChannelSet[ch].uBulk_OUT));
			writew( ENP_DMA_START, UDC_DMACTRLO(ChannelSet[ch].uBulk_OUT));
		}

		while ( bIsConnected ) {
			// check ENP 0 transmit request
			if ( uNeedDoProcCtrlBlockNum > 0 ) {
				int		dma_size;
				
				// dma done now, polling for empty data set
				if (!( readw(UDC_TX0BUF) & TxFULL)) {

					// critical section
					DisableInterrupt();
					uNeedDoProcCtrlBlockNum--;
					dma_src_addr = CtrlInBuffer + uCurrentCtrlBlockNum++ * uCurrentCtrlPacketSize;

					if ( uControlDataSize > uCurrentCtrlPacketSize ) {
						dma_size = uCurrentCtrlPacketSize;
					}
					else {
						dma_size = uControlDataSize;
					}

					// calculate remaining bytes need transfer
					uControlDataSize -= dma_size;

					writew( dma_size, UDC_TX0STAT );
					writew( virt_to_phy((u32_t)dma_src_addr) , UDC_DMA0LM_IADDR );
					writew( ENP_DMA_START , UDC_DMA0CTLI );
					
					EnableInterrupt();
					
					// set ACK--after we have overwritten the previously incorrect data
					writew( readw( UDC_TX0CON ) & ~TxNAK, UDC_TX0CON );					
				
					
				}
			}

			// check channel group transmit request
			for (ch = 0; ch < NUM_OF_USB_CHANNEL; ch++) {

				// check each Bulk_IN End Point transmit request
				if ( ChannelSet[ch].uLoopbackCount > 0 ) {
					if (ChannelSet[ch].bBulkDMAOnGoing == false) {

						// check buffer is available for transmit data
						TX_Status = readw(UDC_TXBUF(ChannelSet[ch].uBulk_IN));	// get buffer status

						if ((TX_Status & TxFULL) == 0) {
#if 0
							if ((TX_Status & TxDS0) == 0)
								DEBUG_OUT('0');
							if ((TX_Status & TxDS1) == 0)
								DEBUG_OUT('1');
#endif

							//DEBUG_OUT('i');

							// enter critical section, protect share variable
							DisableInterrupt();

							//DEBUG_OUT('+');

							ChannelSet[ch].uLoopbackCount--;
							// get transmit buffer address & move buffer to next position
							dma_src_addr = ChannelSet[ch].pBulkInBuffer + ChannelSet[ch].uCurrentBulkInBlockNum * uBulkBlockSize;

							// setup DMA
							writew( ChannelSet[ch].sBulkBlockSizeBuffer[ChannelSet[ch].uCurrentBulkInBlockNum],
									UDC_TXSTAT(ChannelSet[ch].uBulk_IN) );	// write transmit count
							writew( virt_to_phy((u32_t)dma_src_addr),	// set transmit buffer pointer
									UDC_DMALM_IADDR(ChannelSet[ch].uBulk_IN) );
							writew( ENP_DMA_START , UDC_DMACTRLI(ChannelSet[ch].uBulk_IN) );			// start transmit DMA

							// move to next buffer
							ChannelSet[ch].uCurrentBulkInBlockNum = ++ChannelSet[ch].uCurrentBulkInBlockNum % uMaxBlockNumber;

#if 0
							WAIT_DMA_DONE(UDC_TXSTAT(ChannelSet[ch].uBulk_IN));
#endif
#if 0
							for (delay = 0; delay < 1000; delay++) {
								TX2_DMAOnGoing = true;
							}
#endif

							ChannelSet[ch].bBulkDMAOnGoing = true;

							//DEBUG_OUT('-');

							EnableInterrupt();

							// leave critical section
						}
					}
				}

				// check each Intr_IN End Point transmit request
				if ( ChannelSet[ch].uIntrINCount > 0 ) {
//					if (!( readw(UDC_TXBUF(ChannelSet[ch].uIntr_IN)) & TxFULL)) {
					if (ChannelSet[ch].bIntrDMAOnGoing == false) {

						// critical section
						DisableInterrupt();
						ChannelSet[ch].uCurrentIntrInBlockNum--;
						dma_src_addr = ChannelSet[ch].pIntrInBuffer + ChannelSet[ch].uCurrentIntrInBlockNum * INTR_BLOCK_SIZE;
						EnableInterrupt();

						writew( INTR_BLOCK_SIZE, UDC_TXSTAT(ChannelSet[ch].uIntr_IN) );
						writew( virt_to_phy((u32_t)dma_src_addr), UDC_DMALM_IADDR(ChannelSet[ch].uIntr_IN) );
						writew( ENP_DMA_START, UDC_DMACTRLI(ChannelSet[ch].uIntr_IN) );

						ChannelSet[ch].bIntrDMAOnGoing = true;
#if 0
						WAIT_DMA_DONE(UDC_DMACTRLI(ChannelSet[ch].uIntr_IN) );
#endif
						ChannelSet[ch].uCurrentBulkInBlockNum = ++ChannelSet[ch].uCurrentBulkInBlockNum % MAX_INTR_NUM;
					}
				}
			}
		}
	}

	// leave usb test now, should never been here
	return 0;
}
Ejemplo n.º 19
0
static int
socle_audio_dac_master_volume_increment(void)
{
	int i, ret;

	/* Audio codec volume up */
#ifdef CONFIG_UDA1342TS
        for (i = MAX_VOLUME; i >= 0 ; i -= 25) {
#else
	for (i = 0; i <= MAX_VOLUME ; i++) {
#endif
		ret = audio_dac_master_volume(i);
		if (ret)
			return -1;
		MSDELAY(1000);
	}
#ifdef CONFIG_UDA1342TS
	ret = audio_dac_master_volume(0);
#else
	ret = audio_dac_master_volume(MAX_VOLUME);
#endif

	if (ret)
		return -1;

	return 0;
}

static int
socle_audio_dac_master_volume_decrement(void)
{
	int i, ret;

	/* Audio codec volume down */
#ifdef CONFIG_UDA1342TS	
	for (i = 0; i <= MAX_VOLUME; i += 25) {
#else
	for (i = MAX_VOLUME; i >= 0; i--) {
#endif
		ret = audio_dac_master_volume(i);
		if (ret)
			return -1;
		MSDELAY(1000);
	}
#ifdef CONFIG_UDA1342TS
	ret = audio_dac_master_volume(0);
#else
	ret = audio_dac_master_volume(MAX_VOLUME);
#endif

	if (ret)
		return -1;

	return 0;
}

static int
socle_audio_dac_mixer_volume_increment(void)
{
	int i, ret;

	/* Audio codec mixer volume up */
	for (i = 200; i > 0 ; i -= 20) {
		ret = audio_dac_mixer_volume(i);
		if (ret)
			return -1;
		MSDELAY(1000);
	}
	ret = audio_dac_master_volume(0);
	if (ret)
		return -1;

	return 0;
}
Ejemplo n.º 20
0
static int
socle_lcm_t6963c_test_sub(void)
{
	int i, j;

	if (socle_lcm_init())
		return -1;

#ifdef T6963C_REVERSE
	if (t6963c_write_ext_char_gen_data(ascii_table, 0x80, DATA_NUM(ascii_table)))
		return -1;
#endif
	
	if (socle_lcm_t6963c_print_str_with_attr(1, 1, "Diagnostic  Program", BLINK_NORMAL_DISP))
		return -1;
	if (socle_lcm_t6963c_print_str_with_attr(3, 2, "Socle Tech. Corp.", NORMAL_DISP))
		return -1;

	for (i = 0; i < 3; i++) {
		if (socle_lcm_t6963c_print_bar(i + 5, 1))
			return -1;

		for (j = 0; j < 16; j++) {
			char word[2] = "";
			word[0] = '_';
			if (t6963c_write_string_data(i + 5, j + 2, word, 1))
				return -1;
			MSDELAY(100);

			word[0] = 0x30 + i * 16 + j;
			if (t6963c_write_string_data(i + 5, j + 2, word, 1))
				return -1;
		}

		if (socle_lcm_t6963c_print_bar(i + 5, 0))
			return -1;
	}

	for (i = 0; i < 3; i++) {
		if (socle_lcm_t6963c_print_str_with_attr(i + 5, 2, "                ", NORMAL_DISP))
			return -1;
	}

	//flash
	for (i = 0; i < 4; i++) {
		if (socle_lcm_t6963c_print_bar(3, 1))
			return -1;
		MSDELAY(100);

		if (socle_lcm_t6963c_print_bar(3, 0))
			return -1;
		MSDELAY(100);
	}
	if (socle_lcm_t6963c_print_bar(3, 1))
		return -1;

#ifdef T6963C_REVERSE
	if (socle_lcm_t6963c_draw_rectangle_with_attr(0, 0, COLUMN - 1, 5, NORMAL_DISP))
		return -1;
	if (socle_lcm_t6963c_draw_line_with_attr(2, 1, 0, COLUMN - 3,  NORMAL_DISP))
		return -1;
#endif

	if (socle_lcm_t6963c_print_str_with_attr(5, 0, "www.socle-tech.com.tw", REVERSE_DISP))
		return -1;
	if (socle_lcm_t6963c_print_str_with_attr(6, 1, "TEL : 886-3-5163166", REVERSE_DISP))
		return -1;
	if (socle_lcm_t6963c_print_str_with_attr(7, 1, "FAX : 886-3-5163177", REVERSE_DISP))
		return -1;

	if (t6963c_write_attribute_data(3, 1, COLUMN - 4, BLINK_REVERSE_DISP))
		return -1;

	return 0;
}
Ejemplo n.º 21
0
int USBTesting()
{
	UINT	ch;		// channel number
	UINT	TX_Status;
	CHAR	*dma_src_addr;
	char	Continue_test = 1;
	
//cyli++ 01/17/07
	if (IS_16_ENDPT()) {
		printf("16 end-points\n");
	} else if (IS_10_ENDPT()) {
		printf("10 end-points\n");
	} else if (IS_4_ENDPT()) {
		printf("4 end-points\n");
	} else {
		printf("Error end-point number!\n");
		printf("DEV_INFO = 0x%08x", readw(UDC_DEVINFO) & ENDPT_NUM_MASK);
	}

// CY+ to fix program reload Socle phy hang up problem
#ifdef	UDC_SOCLE_PHY
		ASSERT_SOFT_POR();
#if 0
		isr_time_value   = 0;
		isr_waiting_time = 1;
		setup_1ms_timer(1);
#else
		MSDELAY(1);
#endif

		while (isr_time_value != isr_waiting_time);

		DEASSERT_SOFT_POR();
#endif

#ifdef	UDC_SOCLE_PHY
#if 0
		isr_time_value   = 0;
		isr_waiting_time = 8;
		setup_1ms_timer(8);
#else
		MSDELAY(8);
#endif

		while (isr_time_value != isr_waiting_time);

//		SET_PHY_16_BIT();
#endif

	ResetFlag = 0;
	bIsConnected = VBUS_OK();
//	if (bIsConnected)
//		printf(" -> USB VBus connect\n");
//	else
//		printf(" -> USB VBus disconnect");

	// enable interrupt
	INT0_ENABLE(LDK_INTC_UDC);

	// setup interrupt handler
	connectInterrupt( LDK_INTC_UDC, UDCIintHandler, NULL);

	INT0_SET_MASK(LDK_INTC_UDC);

	while (1) {
//		;printf("\n USB cable disconnected!\n");

		SOFT_DISCONNECT();

		// wait for plugin stable on vbus
//		printf("\nWait for USB Host connect...");
//		while ( !bIsConnected );
//CY++ for checking USB Host connect waiting
		int wait=0;
		while ( !bIsConnected ){
          		MSDELAY(60);
			printf("%4d", wait);			
          		wait++;
          		if(wait > 100)
             			return USB_NO_CONNECT_ERROR;
			printf("\b\b\b\b");
        	}

#ifdef	UDC_SOCLE_PHY
		ASSERT_SOFT_POR();
#if 0
		isr_time_value   = 0;
		isr_waiting_time = 1;
		setup_1ms_timer(1);
#else
		MSDELAY(1);
#endif

		while (isr_time_value != isr_waiting_time);

		DEASSERT_SOFT_POR();
#endif

#ifdef	UDC_SOCLE_PHY
#if 0
		isr_time_value   = 0;
		isr_waiting_time = 8;
		setup_1ms_timer(8);
#else
		MSDELAY(8);
#endif

		while (isr_time_value != isr_waiting_time);

//		SET_PHY_16_BIT();
#endif
		initUDCController();	// initialize UDC Controller
		initUDCTestingEnv();	// initialize UDC testing environment
		SOFT_CONNECT();
		;//printf("\n USB cable connected!\n");
		uNeedDoProcCtrlBlockNum = 0;
		while ( bIsConnected ) {
			// check ENP 0 transmit request
			if ( uNeedDoProcCtrlBlockNum > 0 ) {
				int		dma_size;
				
				// dma done now, polling for empty data set
				if (!( readw(UDC_TX0BUF) & TxFULL)) {

					// critical section
					DisableInterrupt();
					uNeedDoProcCtrlBlockNum--;
					dma_src_addr = CtrlInBuffer + uCurrentCtrlBlockNum++ * uCurrentCtrlPacketSize;

					if ( uControlDataSize > uCurrentCtrlPacketSize ) {
						dma_size = uCurrentCtrlPacketSize;
					}
					else {
						dma_size = uControlDataSize;
					}

					// calculate remaining bytes need transfer
					uControlDataSize -= dma_size;

					writew( dma_size, UDC_TX0STAT );
					writew( virt_to_phy((u32_t)dma_src_addr) , UDC_DMA0LM_IADDR );
					writew( ENP_DMA_START , UDC_DMA0CTLI );
					EnableInterrupt();
					
					// set ACK--after we have overwritten the previously incorrect data
					writew( readw( UDC_TX0CON ) & ~TxNAK, UDC_TX0CON );
				
					
				}
			}
		    if (Continue_test){
				printf("Done\n");
		            	printf("USB initialize...Done\n");
		            	printf("HandShaking...Done\n");
				printf("Waiting for Bulk Read/Write test...\n");
				printf("Remove Socle USB Bulk device Hardware from Windows and USB cable to Exit !!!\n");
				Continue_test = 0;
	    		}
			// check channel group transmit request
			for (ch = 0; ch < NUM_OF_USB_CHANNEL; ch++) {

				// check each Bulk_IN End Point transmit request
				if ( ChannelSet[ch].uLoopbackCount > 0 ) {
					if (ChannelSet[ch].bBulkDMAOnGoing == false) {

						// check buffer is available for transmit data
						TX_Status = readw(UDC_TXBUF(ChannelSet[ch].uBulk_IN));	// get buffer status

						if ((TX_Status & TxFULL) == 0) {
#if 0
							if ((TX_Status & TxDS0) == 0)
								DEBUG_OUT('0');
							if ((TX_Status & TxDS1) == 0)
								DEBUG_OUT('1');
#endif

							//DEBUG_OUT('i');

							// enter critical section, protect share variable
							DisableInterrupt();

							//DEBUG_OUT('+');

							ChannelSet[ch].uLoopbackCount--;
							// get transmit buffer address & move buffer to next position
							dma_src_addr = ChannelSet[ch].pBulkInBuffer + ChannelSet[ch].uCurrentBulkInBlockNum * uBulkBlockSize;

							// setup DMA
							writew( ChannelSet[ch].sBulkBlockSizeBuffer[ChannelSet[ch].uCurrentBulkInBlockNum],
									UDC_TXSTAT(ChannelSet[ch].uBulk_IN) );	// write transmit count
							writew( virt_to_phy((u32_t)dma_src_addr),	// set transmit buffer pointer
									UDC_DMALM_IADDR(ChannelSet[ch].uBulk_IN) );
							writew( ENP_DMA_START , UDC_DMACTRLI(ChannelSet[ch].uBulk_IN) );			// start transmit DMA

							// move to next buffer
							ChannelSet[ch].uCurrentBulkInBlockNum = ++ChannelSet[ch].uCurrentBulkInBlockNum % uMaxBlockNumber;

#if 0
							WAIT_DMA_DONE(UDC_TXSTAT(ChannelSet[ch].uBulk_IN));
#endif
#if 0
							for (delay = 0; delay < 1000; delay++) {
								TX2_DMAOnGoing = true;
							}
#endif

							ChannelSet[ch].bBulkDMAOnGoing = true;

							//DEBUG_OUT('-');

							EnableInterrupt();

							// leave critical section
						}
					}
				}

				// check each Intr_IN End Point transmit request
				if ( ChannelSet[ch].uIntrINCount > 0 ) {
//					if (!( readw(UDC_TXBUF(ChannelSet[ch].uIntr_IN)) & TxFULL)) {
					if (ChannelSet[ch].bIntrDMAOnGoing == false) {

						// critical section
						DisableInterrupt();
						ChannelSet[ch].uCurrentIntrInBlockNum--;
						dma_src_addr = ChannelSet[ch].pIntrInBuffer + ChannelSet[ch].uCurrentIntrInBlockNum * INTR_BLOCK_SIZE;
						EnableInterrupt();

						writew( INTR_BLOCK_SIZE, UDC_TXSTAT(ChannelSet[ch].uIntr_IN) );
						writew( virt_to_phy((u32_t)dma_src_addr), UDC_DMALM_IADDR(ChannelSet[ch].uIntr_IN) );
						writew( ENP_DMA_START, UDC_DMACTRLI(ChannelSet[ch].uIntr_IN) );

						ChannelSet[ch].bIntrDMAOnGoing = true;
#if 0
						WAIT_DMA_DONE(UDC_DMACTRLI(ChannelSet[ch].uIntr_IN) );
#endif
						ChannelSet[ch].uCurrentBulkInBlockNum = ++ChannelSet[ch].uCurrentBulkInBlockNum % MAX_INTR_NUM;
					}
				}
			}
		}
 		// CY+ for disconnect detect and exit testing program	
		printf ("USB Host disconnected !!!\n");
		printf ("Press Y to continue and any other Key to exit? ");
		char	i;	
		i=getchar();
		if((i!='Y')&&(i!='y'))
		{
			printf ("\n");		
			return UPF_TEST_SUCCESS;
		}
		else
			Continue_test = 1;
	}

	// leave usb test now, should never been here
	return USB_UNKONW_ERROR;
}