示例#1
0
void PrintMemScreen( int fd ) {

    int i, j;
    char tmp;


    if( enter_mem ) {


        if( ibuf == 0x0a ) {

            enter_mem = 0;
            return;
        }
        else if ( ((ibuf >= '0') && (ibuf <= '9'))
                || ((ibuf >= 'a') && (ibuf <= 'f'))
                || ((ibuf >= 'A') && (ibuf <= 'F')) ) {


            phyaddr <<= 4;
            phyaddr &= ~0x0fUL;

            if( ibuf <= '9' ) {

                phyaddr |= (unsigned long)(ibuf - 0x30);
            }
            else if( ibuf > 'F' ) {

                phyaddr |= (unsigned long)(ibuf - 0x60 + 9);
            }
            else {

                phyaddr |= (unsigned long)(ibuf - 0x40 + 9);
            }
        }


    }
    else {

        if( ibuf == KEY_UP ) {

            if( x > 0 ) {

                x--;
            }

            input = 0;
        }
        else if( ibuf == KEY_DOWN ) {

            if( x < 15 ) {

                x++;
            }

            input = 0;
        }
        else if( ibuf == KEY_LEFT ) {

            if( y > 0 ) {

                y--;
            }

            input = 0;
        }
        else if( ibuf == KEY_RIGHT ) {

            if( y < 15 ) {

                y++;
            }

            input = 0;
        }
        else if( ibuf == KEY_NPAGE ) {

            if( (maxaddr - phyaddr) >= LFDD_MASSBUF_SIZE ) {
        
                phyaddr += LFDD_MASSBUF_SIZE;
            }
            else {
        
                phyaddr = 0;
            }

            input = 0;
        }
        else if( ibuf == KEY_PPAGE ) {

            if( phyaddr >= LFDD_MASSBUF_SIZE ) {
        
                phyaddr -= LFDD_MASSBUF_SIZE;
            }
            else {
        
                phyaddr = (maxaddr - LFDD_MASSBUF_SIZE + 1);
            }

            input = 0;
        }
        else if( ibuf == 0x0a ) {

            if( input ) {

                input = 0;
                WriteMemByteValue( fd );
            }
        }
        else if ( ((ibuf >= '0') && (ibuf <= '9'))
                || ((ibuf >= 'a') && (ibuf <= 'f'))
                || ((ibuf >= 'A') && (ibuf <= 'F')) ) {

            if( !input ) {

                wbuf = 0x00;
                input = 1;
            }


            wbuf <<= 4;
            wbuf &= 0xf0;


            if( ibuf <= '9' ) {

                wbuf |= ibuf - 0x30;
            }
            else if( ibuf > 'F' ) {

                wbuf |= ibuf - 0x60 + 9;
            }
            else {

                wbuf |= ibuf - 0x40 + 9;
            }
        }
    }


    //
    // Print Offset Text
    //
    PrintFixedWin( MemScreen, offset, 17, 52, 4, 1, RED_BLUE, "0000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F0000\n0010\n0020\n0030\n0040\n0050\n0060\n0070\n0080\n0090\n00A0\n00B0\n00C0\n00D0\n00E0\n00F0" );


    //
    // Print memory address
    //
    if( !MemScreen.info ) {

        MemScreen.info = newwin( 1, 47, 22, 0 );
        MemScreen.p_info = new_panel( MemScreen.info );
    }
    wbkgd( MemScreen.info, COLOR_PAIR( WHITE_BLUE ) );
    wattrset( MemScreen.info, COLOR_PAIR( WHITE_BLUE ) | A_BOLD );
    mvwprintw( MemScreen.info, 0, 0, "Type: Memory    Address: " );


    if( enter_mem ) {
    
        if( counter % 2 ) {
                   
            wattrset( MemScreen.info, COLOR_PAIR( YELLOW_RED ) | A_BOLD );
        }
        else {
                   
            wattrset( MemScreen.info, COLOR_PAIR( YELLOW_BLACK ) | A_BOLD );
        }
       
        wprintw( MemScreen.info, "%*.*lX", sizeof(phyaddr) * 2, sizeof(phyaddr) * 2, phyaddr );

        counter++;
    }
    else {
    
        wattrset( MemScreen.info, COLOR_PAIR( WHITE_BLUE ) | A_BOLD );
        wprintw( MemScreen.info, "%*.*lX", sizeof(phyaddr) * 2, sizeof(phyaddr) * 2, phyaddr );
    }

    
    wattrset( MemScreen.info, COLOR_PAIR( WHITE_BLUE ) | A_BOLD );
    wprintw( MemScreen.info, "h" );
    wattrset( MemScreen.info, A_NORMAL );


    //
    // Read memory space 256 bytes
    //
    if( enter_mem ) {

        memset( lfdd_mem_data.mass_buf, 0xff, LFDD_MASSBUF_SIZE );
    }
    else {

        lfdd_mem_data.addr = phyaddr;
        LFDD_IOCTL( fd, LFDD_MEM_READ_256BYTE, lfdd_mem_data );
    }


    //
    // Print ASCII content
    //
    if( !MemScreen.ascii ) {

        MemScreen.ascii = newwin( 17, 16, 4, 58 );
        MemScreen.p_ascii = new_panel( MemScreen.ascii );
    }


    wbkgd( MemScreen.ascii, COLOR_PAIR( CYAN_BLUE ) );
    wattrset( MemScreen.ascii, COLOR_PAIR( CYAN_BLUE ) | A_BOLD );
    mvwprintw( MemScreen.ascii, 0, 0, "" );

    wprintw( MemScreen.ascii, "0123456789ABCDEF" );
    for( i = 0 ; i < 16 ; i++ ) {

        for( j = 0 ; j < 16 ; j++ ) {

            tmp = ((unsigned char)lfdd_mem_data.mass_buf[ (i * 16) + j ]);
            if( (tmp >= '!') && (tmp <= '~') ) {
            
                wprintw( MemScreen.ascii, "%c", tmp );
            }
            else {

                wprintw( MemScreen.ascii, "." ); 
            }
        }
    }

    wattrset( MemScreen.ascii, A_NORMAL );


    //
    // Print 256bytes content
    //
    if( !MemScreen.value ) {

        MemScreen.value = newwin( 17, 47, 5, 6 );
        MemScreen.p_value = new_panel( MemScreen.value );
    }


    wbkgd( MemScreen.value, COLOR_PAIR( WHITE_BLUE ) );
    mvwprintw( MemScreen.value, 0, 0, "" );


    for( i = 0 ; i < 16 ; i++ ) {

        for( j = 0 ; j < 16 ; j++ ) {
    
                
            //
            // Change Color Pair
            //
            if( y == j && x == i ) {
              
                if( input ) {
                
                    if( counter % 2 ) {
                    
                        wattrset( MemScreen.value, COLOR_PAIR( YELLOW_RED ) | A_BOLD );
                    }
                    else {
                    
                        wattrset( MemScreen.value, COLOR_PAIR( YELLOW_BLACK ) | A_BOLD );
                    }
                    
                    counter++;
                }
                else {

                    wattrset( MemScreen.value, COLOR_PAIR( BLACK_YELLOW ) | A_BOLD ); 
                }
            }
            else if( ((unsigned char)lfdd_mem_data.mass_buf[ (i * 16) + j ]) ) {
           
                wattrset( MemScreen.value, COLOR_PAIR( YELLOW_BLUE ) | A_BOLD );            
            }
            else {
            
                wattrset( MemScreen.value, COLOR_PAIR( WHITE_BLUE ) | A_BOLD );
            }


            //
            // Handle input display
            //
            if( y == j && x == i ) {


                if( input ) {
                
                    wprintw( MemScreen.value, "%2.2X", (unsigned char)wbuf );
                }
                else {
                
                    wprintw( MemScreen.value, "%2.2X", (unsigned char)lfdd_mem_data.mass_buf[ (i * 16) + j ] );
                }
            }
            else {

                wprintw( MemScreen.value, "%2.2X", (unsigned char)lfdd_mem_data.mass_buf[ (i * 16) + j ] );
            }


            //
            // End of color pair
            //
            wattrset( MemScreen.value, A_NORMAL );


            //
            // Move to next byte
            //
            if( j != 15 ) {
          
                wprintw( MemScreen.value, " " );
            }
        }
    }
}
示例#2
0
void PrintCmosScreen() {

    int i, j;
    char tmp;


        if( ibuf == KEY_UP ) {

            if( x > 0 ) {

                x--;
            }

            input = 0;
        }
        else if( ibuf == KEY_DOWN ) {

            if( x < 15 ) {

                x++;
            }

            input = 0;
        }
        else if( ibuf == KEY_LEFT ) {

            if( y > 0 ) {

                y--;
            }

            input = 0;
        }
        else if( ibuf == KEY_RIGHT ) {

            if( y < 15 ) {

                y++;
            }

            input = 0;
        }
        else if( ibuf == KEY_NPAGE ) {

            if( (0xffffffff - cmos_addr) >= LFDD_MASSBUF_SIZE ) {
        
                cmos_addr += LFDD_MASSBUF_SIZE;
            }
            else {
        
                cmos_addr = 0;
            }

            input = 0;
        }
        else if( ibuf == KEY_PPAGE ) {

            if( cmos_addr >= LFDD_MASSBUF_SIZE ) {
        
                cmos_addr -= LFDD_MASSBUF_SIZE;
            }
            else {
        
                cmos_addr = (0xffffffff - LFDD_MASSBUF_SIZE + 1);
            }

            input = 0;
        }
        else if( ibuf == 0x0a ) {

            if( input ) {

                input = 0;
				WriteCmosByteValue();
            }
        }
        else if ( ((ibuf >= '0') && (ibuf <= '9'))
                || ((ibuf >= 'a') && (ibuf <= 'f'))
                || ((ibuf >= 'A') && (ibuf <= 'F')) ) {

            if( !input ) {

                wbuf = 0x00;
                input = 1;
            }


            wbuf <<= 4;
            wbuf &= 0xf0;


            if( ibuf <= '9' ) {

                wbuf |= ibuf - 0x30;
            }
            else if( ibuf > 'F' ) {

                wbuf |= ibuf - 0x60 + 9;
            }
            else {

                wbuf |= ibuf - 0x40 + 9;
            }
        }


    //
    // Print Offset Text
    //
    PrintFixedWin( CmosScreen, offset, 17, 52, 4, 1, RED_BLUE, "0000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F0000\n0010\n0020\n0030\n0040\n0050\n0060\n0070\n0080\n0090\n00A0\n00B0\n00C0\n00D0\n00E0\n00F0" );


    //
    // Print memory address
    //
    if( !CmosScreen.info ) {

        CmosScreen.info = newwin( 1, 47, 22, 0 );
        CmosScreen.p_info = new_panel( CmosScreen.info );
    }
    wbkgd( CmosScreen.info, COLOR_PAIR( WHITE_BLUE ) );
    wattrset( CmosScreen.info, COLOR_PAIR( WHITE_BLUE ) | A_BOLD );
    mvwprintw( CmosScreen.info, 0, 0, "Type: CMOS" );


    //
    // Read memory space 256 bytes
    //
	ReadCmos256Bytes( lfdd_io_data.mass_buf );


    //
    // Print ASCII content
    //
    if( !CmosScreen.ascii ) {

        CmosScreen.ascii = newwin( 17, 16, 4, 58 );
        CmosScreen.p_ascii = new_panel( CmosScreen.ascii );
    }


    wbkgd( CmosScreen.ascii, COLOR_PAIR( CYAN_BLUE ) );
    wattrset( CmosScreen.ascii, COLOR_PAIR( CYAN_BLUE ) | A_BOLD );
    mvwprintw( CmosScreen.ascii, 0, 0, "" );

    wprintw( CmosScreen.ascii, "0123456789ABCDEF" );
    for( i = 0 ; i < LFDK_BYTE_PER_LINE ; i++ ) {

        for( j = 0 ; j < LFDK_BYTE_PER_LINE ; j++ ) {

            tmp = ((unsigned char)lfdd_io_data.mass_buf[ (i * LFDK_BYTE_PER_LINE) + j ]);
            if( (tmp >= '!') && (tmp <= '~') ) {
            
                wprintw( CmosScreen.ascii, "%c", tmp );
            }
            else {

                wprintw( CmosScreen.ascii, "." ); 
            }
        }
    }

    wattrset( CmosScreen.ascii, A_NORMAL );


    //
    // Print 256bytes content
    //
    if( !CmosScreen.value ) {

        CmosScreen.value = newwin( 17, 47, 5, 6 );
        CmosScreen.p_value = new_panel( CmosScreen.value );
    }


    wbkgd( CmosScreen.value, COLOR_PAIR( WHITE_BLUE ) );
    mvwprintw( CmosScreen.value, 0, 0, "" );


    for( i = 0 ; i < LFDK_BYTE_PER_LINE ; i++ ) {

        for( j = 0 ; j < LFDK_BYTE_PER_LINE ; j++ ) {
    
                
            //
            // Change Color Pair
            //
            if( y == j && x == i ) {
              
                if( input ) {
                
                    if( counter % 2 ) {
                    
                        wattrset( CmosScreen.value, COLOR_PAIR( YELLOW_RED ) | A_BOLD );
                    }
                    else {
                    
                        wattrset( CmosScreen.value, COLOR_PAIR( YELLOW_BLACK ) | A_BOLD );
                    }
                    
                    counter++;
                }
                else {

                    wattrset( CmosScreen.value, COLOR_PAIR( BLACK_YELLOW ) | A_BOLD ); 
                }
            }
            else if( ((unsigned char)lfdd_io_data.mass_buf[ (i * LFDK_BYTE_PER_LINE) + j ]) ) {
           
                wattrset( CmosScreen.value, COLOR_PAIR( YELLOW_BLUE ) | A_BOLD );            
            }
            else {
            
                wattrset( CmosScreen.value, COLOR_PAIR( WHITE_BLUE ) | A_BOLD );
            }


            //
            // Handle input display
            //
            if( y == j && x == i ) {


                if( input ) {
                
                    wprintw( CmosScreen.value, "%2.2X", (unsigned char)wbuf );
                }
                else {
                
                    wprintw( CmosScreen.value, "%2.2X", (unsigned char)lfdd_io_data.mass_buf[ (i * LFDK_BYTE_PER_LINE) + j ] );
                }
            }
            else {

                wprintw( CmosScreen.value, "%2.2X", (unsigned char)lfdd_io_data.mass_buf[ (i * LFDK_BYTE_PER_LINE) + j ] );
            }


            //
            // End of color pair
            //
            wattrset( CmosScreen.value, A_NORMAL );


            //
            // Move to next byte
            //
            if( j != 15 ) {
          
                wprintw( CmosScreen.value, " " );
            }
        }
    }
}
示例#3
0
文件: lfdk.c 项目: wupeiing/lfdk1
int main( int argc, char **argv ) {

    extern char *optarg;
    extern int optind;

    char c, device[ LFDK_MAX_PATH ];
    int i, fd, orig_fl;

    struct tm *nowtime;
    time_t timer;
    int last_sec;


    //
    // Initialize & set default value
    //
//    strncpy( device, LFDD_DEFAULT_PATH, LFDK_MAX_PATH );
    strncpy( pciname, LFDK_DEFAULT_PCINAME, LFDK_MAX_PATH );


    while( (c = getopt( argc, argv, "b:n:d:h" )) != EOF ) {

        switch( c ) {
        

            //
            // Change default path of device
            //
            case 'd' :

                strncpy( device, optarg, LFDK_MAX_PATH );
                break;

            //
            // Change default path of PCI name database
            //
            case 'n' :

                strncpy( pciname, optarg, LFDK_MAX_PATH );
                break;

            case 'b' :

                maxpcibus = atoi( optarg );
                if( maxpcibus >= LFDK_MAX_PCIBUS ) {
                
                    fprintf( stderr, "Maximum PCI Bus value must be less than %d\n", LFDK_MAX_PCIBUS );
                    return 1;
                }
                break;

            case 'v' :
                break;

            case 'h' :
            default:
                usage();
                return 1;
        }
    }


    //
    // Start communicate with LFDD I/O control driver
    //
    fd = open("/dev/mem", O_RDWR);
    if( fd < 0 ) {

        fprintf( stderr, "Cannot open device: %s\n", "/dev/mem" );
        return 1;
    }
	if (fd) close(fd);


    //
    // Ncurse start
    //
    initscr();
    start_color();
    cbreak();
    noecho();
    nodelay( stdscr, 1 );
    keypad( stdscr, 1 );
    curs_set( 0 );


    //
    // Initialize color pairs for later use
    //
    InitColorPairs();


    //
    // Prepare Base Screen
    //
    PrintBaseScreen();


    //
    // Scan PCI devices
    //
    ScanPCIDevice();


    for( ; ; ) {


        ibuf = getch();
        if( (ibuf == 'q') || (ibuf == 'Q') ) {
        
            //
            // Exit when ESC pressed
            //
            break;
        }


        //
        // Major function switch key binding
        //
        if( (ibuf == 'p') || (ibuf == 'P') ) {

            func = PCI_LIST_FUNC;
            ClearPCIScreen();
            ClearMemScreen(); 
            ClearIOScreen();
			ClearCmosScreen();
            continue;
        }
        else if( (ibuf == 'm') || (ibuf == 'M') ) {
        
            enter_mem = 1;
            func = MEM_SPACE_FUNC;
            ClearPCIScreen();
            ClearPCILScreen();
            ClearIOScreen();
			ClearCmosScreen();
            continue;
        }
        else if( (ibuf == 'i') || (ibuf == 'I') ) {

            enter_mem = 1;
            func = IO_SPACE_FUNC;
            ClearPCIScreen();
            ClearPCILScreen();
            ClearMemScreen();
			ClearCmosScreen();
            continue;
        }
        else if( (ibuf == 'o') || (ibuf == 'O') ) {

            enter_mem = 1;
            func = CMOS_SPACE_FUNC;
            ClearPCIScreen();
            ClearPCILScreen();
            ClearMemScreen();
			ClearIOScreen();
            continue;
        }
/*
        else if( ibuf == '2' ) {

            enter_mem = 1;
            func = I2C_SPACE_FUNC;
            ClearPCIScreen();
            ClearPCILScreen();
            ClearMemScreen();
			ClearIOScreen();
			ClearCmosScreen();
            continue;
        }
*/


        //
        // Update timer
        //
        time( &timer );
        nowtime = localtime( &timer );
        last_sec = nowtime->tm_sec;


        // Skip redundant update of timer
        if( last_sec == nowtime->tm_sec ) {

            PrintFixedWin( BaseScreen, time, 1, 8, 23, 71, BLACK_WHITE, "%2.2d:%2.2d:%2.2d", nowtime->tm_hour, nowtime->tm_min,  nowtime->tm_sec );
        }


        //
        // Major Functions
        //
        switch( func ) {
        
            case PCI_DEVICE_FUNC:

                PrintPCIScreen( fd );
                break;

            case PCI_LIST_FUNC:

                PrintPCILScreen();
                break;

            case MEM_SPACE_FUNC:

                PrintMemScreen( fd );
                break;

            case IO_SPACE_FUNC:

                PrintIOScreen( fd );
                break;

			case CMOS_SPACE_FUNC:

				PrintCmosScreen( fd );
				break;

			case I2C_SPACE_FUNC:

				PrintCmosScreen( fd );
				break;

            default:
                break;
        } 


        //
        // Refresh Screen
        //
        update_panels();
        doupdate();


        usleep( 1000 );
    }


    endwin();
    close( fd );


    fprintf( stderr, "\n" );
    usage();


    return 0;
}