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

📄 debug.c

📁 MC9S12NE64串口与网络通信源代码
💻 C
字号:
/*****************************************************************************
 *
 * File Name     : debug.c
 *
 * DESCRIPTION   : Implementation of the diagnostics output - enabled when
 *              ETH_DEBUG keyword is defined (-DETH_DEBUG) 
 *              _SCI_BASE must be set to SCI0 or SCI1
 *              (see compiler command line arguments)
 *
 * Got from FREESCALE
 * Modified by houlei @2004.12.10 Tsinghua University
 *****************************************************************************/


#include <stdio.h>
#include "etherinit.h"
#include "IO_Map.h"
#include "ethernet.h"
#include "MOTTYPES.h"
#include "ne64api.h"

#define _BASE 0x0000  /**< Base on register map */

#define ECLK 25000000 /**< this is BUSCLK */

#define reg(x)  *((volatile tU08 *)(_BASE+x))
#define regw(x)  *((volatile tU16 *)(_BASE+x))

#define SCI0    0x00c8
#define SCI1    0x00d0

#define _SCI_BASE SCI0

#ifndef _SCI_BASE
#error _SCI_BASE not defined, use SCI0 or SCI1
#endif

#define SCIBD  regw(_SCI_BASE+0x00)
#define SCICR1 reg(_SCI_BASE+0x02)
#define SCICR2 reg(_SCI_BASE+0x03)
#define SCISR1 reg(_SCI_BASE+0x04)
#define SCIDRL reg(_SCI_BASE+0x07)

//===================================================
void InitDebug(void)
{

#define BAUD_RATE    9600
  
#define BAUD_DIV     ECLK/16/BAUD_RATE
 
  SCIBD= BAUD_DIV;
  SCICR1= 0;
  SCICR2= SCI1CR2_TE_MASK | SCI1CR2_RE_MASK | SCI1CR2_RWU_MASK ;
}



//===================================================
/* send string via SCI */
//===================================================
void Debugt(tS08 * s)
{
  while (*s != 0)
  {
    while (!(SCISR1 & 0x80));
    SCIDRL=*s;
    s++;
  }
}


//===================================================
/* convert 8bit number to 2 hexadecimal ascii characters */
//===================================================
tS08 cvt[16]={ '0','1','2','3','4','5','6','7','8','9',
                      'A','B','C','D','E','F' };

//===================================================
void Ctoh (tS08 * s, tU08 c)
{
  *s= cvt[c / 16];
  s++;
  *s= cvt[c % 16];
}


//===================================================
/* send 16bit number in hexa via SCI */
//===================================================
void Debugi(tU16 i)
{
  tS08 s[6];
  s[0]=' ';
  Ctoh(s+1,(tU08)(i / 256));
  Ctoh(s+3,i % 256);
  s[5]=0;
  Debugt(s);
}

//===================================================
/* send 8bit number in hexa via SCI */
//===================================================
void Debugc(tU08 c)
{
  tS08 s[4];
  s[0]=' ';
  Ctoh(s+1,c);
  s[3]=0;
  Debugt(s);
}

//===================================================
/* send newline and return characters via SCI */
//===================================================
void Debugnl(void)
{
  Debugt("\r\n");
}

⌨️ 快捷键说明

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