📄 ge_utility.c
字号:
/**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-
* GE_Utility.c - Ethernet 1000M code. .
*
* some common functions used by many tasks
*
* Copyright 2001-12 by GDT, Inc
*
* modification history
* --------------------
* 2001-12-14,xinyan yang created.
*
*/
#include <errno.h>
#include <taskLib.h>
#include <stdio.h>
#include "arch/ppc/vxppcLib.h"
#include "drv/multi/ppc860Siu.h"
#include "GE_GlobalP.h"
#include "GE_Global.h"
#include "GE_Utility.h"
unsigned int OUT_PUT=0;
static GE_PRINT_ENABLE print_enable = {TRUE,FALSE,TRUE};
/* add by gsx 2002/9/2*/
unsigned char GE_swiport;
/* end the add */
extern unsigned char MAC1[MAC_ADD_SIZ];
extern unsigned char MAC2[MAC_ADD_SIZ];
extern unsigned char MAC3[MAC_ADD_SIZ];
extern unsigned char MAC4[MAC_ADD_SIZ];
/********************************************************************************
* getSelfBoardType: get the board type
* 1--sys_line, 2--sys_pro, 3--output
*/
unsigned char GE_GetSelfBoardType()
{
return GIGA_LINECARD;
}
/********************************************************************************
* getSelfExPort
*/
unsigned char GE_GetSelfExPort()/*flag 28-31*/
{
unsigned char selfExPort;
ULONG FLAG;
taskLock();
FLAG=*(ULONG*)(0x13020014);
taskUnlock();
selfExPort = 15 - (unsigned char)(FLAG&0x0F);
return (selfExPort);
}
/*****************************************************************************
*getSysBoardNum*/
unsigned char GE_GetSysBoardNum()
{
return ((GE_swiport<<2)+1);
}
/********************************************************************************/
void GE_GetPortMac (unsigned char * macAddr,unsigned char n)
{
if(GE_swiport==2)
{
if(n==0)
{
bcopy(MAC1,macAddr,MAC_ADD_SIZ);
}
if(n==1)
{
bcopy(MAC2,macAddr,MAC_ADD_SIZ);
}
}
else
{
if(n==0)
{
bcopy(MAC3,macAddr,MAC_ADD_SIZ);
}
if(n==1)
{
bcopy(MAC4,macAddr,MAC_ADD_SIZ);
}
}
return;
}
/********************************************************************************
* resetHardware:reset all hardware
*/
void resetHardware()
{
resetOutfpga();
resetPM3386();
resetInfpga();
wr_to_pb(8,1);
taskDelay(1);
output("resetHardware:reset hardware succeed!\n");
return;
}
/********************************************************************************
* resetPM3386: reset PM3386
*/
void resetPM3386()
{
wr_to_pb(4,0);
taskDelay(1);
wr_to_pb(4,1);
taskDelay(1);
output("resetPM3386:reset PM3386 succeed!\n");
return;
}
/********************************************************************************
* reset InFpga: Reset FPGA_IN
*/
void resetInfpga()
{
wr_to_pb(5,0);
taskDelay(1);
wr_to_pb(5,1);
taskDelay(1);
output("resetInfpga:reset infpga succeed!\n");
return;
}
/********************************************************************************
* resetOutFpga:reset FPGA_OUT
*/
void resetOutfpga()
{
wr_to_pb(6,0);
taskDelay(1);
wr_to_pb(6,1);
taskDelay(1);
output("resetOutfpga:reset outfpga succeed!\n");
return;
}
/********************************************************************************
* PM3386WriteReg: write a char to PM3386 register
*/
void PM3386Write(ULONG offset,ULONG data)
{
ULONG * addr;
int lockkey;
addr=(ULONG*)((offset<<2) + PM3386BASE);
if (taskLock()==ERROR)
return;
lockkey=intLock();
*addr=(data<<16);
intUnlock(lockkey);
if (taskUnlock()==ERROR)
return;
}
/********************************************************************************
* PM3386ReadReg: read a data from PM3386 register
*/
ULONG PM3386Read(ULONG offset)
{
ULONG * addr;
ULONG PM3386Value;
int lockkey;
addr=(ULONG*)((offset<<2) + PM3386BASE);
if (taskLock()==ERROR)
return -1;
lockkey=intLock();
PM3386Value = *addr;
PM3386Value=(outfpgaRead(0x2D))>>16;
intUnlock(lockkey);
if (taskUnlock()==ERROR)
return -1;
return(PM3386Value);
}
/*****************************************************************************************/
STATUS infpgaWrite(ULONG offset,ULONG data)
{
ULONG*addr;
unsigned int i;
int lockKey;
addr=(ULONG*)((offset<<7)+INFPGABASE);
if(taskLock()==ERROR)
{
return -1;
}
lockKey=intLock();
*addr=data;
intUnlock(lockKey);
if(taskUnlock()==ERROR)
{
return -1;
}
return OK;
}
void infpgaWrite_ip(ULONG index,ULONG ipAddr)
{
taskLock();
*(ULONG*)(INFPGABASE+(index<<2)+(0x10<<7)) = ipAddr;
taskUnlock();
IPAddr[index]=ipAddr;
return;
}
/*****************************************************************************************/
void write_infpga_ip(unsigned char n,ULONG index)
{
unsigned char i;
ULONG *addr;
if(n==32)
{
for(i=0;i<32;i++)
{
addr=(ULONG*) ((0x10<<7)+INFPGABASE+(i<<2));
*addr=IPAddr[i];
}
}
if(n==1)
{
addr=(ULONG*)((0x10<<7)+INFPGABASE+(index<<2));
*addr=IPAddr[index];
}
return;
}
/********************************************************************************
* read a int from FPGA_IN's register
*/
ULONG infpgaRead(ULONG offset)
{
ULONG *addr;
ULONG infpgaValue;
int lockKey;
addr=(ULONG*)((offset<<7)+INFPGABASE);
if(taskLock()==ERROR)
{
return -1;
}
lockKey=intLock();
infpgaValue=*addr;
intUnlock(lockKey);
if(taskUnlock()==ERROR)
{
return -1;
}
return(infpgaValue);
}
/********************************************************************************
* write a int to FPGA_OUT's register
*/
STATUS outfpgaWrite(ULONG offset,ULONG data)
{
ULONG*addr;
int lockKey;
addr=(ULONG*)((offset<<5)+OUTFPGABASE);
if (taskLock()==ERROR)
return ERROR;
lockKey=intLock();
*addr=data;
intUnlock(lockKey);
if (taskUnlock()==ERROR)
return ERROR;
else
return OK;
}
/********************************************************************************
* read a int from FPGA-OUT's register
*/
ULONG outfpgaRead(ULONG offset)
{
ULONG *addr;
int lockKey;
ULONG outfpgaValue;
addr=(ULONG*)((offset<<5)+OUTFPGABASE);
if(taskLock()==ERROR)
return -1;
lockKey=intLock();
outfpgaValue=*addr;
intUnlock(lockKey);
if(taskUnlock()==ERROR)
return -1;
return(outfpgaValue);
}
/********************************************************************************
* output:output function used for debugging
*/
STATUS output (const char *cptr_format, ...)
{
if(OUT_PUT==1)
{
va_list argptr;
va_start (argptr,cptr_format);
#define format cptr_format
#define arg_list argptr
{
typedef struct f_and_f
{
float f1;
float f2;
}f_and_f;
typedef union f_to_d
{
f_and_f f;
double d;
}f_to_d;
int i;
int output_number=0;
char subformat[10];/*used to get a format string of outputing data ,such as "%08lx","%10.6f"*/
for(;*format;format++)
{
if (*format!='%')
{
char out_char;
out_char=*format;
printf("%c",out_char);
output_number++;
continue;
}
format++;
subformat[0]='%';
i=1;
while(i>0)
{
switch(*format)
{
case 'd':
case 'i':
case 'o':
case 'x':
case 'X':
case 'u':
case 'c':
{
subformat[i]=*format;
subformat[i+1]='\0';
output_number+=printf(subformat,va_arg(arg_list,int));
i=0;
break;
}
case 's':
{
subformat[i]=*format;
subformat[i+1]='\0';
output_number+=printf(subformat,va_arg(arg_list,char*));
i=0;
break;
}
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
{
/*Because va_arg(arg_list,double) is not supported by gcc complier when -fpack-struct
option is used,we use va_arg(arg_list,float) twice to get a double data .*/
f_to_d arg_double;
subformat[i]=*format;
subformat[i+1]='\0';
arg_double.f.f1=va_arg(arg_list,float);
arg_double.f.f2=va_arg(arg_list,float);
output_number+=printf(subformat,arg_double.d);
i=0;
break;
}
case 'p':
{
subformat[i]=*format;
subformat[i+1]='\0';
output_number+=printf(subformat,va_arg(arg_list,void *));
i=0;
break;
}
case 'n':
{
subformat[i]=*format;
subformat[i+1]='\0';
output_number+=printf(subformat,va_arg(arg_list,int *));
i=0;
break;
}
case '%':
{
subformat[i]=*format;
subformat[i+1]='\0';
output_number+=printf(subformat);
i=0;
break;
}
/* case '-':
case '+':
case ' ':
case '0':
case '#':
{
subformat[i]=*format;
i++;
format++;
break;
}
*/ default:
{
subformat[i]=*format;
i++;
format++;
}
}
if (i>9)
{
printf("\nWrong format string ,please check it again!\n");
break;
}
}
}
#undef arg_list
#undef format
}
va_end (argptr);
/*printf("\n");*/
}
return (OK);
}
/****************************************************************************************
* GE_debug:
*
* set the print enable flag and debug the FE module.
*
* RETURN:N/A.
*/
void GE_debug(int type,int flag)
{
switch (type)
{
case GE_ALARM:
print_enable.alarm = flag;
break;
case GE_EVENT:
print_enable.event = flag;
break;
case GE_DATA:
print_enable.data = flag;
break;
case GE_CLOSE:
GE_INIT_DEBUG = 0;
GE_MESSAGE_DEBUG = 0;
GE_PRO_SEND_DEBUG = 0;
GE_PRO_REV_DEBUG = 0;
GE_ARP_DEBUG = 0;
GE_CMD_DEBUG = 0;
GE_STAT_DEBUG = 0;
GE_SELFTEST_DEBUG = 0;
break;
case GE_OPEN:
GE_INIT_DEBUG = 1;
GE_MESSAGE_DEBUG = 1;
GE_PRO_SEND_DEBUG = 1;
GE_PRO_REV_DEBUG = 1;
GE_ARP_DEBUG = 1;
GE_CMD_DEBUG = 1;
GE_STAT_DEBUG = 1;
GE_SELFTEST_DEBUG = 1;
break;
default:
printf("GE_debug:unknown debug type!\n");
break;
}
return;
}
/****************************************************************************************
* GE_printf:
*
* if print is enable,print a string formatted with a variable argument list to standard output.
*
* RETURN:The number of characters output, or ERROR if there is an error during output.
*/
int GE_printf(enum GE_PRINT_TYPE print_type,char* fmt,...)
{
enum BOOLEAN enable;
int return_value = 0;
va_list argPtr;
va_start(argPtr,fmt);
switch (print_type)
{
case GE_ALARM:
enable = print_enable.alarm;
if (enable == TRUE)
{
printf("(GE_ALARM)");
}
break;
case GE_EVENT:
enable = print_enable.event;
if (enable == TRUE)
{
printf("(GE_EVENT)");
}
break;
case GE_DATA:
enable = print_enable.data;
if (enable == TRUE)
{
printf("(GE_DATA)");
}
break;
default:
enable = FALSE;
break;
}
if (enable == TRUE)
{
return_value = vprintf(fmt,argPtr);
/*printf("\n");*/
}
va_end(argPtr);
return (return_value);
}
extern void show_sta();
/* end of file GE_Utility.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -