static void configure_syncword_class(syncword_class_t syncword_class, phy_coding_t coding)
{
	if(syncword_class == current_syncword_class)
		return;

	current_syncword_class = syncword_class;
	switch (coding)
	{
		case PHY_CODING_PN9:
			switch (syncword_class)
			{
				case PHY_SYNCWORD_CLASS0:
					ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNC_BITS_CS0_0);
					break;
				case PHY_SYNCWORD_CLASS1:
					ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNC_BITS_CS0_1);
					break;
			}
			break;
		case PHY_CODING_FEC_PN9:
			switch (syncword_class)
			{
				case PHY_SYNCWORD_CLASS0:
					ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNC_BITS_CS1_0);
					break;
				case PHY_SYNCWORD_CLASS1:
					ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNC_BITS_CS1_1);
					break;
			}
			break;
	}
}
static void configure_eirp(const eirp_t eirp)
{
	if (eirp == current_eirp)
		return;


	DPRINT("configure_eirp not implemented using max");
	uint8_t ddac = 0x7F; // max
	ezradio_set_property(0x22, 0x01, 0x01, ddac);
	current_eirp = eirp;
}
void change_eirp(){
#if defined USE_SI4460
    ezradio_set_property(0x22, 0x01, 0x01, current_eirp_level);
#elif defined USE_CC1101
    cc1101_interface_write_single_patable(current_eirp_level);
#endif
#ifdef HAS_LCD
    char string[10] = "";
    sprintf(string, "ptx %3x", current_eirp_level);
    lcd_write_string(string);
#endif
}
static void configure_eirp(const eirp_t eirp)
{
    for (uint8_t var = 0; var < sizeof(eirp_lookup); ++var)
    {
        if(eirp >= (int8_t)eirp_lookup[var])//round the given eirp to a lower possible value
        {
            int8_t reg_value =eirp_reg_values[var];
            ezradio_set_property(0x22, 0x01, 0x01, reg_value);
            current_eirp = eirp;
            break;
        }
    }
}
static void configure_channel(const channel_id_t* channel_id)
{

	// only change settings if channel_id changed compared to current config
	// TODO: check if only channel number changes

	if((channel_id->channel_header_raw != current_channel_id.channel_header_raw))
	{
		DPRINT("configure_channel: %s", byte_to_binary(channel_id->channel_header_raw));
		if (channel_id->channel_header.ch_coding != current_channel_id.channel_header.ch_coding)
		{
			if (has_hardware_crc && channel_id->channel_header.ch_coding != PHY_CODING_FEC_PN9)
			{
				// use HW CRC
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_PKT_LEN_ADJUST_HW_CRC);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_PKT_FIELD_1_CRC_CONFIG_HW_CRC);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_PKT_FIELD_2_CRC_CONFIG_HW_CRC);
			} else {
				// use SW CRC
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_PKT_LEN_ADJUST_SW_CRC);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_PKT_FIELD_1_CRC_CONFIG_SW_CRC);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_PKT_FIELD_2_CRC_CONFIG_SW_CRC);
			}
		}
		// TODO assert valid center freq index

		memcpy(&current_channel_id, channel_id, sizeof(channel_id_t)); // cache new settings

		// TODO preamble size depends on channel class

		// set freq band
		DPRINT("Set frequency band index: %d", channel_id->channel_header.ch_freq_band);

		switch(channel_id->channel_header.ch_class)
		{
		case PHY_CLASS_LO_RATE:
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_PFDCP_CPFF_LR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_PFDCP_CPINT_LR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_LPFILT3_LR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_LPFILT2_LR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_LPFILT1_LR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_DATA_RATE_LR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_TX_NCO_MODE_LR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_PA_TC_LR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AFC_WAIT_LR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_SPIKE_DET_LR);

			break;
		case PHY_CLASS_NORMAL_RATE:
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_PFDCP_CPFF_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_PFDCP_CPINT_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_LPFILT3_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_LPFILT2_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_LPFILT1_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_DATA_RATE_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_TX_NCO_MODE_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_PA_TC_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AFC_WAIT_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_SPIKE_DET_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_DECIMATION_CFG1_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_BCR_OSR_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_BCR_GAIN_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AFC_LIMITER_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AGC_RFPD_DECAY_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AGC_IFPD_DECAY_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_RAW_EYE_NR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_DSA_QUAL_NR);

			break;
		case PHY_CLASS_HI_RATE:
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_PFDCP_CPFF_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_PFDCP_CPINT_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_LPFILT3_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_LPFILT2_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_SYNTH_LPFILT1_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_TX_NCO_MODE_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_PA_TC_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AFC_WAIT_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_SPIKE_DET_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_DECIMATION_CFG1_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_BCR_OSR_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_BCR_GAIN_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AFC_LIMITER_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AGC_RFPD_DECAY_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AGC_IFPD_DECAY_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_RAW_EYE_HR);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_DSA_QUAL_HR);
			//assert(false);
			break;
		default:
			assert(false);
			break;
		}

		// TODO validate
		switch(channel_id->channel_header.ch_freq_band)
		{
		// TODO calculate depending on rate and channr
		case PHY_BAND_433:
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CLKGEN_BAND_433);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_VCOCNT_RX_ADJ_433);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_IF_FREQ_433);

			if(channel_id->channel_header.ch_class == PHY_CLASS_LO_RATE)
			{
				assert(channel_id->center_freq_index <= 68);
				ez_channel_id = channel_id->center_freq_index;
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_FREQ_DEV_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_FRAC_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_DECIMATION_CFG1_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_BCR_OSR_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_BCR_NCO_OFFSET_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_BCR_GAIN_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AFC_GAIN_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AFC_LIMITER_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AGC_RFPD_DECAY_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AGC_IFPD_DECAY_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_RAW_EYE_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE_0_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE_1_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE_0_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE_1_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_DSA_QUAL_433_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_CHANNEL_STEP_SIZE_433_LR);

			}
			else if(channel_id->channel_header.ch_class == PHY_CLASS_NORMAL_RATE)
			{
				assert(channel_id->center_freq_index % 8 == 0 && channel_id->center_freq_index <= 270);
				ez_channel_id = channel_id->center_freq_index / 8;

				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_FREQ_DEV_433_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_FRAC_433_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_BCR_NCO_OFFSET_433_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AFC_GAIN_433_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE_0_433_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE_1_433_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE_0_433_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE_1_433_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_CHANNEL_STEP_SIZE_433_NR);
			}
			else if(channel_id->channel_header.ch_class == PHY_CLASS_HI_RATE)
			{
				assert(channel_id->center_freq_index % 8 == 0 && channel_id->center_freq_index <= 56);
				ez_channel_id = channel_id->center_freq_index / 8;
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_DATA_RATE_433_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_FREQ_DEV_433_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_FRAC_433_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_BCR_NCO_OFFSET_433_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AFC_GAIN_433_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE_0_433_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE_1_433_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE_0_433_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE_1_433_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_CHANNEL_STEP_SIZE_433_HR);
			}

			DPRINT("Set channel freq index: %d", channel_id->center_freq_index);
			break;
		case PHY_BAND_868:
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CLKGEN_BAND_868);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_VCOCNT_RX_ADJ_868);
			ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_IF_FREQ_868);
			if(channel_id->channel_header.ch_class == PHY_CLASS_LO_RATE)
			{
				assert(channel_id->center_freq_index <= 279);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_FREQ_DEV_868_LR);

				ez_channel_id = channel_id->center_freq_index % 255;
				if ((uint8_t) (channel_id->center_freq_index / 255) == 0)
				{
					ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_FRAC_868_LR_01);
				} else
				{
					ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_FRAC_868_LR_02);
				}

				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_DECIMATION_CFG1_868_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_BCR_OSR_868_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_BCR_NCO_OFFSET_868_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_BCR_GAIN_868_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AFC_GAIN_868_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AFC_LIMITER_868_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AGC_RFPD_DECAY_868_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AGC_IFPD_DECAY_868_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_RAW_EYE_868_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE_0_868_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE_1_868_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE_0_868_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE_1_868_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_DSA_QUAL_868_LR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_CHANNEL_STEP_SIZE_868_LR);
			}
			else if(channel_id->channel_header.ch_class == PHY_CLASS_NORMAL_RATE)
			{
				assert(channel_id->center_freq_index % 8 == 0 && channel_id->center_freq_index <= 270);
				ez_channel_id = channel_id->center_freq_index / 8;

				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_FREQ_DEV_868_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_FRAC_868_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_BCR_NCO_OFFSET_868_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AFC_GAIN_868_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE_0_868_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE_1_868_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE_0_868_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE_1_868_NR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_CHANNEL_STEP_SIZE_868_NR);
			} else {
				assert(channel_id->center_freq_index % 8 == 0 && channel_id->center_freq_index <= 270);
				ez_channel_id = channel_id->center_freq_index / 8;

				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_DATA_RATE_868_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_FREQ_DEV_868_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_FRAC_868_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_BCR_NCO_OFFSET_868_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_AFC_GAIN_868_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE_0_868_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE_1_868_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE_0_868_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE_1_868_HR);
				ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_CHANNEL_STEP_SIZE_868_HR);
			}

			DPRINT("Set channel freq index: %d", channel_id->center_freq_index);
			break;
		case PHY_BAND_915:
			assert(false);

			break;

		}
	} else 	if (channel_id->center_freq_index != current_channel_id.center_freq_index)
	{
		DPRINT("configure center_freq_index: %d", channel_id->center_freq_index);
		switch(channel_id->channel_header.ch_freq_band)
		{
		// TODO calculate depending on rate and channr
		case PHY_BAND_433:
			if(channel_id->channel_header.ch_class == PHY_CLASS_LO_RATE)
			{
				assert(channel_id->center_freq_index <= 68);
				ez_channel_id = channel_id->center_freq_index;

			}
			else
			{
				assert(channel_id->center_freq_index % 8 == 0 && channel_id->center_freq_index <= 56);
				ez_channel_id = channel_id->center_freq_index / 8;
			}

			DPRINT("Set channel freq index: %d", channel_id->center_freq_index);
			break;
		case PHY_BAND_868:
			if(channel_id->channel_header.ch_class == PHY_CLASS_LO_RATE)
			{
				assert(channel_id->center_freq_index <= 279);
				ez_channel_id = channel_id->center_freq_index % 255;
				if ((uint8_t) (channel_id->center_freq_index / 255) == 0)
				{
					ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_FRAC_868_LR_01);
				} else
				{
					ezradio_set_property(RADIO_CONFIG_SET_PROPERTY_FREQ_CONTROL_FRAC_868_LR_02);
				}

			}
			else  {
				assert(channel_id->center_freq_index % 8 == 0 && channel_id->center_freq_index <= 272);
				ez_channel_id = channel_id->center_freq_index / 8;
			}

			DPRINT("Set channel freq index: %d", channel_id->center_freq_index);
			break;
		case PHY_BAND_915:
			assert(false);
			break;

		}

		current_channel_id.center_freq_index = channel_id->center_freq_index;
	}
}