Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Git Source Tree
Root/
| 1 | /* JTAG GNU/Linux parport device io |
| 2 | |
| 3 | Copyright (C) 2004 Andrew Rogers |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the Free Software |
| 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
| 18 | |
| 19 | |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <sys/ioctl.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <linux/parport.h> |
| 25 | #include <linux/ppdev.h> |
| 26 | #include <sys/time.h> |
| 27 | #include <unistd.h> |
| 28 | |
| 29 | #include "ioparport.h" |
| 30 | |
| 31 | using namespace std; |
| 32 | |
| 33 | void IOParport::delay(int del) |
| 34 | { |
| 35 | struct timeval actualtime, endtime; |
| 36 | gettimeofday( &actualtime, NULL ); |
| 37 | |
| 38 | endtime.tv_usec=(actualtime.tv_usec+del)% 1000000; |
| 39 | endtime.tv_sec=actualtime.tv_sec+(actualtime.tv_usec+del)/1000000; |
| 40 | |
| 41 | while(1){ |
| 42 | gettimeofday( &actualtime, NULL ); |
| 43 | if ( actualtime.tv_sec > endtime.tv_sec ) |
| 44 | return; |
| 45 | if ( actualtime.tv_sec == endtime.tv_sec ) |
| 46 | if ( actualtime.tv_usec > endtime.tv_usec ) |
| 47 | return; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | IOParport::IOParport(const char *device_name) : IOBase() |
| 52 | { |
| 53 | fd = open (device_name, O_RDWR); |
| 54 | |
| 55 | if (fd == -1) { |
| 56 | //perror ("open"); |
| 57 | error=true; |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | if (ioctl (fd, PPCLAIM)) { |
| 62 | perror ("PPCLAIM"); |
| 63 | close (fd); |
| 64 | error=true; |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | // Switch to compatibility mode. |
| 69 | int mode = IEEE1284_MODE_COMPAT; |
| 70 | if (ioctl (fd, PPNEGOT, &mode)) { |
| 71 | perror ("PPNEGOT"); |
| 72 | close (fd); |
| 73 | error=true; |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | error=false; |
| 78 | } |
| 79 | |
| 80 | bool IOParport::txrx(bool tms, bool tdi) |
| 81 | { |
| 82 | unsigned char ret; |
| 83 | unsigned char data=0x10; // D4 pin5 TDI enable |
| 84 | if(tdi)data|=1; // D0 pin2 |
| 85 | if(tms)data|=4; // D2 pin4 |
| 86 | ioctl(fd, PPWDATA, &data); |
| 87 | //delay(2); |
| 88 | data|=2; // clk high D1 pin3 |
| 89 | ioctl(fd, PPWDATA, &data); |
| 90 | ioctl(fd, PPRSTATUS, &ret); |
| 91 | //delay(2); |
| 92 | //data=data^2; // clk low |
| 93 | //ioctl(fd, PPWDATA, &data); |
| 94 | //delay(2); |
| 95 | //ioctl(fd, PPRSTATUS, &ret); |
| 96 | return (ret&0x10)!=0; // TDO pin13 |
| 97 | } |
| 98 | |
| 99 | void IOParport::tx(bool tms, bool tdi) |
| 100 | { |
| 101 | unsigned char data=0x10; // D4 pin5 TDI enable |
| 102 | if(tdi)data|=1; // D0 pin2 |
| 103 | if(tms)data|=4; // D2 pin4 |
| 104 | ioctl(fd, PPWDATA, &data); |
| 105 | //delay(2); |
| 106 | data|=2; // clk high D1 pin3 |
| 107 | ioctl(fd, PPWDATA, &data); |
| 108 | //delay(2); |
| 109 | //data=data^2; // clk low |
| 110 | //ioctl(fd, PPWDATA, &data); |
| 111 | //delay(2); |
| 112 | } |
| 113 | |
| 114 | IOParport::~IOParport() |
| 115 | { |
| 116 | ioctl (fd, PPRELEASE); |
| 117 | close (fd); |
| 118 | |
| 119 | } |
| 120 |
Branches:
master
