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

📄 usbrc.c

📁 ST72T63游戏杆源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************** (c) 1998       STMicroelectronics **********************

PROJECT : USB - ST7
COMPILER : ST7 HICROSS C (HIWARE)

MODULE  :  usbrc.c
VERSION :  V 1.3

CREATION DATE :  25/05/98

AUTHOR : / MICROCONTROLLER DIVISION / ST Rousset

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

DESCRIPTION : ST7263 USB driver.

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

MODIFICATIONS :
Rev. 1.3 1/03/99
Modified:
void SetEP1Add(void)  USBEP1RB = (USBEP1RB | 0x01); changed to  USBEP1RB = 0x01;  
void SetEP2Add(void)  USBEP2RB = (USBEP2RB | 0x02); changed to  USBEP2RB = 0x02;     
// This modification avoid bad initialization of USBEPxRB register due to the 
unknown state of this register after a H/W reset USBEPxRB = 0000xxxxb.  

Rev. 1.2 12/01/99
Modified:
Bool GetEP0TxValidStatus(void)  changed ~STAT to STAT in if condition
Bool GetEP0RxValidStatus() changed ~STAT to STAT in if condition
Bool GetEP1TxValidStatus(void) changed ~STAT to STAT in if condition  
Bool GetEP2TxValidStatus(void) changed ~STAT to STAT in if condition
Bool GetEP1RxValidStatus()   changed ~STAT to STAT in if condition
Bool GetEP2RxValidStatus() changed ~STAT to STAT in if condition

#include "usbrc.h"
******************************************************************************/

#include <hidef.h>
#include "lib_bits.h"
#include "usb_var.h"
#include "define.h"
#include "map_7263.h"
#include "CondComp.h" // Conditional compilation
#include "usbrc.h"

/*-----------------------------------------------------------------------------
ROUTINE NAME : InitCTLR
INPUT/OUTPUT : None
DESCRIPTION      : Set CTLR register in init configuration
-----------------------------------------------------------------------------*/
void InitCTLR(void)

{
                  USBCTLR = 0x02;

}

/*-----------------------------------------------------------------------------
ROUTINE NAME : ClearISTR
INPUT/OUTPUT : None
DESCRIPTION      : Clear ISTR register
-----------------------------------------------------------------------------*/                 
void ClearISTR(void)                    

{
                  USBISTR = 0;

}

/*-----------------------------------------------------------------------------
ROUTINE NAME : ClearDADDR
INPUT/OUTPUT : None
DESCRIPTION      : Clear DADDR register
-----------------------------------------------------------------------------*/
void ClearDADDR(void)

{
                  USBDADDR = 0;

}

/*-----------------------------------------------------------------------------
ROUTINE NAME : Set8Mhz
INPUT/OUTPUT : None
DESCRIPTION      : Set the FAST bit of MISCR register
-----------------------------------------------------------------------------*/
void Set8Mhz(void)

{
                  MISCR |= 0x20;

}

/*-----------------------------------------------------------------------------
ROUTINE NAME : SetIMR
INPUT/OUTPUT : IMR register mask
DESCRIPTION      : Write the mask value of IMR register
-----------------------------------------------------------------------------*/
void SetIMR(Byte ImrMask)

{
                  USBIMR = ImrMask;

}

/*-----------------------------------------------------------------------------
ROUTINE NAME : SetDmaAdd
INPUT/OUTPUT : DMA high and low bytes address values
DESCRIPTION      : Write the mask value of IMR register
-----------------------------------------------------------------------------*/                                                  
void SetDmaAdd(Word Dmar)

{
                  USBDMAR = Dmar/256;
                  USBIDR = (Dmar%256) & 0xC0;                 
}                       

#ifdef USE_ENDPOINT1
/*-----------------------------------------------------------------------------
ROUTINE NAME : SetEP1Add
INPUT/OUTPUT : 
DESCRIPTION      : Write Endpoint 1 address at 0001
-----------------------------------------------------------------------------*/
void SetEP1Add(void)

{
                                         USBEP1RB =  0x01;
}                                         
#endif

#ifdef USE_ENDPOINT2
/*-----------------------------------------------------------------------------
ROUTINE NAME : SetEP2Add
INPUT/OUTPUT : 
DESCRIPTION      : Write Endpoint 2 address at 0010
-----------------------------------------------------------------------------*/
void SetEP2Add(void)

{
                                         USBEP2RB =  0x02;

}
#endif

/*-----------------------------------------------------------------------------
ROUTINE NAME : SetEP0TxTbc
INPUT/OUTPUT : byte number values
DESCRIPTION      : Write the byte number to send through USB
-----------------------------------------------------------------------------*/
void SetEP0TxTbc(Byte Tbc)

{
                                         USBEP0RA = (USBEP0RA & ~CNT) | Tbc;

}

/*-----------------------------------------------------------------------------
ROUTINE NAME : GetEP0RxCNT
INPUT/OUTPUT : Byte Received
DESCRIPTION  : Return the byte number received through USB
-----------------------------------------------------------------------------*/
Byte GetEP0RxCNT()

{
        Byte ByteReceived;
        
        if((USBIDR & EP) == 0)  // Last transaction on Endpoint 0
        {
                ByteReceived = (USBIDR & CNT);
                return ByteReceived;
        }
        else return 0;

}

/********************************* Endpoint1 input Interrupt Pipe ***************************/
#ifdef USE_ENDPOINT1_IN
/*-----------------------------------------------------------------------------
ROUTINE NAME : SetEP1TxTbc
INPUT/OUTPUT : endpoint number and byte number values
DESCRIPTION      : Write the byte number to send through USB
-----------------------------------------------------------------------------*/
void SetEP1TxTbc(Byte Tbc)

{
                                         USBEP1RA = (USBEP1RA & ~CNT) | Tbc;

}

/*-----------------------------------------------------------------------------
ROUTINE NAME : SetEP1TxStatus
INPUT/OUTPUT : endpoint number and status values
DESCRIPTION      : Write the status of Tx endpoint
-----------------------------------------------------------------------------*/
void SetEP1TxStatus(Byte Status)

{
                                         USBEP1RA = (USBEP1RA & ~STAT) | Status;         

}

/*-----------------------------------------------------------------------------
ROUTINE NAME : GetEP1TxValidStatus
INPUT/OUTPUT : Endpoint number, endpoint direction / boolean
DESCRIPTION      : Return true if the endpoint Tx is valided, false if not
-----------------------------------------------------------------------------*/
Bool GetEP1TxValidStatus(void)

{
                         if((USBEP1RA & STAT) == VALID)
                                return(TRUE);
                         else return(FALSE);     

}

#endif 
/********************************* Endpoint1 input Interrupt Pipe End ***************************/


/********************************* Endpoint2 input Interrupt Pipe ***************************/
#ifdef USE_ENDPOINT2_IN
/*-----------------------------------------------------------------------------
ROUTINE NAME : SetEP2TxTbc
INPUT/OUTPUT : endpoint number and byte number values
DESCRIPTION      : Write the byte number to send through USB
-----------------------------------------------------------------------------*/
void SetEP2TxTbc(Byte Tbc)

{
                                         USBEP2RA = (USBEP2RA & ~CNT) | Tbc;

}

/*-----------------------------------------------------------------------------
ROUTINE NAME : SetEP2TxStatus
INPUT/OUTPUT : endpoint number and status values
DESCRIPTION      : Write the status of Tx endpoint
-----------------------------------------------------------------------------*/
void SetEP2TxStatus(Byte Status)

{
                                         USBEP2RA = (USBEP2RA & ~STAT) | Status;         

}

/*-----------------------------------------------------------------------------
ROUTINE NAME : GetEP2TxValidStatus
INPUT/OUTPUT : Endpoint number, endpoint direction / boolean
DESCRIPTION      : Return true if the endpoint Tx is valided, false if not
-----------------------------------------------------------------------------*/
Bool GetEP2TxValidStatus(void)

{
                         if((USBEP2RA & STAT) == VALID)
                                return(TRUE);
                         else return(FALSE);     

}

#endif
/********************************* Endpoint2 input Interrupt Pipe End ***************************/


/*-----------------------------------------------------------------------------
ROUTINE NAME : SetEP0RxStatus
INPUT/OUTPUT : endpoint number and status values
DESCRIPTION      : Write the status of Rx endpoint
-----------------------------------------------------------------------------*/                                  
void SetEP0RxStatus(Byte Status)

{
                                         USBEP0RB = (USBEP0RB & ~STAT) | Status;

}


/********************************* Endpoint1 output Interrupt Pipe ***************************/
#ifdef USE_ENDPOINT1_OUT
/*-----------------------------------------------------------------------------
ROUTINE NAME : SetEP1RxStatus
INPUT/OUTPUT : endpoint number and status values
DESCRIPTION      : Write the status of Rx endpoint
-----------------------------------------------------------------------------*/                                  
void SetEP1RxStatus(Byte Status)

{
                                         USBEP1RB = (USBEP1RB & ~STAT) | Status;         

}

/*-----------------------------------------------------------------------------
ROUTINE NAME : GetEP1RxValidStatus
INPUT/OUTPUT : Endpoint number, endpoint direction / boolean
DESCRIPTION      : Return true if the endpoint Rx is valided, false if not
-----------------------------------------------------------------------------*/
Bool GetEP1RxValidStatus()

{
                         if((USBEP1RB & STAT) == VALID)
                                return(TRUE);
                         else return(FALSE);     

}

/*-----------------------------------------------------------------------------
ROUTINE NAME : GetEP1RxCNT
INPUT/OUTPUT : Byte Received
DESCRIPTION  : Return the byte number received through USB
-----------------------------------------------------------------------------*/
Byte GetEP1RxCNT()

{
        Byte ByteReceived;
        
        if((USBIDR & EP) == 1)  // Last transaction on Endpoint 1
        {
                ByteReceived = (USBIDR & CNT);
                return ByteReceived;
        }
        else return 0;

}

#endif
/********************************* Endpoint1 output Interrupt Pipe End ***************************/


/********************************* Endpoint2 output Interrupt Pipe ***************************/
#ifdef USE_ENDPOINT2_OUT
/*-----------------------------------------------------------------------------
ROUTINE NAME : SetEP2RxStatus
INPUT/OUTPUT : endpoint number and status values
DESCRIPTION      : Write the status of Rx endpoint
-----------------------------------------------------------------------------*/                                  
void SetEP2RxStatus(Byte Status)

{
                                         USBEP2RB = (USBEP2RB & ~STAT) | Status;         

}

⌨️ 快捷键说明

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