Skip to content

Commit

Permalink
Fix CRC and test on Raspberry Pi Pico
Browse files Browse the repository at this point in the history
  • Loading branch information
linguini1 committed Jan 15, 2025
1 parent b964eee commit 165319c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
16 changes: 16 additions & 0 deletions boards/arm/rp2040/common/src/rp2040_common_bringup.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
#include "rp2040_i2c.h"
#endif

#ifdef CONFIG_SENSORS_MS56XX
#include <nuttx/sensors/ms56xx.h>
#include "rp2040_i2c.h"
#endif

#ifdef CONFIG_SENSORS_MAX6675
#include <nuttx/sensors/max6675.h>
#include "rp2040_max6675.h"
Expand Down Expand Up @@ -508,6 +513,17 @@ int rp2040_common_bringup(void)
}
#endif


#ifdef CONFIG_SENSORS_MS56XX
/* Try to register MS56xx device at I2C0 */
ret = ms56xx_register(rp2040_i2cbus_initialize(0), 0, MS56XX_ADDR0,
MS56XX_MODEL_MS5611);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: couldn't register MS5611: %d\n", ret);
}
#endif

#ifdef CONFIG_VIDEO_FB
ret = fb_register(0, 0);
if (ret < 0)
Expand Down
27 changes: 13 additions & 14 deletions include/nuttx/sensors/msxxxx_crc4.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,41 @@ static uint8_t msxxxx_crc4(FAR uint16_t *src,
uint8_t crcndx,
uint16_t crcmask)
{
uint16_t cnt;
uint16_t n_rem;
uint16_t crc_read;
uint16_t cnt; /* simple counter */
uint16_t n_rem; /* crc reminder */
uint16_t crc_read; /* original value of the crc */
uint8_t n_bit;

n_rem = 0x00;
crc_read = src[crcndx];
src[crcndx] &= ~crcmask;
crc_read = src[crcndx]; /* save read CRC */
src[crcndx] &= ~crcmask; /* CRC byte is replaced by 0 */

for (cnt = 0; cnt < 16; cnt++)
for (cnt = 0; cnt < 16; cnt++) /* operation is performed on bytes */
{
if (cnt % 2 == 1)
{
n_rem ^= src[cnt >> 1] & 0x00ff;
n_rem ^= (uint16_t)((src[cnt >> 1]) & 0x00ff);
}
else
{
n_rem ^= src[cnt >> 1] >> 8;
n_rem ^= (uint16_t)(src[cnt >> 1] >> 8);
}

for (n_bit = 8; n_bit > 0; n_bit--)
{
if (n_rem & (0x8000) != 0)
if (n_rem & (0x8000))
{
n_rem = (n_rem << 1) ^ 0x3000;
}
else
{
n_rem <<= 1;
n_rem = (n_rem << 1);
}
}
}

n_rem = (n_rem >> 12) & 0x000f;
src[crcndx] = crc_read;
return n_rem ^ 0x00;
n_rem = (0x000f & (n_rem >> 12)); /* final 4-bit reminder is CRC code */
src[crcndx] = crc_read; /* restore the crc_read to its original place */
return (n_rem ^ 0x00);
}

#endif /* __INCLUDE_NUTTX_SENSORS_MSXXXX_CRC4_H */

0 comments on commit 165319c

Please sign in to comment.