• Main Page
  • Modules
  • Index
  • File List
  • Globals

projects/nrfgo_sdk/gazell_examples/gzll_host_w_dynamic_pairing/main.c

Go to the documentation of this file.
00001 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is confidential property of Nordic 
00004  * Semiconductor ASA.Terms and conditions of usage are described in detail 
00005  * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 
00006  *
00007  * Licensees are granted free, non-transferable use of the information. NO
00008  * WARRENTY of ANY KIND is provided. This heading must NOT be removed from
00009  * the file.
00010  *              
00011  * $LastChangedRevision: 133 $
00012  */
00013 
00032 //lint -e534
00033 //lint -e830
00034 
00035 #include "gzll_mcu.h"
00036 #include "gzll.h"
00037 #include "gzp.h"
00038 
00039 #ifdef GZP_CRYPT_DISABLE
00040 #error This example project uses gzp_crypt, please remove the definition "GZP_CRYPT_DISABLE".
00041 #endif
00042 
00043 void main(void)
00044 {
00045   uint8_t payload[GZLL_MAX_PAYLOAD_LENGTH];
00046 
00047   mcu_init();
00048   gzll_init();
00049   gzp_init();
00050   gzp_pairing_enable(true);
00051 
00052   // Open pipe 2. (Pipe 0 and 1 are reserved by pairing library).
00053   gzll_set_param(GZLL_PARAM_RX_PIPES, gzll_get_param(GZLL_PARAM_RX_PIPES) | (1 << 2));
00054   
00055   // Set P0 as output
00056   P0DIR = 0;                                          
00057 
00058   EA = 1;
00059 
00060   // Enter host mode (start monitoring for data)
00061   gzll_rx_start();                                          
00062   
00063   for(;;)
00064   { 
00065     // If gzpair_host_execute() returns true, a pairing request has been received
00066     gzp_host_execute();
00067 
00068     // If Host ID request received
00069     if(gzp_id_req_received())
00070     {
00071       // Always grant request
00072       gzp_id_req_grant();
00073     }
00074    
00075     // If any data received (plaintext on pipe 2 or encrypted through Gazell pairing library)
00076     if((gzll_get_rx_data_ready_pipe_number() == 2) || (gzp_crypt_user_data_received()))
00077     {
00078       // Plaintext data received? 
00079       if(gzll_rx_fifo_read(payload, NULL, NULL))
00080       {
00081         // Write received payload[0] to port 0
00082         P0 = payload[0];
00083       }
00084       else
00085       {
00086         // Read data from Gazell pairing library
00087         gzp_crypt_user_data_read(payload, NULL);
00088         // Write received payload[0] to port 0
00089         P0 = payload[0];
00090       }
00091     }   
00092   }          
00093 }
00094 

Generated on Fri Apr 20 2012 14:11:45 for nRFGo SDK by  doxygen 1.7.2