Čeština / English
Login

SVN Repository / Prohlížení

Aktuální adresář: FITkit / trunk / mcu / libfitkit /

cmd.c

   1  /*******************************************************************************
   2     cmd.c:
   3     Copyright (C) 2009 Brno University of Technology,
   4                        Faculty of Information Technology
   5  
   6     LICENSE TERMS
   7  
   8     Redistribution and use in source and binary forms, with or without
   9     modification, are permitted provided that the following conditions
  10     are met:
  11     1. Redistributions of source code must retain the above copyright
  12        notice, this list of conditions and the following disclaimer.
  13     2. Redistributions in binary form must reproduce the above copyright
  14        notice, this list of conditions and the following disclaimer in
  15        the documentation and/or other materials provided with the
  16        distribution.
  17     3. All advertising materials mentioning features or use of this software
  18        or firmware must display the following acknowledgement:
  19  
  20          This product includes software developed by the University of
  21          Technology, Faculty of Information Technology, Brno and its
  22          contributors.
  23  
  24     4. Neither the name of the Company nor the names of its contributors
  25        may be used to endorse or promote products derived from this
  26        software without specific prior written permission.
  27  
  28     This software or firmware is provided ``as is'', and any express or implied
  29     warranties, including, but not limited to, the implied warranties of
  30     merchantability and fitness for a particular purpose are disclaimed.
  31     In no event shall the company or contributors be liable for any
  32     direct, indirect, incidental, special, exemplary, or consequential
  33     damages (including, but not limited to, procurement of substitute
  34     goods or services; loss of use, data, or profits; or business
  35     interruption) however caused and on any theory of liability, whether
  36     in contract, strict liability, or tort (including negligence or
  37     otherwise) arising in any way out of the use of this software, even
  38     if advised of the possibility of such damage.
  39  
  40     $Id$
  41  
  42     Popis:
  43       Rutiny pro command interpreter
  44  *******************************************************************************/
  45  
  46  /* Provedena revize */
  47  
  48  #include "define.h"
  49  #include "globfun.h"
  50  #include "uart.h"
  51  #include "cmd.h"
  52  
  53  /**
  54  
  55  
  56   **/
  57  #define term_read_after_break()     return term_rcv_char();
  58  
  59  
  60  
  61  
  62  
  63  /**
  64  
  65   **/
  66  inline void term_cmd_clear(void) {
  67    CMDStrLen = 0;
  68  }
  69  
  70  /**
  71  
  72  
  73  
  74   **/
  75  unsigned char term_cmd_read(void) {
  76    unsigned char ch;
  77  
  78    if ((ch = term_rcv_char()) != 0)  {
  79      switch (ch) {
  80        case BS:
  81          if (CMDStrLen != 0) {   // backspace
  82            CMDStrLen--;
  83            CMDStr[CMDStrLen] = 0;
  84  
  85            term_send_char(BS);   //smazani znaku v terminalu
  86            term_send_char(' ');
  87            term_send_char(BS);
  88          }
  89        break;
  90  
  91        case LF:                  // konec radku
  92          term_send_char(LF);
  93        break;
  94  
  95        case CR:                  // konec radku
  96          term_send_char(CR);
  97        break;
  98  
  99        default:                  // jine znaky
 100          if (CMDStrLen < MAX_COMMAND_LEN) {
 101            term_send_char(ch);
 102            CMDStr[CMDStrLen] = ch;
 103            CMDStrLen++;
 104            CMDStr[CMDStrLen] = 0;
 105          }
 106        break;
 107      } // switch
 108    }  // if
 109  
 110    if (ch != LF)
 111      return (0);
 112  
 113    return (1);
 114  }
 115  
 116  /**
 117  
 118  
 119   **/
 120  unsigned char term_cmd_decode(char *UString) {
 121  
 122    switch (CMDStrLen) {
 123      case 0:
 124        // neprisel zadny novy prikaz
 125        return (CMD_NULL);
 126  
 127      case 3:
 128        if (strcmp3("CLS", UString))
 129          return (CMD_CLEARSCREEN);
 130      break;
 131  
 132      case 4:
 133        if (strcmp4("HELP", UString))
 134          return (CMD_HELP);
 135      break;
 136  
 137      case 5:
 138        if (strcmp5("RAM D", UString))
 139          return (CMD_MCU_RAM_DUMP);
 140      break;
 141  
 142      case 9:
 143        if (strcmp9("PROG FPGA", UString))
 144          return (CMD_MCU_PROG_FPGAI);
 145        else if (strcmp9("RESET MCU", UString))
 146          return (CMD_MCU_RESET);
 147        else if (strcmp9("FLASH R S", UString))
 148          return (CMD_MCU_FLASHR_STATUS);
 149        else if (strcmp9("FLASH W X", UString))
 150          return (CMD_MCU_FLASHW_X);
 151        else if (strcmp9("SMCLK OFF", UString))
 152          return (CMD_SMCLK_STOP);
 153      break;
 154  
 155      case 10:
 156        if (strcmp10("RESET FPGA", UString))
 157          return (CMD_FPGA_RESET);
 158      break;
 159  
 160  /*
 161      case 11:
 162        if (strcmp10("FLASH E ALL", UString))
 163          return (CMD_MCU_FLASHD_ALL);
 164      break;
 165  */
 166      case 12:
 167        if (strcmp10("FLASH W FPGA", UString))
 168          return (CMD_MCU_FLASHW_FPGA);
 169        else if (strcmp10("FLASH E FPGA", UString))
 170          return (CMD_MCU_FLASHD_FPGA);
 171      break;
 172  
 173      case 15:
 174        if (strcmp15("PROG FPGA FLASH", UString))
 175          return (CMD_MCU_FLASHP_FPGA);
 176      break;
 177    }
 178  
 179    if ((CMDStrLen > 9) && strcmp6("FLASH ", UString) &&
 180        strcmp1(" ", UString+7) && strcmp1(" ", UString+9)) {
 181  
 182      switch (UString[6]) {
 183        case 'R':
 184          if (UString[8] == 'A') {      // vypis z adresy flash
 185            CMD_Long = str2long((unsigned char *)&UString[10]);
 186            return (CMD_MCU_FLASHR_ADR);
 187          }
 188          else if (UString[8] == 'P') { // vypis stranky flash
 189            CMD_Long = str2long((unsigned char *)&UString[10]);
 190            return (CMD_MCU_FLASHR_PAGE);
 191          }
 192          else if (UString[8] == 'B') { // vypis bloku flash
 193            CMD_Long = str2long((unsigned char *)&UString[10]);
 194            return (CMD_MCU_FLASHR_BLOCK);
 195          }
 196        break;
 197  /*
 198        case 'W':
 199          if (UString[8] == 'C') {      // zapis bytu do flash flash
 200            CMD_Char = UString[10];
 201            CMD_Long = str2long((unsigned char *)&UString[12]);
 202            return (CMD_MCU_FLASHW_C);
 203          }
 204        break;
 205  
 206        case 'E':
 207          if (UString[8] == 'A') {      // erase bytu flash
 208            CMD_Long = str2long((unsigned char *)&UString[10]);
 209            return (CMD_MCU_FLASHD_BYTE);
 210          }
 211          else if (UString[8] == 'P') { // erase stranky flash
 212            CMD_Long = str2long((unsigned char *)&UString[10]);
 213            return (CMD_MCU_FLASHD_PAGE);
 214          }
 215          else if (UString[8] == 'B') { // erase bloku flash
 216            CMD_Long = str2long((unsigned char *)&UString[10]);
 217            return (CMD_MCU_FLASHD_BLOCK);
 218          }
 219        break;
 220  */
 221      }
 222    }
 223  
 224    // No way...
 225    return (CMD_UNKNOWN);
 226  }
 227  
 228  
Zobrazeno: 731737x Naposledy: 29.11.2022 04:53:13