Hardware Reference
In-Depth Information
97 set_mode(int mode) {
98 enable(0);
99 stepper_mode = mode;
100 }
101
102 /*
103 * Take a command off the input queue
104 */
105 static char
106 get_cmd(void) {
107 char c;
108
109 pthread_mutex_lock(&mutex);
110
111 while ( !cmd )
112 pthread_cond_wait(&cond,&mutex);
113
114 c = cmd;
115 cmd = stop = 0;
116 pthread_mutex_unlock(&mutex);
117 pthread_cond_signal (&cond); /* Signal that cmd is taken */
118
119 return c;
120 }
121
122 /*
123 * Stepper controller thread :
124 */
125 static void *
126 controller(void * ignored) {
127 int command;
128 int direction;
129
130 for ( stopped = 1; ; ) {
131 command = get_cmd();
132 direction = command == 'F' ? 1 : −1;
133
134 for ( stopped = 0; !stop; ) {
135 step(direction);
136 await(step_time);
137 }
138 stopped = 1;
139 }
140 return 0;
141 }
142
143 /*
Search WWH ::




Custom Search