Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Git Source Tree
Root/
| 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Filename: irq_main.c |
| 4 | * Author: Carlos Camargo |
| 5 | * Created: June 10, 2010 |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | ******************************************************************************/ |
| 13 | |
| 14 | #include "stdio.h" |
| 15 | #include "sys/types.h" |
| 16 | #include "sys/stat.h" |
| 17 | #include "fcntl.h" |
| 18 | #include <unistd.h> |
| 19 | #include <stdlib.h> |
| 20 | |
| 21 | int main(int argc, char **argv) { |
| 22 | int fileNum, bytes; |
| 23 | unsigned char buf[40]; |
| 24 | size_t nbytes; |
| 25 | ssize_t bytes_read; |
| 26 | |
| 27 | if(argc != 2){ |
| 28 | fprintf(stderr,"\nUsage: %s enable|disable|read \n",argv[0]); |
| 29 | } |
| 30 | |
| 31 | nbytes = sizeof(int); |
| 32 | fileNum = open("/dev/irq", O_RDWR); |
| 33 | if (fileNum < 0) { |
| 34 | printf(" Unable to open device\n"); |
| 35 | exit(1); |
| 36 | } |
| 37 | printf("Device opened successfully \n"); |
| 38 | |
| 39 | if(!strcmp(argv[1], "enable")) |
| 40 | write(fileNum, "Q", 1); |
| 41 | if(!strcmp(argv[1], "disable")) |
| 42 | write(fileNum, "S", 1); |
| 43 | if(!strcmp(argv[1], "read")){ |
| 44 | read(fileNum, buf, nbytes); |
| 45 | printf("Interrupts = %d \n", *((int*)(buf))); |
| 46 | } |
| 47 | if( (strcmp(argv[1], "read") != 0 ) & (strcmp(argv[1], "disable") != 0) & (strcmp(argv[1], "enable") != 0) ) |
| 48 | fprintf(stderr,"\nUsage: %s enable|disable|read \n",argv[0]); |
| 49 | |
| 50 | close(fileNum); |
| 51 | |
| 52 | return (0); |
| 53 | } |
| 54 |
Branches:
master
