📄 init.c
字号:
//***********************************************************************
// *
// P H I L I P S P R O P R I E T A R Y *
// *
// COPYRIGHT (c) 1999 BY PHILIPS SINGAPORE (APIC). *
// -- ALL RIGHTS RESERVED -- *
// *
// File Name : Init.c *
// Author : Albert Goh *
// Created : 3 March 2000 *
// *
//***********************************************************************
//***********************************************************************
// *
// Init.c is the initialization of the device attached and also the D14 *
// It will initialize the various variables and component. *
// *
//***********************************************************************
//***********************************************************************
// *
// Module History *
// ************** *
// *
// Date Version Author Changes *
// ==== ======= ====== ======= *
// 030300 0.1 Albert Created *
// *
// *
//***********************************************************************
//***********************************************************************
//* *
//* Include Files Definition *
//* *
//***********************************************************************
#include "standard.h"
#include "Kernel.h"
#include "D14.h"
#include "I2c.h"
//#define D14_TEST 1
//***********************************************************************
//* *
//* External Variable Definition *
//* *
//***********************************************************************
extern void Start_mSEC_Timer(Data);
//extern void Start_SEC_Timer(Data);
extern TIMER idata Timer;
extern KERNEL Kernel_Flag;
extern I2C_FLAG I2C_Flag;
extern USB_INT_FLAG USB_Int_Flag;
extern USB_DEVICE USB_Device;
extern UI Temp;
extern UC Device_Config_Value;
extern UC idata Endpt_FIFO[64];
extern void DMA_Init(void);
//***********************************************************************
//* *
//* Prototype Routine Definition *
//* *
//***********************************************************************
void Init_D14_SFR(void);
void Init_Endpoint(void);
void Enable_Endpoint(void);
void Init_Main(void);
void Init_8051(void);
void Init_D14(void);
//***********************************************************************
//* *
//* Variable Definition *
//* *
//***********************************************************************
DATA_SWAP idata Data_Swap;
DMA_INT_FLAG DMA_Int_Flag;
UI count;
//UC Device_Config_Value;
//UC Type;
UI idata Init_Count;
volatile D14_CNTRL_REG xdata D14_Cntrl_Reg _at_ 0x0000;
D14_CNTRL_REG xdata *D14_Cntrl_Ptr = &D14_Cntrl_Reg;
//***********************************************************************
//* *
//* Routine : Init_Main *
//* Input : None *
//* Output : None *
//* Function : To initialize the D14 and the 8051 *
//* *
//***********************************************************************
void Init_Main(void)
{
ISP1581_CS = 1;//disable ISP1581
// DMA_Start = GDMA_Start;
DMA_EXT_EOT = 0;
DMA_EXT_EOT = 1;
EOT = 1;
EOT = 0;
// CPLD_Reset = 1; //Set CPLD_Reset pin to high.
Init_8051(); //Initialize the 8051
do
{
ISP1581_RESET = 0;
RES_EM = 0;
Start_mSEC_Timer(10);
ISP1581_RESET = 1;
Start_mSEC_Timer(100);
RES_EM = 1;
ISP1581_CS = 0; //Enable ISP1581
if(D14_Cntrl_Ptr->D14_CHIP_ID_MBYTE == 0x81 &&
D14_Cntrl_Ptr->D14_CHIP_ID_MSB == 0x15)
break;
}while(1);
Start_mSEC_Timer(10);
//start initialization delay timer
I2C_Flag.VALUE = 0;
USB_Int_Flag.VALUE = 0;
DMA_Int_Flag.VALUE = 0;
Kernel_Flag.VALUE = 0;
Kernel_Flag.BITS.HS_FS_State = FULL_SPEED;
Init_D14(); //Initialize the D14
}
//***********************************************************************
//* *
//* Routine : Init_8051 *
//* Input : None *
//* Output : None *
//* Function : To initialize 8051 control register *
//* *
//***********************************************************************
void Init_8051(void)
{
TMOD = 0x01; //set to crystal clocking
//set to timer mode
//select 16 bit timer
Timer.mSEC_Scale = 2000;
Timer.Hundred_mSEC_Scale = 20000;
TCON = 0; //reset timer control
EA = 0; //disable all interrupt
IE = 0x03; //disable UART interrupt
//disable timer 1 overflow interrupt
//disable external interrupt 1
//enable timer 0 overflow interrupt
//enable external interrupt 0
IP = 0; //reset all interrupt's priority to low.
PT1 = 1; // set to high priority for timer1
PT0 = 1; // set to high priority for timer0
EA = 1; //enable all interrupt
PCON = 0x40; //disable all power mode control
//enable half/doble baud rate
}
//***********************************************************************
//* *
//* Routine : *
//* Input : *
//* Output : *
//* Function : *
//* *
//***********************************************************************
void Init_D14(void)
{
USB_Device.BITS.Alt_Interface = 0;
Init_D14_SFR(); //Interrupt source configuration
Init_Endpoint(); //Initialize Endpoint Size
USB_Int_Flag.VALUE = 0;
DMA_Int_Flag.VALUE = 0;
USB_Device.BITS.State = USB_Default;
Device_Config_Value = 0;
USB_Device.BITS.Big_Endian = On;
Kernel_Flag.BITS.Tx_Done = 0;
DMA_Init();
}
//***********************************************************************
//* *
//* Routine : *
//* Input : *
//* Output : *
//* Function : *
//* *
//***********************************************************************
void Init_D14_SFR(void)
{
D14_Cntrl_Reg.D14_MODE.VALUE = 0x8F;
//enable Global Interrupt enable
//enable the soft connection of the 1.5KOhms on pin RPU.
//enable wakeup on chip select
//Enable Clock Always On.
D14_Cntrl_Reg.D14_INT_CONFIG.VALUE = 0x54; //0x94;//0x54
//bit7,bit6=01; (Ctrl EP) Interrupt on ACK, NYET.
//bit5,bit4=11; (In EP) Interrupt on ACK, NYET, and first NAK.
//bit3,bit2=11; (out EP) Interrupt on ACK, NYET, and first NAK.
//bit1=0,level mode.
//bit0=0,active low.
D14_Cntrl_Reg.D14_INT_ENABLE.VALUE = 0x792D0000; //0x793D0000
//bit31-16=0; disable the interrupts for the EP7-3.
//enable interrupts for In of endpoint1 and DMA.
//enable the interrupt for the Setup and in/out on endpoint 0
//bit6, enable the interrupt upon DMA status change detection.
//bit5, enable the interrupt upon detection of a 'high speed status change'.
//bit4, enable the interrupt upon detection of a 'resume' state.
//bit3, enable the interrupt upon detection of a 'suspend' state.
//bit0, enable the interrupt upon detection of a bus reset.
//lower byte first.
}
//***********************************************************************
//* *
//* Routine : *
//* Input : *
//* Output : *
//* Function : *
//* *
//***********************************************************************
void Enable_Endpoint(void)
{
if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
{
//Selected Out FIFO of the endpoint 1
D14_Cntrl_Reg.D14_ENDPT_INDEX = 2;
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x0000;
//set to MaxPacketSize data length = 0 bytes.
//Selected In FIFO of the endpoint 1
D14_Cntrl_Reg.D14_ENDPT_INDEX = 3;
if(USB_Device.BITS.Alt_Interface == 0)
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x00;
else if(USB_Device.BITS.Alt_Interface == 1)
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x4000;
else
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0xFC03;
//Selected Out FIFO of the endpoint 2
D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x0000;
//Selected In FIFO of the endpoint 2
D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x1000;
//Selected Out FIFO of the endpoint 3
D14_Cntrl_Reg.D14_ENDPT_INDEX = 6;
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x0000;
//Selected In FIFO of the endpoint 3
D14_Cntrl_Reg.D14_ENDPT_INDEX = 7;
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x0000;
//Iso Out Endpoint Type
D14_Cntrl_Reg.D14_ENDPT_INDEX = 2;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1500;
//Iso In Endpoint Type
D14_Cntrl_Reg.D14_ENDPT_INDEX = 3;
if(USB_Device.BITS.Alt_Interface == 0)
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1500; //ISO
else if(USB_Device.BITS.Alt_Interface == 1)
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1600; //Bulk
else
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1500; //ISO
//Interrupt Out Endpoint Type
D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1700;
//Interrupt In Endpoint Type
D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1700; //Int
//Bulk Out Endpoint Type
D14_Cntrl_Reg.D14_ENDPT_INDEX = 6;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1600;
//Bulk In Endpoint Type
D14_Cntrl_Reg.D14_ENDPT_INDEX = 7;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1600;
D14_Cntrl_Reg.D14_ENDPT_INDEX = 2;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0000; //disable FIFO
D14_Cntrl_Reg.D14_ENDPT_INDEX = 3;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800; //enable FIFO
D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0000; //disable FIFO
D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800; //enable FIFO
D14_Cntrl_Reg.D14_ENDPT_INDEX = 6;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0000; //disable FIFO
D14_Cntrl_Reg.D14_ENDPT_INDEX = 7;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0000; //disable FIFO
}
if(Kernel_Flag.BITS.HS_FS_State == HIGH_SPEED)
{
//Out MaxPacketSize Endpoint
D14_Cntrl_Reg.D14_ENDPT_INDEX = 2; //01
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x0000;
//In MaxPacketSize Endpoint
D14_Cntrl_Reg.D14_ENDPT_INDEX = 3; //81
if(USB_Device.BITS.Alt_Interface == 0)
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x00;
else if(USB_Device.BITS.Alt_Interface == 1)
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x0002;
else
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x0004;
//Out MaxPacketSize Endpoint
D14_Cntrl_Reg.D14_ENDPT_INDEX = 4; //02
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x0000;
//In MaxPacketSize Endpoint
D14_Cntrl_Reg.D14_ENDPT_INDEX = 5; //82
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x0800;
//Out MaxPacketSize Endpoint
D14_Cntrl_Reg.D14_ENDPT_INDEX = 6;
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x0000;
//In MaxPacketSize Endpoint
D14_Cntrl_Reg.D14_ENDPT_INDEX = 7;
D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x0000;
//Iso In Endpoint Type
D14_Cntrl_Reg.D14_ENDPT_INDEX = 2;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1500;
//Bulk Out Endpoint Type (0x1600)
D14_Cntrl_Reg.D14_ENDPT_INDEX = 3;
if(USB_Device.BITS.Alt_Interface == 0)
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1500; //0x1500 for ISO
if(USB_Device.BITS.Alt_Interface == 1)
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1600; //0x1600 for Bulk
else
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1500; //0x1500 for ISO
//Interrupt Out Endpoint Type (0x1700)
D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1700;
//Interrupt In Endpoint Type
D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1700;
//Bulk Out Endpoint Type
D14_Cntrl_Reg.D14_ENDPT_INDEX = 6;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1500;
//Bulk In Endpoint Type
D14_Cntrl_Reg.D14_ENDPT_INDEX = 7;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1500;
D14_Cntrl_Reg.D14_ENDPT_INDEX = 2;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0000; //enable FIFO
D14_Cntrl_Reg.D14_ENDPT_INDEX = 3;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800; //enable FIFO
D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0000; //enable FIFO
D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800; //enable FIFO
D14_Cntrl_Reg.D14_ENDPT_INDEX = 6;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0000; //enable FIFO
D14_Cntrl_Reg.D14_ENDPT_INDEX = 7;
D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0000; //enable FIFO
}
D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
D14_Cntrl_Reg.D14_DMA_ENDPOINT = 3; //set to DMA endpoint 1
D14_Cntrl_Reg.D14_DMA_COMMAND = 0x0F;
}
void Init_Endpoint(void)
{
for(count = 0 ; count < 64 ; count++)
Endpt_FIFO[count] = 0;
D14_Cntrl_Reg.D14_DMA_ENDPOINT = 3; //set to DMA endpoint 1
D14_Cntrl_Reg.D14_ENDPT_INDEX = 4; //set to Endpoint Index to 2
D14_Cntrl_Reg.D14_ADDRESS.VALUE = 0x80;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -