home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / hf / dsp / source / dl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-20  |  3.1 KB  |  124 lines

  1. /*  DL.C -- Download DSP56001 programs to the DSP CARD 3
  2.  *
  3.  *  Copyright (C) by Alef Null 1990, 1991
  4.  *  Author(s): Jarkko Vuori, OH2LNS
  5.  *  Modification(s):
  6.  */
  7.  
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <memory.h>
  12. #include <conio.h>
  13. #include "dspio.h"
  14. #include "sylk.h"
  15.  
  16.  
  17. int cdecl main(int argc, char *argv[]) {
  18.     FILE *fd;
  19.     static struct {
  20.     unsigned debug:1;
  21.     unsigned log:1;
  22.     unsigned dump:1;
  23.     unsigned port:1;
  24.     unsigned ssi:1;
  25.     } flags = { 0 };
  26.     int  y = 1;
  27.     char option, *filename = NULL;
  28.  
  29.     printf("DSP CARD 3 program downloader (%s)\n", __DATE__);
  30.  
  31.     /* parse arguments */
  32.     argc--; argv++;
  33.     while(argc > 0) {
  34.     switch(**argv) {
  35.     case '-':
  36.         switch(option = *(++(*argv))) {
  37.         /* flag for dl to enter special debug mode */
  38.         case 'd':
  39.         case 'D':
  40.         flags.debug = -1;
  41.         break;
  42.  
  43.         /* flag for dl to enter special data logger mode */
  44.         case 'l':
  45.         case 'L':
  46.         flags.log = -1;
  47.         break;
  48.  
  49.         /* flag for dl to enter memory dump check mode */
  50.         case 'c':
  51.         case 'C':
  52.         flags.dump = -1;
  53.         break;
  54.  
  55.         /* flag for dl to force printer port selection */
  56.         case 'p':
  57.         case 'P':
  58.         flags.port = atoi(++(*argv));
  59.         break;
  60.  
  61.         /* flag for dl to force SSI source selection */
  62.         case 's':
  63.         case 'S':
  64.         flags.ssi = atoi(++(*argv));
  65.         break;
  66.  
  67.         default:
  68.         fprintf(stderr, "unknown option '%c', type 'dl ?' to get the allowed options\n", option);
  69.         break;
  70.         }
  71.         break;
  72.  
  73.     case '?':
  74.         fprintf(stderr, "usage: dl [-d | -l | -c | -p<portno> | -s<ssisource>] [<filename>]\n");
  75.         fprintf(stderr, "\t-d reads data from DSP CARD 3 and displays it\n");
  76.         fprintf(stderr, "\t-l reads data from DSP CARD 3 and stores it to the file LOG.DAT\n");
  77.         fprintf(stderr, "\t-c reads memory image from DSP CARD 3 and verifies it\n");
  78.         fprintf(stderr, "\t-p<portno> uses the specified printer port (1 LPT1, 2 LPT2)\n");
  79.         fprintf(stderr, "\t   (otherwise dl searches it automatically)\n");
  80.         fprintf(stderr, "\t-s<ssisource> selects the specified ssi source\n");
  81.         fprintf(stderr, "\t   (1 external, 0 internal (default))\n");
  82.         return (0);
  83.         break;
  84.  
  85.     default:
  86.         filename = *argv;
  87.         break;
  88.     }
  89.  
  90.     argc--; argv++;
  91.     }
  92.  
  93.     if(!filename && !flags.debug) {
  94.     fprintf(stderr, "no file specified\n");
  95.     return (-1);
  96.     }
  97.  
  98.     fd = stdout;
  99.     if (OpenCardIo(flags.port) ||
  100.        (filename  ? OpenLodFile(filename) : 0) ||
  101.        (flags.log ? !(fd = fopen("LOG.DAT", "w")) : 0))
  102.     return (-1);
  103.     setvbuf(fd, NULL, _IOFBF, 4096);
  104.  
  105.     /* select ssi source, and download the software */
  106.     SelectSSI(!flags.ssi);
  107.     if (filename)
  108.     DownLoad(-1);
  109.  
  110.     /* if debug (or log) mode, read data from DSP */
  111.     if (flags.debug || flags.log)
  112.     while (!kbhit())
  113.         if (ReadByte(ISR) & 0x01) {
  114.         fprintf(fd, "%8ld ", ReadHostWord()); if (!(y++ % 8)) fprintf(fd, "\n");
  115.         }
  116.  
  117.     /* if dump check mode, read memory dumps from the DSP and check them */
  118.     if (flags.dump)
  119.     CheckMemDump();
  120.  
  121.     CloseCardIo(); CloseLodFile();
  122.     return (0);
  123. }
  124.