Source code for ska_mid_dish_dcp_lib.device.b5dc_device_mappings

"""Band 5 Down-converter Enum mappings."""
import enum


[docs]class B5dcMappingException(Exception): """Mapping exception."""
[docs]class B5dcAttenuationBusy(Exception): """Exception used to indicate busy with attenuation configuration."""
[docs]class B5dcFrequencyBusy(Exception): """Exception used to indicate busy with frequency configuration."""
[docs]class B5dcPllState(enum.IntEnum): """Band 5 down-converter Phase lock loop state.""" LOCKED = 0 LOCKED_WITH_LOSS_DETECTED = 1 NOT_LOCKED = 2 NOT_LOCKED_WITH_LOSS_DETECTED = 3
[docs]class B5dcFrequency(enum.IntEnum): """Band 5 down-converter frequency options.""" F_11_1_GHZ = 1 F_13_2_GHZ = 2 F_13_86_GHZ = 3
[docs] def frequency_value_ghz(self) -> float: """Return the frequency in GHz based on the enum value.""" frequency_mapping = { B5dcFrequency.F_11_1_GHZ: 11.1, B5dcFrequency.F_13_2_GHZ: 13.2, B5dcFrequency.F_13_86_GHZ: 13.86, } return frequency_mapping[self]
PHOTODIODE_GAIN = 56.56 BUSY_CONF_MASK = 0x80 SPI_BUS_BUSY = 1 SPI_BUS_IDLE = 0
[docs]def map_rfcm_frequency_register(reg_val: int) -> float: """Get the frequency in GHz from the register value.""" # check if busy flag is set if (reg_val & BUSY_CONF_MASK) == BUSY_CONF_MASK: raise B5dcFrequencyBusy("Frequency configuration in progress.") try: freq_enum = B5dcFrequency(reg_val) value = freq_enum.frequency_value_ghz() except ValueError as exc: raise B5dcMappingException( f"Unknown rfcm_frequency mapping for register data: {reg_val}." ) from exc return value
[docs]def map_rfcm_pll_lock_register(reg_val: int) -> B5dcPllState: """Get the PLL status from the register value.""" if (reg_val & 0b11) == 0b11: return B5dcPllState.LOCKED_WITH_LOSS_DETECTED if (reg_val & 0b11) == 0b01: return B5dcPllState.LOCKED if (reg_val & 0b11) == 0b10: return B5dcPllState.NOT_LOCKED_WITH_LOSS_DETECTED # for other cases PLL not locked return B5dcPllState.NOT_LOCKED
[docs]def map_rfcm_attenuation_db(reg_val: int) -> float: """Get the attenuation value in dB from register value.""" # check if busy flag is set if (reg_val & BUSY_CONF_MASK) == BUSY_CONF_MASK: raise B5dcAttenuationBusy("Attenuation configuration in progress.") return reg_val / 2.0
[docs]def map_clk_photodiode_current_ma(reg_val: int) -> float: """Get the photodiode current in mA from register value.""" sense_voltage = 2.5 * reg_val / 4096.0 current = sense_voltage / PHOTODIODE_GAIN / 0.5 return current * 1000.0
[docs]def map_rf_power_in_dbm(reg_val: int) -> float: """Get the rf power in in dBm from register value.""" sense_voltage = 2.5 * reg_val / 4096.0 rf_in_power_dbm = 33.3334 * sense_voltage - 36.667 return rf_in_power_dbm
[docs]def map_if_power_out_dbm(reg_val: int) -> float: """Get the if power out in dBm from register value.""" sense_voltage = 2.5 * reg_val / 4096.0 rf_out_power_dbm = 26.667 * sense_voltage - 36.667 return rf_out_power_dbm
[docs]def map_temperature_degc(reg_val: int) -> float: """Get the temperature in deg C from register value.""" sense_voltage = 2.5 * reg_val / 4096.0 rf_temp = (sense_voltage - 1.8577) / (-11.77 * pow(10, -3)) return rf_temp
[docs]def map_spi_bus_busy(reg_val: int) -> bool: """Get the whether the spi bus is busy from register value.""" if reg_val == SPI_BUS_BUSY: return True if reg_val == SPI_BUS_IDLE: return False raise B5dcMappingException(f"Unknown mapping for spi_bus_lock value ({reg_val})")