Skip to content

Commit a00d1be

Browse files
committed
Simplified pr
1 parent 11e2062 commit a00d1be

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

encoder.c

+4-13
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ static void spi_delay(void);
159159
static void spi_AS5047_cs_delay(void);
160160
static void TS5700N8501_send_byte(uint8_t b);
161161

162-
static void encoder_AS504x_update_connected_diag(uint8_t is_connected);
163162
static void encoder_AS504x_determinate_if_connected(bool was_last_valid);
164163

165164
#if AS504x_USE_SW_MOSI_PIN || AS5047_USE_HW_SPI_PINS
@@ -629,10 +628,6 @@ bool spi_check_parity(uint16_t x) {
629628
return (~x) & 1;
630629
}
631630

632-
void encoder_AS504x_update_connected_diag(uint8_t is_connected) {
633-
AS504x_sensor_diag.is_connected = is_connected;
634-
}
635-
636631
#if AS504x_USE_SW_MOSI_PIN || AS5047_USE_HW_SPI_PINS
637632
static uint8_t encoder_AS504x_fetch_diag(void) {
638633
uint16_t recf[2], senf[2] = {AS504x_SPI_READ_DIAG_MSG, AS504x_SPI_READ_MAGN_MSG};
@@ -735,24 +730,20 @@ static uint8_t spi_transfer_err_check(uint16_t *in_buf, const uint16_t *out_buf,
735730
/*
736731
* Determinate if is connected depending on last retieved data.
737732
*/
738-
void encoder_AS504x_determinate_if_connected(bool was_last_valid) {
733+
static void encoder_AS504x_determinate_if_connected(bool was_last_valid) {
739734
if(!was_last_valid) {
740-
AS504x_spi_communication_error_count+=AS504x_CONNECTION_DETERMINATOR_ERROR_WEIGHT;
735+
AS504x_spi_communication_error_count++;
741736

742737
if(AS504x_spi_communication_error_count >= AS504x_CONNECTION_DETERMINATOR_ERROR_THRESHOLD) {
743738
AS504x_spi_communication_error_count = AS504x_CONNECTION_DETERMINATOR_ERROR_THRESHOLD;
744-
encoder_AS504x_update_connected_diag(0);
739+
AS504x_sensor_diag.is_connected = 0;
745740
mc_interface_fault_stop(FAULT_CODE_ENCODER_SPI, 0, 1);
746741
}
747742
} else {
748743
if(AS504x_spi_communication_error_count) {
749744
AS504x_spi_communication_error_count--;
750745
} else {
751-
encoder_AS504x_update_connected_diag(1);
752-
if(FAULT_CODE_ENCODER_SPI == mc_interface_get_fault()) {
753-
mc_interface_fault_stop(FAULT_CODE_NONE, 0, 1);
754-
755-
}
746+
AS504x_sensor_diag.is_connected = 1;
756747
}
757748
}
758749
}

encoder.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ AS504x_diag encoder_AS504x_get_diag(void);
8080
#define AS504x_SPI_READ_MAGN_MSG (AS504x_SPI_MAGN_ADR | AS504x_SPI_READ_BIT)
8181
#define AS504x_SPI_READ_CLEAR_ERROR_MSG (AS504x_SPI_CLEAR_ERROR_ADR | AS504x_SPI_READ_BIT)
8282

83-
#define AS504x_CONNECTION_DETERMINATOR_ERROR_WEIGHT 4
84-
#define AS504x_CONNECTION_DETERMINATOR_ERROR_THRESHOLD (2 * AS504x_CONNECTION_DETERMINATOR_ERROR_WEIGHT)
83+
#define AS504x_CONNECTION_DETERMINATOR_ERROR_THRESHOLD 5
8584

8685
#define AS504x_DATA_INVALID_THRESHOLD 10000
8786
#define AS504x_REFRESH_DIAG_AFTER_NSAMPLES 100

0 commit comments

Comments
 (0)