/** * NTRXTxEnd: * * NTRXTxEnd() finish transmission and reset internal state. * * Returns: none * */ void NTRXTxEnd (void) { MyByte8T maxArqCount; /* * get number of transmissions needed to last message */ NTRXGetRegister (NA_TxArqCnt, &ntrxArqCount); maxArqCount = NTRXGetTxARQmax(); if ((ntrxArqCount > maxArqCount) && (ntrxState == TxWAIT)) { rcwd++; txIrq &= ~(TxEND); ntrxState = TxIDLE; if (ntrxCal != 0) { # ifdef CONFIG_NTRX_AUTO_RECALIB tiRecal = hwclock() + calDelay; # endif NTRXAllCalibration (); rcwd = 0; # ifdef CONFIG_RECALIB_LED TRIGGER_LED3(); # endif /* CONFIG_RECALIB_LED */ } lState = RANGING_READY; # ifdef CONFIG_TRAFFIC_LED TRIGGER_LED2(); # endif /* CONFIG_TRAFFIC_LED */ }else{ txIrq &= ~(TxEND); ntrxState = TxIDLE; if (lState != RANGING_READY) { RangingCallback_Ack(ntrxArqCount); lState = RANGING_ANSWER1; } } }
void PDSap (MyMsgT *msg) /****************************************************************************/ { MyByte8T txLen[2]; static MyAddressT cacheAddr; /* * check the message length. If the message length is bigger than * the allowed buffer size the packet will be rejected. */ if (msg->len > PHY_PACKET_SIZE) { msg->prim = PD_DATA_CONFIRM; msg->status = PHY_BUSY_TX; SendMsgUp (msg); return; } switch(msg->prim) { case PD_DATA_REQUEST : /* transmitter still busy */ if (txSendMsg != NULL) { msg->prim = PD_DATA_CONFIRM; msg->status = PHY_BUSY_TX; SendMsgUp (msg); return; } /* * there is no break here !!! * This is intentional and not a mistake. */ case PD_RANGING_ANSWER1_EXECUTE : case PD_RANGING_ANSWER2_EXECUTE : case PD_RANGING_REQUEST_EXECUTE : case PD_RANGING_FAST_REQUEST_EXECUTE : case PD_RANGING_FAST_ANSWER1_EXECUTE : # ifdef CONFIG_NTRX_AUTO_RECALIB if (phyPIB.recalInterval != 0) { if( tiRecal < hwclock() ) { /* INFO: If the TRX sends a packet, calibration failes! * In this case rcwd is not reset, but tiRecal is. */ /* normal operation mode */ if (phyPIB.testmode == 0) { if (NTRXAllCalibration ()) { tiRecal = hwclock() + phyPIB.recalInterval; rcwd = 0; TRIGGER_LED_CAL(); } } } } # endif /* CONFIG_NTRX_AUTO_RECALIB */ /* check which buffer is free to transmit data */ if (buffSwapped ==TRUE) { /* write user data to transmit buffer in ntrx chip */ NTRXSetIndexReg (2); NTRXSPIWrite ((MyByte8T)(NA_RamTxBuffer_O & 0xff), msg->data, (MyByte8T)(msg->len & 0xff)); }else { /* write user data to transmit buffer in ntrx chip */ NTRXSetIndexReg (3); NTRXSPIWrite ((MyByte8T)(NA_RamTxBuffer_O & 0xff), msg->data, (MyByte8T)(msg->len & 0xff)); } NTRXSetIndexReg (0); /* copy the destination address to temp buffer */ if (memcmp (cacheAddr, msg->addr, 6) != 0) { memcpy (cacheAddr, msg->addr, 6); NTRXSPIWrite (NA_RamTxDstAddr_O, cacheAddr, 6); } /* merge the three bits into the temp buffer */ txLen[0] = msg->len; // txLen[1] = (len & 0x1F00) >> 8; txLen[1] = (lState & 0x01) ? 0x20 : 0; txLen[1] |= (lState & 0x02) ? 0x40 : 0; txLen[1] |= (lState & 0x04) ? 0x80 : 0; NTRXSPIWrite (NA_RamTxLength_O, txLen, 2); ntrxState = TxSEND; /* mark buffers as valid and start transmission */ NTRXSPIWriteByte (NA_TxBufferCmd_O, (1 << NA_TxCmdStart_B) | (0x03 << NA_TxBufferCmd_LSB)); TRIGGER_LED_TX(); txSendMsg = msg; break; case PD_RANGING_REQUEST : case PD_RANGING_FAST_REQUEST : /* transmitter still busy */ rangingPIB.distance = -1.0; rangingPIB.error = STAT_NO_ERROR; if (txSendMsg != NULL) { msg->prim = PD_RANGING_CONFIRM; msg->status = PHY_BUSY_TX; memcpy(msg->data, (MyByte8T*) &rangingPIB, sizeof(RangingPIB)); msg->len = sizeof(RangingPIB); SendMsgUp (msg); return; } if (lState != RANGING_READY) { txSendMsg = NULL; msg->prim = PD_RANGING_CONFIRM; msg->status = PHY_BUSY; memcpy(msg->data, (MyByte8T*) &rangingPIB, sizeof(RangingPIB)); msg->len = sizeof(RangingPIB); SendMsgUp (msg); return; } memcpy(rDest, msg->addr, 6); if (msg->prim == PD_RANGING_REQUEST) { lState = RANGING_START; RangingMode(RANGING_START, msg->addr); } else if (msg->prim == PD_RANGING_FAST_REQUEST) { lState = RANGING_FAST_START; RangingMode(RANGING_FAST_START, msg->addr); } break; default: break; } }