unsigned int test_fec_decoding(void) { uint8_t input[15] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E}; uint8_t output[32]; TimerA_configureContinuousMode(__MSP430_BASEADDRESS_T0A5__, TIMERA_CLOCKSOURCE_SMCLK, TIMERA_CLOCKSOURCE_DIVIDER_1, TIMERA_TAIE_INTERRUPT_DISABLE, TIMERA_DO_CLEAR); fec_init_encode(input); fec_set_length(15); fec_encode(&output[0]); fec_encode(&output[4]); fec_encode(&output[8]); fec_encode(&output[12]); fec_encode(&output[16]); fec_encode(&output[20]); fec_encode(&output[24]); fec_encode(&output[28]); memset(input, 0, 15); fec_init_decode(input); fec_set_length(15); TimerA_clear(__MSP430_BASEADDRESS_T0A5__); fec_decode(&output[0]); fec_decode(&output[4]); fec_decode(&output[8]); fec_decode(&output[12]); fec_decode(&output[16]); fec_decode(&output[20]); fec_decode(&output[24]); fec_decode(&output[28]); TimerA_stop(__MSP430_BASEADDRESS_T0A5__); return TA0R - TIMER_OFFSET; }
bool phy_rx(phy_rx_cfg_t* cfg) { #ifdef LOG_PHY_ENABLED log_print_stack_string(LOG_PHY, "phy_rx"); #endif RadioState current_state = get_radiostate(); if(current_state != Idle && current_state != Receive) { #ifdef LOG_PHY_ENABLED log_print_stack_string(LOG_PHY, "PHY Cannot RX, PHy not idle"); #endif return false; } //Set radio state state = Receive; //Flush the txfifo Strobe(RF_SIDLE); Strobe(RF_SFRX); //Set configuration if (!phy_translate_and_set_settings(cfg->spectrum_id, cfg->sync_word_class)) return false; set_timeout(cfg->timeout); //TODO Return error if fec not enabled but requested #ifdef D7_PHY_USE_FEC if (fec) { //Disable hardware data whitening set_data_whitening(false); //Initialize fec encoding fec_init_decode(buffer); //Configure length settings set_length_infinite(true); if(cfg->length == 0) { packetLength = 0; remainingBytes = 0; WriteSingleReg(PKTLEN, 0xFF); WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_61_4); } else { fec_set_length(cfg->length); packetLength = ((cfg->length & 0xFE) + 2) << 1; remainingBytes = packetLength; WriteSingleReg(PKTLEN, (uint8_t)(packetLength & 0x00FF)); WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_17_48); } } else { #endif //Enable hardware data whitening set_data_whitening(true); //Set buffer position bufferPosition = buffer; //Configure length settings and txfifo threshold set_length_infinite(false); if(cfg->length == 0) { packetLength = 0; remainingBytes = 0; WriteSingleReg(PKTLEN, 0xFF); WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_61_4); } else { packetLength = cfg->length; remainingBytes = packetLength; WriteSingleReg(PKTLEN, packetLength); WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_17_48); } #ifdef D7_PHY_USE_FEC } #endif //TODO: set minimum sync word rss to scan minimum energy //Enable interrupts phy_set_gdo_values(GDOLine2, GDO_EDGE_RXFilled, GDO_SETTING_RXFilled); phy_set_gdo_values(GDOLine0, GDO_EDGE_EndOfPacket, GDO_SETTING_EndOfPacket); radioClearInterruptPendingLines(); radioEnableGDO2Interrupt(); radioEnableGDO0Interrupt(); //Start receiving Strobe(RF_SRX); return true; }