Čeština / English
Login

SVN Repository / Prohlížení

Aktuální adresář: FITkit / trunk / apps / demo / bram / mcu /

main.c

   1  /*******************************************************************************
   2     main.c: main for blockram demo application
   3     Copyright (C) 2009 Brno University of Technology,
   4                        Faculty of Information Technology
   5     Author(s): Zdenek Vasicek <vasicek AT fit.vutbr.cz>
   6  
   7     LICENSE TERMS
   8  
   9     Redistribution and use in source and binary forms, with or without
  10     modification, are permitted provided that the following conditions
  11     are met:
  12     1. Redistributions of source code must retain the above copyright
  13        notice, this list of conditions and the following disclaimer.
  14     2. Redistributions in binary form must reproduce the above copyright
  15        notice, this list of conditions and the following disclaimer in
  16        the documentation and/or other materials provided with the
  17        distribution.
  18     3. All advertising materials mentioning features or use of this software
  19        or firmware must display the following acknowledgement:
  20  
  21          This product includes software developed by the University of
  22          Technology, Faculty of Information Technology, Brno and its
  23          contributors.
  24  
  25     4. Neither the name of the Company nor the names of its contributors
  26        may be used to endorse or promote products derived from this
  27        software without specific prior written permission.
  28  
  29     This software or firmware is provided ``as is'', and any express or implied
  30     warranties, including, but not limited to, the implied warranties of
  31     merchantability and fitness for a particular purpose are disclaimed.
  32     In no event shall the company or contributors be liable for any
  33     direct, indirect, incidental, special, exemplary, or consequential
  34     damages (including, but not limited to, procurement of substitute
  35     goods or services; loss of use, data, or profits; or business
  36     interruption) however caused and on any theory of liability, whether
  37     in contract, strict liability, or tort (including negligence or
  38     otherwise) arising in any way out of the use of this software, even
  39     if advised of the possibility of such damage.
  40  
  41     $Id$
  42  
  43  *******************************************************************************/
  44  
  45  #include <fitkitlib.h>
  46  
  47  #define BRAM_BASE 0
  48  
  49  
  50  /*******************************************************************************
  51   * Vypis uzivatelske napovedy (funkce se vola pri vykonavani prikazu "help")
  52  *******************************************************************************/
  53  void print_user_help(void)
  54  {
  55    term_send_str_crlf(" BRAM CLEAR ...... vynuluje obsah pameti BRAM");
  56    term_send_str_crlf(" BRAM READ  ...... cteni obsahu pameti BRAM");
  57    term_send_str_crlf(" BRAM WRITE ...... zapis hodnot do pameti BRAM");
  58  }
  59  
  60  
  61  /*******************************************************************************
  62   * Dekodovani uzivatelskych prikazu a jejich vykonavani
  63  *******************************************************************************/
  64  unsigned char decode_user_cmd(char *cmd_ucase, char *cmd)
  65  {
  66    unsigned short ofs, val, cnt;
  67  
  68    if (strcmp10(cmd_ucase, "BRAM CLEAR"))
  69    {
  70      for (ofs=0; ofs < 1024; ofs++)
  71      {
  72        val = 0;
  73        //zapis 16 bitove hodnoty val na adresu BRAM_BASE + offset ofs
  74        FPGA_SPI_RW_AN_DN(SPI_FPGA_ENABLE_WRITE, BRAM_BASE+ofs, (unsigned char *)&val, 2, 2);
  75      }
  76    }
  77    else if (strcmp10(cmd_ucase, "BRAM WRITE"))
  78    {
  79      for (ofs=0; ofs < 1024; ofs++)
  80      {
  81        val = ofs;
  82        //zapis 16 bitove hodnoty val na adresu BRAM_BASE + offset ofs
  83        FPGA_SPI_RW_AN_DN(SPI_FPGA_ENABLE_WRITE, BRAM_BASE+ofs, (unsigned char *)&val, 2, 2);
  84      }
  85    }
  86    else if (strcmp9(cmd_ucase, "BRAM READ"))
  87    {
  88      cnt = 8;
  89      for (ofs=0; ofs < 1024; ofs++)
  90      {
  91        if (cnt==8)
  92        {
  93          term_send_crlf();
  94          term_send_char(' ');
  95          cnt=0;
  96        }
  97        cnt++;
  98  
  99        //cteni 16 bitove hodnoty z adresy BRAM_BASE + offset ofs
 100        FPGA_SPI_RW_AN_DN(SPI_FPGA_ENABLE_READ, BRAM_BASE+ofs, (unsigned char *)&val, 2, 2);
 101        term_send_hex(val);
 102        term_send_char(' ');
 103      }
 104    }
 105    else
 106    {
 107      return (CMD_UNKNOWN);
 108    }
 109    return (USER_COMMAND);
 110  }
 111  
 112  
 113  
 114  /*******************************************************************************
 115   * Inicializace periferii/komponent po naprogramovani FPGA
 116  *******************************************************************************/
 117  void fpga_initialized()
 118  {
 119  }
 120  
 121  
 122  /*******************************************************************************
 123   * Hlavni funkce
 124  *******************************************************************************/
 125  //INLINE INT INIT_MCU(VOID)
 126  int main(void)
 127  {
 128    unsigned int counter = 0;
 129  
 130    initialize_hardware();
 131  
 132    set_led_d6(1);  // rozsviceni D6
 133    set_led_d5(1);  // rozsviceni D5
 134  
 135    while (1)
 136    {
 137      delay_ms(1);  //zpozdeni 1ms
 138  
 139      counter++;
 140      if (counter == 500)
 141      {
 142        flip_led_d6(); //invertovat LED
 143        counter = 0;
 144      }
 145  
 146      terminal_idle();  // obsluha terminalu
 147    }
 148  
 149  }
 150  
Zobrazeno: 595867x Naposledy: 22.1.2022 10:20:32