Exception.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:5k
- /****************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: Exception.c $
- *
- * Description: Exception mechanism.
- * ============
- *
- *
- * Log:
- * ====
- * $Revision: 4 $
- * Last Modified by $Author: Nirm $ at $Modtime: 24/05/02 14:39 $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I49/H49V/Playcore/Exception/Exception.c $
- *
- * 4 24/05/02 16:54 Nirm
- * - Alternative Critical-Section implementation, to allow usage from
- * within Interrupt-context.
- *
- * 3 23/04/02 9:29 Nirm
- * - Added dependency in "Config.h".
- *
- * 2 7/03/02 16:52 Nirm
- * Integrated Exceptioning mechanism.
- *
- * 1 7/03/02 9:09 Nirm
- ****************************************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceCore)
- #include "DebugDbgMain.h"
- #endif //_DEBUG
- #include "KerneluITRONRTOS.h"
- #include "PlaycoreExceptionException.h"
- /////////////////////////////////////////////////////////////////////////////
- // Globals and Singletons
- struct ExceptionInfo_TAG {
- excThrown;
- excIgnored;
- } g_ExceptionInfo= { EXCEPTION_NONE, EXCEPTION_NONE };
- /////////////////////////////////////////////////////////////////////////////
- // Public Services
- /////////////////////////////////////////////////////////////////////////////
- // Exception_throw()
- //
- // Description: Throws an Exception.
- //
- // Input: excThrow - The Exception to throw.
- // Output: None
- // In/Out: None
- //
- // Return: None
- //
- // Remarks: None
- void Exception_throw(EXCEPTION excThrow)
- {
- // Begin Critical-Section
- STATUS_REG srValue= InterruptDisable();
- // Throw the Exception, unless it is being ignored
- g_ExceptionInfo.excThrown |= (excThrow & ~g_ExceptionInfo.excIgnored);
- // End Critical-Section
- set_SR(srValue);
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Exception_catch()
- //
- // Description: Catches an Exception, and clears it.
- //
- // Input: excCatch - The Exception to catch.
- // Output: None
- // In/Out: None
- //
- // Return: TRUE if an Exception was caught; FALSE otherwise.
- //
- // Remarks:
- // If the requested Exception was raised, then it is caught and cleared.
- EXCEPTION Exception_catch(EXCEPTION excCatch)
- {
- EXCEPTION excCaught;
- // Begin Critical-Section
- STATUS_REG srValue= InterruptDisable();
- // Test whether or not the Exception was caught
- excCaught= (g_ExceptionInfo.excThrown & excCatch);
- // Catch and clear the Exception
- g_ExceptionInfo.excThrown &= ~excCatch;
- // End Critical-Section
- set_SR(srValue);
- return excCaught;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Exception_catchAndRethrow()
- //
- // Description: Catches an Exception, without clearing it.
- //
- // Input: excCatch - The Exception to catch.
- // Output: None
- // In/Out: None
- //
- // Return: TRUE if an Exception was caught; FALSE otherwise.
- //
- // Remarks:
- // If the requested Exception was raised, then it is caught but not cleared.
- // Hence, a raised Exception remains raised, and is effectively re-thrown.
- EXCEPTION Exception_catchAndRethrow(EXCEPTION excCatch)
- {
- EXCEPTION excCaught;
- // Begin Critical-Section
- STATUS_REG srValue= InterruptDisable();
- // Test whether or not the Exception was caught, and leave it in place
- excCaught= (g_ExceptionInfo.excThrown & excCatch);
- // End Critical-Section
- set_SR(srValue);
- return excCaught;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Exception_ignore()
- //
- // Description: Controls whether or not a certain Exception is ignored.
- //
- // Input: excIgnore - The Exception to start/stop ignoring;
- // bEnaqble - Determines whether to enable or disable ignoring.
- // Output: None
- // In/Out: None
- //
- // Return: None
- //
- // Remarks:
- // An Exception can be inserted into the list of Ignred Exceptions, which
- // allows the Exception to be thrown without supplying a handler for that
- // Exception.
- // An Ignored Exception remains in that state, until it is explicitely
- // removed from the list of Ignored Exceptions.
- void Exception_ignore(EXCEPTION excIgnore, BOOL bEnable)
- {
- // Begin Critical-Section
- STATUS_REG srValue= InterruptDisable();
- // Enable or Disable the requested Exception
- if (bEnable)
- g_ExceptionInfo.excIgnored |= excIgnore;
- else
- g_ExceptionInfo.excIgnored &= ~excIgnore;
- // End Critical-Section
- set_SR(srValue);
- return;
- }