📄 wmdiagnostics.c
字号:
/*-----------------------------------------------------------------------------
* Copyright (c) Wolfson Microelectronics plc. All rights reserved.
*
* This software as well as any related documentation is furnished under
* license and may only be used or copied in accordance with the terms of the
* license. The information in this file is furnished for informational use
* only, is subject to change without notice, and should not be construed as
* a commitment by Wolfson Microelectronics plc. Wolfson Microelectronics plc
* assumes no responsibility or liability for any errors or inaccuracies that
* may appear in this document or any software that may be provided in
* association with this document.
*
* Except as permitted by such license, no part of this document may be
* reproduced, stored in a retrieval system, or transmitted in any form or by
* any means without the express written consent of Wolfson Microelectronics plc.
*
* $Id: WMDiagnostics.c 2584 2006-01-18 09:47:28Z fb $
*
* This file contains platform-independent routines for performing diagnostics
* on Wolfson codecs.
*
* Warning:
* This driver is specifically written for Wolfson Codecs. It is not a
* general CODEC device driver.
*
* -----------------------------------------------------------------------------*/
/*
* Include files
*/
#include "WMCommon.h"
#include "WMDevice.h"
#include "WMControlLink.h"
#include <stdio.h>
/*
* MACROS
*/
/*-----------------------------------------------------------------------------
* DEFINES
----------------------------------------------------------------------------*/
/*
* The operations supported by WMDebugJacket.
*/
typedef enum tagDEBUG_OP
{
DEBUG_OP_RESET = 0,
DEBUG_OP_READ,
DEBUG_OP_WRITE
} DEBUG_OP;
/*-----------------------------------------------------------------------------
* INTERNAL FUNCTIONS
----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------
* EXTERNAL FUNCTIONS
----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------
* CONSTANTS AND VARIABLES
----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------
* Function: WMStatusText
*
* Purpose:
* This function returns a textual representation of the status value - useful
* for reporting errors.
*
* Parameters:
* status status code.
*
* Returns: const char *
* Textual representation of error code.
----------------------------------------------------------------------------*/
const char *WMStatusText( WMSTATUS status )
{
static char string[25]; /* For "<unknown> (0x%08X)" */
switch ( status )
{
case WMS_SUCCESS:
return "WMS_SUCCESS";
case WMS_RETURN_TRUE:
return "WMS_RETURN_TRUE";
case WMS_RETURN_FALSE:
return "WMS_RETURN_FALSE";
/* Link errors */
case WMS_DEVICE_BUSY:
return "WMS_DEVICE_BUSY";
case WMS_DATA_TIMED_OUT:
return "WMS_DATA_TIMED_OUT";
case WMS_LOCK_TIMED_OUT:
return "WMS_LOCK_TIMED_OUT";
case WMS_ACLINK_NOT_ACTIVE:
return "WMS_ACLINK_NOT_ACTIVE";
case WMS_CODEC_NOT_READY:
return "WMS_CODEC_NOT_READY";
case WMS_NO_SUPPORTED_DEVICE:
return "WMS_NO_SUPPORTED_DEVICE";
case WMS_REG_NOT_PRESENT:
return "WMS_REG_NOT_PRESENT";
/* General errors */
case WMS_RESOURCE_FAIL:
return "WMS_RESOURCE_FAIL";
case WMS_INVALID_PARAMETER:
return "WMS_INVALID_PARAMETER";
case WMS_UNSUPPORTED:
return "WMS_UNSUPPORTED";
case WMS_HW_ERROR:
return "WMS_HW_ERROR";
case WMS_FAILURE:
return "WMS_FAILURE";
case WMS_WRONG_MODE:
return "WMS_WRONG_MODE";
case WMS_RESOURCE_CONFLICT:
return "WMS_RESOURCE_CONFLICT";
case WMS_INVALID_CHANNEL:
return "WMS_INVALID_CHANNEL";
case WMS_RESOURCE_NULL:
return "WMS_RESOURCE_NULL";
case WMS_UNKNOWN_MESSAGE:
return "WMS_UNKNOWN_MESSAGE";
case WMS_UNKNOWN_PROFILE:
return "WMS_UNKNOWN_PROFILE";
case WMS_EVENT_TIMED_OUT:
return "WMS_EVENT_TIMED_OUT";
case WMS_NOT_IMPLEMENTED:
return "WMS_NOT_IMPLEMENTED";
/* ADC/Touch errors */
case WMS_UNEXPECTED_DATA:
return "WMS_UNEXPECTED_DATA";
case WMS_NO_PEN_DOWN:
return "WMS_NO_PEN_DOWN";
case WMS_SCATTERED_SAMPLES:
return "WMS_SCATTERED_SAMPLES";
case WMS_AUXADC_INACTIVE:
return "WMS_AUXADC_INACTIVE";
case WMS_NO_DATA:
return "WMS_NO_DATA";
/* Audio errors */
case WMS_INVALID_SIGNAL:
return "WMS_INVALID_SIGNAL";
/* Shadow register errors */
case WMS_UNABLE_TO_SHADOW:
return "WMS_UNABLE_TO_SHADOW";
case WMS_SHADOW_UNINTIALISED:
return "WMS_SHADOW_UNINTIALISED";
default:
sprintf( string, "<unknown> (0x%08X)", status );
return string;
}
}
/*-----------------------------------------------------------------------------
* Function: WMSignalName
*
* Purpose:
* This function returns a textual representation of the signal - useful
* for reporting errors.
*
* Parameters:
* signal signal.
*
* Returns: const char *
* Textual representation of error code.
----------------------------------------------------------------------------*/
const char *WMSignalName( WM_AUDIO_SIGNAL signal )
{
static char string[25]; /* For "<unknown> (0x%08X)" */
#ifdef DEBUG
switch ( signal )
{
/* Analogue inputs - i.e. signal sources */
case WM_AUDIO_LINEIN: return "WM_AUDIO_LINEIN";
case WM_AUDIO_MONOIN: return "WM_AUDIO_MONOIN";
case WM_AUDIO_MIC: return "WM_AUDIO_MIC";
case WM_AUDIO_MIC2: return "WM_AUDIO_MIC2";
case WM_AUDIO_MIC2A: return "WM_AUDIO_MIC2A";
case WM_AUDIO_MIC2B: return "WM_AUDIO_MIC2B";
case WM_AUDIO_MIC2BTOA: return "WM_AUDIO_MIC2BTOA";
case WM_AUDIO_CD: return "WM_AUDIO_CD";
case WM_AUDIO_VIDEO: return "WM_AUDIO_VIDEO";
case WM_AUDIO_AUXIN: return "WM_AUDIO_AUXIN";
case WM_AUDIO_PCBEEP: return "WM_AUDIO_PCBEEP";
/* Digital outputs - i.e. signal sources */
case WM_AUDIO_HIFI_DAC: return "WM_AUDIO_HIFI_DAC";
case WM_AUDIO_MONO_DAC: return "WM_AUDIO_MONO_DAC";
case WM_AUDIO_VOICE_DAC: return "WM_AUDIO_VOICE_DAC";
/* Analogue outputs - i.e. signal destinations */
case WM_AUDIO_SPEAKER: return "WM_AUDIO_SPEAKER";
case WM_AUDIO_HEADPHONE: return "WM_AUDIO_HEADPHONE";
case WM_AUDIO_MONOOUT: return "WM_AUDIO_MONOOUT";
case WM_AUDIO_OUT3: return "WM_AUDIO_OUT3";
case WM_AUDIO_OUT4: return "WM_AUDIO_OUT4";
/* Digital input - i.e. signal destination */
case WM_AUDIO_HIFI_ADC: return "WM_AUDIO_HIFI_ADC";
case WM_AUDIO_VOICE_ADC: return "WM_AUDIO_VOICE_ADC";
/* Mixers and Muxes */
case WM_AUDIO_HEADPHONE_MIXER: return "WM_AUDIO_HEADPHONE_MIXER";
case WM_AUDIO_HEADPHONE_MIXER_MONO: return "WM_AUDIO_HEADPHONE_MIXER_MONO";
case WM_AUDIO_PHONE_MIXER: return "WM_AUDIO_PHONE_MIXER";
case WM_AUDIO_SPEAKER_MIXER: return "WM_AUDIO_SPEAKER_MIXER";
case WM_AUDIO_MONO_MIXER: return "WM_AUDIO_MONO_MIXER";
case WM_AUDIO_FRONT_MIXER: return "WM_AUDIO_FRONT_MIXER";
/* A value for Don't care / Don't change signals */
case WM_AUDIO_IGNORE: return "WM_AUDIO_IGNORE";
/* A value for unknown signals */
case WM_AUDIO_SIGNAL_UNKNOWN: return "WM_AUDIO_SIGNAL_UNKNOWN";
default:
sprintf( string, "<unknown> (0x%02X)", signal );
return string;
}
#else /* DEBUG */
sprintf( string, "0x%02X", signal );
return string;
#endif /* DEBUG */
}
#if WM_USE_DEBUG_JACKET || defined( DEBUG )
/*-----------------------------------------------------------------------------
* Function: WMDebugJacket
*
* Purpose: This function allows you to do register reads and writes through
* the debugger. To use it, set a breakpoint at the start of the routine.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice).
*
* Returns: void.
*
----------------------------------------------------------------------------*/
void WMDebugJacket( WM_DEVICE_HANDLE hDevice )
{
WMSTATUS status;
volatile WM_BOOL debugging = FALSE;
volatile DEBUG_OP op = DEBUG_OP_WRITE;
volatile WM_REGTYPE reg = 0;
volatile WM_REGVAL regval = 0x0;
/*
* To use this function, set a breakpoint at the start of the routine.
* When you hit the breakpoint, use the debugger to set debugging to 1, then
* set the other variables appropriately for the operations you want to
* perform and step through the loop. Once finished, set debugging to 0
* again to exit the function.
*/
#if WM_USE_DEBUG_JACKET
/*
* A breakpoint so we'll stop here.
*/
WMDebugBreakpoint();
#endif /* WM_USE_DEBUG_JACKET */
while ( debugging )
{
/* Now work out what to do */
switch ( op )
{
case DEBUG_OP_WRITE:
status = WMWrite( hDevice, reg, regval );
WM_TRACE( hDevice, (
"==> Write: R%02Xh := 0x%04X status %s",
reg,
regval,
WMStatusText( status )
));
break;
case DEBUG_OP_READ:
status = WMRead( hDevice, reg, (WM_REGVAL *)®val );
WM_TRACE( hDevice, (
"==> Read: R%02Xh == 0x%04X status %s",
reg,
regval,
WMStatusText( status )
));
break;
case DEBUG_OP_RESET:
status = WMReset( hDevice );
WM_TRACE( hDevice, (
"==> Reset: status %s",
WMStatusText( status )
));
break;
}
}
return;
}
#endif /* WM_USE_DEBUG_JACKET || defined( DEBUG ) */
/*-----------------------------------------------------------------------------
* Now the functions which are only built in debug mode.
----------------------------------------------------------------------------*/
#ifdef DEBUG
/*-----------------------------------------------------------------------------
* Function: WMDumpEveryReg
*
* Purpose: Output the value of every register on the codec
* (for debugging purposes only).
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice).
*
* Returns: void.
*
----------------------------------------------------------------------------*/
void WMDumpEveryReg( WM_DEVICE_HANDLE hDevice )
{
int reg, maxReg, regOffset;
const WM_CHIPDEF *pChipDef;
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WM_ASSERT( hDevice, pChipDef );
if ( !pChipDef )
{
WM_TRACE( hDevice, ("----------------------------------------------") );
WM_TRACE( hDevice, (" ERROR: WM Reg Dump cannot find ChipDef") );
WM_TRACE( hDevice, ("----------------------------------------------") );
goto finish;
}
maxReg = pChipDef->maxRegister;
regOffset = pChipDef->regOffset;
WM_TRACE( hDevice, (" WM Reg Dump") );
WM_TRACE( hDevice, ("----------------------") );
for ( reg = 0; reg <= maxReg; reg += regOffset )
{
WMDumpReg( hDevice, reg );
}
WM_TRACE( hDevice, ("----------------------") );
finish:
return;
}
/*-----------------------------------------------------------------------------
* Function: WMDumpReg
*
* Purpose: Output the value of 1 register on the codec
* (for debugging purposes only).
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
*
* Returns: void.
*
----------------------------------------------------------------------------*/
void WMDumpReg( WM_DEVICE_HANDLE hDevice, WM_REGTYPE reg )
{
WM_REGVAL WMReg;
WMRead(hDevice, reg, &WMReg);
WM_TRACE( hDevice, ("Reg 0x%02X [R%3d] = 0x%04X", reg, reg, WMReg) );
return;
}
/*-----------------------------------------------------------------------------
* Function: WMOutputToHexLeds
*
* Purpose: Output a value to the hex leds
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice).
* value value to output to the hex leds.
*
* Returns: void.
*
----------------------------------------------------------------------------*/
void WMOutputToHexLeds( WM_DEVICE_HANDLE hDevice, unsigned long value )
{
WMPlatformOutputToHexLeds( hDevice, value );
}
#endif /* DEBUG */
/*------------------------------ END OF FILE ---------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -