📄 pp.c
字号:
/* * Copyright (C) 2004 Tobias Lorenz * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. *//* parallel port interface */#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <sys/ioctl.h>#include <linux/ppdev.h>#include "pp.h"/* PP_Port+0: Data PP_Port+1: Status PP_Port+2: Control*//* * linux pp access via direct hardware calls *//* address of parallel port */static unsigned int pp_direct_port;/* macros for inb and outb */static __inline unsigned char pp_direct_inb(void){ unsigned char _v; __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (pp_direct_port+1)); return _v;}static __inline void pp_direct_outb(unsigned char value){ __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (pp_direct_port));}int pp_direct_init(unsigned int port){ pp_direct_port = port; if (port == 0) port = 0x378; /* enable the use of the parallel port */ if (ioperm(pp_direct_port, 3, 1) != 0) { printf ("ERROR: ioperm(0x%x) failed\n", pp_direct_port); return(-1); }}void pp_direct_done(void){}/* * linux pp access via /dev/parport? *//* parallel port device */static unsigned int pp_ppdev_fd = -1;unsigned char pp_ppdev_inb(void){ // PP_Port+1=Status unsigned char status; ioctl(pp_ppdev_fd, PPRSTATUS, &status); return(status);}void pp_ppdev_outb(unsigned char value){ // PP_Port+0=Data ioctl(pp_ppdev_fd, PPWDATA, &value);}int pp_ppdev_init(unsigned char *device){ if (!device) return(-1); if ((pp_ppdev_fd = open(device, O_RDWR)) == -1) { printf ("ERROR: open(%s) failed\n", device); return(-1); } if (ioctl(pp_ppdev_fd, PPCLAIM)) { printf ("ERROR: ioctl(PPCLAIM) failed\n"); close(pp_ppdev_fd); return(-1); }}void pp_ppdev_done(void){ ioctl(pp_ppdev_fd, PPRELEASE); close(pp_ppdev_fd);}/* * generic parallel port access */unsigned char pp_inb(void){ return pp_ppdev_inb();}void pp_outb(unsigned char value){ pp_ppdev_outb(value);}void pp_init(void){ pp_ppdev_init("/dev/parport0");}void pp_done(void){ pp_ppdev_done();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -