a gal programmer for linux pcs

14
A GAL Programmer for LINUX PCs Abstract GALs (Generic Array Logic) are reprogrammable digital integrated cir- cuits which can be used to replace standard 74xx- or 40xx-family devices to gain a higher level of integration and/or a more flexible circuit design. They are inexpensive, easy to obtain and you can get development software for free. This project provides some software to use a home-made GAL programmer (designed by Markus Hoffmann and published in the "Elektor"- Magazine in 1993) with a PC using the LINUX operating system. Addition- ally, it includes a small hardware patch to generate programming voltages needed by recent device types. Currently, only GAL16V8- and GAL20V8- series types are supported. 1 Disclaimer galprog - Linux GAL Programming Software Copyright c 5/1999 M.Prinke <[email protected]> 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 Foun- dation; 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 Li- cense 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., 675 Mass Ave, Cambridge, MA 02139, USA. This means in particular: I will give absolutely no guarantee that the program or circuit will work as de- scribed, that it will not destroy the GAL chips, the circuit, or even your PC and any peripherials connected to it, and that it will program GAL chips and that pro- grammed GAL chips will work as intended or will stay programmed. If you want some guarantee, buy a commerial product. This is a hobbyist grade product. If you intend to program GALs for a commercial product, go 1

Upload: luciedna

Post on 26-Dec-2015

133 views

Category:

Documents


10 download

TRANSCRIPT

Page 1: A GAL Programmer for LINUX PCs

A GAL Programmer for LINUX PCs

Abstract

GALs (Generic Array Logic)are reprogrammable digital integrated cir-cuits which can be used to replace standard 74xx- or 40xx-family devicesto gain a higher level of integration and/or a more flexible circuit design.They are inexpensive, easy to obtain and you can get development softwarefor free. This project provides some software to use a home-made GALprogrammer (designed by Markus Hoffmann and published in the "Elektor"-Magazine in 1993) with a PC using the LINUX operating system. Addition-ally, it includes a small hardware patch to generate programming voltagesneeded by recent device types. Currently, only GAL16V8- and GAL20V8-series types are supported.

1 Disclaimer

galprog - Linux GAL Programming Software

Copyright c©5/1999 M.Prinke <[email protected]>

This program is free software; you can redistribute it and/or modify it under theterms of the GNU General Public License as published by the Free Software Foun-dation; 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 WITHOUTANY WARRANTY; without even the implied warranty of MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public Li-cense for more details.

You should have received a copy of the GNU General Public License alongwith this program; if not, write to the Free Software Foundation, Inc., 675 MassAve, Cambridge, MA 02139, USA.

This means in particular:I will give absolutely no guarantee that the program or circuit will work as de-scribed, that it will not destroy the GAL chips, the circuit, or even your PC andany peripherials connected to it, and that it will program GAL chips and that pro-grammed GAL chips will work as intended or will stay programmed.

If you want some guarantee, buy a commerial product. This is a hobbyistgrade product. If you intend to program GALs for a commercial product, go

1

Page 2: A GAL Programmer for LINUX PCs

and buy a professional programmer. Do not use any GALs programmed by thishardware/software in places where failure or malfunction may be dangerous to thehealth or result in monetary losses.

Caution:The programmer’s circuit uses a voltage converter to produce a voltage which ishigher than the supply voltage. To prevent an electric shock or other insuries incase of a malfunction, the printed circuit board should be mounted in a properenclosure.

2 What You Get

Before I bother you with the reason how and why this stuff came to be, here is ashort description of this project.

2.1 Hardware

The project uses the GAL programmer designed by Markus Hoffmann, which waspublished in the "Elektor"-Magazine ([1]) and in the book "Das GAL-Buch" ([2]).A small hardware-patch provides additional programming voltages of14.00V and14.50V . The programmer is connected to the PC’s parallel port.

2.2 Software

The software consists of several programs:

• gal : Device driver kernel module. Handles all hardware-dependent andtiming-critical tasks.

• galtest : Simple, low-level program to test the hardware. Controls theparallel port from user-space, so it has to be executed by root.

• gal_adj : Simple program to adjust the programming voltages and to checkthe logic levels. Controls the parallel port from user-space, so it has to beexecuted by root.

• repair_pes : Program to write theProgrammers Electronic Signature(PES). Useful if the PES was destroyed and you know its contents (e.g. fromanother device of the same type). Uses the device driver.

• galprog : The GAL programming software. It provides anncurses userinterface and uses the device driver. Reads and writes JEDEC-files.

• galprog2 : A new version of the GAL programming software written inPerl/Tk. It offers the same functions asgalprog , but has a much nicergraphical user interface. It also uses the device driver.

2

Page 3: A GAL Programmer for LINUX PCs

3 Overview

To be honest, GALs are not leading edge technology. If you really want to designhigly integrated digital circuits, CPLDs (Complex Programmable Logic Devices)or FPGAs (Field Programmable Gate Arrays) are the things to watch out for. Thereare CPLDs which can be programmed in circuit (ISP- or JTAG-interface, respec-tively) via a simple PC parallel port interface. You can even get the design softwarefor free, at least for a limited period.

But if you only need some simple glue logic for your microcontroller de-sign, your PC ISA-Bus-Card or whatever, a GAL may be sufficient and prefer-able. GALs can provide combinatorial logic, tristate outputs and registered outputs.They are:

• inexpensive

• easy to obtain

• easy to use

• easy to handle (e.g. 20-/24-pin DIP package)

• and design software (GAL assemblers) is available for free

The major drawback for using GALs as a hobbyist is the need for a program-mer1 which is relatively expensive, but there are some options for home buildingsuch a device at reasonable costs and efforts.

When I started some designs with 8051-series microcontrollers last year, I re-alized that a GAL programmer would be handy. By that time, GALs hat beenavailable some time and a variety of books and articles on that topic had been pub-lished. So I compared some designs and choose the one which seemed the mostsimple and inexpensive to me.

When the hardware was built – which was really easy, I realized that the ac-companying software did not support the recent device types. Obviously, the GALstuff was so outdated by now that nobody considered to keep the software up todate. The bad news was that even no source code was available for these oh-so-great DOS programs. So I decided to write my own software from scratch. It tooksome time for me to learn a little more about Linux device driver modules and toget thencurses user interface working. But that was nothing compared to thefact that the programming algorithms are not available from the manufacturers – asfar as you are not a recognized programming hardware company. But some peoplehave done the great and tedious job of revealing one of the best-kept secrets in theworld. And finally it worked.

For some reasons (see section4), I would not recommend to choose the hard-ware used in this project any more. Maybe the design described in [4] would be a

1exception: the ispGAL22V10 is an in circuit programmable GAL, which is slightly more expen-sive than a standard GAL22V10

3

Page 4: A GAL Programmer for LINUX PCs

better option. In this case, the device driver would have to be modified. If anyoneshould modify/rewrite the device driver part for a different hardware, I would behappy to hear about it. I also wonder if a GAL assembler exists, which could easilybe ported to Linux.

4 Building the Hardware

You can find a description of the hardware in [1] and [2]. For copyright reasons,I cannot include it here. I tried to contact the author on this topic, but I had nosuccess. If you are really interested in these articles and you cannot get any ofthem (because they are out of print), you should ask someone who knows. (Hint,hint. . .)

The design has two disadvantages: At first, it uses a 74LS673 16-bit shift reg-ister. This device is hard to obtain and sometimes very expensive. Since most ofits features are not used in this design, it can easily be replaced by two 8-bit shiftregisters (e.g. 74HC(T)4094 or 74HC(T)595), but this would require a patch of thePCB.

The second drawback is that the circuit was designed when only two differentprogramming voltages (15.75V and16.50V ) were used. Currently, also voltagesof 14.00V , 14.50V and15.00V are required by some device types. Some designsuse a D/A converter to provide the programming voltages. This is a good idea,but I didn’t want to spend any time on a redesign. I just added a simple patch tothe existing hardware (see fig.1) which provides14.00V and14.50V . If a GALshould ever require another value, you could either (a) adjust any voltage to fit yourneeds or (b) simply choose a value which is close enough.2

Once the hardware is ready, use the programgal_adj adjust the program-ming voltages and to check if it works properly.3 You will need a voltmeter anda piece of wire to do this. Using the program should be straightforward. Table1shows the register settings for the respective test cases. If you want to do somereally low-level tests, you can usegaltest to control the hardware.

5 Building and Installing the Software

5.1 Device Driver Kernel Module

5.1.1 Configuration

To build the Linux device driver for the programmer hardware, enter the directorydriver/ . If you did not apply the hardware patch described in section4, youhave to comment out the lines#define EXT_VOLT_1

2check the datasheet for the required accuracy3gal_adj has to be executed by root!

4

Page 5: A GAL Programmer for LINUX PCs

IC4/Pin 3

IC5/Pin 2110k 7k

510

k

BC

547

Figure 1: Hardware-Patch for additional Programming Voltages

and#define EXT_VOLT_2in gal.c before you start to compile.

5.1.2 Linux Kernel 2.2.x/2.4.x

CopyMakefile.linux-2.4.x to Makefile , then compile the module:$ cp Makefile.linux-2.4.x Makefile$ makeThe modulegal.o should have been created. Now you can install the driver. Youwill have to be logged in as root.# make installThis will do the following operations:

• remove anygal device driver loaded previously

• create the directories/lib/modules/misc/and /lib/modules/<kernel_version>/lib/ if they do not existyet

• install the kernel modulegal in these directories

• create the device nodes/dev/gal0 and/dev/gal1

The device’s minor number is used to determine the parallel port’s address:/dev/gal0⇒ port address0x278/dev/gal1⇒ port address0x378

The module will be loaded automatically when the application program tries toopen the device file/dev/gal0 , if you add the following line to your system’s/etc/conf.modules :alias char-major-62 gal # gal programmerOtherwise you will have to load the module manually by usingmodprobe or

5

Page 6: A GAL Programmer for LINUX PCs

insmod each time you want to use it. Please note that the module cannot be loadedif another device blocks the associated parallel port, e.g. a generic parport/printerdriver. In this case you will have to unload this device first.

The modulegal generates some debugging information which should be loggedto your system’s/var/log/messages .

5.1.3 Linux Kernel 2.6.x

With Linux kernel 2.6.x, kernel modules have to be compiled as a part of the ker-nel source tree [8]. This requires write access to the kernel source tree (usually/usr/src/linux/ ). You will have to be logged in as root.# cp Makefile.linux-2.6.x Makefile# make -C /usr/src/linux SUBDIRS=$PWD modulesThe modulegal.ko should have been created. Now the driver can be installed:# ./install.shThis will do the following operations:

• remove anygal device driver loaded previously

• create the directories/lib/modules/<kernel_version>/extra/if they do not exist yet

• install the kernel modulegal in these directories

• create the device nodes/dev/gal0 and/dev/gal1

The device’s minor number is used to determine the parallel port’s address:/dev/gal0⇒ port address0x278/dev/gal1⇒ port address0x378

The module will be loaded automatically when the application program tries toopen the device file/dev/gal0 , if you add the following line to your system’s/etc/modprobe.conf.local :alias char-major-62 gal # gal programmerOtherwise you will have to load the module manually by usingmodprobe orinsmod each time you want to use it. Please note that the module cannot be loadedif another device blocks the associated parallel port, e.g. a generic parport/printerdriver. In this case you will have to unload this device first.

5.2 Compiling the low-level Tools

The low-level toolsgal_adj , galtest andrepair_pes can be found in thedirectory tools/ . There you will finde aMakefile , too. Just typemake tobuild the programs.

6

Page 7: A GAL Programmer for LINUX PCs

5.3 Compiling the GAL Programmer Application Program

The GAL programmer application programgalprog and itsMakefile can befound in the directorygalprog/ . If you did not apply the hardware patch de-scribed in section4, you have to comment out the defines#define EXT_VOLT_1and#define EXT_VOLT_2in galprog.h !

As before, a simplemake should build the executable. However, in some casesthe ncurses library may cause problems. It can either be linked dynamically(which is the default) or statically. If you experience any difficulties, just changethe linking option in theMakefile . When the program is build successfully, justcopy it to/usr/local/bin so you can access it from any working directory.

6 Using thegalprog Software

6.1 General

When you startgalprog , you will have to select the appropriate device driverfirst. Remember that the device driver determines which parallel port will be used.Since there is no possibility to detect the programmer hardware automatically, youhave to watch the LED to check if the setup is correct.

Figure2 shows a screenshot of thegalprog user interface. The operationis straightforward. The first step is to select the GAL device type (GAL 16V8 orGAL 20V8) you want to use. To prevent any demages, please insert/remove a GALinto/from the programming socket only if the program asks you to do so. Make surethat the device is inserted properly, i.e. in the correct position and orientation.

6.2 Menu Options

Set Port Selects the parallel port.

Set GAL Type Sets the general GAL device type. The specific type (e.g. 16V8D)will be detected automatically.

Load JEDEC Loads programming data from a JEDEC file into the internal fusemapbuffer. The file syntax is checked, but not very extensively.

Save JEDEC Saves the programming data in the internal fusemap buffer to aJEDEC file.

Read GAL Reads the programming data from a GAL device (master) to the fusemapbuffer. This works only if its security fuse was not blown, otherwise the datawill be useless.

7

Page 8: A GAL Programmer for LINUX PCs

Figure 2: Screenshot of thegalprog User Interface

Write GAL Programs a GAL device with the data stored in the fusemap bufferand verifies it. Note the security fuse is not blown automatically, even if thesource JEDEC file indicated it.

Verify GAL Checks a programmed GAL against the fusemap buffer. This worksonly if the GAL’s security fuse was not blown.

Security Fuse Blows the security fuse to prevent reading back the fusemap data.The effect is that the AND-matrix data will be read back as all logic ones.

Quit Exits the program.

6.3 Status Information

Device Driver The name of the selected device driver.

GAL family The selected general device type.

JEDEC file The current JEDEC file name.

Fuse ChecksumThe fusemap checksum as a hexadecimal number.

8

Page 9: A GAL Programmer for LINUX PCs

7 Using thegalprog2 Software

The programgalprog2 is a port ofgalprog to Perl/Tk. Therefore, the samefunctionality and a very similar user interface is provided. Figure3 shows thegalprog2 main window. When a function is selected by pressing a button, a se-quence of dialog boxes show up. Please refer to section6 for a detailed descriptionof the programm’s usage.

Figure 3: Screenshot of thegalprog2 User Interface

8 To Do

• If the JEDEC-file contains the directive "*G1", the security fuse shall beblown. This is not implemented yet.

• Bit 0. . .7 of the Programmers Electronic Signature (PES)may contain a

9

Page 10: A GAL Programmer for LINUX PCs

programming cycle counter. I am not sure if commercial programmers stilluse this feature. Not implemented yet.

• Bits 56. . .63 of theProgrammers Electronic Signature (PES)contain a check-sum. I do not know how this checksum is calculated. Not used.

9 Additional Information

• The GALBlast archive ([4]) includes device IDs, manufacturer IDs and pro-gramming algorithms of virtually all GAL devices.

• The JEDEC file format standard can be found on the the JEDEC website([5]).

• GAL assembler GalAsm V1.5 for Linux by Volker Bosch [6]

• A GAL assembler, some useful GAL programming information and otherGAL programmers can be found on [7].

• Detailed background information on GALs and some application examplescan be found in [2] and [3].

• The layout of the configuration fuses for the GAL16V8 and the GAL20V8series can be found in appendixB.

• You can find this project’s archive and other electronics and Linux stuff onmy website http://members.surfeu.de/matthias.prinke/

c©10/2000 M. Prinke <[email protected]>

10

Page 11: A GAL Programmer for LINUX PCs

References

[1] Markus Hoffmann,GAL-Programmer mit Centronics-Schnittstelle, PC-Projekte, Sonderheft Plus 15, Elektor, 1993

[2] Ulrich Hack, Markus Hoffmann,Das GAL-Buch, 2. Auflage, Elektor, 1993

[3] Dieter Bitterle,GALs – Programmierbare Logikbausteine in Theorie undPraxis, 3. Auflage, Franzis, 1993

[4] Manfred Winterhoff,GALBlast ,http://www.geocities.com/ResearchTriangle/Forum/8070/index.html

[5] Standard Data Transfer Format Between Data Preparation System andProgrammable Logic Device Programmer, JEDEC Standard JESD3-C,http://www.jedec.org/

[6] Volker Boschs Homepage, http://www.s-line.de/homepages/bosch/

[7] Steve Walz’ FTP archive, ftp://ftp.armory.com/pub/electronics/GAL/

[8] William von Hagen, Migrating to Linux kernel 2.6 – Part 2:Migrating device drivers to Linux kernel 2.6, LinuxDevices.com,http://www.linuxdevices.com/articles/AT4389927951.html

11

Page 12: A GAL Programmer for LINUX PCs

A GAL Programmer Register Settings

Socket Pin Voltage/Level Shift Reg. Latch Note

2 16.50 V 0x1000 Poti 115.75 V 0x9000 Poti 214.50 V 0x3000 Poti 414.00 V 0xB000 Poti 2+412.00 V 0xD000 Poti 3

low 0x00003 16.50 V 0x0800 Poti 1

15.75 V 0x8800 Poti 214.50 V 0x2800 Poti 414.00 V 0xA800 Poti 2+412.00 V 0xC800 Poti 3

high 0x0400low 0x0000

4 high 0x00015 high 0x00026 high 0x00047 high 0x00088 high 0x00809 high 0x02

10 high 0x0411 high 0x0000 0x01

low 0x0040 0x0013 high 0x0814 high 0x1021 high 0x002022 high 0x001023 5.0 V 0x0200 LED on24 5.0 V 0x0100 LED on

Table 1: GAL Programmer Registers (low:0 . . . 0.5 V, high: 2.4 . . . 5.0 V;Programming Voltages 14.00 V and 14.50 V require modified Hardware)

12

Page 13: A GAL Programmer for LINUX PCs

B Configuration Fusemap

Fuse Nr. Row Index Row Index Fuse Name16V8 16V8A/B/C/D/Z/ZD

2048 32 0 XOR 19...

...2051 35 3 XOR 162052 46 78 XOR 15

......

2055 49 81 XOR 122120 37 5 AC1 19

......

2123 40 8 AC1 162124 41 73 AC1 15

......

2127 44 76 AC1 122128 0 9 PT 0

......

2159 31 40 PT 312160 50 41 PT 32

......

2191 81 72 PT 632192 45 77 SYN2193 36 4 AC0

Table 2: CFG-Fuses GAL16V8 / GAL16V8A/B/C/D/Z/ZD

13

Page 14: A GAL Programmer for LINUX PCs

Fuse Nr. Row Index Row Index Fuse Name20V8 20V8A/B/Z

2560 32 0 XOR 22...

...2563 35 3 XOR 192564 46 78 XOR 18

......

2567 49 81 XOR 152632 37 5 AC1 22

......

2635 40 8 AC1 192636 41 73 AC1 18

......

2639 44 76 AC1 152640 0 9 PT 0

......

2671 31 40 PT 312672 50 41 PT 32

......

2703 81 72 PT 632704 45 77 SYN2705 36 4 AC0

Table 3: CFG-Fuses GAL20V8 / GAL20V8A/B/Z

14