Čeština / English
Login

SVN Repository / Prohlížení

Aktuální adresář: FITkit / trunk / apps / modul_nrf / 01_client / mcu /

main.c

   1  /*******************************************************************************
   2     main.c: PING client
   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  
  46  #include <fitkitlib.h>
  47  #include <nrf24l01/nrf24l01.h>
  48  
  49  /*******************************************************************************
  50   * Vypis uzivatelske napovedy (funkce se vola pri vykonavani prikazu "help")
  51   * systemoveho helpu
  52  *******************************************************************************/
  53  void print_user_help(void)
  54  {
  55    term_send_str_crlf("RF PING client");
  56  }
  57  
  58  
  59  /*******************************************************************************
  60   * Dekodovani a vykonani uzivatelskych prikazu
  61  *******************************************************************************/
  62  unsigned char decode_user_cmd(char *cmd_ucase, char *cmd)
  63  {
  64    return USER_COMMAND;
  65  }
  66  
  67  
  68  /*******************************************************************************
  69   * Inicializace periferii/komponent po naprogramovani FPGA
  70  *******************************************************************************/
  71  void fpga_initialized()
  72  {
  73     term_send_str("NRF init ... ");
  74     if (NRF24L01_init() == 1) {
  75        term_send_str_crlf("OK");
  76  
  77        NRF_config(24, 1, "cli01", 0);
  78        term_send_str_crlf("Listening ...");
  79  
  80     } else {
  81        term_send_str_crlf("FAILED");
  82     }
  83  }
  84  
  85  /*******************************************************************************
  86   * Hlavni funkce
  87  *******************************************************************************/
  88  int main(void)
  89  {
  90    unsigned char data, ttl, dch = 0;
  91  
  92    initialize_hardware();
  93  
  94    set_led_d5(0);
  95    set_led_d6(0);
  96  
  97    NRF_setTXAddress("srv01");
  98    while (1) {
  99  
 100        term_send_str("send byte ...");
 101  
 102        NRF_sendByte(48 + dch);
 103        dch = (dch + 1) % 10;
 104  
 105        while (NRF_isSending()) {
 106           delay_ms(250);
 107           term_send_char('.');
 108        }
 109  
 110        term_send_str(", wait for response ...");
 111  
 112        ttl = 4;
 113        while ((!NRF_dataReady()) && ttl) {
 114           delay_ms(250);
 115           term_send_char('.');
 116           ttl--;
 117        }
 118  
 119        if (ttl) {
 120           data = NRF_getByte();
 121           term_send_hex(data);
 122           term_send_crlf();
 123        } else {
 124           term_send_str_crlf(" timeout");
 125        }
 126        terminal_idle();                       // obsluha terminalu
 127    }
 128  }
 129  
Zobrazeno: 665616x Naposledy: 23.5.2022 01:04:35