Hardware Reference
In-Depth Information
117 static void
118 pwm_init() {
119 int fd;
120 char *map;
121
122 fd = open("/dev/mem",O_RDWR|O_SYNC); /* Needs root access */
123 if ( fd < 0 ) {
124 perror("Opening /dev/mem");
125 exit(1);
126 }
127
128 map = (char *)mmap(
129 NULL, /* Any address */
130 BLOCK_SIZE, /* # of bytes */
131 PROT_READ|PROT_WRITE,
132 MAP_SHARED, /* Shared */
133 fd, /* /dev/mem */
134 PWM_BASE /* Offset to GPIO */
135 );
136
137 if ( (long)map == −1L ) {
138 perror("mmap(/dev/mem)");
139 exit(1);
140 }
141
142 /* Access to PWM */
143 ugpwm = (volatile unsigned *)map;
144 pwm_ctl = (struct S_PWM_CTL *) &ugpwm[BCM2835_PWM_CONTROL];
145 pwm_sta = (struct S_PWM_STA *) &ugpwm[BCM2835_PWM_STATUS];
146 pwm_rng1 = &ugpwm[BCM2835_PWM0_RANGE];
147 pwm_dat1 = &ugpwm[BCM2835_PWM0_DATA];
148
149 map = (char *)mmap(
150 NULL, /* Any address */
151 BLOCK_SIZE, /* # of bytes */
152 PROT_READ|PROT_WRITE,
153 MAP_SHARED, /* Shared */
154 fd, /* /dev/mem */
155 CLK_BASE /* Offset to GPIO */
156 );
157
158 if ( (long )map == −1L ) {
159 perror("mmap(/dev/mem)");
160 exit(1);
161 }
162
Search WWH ::




Custom Search