static void PtUpdateWmcuId (unsigned char broadcast) { /* update jamming data channel id */ if (broadcast) nRFAPI_SetTxMAC (broadcast_mac, sizeof (broadcast_mac)); else { jam_mac[sizeof (jam_mac) - 1] = env.e.mcu_id; nRFAPI_SetTxMAC (jam_mac, sizeof (jam_mac)); } /* update WMCU id for response channel */ wmcu_mac[sizeof (wmcu_mac) - 1] = env.e.mcu_id; nRFAPI_SetRxMAC (wmcu_mac, sizeof (wmcu_mac), 1); }
void ob_setNetID( unsigned char* nid ) { char i; for(i=0; i<NETID_SIZE; i++) { ob_int_mgmt.NetID[i]=nid[i]; } nRFAPI_SetTxMAC( ob_int_mgmt.NetID, NETID_SIZE); nRFAPI_SetRxMAC( ob_int_mgmt.NetID, NETID_SIZE, ob_int_mgmt.Pipes); }
unsigned char nRFAPI_Init( unsigned char channel, const unsigned char *mac, unsigned char mac_size, unsigned char features ) { unsigned char i; // init lower layer nRFCMD_Init(); // check validity if( mac_size<3 || mac_size>5 || !nRFAPI_DetectChip() ) return 0; // update mac nRFAPI_SetSizeMac(mac_size); nRFAPI_SetTxMAC(mac,mac_size); // enables pipe nRFAPI_SetRxMAC(mac,mac_size,0); nRFAPI_PipesEnable(ERX_P0); nRFAPI_PipesAck(0); // set payload sizes for(i=0; i<=5; i++) nRFAPI_SetPipeSizeRX(i,2); // set TX retry count nRFAPI_TxRetries(0); // set selected channel nRFAPI_SetChannel(channel); // set Tx power nRFAPI_SetTxPower(3); // flush FIFOs nRFAPI_FlushRX(); nRFAPI_FlushTX(); nRFAPI_SetRxMode(0); if(features != 0) nRFAPI_SetFeatures(features); return 1; }
uint8_t nRFAPI_Init (uint8_t channel, const uint8_t * mac, uint8_t mac_size, uint8_t features) { uint8_t i; // init IO layer of nRF24L01 nRFCMD_Init (); /* wait for nRF to boot */ pmu_sleep_ms(10); // check validity if (mac_size < 3 || mac_size > 5 || !nRFAPI_DetectChip ()) return 0; // update mac nRFAPI_SetSizeMac (mac_size); nRFAPI_SetTxMAC (mac, mac_size); // enables pipe nRFAPI_SetRxMAC (mac, mac_size, 0); nRFAPI_PipesEnable (ERX_P0); nRFAPI_PipesAck (0); // set payload sizes for (i = 0; i <= 5; i++) nRFAPI_SetPipeSizeRX (i, 16); // set TX retry count nRFAPI_TxRetries (0); // set selected channel nRFAPI_SetChannel (channel); // set Tx power nRFAPI_SetTxPower (3); // flush FIFOs nRFAPI_FlushRX (); nRFAPI_FlushTX (); if (features != 0) nRFAPI_SetFeatures (features); return 1; }
uint8_t nRFAPI_DetectChip (void) { uint8_t mac[NRF_MAX_MAC_SIZE], i; // blank read nRFAPI_GetStatus (); // set dummy MAC size nRFAPI_SetSizeMac (NRF_MIN_MAC_SIZE); // verify dummy MAC size if (nRFAPI_GetSizeMac () != NRF_MIN_MAC_SIZE) return 0; // set dummy MAC size nRFAPI_SetSizeMac (NRF_MAX_MAC_SIZE); // verify dummy MAC size if (nRFAPI_GetSizeMac () != NRF_MAX_MAC_SIZE) return 0; // set dummy MAC nRFAPI_SetTxMAC (rfbroadcast_mac, NRF_MAX_MAC_SIZE); // get dummy MAC memset (&mac, 0, sizeof (mac)); nRFAPI_GetTxMAC (mac, NRF_MAX_MAC_SIZE); // if can't verify written MAC - return with error for (i = 0; i < NRF_MAX_MAC_SIZE; i++) if (mac[i] != rfbroadcast_mac[i]) return 0; // everything is fine return 1; }