Skip to content

Commit

Permalink
feat(bms-monitor): add pladc check function and DCTO values #20
Browse files Browse the repository at this point in the history
  • Loading branch information
Tonidotpy committed Feb 7, 2024
1 parent 9abe1cf commit e1e4763
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
37 changes: 37 additions & 0 deletions bms-monitor/inc/ltc6811.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,25 @@ typedef enum {
LTC6811_CHST_VA,
LTC6811_CHST_VD
} Ltc6811Chst;
/** @brief Discharge timeout values in minutes */
typedef enum {
LTC6811_DCTO_OFF = 0, // Discharge is disabled
LTC6811_DCTO_30S,
LTC6811_DCTO_1MIN,
LTC6811_DCTO_2MIN,
LTC6811_DCTO_3MIN,
LTC6811_DCTO_4MIN,
LTC6811_DCTO_5MIN,
LTC6811_DCTO_10MIN,
LTC6811_DCTO_15MIN,
LTC6811_DCTO_20MIN,
LTC6811_DCTO_30MIN,
LTC6811_DCTO_40MIN,
LTC6811_DCTO_60MIN,
LTC6811_DCTO_75MIN,
LTC6811_DCTO_90MIN,
LTC6811_DCTO_120MIN
} Ltc6811Dcto;

/** @brief I2C inital communication control bits on write */
typedef enum {
Expand Down Expand Up @@ -371,6 +390,17 @@ typedef struct {
*/
void ltc6811_chain_init(Ltc6811Chain * chain, size_t ltc_count);

/**
* @brief Check if the ADC conversion has ended or not
*
* @attention Do not pull the Chip Select(CS) high before the conversion has ended
* otherwise this command will not work
*
* @param byte The single byte read after the pladc command
* @return bool True if the conversion has ended, false otherwise
*/
bool ltc6811_pladc_check(uint8_t byte);

/******************************************/
/* BROADCAST COMMANDS */
/******************************************/
Expand Down Expand Up @@ -944,6 +974,13 @@ size_t ltc6811_clrstat_encode_broadcast(
* @attention The 'out' array should be large enough to contain all the encoded bytes
* Use the LTC6811_POLL_BUFFER_SIZE macro to get the right size for the buffer
*
* @details To check for the ADC conversion status send the encoded command and
* then read a single byte and check the status using the 'ltc6811_pladc_check' function
* until it has ended conversion
*
* @attention Do not pull the Chip Select(CS) high before the conversion has ended
* otherwise this command will not work
*
* @param chain The LTC6811 broadcast handler
* @param out The array were the encoded bytes are written
* @return size_t The number of encoded bytes
Expand Down
4 changes: 4 additions & 0 deletions bms-monitor/src/ltc6811.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ void ltc6811_chain_init(Ltc6811Chain * chain, size_t ltc_count) {
chain->count = ltc_count;
}

bool ltc6811_pladc_check(uint8_t byte) {
return byte == 0xFF;
}

size_t ltc6811_wrcfg_encode_broadcast(
Ltc6811Chain * chain,
Ltc6811Cfgr * config,
Expand Down
11 changes: 11 additions & 0 deletions bms-monitor/test/test-ltc6811.c
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,13 @@ void check_pladc_encode_broadcast_cmd_pec_bytes() {
TEST_ASSERT_EQUAL_HEX8_ARRAY(pec, out + LTC6811_CMD_BYTE_COUNT, LTC6811_PEC_BYTE_COUNT);
}

void check_pladc_check_conversion_running() {
TEST_ASSERT_FALSE(ltc6811_pladc_check(0x07));
}
void check_pladc_check_conversion_ended() {
TEST_ASSERT_TRUE(ltc6811_pladc_check(0xFF));
}

void check_diagn_encode_broadcast_length() {
uint8_t out[LTC6811_POLL_BUFFER_SIZE(LTC_COUNT)];
size_t byte_count = ltc6811_diagn_encode_broadcast(
Expand Down Expand Up @@ -1649,6 +1656,10 @@ int main() {
RUN_TEST(check_pladc_encode_broadcast_length);
RUN_TEST(check_pladc_encode_broadcast_cmd_bytes);
RUN_TEST(check_pladc_encode_broadcast_cmd_pec_bytes);

// Check ADC conversion status byte
RUN_TEST(check_pladc_check_conversion_running);
RUN_TEST(check_pladc_check_conversion_ended);

// Diagnose MUX and poll status broadcast encode
RUN_TEST(check_diagn_encode_broadcast_length);
Expand Down

0 comments on commit e1e4763

Please sign in to comment.