Professional Documents
Culture Documents
Lap Trinh He Nhung Esprogramming c2 1636 PDF
Lap Trinh He Nhung Esprogramming c2 1636 PDF
Lp trnh vo ra c bn
57
Mc tiu chng 2
Sau khi kt thc chng n{y, sinh vin c th
Nm c nguyn tc lp trnh giao tip v{o ra c
bn trn h iu h{nh Linux nhng
Lp trnh giao tip thit b (ghp ni GPIO) vi
driver ~ c (led, button)
Bit c|ch lp trnh giao tip GPIO m rng da trn
giao din sysfs (gpiolib)
58
Ni dung bi hc
2.1. C ch lp trnh giao tip thit b
2.2. Lp trnh iu khin led n
2.3. Lp trnh giao tip nt bm
2.4. Lp trnh giao tip GPIO m rng
59
60
User Space
Cc hm giao tip chun:
Device files
Device Drivers
open
close
read
write
ioctl
Kernel Space
Phn cng
61
62
63
64
65
66
67
Device files
Device Drivers
Phn cng
leds.c
/dev/leds
Hm giao tip:
open
close
ioctl
Mini2440_leds.c
GPIO Port
68
69
70
71
Device files
Device Drivers
Phn cng
Buttons.c
Hm giao tip:
open
close
read
/dev/buttons
Mini2440_buttons.c
GPIO Port
72
Lp trnh ghp ni nt bm
buttons_fd=open(/dev/buttons,0)
buttons_fd: file id
/dev/buttons: device file
read(buttons_fd,current_buttons,sizeof(curren
t_buttons)
c trng th|i c|c nt bm
close(buttons_fd): ng file
M~ ngun driver cho nt bm
linux2.6.32.2/drivers/char/mini2440_buttons.c
Lp trnh nhng ARM-Linux
73
74
75
76
77
78
Tho lun
79