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

📄 hal4d13.c

📁 ISP1181MCU_FW_Ver1.01.zip是基于飞利浦ISP1181的USB HOST开发板固件源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
   //*************************************************************************
   //
   //                  P H I L I P S   P R O P R I E T A R Y
   //
   //           COPYRIGHT (c)   1999 BY PHILIPS SINGAPORE.
   //                     --  ALL RIGHTS RESERVED  --
   //
   // File Name:	HAL4D13.C
   // Created:		Oct 14, 2000
   // Modified:
   // Revision:		1.01
   //
   //*************************************************************************
   //
   //*************************************************************************
   */
#include <reg51.h>                /* special function register declarations   */

#include "BasicTyp.H"
#include "SysCnfg.h"
#include "common.h"
#include "Hal4Sys.h"
#include "mainloop.h"
#include "Hal4d13.h"


/*
//*************************************************************************
//  Public static data
//*************************************************************************
*/

extern D13FLAGS bD13flags;
//extern CONTROL_XFER ControlData;


/*
//*************************************************************************
//  Private static data
//*************************************************************************
*/

//void interrupt (*Hal4D13_OldIsr4D13)(void);

/*
//*************************************************************************
// Subroutines -- 1
//*************************************************************************
*/

/*
//*************************************************************************
//  Subroutines -- 2
//*************************************************************************
*/

void Hal4D13_SetDevConfig(USHORT wDevCnfg)
{
//	if(bD13flags.bits.At_IRQL1 == 0)
//		RaiseIRQL();

	outportb(D13_COMMAND_PORT,D13CMD_DEV_WR_CNFG);
	outportb(D13_DATA_PORT,(UCHAR)wDevCnfg);
	outportb(D13_DATA_PORT,(UCHAR)(wDevCnfg >> 8));

//	if(bD13flags.bits.At_IRQL1 == 0)
//		LowerIRQL();
}

void Hal4D13_SetMode(UCHAR bMode)
{
//	if(bD13flags.bits.At_IRQL1 == 0)
//		RaiseIRQL();

	outportb(D13_COMMAND_PORT, D13CMD_DEV_WR_MODE);
	outportb(D13_DATA_PORT, bMode);

//    if(bD13flags.bits.At_IRQL1 == 0)
//		LowerIRQL();
}
/*
UCHAR Hal4D13_GetMode(void)
{
    UCHAR c;
	if(bD13flags.bits.At_IRQL1 == 0)
		RaiseIRQL();

    outportb(D13_COMMAND_PORT, D13CMD_DEV_RD_MODE);
    c = inportb(D13_DATA_PORT);

    if(bD13flags.bits.At_IRQL1 == 0)
		LowerIRQL();
    return c;
}

UCHAR Hal4D13_GetAddress(void)
{
	UCHAR c;
//	if(bD13flags.bits.At_IRQL1 == 0)
//		RaiseIRQL();

	outportb(D13_COMMAND_PORT, D13CMD_DEV_RD_ADDR);
	c = inportb(D13_DATA_PORT);

//	if(bD13flags.bits.At_IRQL1 == 0)
//		LowerIRQL();
	return c;
}
*/
void Hal4D13_SetAddressEnable(UCHAR bAddress, UCHAR bEnable)
{
//	if(bD13flags.bits.At_IRQL1 == 0)
//		RaiseIRQL();

	outportb(D13_COMMAND_PORT, D13CMD_DEV_WR_ADDR);
	if(bEnable)
		bAddress |= D13REG_DEVADDR_EN;
    else
		bAddress &= D13REG_DEVADDR_MASK;

	outportb(D13_DATA_PORT, bAddress);

//	if(bD13flags.bits.At_IRQL1 == 0)
//		LowerIRQL();
}

//Jan10, the cmd not support
/*
void Hal4D13_SendResume(void)
{
	UCHAR c;
	if(bD13flags.bits.At_IRQL1 == 0)
		RaiseIRQL();

    outportb(D13_COMMAND_PORT, D13CMD_DEV_RD_MODE);
    c = inportb(D13_DATA_PORT);
	outportb(D13_COMMAND_PORT, D13CMD_DEV_WR_MODE);
    outportb(D13_DATA_PORT, D13REG_MODE_RESUME|c);

    if(bD13flags.bits.At_IRQL1 == 0)
		LowerIRQL();
}
*/

//Jan10, WARNING 16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
/*
void Hal4D13_SoftConnect(UCHAR bEnable)
{
	UCHAR c;
	if(bD13flags.bits.At_IRQL1 == 0)
		RaiseIRQL();

    outportb(D13_COMMAND_PORT, D13CMD_DEV_RD_MODE);
	c = inportb(D13_DATA_PORT);
    if(bEnable)
		c |= D13REG_MODE_SOFTCONNECT;
	else
		c &= ~D13REG_MODE_SOFTCONNECT;

	outportb(D13_COMMAND_PORT, D13CMD_DEV_WR_MODE);
    outportb(D13_DATA_PORT, c);

    if(bD13flags.bits.At_IRQL1 == 0)
		LowerIRQL();
}
*/
void Hal4D13_AcknowledgeSETUP(void)
{
//	if(bD13flags.bits.At_IRQL1 == 0)
//		RaiseIRQL();

	outportb(D13_COMMAND_PORT, D13CMD_ACK_SETUP);

//	if(bD13flags.bits.At_IRQL1 == 0)
//		LowerIRQL();
}

void Hal4D13_ClearBuffer(UCHAR bEPIndex)
{
//	if(bD13flags.bits.At_IRQL1 == 0)
//		RaiseIRQL();

    // Select Endpoint 
	outportb(D13_COMMAND_PORT, D13CMD_EP_CLEAR_BUF + bEPIndex);
    
//	if(bD13flags.bits.At_IRQL1 == 0)
//		LowerIRQL();
}
//Jan10, WARNING 16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
/*
void Hal4D13_ValidBuffer(UCHAR bEPIndex)
{
	if(bD13flags.bits.At_IRQL1 == 0)
		RaiseIRQL();

	outportb(D13_COMMAND_PORT, D13CMD_EP_VALID_BUF + bEPIndex);
  
	if(bD13flags.bits.At_IRQL1 == 0)
		LowerIRQL();
}
*/

USHORT Hal4D13_ReadEndpoint(UCHAR bEPIndex, UCHAR * buf, USHORT len)
{
	USHORT i, j;

//	if(bD13flags.bits.At_IRQL1 == 0)
//		RaiseIRQL();

	outportb(D13_COMMAND_PORT, D13CMD_EP_RD_FIFO + bEPIndex);


	// read Buffer read LSB first then MSB of length.
	j = inportb(D13_DATA_PORT);// LSB of Length word 
	i = inportb(D13_DATA_PORT);
	j += (i<<8);// MSB of Length word 

	if(j > len)
		j = len;

	for(i=0; i<j; i++, buf ++ )
		*buf = inportb(D13_DATA_PORT);

	// Clear Buffer
	outportb(D13_COMMAND_PORT, D13CMD_EP_CLEAR_BUF+bEPIndex);

//	if(bD13flags.bits.At_IRQL1 == 0)
//		LowerIRQL();

	return j;
}

/*
USHORT Hal4D13_ReadBulkEndpoint(UCHAR bEPIndex, UCHAR far * buf, USHORT len)
{
	USHORT i, j;
	static unsigned char temp1, key1;

	outportb(D13_COMMAND_PORT, D13CMD_EP_RD_FIFO + bEPIndex);

	j = inportb(D13_DATA_PORT);// LSB of Length word 
	i = inportb(D13_DATA_PORT);
	j += (i<<8);// MSB of Length word 

	if(j > len)
		j = len;

	for(i=0; i<j; i++, buf++ )
	{
		*buf = inportb(D13_DATA_PORT);
		if (i==0)
		{
			if(temp1 != *buf)
			{
				cprintf("-%x", *buf);
//				key1 = 0;
//				printf("press 'G' or 'g' to go");
//				while(key1 != 'g' && key1 != 'G')
//				{
//					if(bioskey(1))
//						key1 = (bioskey(0)&0xff);
//				}// error been read
//
			}
			temp1 = *buf;
			temp1++;
		}
	}
	// Clear Buffer 
	outportb(D13_COMMAND_PORT, D13CMD_EP_CLEAR_BUF+bEPIndex);

	return j;
}

*/

USHORT Hal4D13_ReadEndpointWOClearBuffer(UCHAR bEPIndex, UCHAR * buf, USHORT len)
{
	USHORT i, j;

//	if(bD13flags.bits.At_IRQL1 == 0)
//		RaiseIRQL();

	outportb(D13_COMMAND_PORT, D13CMD_EP_RD_FIFO + bEPIndex);


	// read Buffer  read LSB first then MSB of length.
	j = inportb(D13_DATA_PORT);// LSB of Length word 
	i = inportb(D13_DATA_PORT);//MSB of Length word
	j += (i<<8); 

	if(j > len)
		j = len;

	for(i=0; i<j; i++, buf ++ )
		*buf = inportb(D13_DATA_PORT);

//	if(bD13flags.bits.At_IRQL1 == 0)
//		LowerIRQL();

	return j;
}


USHORT Hal4D13_WriteEndpoint(UCHAR bEPIndex, UCHAR * buf, USHORT len)
{
	USHORT i;
//	UCHAR  c;

//	if(bD13flags.bits.At_IRQL1 == 0)
//		RaiseIRQL();


	outportb(D13_COMMAND_PORT, D13CMD_EP_WR_FIFO + bEPIndex);
//	if(bEPIndex == 0x01 & len != 0)

	outportb(D13_DATA_PORT, (UCHAR)len);  
	outportb(D13_DATA_PORT, (UCHAR)(len>>8));

	for(i=0; i<len; i++, buf++ )
		outportb(D13_DATA_PORT, *buf);

	outportb(D13_COMMAND_PORT, D13CMD_EP_VALID_BUF+bEPIndex);

//	if(bD13flags.bits.At_IRQL1 == 0)
//		LowerIRQL();

	return i;
}

/*
USHORT Hal4D13_WriteBulkEndpoint(UCHAR bEPIndex, UCHAR far * buf, USHORT len)
{
	USHORT i;
	UCHAR  c;
	static unsigned char temp2, key2;

//	static UCHAR j;

	if(bD13flags.bits.At_IRQL1 == 0)
		RaiseIRQL();
//	cprintf("length = %x \n %x \n ", (UCHAR)len, (UCHAR)(len>>8));

	// Select Endpoint 
	outportb(D13_COMMAND_PORT, D13CMD_EP_WR_FIFO + bEPIndex);
//	if(bEPIndex == 0x01 & len != 0)

	outportb(D13_DATA_PORT, (UCHAR)len);  // Send LSB byte  expect MSB first but internal coding error.
	outportb(D13_DATA_PORT, (UCHAR)(len>>8));// Send MSB length 

	// Write Buffer 
	
//	i = *buf;
//	if(j != i)
//		OUT_ERROR_CODE(PKT_INCREASE_ER);

//	j = i+1;

//
	for(i=0; i<len; i++, buf++ )
	{
		outportb(D13_DATA_PORT, *buf);
		if (i ==0)
		{
//			cprintf(" %x", *buf);
			if(temp2 != *buf)
			{
				cprintf(" %x", *buf);
//				key2 = 0;
//				printf("press 'G' or 'g' to go");
//				while(key2 != 'g' && key2 != 'G')
//				{
//					if(bioskey(1))
//						key2 = (bioskey(0)&0xff);
//				}// error been read
//			}
			temp2 = *buf;
			temp2++;
//		}
//	}
	// Validate Buffer 
	outportb(D13_COMMAND_PORT, D13CMD_EP_VALID_BUF+bEPIndex);

	if(bD13flags.bits.At_IRQL1 == 0)
		LowerIRQL();

	return i;
}
*/

/*
ULONG Hal4D13_GetIntEnable(void)
{
	ULONG i;
	if(bD13flags.bits.At_IRQL1 == 0)
		RaiseIRQL();

	outportb(D13_COMMAND_PORT,D13CMD_DEV_RD_INTEN);
	i = inportb(D13_DATA_PORT);
	i += (((ULONG)inportb(D13_DATA_PORT)) << 8);
	i += (((ULONG)inportb(D13_DATA_PORT)) << 16);
	i += (((ULONG)inportb(D13_DATA_PORT)) << 32); // JiangQian add 1 byte

⌨️ 快捷键说明

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