static void runTX(char c1, char c2, char c3, char c4) { // Initialize packet buffer of size PKTLEN + 1 uint8 txBuffer[PKTLEN+1] = {0}; P2SEL &= ~0x40; // P2SEL bit 6 (GDO0) set to one as default. Set to zero (I/O) // connect ISR function to GPIO0, interrupt on falling edge trxIsrConnect(GPIO_0, FALLING_EDGE, &radioRxTxISR); // enable interrupt from GPIO_0 trxEnableInt(GPIO_0); // create a random packet with PKTLEN + 2 byte packet counter + n x random bytes createPacket(txBuffer, c1, c2, c3, c4); // write packet to tx fifo cc11xLSpiWriteTxFifo(txBuffer,sizeof(txBuffer)); // strobe TX to send packet trxSpiCmdStrobe(CC110L_STX); // wait for interrupt that packet has been sent. // (Assumes the GPIO connected to the radioRxTxISR function is set // to GPIOx_CFG = 0x06) while(!packetSemaphore); // clear semaphore flag packetSemaphore = ISR_IDLE; halLedToggle(LED1); __delay_cycles(250000); halLedToggle(LED1); }
/****************************************************************************** * @fn runRX * * @brief puts radio in RX and waits for packets. Function assumes * that status bytes are appended in the RX_FIFO * Update packet counter and display for each packet received. * * @param none * * @return none */ void cc120xRunRX(void){ uint8 rxBuffer[128] = {0}; uint8 rxBytes; uint8 marcStatus; // Write radio registers registerConfig(); // Connect ISR function to GPIO0, interrupt on falling edge trxIsrConnect(&radioRxTxISR); // Enable interrupt from GPIO_0 trxEnableInt(); // Update LCD updateLcd(); // Set radio in RX trxSpiCmdStrobe(CC120X_SRX); // Loop until left button is pushed (exits application) while(BSP_KEY_LEFT != bspKeyPushed(BSP_KEY_ALL)){ // Wait for packet received interrupt if(packetSemaphore == ISR_ACTION_REQUIRED){ // Read number of bytes in rx fifo cc120xSpiReadReg(CC120X_NUM_RXBYTES, &rxBytes, 1); // Check that we have bytes in fifo if(rxBytes != 0){ // Read marcstate to check for RX FIFO error cc120xSpiReadReg(CC120X_MARCSTATE, &marcStatus, 1); // Mask out marcstate bits and check if we have a RX FIFO error if((marcStatus & 0x1F) == RX_FIFO_ERROR){ // Flush RX Fifo trxSpiCmdStrobe(CC120X_SFRX); } else{ // Read n bytes from rx fifo cc120xSpiReadRxFifo(rxBuffer, rxBytes); // Check CRC ok (CRC_OK: bit7 in second status byte) // This assumes status bytes are appended in RX_FIFO // (PKT_CFG1.APPEND_STATUS = 1.) // If CRC is disabled the CRC_OK field will read 1 if(rxBuffer[rxBytes-1] & 0x80){ // Update packet counter packetCounter++; } } } // Update LCD updateLcd(); // Reset packet semaphore packetSemaphore = ISR_IDLE; // Set radio back in RX trxSpiCmdStrobe(CC120X_SRX); } } // Reset packet counter packetCounter = 0; // Put radio to sleep and exit application trxSpiCmdStrobe(CC120X_SPWD); }