mdppfs.c
来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C语言 代码 · 共 371 行
C
371 行
/******************************************************************************
* File: mdppfs.c
* Author: Naresh Gupta
* Date: May 08, 1998 (First working version)
* Purpose: This file implements all the parallel port related stuff. Since
* all the parallel port definitions are ONLY used in this file,
* i've removed the need of any separate include file.
*******************************************************************************/
#include "windows.h"
#include "platform.h"
/*****************************************************************************
* Define DEBUG_PPSH if you want to debug PPSH code
* This would print extra debug messages.
****************************************************************************/
// #define DEBUG_PPSH
/****************************************************************************
* For the DEBUG Version, Enable PPSH Always.
****************************************************************************/
#ifdef DEBUG
# ifdef DISABLE_PPSH
# undef DISABLE_PPSH
# endif // DISABLE_PPSH
#endif // DEBUG
#if (SH_PLATFORM==PLATFORM_ASPEN)
#define PAR_EN 0x8000
#define PAR_AUTOEN 0x2000
#define PAR_BUSY 0x1000
#define PAR_NACK 0x0800
#define PAR_ERROR 0x0400
#define PAR_SELECT 0x0200
#define PAR_NFAULT 0x0100
#define PAR_INTR_MASK 0x0020
#define PAR_INTR 0x0010
#define PAR_SELECTIN 0x0008
#define PAR_INIT 0x0004
#define PAR_AUTOFD 0x0002
#define PAR_NSTROBE 0x0001
#elif (SH_PLATFORM==PLATFORM_BIGSUR)
#define PAR1_EN 0x80
#define PAR1_AUTOEN 0x20
#define PAR1_BUSY 0x10
#define PAR1_NACK 0x08
#define PAR1_ERROR 0x04
#define PAR1_SELECT 0x02
#define PAR1_NFAULT 0x01
#define PAR2_INTR_MASK 0x20
#define PAR2_INTR 0x10 //For Bigsur This bit State Busy
#define PAR2_SELECTIN 0x08
#define PAR2_INIT 0x04
#define PAR2_AUTOFD 0x02
#define PAR2_NSTROBE 0x01
#endif
typedef volatile DWORD *PVDWORD; /* pointer to a volatile dword */
/*****************************************************************************
* Notes
* 1. I have reduced the iWatchdog count since it took too long to timeout
* in case ppsh is not running.
* 2. Another thing i came across is that irrespective of what you set NoPPFS
* here, in the RAM version, it still tries to send a byte to the parallel
* port.
* 3. The Constant DISABLE_PPSH controls whether ppsh is used or not. This is
* defined in the platform specific header file, for eg. aspen.h.
****************************************************************************/
#ifdef DISABLE_PPSH
BOOL NoPPFS = TRUE; // parallel port disconnected flag
#else DISABLE_PPSH
BOOL NoPPFS = FALSE; // parallel port disconnected flag
#endif DISABLE_PPSH
BOOL NoWatchdog = FALSE; // If true, then do not time out if WatchDog
// timer expires.
//***************************************************************************
// 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)
{
#if(SH_PLATFORM==PLATFORM_ASPEN)
DWORD dwStatus, dwData; // parallel port status and Data
unsigned int iWatchdog=0xffffff; // timeout counter
#ifdef DEBUG_PPSH
DEBUGMSG(1, (TEXT("+OEMParallelPortGetByte\r\n")));
#endif DEBUG_PPSH
#ifdef DISABLE_PPSH
iWatchdog = 0xFF;
#endif DISABLE_PPSH
if (NoPPFS) // if parallel port disconnected
return -1; // do nothing
// dwStatus = PAR_AUTOEN | PAR_NACK | PAR_SELECT | PAR_NFAULT | PAR_INTR_MASK;
dwStatus = PAR_AUTOEN | PAR_SELECT | PAR_NFAULT | PAR_INTR_MASK;
*(PVDWORD)(PAR_CONTROL_REG) = dwStatus;
// Wait for INTR pin to go high.
while (!((dwStatus= *(PVDWORD)(PAR_CONTROL_REG)) & PAR_INTR) && --iWatchdog) {
if(NoWatchdog)
iWatchdog ++;
}
if (!iWatchdog) { // if timeout occured
// display error message
#ifndef BOOT_LOADER
ERRORMSG(1, (TEXT("OEMParallelPortGetByte: status timeout(1). Please make sure that you have the parallel cable connected properly and ppsh running on Host.\r\n")));
#endif
NoPPFS=TRUE; // set parallel port to disconnected
return -1; // and return failure
}
dwData = *(PVDWORD)(PAR_DATA_REG);
dwStatus = PAR_BUSY;
*(PVDWORD)(PAR_CONTROL_REG) = dwStatus;
#ifdef DEBUG_PPSH
DEBUGMSG(1, (TEXT("-OEMParallelPortGetByte. Got 0x%x (%c)\r\n", dwData&0xff, dwData&0xff));
#endif DEBUG_PPSH
return(dwData&0xff); // return byte received
#elif (SH_PLATFORM==PLATFORM_BIGSUR)
BYTE bStatus, bData; // parallel port status and Data
unsigned int iWatchdog=0xffffff; // timeout counter
#ifdef DEBUG_PPSH
DEBUGMSG(1, (TEXT("+OEMParallelPortGetByte\r\n")));
#endif DEBUG_PPSH
#ifdef DISABLE_PPSH
iWatchdog = 0xFF;
#endif DISABLE_PPSH
if (NoPPFS) // if parallel port disconnected
return -1; // do nothing
bStatus = PAR1_AUTOEN | PAR1_SELECT | PAR1_NFAULT;
*(PVBYTE)(PAR_CONTROL1_REG) = bStatus;
bStatus = PAR2_INTR_MASK;
*(PVBYTE)(PAR_CONTROL2_REG) = bStatus;
// Wait for INTR pin to go high.
while (!((bStatus= *(PVBYTE)(PAR_CONTROL2_REG)) & PAR2_INTR) && --iWatchdog) {
if(NoWatchdog)
iWatchdog ++;
}
if (!iWatchdog) { // if timeout occured
// display error message
#ifndef BOOT_LOADER
ERRORMSG(1, (TEXT("OEMParallelPortGetByte: status timeout(1). Please make sure that you have the parallel cable connected properly and ppsh running on Host.\r\n")));
ERRORMSG(1, (TEXT("PAR_CONTROL2_REG : (*(PVBYTE)0x%x = 0x%x).\r\n"), PAR_CONTROL2_REG, *(PVBYTE)(PAR_CONTROL2_REG) ));
#endif
NoPPFS=TRUE; // set parallel port to disconnected
return -1; // and return failure
}
bData = *(PVBYTE)(PAR_DATA_REG);
bStatus = PAR1_BUSY;
*(PVBYTE)(PAR_CONTROL1_REG) = bStatus;
#ifdef DEBUG_PPSH
DEBUGMSG(1, (TEXT("-OEMParallelPortGetByte. Got 0x%x (%c)\r\n"), bData&0xff, bData&0xff));
#endif DEBUG_PPSH
return(bData&0xff); // return byte received
#endif (SH_PLATFORM==PLATFORM_ASPEN)
}
//***************************************************************************
// OEMParallelPortSendByte - send byte out parallel port
//
// Input - chData=byte to send
//
// Output - sets NoPPFS=TRUE if parallel port disconnected
//***************************************************************************
VOID OEMParallelPortSendByte(BYTE chData)
{
#if(SH_PLATFORM==PLATFORM_ASPEN)
unsigned int iWatchdog=0xffffff; // timeout counter
DWORD dwStatus, dwData; // parallel port status, Data
#ifdef DEBUG_PPSH
DEBUGMSG(1, (TEXT("+OEMParallelPortSendByte: 0x%x(%c)\r\n", (int)chData, chData)));
#endif DEBUG_PPSH
#ifdef DISABLE_PPSH
iWatchdog = 0xFF;
#endif DISABLE_PPSH
if (NoPPFS) // if ppfs disconnected
return; // do nothing
// Reset NACK, set NFAULT, SELECT, BUSY;
dwStatus = (PAR_NFAULT | PAR_SELECT | PAR_BUSY);
*(PVDWORD)(PAR_CONTROL_REG) = dwStatus;
dwData = (DWORD)(chData << 8);
*(PVDWORD)(PAR_DATA_REG) = dwData;
// Wait for AutoFD to be set.
while (!((dwStatus= *(PVDWORD)(PAR_CONTROL_REG)) & PAR_AUTOFD) && --iWatchdog) {
if(NoWatchdog)
iWatchdog ++;
}
if (!iWatchdog) { // if timeout occurred
// display error message
#ifndef BOOT_LOADER
ERRORMSG(1, (TEXT("OEMParallelPortSendByte: status timeout(1). Please make sure that you have the parallel cable connected properly and ppsh running on Host.\r\n")));
#endif
NoPPFS=TRUE; // and disconnect ppfs
return;
}
dwStatus |= PAR_EN;
*(PVDWORD)(PAR_CONTROL_REG) = dwStatus;
dwStatus |= PAR_NACK;
*(PVDWORD)(PAR_CONTROL_REG) = dwStatus;
// iWatchdog=0xffffff; // timeout counter
// Wait for AutoFD to be reset.
while (((dwStatus= *(PVDWORD)(PAR_CONTROL_REG)) & PAR_AUTOFD) && --iWatchdog) {
if(NoWatchdog)
iWatchdog ++;
}
if (!iWatchdog) { // if timeout occurred
// display error message
#ifndef BOOT_LOADER
ERRORMSG(1, (TEXT("OEMParallelPortSendByte: status timeout(2). Please make sure that you have the parallel cable connected properly and ppsh running on Host.\r\n")));
#endif
NoPPFS=TRUE; // and disconnect ppfs
return;
}
// Reset NACK;
*(PVDWORD)(PAR_CONTROL_REG) = (PAR_BUSY | PAR_NFAULT | PAR_AUTOEN | PAR_SELECT);
#ifdef DEBUG_PPSH
DEBUGMSG(1, (TEXT("-OEMParallelPortSendByte\r\n")));
#endif DEBUG_PPSH
#elif(SH_PLATFORM==PLATFORM_BIGSUR)
unsigned int iWatchdog=0xffffff; // timeout counter
BYTE bStatus, bData; // parallel port status, Data
#ifdef DEBUG_PPSH
DEBUGMSG(1, (TEXT("+OEMParallelPortSendByte: 0x%x(%c)\r\n"), (int)chData, chData));
#endif DEBUG_PPSH
#ifdef DISABLE_PPSH
iWatchdog = 0xFF;
#endif DISABLE_PPSH
if (NoPPFS) // if ppfs disconnected
return; // do nothing
// Reset NACK, set NFAULT, SELECT, BUSY;
bStatus = (PAR1_NFAULT | PAR1_SELECT | PAR1_BUSY);
*(PVBYTE)(PAR_CONTROL1_REG) = bStatus ;
bData = chData;
*(PVBYTE)(PAR_DATA_REG) = bData;
// Wait for AutoFD to be set.
while (!((bStatus = *(PVBYTE)(PAR_CONTROL2_REG)) & PAR2_AUTOFD) && --iWatchdog) {
if(NoWatchdog)
iWatchdog ++;
}
if (!iWatchdog) { // if timeout occurred
// display error message
#ifndef BOOT_LOADER
ERRORMSG(1, (TEXT("OEMParallelPortSendByte: status timeout(1). Please make sure that you have the parallel cable connected properly and ppsh running on Host.\r\n")));
#endif BOOT_LOADER
NoPPFS=TRUE; // and disconnect ppfs
return;
}
bStatus |= PAR1_EN;
*(PVBYTE)(PAR_CONTROL1_REG) = bStatus ;
bStatus |= PAR1_NACK;
*(PVBYTE)(PAR_CONTROL1_REG) = bStatus ;
// iWatchdog=0xffffff; // timeout counter
// Wait for AutoFD to be reset.
while (((bStatus = *(PVBYTE)(PAR_CONTROL2_REG)) & PAR2_AUTOFD) && --iWatchdog) {
if(NoWatchdog)
iWatchdog ++;
}
if (!iWatchdog) { // if timeout occurred
// display error message
#ifndef BOOT_LOADER
ERRORMSG(1, (TEXT("OEMParallelPortSendByte: status timeout(2). Please make sure that you have the parallel cable connected properly and ppsh running on Host.\r\n")));
#endif BOOT_LOADER
NoPPFS=TRUE; // and disconnect ppfs
return;
}
// Reset NACK;
*(PVBYTE)(PAR_CONTROL1_REG) = (PAR1_BUSY | PAR1_NFAULT | PAR1_AUTOEN | PAR1_SELECT);
#ifdef DEBUG_PPSH
DEBUGMSG(1, (TEXT("-OEMParallelPortSendByte\r\n")));
#endif DEBUG_PPSH
#endif (SH_PLATFORM == PLATFORM_ASPEN)
}
//***************************************************************************
// OEMParallelPortGetStatus - check parallel status and return byte if ready
//
// returns: -1 if data not available on parallel port
// else retuns data byte from parallel port
//***************************************************************************
int OEMParallelPortGetStatus(void)
{
#if(SH_PLATFORM==PLATFORM_ASPEN)
DWORD dwStatus, dwData;
dwStatus = PAR_AUTOEN | PAR_SELECT | PAR_NFAULT | PAR_INTR_MASK;
*(PVDWORD)(PAR_CONTROL_REG) = dwStatus;
dwStatus = *(PVDWORD)(PAR_CONTROL_REG);
dwData = *(PVDWORD)(PAR_DATA_REG);
if(!(dwStatus & PAR_INTR))
return -1;
*(PVDWORD)(PAR_CONTROL_REG) = (PAR_BUSY | PAR_NFAULT | PAR_AUTOEN | PAR_SELECT);
return (dwData & 0xff);
#elif(SH_PLATFORM==PLATFORM_BIGSUR)
BYTE bStatus, bData;
bStatus = PAR1_AUTOEN | PAR1_SELECT | PAR1_NFAULT ;
*(PVBYTE)(PAR_CONTROL1_REG) = bStatus;
bStatus = PAR2_INTR_MASK;
*(PVBYTE)(PAR_CONTROL2_REG) = bStatus;
bStatus = *(PVBYTE )(PAR_CONTROL2_REG);
bData = *(PVBYTE )(PAR_DATA_REG);
if(!( bStatus & PAR2_INTR))
return -1;
*(PVBYTE )(PAR_CONTROL1_REG) = (PAR1_BUSY | PAR1_NFAULT | PAR1_AUTOEN | PAR1_SELECT);
return ( bData & 0xff);
#endif(SH_PLATFORM==PLATFORM_BIGSUR)
// For BigSur just return 0 right now.
// This function is never called. So need not worry.
return (0);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?