ARM专辑-152M-pdf.zip

源代码在线查看: isr.c

软件大小: 74715 K
上传用户: QQ
关键词: M-pdf ARM 152 zip
下载地址: 免注册下载 普通下载 VIP

相关代码

				
				   //*************************************************************************
				   //
				   //                  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:	    ISR.C
				   // Author:           Hilbert Zhang ZhenYu
				   //                   Chew Thing Piao
				   // Created:          Oct. 1 99
				   // Modified:
				   // Revision: 		0.0.
				   //
				   //*************************************************************************
				   //
				   //*************************************************************************
				
				#include  "config.h"                /* special function register declarations   */
				#undef   GLOBAL_EXT
				#include "SysCnfg.h"
				#include "BasicTyp.h"
				#include "Common.h"
				#include "Hal4Sys.h"
				#include "Hal4d12.h"
				
				
				//*************************************************************************
				//  Public data
				//*************************************************************************
				
				// bit Flags
				STRUC_EXT BITFLAGS  bFlags;
				
				// Timer 0
				#define             MCUBF_Timer  					bFlags.bits.timer
				INT8_EXT            Hal4Sys_ClockTicks;
				
				// D12 bit flags
				#define             D12BF_SetupOverwritten  		bFlags.bits.setup_overwritten
				#define             D12BF_Configuration	  			bFlags.bits.;configuration
				
				// DefaultControlPipe Finate State Machine [One-Hot]
				STRUC_EXT char_bit   _DCPFSMstate;
				#define		DCPFSMstate			_DCPFSMstate.char_
				#define		DCPFSM_SetupProc 	_DCPFSMstate.bit_.b0
				#define     DCPFSM_DataIn 		_DCPFSMstate.bit_.b1
				#define     DCPFSM_DataOut 		_DCPFSMstate.bit_.b2
				#define     DCPFSM_COhandshake 	_DCPFSMstate.bit_.b3
				#define     DCPFSM_CIhandshake 	_DCPFSMstate.bit_.b4
				#define     DCPFSM_Stall 		_DCPFSMstate.bit_.b7
				
				STRUC_EXT char_bit _BOTFSMstate;
				#define 	BOTFSMstate		_BOTFSMstate.char_ 
				#define 	BOTFSM_IDLE 	_BOTFSMstate.bit_.b0
				#define     BOTFSM_CBWProc  _BOTFSMstate.bit_.b1
				#define     BOTFSM_DataIn 	_BOTFSMstate.bit_.b2
				#define     BOTFSM_DataOut  _BOTFSMstate.bit_.b3
				#define     BOTFSM_CSWProc  _BOTFSMstate.bit_.b4
				#define     BOTFSM_CSW 		_BOTFSMstate.bit_.b5
				#define     BOTFSM_Stall 	_BOTFSMstate.bit_.b7
				
				// USB Device Request
				STRUC_EXT DEVICE_REQUEST DCPDeviceRequest;
				INT8_EXT            UsbReq_Recipient;
				INT8_EXT            UsbReq_Type;
				INT8_EXT            UsbReq_Request;
				#define             REQBF_DCPRequest_dir  			bFlags.bits.DCPRequst_Dir
				#define             REQBF_DCPRequest_EPdir  		bFlags.bits.DCPRequst_EPDir
				#define             REQBF_StallDCPRequest   		bFlags.bits.Stall_DCPRequest
				
				
				// Default Control Pipe Tansfer DCPXfer
				STRUC_EXT char_bit  	_Xfer_Space;
				#define 	Xfer_Space 			_Xfer_Space.char_
				#define     DCPXfer_atMCUCODE 	_Xfer_Space.bit_.b0
				#define     DCPXfer_atMCURAM 	_Xfer_Space.bit_.b1
				#define    	DCPXfer_atEEROM 	_Xfer_Space.bit_.b2
				#define    	DCPXfer_atATA 		_Xfer_Space.bit_.b3
				#define   	BOTXfer_atRAM 		_Xfer_Space.bit_.b4
				#define   	BOTXfer_atATA 		_Xfer_Space.bit_.b5
				#define    	BOTXfer_atROM 		_Xfer_Space.bit_.b6
				
				INT16_EXT           DCPXfer_wResidue;
				INT8_EXT            * DCPXfer_pData;
				
				
				//*************************************************************************
				//  Private data
				//*************************************************************************
				
				char_bit        _ISR_eplts ;
				#define ISR_eplts _ISR_eplts.char_
				#define D12EP0LTS_SUCCESS _ISR_eplts.bit_.b0   //数据接收/发送成功
				#define D12EP0LTS_SETUP   _ISR_eplts.bit_.b5     //setup信息包,1表示成功接收的信息包有一个SETIP标志
				
				uint_bit        _ISR_IR;			// bit addressable data(16bits) from $20H->
				#define		ISR_IR  _ISR_IR.uint_
				#define 	D12IS_EOT          	_ISR_IR.bit_.b0     // D12 Interrupt Src
				#define 	D12IS_SUSPENDCHANGE	_ISR_IR.bit_.b15    // D12 Interrupt Src
				#define 	D12IS_BUSRESET      _ISR_IR.bit_.b14    // D12 Interrupt Src
				#define 	D12IS_ENDP2IN       _ISR_IR.bit_.b13    // D12 Interrupt Src
				#define 	D12IS_ENDP2OUT      _ISR_IR.bit_.b12    // D12 Interrupt Src
				#define 	D12IS_ENDP1IN       _ISR_IR.bit_.b11    // D12 Interrupt Src
				#define 	D12IS_ENDP1OUT      _ISR_IR.bit_.b10    // D12 Interrupt Src
				#define 	D12IS_ENDP0IN       _ISR_IR.bit_.b9     // D12 Interrupt Src
				#define 	D12IS_ENDP0OUT      _ISR_IR.bit_.b8     // D12 Interrupt Src
				
				
				
				//*************************************************************************
				//  Private Functions
				//*************************************************************************
				
				
				void ep0_txdone(void);
				void ep0_rxdone(void);
				
				void ep1_txdone(void);
				void ep1_rxdone(void);
				
				//*************************************************************************
				//  Functions
				//*************************************************************************
				/*
				timer_isr() interrupt 1
				{
					RaiseIRQL();
				    TIMER0_LOW = 0x00;    // 1 MS interval @24MHz
				    TIMER0_HIGH =TIMER0_AT24MHZ;    // 0xF8
				    Hal4Sys_ClockTicks++;
				    MCUBF_Timer = 1;
				    LowerIRQL();
				}
				*/
				
				void usb_isr(void) 
				{
					uint16 temp;
					//RaiseIRQL();
					Hal4D12_ReadInterruptRegister(&ISR_IR);
				    Hal4D12_ReadLastTransactionStatus(4);
				temp = ISR_IR;
					if(ISR_IR != 0)
				    {
					    if(D12IS_BUSRESET)
				        {
				            DCPFSMstate = USBFSM4DCP_IDLE;   //USBFSM4DCP_IDLE =0x00
				            BOTFSMstate = USBFSM4BOT_IDLE;   //USBFSM4BOT_IDLE =0x01
				            D12BF_SetupOverwritten = 0;
				          //  IOSET = SUSP;
				        }
				    
					    if(D12IS_SUSPENDCHANGE)    //挂起,进入掉电模式
						   {
						/*	 	if( D12BF_SetupOverwritten==1 )
									D12SUSPD=1;
								else
									D12SUSPD=0;
				
							   	if(D12SUSPD == 1)
						   			{
				            		P0 = 0xFF;
				    				P1 = 0xFF;
									P2 = 0xFF;
									P3 = 0xFF;
				              	PCON |= 0x02; //Powerdown bit set
							       	while (1);		
									}
									*/
						  }
				
						if(D12IS_ENDP0OUT)
							ep0_rxdone();
						if(D12IS_ENDP0IN)
							ep0_txdone();
						if(D12IS_ENDP1IN)
							ep1_txdone();
						if(D12IS_ENDP1OUT)
							ep1_rxdone();
				
					}
				   // LowerIRQL();
				}
				
				void ep0_rxdone(void)		//接收处理
				{
					ISR_eplts = Hal4D12_ReadLastTransactionStatus(0); // Clear interrupt flag
				    
				    if (!D12EP0LTS_SUCCESS)//数据接收不成功,返回(sbit D12EP0LTS_SUCCESS = ISR_eplts^0)
				        return;
				
				    if (D12EP0LTS_SETUP)	//接收到SETUP信号
				    {
				        if(DCPFSM_SetupProc || DCPFSM_DataOut || DCPFSM_DataIn )
				        {
							D12BF_SetupOverwritten = 1;
				        }
				        DCPFSMstate = USBFSM4DCP_SETUPPROC;//USBFSM4DCP_SETUPPROC =0x01
					}
					else /* not a setup packet, just a Data Out Packet */
					{
				        if (DCPFSM_CIhandshake)
				        {
							DCPFSMstate = USBFSM4DCP_IDLE;//USBFSM4BOT_IDLE =0x01
				        }
				        // else just let it stay in FIFO of Control-Out
				    }
				}
				
				
				
				void ep0_txdone(void)			//发送处理
				{
					ISR_eplts = Hal4D12_ReadLastTransactionStatus(1); // Clear interrupt flag
				    if ( !D12EP0LTS_SUCCESS )	//数据接收不成功,返回
				        return;
				
				    if (DCPFSM_DataIn)  //DCPFSM_DataIn = DCPFSMstate^1
				    {
				        if( DCPXfer_wResidue >= EP0_PACKET_SIZE)
					    {
				            if(DCPXfer_atMCUCODE)
				                Hal4D12_WriteEPAtCode(1, EP0_PACKET_SIZE, DCPXfer_pData);
				            else if(DCPXfer_atMCURAM)
				                Hal4D12_WriteEndpoint(1, EP0_PACKET_SIZE, DCPXfer_pData);
				            else
				                return;
							DCPXfer_pData += EP0_PACKET_SIZE;
				            DCPXfer_wResidue -= EP0_PACKET_SIZE;
						    /*
						    // State remains at USBFSM4DCP_DATAIN
							*/
					    }
					    else if( DCPXfer_wResidue != 0)
					    {
				            if(DCPXfer_atMCUCODE)
				                Hal4D12_WriteEPAtCode(1, (INT8)DCPXfer_wResidue, DCPXfer_pData );
				            else if(DCPXfer_atMCURAM)
				                Hal4D12_WriteEndpoint(1, (INT8)DCPXfer_wResidue, DCPXfer_pData );
				            else
				                return;
							//DCPXfer_pData += DCPXfer_wResidue;
				            DCPXfer_wResidue = 0;
							DCPFSMstate = USBFSM4DCP_HANDSHAKE4CI;
						}
					    else //  DCPXfer_wResidue == 0
					    {
				            // Send zero packet at the end
						    Hal4D12_WriteEndpoint(1, 0, 0);
						    DCPFSMstate = USBFSM4DCP_HANDSHAKE4CI;	// USBFSM4DCP_HANDSHAKE4CI =0x10
					    }
				    }
					else if( DCPFSM_COhandshake )
				    {
				    	DCPFSMstate = USBFSM4DCP_IDLE;				// USBFSM4BOT_IDLE =0x01
				    }
				    // else just exit
				#undef DCPXfer_wResidue
				}
				
				
				void ep1_txdone(void)			//端点1,发送处理
				{
				 	Hal4D12_ReadLastTransactionStatus(3); /* Clear interrupt flag */
				}
				
				void ep1_rxdone(void)			//端点1,接收处理
				{
					Hal4D12_ReadLastTransactionStatus(2); /* Clear interrupt flag */
				}
				
				
				
				
							

相关资源