mirror of
https://github.com/rvtr/ctr_eFuse.git
synced 2025-11-02 00:11:04 -04:00
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@213 ff987cc8-cf2f-4642-8568-d52cce064691
98 lines
2.0 KiB
C
98 lines
2.0 KiB
C
#include <stdio.h>
|
|
#include <termios.h>
|
|
#include <time.h>
|
|
#include <sys/time.h>
|
|
|
|
#include "util.h"
|
|
|
|
static struct termios initial_setting, new_setting;
|
|
static int peek_character = -1;
|
|
|
|
void keyboard_initialize( void )
|
|
{
|
|
tcgetattr( 0, &initial_setting );
|
|
new_setting = initial_setting;
|
|
new_setting.c_lflag &= ~ICANON;
|
|
new_setting.c_lflag &= ~ECHO;
|
|
new_setting.c_lflag &= ~ISIG;
|
|
new_setting.c_cc[VMIN] = 0;
|
|
new_setting.c_cc[VTIME] = 0;
|
|
tcsetattr( 0, TCSANOW, &initial_setting );
|
|
}
|
|
|
|
void keyboard_finalize( void )
|
|
{
|
|
tcsetattr( 0, TCSANOW, &initial_setting );
|
|
}
|
|
|
|
int keyboard_is_hit( void )
|
|
{
|
|
char ch;
|
|
int nread;
|
|
|
|
if ( peek_character != -1 )
|
|
{
|
|
return 1;
|
|
}
|
|
new_setting.c_cc[VMIN] = 0;
|
|
tcsetattr( 0, TCSANOW, &new_setting );
|
|
nread = read( 0, &ch, 1 );
|
|
new_setting.c_cc[VMIN] = 1;
|
|
tcsetattr( 0, TCSANOW, &new_setting );
|
|
|
|
if ( nread == 1 )
|
|
{
|
|
peek_character = ch;
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
char keyboard_get_char( void )
|
|
{
|
|
char ch;
|
|
|
|
if ( peek_character != -1 )
|
|
{
|
|
ch = peek_character;
|
|
peek_character = -1;
|
|
return ch;
|
|
}
|
|
read( 0, &ch, 1 );
|
|
return ch;
|
|
}
|
|
|
|
void debug_print_array( const char *label, const unsigned char *data, int length )
|
|
{
|
|
int i;
|
|
printf( "%s", label );
|
|
for( i = 0 ; i < length; i++ )
|
|
{
|
|
if( (i % 16) == 0 )
|
|
{
|
|
printf("\n ");
|
|
}
|
|
printf("%02X ", data[ i ] );
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
void debug_file_output( unsigned int id, char *suffix, const unsigned char *data, int length )
|
|
{
|
|
FILE *fp;
|
|
char file_name[256];
|
|
|
|
sprintf( file_name, "./0x%08x.%s", id, suffix );
|
|
fp = fopen( file_name, "wb" );
|
|
fwrite( data, length, 1, fp );
|
|
fclose( fp );
|
|
}
|
|
|
|
double gettimeofday_sec(void)
|
|
{
|
|
struct timeval tv;
|
|
gettimeofday(&tv, NULL);
|
|
return tv.tv_sec + (double)tv.tv_usec*1e-6;
|
|
}
|