#include "ip445.h" #define INTERRUPT_LEVEL 5 /* level or bus IRQ - may not be used on all systems */ #define VECTOR 192 /* interrupt vector - may not be used on all systems */ #ifdef __rtems__ #define scanf(fmt...) (fflush(stdout),scanf(fmt)) #endif /* {+D} SYSTEM: Library Software FILENAME: drvr445.c MODULE NAME: main - main routine of example software. VERSION: A CREATION DATE: 05/19/98 DESIGNED BY: BDB CODED BY: BDB ABSTRACT: This module is the main routine for the example program which demonstrates how the IP445 Library is used. CALLING SEQUENCE: MODULE TYPE: void I/O RESOURCES: SYSTEM RESOURCES: MODULES CALLED: REVISIONS: DATE BY PURPOSE ------- ---- ------------------------------------------------ {-D} */ /* MODULES FUNCTIONAL DETAILS: This module is the main routine for the example program which demonstrates how the IP445 Library is used. */ void drvr445() { /* DECLARE LOCAL DATA AREAS: */ long IP_address; /* address for the ip card*/ long Base_address; /* Base address of the board*/ char cmd_buff[40]; /* command line input buffer */ long item; /* menu item selection variable */ long status; /* returned status of driver routines */ long addr; /* long to hold board address */ long flag; /* general flag for exiting loops */ unsigned finished; /* flag to exit program */ unsigned port; /* I/O port number */ unsigned point; /* I/O point number */ unsigned val; /* value of port or point */ struct status_blk s_block; /* allocate status param. blk */ /* ENTRY POINT OF ROUTINE: INITIALIZATION */ flag = 0; /* indicate board address not yet assigned */ finished = 0; /* indicate not finished with program */ s_block.bCarrier = FALSE; /* indicate no carrier initialized and set up yet */ s_block.bInitialized = FALSE; /* indicate not ready to talk to IP */ s_block.slotLetter = SLOT_A; s_block.nHandle = 0; /* make handle to a closed carrier board */ /* Initialize the Carrier library */ if(InitCarrierLib() != S_OK) { printf("\nUnable to initialize the carrier library. Exiting program.\n"); exit(0); } /* Open an instance of a carrier device */ if(CarrierOpen(0, &s_block.nHandle) != S_OK) { printf("\nUnable to Open instance of carrier.\n"); finished = 1; /* indicate finished with program */ } else flag = 1; /* Enter main loop */ while(!finished) { printf("\n\nIP445 Library Demonstration Version A\n\n"); printf(" 1. Exit this Program\n"); printf(" 2. Set Carrier Base Address\n"); printf(" 3. Set IP Slot Letter\n"); printf(" 4. Read ID ROM Command\n"); printf(" 5. Read Output Point (from output data latch)\n"); printf(" 6. Read Output Port (from output data latch)\n"); printf(" 7. Write Output Point\n"); printf(" 8. Write Output Port\n"); printf(" 9. Perform a Software Reset\n"); printf(" 10.Print Memmory Info\n"); printf("\nSelect: "); scanf("%ld",&item); /* perform the menu item selected. */ switch(item) { case 1: /* exit program command */ printf("Exit program(y/n)?: "); scanf("%s",cmd_buff); if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' ) finished++; break; case 2: /* set board address command */ do { if(flag == 0) { printf("\n\nenter base address of carrier board in hex: "); scanf("%lx",&addr); /* Set Carrier Address for Open Carrier Device */ SetCarrierAddress(s_block.nHandle, addr); /* Set Carrier Address */ GetCarrierAddress(s_block.nHandle, &addr); /*Getting the Base address for Base_address*/ Base_address = addr; } GetCarrierAddress(s_block.nHandle, &addr); /* Read back carrier address */ printf("address: %lx\n",addr); printf("is this value correct(y/n)?: "); scanf("%s",cmd_buff); if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' ) { SetCarrierAddress(s_block.nHandle, addr); /* Set Carrier Address */ GetCarrierAddress(s_block.nHandle, &addr); /*Getting the Base address for Base_address*/ Base_address = addr; if(CarrierInitialize(s_block.nHandle) == S_OK) /* Initialize Carrier */ { s_block.bCarrier = TRUE; } flag = 1; } else { flag = 0; } }while( cmd_buff[0] != 'y' && cmd_buff[0] != 'Y' ); break; case 3: /* set IP Slot Letter */ if(flag == 0 || s_block.bCarrier == FALSE) printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n"); else { printf("\n\nEnter IP slot letter (A, B etc...): "); scanf("%s",cmd_buff); cmd_buff[0] = (char)toupper((int)cmd_buff[0]); if(cmd_buff[0] < 'A' || cmd_buff[0] > GetLastSlotLetter()) { printf("\nInvalid Slot Letter!\n"); s_block.bCarrier = FALSE; } else { s_block.slotLetter = cmd_buff[0]; /* Get the IPACK's base address based on the Slot letter, and initialize the IPACK's data structure with the returned address */ if(GetIpackAddress(s_block.nHandle, s_block.slotLetter, &addr) != S_OK) { printf("\nUnable to Get Ipack Address.\n"); s_block.bInitialized = FALSE; } else { s_block.brd_ptr = (struct map445 *)addr; s_block.bInitialized = TRUE; IP_address = addr; printf("This is the address of map445: %x",IP_address); } } } break; case 4: /* read board I.D. command */ if(!s_block.bInitialized) printf("\n>>> ERROR: BOARD NOT SET UP <<<\n"); else { psts445(&s_block); /* read board */ } break; case 5: /* Read Digital I/O Point */ if(!s_block.bInitialized) printf("\n>>> ERROR: BOARD NOT SET UP <<<\n"); else { printf("Enter port number (0 - 3): "); scanf("%d",&port); printf("\nEnter I/O point number (0 - 7): "); scanf("%d",&point); printf("Value of Addr: %X",addr); status = rpnt445(addr,port,point); if(status == -1) printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n"); else { printf("\nValue of port %d, point %d: %lx\n",port ,point,status); } } break; case 6: /* Read Digital I/O Port */ if(!s_block.bInitialized) printf("\n>>> ERROR: BOARD NOT SET UP <<<\n"); else { printf("Enter port number (0 - 3): "); scanf("%d",&port); status = rprt445(addr,port); if(status == -1) printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n"); else printf("\nValue of port %d: %lx\n",port,status); } break; case 7: /* Write Digital I/O Point */ if(!s_block.bInitialized) printf("\n>>> ERROR: BOARD NOT SET UP <<<\n"); else { printf("Enter port number (0 - 3): "); scanf("%d",&port); printf("\nEnter I/O point number (0 - 7): "); scanf("%d",&point); printf("\nEnter point output value (0 or 1): "); scanf("%x",&val); status = wpnt445(addr,port,point,(byte)val); if(status == -1) printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n"); } break; case 8: /* Write Digital I/O Port */ if(!s_block.bInitialized) printf("\n>>> ERROR: BOARD NOT SET UP <<<\n"); else { printf("Enter port number (0 - 3): "); scanf("%d",&port); printf("\nEnter port output value in hex (0 - 0xFF): "); scanf("%x",&val); status = wprt445(addr,port,(byte)val); if(status == -1) printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n"); } break; case 9: /* Perform a Software Reset */ if(!s_block.bInitialized) printf("\n>>> ERROR: BOARD NOT SET UP<<<\n"); else { status = wcntl445(addr, (byte)0x01); /* call the routine that writes the control register */ } break; case 10: if(!s_block.bInitialized) printf("\n>>> ERROR: BOARD NOT SET UP<<<\n"); else { GetCarrierAddress(s_block.nHandle, &Base_address); /* Read back carrier address */ GetIpackAddress(s_block.nHandle, s_block.slotLetter, &IP_address); /* Fetch IP address */ printf("\nThis is the board's base address: %x \n", Base_address); printf("This is the IP card's address: %x \n", IP_address); printf("This is the address of the port: %x\n"); } break; } /* end of switch */ } /* end of while */ if(s_block.bCarrier) CarrierClose(s_block.nHandle); printf("\nEXIT PROGRAM\n"); } /* end of main */ /* {+D} SYSTEM: Library Software FILENAME: drvr445.c MODULE NAME: get_param_445 - get a parameter from the console VERSION: A CREATION DATE: 10/7/88 DESIGNED BY: RTL CODED BY: RTL ABSTRACT: Routine which is used to get parameters CALLING SEQUENCE: get_param_445(); MODULE TYPE: long I/O RESOURCES: SYSTEM RESOURCES: MODULES CALLED: REVISIONS: DATE BY PURPOSE ------- ---- ------------------------------------------------ {-D} */ long get_param_445() { /* declare local storage. */ long temp; /* print prompt string */ printf("enter hex parameter: "); /* get input */ scanf("%lx",&temp); /* output a linefeed */ printf("\n"); /* return the input value */ return(temp); } /* {+D} SYSTEM: Library Software FILENAME: drvr445.c MODULE NAME: psts445 - print board information VERSION: A CREATION DATE: 05/19/98 DESIGNED BY: BDB CODED BY: BDB ABSTRACT: Routine which is used to cause the "Read Board I.D." command to be executed and to print out the results to the console. CALLING SEQUENCE: psts445(&s_block) where: s_block (structure pointer) The address of the status param. block MODULE TYPE: void I/O RESOURCES: SYSTEM RESOURCES: MODULES CALLED: REVISIONS: DATE BY PURPOSE ------- ---- ------------------------------------------------ {-D} */ /* MODULES FUNCTIONAL DETAILS: */ void psts445(s_blk) struct status_blk *s_blk; { /* DECLARE LOCAL DATA AREAS: */ int item; /* menu item variable */ int i; /* loop index */ unsigned finished; /* flags to exit loops */ /* ENTRY POINT OF ROUTINE: */ finished = 0; while(!finished) { rsts445(s_blk); /* Read Command */ printf("\n\nBoard I.D. Information\n\n"); printf("Identification: "); for(i = 0; i < 4; i++) /* identification */ printf("%c",s_blk->id_prom[i]); printf("\nManufacturer's I.D.: %x",(byte)s_blk->id_prom[4]); printf("\nIP Model Number: %x",(byte)s_blk->id_prom[5]); printf("\nRevision: %x",(byte)s_blk->id_prom[6]); printf("\nReserved: %x",(byte)s_blk->id_prom[7]); printf("\nDriver I.D. (low): %x",(byte)s_blk->id_prom[8]); printf("\nDriver I.D. (high): %x",(byte)s_blk->id_prom[9]); printf("\nTotal I.D. Bytes: %x",(byte)s_blk->id_prom[10]); printf("\nCRC: %x",(byte)s_blk->id_prom[11]); printf("\n\n1 Return to Previous Menu\n"); printf("2 Read Again\n"); printf("\nselect: "); scanf("%d",&item); switch(item){ case 1: /* return to previous menu */ finished++; break; } } }