Hardware Reference
In-Depth Information
163 /* Access to CLK */
164 ugclk = (volatile unsigned *)map;
165
166 map = (char *)mmap(
167 NULL, /* Any address */
168 BLOCK_SIZE, /* # of bytes */
169 PROT_READ|PROT_WRITE,
170 MAP_SHARED, /* Shared */
171 fd, /* /dev/mem */
172 GPIO_BASE /* Offset to GPIO */
173 );
174
175 if ( (long)map == −1L ) {
176 perror("mmap(/dev/mem)");
177 exit(1);
178 }
179
180 /* Access to GPIO */
181 ugpio = (volatile unsigned *)map;
182
183 close(fd);
184 }
185
186 /*
187 * Set PWM to ratio N/M, and enable it :
188 */
189 static void
190 pwm_ratio(unsigned n,unsigned m) {
191
192 pwm_ctl−>PWEN1 = 0; /* Disable */
193
194 *pwm_rng1 = m;
195 *pwm_dat1 = n;
196
197 if ( !pwm_sta−>STA1 ) {
198 if ( pwm_sta−>RERR1 )
199 pwm_sta−>RERR1 = 1;
200 if ( pwm_sta−>WERR1 )
201 pwm_sta−>WERR1 = 1;
202 if ( pwm_sta−>BERR )
203 pwm_sta−>BERR = 1;
204 }
205
206 usleep(10); /* Pause */
207 pwm_ctl−>PWEN1 = 1; /* Enable */
208 }
209
 
Search WWH ::




Custom Search