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 cc1120cc1190IdleRx * * @brief Radio state is switched from Idle to RX. Function assumes that * radio is in IDLE when called. * * input parameters * * @param none * * output parameters * * @return void */ static void cc1120cc1190IdleRx(void) { trxClearIntFlag(); //perCC1190HgmEnable(); perCC1120CC1190PaDisable(); perCC1120CC1190LnaEnable(); trxSpiCmdStrobe(CC112X_SRX); trxEnableInt(); return; }
/****************************************************************************** * @fn perCC1120CC1190SendPacket * * @brief Sends the contents that pData points to which has the * following structure: * * txArray[0] = length byte * txArray[n] = payload[n] * | n<[sizeOf(RXFIFO)-2], variable packet length is assumed. * * The radio state after completing TX is dependant on the * CC112X_RFEND_CFG0 register setting. For PG10 this register * dictates IDLE after TX. For PG.0 this function must be * re-implemented since the 2way PER test relies on RX after TX. * This function enables SYNC interrupt. This means that * an interrupt will fire when a packet has been sent, i.e sync * signal transitions from high to low. * * The One-Way PER test disables the sync pin interrupt when TX * finishes, while the Two-Way PER test doesn't to enable quick * reception of Slave ACK. * * Note: Assumes chip is ready * * input parameters * * @param *pData - pointer to data array that starts with length byte * and followed by payload. * output parameters * * @return void */ void perCC1120CC1190SendPacket(uint8 *pData) { uint8 len = *pData; /* PG1.0 errate fix: Before entering TX, the frequency word must be altered from that of RX */ /* This means in general that TX from Idle is the only option, not TX from RX */ perCC1120CC1190EnterIdle(); /* Will only try to transmit if the whole packet can fit i RXFIFO * and we're not currently sending a packet. */ if(!(len > (PER_MAX_DATA-2)) && (cc1120cc1190RadioTxRx != CC112X_STATE_TX) ) { cc112xSpiWriteTxFifo(pData,(len+1)); /* Indicate state to the ISR and issue the TX strobe */ trxEnableInt(); /* Enable PA on CC1190 and be sure LNA is off */ //perCC1190HgmEnable(); perCC1120CC1190LnaDisable(); perCC1120CC1190PaEnable(); cc1120cc1190RadioTxRx = CC112X_STATE_TX; trxSpiCmdStrobe(CC112X_STX); /* Wait until packet is sent before doing anything else */ __low_power_mode_3(); /* This function will not return before the complete packet * is sent and the radio is back in IDLE. The MSP will be * be sleeping while the packet is beeing sent unless waken * by button presses. */ while(cc1120cc1190RadioTxRx == CC112X_STATE_TX); if(perSettings.linkTopology == LINK_1_WAY) { /* Back in Idle*/ trxDisableInt(); /* Turn off PA on CC1190 */ perCC1120CC1190PaDisable(); } } return; }
/****************************************************************************** * @fn perCC115LSendPacket * * @brief Sends the contents that pData points to. pData has the * following structure: * * txArray[0] = length byte * txArray[n] = payload[n] * | n<[sizeOf(RXFIFO)-2], variable packet length is assumed. * * The radio state after completing TX is dependant on the * MCSM1 register setting. This function enables SYNC interrupt. * This means that an interrupt will go off when a packet * has been sent, i.e sync signal transitions from high to low. * MSP will be in low power mode until packet has been sent given * that no other interrupts go off. * * The One-Way PER test disables the sync pin interrupt when TX * finishes, while the Two-Way PER test doesn't to enable quick * reception of Slave ACK. * * Note: Assumes chip is ready * * input parameters * * @param *pData - pointer to data array that starts with length byte * and followed by payload. * output parameters * * @return void */ void perCC115LSendPacket(uint8 *pData) { uint8 len = *pData; /* Will only try to transmit if the whole packet can fit i TXFIFO * and we're not currently sending a packet. */ if(!(len > (PER_MAX_DATA-2)) && (cc115LRadioTxIdle != CC115L_STATE_TX) ) { cc11xLSpiWriteTxFifo(pData,(len+1)); /* Indicate state to the ISR and issue the TX strobe */ trxEnableInt(); cc115LRadioTxIdle = CC115L_STATE_TX; trxSpiCmdStrobe(CC115L_STX); /* Wait until packet is sent before doing anything else */ __low_power_mode_3(); while(cc115LRadioTxIdle == CC115L_STATE_TX); if(perSettings.linkTopology == LINK_1_WAY) { /* Back in Idle*/ trxDisableInt(); } } return; }
/****************************************************************************** * @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); }