Shell Script Operation under Linux

| III.4 Shell Script Operation under Linux If serial I/O is only used for program upload, shell script operation may be the most convenient way of testing with the shortest turn-around cycles. The sample script file below, shows the principles of operating BOOT-51 from a PC, running under Linux, with shell commands: `#!/bin/sh stty 9600 sane clocal -crtscts -hupcl </dev/ttyS1 # until stty 1.16 # stty -F /dev/ttyS1 9600 sane clocal -crtscts -hupcl # stty 2.0 or later reset51 /dev/lp0 sleep 1 asem $1.a51 echo "U" >/dev/ttyS1 cp $1.hex /dev/ttyS1 echo "G 8000" >/dev/ttyS1` In this example, serial I/O is done over serial port /dev/ttyS1, and the target system can be reset over printer port /dev/lp0. First of all, the serial port /dev/ttyS1 is initialized to the desired baudrate of 9600 Baud, 8 data bits, 1 stop bit, no parity and no handshake with the stty command. (If your stty is version 2.0 or later, better use the new command syntax with the -F option, as shown in commentary!) Then the reset51 program provided is executed to reset the target system via printer port /dev/lp0. After that, the sleep command waits until BOOT-51 has recovered from reset, fully output its sign-on message, and is ready for a command. Now ASEM-51 is invoked to assemble the application program. When finished, the BOOT-51 upload command 'U' is echoed to /dev/ttyS1, and the Intel-HEX file is also simply copied to that serial port. Finally the application program is started at address 8000H with the command 'echo "G 8000" >/dev/ttyS1'. To test an application program myprog.a51 with the above shell script (stored in a file test51), simply type `test51 myprog` at the shell prompt, and see what you get. Of course this was only a minimized example! In general you will not only have to modify serial port, baudrate, reset port, and start address for your local requirements, but also to do something for plausibility checking and error handling. For this, the more sophisticated script file boot has been provided. It allows an easy change of all configuration parameters with any ASCII editor. For further information see the commentary inside boot. In principle, boot contains only those configuration data! (The actual work is done by another script upload provided, which is invoked by boot. If your stty command is version 2.0 or later, better use the script file upload.new instead!) A program myprog.a51 can now be assembled, uploaded and started with `boot myprog` To get the boot script running, ensure that you have full read/write access to the serial port used as upload device! If a printer port is employed as reset device, the reset51 program requires root privileges! (see below) Finally, the reset51 program provided, may be worth a detailed explanation: When invoked, reset51 forms a reset pulse of the duration <pulsewidth> at the D0 and D1 outputs of a PC printer <port>, or at the DTR output of a serial <port>: `reset51 /dev/<port> [<pulsewidth>]`
Legal <port> values are: |  | lp0, lp1, lp2, ttyS0, ttyS1, ttyS2, ttyS3, cua0, cua1, cua2, cua3, null
Under Linux with kernels 2.0.x the printer ports are assigned to fixed I/O base addresses (lp0 = 3BCH, lp1 = 378H, lp2 = 278H). From kernel 2.2.0, the parport layer has been introduced, providing dynamic printer port assignment. If your 2.2.x kernel doesn't contain parport layer support or the /proc file system, you should recompile it respectively. This should also make PCI bus printer ports available as reset devices. reset51 can only handle the four standard PC serial ports ttyS0 thru ttyS3. (However, the boot script described above should also work with non-standard serial ports, because it operates them with the stty command only!) The serial ports ttyS0 and cua0 are equivalent, and so are ttyS1 and cua1, and so on. If /dev/null is specified as <port>, reset51 delays only for <pulsewidth> ms. The optional parameter <pulsewidth> is the duration of the reset pulse in ms. Legal values are: 1 <= <pulsewidth> <= 65535. (default is 50) When invoked without parameters, a help screen is displayed. In case of error, reset51 returns the exit code 1, 0 otherwise. When executed, reset51 forms a positive pulse at D0 (pin 2), and a negative pulse at D1 (pin 3) of a PC printer port, or a "high" pulse (-12 V !!!) at the DTR output of a serial port respectively. If the default pulse width of 50 ms is too short to reset the MCS-51 board, specify a greater pulse width. Since reset51 needs direct access to I/O ports, it requires root privileges! To make it available for all users, set the owner to "root" and set the "set-user-id"-bit: `chown root reset51 chmod u+s reset51` For shell script operation, a reset line is highly recommended! If you don't have it, you will always have to press the reset button of the target system, before invoking the boot script. Since this may easily be forgotten, it is better to automate this step.