📄 parport.c
字号:
/* * $Id: parport.c,v 1.1 2002/12/05 22:20:38 telka Exp $ * * Copyright (C) 2001, 2002 ETC s.r.o. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by Marcel Telka <marcel@telka.sk>, 2001, 2002. * */#include <_windows.h>#include <nkintr.h>#include "board.h"#include <sa11x0/gpio.h>#include "parport.h"/* parallel port communication protocol */int PP_Protocol = PP_PROTOCOL_MSCEPB;/* TRUE if error in communication occured */BOOL NoPPFS = FALSE;/* * This file implements MS-specific communication via parallel port - needed for CEPB * This is not true EPP communication - require brutal hardware hack: * must be ACK wired with BUSY (WT) * For more info see `Data Transfer Examples' in WinCE 3.0 documentation * * if you want communicate using standard EPP, set global variable PP_Protocol * to PP_PROTOCOL_EPP */intOEMParallelPortGetByte( void ){#if (WID == EI370) DWORD data; int Timeout = 0x200000; if (NoPPFS) return -1; GPDR &= 0xFE3FFC03; /* in: GP2:9, GP22:24 */ GPDR |= 0x00300000; /* out: GP20:21 */ GPSR = GPIO_DIR_MASK; /* direction: in (GPIO_DIR = 1) */ GPCR = GPIO_WT_MASK; /* nWT = 0 */ while ((GPLR & 0x00C00000) && --Timeout) ; /* wait for data (nWR = nDS = 0) */ if (!Timeout) { NoPPFS = TRUE; return -1; } data = (GPLR >> 2) & 0xFF; /* data = GP2:9 */ GPSR = GPIO_WT_MASK; /* nWT = 1 */ switch (PP_Protocol) { case PP_PROTOCOL_MSCEPB: while ((!(GPLR & GPIO_WR_MASK)) && --Timeout) ; /* wait for nWR = 1 */ break; case PP_PROTOCOL_EPP: default: while ((!(GPLR & GPIO_DS_MASK)) && --Timeout) ; /* wait for nDS = 1 */ } if (!Timeout) { NoPPFS = TRUE; return -1; } GPCR = GPIO_WT_MASK; /* nWT = 0 */ return data;#else /* (WID == EI370) */ NoPPFS = TRUE; return -1;#endif /* (WID == EI370) */}voidOEMParallelPortSendByte( BYTE ch ){#if (WID == EI370) DWORD data = ch; int Timeout = 0x200000; if (NoPPFS) return; GPDR &= 0xFE3FFFFF; /* in: GP22:24 */ GPDR |= 0x003003FC; /* out: GP2:9, GP20:21 */ GPCR = GPIO_DIR_MASK; /* direction: out (GPIO_DIR = 0) */ GPCR = GPIO_WT_MASK; /* nWT = 0 */ switch (PP_Protocol) { case PP_PROTOCOL_MSCEPB: /* wait for nWR = 1, nDS = 1 */ while (((GPLR & 0x00C00000) != 0x00C00000) && --Timeout) ; break; case PP_PROTOCOL_EPP: default: /* wait for nWR = 1, nDS = 0 */ while (((GPLR & 0x00C00000) != 0x00400000) && --Timeout) ; } if (!Timeout) { NoPPFS = TRUE; return; } GPSR = data << 2; GPCR = ((~data) & 0xFF) << 2; /* set data (GP2:9) */ GPSR = GPIO_WT_MASK; /* nWT = 1 */ switch (PP_Protocol) { case PP_PROTOCOL_MSCEPB: while ((GPLR & GPIO_DS_MASK) && --Timeout) ; /* wait for nDS = 0 */ break; case PP_PROTOCOL_EPP: default: while ((!(GPLR & GPIO_DS_MASK)) && --Timeout) ; /* wait for nDS = 1 */ } if (!Timeout) { NoPPFS = TRUE; return; } GPCR = GPIO_WT_MASK; /* nWT = 0 */#else /* (WID == EI370) */ UNREFERENCED_PARAMETER( ch ); NoPPFS = TRUE;#endif /* (WID == EI370) */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -