#include #include #include #include #include #include #include "rbm_functions.h" //========================================================================================== // Used by main to communicate with ARGP parse_opt struct args { int verbose, init, status, read, write, dta_gvn; unsigned int address, data; }; //========================================================================================== //========================================================================================== //========================================================================================== int main(int argc, char ** argv) { struct args args; // Default values args.verbose = 0; args.init = 0; args.status = 0; args.read = 0; args.write = 0; args.address = 0; args.data = 0; args.dta_gvn = 0; while ( 1 ) { int result = getopt(argc, argv, "visr:w:d:"); if (result == -1) break; /* end of list */ switch (result) { case '?': /* unknown parameter */ break; case ':': /* missing argument of a parameter */ fprintf(stderr, "missing argument.\n"); break; case 'v': args.verbose = 1; // break; case 'i': args.init = 1; // Do only init break; case 's': args.status = 1; // Dump only status break; case 'r': sscanf( optarg, "%i", &args.address ); //args.address=(unsigned int)lexical_castoptarg; args.read = 1; // Read break; case 'w': sscanf( optarg, "%i", &args.address ); //args.address=(unsigned int)atoi(optarg); args.write = 1; // Write break; case 'd': sscanf( optarg, "%i", &args.data ); //args.data=(unsigned int)atoi(optarg); args.dta_gvn = 1; // break; default: /* unknown */ break; } } while (optind < argc) { printf("other parameter: <%s>\n", argv[optind++]); } if ( args.init ) { printf("Initializing bus (direct mode)\n"); rbm_init( args.verbose ); // Init bus } if ( args.status ) rbm_sts(args.verbose); // Read bus status if ( args.write ) { if (!args.dta_gvn) printf("No new value specified, doing nothing\n"); else rbm_write(args.address, args.data, args.verbose); } if ( args.read ) { // Read and dump result unsigned int result = rbm_read(args.address, args.verbose); printf("Data: 0x%x\n", result); } return 0; }