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

📄 uart.bak

📁 Discription: This multi-master driver provides the software interface to the I2C Bus hardware of th
💻 BAK
📖 第 1 页 / 共 4 页
字号:
#include "UART.h"
#include "Rtos.h"
#include "i2c.h"
#include "LMSAStructs_Common.h"
#include "CAN/LMSAStructs_YXE.h"
#include "ElctFm.h"
#include "LibWarnings.h"
#include "ElctSFP.h"
#include "stdio.h"

extern uint8_t sfpPlugged;

#define BAUDRATE			103	// Baudrate 4800     
#define BUFSIZE	8
#define COMA	'A'
#define COMa	'a'
#define COMB	'B'
#define COMb	'b'
#define COMC    'C'
#define COMc	'c'
#define COMD	'D'
#define COMd	'd'
#define COME	'E'
#define COMe 	'e'
#define COMF	'F'
#define COMf	'f'
#define COMG	'G'
#define COMg	'g'
#define COMH	'H'
#define COMh	'h'
#define COMI	'I'
#define COMi	'i'
#define COMJ	'J'
#define COMj	'j'
#define COMK	'K'
#define COMk	'k'
#define COML	'L'
#define COMl	'l'
#define COMM	'M'
#define COMm	'm'
#define COMX	'X'
#define COMx 	'x'
#define COMR	'R'
#define COMr	'r'
#define COMZ	'Z'
#define COMz	'z'
#define COMY    'Y'
#define COMy    'y'
#define COMN    'N'
#define COMn    'n'
#define COM1    '1'
#define COM2    '2'
#define COM3    '3'
#define COM4    '4'
#define INPUTC  "Please input your choice"
#define ALARMT  "True "
#define ALARMF  "False"
#define NR      "\r\n"
//#define Information " Information"
#define Version     "Version"
#define Operation   "Operation"
#define protocol    "protocol"
#define Boot        "Boot"
#define SFP         "SFP "
static byte RxBuffer[BUFSIZE];
static char TxBuffer[82];
static volatile unsigned int RxBufBottom = 0;
static volatile unsigned int RxBufTop = 0;
enum CliDisplay {cliMainM,cliCrossM,cliOCProtectM,cliUnitM,cliSFPM,
                    cliCdrM,cliCdrUS,cliCdrS,
                    cliProtocolM,cliProtocolUS,cliProtocolS,
                    cliOpMdM,cliOpMdUS,cliOpMdS,
                    cliCLCM,cliBootM,
                    cliBootUS,cliBootS,cliSFPTXM};

static volatile byte *pwriteEeprom;
static byte writeMask;
//extern byte* entryAddrMIB[];
//extern OS_RSEMA mibTableSema;
static volatile unsigned int RxBufPoi = 0;

static OS_TASK hdlTransmissionRS232Task;
static OS_STACKPTR int RS232Stack[190];

static OS_CSEMA semaRS232;

//static bool useFlash = false;

void hdlTransmissionRS232 ( void );
//
char *OperationalMode[]= {"Default","Loopback","Crossconnect"};
#define OpMdMax 3
char *Protocol[]={"FE","GE","2XGE","FDDI","STM-1/OC3","STM-4/OC12","STM-16/OC48","STM-16/OC48 FEC","ESCON","FC","2XFC","4XFC"};
#define PtclMax 12
char *Bootup[]={"Factory","User"}; 
#define BtUpMax 2 
char *Encode[]= {"Unspecified","8B10B","4B5B","NRZ","Manchester","Scrambled"};
#define EncdMax 6
char *Media[]= {"SM","MM","Copper"};
#define MdMax 3
char *TransDis[]= {"Long","Intermediate","Shot","Very Long"};
#define TrsMax 4
char *RxClkMode[]={"Repeater","Retimer","Bypass"};
#define RxCkMax 3
//-----------------------------------------------------------------------------
//	Data into Receive buffer 
//-----------------------------------------------------------------------------
_inline
void RxData(int RxComData)
{
 	RxBuffer[RxBufTop]= RxComData ;	
   	RxBufTop = (RxBufTop + 1) & (BUFSIZE-1);	// FIFO
  	OS_SignalCSema(&semaRS232);
}

void UART_INIT (byte *enablePort,byte enablePortMask)
{ 
	OS_CREATECSEMA( &semaRS232 );
	OS_CreateTask( &hdlTransmissionRS232Task, "RS232_I2C_Task",10, &hdlTransmissionRS232, &RS232Stack, sizeof(RS232Stack),1); 
    pwriteEeprom = enablePort;
	writeMask=enablePortMask;

	RX_RS232_UART1_DIR  = 0;			// Input
	TX_RS232_UART1_DIR  = 1;			// Output


  U1MR   = 0x00;        //  lock Sio, error reset
  U1C0   = 0x10;        //  RTS/CTS disabled, set clock divisor
  U1BRG  = BAUDRATE;  	//  Calculated Baudrate
  U1C1   = 0;           //  Lock Rx and Tx
  U1MR   = 0x05;         //  8  Data
  OS_IncDI();
  U1IRS  = 0;           //  transmit-interrupt on buffer empty
  U1C1   = 5;           //  enable reception and transmission
  S1RIC  = 0x06;       //  Enable UART Rx interrupts	- Interrupt Register
  S1TIC  = 0x06;           //  Enable UART Tx interrupts

  _nop();
  _nop();
  _nop();
  OS_DecRI();
} 
void uart_SendChar( byte len )
{
	unsigned int point = 0;

	while( len )
	{
     		while (!(U1C1 & (1<<1))); 	   	// Wait until TB empty
  	  		U1TBL = TxBuffer[point++];
            len--;
  	}
}
void uart_SendLine( void )
{
	unsigned int point = 0;

	while( TxBuffer[point] != '\0' )
	{
     		while (!(U1C1 & (1<<1))); 	   	// Wait until TB empty
  	  		U1TBL = TxBuffer[point++];
  	}
}

void TxDataEnd(void)
{
	while (UCON & 0x02 == 0) {}	  		//  UART1: UCON & 0x02 !!!
}

_interrupt(19) void RS232DataSend (void) 
{ 
	OS_EnterInterrupt();  			//  We will disable interrupts 
  	TxDataEnd();					// Transmission completed ?();
        OS_LeaveInterruptNoSwitch();
}
					
			
_interrupt(20) void RS232DataRead (void)
{
  	int Data;
  	int DataL;
	OS_EnterInterrupt();  			//  We will disable interrupts 
  	Data = U1RB;
  	DataL = U1RBL;
  	if (Data & 0x6000) 
  	{    					// Check if errors occurred 
    	U1C1 &= 255-(1<<2);   		// disable Rx
    	U1C1 |=  (1<<2);      		// enable Rx => error reset
  	} 
  	else
	{
  		RxData(DataL);
	}
	OS_LeaveInterruptNoSwitch();
}
byte uart_WaitForLine( char *c )
{
	unsigned int myRxBufBottom, newRxBufBottom;
	byte cPoint = 0; 
	while(1)
	{
		OS_WaitCSema( &semaRS232 );
		myRxBufBottom = RxBufBottom;
		newRxBufBottom = (myRxBufBottom + 1) & (BUFSIZE - 1);
		RxBufBottom = newRxBufBottom;
		c[cPoint] = RxBuffer[myRxBufBottom];
		if( c[cPoint] == '\n' ) break;
		cPoint++;
	}
	return cPoint;
}
void WepromCom (byte comline,char *command)
{
    sprintf(TxBuffer,command);
    WC_EEPROM_PORT &= ~WC_EEPROM_MASK;
    writeEEProm(comline*80, 80, TxBuffer, e_I2c_EEPROM1DvcAdr, eeprom_Large );
    WC_EEPROM_PORT |= WC_EEPROM_MASK;
    uart_SendLine();
}
void RepromCom (byte comline)
{
    memset(TxBuffer, 0, 80);
    readEEProm(comline*80, 80, TxBuffer,e_I2c_EEPROM1DvcAdr,eeprom_Large);
    uart_SendLine();
}
void MainM (void)
{
    /*WepromCom(0,"\r\n");
    WepromCom(1,"        A> Product Parameters\r\n");
    WepromCom(2,"        B> Card Information\r\n");
    WepromCom(3,"        C> Cross Connect Information\r\n");
    WepromCom(4,"        D> Channel Protection Information\r\n");
    WepromCom(5,"        E> Unit Information\r\n");
    WepromCom(6,"        F> Inquery Alarm\r\n");
    WepromCom(7,"        G> Inquery Warning\r\n");
    WepromCom(8,"        H> Inquery All\r\n");
    WepromCom(9,"Please input your choice<A - H,X,Z>:"); */
    RepromCom(0);    //sprintf(TxBuffer,"\r\n");
    RepromCom(1);    //sprintf(TxBuffer,"        A> Product Parameters\r\n");
    RepromCom(2);    //sprintf(TxBuffer,"        B> Card Information\r\n");
    RepromCom(3);    //sprintf(TxBuffer,"        C> Cross Connect Information\r\n");
    RepromCom(4);    //sprintf(TxBuffer,"        D> Channel Protection Information\r\n");
    RepromCom(5);    //sprintf(TxBuffer,"        E> Unit Information\r\n");
    RepromCom(6);    //sprintf(TxBuffer,"        F> Inquery Alarm\r\n");
    RepromCom(7);    //sprintf(TxBuffer,"        G> Inquery Warning\r\n");
    RepromCom(8);    //sprintf(TxBuffer,"        H> Inquery All\r\n");
    RepromCom(9);    //sprintf(TxBuffer,"Please input your choice<A - H,X,Z>:");
}
void StartM (void)
{
    /*WepromCom(10,"Dowslake Network Management Software Command Line Interface.\r\n");
    WepromCom(11,"Copyright <c> 2007 by Dowslake Co.,Ltd.\r\n");
    WepromCom(12,"Dowslake MACS4000 System,ELCT line card ,Version 0.10,Release Jan 7 2007\r\n");
    WepromCom(13,"\nSerial network interfaces\r\n");*/ 
    RepromCom(0);    //sprintf(TxBuffer,"\r\n");
    RepromCom(10);    //sprintf(TxBuffer,"Dowslake Network Management Software Command Line Interface.\r\n");
    RepromCom(11);    //sprintf(TxBuffer,"Copyright <c> 2007 by Dowslake Co.,Ltd.\r\n");
    RepromCom(12);    //sprintf(TxBuffer,"Dowslake MACS4000 System,ELCT line card ,Version 0.10,Release Jan 7 2007\r\n");
    RepromCom(13);    //sprintf(TxBuffer,"\nSerial network interfaces\r\n");
    MainM();
}
void ProductR(void)
{
    //WepromCom(37,"Product Information is:\r\n");
    //WepromCom(38,"Card Type: ELCT Line Card\r\n");
    RepromCom(37);   //sprintf(TxBuffer,"Product Information is:\r\n");uart_SendLine();
    RepromCom(38);   //sprintf(TxBuffer,"Card Type: ELCT Line Card\r\n");uart_SendLine();
    OS_Use( &mibTableSema );
    sprintf(TxBuffer,"Ser.No.: %.12s%s",entryAddrMIB[e_CmnSerialNo],NR);uart_SendLine();
    sprintf(TxBuffer,"Product ID: %.2s%s",entryAddrMIB[e_CmnProductID],NR);uart_SendLine();    
    sprintf(TxBuffer,"HW %.7s: %.6s%s",Version,entryAddrMIB[e_CmnHardwareVersion],NR);uart_SendLine();
    sprintf(TxBuffer,"SW %.7s: %.6s%s",Version,entryAddrMIB[e_CmnSoftwareVersion],NR);uart_SendLine();
    sprintf(TxBuffer,"FPGA %.7s: %.6s%s",Version,entryAddrMIB[e_Cmn_FPGATag],NR);uart_SendLine();
    sprintf(TxBuffer,"Manufacturing. Data: %.2s%s",entryAddrMIB[e_CmnDate],NR);uart_SendLine();
    OS_Unuse( &mibTableSema );
}

void CardR (void)
{
    uint16_t temp;
    float volttemp;
    measureTemp();
    measureAnalogSigs();
    sprintf(TxBuffer,"Card Information is :\r\n");uart_SendLine();
    OS_Use( &mibTableSema );
    sprintf(TxBuffer,"Card Temperature(C): %d%s",*((byte*)entryAddrMIB[e_ELCT_CardTemperature]),NR);uart_SendLine();  
    temp = *((word*)entryAddrMIB[e_ELCT_CardVoltage5V]);
    volttemp = (float)temp/1000;
    sprintf(TxBuffer,"Card Voltage(V): %4.2f%s",volttemp,NR);uart_SendLine();
    sprintf(TxBuffer,"Slot Number: %d%s",*((byte*)entryAddrMIB[e_CmnSlotNumber]),NR);uart_SendLine();
    OS_Unuse( &mibTableSema );
    temp = getWarningFlags();
    sprintf(TxBuffer,"Card Warning:");
    TxBuffer[13]=13;TxBuffer[14]=10;TxBuffer[15]=0;uart_SendLine();
    sprintf(TxBuffer,"Temperature: "); 
    if(temp & (((unsigned long) 1) << e_WarnCardTempHigh))  sprintf(TxBuffer+13,ALARMF);
    else sprintf(TxBuffer+13,ALARMT);
    TxBuffer[18]=13;TxBuffer[19]=10;TxBuffer[20]=0;uart_SendLine();
    sprintf(TxBuffer,"Voltage Low: ");
    if(temp & (((unsigned long) 1) << e_WarnCardV5Low))     sprintf(TxBuffer+13,ALARMF);
    else sprintf(TxBuffer+13,ALARMT);
    TxBuffer[18]=13;TxBuffer[19]=10;TxBuffer[20]=0;uart_SendLine();
    sprintf(TxBuffer+8,"High:");

⌨️ 快捷键说明

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