Skip to content

Commit

Permalink
Add critical section for mpu6500 read() operations
Browse files Browse the repository at this point in the history
  • Loading branch information
shengwen-tw committed May 19, 2024
1 parent ec7dcde commit 43ca468
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/devices/mpu6500.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <fs/fs.h>
#include <kernel/delay.h>
#include <kernel/preempt.h>
#include <printk.h>

#include "lpf.h"
Expand Down Expand Up @@ -35,7 +36,10 @@ static ssize_t mpu6500_accel_read(struct file *filp,
if (size != sizeof(float[3]))
return -EINVAL;

preempt_disable();
memcpy(buf, mpu6500.accel_lpf, sizeof(float[3]));
preempt_enable();

return size;
}

Expand All @@ -57,7 +61,10 @@ static ssize_t mpu6500_gyro_read(struct file *filp,
if (size != sizeof(float[3]))
return -EINVAL;

preempt_disable();
memcpy(buf, mpu6500.gyro_raw, sizeof(float[3]));
preempt_enable();

return size;
}

Expand Down

0 comments on commit 43ca468

Please sign in to comment.