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

📄 e1.c

📁 芯片bt8237的底层驱动,实现E1/T1帧的构建
💻 C
📖 第 1 页 / 共 2 页
字号:
/* for ATMOS system */#include <stdio.h>#include <errno.h>#include <string.h>#include <stdlib.h>//#include <math.h>#include "config.h"#include "kernel.h"#include "messages.h"#include "timelib.h"#include "command.h"#include "ctype.h"#include "e1.h"#define MY_INIT_FILE			"//isfs/init"typedef struct {	    UINT Restart;       /16/    UINT OpStatus;    UINT Led;    UINT Error;	// CONTROL	//unsigned char fmode;	unsigned char tliu;/8/	unsigned char rliu;	//unsigned char cmux;	unsigned char cladi;	unsigned char clado;	unsigned char tx_rled;	unsigned char tx_gled;	unsigned char rx_rled;	unsigned char rx_gled;	unsigned char rx_led_temp;	unsigned char tx_led_temp;	unsigned char change;	unsigned char Startchange;	unsigned char restart;		unsigned char tx_pattern;	U32 	      pattern_counter;		U32	      error_counter;		U32	      test_period;	//BOOL	      debug;	// CONFIG        //UINT DataInvert; //DTINV    	UINT Channel;    	UINT T1_E1;	UINT FramerMode;	UINT ClockSource;	UINT CLoopback;	UINT fractional;	U32  Config;		un_did did;			//00  	un_cro cro;	//01	un_jat_cr jat_cr;		//02    	un_irr irr;			//03    	un_isr7 isr7;	//04    	un_isr6 isr6;	//05    	un_isr5 isr5;	//06    	un_isr4 isr4;	//07    	un_isr3 isr3;	//08    	un_isr2 isr2;	//09    	un_isr1 isr1;	//0A    	un_isr0 isr0;	//0B    	un_isr7 ier7;	//0C    	un_isr6 ier6;	//0D    	un_isr5 ier5;	//0E    	un_isr4 ier4;	//0F    	un_isr3 ier3;	//10    	un_isr2 ier2;	//11    	un_isr1 ier1;	//12    	un_isr0 ier0;	//13    	un_loop loop;		//14  				//01	un_dl3_ts dl3_ts;		//15  	unsigned char dl3_bit;		//16    	un_fstat fstat;		//17   	un_pio pio;			//18    	un_poe poe;			//19    	un_cmux cmux;		//1A    	un_tmux tmux;		//1B    	un_test test;		//1C    	bt8370_reg reserved_1D[3];	//1D,1E,1F    	un_liu_cr liu_cr;		//20	->	Receive LIU    	un_rstat 	 rstat;		//21    	un_rliu_cr 	 rliu_cr;	//022    	un_rcr0 	 rcr0;		//040	un_rpatt 	 rpatt;		//041    	  	un_alm1		 alm1;		//047	un_alm2		 alm2;		//048	un_alm3		 alm3;		//049  	un_tliu_cr	 tliu_cr;	//068	un_tcr1		 tcr1;		//071  	    	un_clad_cr 	clad_cr;		//90 	un_csel 	csel;		//091		    	    	    // STATUS    //UINT SDataInvert; //DTINV	UINT 		ST1_E1;	UINT 		SFramerMode;	UINT 		SClockSource;	UINT 		SCLoopback;	UINT		SLine;	UINT 		Sfractional;	unsigned short  SConfig;//1204		un_did 		Sdid;			//00  	un_cro 		Scro;			//01	un_jat_cr 	Sjat_cr;		//02    	un_irr 		Sirr;			//03    	un_isr7 	Sisr7;	//04    	un_isr6 	Sisr6;	//05    	un_isr5 	Sisr5;	//06    	un_isr4 	Sisr4;	//07    	un_isr3 	Sisr3;	//08    	un_isr2 	Sisr2;	//09    	un_isr1 	Sisr1;	//0A    	un_isr0 	Sisr0;	//0B    	un_isr7 	Sier7;	//0C    	un_isr6 	Sier6;	//0D    	un_isr5 	Sier5;	//0E    	un_isr4 	Sier4;	//0F    	un_isr3 	Sier3;	//10    	un_isr2 	Sier2;	//11    	un_isr1 	Sier1;	//12    	un_isr0 	Sier0;	//13    	un_loop 	Sloop;		//14      	un_dl3_ts 	Sdl3_ts;		//15  	unsigned char 	Sdl3_bit;		//16    	un_fstat 	Sfstat;		//17   	un_pio 		Spio;			//18    	un_poe 		Spoe;			//19    	un_cmux 	Scmux;		//1A    	un_tmux 	Stmux;		//1B    	un_test 	Stest;		//1C    	bt8370_reg 	Sreserved_1D[3];	//1D,1E,1F    	un_liu_cr 	Sliu_cr;		//20	->	Receive LIU    	un_rstat 	Srstat;		//21    	un_rliu_cr 	Srliu_cr;	//22    	un_rcr0 	Srcr0;		//040    	    	un_rpatt 	Srpatt;		//041    	  	un_alm1		Salm1;		//47	un_alm2		Salm2;		//48	un_alm3		Salm3;		//49      	unsigned char	Sberr[2];	//58,59	 	un_tliu_cr	Stliu_cr;	//068   	   	    	un_tcr1		Stcr1;		//071   	    	un_clad_cr 	Sclad_cr;	//90 	un_csel 	Scsel;		//091    	bt8370_reg 	Stpc[32];   	//0x100-0x11f		unsigned char	Stslip_hi;	//17f	unsigned char	Stslip_hi_temp;	//17f	unsigned char	Srsig[32];	//1A0~1BF		unsigned char	Srslip_hi;	//1ff	unsigned char	Srslip_hi_temp;	//1ff} E1;E1 xdragon; static U32 counter=0;static BOOL show=FALSE;static BOOL test=FALSE;static BOOL deblevel=FALSE;static BOOL liu_ais=TRUE;static BOOL pcm_ais=TRUE;static BOOL rliu_haul=FALSE;/////////////////////////////////////implement RLIU Long and Short Haul coefficients start/////////////////////static U8 iEqState;static U8 iVga_new;static U8 iVga_old;static U8 iVga_temp;static U8 RALOS_FLAG;/////////////////////////////////////implement RLIU Long and Short Haul coefficients end/////////////////////// -------------------------------------------------------------------------// For LED Used Define#define LED_ON		0#define LED_OFF		1#define LED_DARK	0x00#define LED_LIGHT	0x01#define LED_BLINK	0x02/*******************************************************//* Bit Rate for Test Purpose ONLY                      *//*******************************************************/#define GTI_ADAPT_SHDSL    1419     /* 0x0048 */#define GTI_72_SHDSL    72     /* 0x0048 */#define GTI_80_SHDSL    80     /* 0x0050 */#define GTI_136_SHDSL   136    /* 0x0088 */#define GTI_144_SHDSL   144    /* 0x0090 */#define GTI_200_SHDSL   200    /* 0x00c8 */#define GTI_208_SHDSL   208    /* 0x00d0 */#define GTI_264_SHDSL   264    /* 0x0108 */#define GTI_272_SHDSL   272    /* 0x0110 */#define GTI_328_SHDSL   328    /* 0x0148 */#define GTI_336_SHDSL   336    /* 0x0150 */#define GTI_392_SHDSL   392    /* 0x0188 */#define GTI_400_SHDSL   400    /* 0x0190 */#define GTI_456_SHDSL   456    /* 0x01c8 */#define GTI_464_SHDSL   464    /* 0x01d0 */#define GTI_520_SHDSL   520    /* 0x0208 */#define GTI_528_SHDSL   528    /* 0x0210 */#define GTI_584_SHDSL   584    /* 0x0248 */#define GTI_592_SHDSL   592    /* 0x0250 */#define GTI_648_SHDSL   648    /* 0x0288 */#define GTI_656_SHDSL   656    /* 0x0290 */#define GTI_712_SHDSL   712    /* 0x02c8 */#define GTI_720_SHDSL   720    /* 0x02d0 */#define GTI_776_SHDSL   776    /* 0x0308 */#define GTI_784_SHDSL   784    /* 0x0310 */#define GTI_840_SHDSL   840    /* 0x0348 */#define GTI_848_SHDSL   848    /* 0x0350 */#define GTI_904_SHDSL   904    /* 0x0388 */#define GTI_912_SHDSL   912    /* 0x0390 */#define GTI_968_SHDSL   968    /* 0x03c8 */#define GTI_976_SHDSL   976    /* 0x03d0 */#define GTI_1032_SHDSL  1032   /* 0x0408 */#define GTI_1040_SHDSL  1040   /* 0x0410 */#define GTI_1096_SHDSL  1096   /* 0x0448 */#define GTI_1104_SHDSL  1104   /* 0x0450 */#define GTI_1160_SHDSL  1160   /* 0x0488 */#define GTI_1168_SHDSL  1168   /* 0x0490 */#define GTI_1224_SHDSL  1224   /* 0x04c8 */#define GTI_1232_SHDSL  1232   /* 0x04d0 */#define GTI_1288_SHDSL  1288   /* 0x0508 */#define GTI_1296_SHDSL  1296   /* 0x0510 */#define GTI_1352_SHDSL  1352   /* 0x0548 */#define GTI_1360_SHDSL  1360   /* 0x0550 */#define GTI_1416_SHDSL  1416   /* 0x0588 */#define GTI_1424_SHDSL  1424   /* 0x0590 */#define GTI_1480_SHDSL  1480   /* 0x05c8 */#define GTI_1488_SHDSL  1488   /* 0x05d0 */#define GTI_1544_SHDSL  1544   /* 0x0608 */#define GTI_1552_SHDSL  1552   /* 0x0610 */#define GTI_1608_SHDSL  1608   /* 0x0648 */#define GTI_1616_SHDSL  1616   /* 0x0650 */#define GTI_1672_SHDSL  1672   /* 0x0688 */#define GTI_1680_SHDSL  1680   /* 0x0690 */#define GTI_1736_SHDSL  1736   /* 0x06c8 */#define GTI_1744_SHDSL  1744   /* 0x06d0 */#define GTI_1800_SHDSL  1800   /* 0x0708 */#define GTI_1808_SHDSL  1808   /* 0x0710 */#define GTI_1864_SHDSL  1864   /* 0x0748 */#define GTI_1872_SHDSL  1872   /* 0x0750 */#define GTI_1928_SHDSL  1928   /* 0x0788 */#define GTI_1936_SHDSL  1936   /* 0x0790 */#define GTI_1992_SHDSL  1992   /* 0x07c8 */#define GTI_2000_SHDSL  2000   /* 0x07d0 */#define GTI_2056_SHDSL  2056   /* 0x0808 */#define GTI_2064_SHDSL  2064   /* 0x0810 */#define GTI_2120_SHDSL  2120   /* 0x0848 */#define GTI_2128_SHDSL  2128   /* 0x0850 */#define GTI_2184_SHDSL  2184   /* 0x0888 */#define GTI_2192_SHDSL  2192   /* 0x0890 */#define GTI_2248_SHDSL  2248   /* 0x08C8 */#define GTI_2256_SHDSL  2256   /* 0x08D0 */#define GTI_2312_SHDSL  2312   /* 0x0908 */#define GTI_2320_SHDSL  2320   /* 0x0910 */#define GTI_2368_SHDSL  2368   /* 0x0940 */void led_control(void);void led_control(void){	un_cpld_reg cpld;	CPLD_GET(V35_C1R);	switch( xdragon.tx_rled )	{		case LED_LIGHT:			cpld.c1r_bit.tx_rled = LED_ON;			break;		case LED_BLINK:			cpld.c1r_bit.tx_rled ^= 1;			break;		default:			cpld.c1r_bit.tx_rled = LED_OFF;			break;	}	switch( xdragon.tx_gled )	{		case LED_LIGHT:			cpld.c1r_bit.tx_gled = LED_ON;			break;		case LED_BLINK:			cpld.c1r_bit.tx_gled ^= 1;			break;		default:			cpld.c1r_bit.tx_gled = LED_OFF;			break;	}	switch( xdragon.rx_rled )	{		case LED_LIGHT:			cpld.c1r_bit.rx_rled = LED_ON;			break;		case LED_BLINK:			cpld.c1r_bit.rx_rled ^= 1;			break;		default:			cpld.c1r_bit.rx_rled = LED_OFF;			break;	}	switch( xdragon.rx_gled )	{		case LED_LIGHT:			cpld.c1r_bit.rx_gled = LED_ON;			break;		case LED_BLINK:			cpld.c1r_bit.rx_gled ^= 1;			break;		default:			cpld.c1r_bit.rx_gled = LED_OFF;			break;	}	CPLD_SET(V35_C1R);}// -------------------------------------------------------------------------#define NORMAL_LEVEL				0#define DEBUG_LEVEL_1				1#define DEBUG_LEVEL_2				2#define DEBUG_LEVEL_3				3#define DEBUG_LEVEL_TOP				100#define HIDEN_LEVEL					200#ifdef DRV_DEBUG	UINT SystemDebugLevel = HIDEN_LEVEL;#else	UINT SystemDebugLevel = NORMAL_LEVEL;#endif// --------------------------------------------------------------------------------------------------------------------typedef struct {    UINT value;    const UCHAR *cmd;    const UCHAR *help;} CMD_TABLE;typedef BOOL (*E1CmdFunction)(E1*, const char*);              /*E1是我们自己定义的一个structure*/typedef struct {	const UCHAR *cmd;	const UCHAR *help;	const UCHAR *cmdhelp;	CMD_TABLE *cmdtable;	UINT maxcmds;	UINT runlevel;	UINT smart;	E1CmdFunction fun;} XAVI_CMD;			//***********************modify by ken*********************// --------------------------------------------------------------------------------------------------------------------/***********************************    StringToValue()  STRAT  Purpose :convert a string to a value(U32)--> max 4 digits                  Argument:            1. U32 *                         2. const char *            3. BOOL HexTrue ***********************************/BOOL StringToValue(U32 *val,const char *STRING,BOOL HexTrue);BOOL StringToValue(U32 *val,const char *STRING,BOOL HexTrue){		const char *string=STRING;	int i;	U32 *value=val;if( TRUE==HexTrue) {	  if(  0 == strncmp("0x",STRING,2)   )    {          string=STRING+2;   for (i=0;i<=3;i++)     {        unsigned int ch = tolower(*string);        unsigned int digit;                if( (*string == '\0')||(*string == ' '))        break;                  /* Convert 0-9 and a-f to digit value         */        if (ch >= '0' && ch <= '9')            digit = ch - '0';        else if (ch >= 'a' && ch <= 'f')            digit = ch - ('a' - 10);        else            return FALSE;          /* Something odd so exit parse loop */         /* Check digit valid for base         */        //if (digit >= 16) break;         /* Update value         */        *value *= 16;        *value += digit;        /* Check maximum number of digits and loop for next character.         */                 string ++;      }     }    else kprintf(" Please Add 0x on head \n");           }   else    //regard it as Decadal   {     //printf("Strat Decadal Convert.............. \n");          if( (*string == '\0')||(*string == ' '))//ken     return FALSE;      //ken          *value=0;     for (i=0;i<=3;i++)     {        unsigned int ch = tolower(*string);        unsigned int digit;                if( (*string == '\0')||(*string == ' '))        break;                  /* Convert 0-9 and a-f to digit value         */        if (ch >= '0' && ch <= '9')            digit = ch - '0';        else            return FALSE;          /* Something odd so exit parse loop */         /* Check digit valid for base         */        //if (digit > 9) break;         /* Update value         */         ;        *value *= 10;        *value += digit;        /* Check maximum number of digits and loop for next character.         */                 string ++;       }   	      }           return TRUE; }/***********************************    StringToValue()  END                ***********************************/			//********************************end*********************void FixInputStrEnd(char *InputStr);void FixInputStrEnd(char *InputStr){	while( *InputStr != '\0' )	{		if( (*InputStr == '\n') || (*InputStr == '\r') )		{			*InputStr = '\0';			break;		}		InputStr++;	}}void FixInputStrSpace(char *InputStr);void FixInputStrSpace(char *InputStr)       /*去空格的功能*/{	UINT f,f2,i;	char *CheckStr = InputStr;	FixInputStrEnd(InputStr);	f = 1;	f2 = 0;	while( *CheckStr != '\0' )	{		i = 1;		if( *CheckStr == ' ')        /*遇到第一个空格f2=1,f=1,i=1*/		{                            /*遇到第二个空格f2=1,f=1,i=0*/			f2 = 1;			if( f == 1 )				i = 0;			else				f = 1;		}		else                          /*非空格f2=0,f=0,i=1*/		{			f2 = 0;			f = 0;		}		*InputStr = *CheckStr++;       		InputStr += i;                /**/	} 

⌨️ 快捷键说明

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