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

📄 debug.c

📁 CYRF6936 zigbee模块设计的全部资料
💻 C
字号:
//--------------------------------------------------------------------------
//
//  Filename:     debug.c
//
//  Description:
//
//--------------------------------------------------------------------------
// $Archive: /WirelessUSB/WUSB Kits/CY3630 LP EVK/DocSrc/CD_Root/Firmware/Source/Unsupported/NetworkQuality/debug.c $
// $Modtime: 3/01/06 6:04p $
// $Revision: 3 $
//--------------------------------------------------------------------------
//
// Copyright 2003-2006, Cypress Semiconductor Corporation.
//
// This software is owned by Cypress Semiconductor Corporation (Cypress)
// and is protected by and subject to worldwide patent protection (United
// States and foreign), United States copyright laws and international
// treaty provisions. Cypress hereby grants to licensee a personal,
// non-exclusive, non-transferable license to copy, use, modify, create
// derivative works of, and compile the Cypress Source Code and derivative
// works for the sole purpose of creating custom software in support of
// licensee product to be used only in conjunction with a Cypress integrated
// circuit as specified in the applicable agreement. Any reproduction,
// modification, translation, compilation, or representation of this
// software except as specified above is prohibited without the express
// written permission of Cypress.
//
// Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// Cypress reserves the right to make changes without further notice to the
// materials described herein. Cypress does not assume any liability arising
// out of the application or use of any product or circuit described herein.
// Cypress does not authorize its products for use as critical components in
// life-support systems where a malfunction or failure may reasonably be
// expected to result in significant injury to the user. The inclusion of
// Cypress' product in a life-support systems application implies that the
// manufacturer assumes all risk of such use and in doing so indemnifies
// Cypress against all charges.
//
// Use may be limited by and subject to the applicable Cypress software
// license agreement.
//
//--------------------------------------------------------------------------


//--------------------------------------
// Included files
//--------------------------------------
#include "PSoCAPI.h"
#include "debug.h"
#include "globalparams.h"
#include "psocgpioint.h"

#if defined(DEBUG)

//--------------------------------------
// Local Definitions and Types
//--------------------------------------
//--------------------------------------
// Local Function Declarations
//--------------------------------------

void OutNibble(unsigned char nibble);


//--------------------------------------
// Local Definitions
//--------------------------------------

#if defined(SOFT_SERIAL_TX)

#if (CPU_CLOCK == 2)	// 24MHz
 #warning Soft serial transmitter is not supported in 24MHz
#elif (CPU_CLOCK == 3)	// 12MHz
 //-------------------------------------------------------------------------
 // The BitDelay needs to burn 73 cycles. The next two functions do that.
 // It was written to favor fewer instructions rather than a series of nop's
 void BitDelayLevel2() // call takes 11 cycles, 2 bytes
 {
     asm("index 0"); // index is 13 cycles, 2 bytes
     // return is 8 cycles, 1 byte
 }
 void BitDelayLevel1() // call takes 11 cycles, 2 bytes
 {
     asm("index 0"); // index is 13 cycles, 2 bytes

     BitDelayLevel2();

     // A nop takes 4 cycles, 1 byte
     // cmp A,3 is 5 cycles, 2 bytes
     asm("nop"); asm("cmp A,3");

     // return is 8 cycles, 1  byte
 }

 #define BitDelay BitDelayLevel1()
 //-------------------------------------------------------------------------
#elif (CPU_CLOCK == 1) // 3 MHz
 #define BitDelay
#else
 #warning Soft serial transmitter is not supported at this clock speed
#endif
 
//--------------------------------------------------------------------------
//
//  Function:    Serial_Tx_SendData
//
//  Description: Generate a SW UART, n,8,1,115.2k on UART_TX port
//				 This has been tuned for a 12mhz cpu
//
//  Inputs:      char
//
//--------------------------------------------------------------------------
void Serial_Tx_SendData(unsigned char Data)
{
//    M8C_DisableGInt;
    // Out put start bit
    UART_TX_Data_ADDR &= ~UART_TX_MASK;
    BitDelay;
#if (CPU_CLOCK == 3)	// 12MHz
    asm("nop");
#endif

    // output bit 0
    if(Data & 0x01)
        UART_TX_Data_ADDR |= UART_TX_MASK;
    else
    {
        UART_TX_Data_ADDR &= ~UART_TX_MASK;
        asm("nop"); // This balances out the jump used by the other half of the if clause
    }
 
    BitDelay;
   
    // Output bit 1
    if(Data & 0x02)
        UART_TX_Data_ADDR |= UART_TX_MASK;
    else
    {
        UART_TX_Data_ADDR &= ~UART_TX_MASK;
        asm("nop");
    }
    BitDelay;
    // Output bit 2
    if(Data & 0x04)
        UART_TX_Data_ADDR |= UART_TX_MASK;
    else
    {
        UART_TX_Data_ADDR &= ~UART_TX_MASK;
        asm("nop");
    }
    BitDelay;
    // Output bit 3
    if(Data & 0x08)
        UART_TX_Data_ADDR |= UART_TX_MASK;
    else
    {
        UART_TX_Data_ADDR &= ~UART_TX_MASK;
        asm("nop");
    }
    BitDelay;
    // Output bit 4
    if(Data & 0x10)
        UART_TX_Data_ADDR |= UART_TX_MASK;
    else
    {
        UART_TX_Data_ADDR &= ~UART_TX_MASK;
        asm("nop");
    }
    BitDelay;
    // Output bit 5
    if(Data & 0x20)
        UART_TX_Data_ADDR |= UART_TX_MASK;
    else
    {
        UART_TX_Data_ADDR &= ~UART_TX_MASK;
        asm("nop");
    }
    BitDelay;
    // Output bit 6
    if(Data & 0x40)
        UART_TX_Data_ADDR |= UART_TX_MASK;
    else
    {
        UART_TX_Data_ADDR &= ~UART_TX_MASK;
        asm("nop");
    }
    BitDelay;
    // Output bit 7
    if(Data & 0x80)
        UART_TX_Data_ADDR |= UART_TX_MASK;
    else
    {
        UART_TX_Data_ADDR &= ~UART_TX_MASK;
        asm("nop");
    }
    BitDelay;
    // Do pairty
#if (CPU_CLOCK == 3)	// 12MHz
    asm("nop");
    asm("nop");
    asm("nop");
    asm("nop");
    asm("nop");
#endif
   
    UART_TX_Data_ADDR |= UART_TX_MASK;
    BitDelay;
   
    // Do stop bit
#if (CPU_CLOCK == 3)	// 12MHz
    asm("nop");
    asm("nop");
    asm("nop");
    asm("nop");
    asm("nop");
#endif
   
    UART_TX_Data_ADDR |= UART_TX_MASK;
//    M8C_EnableGInt;
    BitDelay;
}   
#endif // defined(SOFT_SERIAL_TX)
 
 
//--------------------------------------------------------------------------
//
//  Function:    GetChar
//
//  Description: Reads characters from the serial port
//
//  Returns:     Character read or 0x00 if not character read
//
//--------------------------------------------------------------------------
BYTE GetChar()
{
	//Stay here until a char is received via RX serial port!
//	if (!(Serial_Rx_CONTROL_REG & RX8_RX_COMPLETE ))
	{
		return 0x00;
	}

//	return Serial_Rx_RX_BUFFER_REG;
}


//--------------------------------------------------------------------------
//
//  Function:    OutChar
//
//  Description: Ouput a character to the serial port
//
// TODO, test more to find out why the data overruns soemtime with testing for empty
//
//  Inputs:      char
//
//--------------------------------------------------------------------------
#if !defined(SOFT_SERIAL_TX)
void OutChar(unsigned char data)
{
	// Wait for the last byte to be sent.
    while(!(Serial_Tx_CONTROL_REG & Serial_Tx_TX_BUFFER_EMPTY));
    
	// write a byte
	Serial_Tx_TX_BUFFER_REG = data;
}
#endif


//--------------------------------------------------------------------------
//
//  Function:    OutStr
//
//  Description: Writes a string to the serial port
//
//  Inputs:      uchar
//
//--------------------------------------------------------------------------
void OutStr(const unsigned char *pbStrPtr)
{
   // loop for the null terminated string
   while ( *pbStrPtr != 0 )
   {
       // write a character
       OutChar( *pbStrPtr );

       // point to the next character
       pbStrPtr++;
   }
}


//--------------------------------------------------------------------------
//
//  Function:    OutStrData
//
//  Description: Writes a string to the serial port
//
//  Inputs:      uchar
//
//--------------------------------------------------------------------------
void OutStrData(unsigned char *pbStrPtr)
{
   // loop for the null terminated string
   while ( *pbStrPtr != 0 )
   {
       // write a character
       OutChar( *pbStrPtr );
          
       // point to the next character
       pbStrPtr++;
   }
}


//--------------------------------------------------------------------------
//
//  Function:    OutHex
//
//  Description: Converts a byte to a hex value
//
//  Inputs:      Byte to be printed
//
//--------------------------------------------------------------------------
void OutHex(unsigned char data)
{
	OutNibble(data >> 4);
	OutNibble(data);
}


//--------------------------------------------------------------------------
//
//  Function:    OutHex16
//
//  Description: Converts a word to a hex value
//
//  Inputs:      Two byte value to printed
//
//--------------------------------------------------------------------------
/* Using Macro version
void OutHex16(unsigned short data)
{
	// putchar is the more expensive HiTech version of putch
	// we're using putch to save on code space
	OutNibble(data >> 12);
	OutNibble(data >> 8);
	OutNibble(data >> 4);
	OutNibble(data);
}*/


//--------------------------------------------------------------------------
//
//  Function:    OutDec
//
//  Description: Converts both unsigned char and unsigned short to a decimal ascii value
//
//  Inputs:      Two byte or one byte value to be printed
//
//--------------------------------------------------------------------------
void OutDec(unsigned short u16DecByte)
{
	char decStr[6];
	unsigned char loop = 5;
	
	decStr[5] = '\0';
	
	while (loop)
	{
		// 22 code bytes cheaper here than in the while above
		--loop;
		
		decStr[loop] = (u16DecByte % 10) + '0';
		u16DecByte /= 10;
		
		if (u16DecByte == 0)
			break; // Kills leading zeros
	}
	
	OutStrData(&decStr[loop]);
}


//--------------------------------------------------------------------------
//
//  Function:    OutSignedDec8
//
//  Description: Prints sign if necessary then calls OutDec
//
//  Inputs:      I8 - the value you want to print
//
//--------------------------------------------------------------------------
void OutSignedDec8(char decByte)
{
	if (decByte & 0x80)
	{
		OutChar('-');
		decByte = 0 - decByte;
	}

	OutDec(decByte);
}


//--------------------------------------------------------------------------
//
//  Function:    OutNibble
//
//  Description: Convert a nibble to an ASCII value
//
//  Inputs:      Byte to be printed in ASCII
//
//--------------------------------------------------------------------------
void OutNibble(unsigned char nibble)
{
	nibble = nibble & 0x0F;

	if (nibble > 9)
	{
		nibble += ('A' - 10);
	}
	else
	{
		nibble += '0';
	}

	OutChar(nibble);
}

#endif // defined(DEBUG)

⌨️ 快捷键说明

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