Hardware Reference
In-Depth Information
Source Code
The next few pages list the source code for the program. This was assembled into one
compile unit by using the #include directive. This was done to save pages by eliminating
additional header files and extern declarations.
the source code for gpio_io.c is found in Chapter 10 of Raspberry Pi Hardware
Reference (apress, 2014).
Note
1 /
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
2
dht11.c: Direct GPIO access reading DHT11 humidity and temp sensor.
3
/
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <fcntl.h>
8 #include <unistd.h>
9 #include <errno.h>
10 #include <setjmp.h>
11 #include <sys/mman.h>
12 #include <signal.h>
13
14 #include "gpio_io.c" /
GPIO routines
/
15 #include "timed_wait.c" /
timed_wait()
/
16
17 static const int gpio_dht11 = 22; /
GPIO pin
/
18 static jmp_buf timeout_exit; /
longjmp on timeout
/
19 static int is_signaled = 0; /
Exit program if signaled
/
20
21/
22
Signal handler to quit the program:
23
/
24 static void
25 sigint_handler(int signo) {
26 is_signaled = 1; /
Signal to exit program
/
27 }
28
29 /
30
Read the GPIO line status:
31
/
32 static inline unsigned
33 gread(void) {
34 return gpio_read(gpio_dht11);
35 }
36
 
 
Search WWH ::




Custom Search