44blib.c

来自「在VC6环境下开发」· C语言 代码 · 共 290 行

C
290
字号

/************************************************
* NAME : 44BMON: 44BLIB.C *
* Version : 17.APR.00 *
************************************************/

#include "44b.h"
#include "44blib.h"
#include "def.h"
#include "option.h"

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


/************************* SYSTEM *************************/
void Delay(int time){	
	int i;
	for(;time>0;time--)
		for(i=0;i<400;i++);
}
/************************* PORTS ****************************/
void Port_Init(void){

	//PORT A GROUP
	//ADDR24 ADDR23 ADDR22 ADDR21 ADDR20 ADDR19 ADDR18 ADDR17 ADDR16 ADDR0
	//   0      0      1      1      0      1      1      1      1    0
	rPCONA=0xDE;
	
	//PORT B GROUP
	//nGCS5 nGCS4 nGCS3 nGCS2 nGCS1 OUTPUT OUTPUT nSRAS nSCAS SCLK SCKE
	//  1     1     1     1     1      0      0     1     1     1    1
	rPCONB=0x7CF;
	
	//PORT C GROUP	
	// I   I   RxD1 TxD1 I   O   I   O   VD4 VD5 VD6  VD7 N  IN  IN  IN
	// 01, 01, 11,  11, 00, 01, 00, 01, 11, 11, 11, 11, 00, 00, 00, 00
	rPCONC = 0x5F11FF00;
	rPUPC = 0x30000;
	
	//PORT D GROUP
	//VFRAME VM VLINE VCLK VD3 VD2 VD1 VD0
	// 10,10, 10, 10, 10, 10, 10, 10
	rPCOND=0xaaaa;
	rPUPD=0xff;
	
	//PORT E GROUP
	// CODECLK  O   O   O   O   I   RxD0 TxD0  I
	//   10    01   01  01  01  00   10   10   00

	rPCONE=0x25528;
	rPUPE=0x106;
	
	//PORT F GROUP
	// SIOCLK   SIORxD    I    SIOTxD   I    I    O   IICSDA  IICSCL
	//   011      011    000     011    00   00   01     10     10     
	rPDATF = 0;
	rPCONF = 0x1b0c1a;
	rPUPF = 0x00;
	
	//PORT G GROUP
	// EINT7  EINT6  EINT5  EINT4  EINT3  EINT2  EINT1  EINT0
	//   11     11     11    11      11     11     11     11
	rPCONG = 0xffff;
	rPUPG = 0x00;
	rSPUCR = 0x7;		//pull-up disable
	rEXTINT = 0x00;	//All EINT[7:0] will be low level triggered.
}
/*
** ************************ UART ***************************
*/
void Uart_Init(int nCOM,int baud){
	int i;
	if(nCOM == 0){
		rUFCON0 = 0x0;		/* FIFO disable */
		rUMCON0 = 0x0;
		rULCON0 = 0x3;		/* Normal,No parity,1 stop,8 bit */
		//rULCON0=0x7;		/* Normal,No parity,2 stop,8 bit */
		rUCON0 = 0x245;		/* rx=edge,tx=level,disable timeout int.,
							** enable rx error int.,
							** normal,interrupt or polling 
							*/
		rUBRDIV0 = ((int)(MCLK/16./baud + 0.5) -1);
	}else{
		rUFCON1 = 0x0;		/* FIFO disable */
		rUMCON1 = 0x0;
		rULCON1 = 0x3;		/* Normal,No parity,1 stop,8 bit */
		//rULCON1=0x7;		/* Normal,No parity,2 stop,8 bit */
		rUCON1 = 0x245;		/* rx=edge,tx=level,disable timeout int.,
							** enable rx error int.,
							** normal,interrupt or polling 
							*/
		rUBRDIV1 = ((int)(MCLK/16./baud + 0.5) -1);
	}
	for(i=0;i<100;i++);
}

static int whichUart = 0;

void Uart_Select(int ch){
	whichUart=ch;
}

void Uart_TxEmpty(int ch){
	if(ch == 0)
		while(!(rUTRSTAT0 & 0x4));	//wait until tx shifter is empty.
	else
		while(!(rUTRSTAT1 & 0x4));	//wait until tx shifter is empty.
}
char Uart_Getch(void){
	if(whichUart == 0)	{
		while(!(rUTRSTAT0 & 0x1));	//Receive data read
		return RdURXH0();
	}else{
		while(!(rUTRSTAT1 & 0x1));	//Receive data ready
		return rURXH1;
	}
}
char Uart_GetKey(void){
	if(whichUart == 0){
		if(rUTRSTAT0 & 0x1) //Receive data ready
			return RdURXH0();
		else
			return 0;
	}else{
		if(rUTRSTAT1 & 0x1) //Receive data ready
			return rURXH1;
		else
			return 0;
	}
}
void Uart_GetString(char *string){
	char *string2 = string;
	char c;
	while((c=Uart_Getch())!='\r'){
		if(c=='\b'){
			if( (int)string2 < (int)string ){
				Uart_Printf("\b \b");
				string--;
			}
		}else{
			*string++ = c;
			Uart_SendByte(c);
		}
	}
	*string='\0';
	Uart_SendByte('\n');
}

int Uart_GetIntNum(void){
	char str[30];
	char *string = str;
	int base = 10;
	int minus = 0;
	int lastIndex;
	int result = 0;
	int i;
	Uart_GetString(string);
	if(string[0] == '-'){
		minus = 1;
		string++;
	}
	if(string[0] == '0' && (string[1] == 'x' || string[1] == 'X')){
		base = 16;
		string += 2;
	}
	lastIndex = strlen(string) - 1;
	if( string[lastIndex] == 'h' || string[lastIndex] == 'H' ){
		base = 16;
		string[lastIndex] = 0;
		lastIndex--;
	}
	if(base == 10){
		result = atoi(string);
		result = minus ? (-1 * result) : result;
	}else{
		for(i=0;i<=lastIndex;i++){
			if(isalpha(string[i])){
				if(isupper(string[i]))
					result=(result<<4)+string[i]-'A'+10;
				else
					result=(result<<4)+string[i]-'a'+10;
			}else{
				result=(result<<4)+string[i]-'0';
			}
		}
		result=minus ? (-1*result):result;
	}
	return result;
}
void Uart_SendByte(int data){
	if(whichUart==0){
		if(data=='\n'){
			while(!(rUTRSTAT0 & 0x2));
			Delay(10); //because the slow response of hyper_terminal
			WrUTXH0('\r');
		}
		while(!(rUTRSTAT0 & 0x2)); //Wait until THR is empty.
		Delay(10);
		WrUTXH0(data);
	}else{
		if(data=='\n'){
			while(!(rUTRSTAT1 & 0x2));
			Delay(10); //because the slow response of hyper_terminal
			rUTXH1='\r';
		}
		while(!(rUTRSTAT1 & 0x2)); //Wait until THR is empty.
		Delay(10);
		rUTXH1=data;
	}
}
void Uart_SendString(char *pt){
	while(*pt)
	Uart_SendByte(*pt++);
}

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);
}


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

//disable memory management unit.
void uHALr_ResetMMU(void)
{
}

//Initialize timer that is used OS.
void uHALr_InitTimers(void)
{			
	rTCFG0 = 0x7d;		//mux0,pre0=125,pre1=0xf
	rTCFG1 = 0x04;		//timer0 1/32

	rTCNTB0 = _CLOCK;
	rTCMPB0 = 0x0;
	rTCON = 0x2;			//update mode for TCNTB0 and TCMPB0.
	rTCON = 0x9;			//timer0 = auto reload, start
}

/*
 * Initialize an ARM Target board
 */
void ARMTargetInit(void){
	
	
	ChangePllValue(0x48,2,1);		/* 60M = (0x48+2) * 6M /((2+2)* 2)  */
	Port_Init();
	Uart_Init(0,115200);
	Uart_Init(1,115200);
	
	Uart_Printf("uCOS-II Running on SAMSUNG S3C44B0X ...\n");	
	
    /* ---- disable the MMU        ------------------------------------- */
    uHALr_ResetMMU();

	/*set interrupt vector routine*/
	uHALr_InitInterrupts();
	
    uHALr_InitTimers();
}

/* start the ARM target running */
void ARMTargetStart(void){
	
    /* Start system timer & enable the interrupt. 
    */
    uHALr_EnableSystemInterrupt();
}

/************************* PLL ********************************/
void ChangePllValue(int mdiv,int pdiv,int sdiv){
	rPLLCON = (mdiv<<12)|(pdiv<<4)|sdiv;
}

⌨️ 快捷键说明

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