@@ -159,16 +159,16 @@ static void spi_delay(void);
159
159
static void spi_AS5047_cs_delay (void );
160
160
static void TS5700N8501_send_byte (uint8_t b );
161
161
162
- static void encoder_AS504x_determinate_if_connected (bool was_last_valid );
162
+ static void AS504x_determinate_if_connected (bool was_last_valid );
163
163
164
164
#if AS504x_USE_SW_MOSI_PIN || AS5047_USE_HW_SPI_PINS
165
165
static uint16_t AS504x_diag_fetch_now_count = 0 ;
166
166
167
- static uint8_t encoder_AS504x_fetch_diag (void );
168
- static uint8_t encoder_AS504x_verify_serial (void );
169
- static void encoder_AS504x_deserialize_diag (void );
170
- static void encoder_AS504x_fetch_clear_err_diag (void );
171
- static uint8_t spi_transfer_err_check (uint16_t * in_buf , const uint16_t * out_buf , int length );
167
+ static uint8_t AS504x_fetch_diag (void );
168
+ static uint8_t AS504x_verify_serial (void );
169
+ static void AS504x_deserialize_diag (void );
170
+ static void AS504x_fetch_clear_err_diag (void );
171
+ static uint8_t AS504x_spi_transfer_err_check (uint16_t * in_buf , const uint16_t * out_buf , int length );
172
172
#else
173
173
static uint32_t AS504x_data_last_invalid_counter = 0 ;
174
174
#endif
@@ -620,7 +620,7 @@ void encoder_reset(void) {
620
620
}
621
621
622
622
// returns true for even number of ones (no parity error according to AS5047 datasheet
623
- bool spi_check_parity (uint16_t x ) {
623
+ static bool spi_check_parity (uint16_t x ) {
624
624
x ^= x >> 8 ;
625
625
x ^= x >> 4 ;
626
626
x ^= x >> 2 ;
@@ -629,7 +629,7 @@ bool spi_check_parity(uint16_t x) {
629
629
}
630
630
631
631
#if AS504x_USE_SW_MOSI_PIN || AS5047_USE_HW_SPI_PINS
632
- static uint8_t encoder_AS504x_fetch_diag (void ) {
632
+ static uint8_t AS504x_fetch_diag (void ) {
633
633
uint16_t recf [2 ], senf [2 ] = {AS504x_SPI_READ_DIAG_MSG , AS504x_SPI_READ_MAGN_MSG };
634
634
uint8_t ret = 0 ;
635
635
@@ -641,13 +641,13 @@ static uint8_t encoder_AS504x_fetch_diag(void) {
641
641
spi_AS5047_cs_delay ();
642
642
643
643
spi_begin ();
644
- ret |= spi_transfer_err_check (recf , senf + 1 , 1 );
644
+ ret |= AS504x_spi_transfer_err_check (recf , senf + 1 , 1 );
645
645
spi_end ();
646
646
647
647
spi_AS5047_cs_delay ();
648
648
649
649
spi_begin ();
650
- ret |= spi_transfer_err_check (recf + 1 , 0 , 1 );
650
+ ret |= AS504x_spi_transfer_err_check (recf + 1 , 0 , 1 );
651
651
spi_end ();
652
652
653
653
if (!ret ) {
@@ -663,7 +663,7 @@ static uint8_t encoder_AS504x_fetch_diag(void) {
663
663
/*
664
664
* This function fetches error flag from AS504x and afterwards clean error flag
665
665
*/
666
- static void encoder_AS504x_fetch_clear_err_diag () {
666
+ static void AS504x_fetch_clear_err_diag () {
667
667
uint16_t recf , senf = AS504x_SPI_READ_CLEAR_ERROR_MSG ;
668
668
669
669
spi_begin ();
@@ -683,7 +683,7 @@ static void encoder_AS504x_fetch_clear_err_diag() {
683
683
* Try verify if the diagnostics are not corrupt
684
684
* This function can prevent deserialazing corrupted data if the MISO bus is HIGH or LOW
685
685
*/
686
- static uint8_t encoder_AS504x_verify_serial () {
686
+ static uint8_t AS504x_verify_serial () {
687
687
uint16_t serial_diag_flgs , serial_magnitude , test_magnitude ;
688
688
uint8_t test_AGC_value , test_is_Comp_high , test_is_Comp_low ;
689
689
@@ -705,7 +705,7 @@ static uint8_t encoder_AS504x_verify_serial() {
705
705
return 0 ;
706
706
}
707
707
708
- static void encoder_AS504x_deserialize_diag () {
708
+ static void AS504x_deserialize_diag () {
709
709
AS504x_sensor_diag .AGC_value = AS504x_sensor_diag .serial_diag_flgs ;
710
710
AS504x_sensor_diag .is_OCF = (AS504x_sensor_diag .serial_diag_flgs >> AS504x_SPI_DIAG_OCF_BIT_POS ) & 1 ;
711
711
AS504x_sensor_diag .is_COF = (AS504x_sensor_diag .serial_diag_flgs >> AS504x_SPI_DIAG_COF_BIT_POS ) & 1 ;
@@ -714,7 +714,7 @@ static void encoder_AS504x_deserialize_diag() {
714
714
AS504x_sensor_diag .magnitude = AS504x_sensor_diag .serial_magnitude & AS504x_SPI_EXCLUDE_PARITY_AND_ERROR_BITMASK ;
715
715
}
716
716
717
- static uint8_t spi_transfer_err_check (uint16_t * in_buf , const uint16_t * out_buf , int length ) {
717
+ static uint8_t AS504x_spi_transfer_err_check (uint16_t * in_buf , const uint16_t * out_buf , int length ) {
718
718
spi_transfer (in_buf , out_buf , length );
719
719
720
720
for (int len_count = 0 ; len_count < length ; len_count ++ ) {
@@ -730,14 +730,13 @@ static uint8_t spi_transfer_err_check(uint16_t *in_buf, const uint16_t *out_buf,
730
730
/*
731
731
* Determinate if is connected depending on last retieved data.
732
732
*/
733
- static void encoder_AS504x_determinate_if_connected (bool was_last_valid ) {
733
+ static void AS504x_determinate_if_connected (bool was_last_valid ) {
734
734
if (!was_last_valid ) {
735
735
AS504x_spi_communication_error_count ++ ;
736
736
737
737
if (AS504x_spi_communication_error_count >= AS504x_CONNECTION_DETERMINATOR_ERROR_THRESHOLD ) {
738
738
AS504x_spi_communication_error_count = AS504x_CONNECTION_DETERMINATOR_ERROR_THRESHOLD ;
739
739
AS504x_sensor_diag .is_connected = 0 ;
740
- mc_interface_fault_stop (FAULT_CODE_ENCODER_SPI , 0 , 1 );
741
740
}
742
741
} else {
743
742
if (AS504x_spi_communication_error_count ) {
@@ -765,32 +764,32 @@ void encoder_tim_isr(void) {
765
764
spi_AS5047_cs_delay ();
766
765
767
766
spi_begin ();
768
- spi_data_err_raised = spi_transfer_err_check (& pos , 0 , 1 );
767
+ spi_data_err_raised = AS504x_spi_transfer_err_check (& pos , 0 , 1 );
769
768
spi_end ();
770
769
spi_val = pos ;
771
770
772
771
// get diagnostic every AS504x_REFRESH_DIAG_AFTER_NSAMPLES
773
772
AS504x_diag_fetch_now_count ++ ;
774
773
if (AS504x_diag_fetch_now_count >= AS504x_REFRESH_DIAG_AFTER_NSAMPLES || spi_data_err_raised ) {
775
774
// clear error flags before getting new diagnostics data
776
- encoder_AS504x_fetch_clear_err_diag ();
775
+ AS504x_fetch_clear_err_diag ();
777
776
778
- if (!encoder_AS504x_fetch_diag ()) {
779
- if (!encoder_AS504x_verify_serial ()) {
777
+ if (!AS504x_fetch_diag ()) {
778
+ if (!AS504x_verify_serial ()) {
780
779
781
780
// if (encoder_AS504x_get_diag().is_Comp_high) {
782
781
// mc_interface_fault_stop(FAULT_CODE_ENCODER_NO_MAGNET, 0, 1); // COMP HIGH
783
782
// } else if(encoder_AS504x_get_diag().is_Comp_low) {
784
783
// mc_interface_fault_stop(FAULT_CODE_ENCODER_MAGNET_TOO_STRONG, 0, 1); // COMP low
785
784
// }
786
785
787
- encoder_AS504x_deserialize_diag ();
788
- encoder_AS504x_determinate_if_connected (true);
786
+ AS504x_deserialize_diag ();
787
+ AS504x_determinate_if_connected (true);
789
788
} else {
790
- encoder_AS504x_determinate_if_connected (false);
789
+ AS504x_determinate_if_connected (false);
791
790
}
792
791
} else {
793
- encoder_AS504x_determinate_if_connected (false);
792
+ AS504x_determinate_if_connected (false);
794
793
}
795
794
AS504x_diag_fetch_now_count = 0 ;
796
795
}
@@ -804,11 +803,11 @@ void encoder_tim_isr(void) {
804
803
AS504x_data_last_invalid_counter ++ ;
805
804
} else {
806
805
AS504x_data_last_invalid_counter = 0 ;
807
- encoder_AS504x_determinate_if_connected (true);
806
+ AS504x_determinate_if_connected (true);
808
807
}
809
808
810
809
if (AS504x_data_last_invalid_counter >= AS504x_DATA_INVALID_THRESHOLD ) {
811
- encoder_AS504x_determinate_if_connected (false);
810
+ AS504x_determinate_if_connected (false);
812
811
AS504x_data_last_invalid_counter = AS504x_DATA_INVALID_THRESHOLD ;
813
812
}
814
813
#endif
0 commit comments