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

📄 dbmessage.c

📁 IT projecotr reference design.
💻 C
字号:
/****************************************************************************/
/*             TEXAS INSTRUMENTS PROPRIETARY INFORMATION                    */
/*                                                                          */
/*  (c) Copyright, Texas Instruments Incorporated, 2006.                    */
/*      All Rights Reserved.                                                */
/*                                                                          */
/*  Property of Texas Instruments Incorporated. Restricted Rights -         */
/*  Use, duplication, or disclosure is subject to restrictions set          */
/*  forth in TI's program license agreement and associated documentation.   */
/****************************************************************************/

/****************************************************************************/
/* dbmessage.c                                                              */
/*                                                                          */
/* Debug messaging.                                                         */
/****************************************************************************/


#include <string.h>

#include "common.h"
#include "ddp2230_rtos_include.h"
#include "gpio.h"
#include "urt.h"

#include "dbmessage.h"
#include "global.h"
#include "app_cfg.h"
#include "gpioFunction.h"
#include "eeprom.h"


const  char    dbgModuleName[] = "Debug output";             /* module name */
static uint32  dbmsg_semID;                          /* messaging semaphore */
static URTPORT dbmsg_serPort   = URT_MAX_PORT;      /* debug port selection */
static uint32  mEnable         = 0xdfffffff;         /* message enable mask */

static char   *msgString       = NULL;          /* formatted message string */
static uint08  maxMsgLength    = 0;                   /* max message length */

static int08        dbmsg__send( char *msg );
static EXEC_CC_ENUM dbmsg__open( void );



/****************************************************************************/
/* Send a vsprintf-style string to the debug port                           */
/*                                                                          */
/* fmstring and ... arguments are passed to vsprintf() for formatting.      */
/*                                                                          */
/* bitmask: Debug message filter: Each major subsystem is provided with     */
/*          a 1-bit mask. Send message if that bit is set in the mEnable    */
/*          (message enable) filter.                                        */
/****************************************************************************/

void dbmsg_ftrace( uint32 bitmask, char *fmtstring, ... )
{
    va_list vlist;
    
    if( dbmsg_serPort != URT_MAX_PORT )
    {
        if( mEnable & bitmask )
        {
            if( NULL == msgString )              /* if this is the first ftrace */
            {
                if( RTA_SUCCESS != RTA_MemRequest( gID_MemPool, DBMSG_STRLEN, (void**)&msgString ))
                    return;
            }
            
            if( RTA_SUCCESS != RTA_SemReserve( dbmsg_semID, DBMSG_WAIT )) 
                return;
            
            va_start( vlist, fmtstring );
            vsprintf( msgString, fmtstring, vlist );
            dbmsg__send( msgString );
            RTA_SemRelease( dbmsg_semID );
        }
    }
}
 
 

/****************************************************************************/
/* Send a constant string to the debug port using polled output.            */
/*                                                                          */
/* This call is intended to be used during interrupt or exception handling  */
/* when interrupt-driven output cannot be performed.                        */
/****************************************************************************/

void dbmsg_ptrace( char *msg )
{
    uint32 k;                    /* must be supplied; API won't accept NULL */
    
    if( dbmsg_serPort != URT_MAX_PORT )
        URT_PolledWrite( dbmsg_serPort, strlen( msg ), (uint08*)msg, 0, &k );
}
 
 

/****************************************************************************/
/* Send a constant string to the debug port.                                */
/*                                                                          */
/* bitmask: Debug message filter: Each major subsystem is provided with     */
/*          a 1-bit mask. Send message if that bit is set in the mEnable    */
/*          (message enable) filter.                                        */
/*                                                                          */
/* msg:   Constant string message.                                          */
/****************************************************************************/

void dbmsg_trace( uint32 bitmask, char *msg )
{
    if( dbmsg_serPort != URT_MAX_PORT )
    {
        if( mEnable & bitmask )
        { 
            if( RTA_SUCCESS != RTA_SemReserve( dbmsg_semID, DBMSG_WAIT )) 
                return;
            
            dbmsg__send( msg );
            
            RTA_SemRelease( dbmsg_semID );
        }
    }
}
 


/****************************************************************************/
/* Get debug message enable mask.                                           */
/****************************************************************************/

uint32 dbmsg_getmask( void )
{
    return mEnable;
}

 
 
/****************************************************************************/
/* Set debug message enable mask.                                           */
/*                                                                          */
/* Set enable mask for debug messages.                                      */
/*                                                                          */
/* bitmask: Identifies the source of the debug message to be enabled or     */
/*          disabled.                                                       */
/****************************************************************************/

void dbmsg_setmask( uint32 bitmask )
{
    mEnable = bitmask | DBM_ALWAYS;
    EE_PUTVAR( UserSystem.DebugMsgMask, mEnable );
}

 
 
/****************************************************************************/
/* Module reset function.                                                   */
/*                                                                          */
/* API completion code is not examined since execution will be allowed to   */
/* continue regardless of error.                                            */
/****************************************************************************/

EXEC_CC_ENUM dbmsg_init( void )
{
    RTA_SemCreate( &dbmsg_semID, "dbug" );

    return dbmsg__open();
}



/****************************************************************************/
/* Get vsprintf string usage.                                               */
/****************************************************************************/

void dbmsg_stringUsage( uint08 *alloc, uint08 *used )
{
    if( 0 == maxMsgLength )              /* if no string has been allocated */
    {
       *used  = 0;
       *alloc = 0;
    }
    
    else
    {
       *used  = maxMsgLength + 1;                            /* include \0 */
       *alloc = DBMSG_STRLEN;
    }
}



/****************************************************************************/
/* Open debug communication link.                                           */
/****************************************************************************/

static const char oMsg[] = "\r\nDebug opened on URT";       /* open message */

/****************************************************************************/

EXEC_CC_ENUM dbmsg__open( void )
{
    uint08  debugConfig;                        /* debug port configuraiton */
    URTINIT config;                                /* UART config structure */
    uint32  k;                   /* must be supplied; API won't accept NULL */
    char    str[4] = "0\r\n";                     /* URT port number string */

                        /****************************************************/
                        /* Define debug port configuration.                 */
                        /****************************************************/

    debugConfig = gpConfiguration -> Peripherals.DebugOut;
    
    dbmsg_serPort = 0x03 & ( debugConfig >> 5 );
    
                        /****************************************************/
                        /* Set alternate pin function if serial port 1.     */
                        /****************************************************/
                        
    if( dbmsg_serPort == URT_PORT1 )
    {
        GPIO_EnableAlternativeFunction( GPIO_UART1_TXD_RXD, TRUE );
        GPIO_SetPinConfig( GIO_UART1TXD, GIOCFG_OUTPUT, TRUE, GIOCFG_ACTIVE );
    }

                        /****************************************************/
                        /* Exit if not serial port 0.                       */
                        /****************************************************/

    else if( dbmsg_serPort != URT_PORT0 )
    {
        dbmsg_serPort = URT_MAX_PORT;         /* invalid, debug not enabled */
        return EXEC_CC_PASS;
    }

                        /****************************************************/
                        /* Complete the configuration. API return codes are */
                        /* not examined since execution will be allowed to  */
                        /* continue regardless of error.                    */
                        /****************************************************/
                        
    URT_EnableFIFOs( dbmsg_serPort, TRUE );
    
    config.PortEnable  = TRUE;                              
    config.BaudRate    = debugConfig & 0x07;   
    config.DataBits    = URT_8DBITS;   
    config.StopBits    = URT_1SBITS;   
    config.Parity      = URT_NONE;     
    config.FlowControl = ( debugConfig & 0x10 ) ? URT_HW : URT_OFF;
    config.RXTrigLevel = URT_RX_ONE_HALF_FULL;
    config.TXTrigLevel = URT_TX_ONE_HALF_FULL;
    config.RXDPolarity = URT_NONINV_RXDPOL;

    URT_SetConfig( dbmsg_serPort, &config );
    
    str[0] += dbmsg_serPort;                          /* format port number */

    URT_Write( dbmsg_serPort, strlen( oMsg ), (uint08*)oMsg, DBMSG_WAIT, &k );
    URT_Write( dbmsg_serPort, 4, (uint08*)str, DBMSG_WAIT, &k );

    return EXEC_CC_PASS;
}



/****************************************************************************/
/* Send debug message.                                                      */
/****************************************************************************/

static int08 dbmsg__send( char *msg )
{
    uint32 k;                    /* must be supplied; API won't accept NULL */
    size_t  strLength;
            
    if(( strLength = strlen( msg )) > maxMsgLength )
        maxMsgLength = (uint08)strLength;
    
    return URT_Write( dbmsg_serPort, strLength, (uint08*)msg, 0, &k );
}

⌨️ 快捷键说明

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