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

📄 ef8681.c

📁 CML CMX868 modem
💻 C
📖 第 1 页 / 共 2 页
字号:
		{
			GPT1--;					// Decrement General Purpose Timer 1
		}

		if (GPT2 != 0)					// Check status of General Purpose Timer 2 (10ms)
		{
			GPT2--;					// Decrement General Purpose Timer 2
		}

		if (PS100ms == 0)
		{
			PS100ms = 10;				// Reload 100ms prescaler

			PS1s--;					// Decrement 1s Prescaler

			if (CDLOSTTMR != 0)			// Check status of Carrier Detect Lost Timer (100ms)
			{
				CDLOSTTMR--;			// Decrement Carrier Detect Lost Timer
			}

			if (RDTIMEOUT != 0)			// Check status of Ring Detect timeout reg (100ms)
			{
				RDTIMEOUT--;			// Decrement Ring Detect timeout reg
			}

			if (GPT3 != 0)				// Check status of General Purpose Timer 3 (100ms)
			{
				GPT3--;				// Decrement General Purpose Timer 3
			}

			if (GPT4 != 0)				// Check status of General Purpose Timer 4 (100ms)
			{
				GPT4--;				// Decrement General Purpose Timer 4
			}			
			else
			{
				if(LED_OVERRIDE)
				{		
								// Ensures that the TXD and RXD LEDs stay illuminated
					TXDIND = 1;		// after an at@f1 command
					RXDIND = 1;				
				}
				if(!LED_OVERRIDE)
				{
					TXDIND = 0;		// Ensures that the TXD and RXD LEDs 
					RXDIND = 0;
				}		
			}
			
			if (PS1s == 0)
			{
				PS1s = 10;			// Reload 1s prescaler

				if (GPT5 != 0)			// Check status of General Purpose Timer 5 (1s)
				{
					GPT5--;			// Decrement General Purpose Timer 5
				}

				if (GPT6 != 0)			// Check status of General Purpose Timer 6 (1s)
				{
					GPT6--;			// Decrement General Purpose Timer 6
				}
			}
		}
	}

	TMR0 = 22;						// Reload the timer (250us * 4) per interrupt
								// Delay in interrupt saving adjusted for
	T0IF = 0;						// Clear the interrupt flag

	T0IE = 1;						// Enable Timer interrupt
}

void init_regs()
{
	unsigned char i;

	for(i=0; i<48; i++)
	{
		ATBUF[i] = 0;					// Clear AT Command Buffer 
	}
		
	for(i=0; i<32; i++)
	{
		MSGBUF[i] = 0;					// Clear Message Buffer 
	}

	TELNUM[0] = NUL;					// Will intially appear empty

	MODEMSTAT = 0x00;					// Initially set Evaluation Mode Flag and AT Command Mode Flag
	ATCMDSTAT = 0x00;					// Clear AT Command Status register
	BERTSTAT = 0x00;
	XFERSTAT = 0x00;

	
	ATBUFPTR = 0x00;					// Initialise AT Command Buffer pointer
	MSGBUFLDPTR = 0x00;					// Initialise Message Buffer Load pointer
	MSGBUFRDPTR = 0x00;					// Initialise Message Buffer Read pointer

	DATABUFLDPTR = 0x00;					// Initialise Data Buffer Load pointer
	DATABUFRDPTR = 0x00;					// Initialise Data Buffer Read pointer
}

void init_sregs(unsigned char settings)
{

	static unsigned char bank1 sreginit[2][30] ={		// Factory Profile 0
		{	0,0,43,13,10,8,2,50,2,6,		// S0 to S9
			7,10,20,0,138,0,0,0,30,2,		// S10 to S19
			0,193,64,0,1,176,48,0,0,0},		// S20 to S29

								// Factory Profile 1
		{	5,0,43,13,10,8,2,50,2,6,		// S0 to S9
			7,20,20,0,128,0,0,0,30,2,		// S10 to S19
			0,193,0,0,3,176,176,0,0,0}		// S20 to S29
		};

	unsigned char i;

	volatile unsigned char bank2 * sregptr;

	if (settings <= 1)
	{
		sregptr = &S0;

		for(i=0; i < numsregs; i++)
		{
			*sregptr = sreginit[settings][i];	// Load S registers with initial settings
			sregptr++;
		}
	}
}

void init_micro()
{
	OPTION = 0x00;
	STATUS = 0x00;
	PIR1 = 0x00;
	INTCON = 0x00;
	PIE1 = 0x00;
}

void init_ports()
{
	TRISA = CONFIGPA;					// Configure Port A
	TRISB = CONFIGPB;					// Configure Port B
	TRISC = CONFIGPC;					// Configure Port C

	ADCON1 = 0x06;						// Port A no analog i/p's, all digital.

	PORTA = INITPA;						// Initial Port A settings
	PORTB = INITPB;						// Initial Port B settings
	PORTC = INITPC;						// Initial Port C settings
}

void hook(unsigned char state)					// State determines if on or off hook (State != 0 takes modem off-hook)
{
	if (state == 0)
	{
		RLYDRV_ON = 0;					// On-Hook
	}
	else
	{
		RLYDRV_ON = 1;					// Off-Hook
	}

	wr16_cbus(CMXGENCTRL_ADDR,CMXGENCTRL);			// Write General Control information to C-BUS.
}

void ringdetection()						// Simple crude BT or Bell Ring Detect Check.  A valid ring consists of a burst greater
								// than 300ms then no ring detect when resampled 1 sec after burst ended.
{
	if (POLLTMR == 0)
	{
		POLLTMR = 20;					// Reload 20ms Ring detect sampling interval register
		if (!RDINPROG)					// Check if ringing is in progress
		{
			RDCNT = 0;				// Clear ring detect sample counter
			CMXSTAT = rd16_cbus(CMXSTAT_ADDR);	// Read CMX868 Status reg and update shadow reg
			if (RDET)				// Ring Detect Check 
			{
				S1 = 0;				// Clear ring count S-register
				RDCNT++;
				RDTIMEOUT = 0;			// Ensure ring detect timeout reg is clear at start
				RDINPROG = 1;			// Set flag to indicate ringing in progress
				RIN = 0;			// Clear RIN line
			}
		}
		else
		{
			if (RDTIMEOUT <= 70)			// Check 8sec ring timeout timer has been running for at least 1sec
			{
				CMXSTAT = rd16_cbus(CMXSTAT_ADDR);	// Read CMX868 Status reg and update shadow reg
				if (RDET)					// Ring Detect Check 
				{
					RIN = 0;		// Ensure RIN line is clear	
					if (RDCNT != 255)	// Prevent ring detect sample count reg from wrapping round
					{
						RDCNT++;
					}
				}
				else
				{
					RIN = 1;		// Set RIN line
					if (RDCNT >= 15)	// Check if ring burst exceeded 300ms
					{
						S1++;		// Increment ring count S-register
						resmsgtopc(RING);	// Send Ring message to terminal			
		 				if (S1 == S0)
						{
							RDINPROG = 0;	// Initialise flag ready for next auto answer
							ATCMDMODE = 0;	// Clear flag to indicate ready for handshaking
							ANSORIG = 0;	// Clear flag to indicate answering
						}
						else
						{
							RDTIMEOUT = 80;	// Reload 8sec ring detect timeout timer (100ms)
							RDCNT = 0;	// Clear ring detect sample counter
						}
					}
					else
					{
						if (RDTIMEOUT == 0)	// Abort ring detect validation if 8 sec timeout has occurred
						{
							RDINPROG = 0;	// Initialise flag ready for next auto answer
						}
					}
				}
			}			
		}
	}
}

void dial()							// Dial routine Tx always enabled, alternates between DTMF and Notone
{
	unsigned char i=0;

	CMXTXMODE &= 0x0E00;		
	CMXTXMODE ^= 0x1000;					// Select DTMF/Tones

	while (TELNUM[i] != NUL)
	{
		if (TELNUM[i] == ',')				// Introduce delay dial sequence
		{
			Delay1s(S8);
		}
		else
		{
			CMXTXMODE ^= 0x0010;			// Tx DTMF

			switch(TELNUM[i])
			{
				case 'A': case 'a':
					CMXTXMODE ^= DTMF_A;
					break;
				case 'B': case 'b':
					CMXTXMODE ^= DTMF_B;
					break;
				case 'C': case 'c':
					CMXTXMODE ^= DTMF_C;
					break;
				case 'D': case 'd':
					CMXTXMODE ^= DTMF_D;
					break;
				case '*':
					CMXTXMODE ^= DTMF_star;
					break;
				case '#':
					CMXTXMODE ^= DTMF_hash;
					break;
				case '0':
					CMXTXMODE ^= DTMF_0;
					break;
				default:			// Numbers 1-9
					CMXTXMODE ^= (TELNUM[i] - 0x30);
					break;
			}

			wr16_cbus(CMXTXMODE_ADDR, CMXTXMODE);

			DelayMs(S11 * 10);

			CMXTXMODE &= 0xFF00;			// Turn Tone Off

			wr16_cbus(CMXTXMODE_ADDR, CMXTXMODE);

			DelayMs(S11 * 10);
		}
		i++;
	}
}

void decnum2scrn(unsigned int value, unsigned char digits, unsigned char linefeed) // Number of digits and LF can be controlled
{
	unsigned int k,quot,rem;

	if ((digits > 0) && (digits < 6)) 
	{
		rem = value;

		k=1;

		do
		{
			k *= 10;				// Multiply k by 10

			digits--;				// Decrement digits value

		} while (digits > 1);


		do
		{
			quot = rem / k;

			MSGBUF[MSGBUFLDPTR++] = (quot + 0x30) & 0xFF;// Load Message Buffer
	
			MSGBUFLDPTR &= msgbufwrap;		// Wrap round buffer if necessary

			rem %= k;

			k /= 10;

		} while (k >= 1);

	}

	MSGBUF[MSGBUFLDPTR++] = S3;				// Load Message Buffer with CR Char

	MSGBUFLDPTR &= msgbufwrap;				// Wrap round buffer if necessary

	if (linefeed)
	{
		MSGBUF[MSGBUFLDPTR++] = S4;			// Load Message Buffer with LF Char

		MSGBUFLDPTR &= msgbufwrap;			// Wrap round buffer if necessary
	}

	TXIE=1;							// Enable TX Interrupt

	while (TXIE)
		continue;					// Wait until all characters have been sent to screen
}

void hexnum2scrn(unsigned int wordvalue, unsigned char digits, unsigned char linefeed) // LF can be controlled
{
	unsigned char shift;

	unsigned char k;

	shift = 4 * digits;

	do
	{
		shift = shift - 4;

		k = (wordvalue >> shift) & 0x0F;

		if (k <= 9)
		{
			MSGBUF[MSGBUFLDPTR++] = (k + 0x30) & 0xFF;	// Load Message Buffer
		}
		else
		{
			MSGBUF[MSGBUFLDPTR++] = (k + 0x37) & 0xFF;	// Load Message Buffer
		}
		MSGBUFLDPTR &= msgbufwrap;			// Wrap round buffer if necessary
	} while (shift != 0);

	MSGBUF[MSGBUFLDPTR++] = S3;				// Load Message Buffer with CR Char

	MSGBUFLDPTR &= msgbufwrap;				// Wrap round buffer if necessary

	if (linefeed)
	{
		MSGBUF[MSGBUFLDPTR++] = S4;			// Load Message Buffer with LF Char

		MSGBUFLDPTR &= msgbufwrap;			// Wrap round buffer if necessary
	}

	TXIE=1;							// Enable TX Interrupt

	while (TXIE)
		continue;					// Wait until all characters have been sent to screen
}

unsigned char dut_chksum()					// Routine for extracting DSP ROM Checksums
{								// Assumes device is powered up
	do
	{
		CMXSTAT = rd16_cbus(CMXSTAT_ADDR);
	} while (!PROGFLAG);					// Wait until Programming flag is set

	wr16_cbus(0xE9,0xC018);					// Start DSP ROM Checksum Routine.

	do
	{
		CMXSTAT = rd16_cbus(CMXSTAT_ADDR);
	} while (!PROGFLAG);					// Wait until Programming flag is set

	if (rd16_cbus(0xE5) != 0xFF54)				// Check CMX868 XROM MS Word 
	{
		return(ERROR);
	}

	do
	{
		CMXSTAT = rd16_cbus(CMXSTAT_ADDR);
	} while (!PROGFLAG);					// Wait until Programming flag is set

	if (rd16_cbus(0xEB) != 0x67A1)				// Check CMX868 XROM LS Word 
	{
		return(ERROR);
	}

	do
	{
		CMXSTAT = rd16_cbus(CMXSTAT_ADDR);
	} while (!PROGFLAG);					// Wait until Programming flag is set

	if (rd16_cbus(0xE5) != 0xFE35)				// Check CMX868 PROM MS Word 
	{
		return(ERROR);
	}

	do
	{
		CMXSTAT = rd16_cbus(CMXSTAT_ADDR);
	} while (!PROGFLAG);					// Wait until Programming flag is set

	if (rd16_cbus(0xEB) != 0x2C80)				// Check CMX868 PROM LS Word 
	{
		return(ERROR);
	}

	return(OK);
}

void testfunc1()
{
	CMXSTAT = rd16_cbus(CMXSTAT_ADDR);			// Update CMX868 Status Shadow register

	if (HEXOP)
	{
		hexnum2scrn(CMXSTAT,4,WORDRES);			// Send LF char if word results enabled
	}
	else
	{
		decnum2scrn(CMXSTAT,5,WORDRES);			// Send LF char if word results enabled
	}

	GPT1 = S19;						// Load GPT1(10ms) with S19 value

	if (GPT1 < 2)
	{
		GPT1 = 2;					// Only allow 20ms minimum
	}
	while(GPT1 != 0)					// Continue to loop until timer has expired
		continue;
}

⌨️ 快捷键说明

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