1. 首页
  2. 课程学习
  3. 专业指导
  4. CC2550等TI系列RF芯片内部FEC解码算法分析及其源码

CC2550等TI系列RF芯片内部FEC解码算法分析及其源码

上传者: 2020-12-23 22:51:43上传 PDF文件 264.17KB 热度 14次
BesignNote LNbr 3 Implementation 3.1 Code Example Assumptions and Limitations Assume that you want to use the CC1101 [5] to transmit a packet and the CC430FX [2]to receive it. The payload is 29 bytes and 2 bytes of CRC are appended. If FEC is enabled (MDMCFG1 FEC EN 1 on the transmitter, 64 bytes will be transmitted over the air in addition to preamble and sync word. Due to the appended trellis terminator and the size of the interleaving buffer the packet length will always be a multiple of 4 after encoding (see DN504 [11. The number of bytes sent over the air(not including preamble and sync ord)can be calculated as shown in Equation 1 of Bytes on the△ir=( Payload Length +2 Bytes Optional CrC )+14 2 Equation 1.# of Bytes on the air The code example shown in Section 3.2 does not show how to set up the CC430Fx to receive a packet and it does not show how to implement the function (readRXFifo) that will read from the RXFIFo in Figure 5(see the CC430FX User's Guide [2 on how this can be done ). It is assumed that a flag, packetReceived, is asserted when the packet is received and the 64 bytes are in the RXFIFo. It is important to notice that there is no packet size limitation to the Fec decoding itself, but if more than 64 bytes are sent over the air, the receiver must start to read the rXFiFo before the complete packet is received and additional RAM is needed to store the un-coded packet. When 64 bytes or less is sent on the air, the un-coded data can simply be kept in the RXFIFO until being decoded. The CC1101 [5 only support fixed packet length mode(PkTCtrlo LENGTH CoNFIG o)when FEC is enabled so the cc430Fx should also use this mode. overflow of the rxfifo will therefore not be an issue as long as the maximum packet length is less than 64 bytes(PKTlen state 6 produces("=0",01" state [3,7)->state 7 produces "01","l0 // T.- r inUiT. bit at encoder when: Destination state const unsigned char aTrellisTransitionInput [8] k实步女实*洲实?出女?★实步★出步宋出实*出实为出★实;出k★为出实头出实实头出实实实为宫★实头出出实实出★实》出实★实?出k?出★实》出实出k实 DEF工NEs // NUMBER OF EYTES AFTER DECODING should be given the length of the pay load CEC(CRC is cpticnal tdefine NtMBER OF BYTES AFTER DECCDING 31 #define NUMBER OF BYTES 3EFORE DECODING (4 *((NUMBER OF BY ES AFTER DECODING/2)+1)) Fiqure 1 Function Prototypes, Global variables, and Defines TEXAS STRUMENTS SWRA313 Page 4 of 17 BesignNote LNbr /*古内古古古+古古古十内古古古内古古十古古内古古古古古十古古女古古古古古古内古古内为古古古古害古古内古古古古实古古内古古古古六古古古内古古古内女★ fafI Calculates Lamming weight of byte ( bits set 回pa工 a- Byte to find the aming weight for 6 return Harming weight (# cf Dite set in a) static unsigned char hammweight (unsigned char a) (as0x)>>1)1(a&0x55;; (as0xcc)>>2)+ia&0x33 (a0xF0)>>4)+ia&0x0F}; return a 古肯古古古尹古古古古六大世古古古古古古大世古六古尹 Returns the minimum of two values a- Valule 1 b- value 2 Minimim of two values Value 1(val vallle 2(va7 11) static unsigned char min(unsigned char a, unsigned char b) return (a b ofn Calculates a checksum cver n data bytes Example of usace checksum 0xFFFF checks um= calcCRc (dataBytes[, check sum ap:ram cremata-checksum (init ally set to OxFFFF) croRe aata上yte static unsigned short calccRC(unsigned char crcData, unsigned chort crcReg) unsigned char i for ii -0; i>8:(crcData 0x80) e⊥ge crcReg =(crcReg >( pInNata aDeintData; 7 Process up to 4 bytes of de-interleaved input data, processing one e:coder symbol (2o)at a time for unsigned char iDeststate unsigned char symbol =(("pInnata)>>+Bit )N 0x02 // Find minimum ccst ao tha an e costs (only last iteration uae tM⊥ ncos t=0xFE // Get 2b input symbol (MSB First) and do one iteration of viterbi decoding if ((iBit-=2 ⊥Bit=6 pInNata++ / Update pointer to the next byte of received data For each destination state in the trellis, calculate hamming costs for both possible paths into state and select the one vith lowest cost for (iDeststate=0: iDeststate =8: iDeststate-+)i unsigned char aCosta; unsigned char ncost1 unsigned char isrcstata0: unsigned char iSrcstatel unsigned char nInputBit; nInput3it -aTrellicTransitionInput [iDectState]; / Calculate cost of transition from each of the two source states (cost is Hamming difference between received 2b symbol and expected synbol for transit_on) iSrcStateo- aTrellisSourcestateLut [iDeststatel[c nCosto= Cost [ilastB if][isrcstateo nCosto + harm weight i symbol aTrellisTransitionoutput [iDeststatel [ol) iSrcStatel aTrellisSourcastatelut liDest state [l nCost1- Cost [ilastB f][isrcstatel nCost1 + hatnm'Neight i symbol aTrellisTransitionoutput [iDestState][1]) Figure 3. FEC Decoder Implementation (1) TEXAS STRUMENTS SWRA313 Page 6 of 17 BesignNote LNbr Select transition that gives lowest cost in destination state, copy that source state's path i=(ncosto c。st1){ cOst [icurrBIf][iDeststate]=nCostoi mIncha st= min inMincost, ncosto) apan[iC Rrr:if] [ineststate] =(a. h [iT: Rulf] [+Srosraten] 24)&0xF npathBits --8 / After having processed 3-symbol trellis terminator, flush out remaining data if ((nRemEytee =8: *ETJecnata++=(apat h[icurrRulf][ol >>(npathRits -F)) N nxFF: nPatnEits - 8 return nout / Swap current and last buffers for next iteration f= (iTastPulf +1)%2 iCurrEuf (icu / Normalize costs so that n in unsigned char istate; Figure 4. FEC Decoder Implementation(2) ★女实实为为实出实》★实9为★实步实实实坐出实女为实出实为密密实头宫谢实头出实头出★实头出青实头★实出谢实出出★实》出★实实实出来实出实步实9★实甘实实*谢实实出k实 (abrief Tni s code example demonstrates how the fecrecode finction can ne used. Tt. is assumed that. a flag, racketRaceived, is asserted when a packet -s received ithere are 64 bytes in the RXFIFO) pa⊥dml ★ oreTi unsigned short nBytes signed char *EDecData= rxPacket / Destination for decoded data / Init MCJ and Radio while ( I packetReceivad) // Wait for packet to be reseived (54 bytes in the RXFIFO) pDecData rxFacket: // Perform de-interleaving and decoding (both done in the same function) fecDecode(NULL NCLL, 0 / The function needs to be called with a NULI pointer for in-tialization before every packet to decode nBytes NUMBER OF BYTES AFTER DECODING while (nBytes >0) unsigned short nBytesout: readRxFifo(RF RXFIFO, rxBuffer, 4) / Read 4 bytes from the RXFIFo and store them in rxEuffer nBytesout ecDecode(pfecJata, rxBuffer, nBy nBytes - nEytecout pDecData + nBytesout Perform CRC check (Optional unsigned short i nBytes NJNBER OF EYTES AFTER DECODING; checksum CXFFFE / Init value for CRc calculation s nBytes; i++) hecksum calccRc irxFacket [i, checksum if(Checksum,( // Do something to indicate that the cRc is OK Figure 5. main TEXAS STRUMENTS SWRA313 Page 7 of 17 BesignNote LNbr 4 Explanation to the Code The most important part of the code is the decoder part implemented in the function fecDecode(see Figure 3 and Figure 4). The function will process 4 and 4 bytes of received data since this is the data size the interleaver works on this means that in most cases the function will be called several times for each received packet. The pseudo code for the function is shown in Figure 6 // Variable Declaration /7 Initialize variables at start of packet (and return without doing any more) // De-interleave 4 byter of received data (4 bytes of data mean -6(2b) enccde eymoclc / For all 16 symbols do oe iteration of viterbi decoding for (nTterations 16: ntterations nTrerations--)( // Get 2D input symbol (MCB first)and do one iteration of viterbi decoding // For each destination state in the trellis for(iDestState-0: iDestState
用户评论