// User application // Function: Accepts two integers as input and prints their sum // Uses the device driver associated with the FPGA adder to get the sum #include "stdio.h" #include #include #include #include #define READ_CMD (0x0 << 31) #define WRITE_CMD1 (0x1 << 31) #define WRITE_CMD2 (0x1 << 30) #define ADDER_BASE 0xd3000000 #define ADDER_MASK 0x00001fff #define ADDER_SIZE 0x20000 #define COMMAND_MASK 0x80000000 int main(int argc, char * argv[]) { // Variable declarations int val1, val2, result; //Ensure proper usage if(argc != 3) { printf("Usage: %s value1 value2\n",argv[0]); return -1; } //assign val1 and val2 val1 = atoi(argv[1]); val2 = atoi(argv[2]); //Open the adder as a file int fd = open("/dev/adder", O_RDWR|O_SYNC); printf("fd %d\n",fd); if(!fd) { printf("Unable to open /dev/adder. Ensure it exists (major=246, minor=1)\n"); return -1; } // Write the input values ioctl(fd, WRITE_CMD1, &val1); printf ("%d written as first value\n",val1); ioctl(fd, WRITE_CMD2, &val2); printf ("%d written as second value\n",val2); // Read back output value ioctl(fd, READ_CMD, &result); printf("The sum of %d and %d is %d\n", val1, val2, result); close(fd); return 0; }