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

📄 dsp28_sci.c

📁 DSP捕获历程
💻 C
字号:
//
//      TMDX ALPHA RELEASE
//      Intended for product evaluation purposes
//
//###########################################################################
//
// FILE:	DSP28_Sci.c
//
// TITLE:	DSP28 SCI Initialization & Support Functions.
//
//###########################################################################
//
//  Ver | dd mmm yyyy | Who  | Description of changes
// =====|=============|======|===============================================
//  0.55| 06 May 2002 | L.H. | EzDSP Alpha Release
//  0.56| 20 May 2002 | L.H. | No change
//  0.57| 27 May 2002 | L.H. | No change
//###########################################################################

#include "DSP28_Device.h"
#include "ctype.h"
#include "math.h"
#include "stdarg.h"
#include "stdlib.h"


//---------------------------------------------------------------------------
// InitSPI: 
//---------------------------------------------------------------------------
// This function initializes the SPI(s) to a known state.
//
void InitSci(void)
{	// Initialize SCI-A:
		
	// loopback   8 bit data 
	SciaRegs.SCICCR.all = 0x07;
	
	SciaRegs.SCICTL1.all = 0x03;
	SciaRegs.SCICTL2.all = 0x00;
	
	SciaRegs.SCIHBAUD = 0x00;
	SciaRegs.SCILBAUD = 0xF3;
	
	SciaRegs.SCICTL1.all = 0x23;
	
	SciaRegs.SCIPRI.all=0x08;	
	//tbd...
 	// Initialize SCI-B:
	//tbd...
}
	////////////////////////////////////////////////////////
	//	name:	int SciaTx_Ready(void)
	//	input:	none
	//	output:	i	1:	ready
	//			0:	busy
	//////////////////////////////////////////////////////////
int SciaTx_Ready(void)
{	unsigned int i;
	if(SciaRegs.SCICTL2.bit.TXRDY == 1)
	{
		i = 1;
	}
	else
	{
		i = 0;
	}
	return(i);
}

	////////////////////////////////////////////////////////
	//	name:	int SciaRx_Ready(void)
	//	input:	none
	//	output:	i	1:	new data
	//			0:	none
	/////////////////////////////////////////////////////////

int SciaRx_Ready(void)
{	unsigned int i;
	if(SciaRegs.SCIRXST.bit.RXRDY == 1)
	{
		i = 1;
	}
	else
	{
		i = 0;
	}
	return(i);
}

//+++++++++++++++++++++++++++++++++++SCI_Unit++++++++++++++++++++++++++++++++++++++++++++++//
short SendByte (char sbyte)
{
  while (SciaTx_Ready()==0);   // wait for ready to send
   SciaRegs.SCITXBUF= sbyte;
   return 1;
}

char GetSByte() {
  short Temp1;
  while(SciaRx_Ready() == 0) ;   // wait for new incomming data
 Temp1= SciaRegs.SCIRXBUF.all;    // read the port
 return (unsigned char) (Temp1 & 0x00FF);
}

short GetNewByte() 
{
   short Temp1;
   if(SciaRx_Ready() == 1)    // wait for new incomming data
   Temp1= SciaRegs.SCIRXBUF.all;    // read the port
   return (Temp1 & 0x00FF);
}
//--------------------------------------  Myio ----------------------------
void putch (char ch)
{
   if (ch == '\n') 
   {   SendByte ('\r');
   }
   SendByte (ch);
 }

void printstr (char *sptr)
{
   while (*sptr) 
   {  putch (*sptr);
      ++sptr;
   }
}

//TI, char=short=int=16bits, long=32bits, float=double=32bits(TMS)
void printbase (unsigned int n, unsigned int b) {
   unsigned char d;
   if (n > 0) 
   {  printbase (n/b, b);
      d = n % b;
      if (d < 10) putch (d + '0');
      else putch (d - 10 + 'a');
   }
}

void printhex (unsigned int a) 
{  printstr ("0x");
   if (a > 0) printbase (a, 16);
   else putch ('0');
}

void printuint (unsigned int a) 
{	if (a == 0)	putch ('0');
	else printbase (a, 10);
}

void printint (int a) 
{	if (a < 0) 
	{	putch ('-');
		a *= -1;
	}
	printuint (a);
}
//--------------------------------- Print long (32bits) --------------------------------------/
void printbase2 (unsigned long n, unsigned int b) {
   unsigned char d;
   if (n > 0) 
   {  printbase2 (n/b, b);
      d = n % b;
      if (d < 10) putch (d + '0');
      else putch (d - 10 + 'a');
   }
}

void printulong (unsigned long a) 
{	if (a == 0)
		putch ('0');
	else
		printbase2 (a, 10);
}

void printlong (long a) {
	if (a < 0) 
	{	putch ('-');
		a *= -1;
	}
	printulong (a);
}

//------------------------------------- End of Printlong ------------------------------------/
void printfloat (double a, int d)
{
   double ipart, fpart;
	if (a < 0.0) 
	{	putch ('-');
		a *= -1.0;
	}
   fpart = modf (a, &ipart);
   printint ((int) ipart);
   putch ('.');
   for (; d > 0; d--) 
   {    fpart *= 10.0;
		fpart = modf (fpart, &ipart);
		putch ((int) ipart + '0');
	}
   printint ((int) fpart);
}

void printfrac (int a, int n)
{	int w;
	if (a < 0) 
	{	putch ('-');
		a *= -1;
	}
	printint (a >> n);
	putch ('.');
	w = 1 << n;
	while (a) 
	{	a %= w; // get the "fraction" 
		a *= 10;
		if (a >= w)	putch ((a>>n) + '0');
		else putch ('0');
	}
}
//---------------------------------------- print fraction2 for long (32bits) --------------------------------------/
void printfrac2 (long a, int n)
{	long w;
	if (a < 0) 
	{	putch ('-');
		a *= -1;
	}
	printlong (a >> n);
	putch ('.');
	w = 1 << n;
	while (a) 
	{	a %= w; // get the "fraction" 
		a *= 10;
		if (a >= w)	putch ((a>>n) + '0');
		else putch ('0');
	}
}


//--------------------------------------- My printf -------------------//
void My_printf (char *fmt, ...)
{  va_list ap;
   int width;
   va_start (ap, fmt);
   while (*fmt) 
   {  switch (*fmt) 
   	  {	case '%':
         	width = -1;
         	fmt++;
         	if (*fmt == '.') 
         	{     // handle precision 
          	    fmt++;      // digit has to follow the '.' 
            	width = 0;
            	while (isdigit (*fmt)) 
            	{  width = width * 10 + *fmt - '0';
               	fmt++;
            	}
         	}
         	switch (*fmt) 
         	{ case '%':
            	putch ('%');
            	break;
        	  case 'c':
	            putch (va_arg (ap, char));
	            break;
        	  case 'd':
           		if (width >= 0) printfrac (va_arg (ap, int), width);
            	else  printint (va_arg (ap, int));
            	break;

              case 'e':
        	  case 'f':
        	  case 'g':
            	printfloat (va_arg (ap, double), width >= 0 ? width : 2);
            	break;   

         	  case 'l':             
				if (width >= 0) printfrac2 (va_arg (ap, long), width);
        		else  printlong (va_arg (ap, long));
           	 	break;
         	  case 's':
            	printstr (va_arg (ap, char *));
            	break;
         	  case 'u':
            	printuint (va_arg (ap, unsigned int));
            	break;
         	  case 'x':
         	  case 'X':
            	printhex (va_arg (ap, int));
            	break;
            }
         	break;
      	default:
         	putch (*fmt);
      }
      fmt++;
   }
   va_end (ap);
}

//===========================================================================
// No more.
//===========================================================================

⌨️ 快捷键说明

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