Hardware Reference
In-Depth Information
10 #include <math.h>
11 #include <ctype.h>
12 #include <termio.h>
13 #include <sys/mman.h>
14 #include <pthread.h>
15 #include <assert.h>
16
17 #include "gpio_io.c" /* GPIO routines */
18 #include "timed_wait.c" /* timed_wait() */
19
20 /*
21 * GPIO definitions :
22 */
23 static const int g_enable = 17; /* L298 EnA and EnB */
24 static const int g_in1 = 27; /* L298 In1 */
25 static const int g_in2 = 22; /* L298 In2 */
26 static const int g_in3 = 23; /* L298 In3 */
27 static const int g_in4 = 24; /* L298 In4 */
28
29 static volatile int stepper_mode = 0; /* Stepper mode − 1 */
30 static volatile float step_time = 0.1; /* Step time in seconds */
31
32 static volatile char cmd = 0; /* Thread command when nonzero */
33 static volatile char stop = 0; /* Stop thead when nonzero */
34 static volatile char stopped = 0; /* True when thread has stopped */
35
36 static pthread_mutex_t mutex; /* For inter−thread locks */
37 static pthread_cond_t cond; /* For inter−thread signaling */
38
39 /*
40 * Await so many fractional seconds
41 */
42 static void
43 await(float seconds) {
44 long sec, usec;
45
46 sec = floor(seconds); /* Seconds to wait */
47 usec = floor((seconds−sec)*1000000); /* Microseconds */
48 timed_wait(sec,usec,0); /* Wait */
49 }
50
51 /*
52 * Enable/Disable drive to the motor
53 */
54 static inline void
Search WWH ::




Custom Search