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

📄 sio.c

📁 ADAM2 sources (modified by Oleg)
💻 C
📖 第 1 页 / 共 2 页
字号:
      if (SIO1__RSTMASK)
        {
        SIO1_RDAT=avbaud;  /*Set baud rate LSB                               */
        SIO1_IE=avbaud>>8; /*Set baud rate MSB                               */
        }
       else
        {
        SIO1_RDAT=baud;  /*Set baud rate LSB                                 */
        SIO1_IE=baud>>8; /*Set baud rate MSB                                 */
        }
      SIO1_LC=0x03;      /*Set word length                                   */
      SIO1_MC=0x0f;      /*Set modem control                                 */
      SIO1_IIR=0x41;     /*Set fifo enabled(Signal at 4 bytes)               */
      AvSio1Inited=1;      

      ctmp =SIO1_LS;
      ctmp|=SIO1_RDAT;
      ctmp|=SIO1_MS;
      ctmp|=SIO1_IIR;

      if ((SIO1_MS&SIO_MS_CTS)&&(SIO1__FDEN))
        {
        SIO1_MC=0x2f;    /*Set modem control, enable AutoFlowControl         */
        sflow=1;
        }
      }
    }
  }

void IfFlowEnable(void)
  {

  if (sflow) return;

  if ((AvSio0Inited)&&(SIO0__FDEN))
    {
    if (SIO0_MS&SIO_MS_CTS)
      {
      SIO0_MC=0x2f;    /*Set modem control, enable AutoFlowControl           */
      sflow=1;
      }
    }

  if ((AvSio1Inited)&&(SIO1__FDEN))
    {
    if (SIO1_MS&SIO_MS_CTS)
      {
      SIO1_MC=0x2f;    /*Set modem control, enable AutoFlowControl           */
      sflow=1;
      }
    }
  }

void SioOutChar(char chr)
  {
  int i;

  i=0;
  
  if (((AvSio0Inited)&&(!siolock))||
      ((AvSio0Inited)&&(siolast==0)))
    {
    while((SIO0_LS&SIO_LS_TE)==0)
      i++;
    SIO0_TDAT=chr;
    }

  if (((AvSio1Inited)&&(!siolock))||
      ((AvSio1Inited)&&(siolast==1)))
    {
    while((SIO1_LS&SIO_LS_TE)==0)
      i++;
    SIO1_TDAT=chr;
    }
  }

/* Return the tx status of the open serial ports */
int SioTxEmpty()
  {

  if (((AvSio0Inited)&&(!siolock))||
      ((AvSio0Inited)&&(siolast==0)))
    {
    if((SIO0_LS&SIO_LS_TE)==0)
      return(FALSE);
    }

  if (((AvSio1Inited)&&(!siolock))||
      ((AvSio1Inited)&&(siolast==1)))
    {
    if((SIO1_LS&SIO_LS_TE)==0)
      return(FALSE);
    }
  return(TRUE);
  }

void SioBackground(void)
  {
  }

void SioFlush(void)     
{

  if (AvSio0Inited)
    {
    do 
      {
      if ((SIO0_LS&0x60)!=0x60)  
        SioBackground();
      }while((SIO0_LS&0x60)!=0x60);
    }
  if (AvSio1Inited)
    {
    do 
      {
      if ((SIO1_LS&0x60)!=0x60)  
        SioBackground();
      }while((SIO1_LS&0x60)!=0x60);
    }
  SioBackground();  
}  

void SioOutStr(char *str)
  {
  while (*str)
    {
    if (*str=='\n')
      SioOutChar(13);
    SioOutChar(*str++);
    }
  }

void SioOutStrNum(char *str,int num)
  {
  while (num)
    {
    if (*str=='\n')
      SioOutChar(13);
    SioOutChar(*str++);
    num--;
    }
  }

void SioOutDec(int num,int siz)
  {

  if (num>=10)
    {
    SioOutDec(num/10,siz-1);
    }
  SioOutChar((num%10)+'0');
  }

void SioOutStr1(char *str,int num)
  {
  while (*str)
    {
    if (*str=='\n')
      SioOutChar(13);
    if ((*str=='%')&&((str[1]=='c')||(str[1]=='d')||(str[1]=='s')))
      {
      str++;
      switch (*str)
        {
        case 'c': SioOutChar(num);
                  break;
        case 'd': SioOutDec(num,0);
                  break;
        case 's': SioOutStr((char *)num);
                  break;
        default:  break;
        }
      if (*str)
        str++;
      }
     else
      SioOutChar(*str++);
    }
  }

int SioInCharCheck(char *al)
  {

  if (((AvSio0Inited)&&(!siolock))||
      ((AvSio0Inited)&&(siolast==0)))
    {
    if (SIO0_LS&SIO_LS_RX)
      {
      *al=SIO0_RDAT;
      siolast=0;
      return(TRUE);
      }
    }
  if (((AvSio1Inited)&&(!siolock))||
      ((AvSio1Inited)&&(siolast==1)))
    {
    if (SIO1_LS&SIO_LS_RX)
      {
      *al=SIO1_RDAT;
      siolast=1;
      return(TRUE);
      }
    }
  return(FALSE);
  }


int SioInChar(void)
  {
  char achar = 0;
  
  while(1)
    {
    if (((AvSio0Inited)&&(!siolock))||
        ((AvSio0Inited)&&(siolast==0)))
      {
      if (SIO0_LS&SIO_LS_RX)
        {
        achar=SIO0_RDAT;
        siolast=0;				
        }
      }
    if (((AvSio1Inited)&&(!siolock))||
        ((AvSio1Inited)&&(siolast==1)))
      {
      if (SIO1_LS&SIO_LS_RX)
        {
        achar=SIO1_RDAT;
        siolast=1;        
        }
      }
	
	if (achar != 0)
	  {
	  if (autoloadFlag == TRUE)
	    autoloadFlag = FALSE;
	  return(achar);
	  }
	main_Handler();	
	}
  }

#define AUTOLOAD_TIMEOUT_SECS	8  	/* Wait 5 secs before loading OS; PCApp can connect within this time */
#define REBOOT_TIMEOUT_SECS		3 	/* Wait 3 secs before rebooting the target */
#define CRASH_TIMEOUT_SECS		1   /* LED timer for crash notification */

extern void t_clear(void);
extern int t_get(void);

void main_Handler (void)
{
	static UINT32 autoload_timeout = 0;
	static int timeoutvalue = 0;
	static char *cp = NULL;
	
#if defined(DHCP_SUPPORT) || defined(FTP_SERVER_SUPPORT) || defined(TFTP_SERVER_SUPPORT)
	/* Check for IP Packets. */
	ip_Handler();
#endif
	
#ifdef TFTP_SERVER_SUPPORT
	//wwzh add for tftp server 
	//if tftp client is connected, STOP loading OS
	if (tftp_update == 1)
		autoloadFlag = FALSE;
#endif

#ifdef FTP_SERVER_SUPPORT
	{
		static UINT32 reboot_timeout = 0;
		static UINT32 crash_timeout = 0;
		static int led_flag = 0;
		
		/* Check for reboot Flag set, start the timer for 5 secs before 
		 * rebooting the system. */
		if (rebootFlag)
		{
			t_clear();
			reboot_timeout = t_get() + GetTicks(REBOOT_TIMEOUT_SECS);
			rebootFlag = FALSE;
			sys_printf("Rebooting the system in %d secs...\n", REBOOT_TIMEOUT_SECS);
		}
		if ((reboot_timeout != 0) && (t_get() > reboot_timeout))
			reboot();

		/* If ftp session is closed, start it again. */
		if (ftpServerStatus == STATUS_NONE)
			FTPServer();
		/* STOP loading OS, if PCApp is connected */
		else if (ftpServerStatus != STATUS_WELCOME)
			autoloadFlag = FALSE; 
	
		/* crash notification through LED */
		if ((crashFlag != CRASH_NONE) && (crash_timeout == 0))
		{
			crash_timeout = t_get() + (GetTicks(CRASH_TIMEOUT_SECS))/3;
		
			/* STOP loading OS, if a crash is identified */
			autoloadFlag = FALSE;
		}
		if ((crash_timeout != 0) && t_get() > crash_timeout)
		{
			toggle_leds(led_flag);
			if (crashFlag == CRASH_KERNEL)
				led_flag = !led_flag;
			else if (crashFlag == CRASH_FS)
			{
				led_flag++;
				if (led_flag >= 4)
					led_flag = 1;
			}
			crash_timeout = 0;
		}	
	}
#endif
	
	/* Check for autoloadFlag set, start the timer for autoload_timeout/AUTOLOAD_TIMEOUT_SECS
	 * before giving control to the Linux kernel. */
	if (autoloadFlag == TRUE)	
	{
		if (autoload_timeout == 0)
		{
			t_clear();
	    	timeoutvalue = (cp = sys_getenv("autoload_timeout")) ? atoui(cp) : AUTOLOAD_TIMEOUT_SECS;
		  	sys_printf("\nPress any key to abort OS load, or wait %d seconds for OS to boot...\n", timeoutvalue);
			autoload_timeout = t_get() + GetTicks(timeoutvalue);
		}
		else if (t_get() > autoload_timeout)
		{
  	  		int argc = 1;
		  	char *argv[1];  	
			argv[0] = "go";
			gocommand(argc, argv);		
			autoloadFlag = FALSE;
		}
	}
}

#if 0
bit32 RxOverrun, RxError, RxBits;
void SioDump(void)
  {
  sys_printf("RxOverrun: %d, RxError: %d, ",RxOverrun,RxError);
  sys_printf("bits:%8x\n",RxBits);
  }
#endif

⌨️ 快捷键说明

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