unsigned char recvBeacon( ob_data* block ) { unsigned long crc; unsigned char ret=0, status; ob_switchRXMode(); if((AT91F_PIO_GetInput(AT91C_BASE_PIOA)&IRQ_PIN)==0) { portENTER_CRITICAL(); status=nRFAPI_GetStatus(); if(status&MASK_RX_DR_FLAG ) { ret=nRFAPI_RX((unsigned char*)block, sizeof(ob_data) ); if(ret>0) { // CRC Check crc = env_crc16(block->payload, sizeof(block->payload) ); if(block->crc == swapshort(crc)) { increment(ob_int_mgmt.rx_beacons, 4); } else { increment(ob_int_mgmt.fail_rx_beacons, 4); ret=0; } } nRFAPI_FlushRX(); } nRFAPI_ClearIRQ(status); portEXIT_CRITICAL (); } return ret; }
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; }
unsigned char nRFAPI_RX(unsigned char *buf,unsigned char count) { unsigned char size,pipe; pipe=nRFAPI_GetPipeCurrent(); if(pipe>=7) size=0; else { size=nRFAPI_GetPipeSizeRX(pipe); if(size<=count) nRFCMD_RegReadBuf(RD_RX_PLOAD,buf,size); else { nRFAPI_FlushRX(); size=0; } } return size; }
uint8_t nRFAPI_RX (uint8_t * buf, uint8_t count) { uint8_t size, pipe; pipe = nRFAPI_GetPipeCurrent (); if (pipe >= 7) size = 0; else { size = nRFAPI_GetPipeSizeRX (pipe); if (size <= count) nRFCMD_RegReadBuf (RD_RX_PLOAD, buf, size); else { nRFAPI_FlushRX (); size = 0; } } return size; }