Čeština / English
Login

SVN Repository / Prohlížení

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

terminal.c

   1  /*******************************************************************************
   2     terminal.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       Realizace TERMINAL modu.
  44  *******************************************************************************/
  45  
  46  /* Provedena revize */
  47  
  48  #include <stdio.h>
  49  #include <stdlib.h>
  50  #include <string.h>
  51  #include "arch_specific.h"
  52  #include "define.h"
  53  #include "timer_b.h"
  54  #include "globfun.h"
  55  #include "uart.h"
  56  #include "cmd.h"
  57  
  58  //#include "xmodem.h"
  59  #include "filetransfer.h"
  60  
  61  #include "flash.h"
  62  #include "flash_fpga.h"
  63  #include "terminal.h"
  64  #include "fitkitlib.h"
  65  #include "fpga.h"
  66  #include "spi.h"
  67  
  68  
  69  
  70  
  71  /**
  72  
  73   **/
  74  void terminal_init(void) {
  75    term_cmd_clear();
  76  
  77    serial_init();                // inicializace RS232 0
  78  
  79    /// vymazani obrazovky terminalu
  80    term_send_esc_seq("[2J");
  81  
  82    //RS232_SendESCString("[1;34;47m");
  83    term_send_esc_seq("[4m");
  84    term_send_str_crlf(ID_KIT_STRING);
  85    //RS232_SendESCString("[0;30;47m");INIT_HW_MCU
  86    term_send_esc_seq("[24m");
  87    term_send_crlf();
  88  }
  89  
  90  /**
  91  
  92   **/
  93  void terminal_idle_cb(void (*before_prog_cb)(void)) {
  94    char int_swp;
  95    char cmdustr[CMDStrLen+1];
  96    unsigned ij;
  97  
  98    // osetreni terminalu
  99    WDG_reset();
 100    if (term_cmd_read() != 0) {  // cteni prikazu
 101  
 102      strupper(cmdustr, CMDStr);
 103      Cmd = term_cmd_decode(cmdustr);  // dekodovani prikazu
 104  
 105      if (Cmd == CMD_NULL)
 106        Cmd = Cmd_Old;                // vyvolani predchoziho prikazu
 107  
 108      Cmd_Old = Cmd;                  // uchovani prikazu
 109  
 110      switch (Cmd) {
 111        case CMD_NULL:                // NEBYLO NIC ZADANO
 112        break;
 113        /*
 114        case CMD_UNKNOWN:            // NEZNAMY PRIKAZ
 115          RS232_SendString(" Neznamy prikaz");
 116          Cmd_Old = CMD_NULL;
 117        break;
 118        */
 119        case CMD_HELP:               // HELP
 120          term_send_str_crlf("Napoveda:");
 121          term_send_crlf();
 122          term_send_str_crlf(" PROG FPGA........programovani z pc (XModem)");
 123          term_send_str_crlf(" PROG FPGA FLASH..programovani FPGA z flash");
 124          term_send_crlf();
 125          term_send_str_crlf(" RESET MCU....software reset MCU");
 126          term_send_str_crlf(" RESET FPGA...software reset FPGA");
 127          term_send_str_crlf(" CLS..........reset terminalu");
 128          term_send_crlf();
 129  /*
 130          term_send_str_crlf(" FLASH W C chr adr...zapis znaku 'chr' dat do flash na adresu 'adr'");
 131          term_send_str_crlf(" FLASH W X adr...zapis dat do flash na adresu 'adr' (XModem)");
 132  */
 133          term_send_str_crlf(" FLASH W FPGA.....zapis FPGA dat z PC do flash (XModem)");
 134          term_send_str_crlf(" FLASH W X........zapis dat do flash na adresu 'adr' (XModem)");
 135          term_send_str_crlf(" FLASH R A adr....vypis 64Bytu flash z adresy 'adr'");
 136          term_send_str_crlf(" FLASH R P page...vypis stranky c. 'page' flash");
 137          term_send_str_crlf(" FLASH R B block..vypis bloku c. 'block' flash");
 138          term_send_str_crlf(" FLASH R S........vypis status registru flash");
 139          term_send_str_crlf(" FLASH E FPGA.....odstraneni FPGA dat z flash");
 140  /*
 141          term_send_str_crlf(" FLASH E A adr....smazani bytu ve flash na adrese 'adr'");
 142          term_send_str_crlf(" FLASH E P page...smazani stranky 'page' flash");
 143          term_send_str_crlf(" FLASH E B block..smazani bloku 'block' flash");
 144          term_send_str_crlf(" FLASH E ALL......smazani cele flash"); */
 145          term_send_crlf();
 146          term_send_str_crlf(" RAM D....dump RAM Memory");
 147          term_send_crlf();
 148          /*
 149          term_send_str_crlf(" FPGA R B adr....vypis bytu z fpga z adresy 'adr'");
 150          term_send_str_crlf(" FPGA R W adr....vypis wordu z fpga z adresy 'adr'");
 151          term_send_str_crlf(" FPGA W B adr byte....zapis bytu do fpga na adresu 'adr'");
 152          term_send_str_crlf(" FPGA W W adr world....zapis wordu do fpga na adresu 'adr'");
 153          */
 154          term_send_str_crlf("Uzivatelska napoveda:");
 155          print_user_help();
 156        break;
 157        case CMD_MCU_RAM_DUMP: {
 158          unsigned char *ptr = (unsigned char *)MCU_RAM_START - 8;
 159  
 160          term_send_hex((unsigned int)ptr-8);
 161          term_send_str(" : ");
 162          for (; ((unsigned int)ptr % 16) == 0; ptr++) {
 163  
 164            WDG_reset();
 165  
 166            term_send_char_hex(0);
 167          }
 168          for (; ptr <= (unsigned char *)MCU_RAM_END; ptr++) {
 169  
 170            WDG_reset();
 171  
 172            term_send_char_hex(*ptr);
 173            term_send_char(' ');
 174            if (((unsigned int)ptr % 16) == 0) {
 175              term_send_crlf();
 176              term_send_hex((unsigned int)ptr);
 177              term_send_str(" : ");
 178            }
 179          }
 180        }
 181        break;
 182        case CMD_MCU_PROG_FPGAI:      // NAPROGRAMOVANI FPGA  z PC
 183          if (before_prog_cb != NULL)
 184            before_prog_cb(); //callback
 185          int_swp = P1IE; //  = MCU_INTERRUP_PINS;
 186          P1IE = 0;    // disable interrupt
 187          fpga_configure_from_mcu();
 188          P1IE = int_swp;  // enable interrupt
 189        break;
 190        case CMD_MCU_RESET:           // RESET MCU
 191          _DINT();                               // zakaz preruseni
 192          /*
 193          WDTCTL = WDTPW + WDTCNTCL + WDTIS0;    // povoleni software watchdog
 194          for (;;) {
 195            tii++;                    // nekonecny cyklus, dokud watchdog nezresetuje MCU
 196          }
 197          */
 198          /* vyvolany reset, pokud se zapisuje do WDTCTL bez WDTPW,
 199             i kdyz neni povoleny watchdog */
 200          WDTCTL = WDTCNTCL + WDTIS0;
 201        break;                        // RESET FPGA
 202        case CMD_FPGA_RESET:
 203          FPGA_reset();
 204        break;
 205        case CMD_CLEARSCREEN:         // CLS (terminal reset)
 206          term_send_esc_seq("[2J");
 207        break;
 208        case CMD_MCU_FLASHW_FPGA:     // ZAPSANI FPGA DAT SpartanIII do Flash
 209          #ifdef XMODEMAPI
 210          FLASH_WriteFile(FLASH_FPGA_BIN_PAGE);
 211          #else
 212          FLASH_WriteFile(FLASH_FPGA_BIN_PAGE,"FPGA configuration","*.bin", FPGA_BIN_PAGES);
 213          #endif
 214        break;
 215  /*      case CMD_MCU_FLASHW_C:        // ZAPSANI BYTE DO FLASH
 216          FLASH_WriteByte(CMD_Long, CMD_Char);
 217        break;
 218  */
 219        case CMD_MCU_FLASHW_X:        // ZAPSANI DAT Z PC DO FLASH
 220          #ifdef XMODEMAPI
 221          FLASH_WriteFile(FLASH_USER_DATA_PAGE);
 222          #else
 223          FLASH_WriteFile(FLASH_USER_DATA_PAGE,0,0,0);
 224          #endif
 225        break;
 226        case CMD_MCU_FLASHP_FPGA:     // PROGRAMOVANI FPGA SpartanIII z FLASH
 227          //char int_swp;
 228          if (before_prog_cb != NULL)
 229            before_prog_cb(); //callback
 230          int_swp = P1IE;//  = MCU_INTERRUP_PINS;      //
 231          P1IE = 0;   // disable interrupt
 232          fpga_configure_from_flash();
 233          P1IE = int_swp;
 234         break;
 235        case CMD_MCU_FLASHR_ADR:      // VYPIS casti flash pameti
 236        case CMD_MCU_FLASHR_PAGE:
 237        case CMD_MCU_FLASHR_BLOCK:
 238          switch (Cmd) {
 239            case CMD_MCU_FLASHR_ADR:
 240              FLASH_Dump_Adr(CMD_Long, 64);
 241            break;
 242            case CMD_MCU_FLASHR_PAGE:
 243              FLASH_Dump_Page(CMD_Long);
 244            break;
 245            case CMD_MCU_FLASHR_BLOCK:
 246              FLASH_Dump_Block(CMD_Long);
 247            break;
 248            default:
 249            break;
 250          }
 251  
 252          // zvetsim automaticky CMD_Long pro opakovani prikazu
 253          if ((Cmd_Old == CMD_MCU_FLASHR_PAGE) || (Cmd_Old == CMD_MCU_FLASHR_BLOCK))
 254            CMD_Long++;
 255          else if (Cmd_Old == CMD_MCU_FLASHR_ADR)
 256            CMD_Long += 64;
 257        break;
 258  
 259        case CMD_MCU_FLASHD_FPGA:     // ODSTRANENI DAT FPGA z FLASH
 260          term_send_str("Mazani dat FPGA ve Flash");
 261          FLASH_WriteByte(128,0);
 262          for (ij = 0; ij < FPGA_BIN_PAGES; ij++) {
 263            FLASH_ErasePage(FLASH_FPGA_BIN_PAGE + ij);
 264            WDG_reset();
 265          }
 266          term_send_crlf();
 267        break;
 268  /*
 269        case CMD_MCU_FLASHD_BYTE:     // SMAZANI jednoho bytu flash pameti
 270          term_send_str("Mazani bytu ve flash na adrese: 0x");
 271          term_send_hex(CMD_Long);
 272          FLASH_EraseByte(CMD_Long);
 273          term_send_crlf();
 274        break;
 275  
 276        case CMD_MCU_FLASHD_PAGE:     // SMAZANI jedne stranky flash pameti
 277        case CMD_MCU_FLASHD_BLOCK:
 278        case CMD_MCU_FLASHD_ALL:
 279          // smazani casti flash
 280          switch (Cmd) {
 281            case CMD_MCU_FLASHD_PAGE:
 282              term_send_str("Mazani flash na strance: ");
 283              term_send_num(CMD_Long);
 284              FLASH_ErasePage(CMD_Long);
 285              term_send_crlf();
 286            break;
 287            case CMD_MCU_FLASHD_BLOCK:
 288              term_send_str("Mazani bloku flash: ");
 289              term_send_num(CMD_Long);
 290              FLASH_EraseBlock(CMD_Long);
 291              term_send_crlf();
 292            break;
 293            case CMD_MCU_FLASHD_ALL:
 294              term_send_str_crlf("Mazani cele flash.");
 295              FLASH_EraseAll();
 296              term_send_crlf();
 297            break;
 298            default :
 299            break;
 300          }
 301        break;
 302  */
 303        case CMD_MCU_FLASHR_STATUS:   // VYPIS status registru flash pameti
 304          FLASH_print_status();
 305        break;
 306  
 307        case CMD_SMCLK_STOP:
 308          smclk_stop();
 309        break;
 310  
 311        default:
 312          if (decode_user_cmd(cmdustr, CMDStr) != USER_COMMAND) {
 313            term_send_str("Neznamy prikaz: ");
 314            term_send_char('\'');
 315            term_send_str(CMDStr);
 316            term_send_char('\'');
 317          }
 318        break;
 319      } // switch
 320      term_send_crlf();
 321      term_send_str(">");
 322      term_cmd_clear();
 323    }  // if
 324  }
 325  
 326  /**
 327  
 328   **/
 329  void terminal_idle(void) {
 330    terminal_idle_cb(NULL);
 331  }
 332  
 333  
Zobrazeno: 731767x Naposledy: 29.11.2022 06:41:25