Created
June 17, 2014 16:31
-
-
Save bemasher/1d74d9bee708e07ca10d to your computer and use it in GitHub Desktop.
Basic receiver and bch error checking for TI ChipCon sub-Ghz receivers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cc1110.h> | |
#include "cc1110-ext.h" | |
#include <stdint.h> | |
#define GENPOLY 0x6F63 | |
//! Receives a packet out of the radio from 0xFE00. | |
char __xdata __at 0xFE00 packet[0xFF]; | |
uint16_t bch() { | |
uint8_t byteIdx, bitIdx; | |
uint16_t checksum = 0; | |
for (byteIdx = 0; byteIdx < PKTLEN; byteIdx++) { | |
checksum ^= (uint16_t)packet[byteIdx] << 8; | |
for (bitIdx = 0; bitIdx < 8; bitIdx++) { | |
if (checksum & 0x8000) { | |
checksum = (checksum << 1) ^ GENPOLY; | |
} else { | |
checksum <<= 1; | |
} | |
} | |
} | |
return checksum; | |
} | |
void main() { | |
unsigned char idx = 0; | |
// Disable interrupts. | |
RFTXRXIE = 0; | |
do { | |
// Strobe RX and wait for ready. | |
RFST = RFST_SRX; | |
while(MARCSTATE != MARC_STATE_RX); | |
for(idx = 0; idx < PKTLEN; idx++) { | |
// Wait for byte to be ready. | |
while(!RFTXRXIF); | |
// Clear the flag. | |
RFTXRXIF=0; | |
// Grab the next byte. | |
packet[idx]=RFD; | |
} | |
// We sync on 16+1 bits, discard last bit. | |
packet[PKTLEN-1] &= 0xFE; | |
} while (bch()); | |
P1_4 = 1; | |
P1_4 = 0; | |
//End receive. | |
RFST = RFST_SIDLE; | |
while(MARCSTATE != MARC_STATE_IDLE); | |
HALT; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment