110 likes | 257 Views
Lab 4 CRC, PDR vs. distance, preamble sampling. Thomas Watteyne EE290Q – Spring 2010 http://wsn.eecs.berkeley.edu/290Q. CRC: Cyclic Redundancy Check. If PKTCTRL0.CRC_EN=1: At Tx , data is hashed and result append to the packet as a 2-byte field
E N D
Lab 4CRC, PDR vs. distance,preamble sampling Thomas Watteyne EE290Q – Spring 2010 http://wsn.eecs.berkeley.edu/290Q
CRC: Cyclic Redundancy Check • If PKTCTRL0.CRC_EN=1: • At Tx, data is hashed and result append to the packet as a 2-byte field • At Rx, data is hashed and result compared to CRC field, packet dropped if fails • How CRC works • Calculate the remainderof a (binary) division • In CC2500,CRC-16-IBM (x16 + x15 + x2 + 1)
CRC: Cyclic Redundancy Check 11010011101100 1011 01100011101100 1011 0111011101100 1011 010111101100 1011 00001101100 1011 0001101100 1011 001101100 1011 01101100 1011 0110100 1011 011000 1011 01110 1011 0101 • Pick a CRC length • e.g. 3 bits • Pick a polynom • e.g. x4+x+1 (1011) • (Always a leftmost 1!) • While bits in data • Write under leftmost data bits • iif leftmost data bit is 1, XOR(leftmost bit always turns to 0) • Shift right one place • Collect 3-bit CRC
The Importance of CRC [1/3] reduce the Tx Power for more frequent errors disable CRC Enable UART lab4_crc #include "radios/family1/mrfi_spi.h" #include "mrfi.h" mrfiPacket_tpacketToSend; int main(void) { BSP_Init(); P1REN |= 0x04; P1IE |= 0x04; MRFI_Init(); mrfiSpiWriteReg(PATABLE,0xBB); mrfiSpiWriteReg(PKTCTRL0,0x41); P3SEL |= 0x30; UCA0CTL1 = UCSSEL_2; UCA0BR0 = 0x41; UCA0BR1 = 0x3; UCA0MCTL = UCBRS_2; UCA0CTL1 &= ~UCSWRST; MRFI_WakeUp(); MRFI_RxOn(); __bis_SR_register(GIE+LPM4_bits); }
The Importance of CRC [2/3] when receiving a packet Copy RXFIFO to “packet” format string send string over serial lab4_crc void MRFI_RxCompleteISR() { uint8_t i; P1OUT ^= 0x02; mrfiPacket_t packet; MRFI_Receive(&packet); char output[] = {" \r\n"}; for (i=9;i<packet.frame[0];i++) { output[i-9]=packet.frame[i]; } TXString(output, (sizeof output)); }
The Importance of CRC [3/3] when button is pressed comment out for continuous Tx Fill frame with ‘abcdef…’ Copy to TXFIFO and send lab4_crc #pragma vector=PORT1_VECTOR __interrupt void Port_1 (void) { P1IFG &= ~0x04; char character = 'a'; uint8_t index; mrfiPacket_t packet; for (index=9;index<30;index++) { packet.frame[index]=character++; } packet.frame[0]=++index; MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED); P1OUT ^= 0x01; }
Channel Success Probability • Receiver listens • When button pressed sender sends a burst of packets • 100 packets with counter from 1 to 100 • 20 packets with counter to 101 • When receiving a packet • If packet counter <101, increment a counter and store the RSSI • For the first packet with counter==101, display “average RSSI – channel success probability”
Channel Success Probability [1/4] e.g. “-55 0.75” Prepare string transmit string over serial lab4_pdr #include "mrfi.h" uint8_t counter, num_received, bool_counting; int16_t cumulative_rssi; mrfiPacket_t packet; void print_probability(int16_t cumulative_rssi, uint8_t number) { char output[] = {" 000 0.00\n"}; if (cumulative_rssi<0) { output[0]='-'; cumulative_rssi=-cumulative_rssi; } output[1] = '0'+((cumulative_rssi/100)%10); output[2] = '0'+((cumulative_rssi/10)%10); output[3] = '0'+ (cumulative_rssi%10); output[5] = '0'+((number/100)%10); output[7] = '0'+((number/10)%10); output[8] = '0'+ (number%10); TXString(output, (sizeof output)-1); }
Channel Success Probability [2/4] when button is pressed enable serial communication Wait for interrupts in low power mode lab4_pdr int main(void) { BSP_Init(); P1REN |= 0x04; P1IE |= 0x04; MRFI_Init(); mrfiSpiWriteReg(PATABLE,0x50); P3SEL |= 0x30; UCA0CTL1 = UCSSEL_2; UCA0BR0 = 0x41; UCA0BR1 = 0x3; UCA0MCTL = UCBRS_2; UCA0CTL1 &= ~UCSWRST; MRFI_WakeUp(); MRFI_RxOn(); __bis_SR_register(GIE+LPM4_bits); }
Channel Success Probability [3/4] When I receive a packet lab4_pdr void MRFI_RxCompleteISR() { P1OUT ^= 0x02; MRFI_Receive(&packet); counter = packet.frame[9]; if (counter==101) { if (bool_counting == 1) { print_probability(cumulative_rssi/num_received,num_received); } bool_counting=0; num_received=0; cumulative_rssi=0; } else { bool_counting=1; num_received++; cumulative_rssi+=(int8_t) packet.rxMetrics[0]; } }
Channel Success Probability [4/4] when button is pressed lab4_pdr #pragma vector=PORT1_VECTOR __interrupt void interrupt_button (void) { P1IFG &= ~0x04; P1OUT ^= 0x01; mrfiPacket_t packet; packet.frame[0]=8+3; for (counter=1;counter<101;counter++){ packet.frame[9]=counter; MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED); } for (counter=0;counter<20;counter++){ packet.frame[9]=101; MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED); } }