⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exhelper.c

📁 M-System DOC(Disk on a Chip) Flash芯片映像读写工具, 可以进行二片Flash芯片的内容互相拷贝, 提高烧录程序的效率.
💻 C
字号:
#include "exhelper.h"
#include "flstatus.h"

/*---------------------------------------------------------------------------------*/
#ifdef EX_USE_MSG_DEVICE
#include <stdio.h>
#include <stdarg.h>
#define MAX_BUFFER_LEN	500
/***********************************************************************
 * Name : ExPrint  
 *   send variable number of arguments to the message device
 * 
 * 
 * Parameters:   
 *   string  - format control string
 *	 following arguments  - argument that their value will be send to the 
 *	
 * Outputs:
 *   none
 * 
 ***********************************************************************/

void EXAPI ExPrint( const EXCHAR* string, ... )
{
   va_list		pArguments;
   EXCHAR    Buffer[MAX_BUFFER_LEN];
   ExDevice	msgDevice;


   ExMemSet( Buffer, 0x00, MAX_BUFFER_LEN );
	
   va_start( pArguments, string );
   vsprintf( Buffer, string, pArguments );
   va_end( pArguments );
	
   OpenMsgDevice( &msgDevice );
   WriteMsgDevice( &msgDevice , Buffer );
   CloseMsgDevice( &msgDevice );
}

#endif /* EX_USE_MSG_DEVICE */


/***********************************************************************
 * Name : ExPrintLine  
 *   Print horizontal line
 * 
 * 
 * Parameters:   
 *   len - the lenght of the line
 *	 
 *	
 * Outputs:
 *   none
 * 
 ***********************************************************************/
void EXAPI ExPrintLine( EXWORD len )
{
  EXWORD  l;
  EXCHAR  line[30];
  
  if(len < 30)
  {
     for ( l = 0 ; l < len ; l++ )
        line[l] = '-';

     line[len] = '\0';
     ExPrint("%s",line);
  }
  ExPrint( "\n" );   
}
/*---------------------------------------------------------------------------------*/
#ifdef EX_USE_SERIAL_DEVICE
/***********************************************************************
 * Name : ExFprintf  
 *   send variable number of arguments to serial File device
 * 
 * 
 * Parameters:   
 *   fileDev - pointer to serial file device
 *	 string  - text to be written
 *	
 * Outputs:
 *   ExStatus - status of the operation
 * 
 ***********************************************************************/

ExStatus EXAPI ExFprintf( ExDevice* fileDev, EXCHAR* string ,...)
{
  va_list		    pArguments;
	EXCHAR        Buffer[MAX_BUFFER_LEN];

	ExMemSet( Buffer, 0x00, MAX_BUFFER_LEN );
	
  va_start( pArguments, string );
  vsprintf( Buffer, string, pArguments );
	va_end( pArguments );

	return WriteSerialFileDevice( fileDev, Buffer, ExStrLen(Buffer) );
}

/***********************************************************************
 * Name : ExPrintf  
 *   Open Serial file device, write test to it and close the device
 * 
 * 
 * Parameters:   
 *   fileName - the file name
 *	 text     - the text to be written
 *	
 * Outputs:
 *   ExStatus - status of the operation
 * 
 ***********************************************************************/
ExStatus EXAPI ExPrintf( EXCHAR* fileName, EXCHAR* text )
{
	ExDevice		writeFile;
	ExStatus			exErr;

	if( ( exErr = OpenSerialWriteFileDevice( &writeFile, fileName ) ) != EX_OK )
		return exErr;
		
	if( ( exErr = WriteSerialFileDevice( &writeFile, text, ExStrLen(text) ) ) != EX_OK )
		return exErr;

	if( ( exErr = CloseWriteSerialFileDevice( &writeFile ) ) != EX_OK )
		return exErr;

	return exErr;
}

/*---------------------------------------------------------------------------------*/
#define ExFscanf fscanf

#endif /* EX_USE_SERIAL_DEVICE */



/***********************************************************************
 * Name : ExMore  
 *   not implemented.
 * 
 * 
 * Parameters:   
 *   none
 *	 
 *	 
 * Outputs:
 *   none
 ***********************************************************************/
void EXAPI ExMore( void )
{
}

/***********************************************************************
 * Name : ExHitKey  
 *   not implemented.
 * 
 * 
 * Parameters:   
 *   none
 *	 
 *	 
 * Outputs:
 *   none
 ***********************************************************************/
void EXAPI ExHitKey( void )
{
}


/***********************************************************************
 * Name : ExPrintVer  
 *   clear the disply and write version information to the message device.
 * 
 * 
 * Parameters:   
 *   utilityName - the utility name
 *	 version     - the utility version
 *	 lastUpdate  - last update 
 * Outputs:
 *   none
 ***********************************************************************/
void EXAPI ExPrintVer( EXCHAR* utilityName, EXCHAR* version, EXCHAR* lastUpdate )
{
	ExClearScreen();
	ExPrint("                %s Utility, Version %s\n", utilityName, version );
	ExPrint("                     Last Update %s\n", lastUpdate );
	ExPrint("              Copyright (C) M-Systems, 1992 - 2004\n");
	ExPrint("            -----------------------------------------\n");
}



/***********************************************************************
 * Name : ExSufixToSize  
 *   Convert string + Suffix such as G,M,K  , to a number.
 * 
 * 
 * Parameters:   
 *   fileDev - pointer to device
 *	 Str     - string that contain the number + suffix
 * Outputs:
 *   RetLenght - the returned number 
 *	 Suffix  - the suffix in the end of the string
 * 
 ***********************************************************************/
void EXAPI ExSufixToSize( EXDWORD* RetLenght,EXCHAR* Str,EXCHAR* Suffix)
{
	EXWORD  len ;
	EXCHAR  *err = EXNULL ;

	len = ExStrLen( Str ) ;
  
	switch ( ExToupper( Str[len-1] ) )
	{
	  case('G'):		  
		Str[len-1] = '\0' ;
		*RetLenght =  (EXDWORD)ExStrtol(Str,&err,0) ;
		*RetLenght =  (*RetLenght)<<30;
		*Suffix    = 'G' ;
		break ;	
	  case('M'):
		Str[len-1] = '\0' ;
		*RetLenght =  (EXDWORD)ExStrtol(Str,&err,0) ;
		*RetLenght =  (*RetLenght)<<20;
		*Suffix    = 'M' ;
		break ;	
	  case('K'):	
		Str[len-1] = '\0' ;
		*RetLenght =  (EXDWORD)ExStrtol(Str,&err,0) ;
		*RetLenght =  (*RetLenght)<<10;
		*Suffix    = 'K' ;
		break ;	
	case('S'):	
		Str[len-1] = '\0' ;
		*RetLenght = (EXDWORD)ExStrtol(Str,&err,0) ;
		*Suffix    = 'S' ;
		break ;	
	case('U'):	
        *RetLenght = (EXDWORD)ExStrtol(Str,&err,0);
		*Suffix    = 'U' ;
      break ;	
	default:	
	  *RetLenght = (EXDWORD)ExStrtol (Str,&err,0) ;	
   	  *Suffix    = 0 ;
      break ;	
	}
}


/***********************************************************************
 * Name : ExFillBuffer  
 *   Fill buffer with a char
 * 
 * 
 * Parameters:   
 *   buf     - pointer to buffer
 *	 len     - num of char to fill
 * Outputs:
 *   none 
 ***********************************************************************/
void EXAPI ExFillBuffer( EXCHAR*	buf, EXWORD len, EXCHAR ch )
{
  EXWORD	  w;

  for( w = 0 ; w < len ; w++ )
    buf[w] = ch;
}


#ifdef	EX_USE_RANDOM

/***********************************************************************
 * Name : ExChooseNumber  
 *   Choose a random number within a certain range
 * 
 * 
 * Parameters:   
 *   start     - start of the range
 *	 end       - end of the range
 * Outputs:
 *   return the number that was choosen 
 ***********************************************************************/
EXDWORD EXAPI ExChooseNumber( EXDWORD start, EXDWORD end )
{
	static  EXDWORD count = 0;
	count++;
	return (EXDWORD)( start + ( ( ExRand() /* * tstruct.millitm * tstruct.time */ + count ) % ( end - start + 1 ) ) );

}

/***********************************************************************
 * Name : ExFillRandomBuffer  
 *   fill a buffer with random numbers
 * 
 * 
 * Parameters:   
 *   buf       - pointer to buffer
 *	 len       - number of items
 * Outputs:
 *   none
 ***********************************************************************/
void EXAPI ExFillRandomBuffer( EXCHAR*	buf, EXWORD len )
{
	EXWORD	  w;

  ExSrand( ( EXWORD )ExTime( EXNULL ) );
	for( w = 0 ; w < len ; w++ )
		buf[w] = ( EXBYTE )ExRand();
}

#endif	/* EX_USE_RANDOM */

/***********************************************************************
 * Name : ExMakeUpperCase  
 *   loop over charecters in a NULL termonated string and convert 
 *   lower to upper case.
 * 
 * 
 * Parameters:   
 *   str       - pointer to a string
 *	 
 * Outputs:
 *   str	   - pointer to the converted string
 ***********************************************************************/
EXCHAR* EXAPI ExMakeUpperCase( EXCHAR* str )
{
  int     strLen = ExStrLen( str );
  char*   tmp;
  
  
  for( tmp = str ; tmp < str + strLen ; tmp++ )
  {
    *tmp = ExToupper( *tmp );
  }
  return str;
}

/***********************************************************************
 * Name : ExWriteBufferToSerDevice  
 *   write data buffer with addresses to serial device
 *   
 * 
 * Parameters:   
 *   dwStartAddress  - the address
 *	 DataType        - this string that hold the data type will be printed after the address
 *   bBuffer		 - ptr to data buffer
 *   wLength         - len of data to be displyed
 *   RetLine         - send \n\r to serial device at the end
 *   WriteAddr       - can be EXTRUE or EXFALSE and tells if to write addr or not
 *   WriteAscii      - print also ascii chars
 * Outputs:
 *   none
 ***********************************************************************/
void EXAPI ExWriteBufferToSerDevice (EXDWORD dwStartAddress,EXCHAR *DataType,
							   EXBYTE *bBuffer,EXWORD wLength,EXBOOL RetLine,EXBOOL WriteAddr,
							   EXBOOL WriteAscii)
{
  EXDWORD dwAddress ; 
  EXBYTE bStartOffset,bBytesToWrite ;
  EXWORD i ; 

  if (wLength==0)
	return ;   

  dwAddress = dwStartAddress ;
	  
  /*** The writing would be done in quantities of 16 ***/
  /*** check what is the offset from 16              ***/
  bStartOffset  = (EXBYTE) (dwStartAddress % 16) ;  

  ExPrint ("-----------------------------------------------------------------------------\r\n") ;

  while (wLength)
  {
    if (WriteAddr==EXTRUE)
      ExPrint ("%07X",dwAddress) ;
    else
      ExPrint ("       "); 
	
	ExPrint (" %s ",DataType) ;

    /*** Print spaces if necessary                   ***/
    if ((bStartOffset) && (dwAddress==dwStartAddress) && (WriteAddr))
	{
      for (i=0;i<bStartOffset;i++)
        ExPrint("-- ");
	}

    /*** Print the buffer                            ***/
    if (wLength>=16) 
	{
	  bBytesToWrite = 16 ;
      if ((bStartOffset) && (dwAddress==dwStartAddress) && (WriteAddr))
        bBytesToWrite -= bStartOffset ;
	}
	else
      bBytesToWrite = (EXBYTE)wLength ;


	/*** Print numbers                               ***/
	for (i=0;i<bBytesToWrite;i++)
	{
      ExPrint("%02X ", bBuffer[i]);
	}
    
	/*** Print spaces                                ***/
	for (i=0;i<(16-bBytesToWrite);i++)
	{
      if (!((bStartOffset) && (dwAddress==dwStartAddress) && (WriteAddr)))
        ExPrint("-- ");
	}
    ExPrint("|") ;

    if (WriteAscii==EXTRUE)
	{
	  for (i=0;i<bBytesToWrite;i++)
	  {
        if ( (bBuffer[i] == 0xff) ||
             (bBuffer[i] == 0x0d) ||
             (bBuffer[i] == 0x0a) ||
             (bBuffer[i] == 0x08) ||
             (bBuffer[i] == 0x07) )
          ExPrint("");
        else
          ExPrint("%c",bBuffer[i]);
	  }      
	}    

	/*** Advance the Buffer                          ***/
    bBuffer += bBytesToWrite ;
   
	/*** Sub from length the written bytes           ***/
    wLength -= bBytesToWrite ; 

	/*** Advance the Address                         ***/
    dwAddress += bBytesToWrite ; 

	/*** Go to next line if this is not last line    ***/
	if (wLength)
      ExPrint("\n\r");
  }
  if (RetLine)
    ExPrint("\n\r");    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -