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

📄 mdppfs.c

📁 CIRRUS 公司EP93XX系列CPU的WINCE下的BSP
💻 C
字号:
//**********************************************************************
//                                                                      
// Filename: mdppfs.c
//                                                                      
// Description: Debug Parallel port routines.
//                                                                      
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// Copyright(c) Cirrus Logic Corporation 2001, All Rights Reserved                       
//                                                                      
//**********************************************************************
#include <windows.h>
#include <hwdefs.h>
#include <halether.h>
#include <debugtimer.h>



//
// Parallel Port                    IDE Interface
//
// Pin      Name                    Pin         Name                        Comment
// ---      -------------------     ---         ----------------------      ----------------
// 1        Strobe(Output)          31          INTRQ                        
// 2        Data bit 0              17          DD0
// 3        Data bit 1              15          DD1
// 4        Data bit 2              13          DD2
// 5        Data bit 3              11          DD3
// 6        Data bit 4              9           DD4
// 7        Data bit 5              7           DD5
// 8        Data bit 6              5           DD6
// 9        Data bit 7              3           DD7
// 10       Acknowledge(Input)      37          nCS0          
// 11       Busy Status(Input)      35          Data Address 0 (DA0)
// 12       Paper End/Fault (Input)             GND
// 13       Select Status(Input)                                            Not Used
// 14       Auto Feed(Output)       27          IORDY                                    
// 15       Error(Input)                                                    Not Used
// 16       Initialize(Output)                                              Not Used                                          
// 17       Select(Output)                                                  Not Used
// 18 -25   GND                     2,19,22,    GND                         GND
//                                  24,26,30
//
//  NC      No Connection           1,4,6,8,                                Not Used
//                                  10,12,14,16,                            Not Used
//                                  18,20,21,23,                            Not Used
//                                  25,28,29,32,                            Not Used
//                                  33,34,36,38,                            Not Used
//                                  39,40                                   Not Used

#define PAR_BUSY                        IDE_CTRL_DA0
#define PAR_ACK                         IDE_CTRL_CS0
#define PAR_AUTOFD                      IDE_CTRL_IORDY
#define PAR_STROBE                      IDE_CTRL_INTRQ

#define  PAR_NREAD                       (IDE_CTRL_DIOR)
#define  PAR_NWRITE                      (IDE_CTRL_DIOW)


extern void OEMWriteDebugByte(BYTE ucChar);
extern int OEMReadDebugByte(void);

typedef volatile DWORD *PVDWORD;    /* pointer to a volatile dword */

BOOL NoPPFS = FALSE;                    // parallel port disconnected flag

BOOL UART1Started = FALSE;
BOOL UART3Started = FALSE;


//
// Maximum iteration the parallel port code wait for the OS to send/recieve a byte.
//
#define     PARALLEL_WAIT               0x1000000

//
// The maximum time to wait after a byte is sent/recieve for the autofd/strobe line.
//
#define     PARALLEL_TIMEOUT            0x1000000


//****************************************************************************
// OEMInitParallelPort
//****************************************************************************
// 
// 
//
int OEMInitParallelPort()
{
    *IDE_CTRL   =  PAR_NREAD | PAR_NWRITE | IDE_CTRL_CS1;
    *IDE_CFG    = IDE_CFG_IDEEN | IDE_CFG_PIOEN | IDE_CFG_PIO4 | (3<<IDE_CFG_WST_SHIFT);
    return 0;
}

//***************************************************************************
// OEMParallelPortGetByte - Get byte from parallel port
//
// Input -  none
// Ouput -  if parallel port disconnected, set NoPPFS=TRUE and returns -1
//          else returns byte received from parallel port
//***************************************************************************
int OEMParallelPortGetByte(void)
{
    //DWORD           dwStatus;                     // parallel port status
    unsigned int    iWatchdog;                      // timeout counter
    int             iByteReturned;

    //
    // if ppfs disconnected do nothing
    //
    if (NoPPFS)
        return -1;
    
    //
    // Clear busy.
    //
    *IDE_CTRL =  PAR_NREAD| PAR_NWRITE ;
    
     //
    // Wait for the strobe to go low.
    //
    while(1)
    {    
        for(iWatchdog = 0 ; ; iWatchdog++)
        {
            if(!( *IDE_CTRL & PAR_STROBE))
            {
                break; 
            }

            //
            // Check to see if the watchdog has timed out
            if (iWatchdog==PARALLEL_WAIT)                    
            {                                    
                //
                // Display error message
                //
                EdbgOutputDebugString("OEMParallelPortGetByte: status timeout 1.\r\n");

                //
                // set parallel port to disconnected and return failure   
                //
                NoPPFS=TRUE;                    

                *IDE_CTRL  = PAR_NWRITE| PAR_NREAD;
                return -1;                      
            }
        }
        
        //
        // Read strobe a four more times to make sure that it is low.
        //
        if(( *IDE_CTRL & PAR_STROBE))
        {
            continue; 
        }
        if(( *IDE_CTRL & PAR_STROBE))
        {
            continue; 
        }
        if(( *IDE_CTRL & PAR_STROBE))
        {
            continue; 
        }
        if(!( *IDE_CTRL & PAR_STROBE))
        {
            break; 
        }

    }

    //
    // Set the IDE port for Reading and set busy
    //
    *IDE_CTRL =  PAR_NWRITE | PAR_BUSY ;

    
    //
    // Wait for the strobe to go high.
    //
    while(1)
    {    
        for(iWatchdog = 0 ; ; iWatchdog++)
        {
            if( *IDE_CTRL & PAR_STROBE)
            {
                break;                        
            }

            //
            // Check to see if the watchdog has timed out
            if (iWatchdog==PARALLEL_TIMEOUT)                    
            {                                    
                //
                // Display error message
                //
                EdbgOutputDebugString("OEMParallelPortGetByte: status timeout 2.\r\n");

                //
                // set parallel port to disconnected and return failure   
                //
                NoPPFS=TRUE; 
                
                *IDE_CTRL  = PAR_NWRITE| PAR_NREAD;
                return -1;                      
            }
        }            
        //
        // Read strobe a couple more time to make sure that strobe is high.
        // next state.
        //
        if(!( *IDE_CTRL & PAR_STROBE))
        {
            continue;                        
        }
        if(!( *IDE_CTRL & PAR_STROBE))
        {
            continue;                        
        }
        if(!( *IDE_CTRL & PAR_STROBE))
        {
            continue;                        
        }
        if(( *IDE_CTRL & PAR_STROBE))
        {
            break;                        
        }
    }

    //
    //  Clear Busy and DIOR. The data is now latched into the Data in register.
    //
    *IDE_CTRL  = PAR_NWRITE | PAR_NREAD ;
    iByteReturned = (*IDE_DATAIN & 0xFF);

    
    return (iByteReturned);
}

//***************************************************************************
// OEMParallelPortSendByte - send byte out parallel port
//
// Input -  chData=byte to send
//
// Output - sets NoPPFS=TRUE if parallel port disconnected
//***************************************************************************
void OEMParallelPortSendByte(BYTE chData)
{
    unsigned int iWatchdog;

    //
    // if ppfs disconnected do nothing
    //
    if (NoPPFS)
        return;
        
        
    //
    // Get ready to output data.
    //        
    *IDE_DATAOUT = (ULONG)chData;

    //    
    // Initialize the IDE interface/ Parallel Port for writing.
    //
    *IDE_CTRL = PAR_NWRITE | PAR_NREAD ;


    //
    // Wait for the AUTOFD to go high.
    //
    while (1) 
    {
        for(iWatchdog = 0 ; ; iWatchdog++)
        {
            if(( *IDE_CTRL & PAR_AUTOFD))
            {
                break;
            }
            
            //
            // Check to see if the watchdog has timed out
            //
            if (iWatchdog==PARALLEL_WAIT)                    
            {                                    
                //
                // Display error message
                //
                EdbgOutputDebugString("OEMParallelPortSendByte: status timeout 1.\n");

                //
                // set parallel port to disconnected and return failure   
                //
                NoPPFS=TRUE;                    
                return;                      
            }
        }            

        //
        // Read auto FD two times to make sure that it is set again.
        //
        if( !(*IDE_CTRL & PAR_AUTOFD))
        {
            continue;
        }
        if( !(*IDE_CTRL & PAR_AUTOFD))
        {
            continue;
        }
        if( !(*IDE_CTRL & PAR_AUTOFD))
        {
            continue;
        }

        if( (*IDE_CTRL & PAR_AUTOFD))
        {
            break;
        }

    }

    //
    // Set PAR_ACK
    //
    *IDE_CTRL = PAR_NREAD | PAR_ACK ;               
    
    //
    // Wait for the AUTOFD to go low.
    //
    while (1) 
    {
        for(iWatchdog = 0 ; ; iWatchdog++)
        {
            if( !(*IDE_CTRL & PAR_AUTOFD))
            {
                break;
            }
            
            //
            // Check to see if the watchdog has timed out
            //
            if (iWatchdog == PARALLEL_TIMEOUT)                    
            {                                    
                //
                // Display error message
                //
                EdbgOutputDebugString("OEMParallelPortSendByte: status timeout 2.\r\n");

                //
                // set parallel port to disconnected and return failure   
                //
                NoPPFS=TRUE;                    
                return;                      
            }
        }            

        //
        // Read auto FD two times to make sure that it is set again.
        //
        if(( *IDE_CTRL & PAR_AUTOFD))
        {
            continue;
        }
        if(( *IDE_CTRL & PAR_AUTOFD))
        {
            continue;
        }
        if(( *IDE_CTRL & PAR_AUTOFD))
        {
            continue;
        }

        if( !(*IDE_CTRL & PAR_AUTOFD))
        {
            break;
        }

    }
    //
    // Clear Ack
    //
    *IDE_CTRL = PAR_NREAD ;               
    
    //
    // Put a little delay in here.
    //
    //VosDelayInuS(20);

    //
    // Assert Busy and nAcknowledge.  Back to the default Parallel port state
    //
    *IDE_CTRL  = PAR_NWRITE | PAR_NREAD ;
}


//***************************************************************************
//  OEMIsParallelReady - is parallel port connected and ready for transfer
//
//  
//***************************************************************************
BOOL OEMIsParallelReady(void) 
{
    DWORD dwStart;

    //
    // Find the initial time in seconds.
    //
    dwStart= GetSystemTimeInMsec();
    
    //
    // Set direction to write and latch in the line data.
    //
    *IDE_CTRL  = PAR_NREAD| PAR_NWRITE |PAR_ACK ;
        
    //
    // Wait for AUTOFD
    //
    while (*IDE_CTRL & PAR_AUTOFD) 
    {
        if (GetSystemTimeInMsec() - dwStart > 3000)
            return FALSE;
    }
    return TRUE;
}

⌨️ 快捷键说明

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