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

📄 44blib.c

📁 这个是FS44B0XII板子的BIOS源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
{
	char c;
	
	puts(" [y/n] ");
	while(1) {		
		c = getch();
		if((c=='y')||(c=='Y')||(c=='n')||(c=='N'))
			break;
	}
	putch(c);
	putch('\n');
	return c&1;	//y&Y are odd, n&N are even
}

/****************************************************************************
【功能说明】以标准输出格式向串口输出各种信息
****************************************************************************/
#if	1
/*---------------------printf and support routines ---------------------*/
/* print c count times */
void PutRepChar(char c, int count)
{
  while (count--) Uart_SendByte(c);
}

/* put string reverse */
void PutStringReverse(char *s, int index)
{
  while ((index--) > 0) Uart_SendByte(s[index]);
}

/*-------------------------------------------------------------------------*/
/* 
   prints value in radix, in a field width width, with fill
   character fill
   if radix is negative, print as signed quantity
   if width is negative, left justify
   if width is 0, use whatever is needed
   if fill is 0, use ' '
 */
#define	FALSE	0
#define	TRUE	1

static void PutNumber(int value, int radix, int width, char fill)
{
  char buffer[40];
  int bi = 0;
  int unsigned uvalue;
  short int digit;
  short int left = FALSE;
  short int negative = FALSE;

  if (fill == 0) fill = ' ';

  if (width < 0) {
    width = -width;
    left = TRUE;
  }
  if (width < 0 || width > 80) width = 0;
  
  if (radix < 0) {
    radix = -radix;
    if (value < 0) {
      negative = TRUE;
      value = -value;
    }
  }
  uvalue = value;
  do {
    if (radix != 16) {
      digit = uvalue % radix ;
      uvalue = uvalue / radix ;
    }
    else {
      digit = uvalue & 0xf;
      uvalue = uvalue >> 4;
    }
    buffer[bi] = digit + ((digit <= 9) ? '0' : ('A' - 10));
    bi++;

    if (uvalue != 0) {
      if ((radix==10)&&((bi==3)||(bi==7)||(bi==11)|(bi==15))) {
	buffer[bi++]=',';
      }
    }
  } while (uvalue != 0);

  if (negative) {
    buffer[bi] = '-';
    bi += 1;
  }
  if (width <= bi) PutStringReverse(buffer, bi);
  else {
    width -= bi;
    if (!left) PutRepChar(fill, width);
    PutStringReverse(buffer, bi);
    if (left) PutRepChar(fill, width);
  } 
}

/*-------------------------------------------------------------------------*/
static char *FormatItem(char *f, int a)
{
  char c;
  int fieldwidth = 0;
  int leftjust = FALSE;
  int radix = 0;
  char fill = ' ';

  if (*f == '0') fill = '0';
  while ((c = *f++)!=0) {
    if (c >= '0' && c <= '9') {
      fieldwidth = (fieldwidth * 10) + (c - '0');
    }
    else switch (c) {
    case '\000': return(--f);
    case '%': Uart_SendByte('%');
      return(f);
    case '-': leftjust = TRUE;
      break;
    case 'c': {
      if (leftjust) Uart_SendByte(a & 0x7f);
      if (fieldwidth > 0) PutRepChar(fill, fieldwidth - 1);
      if (!leftjust) Uart_SendByte(a & 0x7f);
      return(f);
    }
    case 's': {
      if (leftjust) Uart_SendString((char *) a);
      if (fieldwidth > strlen((char *) a))
	PutRepChar(fill, fieldwidth - strlen((char *)a));
      if (!leftjust) Uart_SendString((char *) a);
      return(f);
    }
    case 'd': 
    case 'i': radix = -10;break;
    case 'u': radix = 10;break;
    case 'x': radix = 16;break;
    case 'X': radix = 16;break;
    case 'o': radix = 8;break;
    default : radix = 3;break;/* unknown switch! */
    }
    if (radix) break;
  }
  if (leftjust) fieldwidth = -fieldwidth;
  PutNumber(a, radix, fieldwidth, fill);
  return(f);
}

#define vaStart(list, param) list = (char*)((int)&param + sizeof(param))
#define vaArg(list, type) ((type *)(list += sizeof(type)))[-1]
#define vaEnd(list)

void Uart_Printf(char *f, ...)       /* variable arguments */
{
//  U32 mode ;
  char *argP;

  /* disable IRQs and FIQs */
//  mode = uHALir_ReadMode() ;
//  uHALir_WriteMode(mode | NoFIQ | NoIRQ) ;

  vaStart(argP,f);		/* point at the end of the format string */
  while (*f) {			/* this works because args are all ints */
    if (*f == '%') f = FormatItem(f + 1, vaArg(argP, int));
    else Uart_SendByte(*f++);
  }
  vaEnd(argP);

  /* restore the previous mode */
//  uHALir_WriteMode(mode) ;
}

#else

#include <stdarg.h>
#include <string.h>
#include <stdlib.h>

//If you don't use vsprintf(), the code size is reduced very much.
typedef int *__va_list[1];
int vsprintf(char * /*s*/, const char * /*format*/, __va_list /*arg*/);

//if you don't use vsprintf(), the code size is reduced very much.
void Uart_Printf(char *fmt,...)
{
    va_list ap;
    char string[256];

    va_start(ap,fmt);
    vsprintf(string,fmt,ap);
    Uart_SendString(string);
    va_end(ap);
}

#endif

//***************************************************************************

/****************************************************************************
【功能说明】蜂鸣器鸣叫time个100us
****************************************************************************/
void Beep(unsigned int time)
{
	rPDATE = (rPDATE | 0x08);
	Delay(time);		//延时若干个100us
	rPDATE = (rPDATE & 0x1f7);
}
//***************************************************************************

/****************************************************************************
【功能说明】检测四个按键,有任何一个按键按下就让蜂鸣器鸣叫,否则不鸣叫
****************************************************************************/
void Key_Speaker(void)
{
	unsigned int m;
	m = rPDATG;
	if((m & 0xf8) < 0xf8)	{rPDATE = (rPDATE | 0x08);}
	else	{rPDATE = (rPDATE & 0x1f7);}
}
//***************************************************************************

/****************************************************************************
【功能说明】四个LED 点亮/熄灭状态设置(LedStatus低四位电平高低对应着四个LED亮/熄)
****************************************************************************/
void Led_Set(int LedStatus)
{
	if(LedStatus&1)			//PE7状态设置
		rPDATE=rPDATE&0x17f;
	else
		rPDATE=rPDATE|0x80;
	
	if(LedStatus&2)			//PE6状态设置
//		rPDATE=rPDATE&0x1bf;
		rPDATC |= 2;
	else
//		rPDATE=rPDATE|0x40;
		rPDATC &= ~2;

	if(LedStatus&4)			//PE5状态设置
//		rPDATE=rPDATE&0x1df;
		rPDATC |= 4;
	else
//		rPDATE=rPDATE|0x20;
		rPDATC &= ~4;

	if(LedStatus&8)			//PE4状态设置
//		rPDATE=rPDATE&0x1ef;
		rPDATC |= 8;
	else
//		rPDATE=rPDATE|0x10;
		rPDATC &= ~8;
}
//***************************************************************************

/****************************************************************************
【功能说明】LED来回闪烁显示 
****************************************************************************/
void Led_Disp(void)
{
	rPDATE = (rPDATE | 0x20);		//蜂鸣器开始鸣叫
	Led_Set(0x08);		//LED点亮/熄灭状态设置
	Delay(800);		//延时若干个100us
	Led_Set(0x04);		//LED点亮/熄灭状态设置
	Delay(800);		//延时若干个100us
	Led_Set(0x02);		//LED点亮/熄灭状态设置
	Delay(800);		//延时若干个100us
//	Led_Set(0x01);		//LED点亮/熄灭状态设置
//	Delay(800);		//延时若干个100us
	Led_Set(0x02);		//LED点亮/熄灭状态设置
	Delay(800);		//延时若干个100us
	Led_Set(0x04);		//LED点亮/熄灭状态设置
	Delay(800);		//延时若干个100us
	Led_Set(0x08);		//LED点亮/熄灭状态设置
	Delay(800);		//延时若干个100us
	Led_Set(0x00);		//LED点亮/熄灭状态设置
	rPDATE = (rPDATE & ~0x20);		//蜂鸣器停止鸣叫
}
//***************************************************************************

/****************************************************************************
【功能说明】定时器启动
****************************************************************************/
void Timer_Start(int divider)  //0:16us,1:32us 2:64us 3:128us
{
    rWTCON=((MCLK/1000000-1)<<8)|(divider<<3);
    rWTDAT=0xffff;
    rWTCNT=0xffff;   

    // 1/16/(65+1),nRESET & interrupt  disable
    rWTCON=((MCLK/1000000-1)<<8)|(divider<<3)|(1<<5);	
}
//***************************************************************************

/****************************************************************************
【功能说明】定时器停止
****************************************************************************/
int Timer_Stop(void)
{
//    int i;
    rWTCON=((MCLK/1000000-1)<<8);
    return (0xffff-rWTCNT);
}
//***************************************************************************

/****************************************************************************
【功能说明】锁相环设置,修改系统主频
Fout = (8 + M_DIV) * Fin / [ (2+P_DIV) * (2^S_DIV) ]
****************************************************************************/
void ChangePllValue(int mdiv,int pdiv,int sdiv)
{
	int i = 1;	
	
    rPLLCON = (mdiv << 12) | (pdiv << 4) | sdiv;

	while(sdiv--)
		i *= 2;	
	
	MCLK = (EXT_OSC_CLK*(mdiv+8))/((pdiv+2)*i);		
}

//***************************************************************************

/****************************************************************************
【功能说明】
****************************************************************************/
void * malloc(unsigned nbyte) 
/*Very simple; Use malloc() & free() like Stack*/
//void *mallocPt=Image$$RW$$Limit;
{
    void *returnPt=mallocPt;

    mallocPt= (int *)mallocPt+nbyte/4+((nbyte%4)>0); //to align 4byte

    if( (int)mallocPt > HEAPEND )
    {
	mallocPt=returnPt;
	return NULL;
    }
    return returnPt;
}
//***************************************************************************

/****************************************************************************
【功能说明】
****************************************************************************/
void free(void *pt)
{
    mallocPt=pt;
}
//***************************************************************************

/****************************************************************************
【功能说明】
****************************************************************************/
void Cache_Flush(void)
{
    int i,saveSyscfg;
    
    saveSyscfg=rSYSCFG;

    rSYSCFG=SYSCFG_0KB; 		      
    for(i=0x10004000;i<0x10004800;i+=16)    
    {					   
	*((int *)i)=0x0;		   
    }
    rSYSCFG=saveSyscfg; 			    
}
//***************************************************************************

⌨️ 快捷键说明

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