Ejemplo n.º 1
0
/**
 * @brief Converts a phyTransmitPower value to a register value
 *
 * @param phyTransmitPower_value phyTransmitPower value
 *
 * @return register value
 */
static uint8_t convert_phyTransmitPower_to_reg_value(uint8_t phyTransmitPower_value)
{
    int8_t dbm_value;
    uint8_t reg_value = 0x00;

    dbm_value = CONV_phyTransmitPower_TO_DBM(phyTransmitPower_value);

    /* Select the corresponding tx_pwr_table */
#ifdef HIGH_DATA_RATE_SUPPORT
    if ((tal_pib_CurrentPage == 5) || (tal_pib_CurrentPage == 18) || (tal_pib_CurrentPage == 19))
#else
    if (tal_pib_CurrentPage == 5)
#endif
    {
        reg_value = PGM_READ_BYTE(&tx_pwr_table_China[MAX_TX_PWR - dbm_value]);
    }
    else
    {
        if (tal_pib_CurrentChannel == 0)
        {
            reg_value = PGM_READ_BYTE(&tx_pwr_table_EU[MAX_TX_PWR - dbm_value]);
        }
        else    // channels 1-10
        {
            reg_value = PGM_READ_BYTE(&tx_pwr_table_NA[MAX_TX_PWR - dbm_value]);
        }
    }

    return reg_value;
}
Ejemplo n.º 2
0
void sserial_find_bootloader()
{
	byte found=0;
	uint32_t pos=FLASHEND-32;
	do
	{
		pos--;
		found=1;
		for (uint32_t i=0; i<7; i++)
		{
			uint32_t p=pos+i;
			if (PGM_READ_BYTE(p)!="BwlBoot"[i]){found=0;i=8;}
		}
	} while ((found==0)&&(pos>FLASHEND-4096));
	
	if (found==1)
	{
		for (byte i=0; i<16; i++)
		{
			sserial_devname[i]=PGM_READ_BYTE(pos+16+i);
			sserial_devguid[i]=PGM_READ_BYTE(pos+32+i);
		}
		for (byte i=0; i<16; i++)
		{
			sserial_bootname[i]=PGM_READ_BYTE(pos+i);
		}
	}
	sserial_bootloader_present=found;
}
Ejemplo n.º 3
0
uint8_t mac_get_pib_attribute_size(uint8_t pib_attribute_id)
{
#if (MAC_START_REQUEST_CONFIRM == 1)

	/*
	 * Since the current length of the beacon payload is not a contant, but
	 * a variable, it cannot be stored in a Flash table. Therefore we need
	 * to handle this PIB attribute special.
	 */
	if (macBeaconPayload == pib_attribute_id) {
		return (*(rcv_frame_ptr + 4));
	}

#endif  /* (MAC_START_REQUEST_CONFIRM == 1) */

	if (MAX_PHY_PIB_ATTRIBUTE_ID >= pib_attribute_id) {
		return (PGM_READ_BYTE(&phy_pib_size[pib_attribute_id]));
	}

	if (MIN_MAC_PIB_ATTRIBUTE_ID <= pib_attribute_id &&
			MAX_MAC_PIB_ATTRIBUTE_ID >= pib_attribute_id) {
		return(PGM_READ_BYTE(&mac_pib_size[pib_attribute_id -
		       MIN_MAC_PIB_ATTRIBUTE_ID]));
	}

	if (MIN_PRIVATE_PIB_ATTRIBUTE_ID <= pib_attribute_id) {
		return(PGM_READ_BYTE(&private_pib_size[pib_attribute_id -
		       MIN_PRIVATE_PIB_ATTRIBUTE_ID]));
	}

	return(0);
}
Ejemplo n.º 4
0
/**
 * @brief Gets the size of a PIB attribute
 *
 * @param attribute PIB attribute
 *
 * @return Size (number of bytes) of the PIB attribute
 */
uint8_t nwk_get_ib_attribute_size(NWK_NibId_t pib_attribute_id)
{

//    if (MAX_PHY_PIB_ATTRIBUTE_ID >= pib_attribute_id)
//    {
//       return (PGM_READ_BYTE(&phy_pib_size[pib_attribute_id]));
//    }

    if (MIN_NWK_PIB_ATTRIBUTE_ID <= pib_attribute_id && MAX_NWK_PIB_ATTRIBUTE_ID >= pib_attribute_id)
    {
       return(PGM_READ_BYTE(&nwk_pib_size[pib_attribute_id - MIN_NWK_PIB_ATTRIBUTE_ID]));
    }

//#ifdef MAC_SECURITY_ZIP
//    if (MIN_MAC_SEC_PIB_ATTRIBUTE_ID <= pib_attribute_id && MAX_MAC_SEC_PIB_ATTRIBUTE_ID >= pib_attribute_id)
//    {
//       return(PGM_READ_BYTE(&mac_sec_pib_size[pib_attribute_id - MIN_MAC_SEC_PIB_ATTRIBUTE_ID]));
//    }
//#endif  /* MAC_SECURITY_ZIP */
//
//    if (MIN_PRIVATE_PIB_ATTRIBUTE_ID <= pib_attribute_id)
//    {
//        return(PGM_READ_BYTE(&private_pib_size[pib_attribute_id - MIN_PRIVATE_PIB_ATTRIBUTE_ID]));
//    }

    return(0);
}
Ejemplo n.º 5
0
/**
 * @brief Converts a phyTransmitPower value to a register value
 *
 * @param phyTransmitPower_value phyTransmitPower value
 *
 * @return register value
 */
static uint8_t convert_phyTransmitPower_to_reg_value(uint8_t phyTransmitPower_value)
{
    int8_t dbm_value;
    uint8_t i;
    int8_t trx_tx_level;

    dbm_value = CONV_phyTransmitPower_TO_DBM(phyTransmitPower_value);

    /* Compare to the register value to identify the value that matches. */
    for (i = 0; i < sizeof(tx_pwr_table); i++)
    {
        trx_tx_level = (int8_t)PGM_READ_BYTE(&tx_pwr_table[i]);
        if (trx_tx_level <= dbm_value)
        {
            if (trx_tx_level < dbm_value)
            {
                return (i - 1);
            }
            return i;
        }
    }

    /* This code should never be reached. */
    return 0;
}
Ejemplo n.º 6
0
/**
 * @brief Gets the AGC settling period
 *
 * @param sr    Sample rate
 * @param avgs  AGC average time in number of samples
 * @param agci  AGC input
 */
static uint16_t get_agc_settling_period(uint8_t sr, uint8_t avgs, uint8_t agci)
{
	uint16_t period = 0;

	for (uint8_t i = 0; i < AGC_SETTLE_TABLE_ROW_SIZE; i++) {
		if (sr == (uint8_t)PGM_READ_BYTE(&agc_settle[i][0])) {
			uint8_t idx = 1 + 2 * avgs + agci;
			period = (uint8_t)PGM_READ_BYTE(&agc_settle[i][idx]);
			break;
		}
	}

	period *= 2;

	return period;
}
Ejemplo n.º 7
0
static uint16_t oqpsk_ack_psdu_duration_sym(trx_id_t trx_id)
{
	uint8_t Ns
		= (uint8_t)PGM_READ_BYTE(&oqpsk_sym_len_table[tal_pib[trx_id].
			phy.phy_mode.oqpsk.chip_rate]);                                                      /*
	                                                                                                      * Table
	                                                                                                      * 183 */
	uint8_t Rspread = oqpsk_spreading(
			tal_pib[trx_id].phy.phy_mode.oqpsk.chip_rate,
			tal_pib[trx_id].OQPSKRateMode);
	uint16_t Npsdu = Rspread * 2 * 63; /* Nd == 63, since ACK length is 5 or
	                                    * 7 octects only */
	uint16_t duration_sym = Npsdu / Ns;
	if (Npsdu % Ns) {
		duration_sym += 1;
	}

	uint16_t temp = 16 * Ns;
	duration_sym += Npsdu / temp;
	if ((Npsdu % temp) > 0) {
		duration_sym += 1;
	}

	return duration_sym;
}
Ejemplo n.º 8
0
/**
 * @brief Gets the CCA threshold
 *
 * @param trx_id Transceiver identifier
 *
 * @return CCA threshold in dBm
 */
int8_t get_cca_thres(trx_id_t trx_id)
{
	int8_t thres = 0; /* 0: indicator for wrong parameter */

	switch (tal_pib[trx_id].phy.modulation) {
#ifdef SUPPORT_FSK
	case FSK:
		thres
			= (int8_t)PGM_READ_BYTE(&fsk_cca_thres_table[tal_pib[
					trx_id
				].phy.phy_mode.fsk.data_rate]);
		if (tal_pib[trx_id].FSKFECEnabled) {
			thres -= FK_CCA_THRES_FEC_OFFSET;
		}
		break;

#endif
#ifdef SUPPORT_OFDM
	case OFDM:
		/* rows: MCSn; column: option n */
		thres
			= (int8_t)PGM_READ_BYTE(&ofdm_cca_thres[tal_pib[trx_id].
				OFDMMCS] \
				[tal_pib[trx_id].phy.phy_mode.ofdm.option ]);           /* option
		                                                                         * -
		                                                                         * 1 */
		break;

#endif
#ifdef SUPPORT_OQPSK
	case OQPSK:
		thres = (int8_t)OQPSK_CCA_THRES;
		break;

#endif
#ifdef SUPPORT_LEGACY_OQPSK
	case LEG_OQPSK:
		thres = -85 + 10;
		break;
#endif

	default:
		break;
	}

	return thres;
}
Ejemplo n.º 9
0
static uint16_t oqpsk_get_chip_rate(trx_id_t trx_id)
{
	uint16_t rate = 10 *
			(uint16_t)PGM_READ_BYTE(&oqpsk_chip_rate_table[tal_pib[
				trx_id].phy.phy_mode.oqpsk.chip_rate]);

	return rate;
}
Ejemplo n.º 10
0
// classic Tx a C-string routine
// As there is no .data (in the bootloader) it only makes sense for theis to use PSTR()
void UART_puts(const char * str) {
    char c;
    do {
        c = PGM_READ_BYTE(str++);
        if (c) {
            UART_put(c);
        }
    } while (c != 0);
}
Ejemplo n.º 11
0
static void AES_SubBytes( uint8_t * bytes, uint8_t count )
{
	// Copy to temporary variables for optimization.
	uint8_t * tempPtr = bytes;
	uint8_t tempCount = count;

	do {
		*tempPtr = PGM_READ_BYTE( AES_sBox + *tempPtr ); // Substitute every byte in state.
		++tempPtr;
	} while (--tempCount);
}
Ejemplo n.º 12
0
/**
 * @brief Limit the phyTransmitPower to the trx limits
 *
 * @param phyTransmitPower phyTransmitPower value
 *
 * @return limited tal_pib_TransmitPower
 */
static uint8_t limit_tx_pwr(uint8_t tal_pib_TransmitPower)
{
    uint8_t ret_val = tal_pib_TransmitPower;
    int8_t dbm_value;

    dbm_value = CONV_phyTransmitPower_TO_DBM(tal_pib_TransmitPower);
    if (dbm_value > (int8_t)PGM_READ_BYTE(&tx_pwr_table[0]))
    {
        dbm_value = (int8_t)PGM_READ_BYTE(&tx_pwr_table[0]);
        ret_val = CONV_DBM_TO_phyTransmitPower(dbm_value);

    }
    else if (dbm_value < (int8_t)PGM_READ_BYTE(&tx_pwr_table[sizeof(tx_pwr_table)-1]))
    {
        dbm_value = (int8_t)PGM_READ_BYTE(&tx_pwr_table[sizeof(tx_pwr_table)-1]);
        ret_val = CONV_DBM_TO_phyTransmitPower(dbm_value);
    }

    return (ret_val | TX_PWR_TOLERANCE);
}
Ejemplo n.º 13
0
static void AES_InvSubstAndAddConst( uint8_t * bytes, uint8_t const * constant, uint8_t count )
{
	// Copy to temporary variables for optimization.
	uint8_t * tempDestination = bytes;
	uint8_t const * tempSource = constant;
	uint8_t tempCount = count;
	uint8_t tempValue;

	do {
		// Add in GF(2), ie. XOR.
		tempValue = *tempDestination;
		*tempDestination++ = PGM_READ_BYTE( AES_invSBox + tempValue ) ^ *tempSource++;
	} while (--tempCount);
}
Ejemplo n.º 14
0
/**
 * @brief Gets the CCA duration in us
 *
 * @param trx_id Transceiver identifier
 *
 * @return CCA duration in us
 */
uint16_t get_cca_duration_us(trx_id_t trx_id)
{
	uint16_t ret_val = 0;

	if (tal_pib[trx_id].phy.freq_band == JAPAN_920) {
		ret_val = calculate_cca_duration_us(trx_id);
	} else {
		switch (tal_pib[trx_id].phy.modulation) {
#ifdef SUPPORT_FSK
		case FSK:
			ret_val = 8;
			break;

#endif
#ifdef SUPPORT_OFDM
		case OFDM:
			ret_val = 8; /* symbols */
			break;

#endif
#ifdef SUPPORT_OQPSK
		case OQPSK:
			/* Check CCA table for entry */
			ret_val
				= (uint8_t)PGM_READ_BYTE(&oqpsk_cca_dur_table[
						tal_pib
						[trx_id].phy.phy_mode.oqpsk.
						chip_rate]);                                                          /*
			                                                                                               *symbols
			                                                                                               **/
			break;

#endif
#ifdef SUPPORT_LEGACY_OQPSK
		case LEG_OQPSK:
			ret_val = 8;
			break;

#endif
		default:
			break;
		}

		/* Change value from symbols to us */
		ret_val = ret_val * tal_pib[trx_id].SymbolDuration_us;
	}

	return ret_val;
}
Ejemplo n.º 15
0
/**
 * \brief Converts a phyTransmitPower value to a register value
 *
 * \param phyTransmitPower_value phyTransmitPower value
 *
 * \return register value
 */
static uint8_t convert_phyTransmitPower_to_reg_value(
		uint8_t phyTransmitPower_value)
{
	int8_t dbm_value;
	uint8_t reg_value = 0x00;

	dbm_value = CONV_phyTransmitPower_TO_DBM(phyTransmitPower_value);

	/* Select the corresponding tx_pwr_table, also valid for high data rates
	**/
#ifdef HIGH_DATA_RATE_SUPPORT
	if ((tal_pib.CurrentPage == 5) || (tal_pib.CurrentPage == 18) ||
			(tal_pib.CurrentPage == 19))
#else
	if (tal_pib.CurrentPage == 5)
#endif
	{
		reg_value
			= PGM_READ_BYTE(
				&tx_pwr_table_China[MAX_TX_PWR - dbm_value]);
	} else { /* concerns channel pages={0, 2, 16, 17}*/
		if (tal_pib.CurrentChannel == 0) {
			reg_value
				= PGM_READ_BYTE(
					&tx_pwr_table_EU[MAX_TX_PWR -
					dbm_value]);
		} else { /* channels 1-10 */
			reg_value
				= PGM_READ_BYTE(
					&tx_pwr_table_NA[MAX_TX_PWR -
					dbm_value]);
		}
	}

	return reg_value;
}
Ejemplo n.º 16
0
/**
 * @brief Gets the SHR duration
 *
 * @param trx_id Transceiver identifier
 *
 * @return SHR duration in symbols
 */
uint8_t shr_duration_sym(trx_id_t trx_id)
{
	uint8_t shr = 0;

	switch (tal_pib[trx_id].phy.modulation) {
#ifdef SUPPORT_FSK
	case FSK:
		/* Preamble + SFD; SFD=2 */
		shr = (tal_pib[trx_id].FSKPreambleLength + 2) * 8;
		break;
#endif

#ifdef SUPPORT_OFDM
	case OFDM:
		shr = 6;
		break;
#endif

#ifdef SUPPORT_OQPSK
	case OQPSK: /* see pg. 119 */
		shr
			= (uint8_t)PGM_READ_BYTE(&oqpsk_shr_duration_table[
					tal_pib[trx_id
					].phy.phy_mode.oqpsk.chip_rate]);
		break;
#endif

#ifdef SUPPORT_LEGACY_OQPSK
	case LEG_OQPSK:
		shr = 8 + 2; /* 8 = SHR; 2 = SFD */
		break;

#endif
	default:
		break;
	}

	return shr;
}
Ejemplo n.º 17
0
/**
 * @brief Configures RF according FSK
 *
 * @param mod_type Modulation order / type; i.e. F2FSK or F4FSK
 * @param srate Data rate
 * @param mod_idx Modulation index
 * @param trx_id Transceiver identifier
 */
retval_t fsk_rfcfg(fsk_mod_type_t mod_type, fsk_data_rate_t srate,
		mod_idx_t mod_idx, trx_id_t trx_id)
{
	retval_t status = MAC_SUCCESS;
	uint16_t reg_offset = RF_BASE_ADDR_OFFSET * trx_id;
	uint8_t srate_midx = (srate << 3) + mod_idx;

	/* TX configuration: */
	/* - PA ramp time +  TX-SSBF fcut */
	/* - DFE sampling rate reduction + TX-DFE fcut */
	{
		uint8_t temp[2];
		PGM_READ_BLOCK(temp, (uint8_t *)&fsk_params_tbl[srate_midx][0],
				2);
		rf_blk_write(reg_offset + RG_RF09_TXCUTC, temp, 2);
	}

	/* - Transmit Power*/
#ifdef IQ_RADIO
	pal_dev_reg_write(RF215_RF, reg_offset + RG_RF09_PAC,
			((3 <<
			PAC_PACUR_SHIFT) |
			(DEFAULT_TX_PWR_REG << PAC_TXPWR_SHIFT)));
#else
	trx_reg_write(reg_offset + RG_RF09_PAC,
			((3 <<
			PAC_PACUR_SHIFT) |
			(DEFAULT_TX_PWR_REG << PAC_TXPWR_SHIFT)));
#endif

	/* RX configuration: */
	/* - RX-SSBF bandwidth + RX-SSBF IF shift */
	/* - DFE sampling rate reduction  + RX-DFE cut-off ratio */
	if (trx_id == RF09) {
		uint8_t temp[2];
		PGM_READ_BLOCK(temp, (uint8_t *)&fsk_params_tbl[srate_midx][5],
				2);
		rf_blk_write(RG_RF09_RXBWC, temp, 2);
	} else {
		uint8_t temp[2];
		PGM_READ_BLOCK(temp, (uint8_t *)&fsk_params_tbl[srate_midx][7],
				2);
		rf_blk_write(RG_RF24_RXBWC, temp, 2);
	}

	/* - AGC input + AGC average period */
	/* - AGC target */
	{
		uint8_t temp[2];
		PGM_READ_BLOCK(temp, (uint8_t *)&fsk_params_tbl[srate_midx][9],
				2);
		rf_blk_write(reg_offset + RG_RF09_AGCC, temp, 2);
	}

#ifndef FWNAME
	uint8_t agcc = (uint8_t)PGM_READ_BYTE(&fsk_params_tbl[srate_midx][9]);
	uint8_t agci = (agcc & AGCC_AGCI_MASK) >> AGCC_AGCI_SHIFT;
	uint8_t avgs = (agcc & AGCC_AVGS_MASK) >> AGCC_AVGS_SHIFT;
	uint8_t rxdfe;
	if (trx_id == RF09) {
		rxdfe = (uint8_t)PGM_READ_BYTE(&fsk_params_tbl[srate_midx][6]);
	} else {
		rxdfe = (uint8_t)PGM_READ_BYTE(&fsk_params_tbl[srate_midx][8]);
	}

	uint8_t sr = rxdfe & RXDFE_SR_MASK;
	tal_pib[trx_id].agc_settle_dur
		= get_agc_settling_period(sr, avgs, agci);
#endif

#if (!defined RF215v2)
	/* Keep compiler happy */
	mod_type = mod_type;
#endif

	return status;
}
Ejemplo n.º 18
0
/**
 * @brief Gets PSDU data rate
 *
 * @param trx_id Transceiver identifier
 *
 * @return data rate in kbit/s
 */
float get_data_rate(trx_id_t trx_id)
{
	float rate = 0;

	switch (tal_pib[trx_id].phy.modulation) {
#ifdef SUPPORT_FSK
	case FSK:
		rate = 10 *
				(uint8_t)PGM_READ_BYTE(&fsk_data_rate_table[
					tal_pib[trx_id
					].phy.phy_mode.fsk.data_rate]);
		if (tal_pib[trx_id].phy.phy_mode.fsk.mod_type == F4FSK) {
			rate *= 2;
		}

		if (tal_pib[trx_id].FSKFECEnabled) {
			rate /= 2;
		}
		break;

#endif
#ifdef SUPPORT_OFDM
	case OFDM:
		rate
			= (uint16_t)PGM_READ_WORD(&ofdm_data_rate_table[tal_pib[
					trx_id
				].OFDMMCS] \
				[tal_pib[trx_id].phy.phy_mode.ofdm.option]);            /* optoin
		                                                                         * -
		                                                                         * 1 */
		break;

#endif
#ifdef SUPPORT_OQPSK
	case OQPSK:
	{
		uint16_t chip_rate = oqpsk_get_chip_rate(trx_id);
		uint8_t spread = oqpsk_spreading(
				tal_pib[trx_id].phy.phy_mode.oqpsk.chip_rate,
				tal_pib[trx_id].OQPSKRateMode);
		rate = (float)chip_rate / (float)spread / (float)2;
	}
	break;

#endif
#ifdef SUPPORT_LEGACY_OQPSK
	case LEG_OQPSK:
		rate = 250;
		if (tal_pib[trx_id].HighRateEnabled) {
			if (tal_pib[trx_id].phy.phy_mode.leg_oqpsk.chip_rate ==
					CHIP_RATE_1000) {
				rate *= 2;
			} else {
				rate *= 4;
			}
		}
		break;
#endif

	default:
		break;
	}

	return rate;
}
Ejemplo n.º 19
0
/**
 * @brief Gets the ACK timing in us
 *
 * @param trx_id Transceiver identifier
 *
 * @return ACK timing in us
 */
uint16_t get_AckTiming_us(trx_id_t trx_id)
{
	uint16_t ack;

#ifdef SUPPORT_LEGACY_OQPSK
	if (tal_pib[trx_id].phy.modulation == LEG_OQPSK) {
		ack = aTurnaroundTime; /* = 12 */
	} else
#endif
	{
		ack = ceiling_sym(trx_id, aMinTurnaroundTimeSUNPHY);
	}

	/* Convert symbols to usec */
	ack *= tal_pib[trx_id].SymbolDuration_us;

	/*
	 * ACK timing correction - processing delay:
	 * RX to RXFE IRQ delay - PHY dependent
	 * Txprep to Tx delay
	 * MCU processing delay - MCU dependent
	 * PA ramping delay
	 */
	switch (tal_pib[trx_id].phy.modulation) {
#ifdef SUPPORT_FSK
	case FSK:
		ack
			-= (uint8_t)PGM_READ_BYTE(&fsk_processing_delay_ack_timing[
					tal_pib
					[trx_id].phy.phy_mode.fsk.data_rate]);
		break;

#endif
#ifdef SUPPORT_OFDM
	case OFDM:
		ack -= 100;
		break;

#endif
#if (defined SUPPORT_OQPSK) && (!defined BASIC_MODE)
	case OQPSK:
		ack
			-= (uint8_t)PGM_READ_BYTE(&oqpsk_ack_timing_offset_table[
					tal_pib
					[trx_id].phy.phy_mode.oqpsk.chip_rate]);
		break;

#endif
#ifdef SUPPORT_LEGACY_OQPSK
	case LEG_OQPSK:
#ifndef BASIC_MODE
		ack -= 20;
#else
		ack -= 16;
#endif
		break;

#endif /* #if (defined SUPPORT_LEGACY_OQPSK) */
	default:
		break;
	}

	return ack;
}