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

projects/nrfgo_sdk/gazell_examples/gzll_device_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: 184 $
00012  */
00013 
00041 //lint -e644
00042 //lint -e830
00043 //lint -e534
00044 
00045 #include "gzll_mcu.h"
00046 #include "gzll.h"
00047 #include "gzp.h"
00048 
00049 #ifdef GZP_CRYPT_DISABLE
00050 #error This example project uses gzp_crypt, please remove the definition "GZP_CRYPT_DISABLE".
00051 #endif
00052 
00053 void main(void)
00054 {
00055   bool send_crypt_data = false;
00056   bool tx_success = false;
00057   gzp_id_req_res_t id_req_status;
00058   uint8_t payload[GZLL_MAX_PAYLOAD_LENGTH];
00059   
00060   mcu_init();
00061   
00062   // Initialize Gazell Link Layer
00063   gzll_init();
00064   
00065   // Initialize Gazell Pairing Library
00066   gzp_init();
00067 
00068   EA = 1;
00069 
00070   for(;;)
00071   {      
00072     payload[0] = ~P0;
00073     
00074     // Send every other packet as encrypted data  
00075     
00076     if(send_crypt_data)
00077     {
00078       // Send encrypted packet using the Gazell pairing library
00079       tx_success = gzp_crypt_data_send(payload, GZP_ENCRYPTED_USER_DATA_MAX_LENGTH);
00080     }
00081 
00082     else
00083     
00084     {
00085       // Send packet as plaintext on pipe 2
00086       gzll_tx_data(payload, GZLL_MAX_FW_PAYLOAD_LENGTH, 2);   
00087       while(gzll_get_state() != GZLL_IDLE){
00088       }
00089       tx_success = gzll_tx_success();
00090     }
00091     send_crypt_data = !send_crypt_data;
00092 
00093     // If data transfer failed
00094     if(!tx_success)
00095     {
00096       // Send "system address request". Needed for sending any user data to Host.
00097       gzp_address_req_send();
00098       
00099       // Send "Host ID request". Needed for sending encrypted user data to host.
00100       id_req_status = gzp_id_req_send();
00101     }
00102 
00103     // If waiting for Host to grant or reject ID request
00104     if(id_req_status == GZP_ID_RESP_PENDING)
00105     {
00106       // Send new ID request for fetching response
00107       id_req_status = gzp_id_req_send();
00108     }
00109   }  
00110 }
00111 

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