|
|
|
@ -18,6 +18,7 @@
@@ -18,6 +18,7 @@
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
|
|
#include <AP_Math/AP_Math.h> |
|
|
|
|
#include <AP_Math/crc.h> |
|
|
|
|
|
|
|
|
|
extern const AP_HAL::HAL &hal; |
|
|
|
|
|
|
|
|
@ -150,34 +151,6 @@ bool AP_Baro_MS56XX::_init()
@@ -150,34 +151,6 @@ bool AP_Baro_MS56XX::_init()
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* MS56XX crc4 method from datasheet for 16 bytes (8 short values) |
|
|
|
|
*/ |
|
|
|
|
uint16_t AP_Baro_MS56XX::crc4(uint16_t *data) |
|
|
|
|
{ |
|
|
|
|
uint16_t n_rem = 0; |
|
|
|
|
uint8_t n_bit; |
|
|
|
|
|
|
|
|
|
for (uint8_t cnt = 0; cnt < 16; cnt++) { |
|
|
|
|
/* uneven bytes */ |
|
|
|
|
if (cnt & 1) { |
|
|
|
|
n_rem ^= (uint8_t)((data[cnt >> 1]) & 0x00FF); |
|
|
|
|
} else { |
|
|
|
|
n_rem ^= (uint8_t)(data[cnt >> 1] >> 8); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (n_bit = 8; n_bit > 0; n_bit--) { |
|
|
|
|
if (n_rem & 0x8000) { |
|
|
|
|
n_rem = (n_rem << 1) ^ 0x3000; |
|
|
|
|
} else { |
|
|
|
|
n_rem = (n_rem << 1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return (n_rem >> 12) & 0xF; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uint16_t AP_Baro_MS56XX::_read_prom_word(uint8_t word) |
|
|
|
|
{ |
|
|
|
|
const uint8_t reg = CMD_MS56XX_PROM + (word << 1); |
|
|
|
@ -224,7 +197,7 @@ bool AP_Baro_MS56XX::_read_prom_5611(uint16_t prom[8])
@@ -224,7 +197,7 @@ bool AP_Baro_MS56XX::_read_prom_5611(uint16_t prom[8])
|
|
|
|
|
/* remove CRC byte */ |
|
|
|
|
prom[7] &= 0xff00; |
|
|
|
|
|
|
|
|
|
return crc_read == crc4(prom); |
|
|
|
|
return crc_read == crc_crc4(prom); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool AP_Baro_MS56XX::_read_prom_5637(uint16_t prom[8]) |
|
|
|
@ -257,7 +230,7 @@ bool AP_Baro_MS56XX::_read_prom_5637(uint16_t prom[8])
@@ -257,7 +230,7 @@ bool AP_Baro_MS56XX::_read_prom_5637(uint16_t prom[8])
|
|
|
|
|
/* remove CRC byte */ |
|
|
|
|
prom[0] &= ~0xf000; |
|
|
|
|
|
|
|
|
|
return crc_read == crc4(prom); |
|
|
|
|
return crc_read == crc_crc4(prom); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|