Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Git Source Tree
Root/
| 1 | /* JTAG chain device database |
| 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 | #include "devicedb.h" |
| 21 | |
| 22 | using namespace std; |
| 23 | |
| 24 | DeviceDB::DeviceDB(const char *fname) |
| 25 | { |
| 26 | filename=fname; |
| 27 | FILE *fp=fopen(fname,"rt"); |
| 28 | if(fp==0)fprintf(stderr,"Cannot open device database file '%s'\n",fname); |
| 29 | else fclose(fp); |
| 30 | } |
| 31 | |
| 32 | int DeviceDB::loadDevice(const unsigned long id) |
| 33 | { |
| 34 | FILE *fp=fopen(filename.c_str(),"rt"); |
| 35 | if(fp==0){ |
| 36 | fprintf(stderr,"Cannot open device database file '%s'\n",filename.c_str()); |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | int irlen; |
| 41 | while(!feof(fp)){ |
| 42 | unsigned long idr; |
| 43 | char text[256]; |
| 44 | char buffer[256]; |
| 45 | fgets(buffer,256,fp); // Get next line from file |
| 46 | sscanf(buffer,"%08x %d %s",&idr,&irlen,text); |
| 47 | if(id==idr){ |
| 48 | device_t dev; |
| 49 | dev.text=text; |
| 50 | dev.idcode=idr; |
| 51 | dev.irlen=irlen; |
| 52 | devices.push_back(dev); |
| 53 | fclose(fp); |
| 54 | return irlen; |
| 55 | } |
| 56 | } |
| 57 | fclose(fp); |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | int DeviceDB::getIRLength(int i) |
| 62 | { |
| 63 | if(i>=devices.size())return 0; |
| 64 | return devices[i].irlen; |
| 65 | } |
| 66 | |
| 67 | const char *DeviceDB::getDeviceDescription(int i) |
| 68 | { |
| 69 | if(i>=devices.size())return 0; |
| 70 | return devices[i].text.c_str(); |
| 71 | } |
| 72 |
Branches:
master
