From 412defae43137c90ecb7a80e10b9b06332e4e86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Silva?= Date: Sat, 1 Jun 2024 20:13:12 +0100 Subject: [PATCH] pmc: Completely remove floating point math MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Silva --- software/pmc/src/include/lt7182s.h | 188 ++++--- software/pmc/src/lt7182s.c | 767 ++++++++++++++++++++++------- software/pmc/src/main.c | 212 ++++---- software/pmc/src/printf/printf.c | 2 +- 4 files changed, 851 insertions(+), 318 deletions(-) diff --git a/software/pmc/src/include/lt7182s.h b/software/pmc/src/include/lt7182s.h index e4fe64a7..e9cba528 100644 --- a/software/pmc/src/include/lt7182s.h +++ b/software/pmc/src/include/lt7182s.h @@ -15,6 +15,8 @@ #define LT7182S_OPERATION_MARGIN_HIGH 0xA8 #define LT7182S_OPERATION_SEQUENCE_OFF 0x40 +#define LT7182S_DISABLE_FLOAT 1 + uint8_t lt7182s_init(); uint8_t lt7182s_read_mfr_id(char *pszBuffer, uint8_t ubBufferMaxSize); @@ -59,65 +61,139 @@ uint8_t lt7182s_get_on_off_config(uint8_t ubChannel); uint8_t lt7182s_set_on_off_config(uint8_t ubChannel, uint8_t ubConfig); uint16_t lt7182s_get_pwm_config(uint8_t ubChannel); uint8_t lt7182s_set_pwm_config(uint8_t ubChannel, uint16_t usConfig); -float lt7182s_get_pwm_phase(uint8_t ubChannel); -uint8_t lt7182s_set_pwm_phase(uint8_t ubChannel, float fPhase); - -float l17182s_pwm_config_parse_gmea(uint16_t usPWMConfig); // uS -float l17182s_pwm_config_parse_pos_ilim(uint16_t usPWMConfig); // A -float l17182s_pwm_config_parse_neg_ilim(uint16_t usPWMConfig); // A -float l17182s_pwm_config_parse_cith(uint16_t usPWMConfig); // pF -float l17182s_pwm_config_parse_rith(uint16_t usPWMConfig); // kOhm +#ifndef LT7182S_DISABLE_FLOAT +float lt7182s_getf_pwm_phase(uint8_t ubChannel); // deg +uint8_t lt7182s_setf_pwm_phase(uint8_t ubChannel, float fPhase); // deg +#endif +uint32_t lt7182s_get_pwm_phase(uint8_t ubChannel); // m deg +uint8_t lt7182s_set_pwm_phase(uint8_t ubChannel, uint32_t ulPhase); // m deg + +#ifndef LT7182S_DISABLE_FLOAT +float l17182s_pwm_config_parsef_gmea(uint16_t usPWMConfig); // uS +float l17182s_pwm_config_parsef_pos_ilim(uint16_t usPWMConfig); // A +float l17182s_pwm_config_parsef_neg_ilim(uint16_t usPWMConfig); // A +float l17182s_pwm_config_parsef_cith(uint16_t usPWMConfig); // pF +float l17182s_pwm_config_parsef_rith(uint16_t usPWMConfig); // kOhm +#endif +uint32_t l17182s_pwm_config_parse_gmea(uint16_t usPWMConfig); // nS +uint16_t l17182s_pwm_config_parse_pos_ilim(uint16_t usPWMConfig); // mA +int16_t l17182s_pwm_config_parse_neg_ilim(uint16_t usPWMConfig); // mA +uint8_t l17182s_pwm_config_parse_cith(uint16_t usPWMConfig); // pF +uint8_t l17182s_pwm_config_parse_rith(uint16_t usPWMConfig); // kOhm uint8_t l17182s_pwm_config_parse_pulse_skipping(uint16_t usPWMConfig); uint8_t l17182s_pwm_config_parse_fcm_at_toff(uint16_t usPWMConfig); uint8_t l17182s_pwm_config_parse_low_vout_mode(uint16_t usPWMConfig); -float lt7182s_read_vin(uint8_t ubChannel); -float lt7182s_read_vin_peak(uint8_t ubChannel); -float lt7182s_get_vin_on(uint8_t ubChannel); -uint8_t lt7182s_set_vin_on(uint8_t ubChannel, float fVoltage); -float lt7182s_get_vin_off(uint8_t ubChannel); -uint8_t lt7182s_set_vin_off(uint8_t ubChannel, float fVoltage); -float lt7182s_get_vin_uv_warn(uint8_t ubChannel); -uint8_t lt7182s_set_vin_uv_warn(uint8_t ubChannel, float fVoltage); -float lt7182s_read_iin(uint8_t ubChannel); -float lt7182s_get_iin_oc_warn(uint8_t ubChannel); -uint8_t lt7182s_set_iin_oc_warn(uint8_t ubChannel, float fCurrent); -float lt7182s_read_vout(uint8_t ubChannel); -float lt7182s_read_vout_peak(uint8_t ubChannel); -float lt7182s_get_vout(uint8_t ubChannel); -uint8_t lt7182s_set_vout(uint8_t ubChannel, float fVoltage); -float lt7182s_get_vout_max(uint8_t ubChannel); -uint8_t lt7182s_set_vout_max(uint8_t ubChannel, float fVoltage); -float lt7182s_get_vout_margin_high(uint8_t ubChannel); -uint8_t lt7182s_set_vout_margin_high(uint8_t ubChannel, float fVoltage); -float lt7182s_get_vout_margin_low(uint8_t ubChannel); -uint8_t lt7182s_set_vout_margin_low(uint8_t ubChannel, float fVoltage); -float lt7182s_get_vout_transition_rate(uint8_t ubChannel); -uint8_t lt7182s_set_vout_transition_rate(uint8_t ubChannel, float fRate); -float lt7182s_get_vout_ov_fault(uint8_t ubChannel); -uint8_t lt7182s_set_vout_ov_fault(uint8_t ubChannel, float fVoltage); -float lt7182s_get_vout_ov_warn(uint8_t ubChannel); -uint8_t lt7182s_set_vout_ov_warn(uint8_t ubChannel, float fVoltage); -float lt7182s_get_vout_uv_fault(uint8_t ubChannel); -uint8_t lt7182s_set_vout_uv_fault(uint8_t ubChannel, float fVoltage); -float lt7182s_get_vout_uv_warn(uint8_t ubChannel); -uint8_t lt7182s_set_vout_uv_warn(uint8_t ubChannel, float fVoltage); -float lt7182s_read_iout(uint8_t ubChannel); -float lt7182s_read_iout_peak(uint8_t ubChannel); -float lt7182s_get_iout_oc_warn(uint8_t ubChannel); -uint8_t lt7182s_set_iout_oc_warn(uint8_t ubChannel, float fCurrent); -float lt7182s_read_freq(uint8_t ubChannel); -float lt7182s_read_pout(uint8_t ubChannel); -float lt7182s_read_ith(uint8_t ubChannel); - -float lt7182s_read_extvcc(); -float lt7182s_read_temperature(); -float lt7182s_read_temperature_peak(); -float lt7182s_get_ot_fault(); -uint8_t lt7182s_set_ot_fault(float fTemperature); -float lt7182s_get_ot_warn(); -uint8_t lt7182s_set_ot_warn(float fTemperature); -float lt7182s_get_freq(); -uint8_t lt7182s_set_freq(float fFrequency); +#ifndef LT7182S_DISABLE_FLOAT +float lt7182s_readf_vin(uint8_t ubChannel); // V +float lt7182s_readf_vin_peak(uint8_t ubChannel); // V +float lt7182s_getf_vin_on(uint8_t ubChannel); // V +uint8_t lt7182s_setf_vin_on(uint8_t ubChannel, float fVoltage); // V +float lt7182s_getf_vin_off(uint8_t ubChannel); // V +uint8_t lt7182s_setf_vin_off(uint8_t ubChannel, float fVoltage); // V +float lt7182s_getf_vin_uv_warn(uint8_t ubChannel); // V +uint8_t lt7182s_setf_vin_uv_warn(uint8_t ubChannel, float fVoltage); // V +#endif +uint16_t lt7182s_read_vin(uint8_t ubChannel); // mV +uint16_t lt7182s_read_vin_peak(uint8_t ubChannel); // mV +uint16_t lt7182s_get_vin_on(uint8_t ubChannel); // mV +uint8_t lt7182s_set_vin_on(uint8_t ubChannel, uint16_t usVoltage); // mV +uint16_t lt7182s_get_vin_off(uint8_t ubChannel); // mV +uint8_t lt7182s_set_vin_off(uint8_t ubChannel, uint16_t usVoltage); // mV +int16_t lt7182s_get_vin_uv_warn(uint8_t ubChannel); // mV +uint8_t lt7182s_set_vin_uv_warn(uint8_t ubChannel, int16_t sVoltage); // mV + +#ifndef LT7182S_DISABLE_FLOAT +float lt7182s_readf_iin(uint8_t ubChannel); // A +float lt7182s_getf_iin_oc_warn(uint8_t ubChannel); // A +uint8_t lt7182s_setf_iin_oc_warn(uint8_t ubChannel, float fCurrent); // A +#endif +uint16_t lt7182s_read_iin(uint8_t ubChannel); // mA +uint16_t lt7182s_get_iin_oc_warn(uint8_t ubChannel); // mA +uint8_t lt7182s_set_iin_oc_warn(uint8_t ubChannel, uint16_t usCurrent); // mA + +#ifndef LT7182S_DISABLE_FLOAT +float lt7182s_readf_vout(uint8_t ubChannel); // V +float lt7182s_readf_vout_peak(uint8_t ubChannel); // V +float lt7182s_getf_vout(uint8_t ubChannel); // V +uint8_t lt7182s_setf_vout(uint8_t ubChannel, float fVoltage); // V +float lt7182s_getf_vout_max(uint8_t ubChannel); // V +uint8_t lt7182s_setf_vout_max(uint8_t ubChannel, float fVoltage); // V +float lt7182s_getf_vout_margin_high(uint8_t ubChannel); // V +uint8_t lt7182s_setf_vout_margin_high(uint8_t ubChannel, float fVoltage); // V +float lt7182s_getf_vout_margin_low(uint8_t ubChannel); // V +uint8_t lt7182s_setf_vout_margin_low(uint8_t ubChannel, float fVoltage); // V +float lt7182s_getf_vout_transition_rate(uint8_t ubChannel); // V/ms +uint8_t lt7182s_setf_vout_transition_rate(uint8_t ubChannel, float fRate); // V/ms +float lt7182s_getf_vout_ov_fault(uint8_t ubChannel); // V +uint8_t lt7182s_setf_vout_ov_fault(uint8_t ubChannel, float fVoltage); // V +float lt7182s_getf_vout_ov_warn(uint8_t ubChannel); // V +uint8_t lt7182s_setf_vout_ov_warn(uint8_t ubChannel, float fVoltage); // V +float lt7182s_getf_vout_uv_fault(uint8_t ubChannel); // V +uint8_t lt7182s_setf_vout_uv_fault(uint8_t ubChannel, float fVoltage); // V +float lt7182s_getf_vout_uv_warn(uint8_t ubChannel); // V +uint8_t lt7182s_setf_vout_uv_warn(uint8_t ubChannel, float fVoltage); // V +#endif +uint16_t lt7182s_read_vout(uint8_t ubChannel); // mV +uint16_t lt7182s_read_vout_peak(uint8_t ubChannel); // mV +uint16_t lt7182s_get_vout(uint8_t ubChannel); // mV +uint8_t lt7182s_set_vout(uint8_t ubChannel, uint16_t usVoltage); // mV +uint16_t lt7182s_get_vout_max(uint8_t ubChannel); // mV +uint8_t lt7182s_set_vout_max(uint8_t ubChannel, uint16_t usVoltage); // mV +uint16_t lt7182s_get_vout_margin_high(uint8_t ubChannel); // mV +uint8_t lt7182s_set_vout_margin_high(uint8_t ubChannel, uint16_t usVoltage); // mV +uint16_t lt7182s_get_vout_margin_low(uint8_t ubChannel); // mV +uint8_t lt7182s_set_vout_margin_low(uint8_t ubChannel, uint16_t usVoltage); // mV +uint16_t lt7182s_get_vout_transition_rate(uint8_t ubChannel); // mV/ms +uint8_t lt7182s_set_vout_transition_rate(uint8_t ubChannel, uint16_t usRate); // mV/ms +uint16_t lt7182s_get_vout_ov_fault(uint8_t ubChannel); // mV +uint8_t lt7182s_set_vout_ov_fault(uint8_t ubChannel, uint16_t usVoltage); // mV +uint16_t lt7182s_get_vout_ov_warn(uint8_t ubChannel); // mV +uint8_t lt7182s_set_vout_ov_warn(uint8_t ubChannel, uint16_t usVoltage); // mV +uint16_t lt7182s_get_vout_uv_fault(uint8_t ubChannel); // mV +uint8_t lt7182s_set_vout_uv_fault(uint8_t ubChannel, uint16_t usVoltage); // mV +uint16_t lt7182s_get_vout_uv_warn(uint8_t ubChannel); // mV +uint8_t lt7182s_set_vout_uv_warn(uint8_t ubChannel, uint16_t usVoltage); // mV + +#ifndef LT7182S_DISABLE_FLOAT +float lt7182s_readf_iout(uint8_t ubChannel); // A +float lt7182s_readf_iout_peak(uint8_t ubChannel); // A +float lt7182s_getf_iout_oc_warn(uint8_t ubChannel); // A +uint8_t lt7182s_setf_iout_oc_warn(uint8_t ubChannel, float fCurrent); // A +#endif +uint16_t lt7182s_read_iout(uint8_t ubChannel); // mA +uint16_t lt7182s_read_iout_peak(uint8_t ubChannel); // mA +uint16_t lt7182s_get_iout_oc_warn(uint8_t ubChannel); // mA +uint8_t lt7182s_set_iout_oc_warn(uint8_t ubChannel, uint16_t usCurrent); // mA + +#ifndef LT7182S_DISABLE_FLOAT +float lt7182s_readf_freq(uint8_t ubChannel); // kHz +float lt7182s_readf_pout(uint8_t ubChannel); // W +float lt7182s_readf_ith(uint8_t ubChannel); // V +#endif +uint32_t lt7182s_read_freq(uint8_t ubChannel); // Hz +uint16_t lt7182s_read_pout(uint8_t ubChannel); // mW +uint16_t lt7182s_read_ith(uint8_t ubChannel); // mV + +#ifndef LT7182S_DISABLE_FLOAT +float lt7182s_readf_extvcc(); // V +float lt7182s_readf_temperature(); // degC +float lt7182s_readf_temperature_peak(); // degC +float lt7182s_getf_ot_fault(); // degC +uint8_t lt7182s_setf_ot_fault(float fTemperature); // degC +float lt7182s_getf_ot_warn(); // degC +uint8_t lt7182s_setf_ot_warn(float fTemperature); // degC +float lt7182s_getf_freq(); // kHz +uint8_t lt7182s_setf_freq(float fFrequency); // kHz +#endif +uint16_t lt7182s_read_extvcc(); // mV +int32_t lt7182s_read_temperature(); // m degC +int32_t lt7182s_read_temperature_peak(); // m degC +int32_t lt7182s_get_ot_fault(); // m degC +uint8_t lt7182s_set_ot_fault(int32_t lTemperature); // m degC +int32_t lt7182s_get_ot_warn(); // m degC +uint8_t lt7182s_set_ot_warn(int32_t lTemperature); // m degC +uint32_t lt7182s_get_freq(); // Hz +uint8_t lt7182s_set_freq(uint32_t ulFrequency); // Hz #endif // __LT7182S_H__ \ No newline at end of file diff --git a/software/pmc/src/lt7182s.c b/software/pmc/src/lt7182s.c index 1b45f9ef..5b700c1c 100644 --- a/software/pmc/src/lt7182s.c +++ b/software/pmc/src/lt7182s.c @@ -1,5 +1,6 @@ #include "lt7182s.h" +#ifndef LT7182S_DISABLE_FLOAT static float lt7182s_pow2f(int8_t bExp) { switch(bExp) @@ -72,32 +73,6 @@ static float lt7182s_pow2f(int8_t bExp) return 0.f; } -static uint64_t lt7182s_pow2ull1e9(int8_t bExp) // Full precision for bExp in range [-9, 15], lower precision for bExp in range [-16, -10] -{ - if(bExp < -16 || bExp > 15) - return 0; - - switch(bExp) - { - case -16: - return 15259ULL; - case -15: - return 30518ULL; - case -14: - return 61035ULL; - case -13: - return 122070ULL; - case -12: - return 244141ULL; - case -11: - return 488281ULL; - case -10: - return 976563ULL; - default: - return 1953125ULL << (bExp + 9); - } -} - static float lt7182s_from_l11f(uint16_t usData) { int8_t bExp = (usData >> 11) & 0xF; @@ -112,20 +87,46 @@ static float lt7182s_from_l11f(uint16_t usData) return (float)sMant * lt7182s_pow2f(bExp); } -static int64_t lt7182s_from_l11ll1e9(uint16_t usData) // NOT full precision +#endif +static int64_t lt7182s_from_l11ll1e9(uint16_t usData) { - int8_t bExp = (usData >> 11) & 0xF; + uint8_t ubExp = (usData >> 11) & 0xF; + uint16_t usMant = usData & 0x3FF; + int8_t bSign; + uint64_t ullVal; + + if(usData & BIT(10)) + { + bSign = -1; + ullVal = (uint64_t)((usMant ^ 0x3FF) + 1) * 1000000000ULL; + } + else + { + bSign = 1; + ullVal = (uint64_t)usMant * 1000000000ULL; + } if(usData & BIT(15)) - bExp = -1 * (bExp ^ 0xF) - 1; + { + ubExp = (ubExp ^ 0xF) + 1; - int16_t sMant = usData & 0x3FF; + if(ubExp > 1) + ullVal >>= ubExp - 1; // Divide by two n-1 times - if(usData & BIT(10)) - sMant = -1 * (sMant ^ 0x3FF) - 1; + if(ubExp) + { + ullVal++; // Round on the last division + ullVal >>= 1; // Do the last division + } + } + else + { + ullVal <<= ubExp; + } - return (int64_t)sMant * (int64_t)lt7182s_pow2ull1e9(bExp); + return (int64_t)ullVal * bSign; } +#ifndef LT7182S_DISABLE_FLOAT static uint16_t lt7182s_to_l11f(float fData) { int8_t bExp = -16; @@ -134,59 +135,57 @@ static uint16_t lt7182s_to_l11f(float fData) // Search for an exponent that produces valid 11-bit mantissa do { - if(lMant >= -512 && lMant <= 511) + if(lMant >= -1024 && lMant <= 1023) break; lMant = (int32_t)(fData / lt7182s_pow2f(++bExp)); } while(bExp < 15); - if(lMant < -512 || lMant > 511) + if(lMant < -1024 || lMant > 1023) return 0; - if(bExp < -16 || bExp > 15) - return 0; - - uint16_t usExp = bExp << 11; - uint16_t usMant = lMant & 0x07FF; - - return usExp | usMant; + return ((uint16_t)bExp << 11) | (lMant & 0x07FF); } -static uint16_t lt7182s_to_l11ll1e9(int64_t llData) // NOT full precision +#endif +static uint16_t lt7182s_to_l11ll1e9(int64_t llData) { - int8_t bExp = -16; - int64_t p = lt7182s_pow2ull1e9(bExp); - int32_t lMant = (int32_t)DIV_ROUND(llData, p); + uint64_t ullData = llData < 0 ? (uint64_t)(-1 * llData) : (uint64_t)llData; + int8_t bExp = 15; + uint16_t usMant = DIV_ROUND(ullData >> 15, 1000000000ULL); // Search for an exponent that produces valid 11-bit mantissa do { - if(lMant >= -512 && lMant <= 511) + if(usMant >= 512 && usMant < 1024) break; - p = lt7182s_pow2ull1e9(++bExp); - lMant = (int32_t)DIV_ROUND(llData, p); - } while(bExp < 15); + bExp--; - if(lMant < -512 || lMant > 511) - return 0; + if(bExp < 0) + usMant = DIV_ROUND(ullData << -bExp, 1000000000ULL); + else + usMant = DIV_ROUND(ullData >> bExp, 1000000000ULL); + } while(bExp >= -16); - if(bExp < -16 || bExp > 15) - return 0; + int16_t sMant = llData < 0 ? (-1 * (int16_t)usMant) : (int16_t)usMant; - uint16_t usExp = bExp << 11; - uint16_t usMant = lMant & 0x07FF; + if(sMant < -1024 || sMant > 1023) + return 0; - return usExp | usMant; + return ((uint16_t)bExp << 11) | (sMant & 0x07FF); } +#ifndef LT7182S_DISABLE_FLOAT static float lt7182s_from_ul16f(uint16_t usData) { return (float)usData / 4096.f; } -static uint64_t lt7182s_from_ul16ull1e12(uint16_t usData) // Full precision +#endif +static uint64_t lt7182s_from_ul16ull1e12(uint16_t usData) { return (uint64_t)usData * 1000000000000ULL / 4096ULL; } +#ifndef LT7182S_DISABLE_FLOAT static uint16_t lt7182s_to_ul16f(float fData) { if(fData < 0.f || fData > 16.f) @@ -194,7 +193,8 @@ static uint16_t lt7182s_to_ul16f(float fData) return (uint16_t)(fData * 4096.f); } -static uint16_t lt7182s_to_ul16ull1e12(uint64_t ullData) // Full precision +#endif +static uint16_t lt7182s_to_ul16ull1e12(uint64_t ullData) { return (uint16_t)(ullData * 4096ULL / 1000000000000ULL); } @@ -258,14 +258,24 @@ static uint8_t lt7182s_pmbus_write_dword(uint8_t ubCommand, uint32_t ulData) return 1; } -static uint8_t lt7182s_pmbus_write_l11(uint8_t ubCommand, float fData) +#ifndef LT7182S_DISABLE_FLOAT +static uint8_t lt7182s_pmbus_write_l11f(uint8_t ubCommand, float fData) { return lt7182s_pmbus_write_word(ubCommand, lt7182s_to_l11f(fData)); } -static uint8_t lt7182s_pmbus_write_ul16(uint8_t ubCommand, float fData) +static uint8_t lt7182s_pmbus_write_ul16f(uint8_t ubCommand, float fData) { return lt7182s_pmbus_write_word(ubCommand, lt7182s_to_ul16f(fData)); } +#endif +static uint8_t lt7182s_pmbus_write_l11(uint8_t ubCommand, int64_t llData) +{ + return lt7182s_pmbus_write_word(ubCommand, lt7182s_to_l11ll1e9(llData)); +} +static uint8_t lt7182s_pmbus_write_ul16(uint8_t ubCommand, uint64_t ullData) +{ + return lt7182s_pmbus_write_word(ubCommand, lt7182s_to_ul16ull1e12(ullData)); +} static uint8_t lt7182s_pmbus_read_byte(uint8_t ubCommand) { uint8_t ubTemp; @@ -311,14 +321,24 @@ static uint32_t lt7182s_pmbus_read_dword(uint8_t ubCommand) return (((uint32_t)ubTemp[3]) << 24) | (((uint32_t)ubTemp[2]) << 16) | (((uint32_t)ubTemp[1]) << 8) | ubTemp[0]; } -static float lt7182s_pmbus_read_l11(uint8_t ubCommand) +#ifndef LT7182S_DISABLE_FLOAT +static float lt7182s_pmbus_read_l11f(uint8_t ubCommand) { return lt7182s_from_l11f(lt7182s_pmbus_read_word(ubCommand)); } -static float lt7182s_pmbus_read_ul16(uint8_t ubCommand) +static float lt7182s_pmbus_read_ul16f(uint8_t ubCommand) { return lt7182s_from_ul16f(lt7182s_pmbus_read_word(ubCommand)); } +#endif +static int64_t lt7182s_pmbus_read_l11(uint8_t ubCommand) +{ + return lt7182s_from_l11ll1e9(lt7182s_pmbus_read_word(ubCommand)); +} +static uint64_t lt7182s_pmbus_read_ul16(uint8_t ubCommand) +{ + return lt7182s_from_ul16ull1e12(lt7182s_pmbus_read_word(ubCommand)); +} static uint8_t lt7182s_pmbus_read_block(uint8_t ubCommand, uint8_t *pubBuffer, uint8_t ubBufferMaxSize) { uint8_t ubTemp[256]; // Max PMBus block read size @@ -603,14 +623,15 @@ uint8_t lt7182s_set_pwm_config(uint8_t ubChannel, uint16_t usConfig) return lt7182s_pmbus_write_word(0xD4, usConfig & 0x3FFF); } -float lt7182s_get_pwm_phase(uint8_t ubChannel) +#ifndef LT7182S_DISABLE_FLOAT +float lt7182s_getf_pwm_phase(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_read_l11(0xF5); + return lt7182s_pmbus_read_l11f(0xF5); } -uint8_t lt7182s_set_pwm_phase(uint8_t ubChannel, float fPhase) +uint8_t lt7182s_setf_pwm_phase(uint8_t ubChannel, float fPhase) { if(!lt7182s_select_page(ubChannel)) return 0; @@ -618,10 +639,29 @@ uint8_t lt7182s_set_pwm_phase(uint8_t ubChannel, float fPhase) while(fPhase >= 360) fPhase -= 360; - return lt7182s_pmbus_write_l11(0xF5, fPhase); + return lt7182s_pmbus_write_l11f(0xF5, fPhase); +} +#endif +uint32_t lt7182s_get_pwm_phase(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_l11(0xF5), 1000000ULL); // m deg +} +uint8_t lt7182s_set_pwm_phase(uint8_t ubChannel, uint32_t ulPhase) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + while(ulPhase >= 360000) + ulPhase -= 360000; + + return lt7182s_pmbus_write_l11(0xF5, (uint64_t)ulPhase * 1000000ULL); // m deg } -float l17182s_pwm_config_parse_gmea(uint16_t usPWMConfig) +#ifndef LT7182S_DISABLE_FLOAT +float l17182s_pwm_config_parsef_gmea(uint16_t usPWMConfig) { switch(usPWMConfig & 0x3800) { @@ -643,7 +683,7 @@ float l17182s_pwm_config_parse_gmea(uint16_t usPWMConfig) return (usPWMConfig & BIT(1)) ? 1200.f : 300.f; } } -float l17182s_pwm_config_parse_pos_ilim(uint16_t usPWMConfig) +float l17182s_pwm_config_parsef_pos_ilim(uint16_t usPWMConfig) { switch(usPWMConfig & 0x0600) { @@ -657,7 +697,7 @@ float l17182s_pwm_config_parse_pos_ilim(uint16_t usPWMConfig) return 8.5f; } } -float l17182s_pwm_config_parse_neg_ilim(uint16_t usPWMConfig) +float l17182s_pwm_config_parsef_neg_ilim(uint16_t usPWMConfig) { switch(usPWMConfig & 0x0600) { @@ -671,11 +711,11 @@ float l17182s_pwm_config_parse_neg_ilim(uint16_t usPWMConfig) return -4.25f; } } -float l17182s_pwm_config_parse_cith(uint16_t usPWMConfig) +float l17182s_pwm_config_parsef_cith(uint16_t usPWMConfig) { return (((usPWMConfig & 0x01C0) >> 6) + 1) * 10.f; } -float l17182s_pwm_config_parse_rith(uint16_t usPWMConfig) +float l17182s_pwm_config_parsef_rith(uint16_t usPWMConfig) { switch(usPWMConfig & 0x0038) { @@ -697,6 +737,83 @@ float l17182s_pwm_config_parse_rith(uint16_t usPWMConfig) return 120.f; } } +#endif +uint32_t l17182s_pwm_config_parse_gmea(uint16_t usPWMConfig) +{ + switch(usPWMConfig & 0x3800) + { + case 0x0000: + return (usPWMConfig & BIT(1)) ? 150000 : 37500; + case 0x0800: + return (usPWMConfig & BIT(1)) ? 300000 : 75000; + case 0x1000: + return (usPWMConfig & BIT(1)) ? 450000 : 112500; + case 0x1800: + return (usPWMConfig & BIT(1)) ? 600000 : 150000; + case 0x2000: + return (usPWMConfig & BIT(1)) ? 750000 : 187500; + case 0x2800: + return (usPWMConfig & BIT(1)) ? 900000 : 225000; + case 0x3000: + return (usPWMConfig & BIT(1)) ? 1050000 : 262500; + case 0x3800: + return (usPWMConfig & BIT(1)) ? 1200000 : 300000; + } +} +uint16_t l17182s_pwm_config_parse_pos_ilim(uint16_t usPWMConfig) +{ + switch(usPWMConfig & 0x0600) + { + case 0x0000: + return 3000; + case 0x0200: + return 4500; + case 0x0400: + return 6500; + case 0x0600: + return 8500; + } +} +int16_t l17182s_pwm_config_parse_neg_ilim(uint16_t usPWMConfig) +{ + switch(usPWMConfig & 0x0600) + { + case 0x0000: + return -2300; + case 0x0200: + return -3400; + case 0x0400: + return -4000; + case 0x0600: + return -4250; + } +} +uint8_t l17182s_pwm_config_parse_cith(uint16_t usPWMConfig) +{ + return (((usPWMConfig & 0x01C0) >> 6) + 1) * 10; +} +uint8_t l17182s_pwm_config_parse_rith(uint16_t usPWMConfig) +{ + switch(usPWMConfig & 0x0038) + { + case 0x0000: + return 5; + case 0x0008: + return 10; + case 0x0010: + return 20; + case 0x0018: + return 40; + case 0x0020: + return 60; + case 0x0028: + return 80; + case 0x0030: + return 100; + case 0x0038: + return 120; + } +} uint8_t l17182s_pwm_config_parse_pulse_skipping(uint16_t usPWMConfig) { return !!(usPWMConfig & BIT(0)); @@ -710,306 +827,624 @@ uint8_t l17182s_pwm_config_parse_low_vout_mode(uint16_t usPWMConfig) return !!(usPWMConfig & BIT(1)); } -float lt7182s_read_vin(uint8_t ubChannel) +#ifndef LT7182S_DISABLE_FLOAT +float lt7182s_readf_vin(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_l11(0x88); + return lt7182s_pmbus_read_l11f(0x88); } -float lt7182s_read_vin_peak(uint8_t ubChannel) +float lt7182s_readf_vin_peak(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_l11(0xDE); + return lt7182s_pmbus_read_l11f(0xDE); } -float lt7182s_get_vin_on(uint8_t ubChannel) +float lt7182s_getf_vin_on(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_l11(0x35); + return lt7182s_pmbus_read_l11f(0x35); } -uint8_t lt7182s_set_vin_on(uint8_t ubChannel, float fVoltage) +uint8_t lt7182s_setf_vin_on(uint8_t ubChannel, float fVoltage) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_write_l11(0x35, fVoltage); + return lt7182s_pmbus_write_l11f(0x35, fVoltage); } -float lt7182s_get_vin_off(uint8_t ubChannel) +float lt7182s_getf_vin_off(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_l11(0x36); + return lt7182s_pmbus_read_l11f(0x36); } -uint8_t lt7182s_set_vin_off(uint8_t ubChannel, float fVoltage) +uint8_t lt7182s_setf_vin_off(uint8_t ubChannel, float fVoltage) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_write_l11(0x36, fVoltage); + return lt7182s_pmbus_write_l11f(0x36, fVoltage); } -float lt7182s_get_vin_uv_warn(uint8_t ubChannel) +float lt7182s_getf_vin_uv_warn(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_l11(0x58); + return lt7182s_pmbus_read_l11f(0x58); +} +uint8_t lt7182s_setf_vin_uv_warn(uint8_t ubChannel, float fVoltage) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_l11f(0x58, fVoltage); +} +#endif +uint16_t lt7182s_read_vin(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_l11(0x88), 1000000ULL); // mV +} +uint16_t lt7182s_read_vin_peak(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_l11(0xDE), 1000000ULL); // mV } -uint8_t lt7182s_set_vin_uv_warn(uint8_t ubChannel, float fVoltage) +uint16_t lt7182s_get_vin_on(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_write_l11(0x58, fVoltage); + return DIV_ROUND(lt7182s_pmbus_read_l11(0x35), 1000000ULL); // mV } -float lt7182s_read_iin(uint8_t ubChannel) +uint8_t lt7182s_set_vin_on(uint8_t ubChannel, uint16_t usVoltage) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_l11(0x35, (uint64_t)usVoltage * 1000000ULL); // mV +} +uint16_t lt7182s_get_vin_off(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_l11(0x36), 1000000ULL); // mV +} +uint8_t lt7182s_set_vin_off(uint8_t ubChannel, uint16_t usVoltage) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_l11(0x36, (uint64_t)usVoltage * 1000000ULL); // mV +} +int16_t lt7182s_get_vin_uv_warn(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_l11(0x58), 1000000LL); // mV +} +uint8_t lt7182s_set_vin_uv_warn(uint8_t ubChannel, int16_t sVoltage) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_l11(0x58, (int64_t)sVoltage * 1000000LL); // mV +} + +#ifndef LT7182S_DISABLE_FLOAT +float lt7182s_readf_iin(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_l11(0x89); + return lt7182s_pmbus_read_l11f(0x89); } -float lt7182s_get_iin_oc_warn(uint8_t ubChannel) +float lt7182s_getf_iin_oc_warn(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_l11(0x5D); + return lt7182s_pmbus_read_l11f(0x5D); +} +uint8_t lt7182s_setf_iin_oc_warn(uint8_t ubChannel, float fCurrent) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_l11f(0x5D, fCurrent); } -uint8_t lt7182s_set_iin_oc_warn(uint8_t ubChannel, float fCurrent) +#endif +uint16_t lt7182s_read_iin(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_write_l11(0x5D, fCurrent); + return DIV_ROUND(lt7182s_pmbus_read_l11(0x89), 1000000ULL); // mA } -float lt7182s_read_vout(uint8_t ubChannel) +uint16_t lt7182s_get_iin_oc_warn(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_l11(0x5D), 1000000ULL); // mA +} +uint8_t lt7182s_set_iin_oc_warn(uint8_t ubChannel, uint16_t usCurrent) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_l11(0x5D, (uint64_t)usCurrent * 1000000ULL); // mA +} + +#ifndef LT7182S_DISABLE_FLOAT +float lt7182s_readf_vout(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_ul16(0x8B); + return lt7182s_pmbus_read_ul16f(0x8B); } -float lt7182s_read_vout_peak(uint8_t ubChannel) +float lt7182s_readf_vout_peak(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_ul16(0xDD); + return lt7182s_pmbus_read_ul16f(0xDD); } -float lt7182s_get_vout(uint8_t ubChannel) +float lt7182s_getf_vout(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_ul16(0x21); + return lt7182s_pmbus_read_ul16f(0x21); } -uint8_t lt7182s_set_vout(uint8_t ubChannel, float fVoltage) +uint8_t lt7182s_setf_vout(uint8_t ubChannel, float fVoltage) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_write_ul16(0x21, fVoltage); + return lt7182s_pmbus_write_ul16f(0x21, fVoltage); } -float lt7182s_get_vout_max(uint8_t ubChannel) +float lt7182s_getf_vout_max(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_ul16(0x24); + return lt7182s_pmbus_read_ul16f(0x24); } -uint8_t lt7182s_set_vout_max(uint8_t ubChannel, float fVoltage) +uint8_t lt7182s_setf_vout_max(uint8_t ubChannel, float fVoltage) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_write_ul16(0x24, fVoltage); + return lt7182s_pmbus_write_ul16f(0x24, fVoltage); } -float lt7182s_get_vout_margin_high(uint8_t ubChannel) +float lt7182s_getf_vout_margin_high(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_ul16(0x25); + return lt7182s_pmbus_read_ul16f(0x25); } -uint8_t lt7182s_set_vout_margin_high(uint8_t ubChannel, float fVoltage) +uint8_t lt7182s_setf_vout_margin_high(uint8_t ubChannel, float fVoltage) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_write_ul16(0x25, fVoltage); + return lt7182s_pmbus_write_ul16f(0x25, fVoltage); } -float lt7182s_get_vout_margin_low(uint8_t ubChannel) +float lt7182s_getf_vout_margin_low(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_ul16(0x26); + return lt7182s_pmbus_read_ul16f(0x26); } -uint8_t lt7182s_set_vout_margin_low(uint8_t ubChannel, float fVoltage) +uint8_t lt7182s_setf_vout_margin_low(uint8_t ubChannel, float fVoltage) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_write_ul16(0x26, fVoltage); + return lt7182s_pmbus_write_ul16f(0x26, fVoltage); } -float lt7182s_get_vout_transition_rate(uint8_t ubChannel) +float lt7182s_getf_vout_transition_rate(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_l11(0x27); + return lt7182s_pmbus_read_l11f(0x27); } -uint8_t lt7182s_set_vout_transition_rate(uint8_t ubChannel, float fRate) +uint8_t lt7182s_setf_vout_transition_rate(uint8_t ubChannel, float fRate) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_write_l11(0x27, fRate); + return lt7182s_pmbus_write_l11f(0x27, fRate); } -float lt7182s_get_vout_ov_fault(uint8_t ubChannel) +float lt7182s_getf_vout_ov_fault(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_ul16(0x40); + return lt7182s_pmbus_read_ul16f(0x40); } -uint8_t lt7182s_set_vout_ov_fault(uint8_t ubChannel, float fVoltage) +uint8_t lt7182s_setf_vout_ov_fault(uint8_t ubChannel, float fVoltage) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_write_ul16(0x40, fVoltage); + return lt7182s_pmbus_write_ul16f(0x40, fVoltage); } -float lt7182s_get_vout_ov_warn(uint8_t ubChannel) +float lt7182s_getf_vout_ov_warn(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_ul16(0x42); + return lt7182s_pmbus_read_ul16f(0x42); } -uint8_t lt7182s_set_vout_ov_warn(uint8_t ubChannel, float fVoltage) +uint8_t lt7182s_setf_vout_ov_warn(uint8_t ubChannel, float fVoltage) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_write_ul16(0x42, fVoltage); + return lt7182s_pmbus_write_ul16f(0x42, fVoltage); } -float lt7182s_get_vout_uv_fault(uint8_t ubChannel) +float lt7182s_getf_vout_uv_fault(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_ul16(0x44); + return lt7182s_pmbus_read_ul16f(0x44); } -uint8_t lt7182s_set_vout_uv_fault(uint8_t ubChannel, float fVoltage) +uint8_t lt7182s_setf_vout_uv_fault(uint8_t ubChannel, float fVoltage) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_write_ul16(0x44, fVoltage); + return lt7182s_pmbus_write_ul16f(0x44, fVoltage); } -float lt7182s_get_vout_uv_warn(uint8_t ubChannel) +float lt7182s_getf_vout_uv_warn(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_ul16(0x43); + return lt7182s_pmbus_read_ul16f(0x43); +} +uint8_t lt7182s_setf_vout_uv_warn(uint8_t ubChannel, float fVoltage) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_ul16f(0x43, fVoltage); +} +#endif +uint16_t lt7182s_read_vout(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_ul16(0x8B), 1000000000ULL); // mV +} +uint16_t lt7182s_read_vout_peak(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_ul16(0xDD), 1000000000ULL); // mV +} +uint16_t lt7182s_get_vout(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_ul16(0x21), 1000000000ULL); // mV +} +uint8_t lt7182s_set_vout(uint8_t ubChannel, uint16_t usVoltage) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_ul16(0x21, (uint64_t)usVoltage * 1000000000ULL); // mV +} +uint16_t lt7182s_get_vout_max(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_ul16(0x24), 1000000000ULL); // mV +} +uint8_t lt7182s_set_vout_max(uint8_t ubChannel, uint16_t usVoltage) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_ul16(0x24, (uint64_t)usVoltage * 1000000000ULL); // mV } -uint8_t lt7182s_set_vout_uv_warn(uint8_t ubChannel, float fVoltage) +uint16_t lt7182s_get_vout_margin_high(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_write_ul16(0x43, fVoltage); + return DIV_ROUND(lt7182s_pmbus_read_ul16(0x25), 1000000000ULL); // mV } -float lt7182s_read_iout(uint8_t ubChannel) +uint8_t lt7182s_set_vout_margin_high(uint8_t ubChannel, uint16_t usVoltage) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_ul16(0x25, (uint64_t)usVoltage * 1000000000ULL); // mV +} +uint16_t lt7182s_get_vout_margin_low(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_ul16(0x26), 1000000000ULL); // mV +} +uint8_t lt7182s_set_vout_margin_low(uint8_t ubChannel, uint16_t usVoltage) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_ul16(0x26, (uint64_t)usVoltage * 1000000000ULL); // mV +} +uint16_t lt7182s_get_vout_transition_rate(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_l11(0x27), 1000000ULL); // mV/ms +} +uint8_t lt7182s_set_vout_transition_rate(uint8_t ubChannel, uint16_t usRate) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_l11(0x27, (uint64_t)usRate * 1000000ULL); // mV/ms +} +uint16_t lt7182s_get_vout_ov_fault(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_ul16(0x40), 1000000000ULL); // mV +} +uint8_t lt7182s_set_vout_ov_fault(uint8_t ubChannel, uint16_t usVoltage) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_ul16(0x40, (uint64_t)usVoltage * 1000000000ULL); // mV +} +uint16_t lt7182s_get_vout_ov_warn(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_ul16(0x42), 1000000000ULL); // mV +} +uint8_t lt7182s_set_vout_ov_warn(uint8_t ubChannel, uint16_t usVoltage) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_ul16(0x42, (uint64_t)usVoltage * 1000000000ULL); // mV +} +uint16_t lt7182s_get_vout_uv_fault(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_ul16(0x44), 1000000000ULL); // mV +} +uint8_t lt7182s_set_vout_uv_fault(uint8_t ubChannel, uint16_t usVoltage) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_ul16(0x44, (uint64_t)usVoltage * 1000000000ULL); // mV +} +uint16_t lt7182s_get_vout_uv_warn(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_ul16(0x43), 1000000000ULL); // mV +} +uint8_t lt7182s_set_vout_uv_warn(uint8_t ubChannel, uint16_t usVoltage) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_ul16(0x43, (uint64_t)usVoltage * 1000000000ULL); // mV +} + +#ifndef LT7182S_DISABLE_FLOAT +float lt7182s_readf_iout(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_l11(0x8C); + return lt7182s_pmbus_read_l11f(0x8C); } -float lt7182s_read_iout_peak(uint8_t ubChannel) +float lt7182s_readf_iout_peak(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_l11(0xD7); + return lt7182s_pmbus_read_l11f(0xD7); } -float lt7182s_get_iout_oc_warn(uint8_t ubChannel) +float lt7182s_getf_iout_oc_warn(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_l11(0x4A); + return lt7182s_pmbus_read_l11f(0x4A); +} +uint8_t lt7182s_setf_iout_oc_warn(uint8_t ubChannel, float fCurrent) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_l11f(0x4A, fCurrent); +} +#endif +uint16_t lt7182s_read_iout(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_l11(0x8C), 1000000ULL); // mA +} +uint16_t lt7182s_read_iout_peak(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_l11(0xD7), 1000000ULL); // mA } -uint8_t lt7182s_set_iout_oc_warn(uint8_t ubChannel, float fCurrent) +uint16_t lt7182s_get_iout_oc_warn(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0; - return lt7182s_pmbus_write_l11(0x4A, fCurrent); + return DIV_ROUND(lt7182s_pmbus_read_l11(0x4A), 1000000ULL); // mA } -float lt7182s_read_freq(uint8_t ubChannel) +uint8_t lt7182s_set_iout_oc_warn(uint8_t ubChannel, uint16_t usCurrent) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return lt7182s_pmbus_write_l11(0x4A, (uint64_t)usCurrent * 1000000ULL); // mA +} + +#ifndef LT7182S_DISABLE_FLOAT +float lt7182s_readf_freq(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_l11(0x95); + return lt7182s_pmbus_read_l11f(0x95); } -float lt7182s_read_pout(uint8_t ubChannel) +float lt7182s_readf_pout(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_l11(0x96); + return lt7182s_pmbus_read_l11f(0x96); } -float lt7182s_read_ith(uint8_t ubChannel) +float lt7182s_readf_ith(uint8_t ubChannel) { if(!lt7182s_select_page(ubChannel)) return 0.f; - return lt7182s_pmbus_read_l11(0xCE); + return lt7182s_pmbus_read_l11f(0xCE); +} +#endif +uint32_t lt7182s_read_freq(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_l11(0x95), 1000000ULL); // Hz +} +uint16_t lt7182s_read_pout(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; + + return DIV_ROUND(lt7182s_pmbus_read_l11(0x96), 1000000ULL); // mW } +uint16_t lt7182s_read_ith(uint8_t ubChannel) +{ + if(!lt7182s_select_page(ubChannel)) + return 0; -float lt7182s_read_extvcc() + return DIV_ROUND(lt7182s_pmbus_read_l11(0xCE), 1000000ULL); // mV +} + +#ifndef LT7182S_DISABLE_FLOAT +float lt7182s_readf_extvcc() +{ + return lt7182s_pmbus_read_l11f(0xCD); +} +float lt7182s_readf_temperature() +{ + return lt7182s_pmbus_read_l11f(0x8D); +} +float lt7182s_readf_temperature_peak() +{ + return lt7182s_pmbus_read_l11f(0xDF); +} +float lt7182s_getf_ot_fault() +{ + return lt7182s_pmbus_read_l11f(0x4F); +} +uint8_t lt7182s_setf_ot_fault(float fTemperature) +{ + return lt7182s_pmbus_write_l11f(0x4F, fTemperature); +} +float lt7182s_getf_ot_warn() +{ + return lt7182s_pmbus_read_l11f(0x51); +} +uint8_t lt7182s_setf_ot_warn(float fTemperature) +{ + return lt7182s_pmbus_write_l11f(0x51, fTemperature); +} +float lt7182s_getf_freq() +{ + return lt7182s_pmbus_read_l11f(0x33); +} +uint8_t lt7182s_setf_freq(float fFrequency) +{ + return lt7182s_pmbus_write_l11f(0x33, fFrequency); +} +#endif +uint16_t lt7182s_read_extvcc() { - return lt7182s_pmbus_read_l11(0xCD); + return DIV_ROUND(lt7182s_pmbus_read_l11(0xCD), 1000000ULL); // mV } -float lt7182s_read_temperature() +int32_t lt7182s_read_temperature() { - return lt7182s_pmbus_read_l11(0x8D); + return DIV_ROUND(lt7182s_pmbus_read_l11(0x8D), 1000000LL); // m degC } -float lt7182s_read_temperature_peak() +int32_t lt7182s_read_temperature_peak() { - return lt7182s_pmbus_read_l11(0xDF); + return DIV_ROUND(lt7182s_pmbus_read_l11(0xDF), 1000000LL); // m degC } -float lt7182s_get_ot_fault() +int32_t lt7182s_get_ot_fault() { - return lt7182s_pmbus_read_l11(0x4F); + return DIV_ROUND(lt7182s_pmbus_read_l11(0x4F), 1000000LL); // m degC } -uint8_t lt7182s_set_ot_fault(float fTemperature) +uint8_t lt7182s_set_ot_fault(int32_t lTemperature) { - return lt7182s_pmbus_write_l11(0x4F, fTemperature); + return lt7182s_pmbus_write_l11(0x4F, (uint64_t)lTemperature * 1000000LL); // m degC } -float lt7182s_get_ot_warn() +int32_t lt7182s_get_ot_warn() { - return lt7182s_pmbus_read_l11(0x51); + return DIV_ROUND(lt7182s_pmbus_read_l11(0x51), 1000000LL); // m degC } -uint8_t lt7182s_set_ot_warn(float fTemperature) +uint8_t lt7182s_set_ot_warn(int32_t lTemperature) { - return lt7182s_pmbus_write_l11(0x51, fTemperature); + return lt7182s_pmbus_write_l11(0x51, (uint64_t)lTemperature * 1000000LL); // m degC } -float lt7182s_get_freq() +uint32_t lt7182s_get_freq() { - return lt7182s_pmbus_read_l11(0x33); + return DIV_ROUND(lt7182s_pmbus_read_l11(0x33), 1000000ULL); // Hz } -uint8_t lt7182s_set_freq(float fFrequency) +uint8_t lt7182s_set_freq(uint32_t ulFrequency) { - return lt7182s_pmbus_write_l11(0x33, fFrequency); + return lt7182s_pmbus_write_l11(0x33, (uint64_t)ulFrequency * 1000000ULL); // Hz } \ No newline at end of file diff --git a/software/pmc/src/main.c b/software/pmc/src/main.c index d8974ddd..fcbdc959 100644 --- a/software/pmc/src/main.c +++ b/software/pmc/src/main.c @@ -491,7 +491,7 @@ int init() DBGPRINTLN_CTX(" VEXT: %u mV", adc_get_vext()); DBGPRINTLN_CTX(" 12V0: %u mV", adc_get_12v0()); DBGPRINTLN_CTX(" VBUS: %u mV", adc_get_vbus()); - DBGPRINTLN_CTX(" Temp: %d.%02u C", lTemp / 1000, ABS(lTemp % 1000)); + DBGPRINTLN_CTX(" Temp: %d.%03u C", lTemp / 1000, ABS(lTemp % 1000)); nvmctrl_config_waitstates(PM_CPU_CLOCK_FREQ, adc_get_iovdd()); // Optimize flash wait states for frequency and voltage @@ -581,81 +581,91 @@ int main() lt7182s_set_operation(0, LT7182S_OPERATION_TURN_OFF_IMMED); lt7182s_set_on_off_config(0, BIT(3)); // Only care about OPERATION commands, ignore RUN pin lt7182s_set_pwm_config(0, (3 << 11) | (2 << 9) | (7 << 6) | (3 << 3) | BIT(2)); // GMEA = 150 uS, ILIM = 6.5 A / -4 A, CITH = 80 pF, RITH = 40 kOhm, FCM, Low VOUT Disabled - lt7182s_set_vin_on(0, 7.f); // 7 V Input Voltage to start power conversion - lt7182s_set_vin_off(0, 6.5f); // 6.5 V Input Voltage to stop power conversion (UVLO) - lt7182s_set_vin_uv_warn(0, 6.75f); // 6.75 V Input Undervoltage Warning - lt7182s_set_iin_oc_warn(0, 4.5f); // 4.5 A Input Overcurrent Warning - lt7182s_set_vout_max(0, 5.4f); // 5.4 V Maximum Output Voltage - lt7182s_set_vout(0, 5.2f); // 5.2 V Nominal Output Voltage - lt7182s_set_vout_margin_high(0, 5.25f); // 5.25 V High Margin - lt7182s_set_vout_margin_low(0, 5.15f); // 5.15 V Low Margin - lt7182s_set_vout_ov_fault(0, 5.5f); // 5.5 V Overvoltage Fault - lt7182s_set_vout_ov_warn(0, 5.4f); // 5.4 V Overvoltage Warning - lt7182s_set_vout_uv_fault(0, 4.95f); // 4.95 V Undervoltage Fault - lt7182s_set_vout_uv_warn(0, 5.05f); // 5.05 V Undervoltage Warning - lt7182s_set_iout_oc_warn(0, 5.5f); // 5.5 A Output Overcurrent Warning + lt7182s_set_vin_on(0, 7000); // 7 V Input Voltage to start power conversion + lt7182s_set_vin_off(0, 6500); // 6.5 V Input Voltage to stop power conversion (UVLO) + lt7182s_set_vin_uv_warn(0, 6750); // 6.75 V Input Undervoltage Warning + lt7182s_set_iin_oc_warn(0, 4500); // 4.5 A Input Overcurrent Warning + lt7182s_set_vout_max(0, 5400); // 5.4 V Maximum Output Voltage + lt7182s_set_vout(0, 5200); // 5.2 V Nominal Output Voltage + lt7182s_set_vout_margin_high(0, 5250); // 5.25 V High Margin + lt7182s_set_vout_margin_low(0, 5150); // 5.15 V Low Margin + lt7182s_set_vout_transition_rate(0, 100); // 0.1 V/ms Output Voltage Transition Rate + lt7182s_set_vout_ov_fault(0, 5500); // 5.5 V Overvoltage Fault + lt7182s_set_vout_ov_warn(0, 5400); // 5.4 V Overvoltage Warning + lt7182s_set_vout_uv_fault(0, 4950); // 4.95 V Undervoltage Fault + lt7182s_set_vout_uv_warn(0, 5050); // 5.05 V Undervoltage Warning + lt7182s_set_iout_oc_warn(0, 5500); // 5.5 A Output Overcurrent Warning // Configure Channel 1 lt7182s_set_operation(1, LT7182S_OPERATION_TURN_OFF_IMMED); lt7182s_set_on_off_config(1, BIT(3) | BIT(2) | BIT(0)); // Only start if OPERATION is on and RUN is high (PGOOD from previous regulator) lt7182s_set_pwm_config(1, (0 << 11) | (2 << 9) | (7 << 6) | (3 << 3) | BIT(2) | BIT(1)); // GMEA = 150 uS, ILIM = 6.5 A / -4 A, CITH = 80 pF, RITH = 40 kOhm, FCM, Low VOUT Enabled - lt7182s_set_vin_on(1, 7.f); // 7 V Input Voltage to start power conversion - lt7182s_set_vin_off(1, 6.5f); // 6.5 V Input Voltage to stop power conversion (UVLO) - lt7182s_set_vin_uv_warn(1, 6.75f); // 6.75 V Input Undervoltage Warning - lt7182s_set_iin_oc_warn(1, 0.8f); // 0.8 A Input Overcurrent Warning - lt7182s_set_vout_max(1, 1.1f); // 1.1 V Maximum Output Voltage - lt7182s_set_vout(1, 1.f); // 1 V Nominal Output Voltage - lt7182s_set_vout_margin_high(1, 1.05f); // 1.05 V High Margin - lt7182s_set_vout_margin_low(1, 1.f); // 1 V Low Margin - lt7182s_set_vout_ov_fault(1, 1.15f); // 1.15 V Overvoltage Fault - lt7182s_set_vout_ov_warn(1, 1.1f); // 1.1 V Overvoltage Warning - lt7182s_set_vout_uv_fault(1, 0.9f); // 0.9 V Undervoltage Fault - lt7182s_set_vout_uv_warn(1, 0.95f); // 0.95 V Undervoltage Warning - lt7182s_set_iout_oc_warn(1, 3.f); // 3 A Output Overcurrent Warning TODO: Up up + lt7182s_set_vin_on(1, 7000); // 7 V Input Voltage to start power conversion + lt7182s_set_vin_off(1, 6500); // 6.5 V Input Voltage to stop power conversion (UVLO) + lt7182s_set_vin_uv_warn(1, 6750); // 6.75 V Input Undervoltage Warning + lt7182s_set_iin_oc_warn(1, 800); // 0.8 A Input Overcurrent Warning + lt7182s_set_vout_max(1, 1100); // 1.1 V Maximum Output Voltage + lt7182s_set_vout(1, 1000); // 1 V Nominal Output Voltage + lt7182s_set_vout_margin_high(1, 1050); // 1.05 V High Margin + lt7182s_set_vout_margin_low(1, 1000); // 1 V Low Margin + lt7182s_set_vout_transition_rate(1, 250); // 0.25 V/ms Output Voltage Transition Rate + lt7182s_set_vout_ov_fault(1, 1150); // 1.15 V Overvoltage Fault + lt7182s_set_vout_ov_warn(1, 1100); // 1.1 V Overvoltage Warning + lt7182s_set_vout_uv_fault(1, 900); // 0.9 V Undervoltage Fault + lt7182s_set_vout_uv_warn(1, 950); // 0.95 V Undervoltage Warning + lt7182s_set_iout_oc_warn(1, 3000); // 3 A Output Overcurrent Warning TODO: Up up for(uint8_t i = 0; i < 2; i++) { DBGPRINTLN_CTX(" Channel #%hhu:", i); - DBGPRINTLN_CTX(" VIN: %.3f V (Pk: %.3f V)", lt7182s_read_vin(i), lt7182s_read_vin_peak(i)); - DBGPRINTLN_CTX(" VIN ON: %.3f V", lt7182s_get_vin_on(i)); - DBGPRINTLN_CTX(" VIN OFF: %.3f V", lt7182s_get_vin_off(i)); - DBGPRINTLN_CTX(" VIN UV Warn: %.3f V", lt7182s_get_vin_uv_warn(i)); - DBGPRINTLN_CTX(" IIN: %.3f A", lt7182s_read_iin(i)); - DBGPRINTLN_CTX(" IIN OC Warn: %.3f A", lt7182s_get_iin_oc_warn(i)); - DBGPRINTLN_CTX(" VOUT: %.3f V (Set: %.3f V, Pk: %.3f V)", lt7182s_read_vout(i), lt7182s_get_vout(i), lt7182s_read_vout_peak(i)); - DBGPRINTLN_CTX(" VOUT Max: %.3f V", lt7182s_get_vout_max(i)); - DBGPRINTLN_CTX(" VOUT Mg High: %.3f V", lt7182s_get_vout_margin_high(i)); - DBGPRINTLN_CTX(" VOUT Mg Low: %.3f V", lt7182s_get_vout_margin_low(i)); - DBGPRINTLN_CTX(" VOUT Tr Rate: %.3f V/ms", lt7182s_get_vout_transition_rate(i)); - DBGPRINTLN_CTX(" VOUT OV Fault: %.3f V", lt7182s_get_vout_ov_fault(i)); - DBGPRINTLN_CTX(" VOUT OV Warn: %.3f V", lt7182s_get_vout_ov_warn(i)); - DBGPRINTLN_CTX(" VOUT UV Fault: %.3f V", lt7182s_get_vout_uv_fault(i)); - DBGPRINTLN_CTX(" VOUT UV Warn: %.3f V", lt7182s_get_vout_uv_warn(i)); - DBGPRINTLN_CTX(" IOUT: %.3f A (Pk: %.3f A)", lt7182s_read_iout(i), lt7182s_read_iout_peak(i)); - DBGPRINTLN_CTX(" IOUT OC Warn: %.3f A", lt7182s_get_iout_oc_warn(i)); - DBGPRINTLN_CTX(" FREQ: %.3f kHz", lt7182s_read_freq(i)); - DBGPRINTLN_CTX(" POUT: %.3f W", lt7182s_read_pout(i)); - DBGPRINTLN_CTX(" VITH: %.3f V", lt7182s_read_ith(i)); + DBGPRINTLN_CTX(" VIN: %hu mV (Pk: %hu mV)", lt7182s_read_vin(i), lt7182s_read_vin_peak(i)); + DBGPRINTLN_CTX(" VIN ON: %hu mV", lt7182s_get_vin_on(i)); + DBGPRINTLN_CTX(" VIN OFF: %hu mV", lt7182s_get_vin_off(i)); + DBGPRINTLN_CTX(" VIN UV Warn: %hd mV", lt7182s_get_vin_uv_warn(i)); + DBGPRINTLN_CTX(" IIN: %hu mA", lt7182s_read_iin(i)); + DBGPRINTLN_CTX(" IIN OC Warn: %hu mA", lt7182s_get_iin_oc_warn(i)); + DBGPRINTLN_CTX(" VOUT: %hu mV (Set: %hu mV, Pk: %hu mV)", lt7182s_read_vout(i), lt7182s_get_vout(i), lt7182s_read_vout_peak(i)); + DBGPRINTLN_CTX(" VOUT Max: %hu mV", lt7182s_get_vout_max(i)); + DBGPRINTLN_CTX(" VOUT Mg High: %hu mV", lt7182s_get_vout_margin_high(i)); + DBGPRINTLN_CTX(" VOUT Mg Low: %hu mV", lt7182s_get_vout_margin_low(i)); + DBGPRINTLN_CTX(" VOUT Rate: %hu mV/ms", lt7182s_get_vout_transition_rate(i)); + DBGPRINTLN_CTX(" VOUT OV Fault: %hu mV", lt7182s_get_vout_ov_fault(i)); + DBGPRINTLN_CTX(" VOUT OV Warn: %hu mV", lt7182s_get_vout_ov_warn(i)); + DBGPRINTLN_CTX(" VOUT UV Fault: %hu mV", lt7182s_get_vout_uv_fault(i)); + DBGPRINTLN_CTX(" VOUT UV Warn: %hu mV", lt7182s_get_vout_uv_warn(i)); + DBGPRINTLN_CTX(" IOUT: %hu mA (Pk: %hu mA)", lt7182s_read_iout(i), lt7182s_read_iout_peak(i)); + DBGPRINTLN_CTX(" IOUT OC Warn: %hu mA", lt7182s_get_iout_oc_warn(i)); + DBGPRINTLN_CTX(" FREQ: %u Hz", lt7182s_read_freq(i)); + DBGPRINTLN_CTX(" POUT: %hu mW", lt7182s_read_pout(i)); + DBGPRINTLN_CTX(" VITH: %hu mV", lt7182s_read_ith(i)); uint16_t usPWMConfig = lt7182s_get_pwm_config(i); DBGPRINTLN_CTX(" PWM Config:"); - DBGPRINTLN_CTX(" GMEA: %.3f uS", l17182s_pwm_config_parse_gmea(usPWMConfig)); - DBGPRINTLN_CTX(" ILIM Pos: %.3f A", l17182s_pwm_config_parse_pos_ilim(usPWMConfig)); - DBGPRINTLN_CTX(" ILIM Neg: %.3f A", l17182s_pwm_config_parse_neg_ilim(usPWMConfig)); - DBGPRINTLN_CTX(" CITH: %.3f pF", l17182s_pwm_config_parse_cith(usPWMConfig)); - DBGPRINTLN_CTX(" RITH: %.3f kOhm", l17182s_pwm_config_parse_rith(usPWMConfig)); + DBGPRINTLN_CTX(" GMEA: %lu nS", l17182s_pwm_config_parse_gmea(usPWMConfig)); + DBGPRINTLN_CTX(" ILIM Pos: %hu mA", l17182s_pwm_config_parse_pos_ilim(usPWMConfig)); + DBGPRINTLN_CTX(" ILIM Neg: %hd mA", l17182s_pwm_config_parse_neg_ilim(usPWMConfig)); + DBGPRINTLN_CTX(" CITH: %hhu pF", l17182s_pwm_config_parse_cith(usPWMConfig)); + DBGPRINTLN_CTX(" RITH: %hhu kOhm", l17182s_pwm_config_parse_rith(usPWMConfig)); DBGPRINTLN_CTX(" Pulse Skip: %s", l17182s_pwm_config_parse_pulse_skipping(usPWMConfig) ? "Enabled" : "Disabled"); DBGPRINTLN_CTX(" FCM at TOFF: %s", l17182s_pwm_config_parse_fcm_at_toff(usPWMConfig) ? "Enabled" : "Disabled"); DBGPRINTLN_CTX(" Low VOUT: %s", l17182s_pwm_config_parse_low_vout_mode(usPWMConfig) ? "Enabled" : "Disabled"); - DBGPRINTLN_CTX(" Phase: %.3f deg", lt7182s_get_pwm_phase(i)); + DBGPRINTLN_CTX(" Phase: %lu mdeg", lt7182s_get_pwm_phase(i)); } - DBGPRINTLN_CTX(" EXTVCC: %.3f V", lt7182s_read_extvcc()); - DBGPRINTLN_CTX(" Temp: %.3f C (Pk: %.3f C)", lt7182s_read_temperature(), lt7182s_read_temperature_peak()); - DBGPRINTLN_CTX(" OT Fault Temp: %.3f C", lt7182s_get_ot_fault()); - DBGPRINTLN_CTX(" OT Warn Temp: %.3f C", lt7182s_get_ot_warn()); - DBGPRINTLN_CTX(" Freq: %.3f kHz", lt7182s_get_freq()); + DBGPRINTLN_CTX(" EXTVCC: %hu mV", lt7182s_read_extvcc()); + + int32_t lTemp = lt7182s_read_temperature(); + int32_t lTempPeak = lt7182s_read_temperature_peak(); + DBGPRINTLN_CTX(" Temp: %d.%03u C (Pk: %d.%03u C)", lTemp / 1000, ABS(lTemp % 1000), lTempPeak / 1000, ABS(lTempPeak % 1000)); + + lTemp = lt7182s_get_ot_fault(); + DBGPRINTLN_CTX(" OT Fault Temp: %d.%03u C", lTemp / 1000, ABS(lTemp % 1000)); + + lTemp = lt7182s_get_ot_warn(); + DBGPRINTLN_CTX(" OT Warn Temp: %d.%03u C", lTemp / 1000, ABS(lTemp % 1000)); + + DBGPRINTLN_CTX(" Freq: %u Hz", lt7182s_get_freq()); //// UPD test // UPD350_SELECT(); @@ -754,6 +764,8 @@ int main() } } + uint8_t ubI2CIsMaster = 0; + if(!DBG_PRESENT()) { // Done with I2C master, switch to slave @@ -763,6 +775,8 @@ int main() } else { + ubI2CIsMaster = 1; + DBGPRINTLN_CTX("Debugger detected, I2C will remain in master mode"); } @@ -917,51 +931,59 @@ int main() DBGPRINTLN("VEXT: %u mV", ulVEXT); DBGPRINTLN("12V0: %u mV", ul12V0); DBGPRINTLN("VBUS: %u mV", ulVBUS); - DBGPRINTLN("Temp: %d.%02u C", lTemp / 1000, ABS(lTemp % 1000)); - - DBGPRINTLN("LT7182S:"); + DBGPRINTLN("Temp: %d.%03u C", lTemp / 1000, ABS(lTemp % 1000)); - for(uint8_t i = 0; i < 2; i++) + if(ubI2CIsMaster) { - DBGPRINTLN(" Channel #%hhu:", i); - - uint16_t usStatus = lt7182s_get_status_word(i); + DBGPRINTLN("LT7182S:"); - if(usStatus != 0x0000) + for(uint8_t i = 0; i < 2; i++) { - uint8_t ubStatusVOUT = lt7182s_get_status_vout(i); - uint8_t ubStatusIOUT = lt7182s_get_status_iout(i); - uint8_t ubStatusInput = lt7182s_get_status_input(i); - uint8_t ubStatusTemperature = lt7182s_get_status_temperature(); - uint8_t ubStatusCML = lt7182s_get_status_cml(); - uint8_t ubStatusMFRSpecific = lt7182s_get_status_mfr_specific(i); - uint8_t ubStatusMFRCommon = lt7182s_get_status_mfr_common(); - uint16_t usStatusMFRPads = lt7182s_get_status_mfr_pads(); - uint8_t ubStatusMFRPinConfig = lt7182s_get_status_mfr_pin_config(); - - DBGPRINTLN(" Status (0x%04X):", usStatus); - DBGPRINTLN(" VOUT: 0x%02X", ubStatusVOUT); - DBGPRINTLN(" IOUT: 0x%02X", ubStatusIOUT); - DBGPRINTLN(" Input: 0x%02X", ubStatusInput); - DBGPRINTLN(" Temp: 0x%02X", ubStatusTemperature); - DBGPRINTLN(" CML: 0x%02X", ubStatusCML); - DBGPRINTLN(" MFR Spec: 0x%02X", ubStatusMFRSpecific); - DBGPRINTLN(" MFR Com: 0x%02X", ubStatusMFRCommon); - DBGPRINTLN(" MFR Pads: 0x%04X", usStatusMFRPads); - DBGPRINTLN(" MFR PinCfg: 0x%02X", ubStatusMFRPinConfig); + DBGPRINTLN(" Channel #%hhu:", i); + + uint16_t usStatus = lt7182s_get_status_word(i); + + if(usStatus != 0x0000) + { + uint8_t ubStatusVOUT = lt7182s_get_status_vout(i); + uint8_t ubStatusIOUT = lt7182s_get_status_iout(i); + uint8_t ubStatusInput = lt7182s_get_status_input(i); + uint8_t ubStatusTemperature = lt7182s_get_status_temperature(); + uint8_t ubStatusCML = lt7182s_get_status_cml(); + uint8_t ubStatusMFRSpecific = lt7182s_get_status_mfr_specific(i); + uint8_t ubStatusMFRCommon = lt7182s_get_status_mfr_common(); + uint16_t usStatusMFRPads = lt7182s_get_status_mfr_pads(); + uint8_t ubStatusMFRPinConfig = lt7182s_get_status_mfr_pin_config(); + + DBGPRINTLN(" Status (0x%04X):", usStatus); + DBGPRINTLN(" VOUT: 0x%02X", ubStatusVOUT); + DBGPRINTLN(" IOUT: 0x%02X", ubStatusIOUT); + DBGPRINTLN(" Input: 0x%02X", ubStatusInput); + DBGPRINTLN(" Temp: 0x%02X", ubStatusTemperature); + DBGPRINTLN(" CML: 0x%02X", ubStatusCML); + DBGPRINTLN(" MFR Spec: 0x%02X", ubStatusMFRSpecific); + DBGPRINTLN(" MFR Com: 0x%02X", ubStatusMFRCommon); + DBGPRINTLN(" MFR Pads: 0x%04X", usStatusMFRPads); + DBGPRINTLN(" MFR PinCfg: 0x%02X", ubStatusMFRPinConfig); + } + + DBGPRINTLN(" VIN: %hu mV (Pk: %hu mV)", lt7182s_read_vin(i), lt7182s_read_vin_peak(i)); + DBGPRINTLN(" IIN: %hu mA", lt7182s_read_iin(i)); + DBGPRINTLN(" VOUT: %hu V (Set: %hu V, Pk: %hu V)", lt7182s_read_vout(i), lt7182s_get_vout(i), lt7182s_read_vout_peak(i)); + DBGPRINTLN(" IOUT: %hu mA (Pk: %hu mA)", lt7182s_read_iout(i), lt7182s_read_iout_peak(i)); + DBGPRINTLN(" FREQ: %u Hz", lt7182s_read_freq(i)); + DBGPRINTLN(" POUT: %hu mW", lt7182s_read_pout(i)); + DBGPRINTLN(" VITH: %hu mV", lt7182s_read_ith(i)); } - DBGPRINTLN(" VIN: %.3f V (Pk: %.3f V)", lt7182s_read_vin(i), lt7182s_read_vin_peak(i)); - DBGPRINTLN(" IIN: %.3f A", lt7182s_read_iin(i)); - DBGPRINTLN(" VOUT: %.3f V (Set: %.3f V, Pk: %.3f V)", lt7182s_read_vout(i), lt7182s_get_vout(i), lt7182s_read_vout_peak(i)); - DBGPRINTLN(" IOUT: %.3f A (Pk: %.3f A)", lt7182s_read_iout(i), lt7182s_read_iout_peak(i)); - DBGPRINTLN(" FREQ: %.3f kHz", lt7182s_read_freq(i)); - DBGPRINTLN(" POUT: %.3f W", lt7182s_read_pout(i)); - DBGPRINTLN(" VITH: %.3f V", lt7182s_read_ith(i)); + DBGPRINTLN(" EXTVCC: %hu mV", lt7182s_read_extvcc()); + + int32_t lTemp = lt7182s_read_temperature(); + int32_t lTempPeak = lt7182s_read_temperature_peak(); + + DBGPRINTLN(" Temp: %d.%03u C (Pk: %d.%03u C)", lTemp / 1000, ABS(lTemp % 1000), lTempPeak / 1000, ABS(lTempPeak % 1000)); } - DBGPRINTLN(" EXTVCC: %.3f V", lt7182s_read_extvcc()); - DBGPRINTLN(" Temp: %.3f C (Pk: %.3f C)", lt7182s_read_temperature(), lt7182s_read_temperature_peak()); DBGPRINTLN("CM4: %s", CM4_RUNNING() ? "Running" : "OFF"); } } diff --git a/software/pmc/src/printf/printf.c b/software/pmc/src/printf/printf.c index 33ecb444..c6006c18 100644 --- a/software/pmc/src/printf/printf.c +++ b/software/pmc/src/printf/printf.c @@ -46,7 +46,7 @@ #define PRINTF_FTOA_BUFFER_SIZE 32U // define this to support floating point (%f) -#define PRINTF_SUPPORT_FLOAT +// #define PRINTF_SUPPORT_FLOAT // define this to support long long types (%llu or %p) #define PRINTF_SUPPORT_LONG_LONG