Bug in lis2ds12_fifo_data_level_get implementation
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- c
- Domain
- embedded-iot
Research direction
Start at the lis2ds12_fifo_data_level_get implementation and consult the LIS2DS12 datasheet sections 8.24 and 8.25. Verify the FIFO sample count comes from the samples register rather than the threshold register, then check the driver’s available build or validation process to confirm the corrected behavior.
Written by the indexing model from the issue text.
Description
Current:
int32_t lis2ds12_fifo_data_level_get(stmdev_ctx_t *ctx, uint16_t *val)
{
lis2ds12_fifo_ths_t fifo_ths;
lis2ds12_fifo_src_t fifo_src;
int32_t ret;
ret = lis2ds12_read_reg(ctx, LIS2DS12_FIFO_THS, (uint8_t *)&fifo_ths, 1);
if (ret == 0)
{
ret = lis2ds12_read_reg(ctx, LIS2DS12_FIFO_SRC, (uint8_t *)&fifo_src, 1);
*val = fifo_src.diff;
*val = (*val * 256U) + fifo_ths.fth;
}
return ret;
}
Suggested:
int32_t lis2ds12_fifo_data_level_get(stmdev_ctx_t *ctx, uint16_t *val)
{
uint8_t samples;
lis2ds12_fifo_src_t fifo_src;
int32_t ret;
ret = lis2ds12_read_reg(ctx, LIS2DS12_FIFO_SAMPLES, &samples, 1);
if (ret == 0)
{
ret = lis2ds12_read_reg(ctx, LIS2DS12_FIFO_SRC, (uint8_t *)&fifo_src, 1);
*val = fifo_src.diff;
*val = (*val * 256U) + samples;
}
return ret;
}
The problem with the current implementation is that it uses the LIS2DS12_FIFO_THS register to get the count of the samples in the FIFO. This is wrong because that register is the FIFO threshold. The function should be using LIS2DS12_FIFO_SAMPLES instead. This is all based on this datasheet, sections 8.24 and 8.25.
- Dominant language
- C
- Stars
- 6
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Similar issues
-
level/task module/gcp type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 1/5 Under an hour Newbie friendliness 86/100
hapostgres/pg_auto_failover#1190 ·
-
docs
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
P3 sonic-vpp
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
sonic-net/sonic-buildimage#29662 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
spack/spack-packages#6586 ·