Changeset 10227 for src/router/libutils/gpio.c
- Timestamp:
- 08/27/08 20:16:34 (5 years ago)
- File:
-
- 1 edited
-
src/router/libutils/gpio.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/router/libutils/gpio.c
r10176 r10227 17 17 #include <stdlib.h> 18 18 #include <fcntl.h> 19 20 #if defined(HAVE_AR531X) || defined(HAVE_LSX) 19 #include <errno.h> 20 21 #if defined(HAVE_AR531X) || defined(HAVE_LSX) || defined(HAVE_DANUBE) 21 22 22 23 void set_gpio( int gpio, int value ) … … 93 94 * ERROR HANDLING; you can check errno to see what went wrong 94 95 */ 95 // fprintf (stderr, "Error: could not open %s (%d)\n", filename, 96 // errno); 96 fprintf( stderr, "Error: could not open %s (%d)\n", filename, errno ); 97 97 return; 98 98 } … … 108 108 * ERROR HANDLING; you can check errno to see what went wrong 109 109 */ 110 // fprintf (stderr, "Error: ioctl failed: %s (%d)\n", strerror 111 // (errno), 112 // errno); 110 fprintf( stderr, "Error: ioctl failed: %s (%d)\n", strerror( errno ), 111 errno ); 113 112 return; 114 113 } … … 124 123 * ERROR HANDLING; you can check errno to see what went wrong 125 124 */ 126 // fprintf (stderr, "Error: ioctl failed: %s (%d)\n", strerror 127 // (errno), 128 // errno); 125 fprintf( stderr, "Error: ioctl failed: %s (%d)\n", strerror( errno ), 126 errno ); 129 127 return; 130 128 } … … 147 145 * ERROR HANDLING; you can check errno to see what went wrong 148 146 */ 147 fprintf( stderr, "Error: ioctl failed: %s (%d)\n", strerror( errno ), 148 errno ); 149 149 return 1; 150 150 } … … 160 160 * ERROR HANDLING; you can check errno to see what went wrong 161 161 */ 162 fprintf( stderr, "Error: ioctl failed: %s (%d)\n", strerror( errno ), 163 errno ); 162 164 return 1; 163 165 } … … 172 174 * ERROR HANDLING; you can check errno to see what went wrong 173 175 */ 176 fprintf( stderr, "Error: ioctl failed: %s (%d)\n", strerror( errno ), 177 errno ); 178 return 1; 179 } 180 181 close( file ); 182 return _bit.state; 183 } 184 185 #elif HAVE_STORM 186 #include <linux/mii.h> 187 #include <linux/sockios.h> 188 #include <net/if.h> 189 #include <arpa/inet.h> 190 #include <sys/socket.h> 191 #include <linux/sockios.h> 192 #include <linux/mii.h> 193 #define u8 unsigned char 194 #define u32 unsigned long 195 196 #define GPIO_GET_BIT 0x0000001 197 #define GPIO_SET_BIT 0x0000002 198 #define GPIO_GET_CONFIG 0x0000003 199 #define GPIO_SET_CONFIG 0x0000004 200 201 #define IXP4XX_GPIO_OUT 0x1 202 #define IXP4XX_GPIO_IN 0x2 203 204 struct gpio_bit 205 { 206 unsigned char bit; 207 unsigned char state; 208 }; 209 210 char *filename = "/dev/gpio"; 211 212 void set_gpio( int gpio, int value ) 213 { 214 int file; 215 struct gpio_bit _bit; 216 217 /* 218 * open device 219 */ 220 if( ( file = open( filename, O_RDWR ) ) == -1 ) 221 { 222 /* 223 * ERROR HANDLING; you can check errno to see what went wrong 224 */ 225 fprintf( stderr, "Error: could not open %s (%d)\n", filename, errno ); 226 return; 227 } 228 229 /* 230 * Config bit as output 231 */ 232 _bit.bit = gpio; 233 _bit.state = IXP4XX_GPIO_OUT; 234 if( ioctl( file, GPIO_SET_CONFIG, ( long )&_bit ) < 0 ) 235 { 236 /* 237 * ERROR HANDLING; you can check errno to see what went wrong 238 */ 239 fprintf( stderr, "Error: ioctl failed: %s (%d)\n", strerror( errno ), 240 errno ); 241 return; 242 } 243 244 /* 245 * Write data 246 */ 247 _bit.bit = gpio; 248 _bit.state = value; 249 if( ioctl( file, GPIO_SET_BIT, ( unsigned long )&_bit ) < 0 ) 250 { 251 /* 252 * ERROR HANDLING; you can check errno to see what went wrong 253 */ 254 fprintf( stderr, "Error: ioctl failed: %s (%d)\n", strerror( errno ), 255 errno ); 256 return; 257 } 258 259 close( file ); 260 261 } 262 263 int get_gpio( int gpio ) 264 { 265 int file; 266 struct gpio_bit _bit; 267 268 /* 269 * open device 270 */ 271 if( ( file = open( filename, O_RDONLY ) ) == -1 ) 272 { 273 /* 274 * ERROR HANDLING; you can check errno to see what went wrong 275 */ 276 fprintf( stderr, "Error: could not open %s (%d)\n", filename, errno ); 277 return 1; 278 } 279 280 /* 281 * Config pin as input 282 */ 283 _bit.bit = gpio; 284 _bit.state = IXP4XX_GPIO_IN; 285 if( ioctl( file, GPIO_SET_CONFIG, ( long )&_bit ) < 0 ) 286 { 287 /* 288 * ERROR HANDLING; you can check errno to see what went wrong 289 */ 290 fprintf( stderr, "Error: ioctl failed: %s (%d)\n", strerror( errno ), 291 errno ); 292 return 1; 293 } 294 295 /* 296 * Read data 297 */ 298 _bit.bit = gpio; 299 if( ioctl( file, GPIO_GET_BIT, ( long )&_bit ) < 0 ) 300 { 301 /* 302 * ERROR HANDLING; you can check errno to see what went wrong 303 */ 304 fprintf( stderr, "Error: ioctl failed: %s (%d)\n", strerror( errno ), 305 errno ); 174 306 return 1; 175 307 }
Note: See TracChangeset
for help on using the changeset viewer.
