Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10 concurrency and synchronization module #150

Open
wants to merge 6 commits into
base: Dmitry.Domnin
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions 10-ConcurrencyAndSynchronization/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
NAME = mpu6050

ifneq ($(KERNELRELEASE),)

obj-m := $(NAME).o

else

NAMELINUX ?= [email protected]
MODULEDIR ?= /lib/modules/4.19.83-sunxi/kernel/drivers/iio/accel
KERNELDIR ?= /home/dmitry/GL/orange-pi-4.19.83
DTSDIR ?= $(PWD)/dtsi

export ARCH = arm
export CROSS_COMPILE ?= arm-linux-gnueabihf-

.PHONY: all clean

all: $(NAME).c
$(MAKE) -C $(KERNELDIR) M=$(CURDIR) modules

dtbo:
$(KERNELDIR)/scripts/dtc/dtc -I dts -O dtb \
-o $(DTSDIR)/$(NAME).dtbo \
$(DTSDIR)/$(NAME).dtsi

copymod: $(NAME).ko
scp $< $(NAMELINUX):$(MODULEDIR)

copysshid:
ssh-copy-id -i ~/.ssh/id_rsa.pub $(NAMELINUX)

copydtbo:
scp $(PWD)/dtsi/$(NAME).dtbo \
$(NAMELINUX):/boot/overlay-user

clean:
$(MAKE) -C $(KERNELDIR) M=$(CURDIR) clean
-rm $(DTSDIR)/$(NAME).dtbo

endif
21 changes: 21 additions & 0 deletions 10-ConcurrencyAndSynchronization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Concurrency and synchronization

## Homework

**(based on MPU6050 driver)**

_NB_:
Communication with peripheral device on i2c is quite slow asynchronous process
which responsiveness depends on the slave latency and bus utilisation.
Thus generally it's better to be done in background process.

1. Move interaction with MPU6050 into separate thread.

2. Protect static data of the driver (`g_mpu6050_data` in the master)
for the case of concurrent access.

3. Limit interaction with MPU6050 in case of frequent requests:
Define validity interval - if the latest read data is older than this threshold
then new data reading is performed, otherwise previously read data is returned.
(This threshold should be configurable parameter with reasonable default.)

22 changes: 22 additions & 0 deletions 10-ConcurrencyAndSynchronization/dtsi/mpu6050.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/dts-v1/;
/plugin/;

/ {
compatible = "allwinner,sun8i-h3";

fragment@0 {
target = <&i2c0>;
__overlay__ {
status = "okay";
#address-cells = <1>;
#size-cells = <0>;

mpu: mpu6050@68 {
compatible = "gl, mpu6050";
reg = <0x68>;
delay_ms = <10000>;
status = "okay";
};
};
};
};
33 changes: 33 additions & 0 deletions 10-ConcurrencyAndSynchronization/mpu6050-regs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef _MPU6050_REGS_H
#define _MPU6050_REGS_H

/* Registed addresses */
#define REG_CONFIG 0x1A
#define REG_GYRO_CONFIG 0x1B
#define REG_ACCEL_CONFIG 0x1C
#define REG_FIFO_EN 0x23
#define REG_INT_PIN_CFG 0x37
#define REG_INT_ENABLE 0x38
#define REG_ACCEL_XOUT_H 0x3B
#define REG_ACCEL_XOUT_L 0x3C
#define REG_ACCEL_YOUT_H 0x3D
#define REG_ACCEL_YOUT_L 0x3E
#define REG_ACCEL_ZOUT_H 0x3F
#define REG_ACCEL_ZOUT_L 0x40
#define REG_TEMP_OUT_H 0x41
#define REG_TEMP_OUT_L 0x42
#define REG_GYRO_XOUT_H 0x43
#define REG_GYRO_XOUT_L 0x44
#define REG_GYRO_YOUT_H 0x45
#define REG_GYRO_YOUT_L 0x46
#define REG_GYRO_ZOUT_H 0x47
#define REG_GYRO_ZOUT_L 0x48
#define REG_USER_CTRL 0x6A
#define REG_PWR_MGMT_1 0x6B
#define REG_PWR_MGMT_2 0x6C
#define REG_WHO_AM_I 0x75

/* Register values */
#define MPU6050_WHO_AM_I 0x68

#endif /* _MPU6050_REGS_H */
Loading