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

📄 com.c

📁 AT91所有开发板的资料 AT91所有开发板的资料
💻 C
字号:
/* -*-C-*- * * $Revision: 1.2 $ *   $Author: mechavar $ *     $Date: 2000/05/01 19:37:08 $ * * Copyright (c) 2000 ARM, INC. * All Rights Reserved. * *   Project: BootStrap Loader * *    */#include "bsl.h"#include "uhal.h"#include "c501uart.h"#include "lib.h"#define	ESC	(27)const char StatusRep[] = { ESC, '[', '0', 'n' };const char StatusReq[] = { ESC, '[', '5', 'n', 0 };const char *BaudNames[]= {"9600","19200","38400","57600","115200"};static const unsigned BaudKeys[] = { C501_BAUD_9600, C501_BAUD_19200, 				     C501_BAUD_38400, C501_BAUD_57600, 				     C501_BAUD_115200 };/* Initialize both ports to 9600 baud */void bsl_SerialInit( void ){   uHALir_InitSerial( UART0_BASE, BAUD_9600 );   uHALir_InitSerial( UART1_BASE, BAUD_9600 );}#define RESP_DELAY	(10 * 1000)	/* approximately how many loops to					   test for receive ready, for 9600					   baud */#define BOOT_DELAY	(1 * 1000 * 1000)#define RX_DONE()	(RX_DATA(GET_STATUS(HOST_COMPORT)))int testForResponse( const unsigned baud_value ){   int i = RESP_DELAY;   int j = 0;      uHALir_InitSerial( HOST_COMPORT, baud_value );   PutString( (char *)&StatusReq[0] );   while ( i-- > 0 )   {      if ( 0 != RX_DONE() )      {	 if ( StatusRep[j++] == (char)GET_CHAR(HOST_COMPORT) )	 {	    if ( j >= sizeof(StatusRep) / sizeof(StatusRep[0]) )	    {	       return( TRUE );	    } /* end if we've got all of the response data */	    else	    {	       i = RESP_DELAY;	       continue;	    }	 } /* end if we've got a match with the response data */	 else	 {	    return( FALSE );	 }      }	/* end if a charater is ready at the receive port */   } /* end while we wait for a character from the com port */   return( FALSE );}int bsl_AutoBaud( const unsigned com_port ){   int i = sizeof( BaudKeys ) / sizeof( BaudKeys[0] );   if ( com_port != HOST_COMPORT )   {      return( -1 );   }   while ( i-- > 0 )   {      if ( FALSE != testForResponse( BaudKeys[i] ) )      {	 break;      }   }   return( i );}void bsl_SetBaudPerEnv( void ){   char *pEnvData;   int i;   pEnvData = env_lookup( "baud" );   if ( NULL != pEnvData )   {      pEnvData = nextword( pEnvData );      for ( i=0; i < sizeof(BaudNames) / sizeof( BaudNames[0] ); i++  )      {	 if ( NULL != lookupword( pEnvData, (char *)BaudNames[i] ) )	 {	    uHALir_InitSerial( HOST_COMPORT, BaudKeys[i] );	    return;	 }      }   } /* end if "baud" is set in the env */   /* by default, we're already set for 9600 baud */}int bsl_BootQuery( void ){   int i = BOOT_DELAY;   /* Clear receive buffer */   while ( 0 == (GET_STATUS(HOST_COMPORT) & USRTxEmpty) )   {      ;   }   *(unsigned *)(HOST_COMPORT + UCON) |= UCRLPB;   PUT_CHAR( HOST_COMPORT, 0 );   while ( 0 == RX_DATA( GET_STATUS( HOST_COMPORT ) ) )   {      ;   }   *(unsigned *)(HOST_COMPORT + UCON) &= ~UCRLPB;   uHALr_printf( "Press ENTER within 2 seconds to stop autoboot\n" );   while ( i-- > 0 )   {      if ( 0 != RX_DONE() )      {	 if ( 0x0d == (char)GET_CHAR( HOST_COMPORT ) )	 {	    return( TRUE );	 }      }   }   return( FALSE );}void WriteC(int c){   while ( 0 == (GET_STATUS(HOST_COMPORT) & USRTxHoldEmpty) )   {      ;   }   PUT_CHAR( HOST_COMPORT, c );}int	ReadC(void){   while ( 0 == RX_DATA( GET_STATUS( HOST_COMPORT ) ) )   {      ;   }   return( GET_CHAR( HOST_COMPORT ) );}

⌨️ 快捷键说明

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