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

📄 dc_spcfc.c

📁 使用ISP1362芯片的USB_OTG参考设计源代码比较新的版本
💻 C
字号:
/*
**  WASABI-Hot! version 1.2c    (OTG sub-unit)
**
**
**      -- copyright (c) 2001-2004 by Philips Japan, Ltd. -- All rights reserved --
**
**
**      ** This code has been made to check/learn                          ** 
**      **                             the ISP1362/ISP1363 functionalities **
**      ** Release 06-Aug-2004                                             **
**
**      OKANO, Akifumi
**      
**		Application Laboratory, Mobile and Connectivity
**      Semiconductors Div, Philips Japan Ltd.
**      akifumi.okano@philips.com
**      +81-3-3740-4668 
*/


#include <stdio.h>
#include <dos.h>
#include <conio.h>

#include "_dc/dc_main.h"
#include "_dc/dc_hal.h"
#include "_dc/dc_comm.h"
#include "_dc/dc_isr.h"
#include "_dc/dc_flags.h"
#include "_dc/dc_chap9.h"
#include "_dc/dc_spcfc.h"

#include "ui.h"

//#include "_hc_hw/dma.h"

#include 		"_otg/otg_demo.h"

void dma_in( void );
void dma_out( void );
void pio_in( void );
void pio_out( void );
//void start_pio_in( unsigned short *buf, unsigned short pio_in_count, int ep_index );
void start_pio_in( void );

//void Vendor_request3( void );

unsigned short tr_count;
unsigned short dc_vs_count;

unsigned short *in_4_buf;


extern unsigned char	*g_transmitting_buffer_pos_ptr;
extern unsigned short	g_transmitting_length;
extern unsigned long	g_remote_file_read_request;

unsigned char			g_dc_ep4_flag	= False;


char			g_s[ 64 ];
unsigned short	g_length;


void Vendor_request3( void )
{
	if ( ( wValue >> 8 ) == OTG_DEMO_GET_A_STRING )			// Get Hello ?
	{
		OTG_demo_peripheral_side_7( g_s, &g_length, wValue & 0xF );
		start_transmit( (unsigned short *)g_s, g_length  );
		Dc_printf( WHITE, CONTINUE, "Hello message returned.  by request from remote\r\n" );
	}
	
	
	else if ( ( wValue >> 8 ) == OTG_DEMO_CTRL_AUDIO )	//	Get list item ?
	{
		unsigned char	start	= 0;
	
		start	= OTG_demo_peripheral_side_9_0( g_s, &g_length, wValue );

		start_transmit( (unsigned short *)g_s, g_length  );

		if ( start )
			OTG_demo_peripheral_side_9_11( wValue );
	}
	
	
	else if ( ( wValue >> 8 ) == OTG_DEMO_CLOCK_SYNC )		//	Clock sync
	{
		OTG_demo_peripheral_side_1( g_s, &g_length, wValue & 0x0F );
		start_transmit( (unsigned short *)g_s, g_length );
	}
	
	
	else if ( ( wValue >> 8 ) == OTG_DEMO_BAR_DISPLAY )	//	Dummy data transfer ?
	{
		OTG_demo_peripheral_side_8( wValue & 0xFF );
		
		start_transmit( (unsigned short *)g_s, 64  );
		Dc_printf( WHITE, CONTINUE, "Dummy data transfer (%02d - %d)\r", wValue & 0x7F, wValue >> 7 );
		
		if ( (wValue & 0xFF) == 69 )
			Dc_printf( WHITE, CONTINUE, "\r\n" );
	}
	
	
	else if ( ( wValue >> 8 ) == OTG_DEMO_APP_UPDATE )	//	Dummy data transfer ?
	{
		OTG_demo_peripheral_side_0( g_s, &g_length, wValue & 0xFF );

		start_transmit( (unsigned short *)g_s, g_length  );
		Dc_printf( WHITE, CONTINUE, "file data transfer %d\r", wValue & 0xFF );
	}
	
	
	else if ( ( wValue >> 8 ) == OTG_DEMO_REMOTE_AUDIO )	//	data transfer through EP4?
	{
		OTG_demo_peripheral_side_2( g_s, &g_length, wValue & 0xFF );

		if ( ctrl.read==1 )
			start_transmit( (unsigned short *)g_s, g_length  );
		else
		{
			vendor_specific.data = 0;
			vendor_specific.wait = 0;

			zero_packet();
		}	
//		Dc_printf( WHITE, CONTINUE, "remote command : 0x%02X\r\n", wValue & 0xFF );
	}

	else if ( ( wValue >> 8 ) == OTG_DEMO_REMOTE_BEEP )			// Get Hello ?
	{
		OTG_demo_peripheral_side_3( g_s, &g_length, wValue & 0xF );
		start_transmit( (unsigned short *)g_s, g_length  );
		Dc_printf( WHITE, CONTINUE, "Got beep command\r\n" );
	}
	

	else								// Unsupported Descriptor?
	{
		Stall_handshake();
		ctrl.read=0;
	}
	
}


void io_request( void )
{
	if ( wIndex == 0x0471 && bRequest == 0x0c && wLength == 0x0006 )
	{
		vendor_specific.wait=1;		
	}
	else
	{
		vendor_specific.data = 0;
		vendor_specific.wait = 0;
		Stall_handshake();	
	}
}

void io_req_data_stage( void )
{
	int i;

	vendor_specific.data = 0;
	vendor_specific.wait = 0;

/*	for (i=0; i<3; Dc_printf( WHITE, CONTINUE, "%04X ", ctrl_out_buf[i++] ) );
	Dc_printf( WHITE, CONTINUE, "\r\n" );
*/
	if ( ctrl_out_buf[2] & 0x8000 )
	{
		if ( ctrl_out_buf[2] & 0x0100 )
			dma_in();
		else
			dma_out();
	}
	else
	{
		if ( ctrl_out_buf[2] & 0x0100 )
			pio_in();
		else
			pio_out();
	}
}

void dma_in( void )
{
	zero_packet();

//	Dc_printf( WHITE, CONTINUE, "DMA IN\r\n" );
}

void dma_out( void )
{
	zero_packet();

//	Dc_printf( WHITE, CONTINUE, "DMA OUT\r\n" );
//	dc_dma_start( 3, dc_dma_buff, dc_vs_count );	// DMA test ep=3, dir=out
//	Dc_printf( WHITE, CONTINUE, "DMA enabled!!\r\n" );

}

void pio_in( void )
{
	zero_packet();

//	Dc_printf( WHITE, CONTINUE, "PIO IN\r\n" );
	dc_vs_count = (( ctrl_out_buf[1] & 0xFF00 ) >>8) | (( ctrl_out_buf[2] & 0x00FF )<<8);
//	start_pio_in( (unsigned short *)g_transmitting_buffer_pos_ptr, g_transmitting_length, 4 );
	start_pio_in();
}

void pio_out( void )
{
	zero_packet();

	Dc_printf( WHITE, CONTINUE, "PIO OUT\r\n" );
}

//void start_pio_in( unsigned short *buf, unsigned short pio_in_count, int ep_index )
void start_pio_in( void )
{
	otg_demo_file_read_periph_side();
	ep4in();
}
	



void ep4in( void )
{
	unsigned short	size;


#ifdef	USE_DOUBLE_BUFFER_FOR_DEV_EP4

	int i, j;
	
	i= (Comm_r16( R_Ep_Status + 4 ) & 0x0060) ? 1 : 2;
	
	for ( j=1; j<=i; j++ )
	{
	


		if ( g_transmitting_length )
		{
			size	= ( g_transmitting_length > 64) ? 64 : g_transmitting_length;

			Comm_w( W_Ep_Buf + 4 , size, g_transmitting_buffer_pos_ptr );
			Comm( Valid_Ep + 4 );
			tr_count 						+= size;
			g_transmitting_length			-= size;
			g_transmitting_buffer_pos_ptr	+= size;
		}
		else
		{
			g_remote_file_read_request		= 1;
	//		vendor_specific.ep4_in	= 1;
		}
	}

#else


	if ( g_transmitting_length )
	{
		size	= ( g_transmitting_length > 64) ? 64 : g_transmitting_length;

		Comm_w( W_Ep_Buf + 4 , size, (unsigned short *)g_transmitting_buffer_pos_ptr );
		Comm( Valid_Ep + 4 );
		tr_count 						+= size;
		g_transmitting_length			-= size;
		g_transmitting_buffer_pos_ptr	+= size;
	}
	else
	{
		g_remote_file_read_request		= 1;
//		vendor_specific.ep4_in	= 1;
	}

#endif
	
}























⌨️ 快捷键说明

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