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

📄 tmexceptions.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
字号:
/*
 * Copyright (c) 1995,2000 TriMedia Technologies Inc.          
 *
 * +------------------------------------------------------------------+
 * | This software is furnished under a license and may only be used  |
 * | and copied in accordance with the terms and conditions of  such  |
 * | a license and with the inclusion of this copyright notice. This  |
 * | software or any other copies of this software may not be provided|
 * | or otherwise made available to any other person.  The ownership  |
 * | and title of this software is not transferred.                   |
 * |                                                                  |
 * | The information in this software is subject  to change without   |
 * | any  prior notice and should not be construed as a commitment by |
 * | TriMedia Technologies.                                           |
 * |                                                                  |
 * | this code and information is provided "as is" without any        |
 * | warranty of any kind, either expressed or implied, including but |
 * | not limited to the implied warranties of merchantability and/or  |
 * | fitness for any particular purpose.                              |
 * +------------------------------------------------------------------+
 *
 *  Module name              : tmExceptions.c    1.32
 *
 *  Last update              : 10:40:45 - 00/06/20
 *
 *  Description              :
 *      Trimedia Exceptions library.
 *
 *  Revision                 :
 *
 *
 */

/*----------------------------- includes ------------------------------------*/

#include <tm1/tmExceptions.h>
#include <tm1/mmio.h>
#include <ops/custom_ops.h>
#include <tm1/tmAssert.h>
#include <tm1/tmLibdevErr.h>
#include <tm1/tmInterrupts.h>


/*------------------------- local definitions -------------------------------*/


#define NROF_EXCEPTIONS                  11
#define MAX_EXCEPTION_NR                 26

#define WORDSIZE                  sizeof(Pointer)

#define ALLOCATE(instance)        (allocated  |=  (1<<(instance)))
#define DEALLOCATE(instance)      (allocated  &= ~(1<<(instance)))

#define IS_ALLOCATED(instance)    (  ((instance) >= 0         )         \
                                  && ((instance) <= MAX_EXCEPTION_NR )  \
                                  && (allocated  &    (1<<(instance)))  \
                                  )

#define PENDING_MASK(itr)     (  1     << (itr) )
#define ENABLED_MASK(itr)     ( (1<<16)<< (itr) )

#define EXCEPTIONS_ENABLE_MASK   0xe07f0000


static excCapabilities_t capabilities =
{
     /* version                */ {MAJOR_VERSION, MINOR_VERSION, BUILD_VERSION},
     /* numSupportedInstances  */ NROF_EXCEPTIONS,
     /* numCurrentInstances    */ 0
};


static UInt allocated;
static excInstanceSetup_t exc_info[MAX_EXCEPTION_NR+1];

extern void _default_exception_callback(UInt32 dpc, UInt32 spc);


/*------------------------ master exception handler -------------------------*/



#define log2(n, m) \
    { float fl= ufloatrz(n); m= ((*(unsigned int*)&fl) >> 23) - 127; }


static void 
master_exception_handler(void *dpc)
{
#pragma TCS_exception_handler
    UInt32      spc, pcsw, exceptions;

    spc  = readspc();
    pcsw = readpcsw();

    exceptions= pcsw  
                &  (  ((pcsw & EXCEPTIONS_ENABLE_MASK) >> 16)
                   |   PENDING_MASK(excTFE)   
                   );

    writepcsw(0, exceptions);

    while (exceptions) {
        UInt excmask;
        UInt exc;

        excmask= ((exceptions ^ (exceptions-1)) +1 ) >> 1;
        log2(excmask,exc);

        exceptions &= ~excmask;

        exc_info[exc].handler((UInt32) dpc, spc);
    }
}


/*--------------------- capability/parameter functions ----------------------*/



/*
 * Function         : Retrieve global capabilities.
 * Parameters       : cap  (O)  returned pointer to
 *                              internal capabilities structure
 * Function Result  : resulting error condition
 */

extern      tmLibdevErr_t
excGetCapabilities(pexcCapabilities_t * cap)
{
    tmAssert(cap != Null, TMLIBDEV_ERR_NULL_PARAMETER);

    *cap = &capabilities;
    return TMLIBDEV_OK;
}



/*
 * Function         : Set/change instance parameters.
 * Parameters       : instance (I)  instance to set parameters for
 *                    setup    (I)  pointer to buffer
 *                                  holding new parameters
 * Function Result  : resulting error condition
 */

extern      tmLibdevErr_t
excInstanceSetup(
         excException_t instance,
         excInstanceSetup_t * setup)
{
    UInt        ien;
    excHandler  old_handler, new_handler;

    /*
     * Precondition checks:
     */
    tmAssert(setup != Null, TMLIBDEV_ERR_NULL_PARAMETER);
    tmAssert(sizeof (*setup) == 2 * WORDSIZE, EXC_ERR_STRUCT_CHANGED);
    tmAssert(IS_ALLOCATED(instance), TMLIBDEV_ERR_NOT_OWNER);

    if (!IS_ALLOCATED(instance))
        return TMLIBDEV_ERR_NOT_OWNER;

    ien = intCLEAR_IEN();
    {
        old_handler= exc_info[instance].handler;

        exc_info[instance] = *setup;

        if (setup->handler == Null) {
            exc_info[instance].handler = _default_exception_callback;
        } else

        if (instance == excTFE) {
            exc_info[instance].enabled= True;
        } else {
	    if (setup->enabled) {
		writepcsw(0xffffffff, ENABLED_MASK(instance));
	    } else {
		writepcsw(0,          ENABLED_MASK(instance));
	    }
        }

        new_handler= exc_info[instance].handler;
    }
    intRESTORE_IEN(ien);

    if (old_handler != new_handler) {
        AppModel_bind_codeseg(old_handler,False);
        AppModel_bind_codeseg(new_handler,True);
    }

    return TMLIBDEV_OK;
}



/*
 * Function         : Retrieve instance parameters.
 * Parameters       : instance (I)  instance to get parameters from
 *                    setup    (O)  pointer to buffer
 *                                  receiving returned parameters
 * Function Result  : resulting error condition
 */

extern      tmLibdevErr_t
excGetInstanceSetup(
            excException_t instance,
            excInstanceSetup_t * setup)
{
    UInt        ien;

    /*
     * Precondition checks:
     */
    tmAssert(setup != Null, TMLIBDEV_ERR_NULL_PARAMETER);
    tmAssert(IS_ALLOCATED(instance), TMLIBDEV_ERR_NOT_OWNER);

    ien = intCLEAR_IEN();
    {
        /*
         * Extraction of result:
         */
        *setup = exc_info[instance];

        if (setup->handler == (excHandler) _default_exception_callback) {
            setup->handler = Null;
        }
    }
    intRESTORE_IEN(ien);

    return TMLIBDEV_OK;
}


/*--------------------- open/close functions ---------------------------------*/


/*
 * Function         : Reserve the use of a specified exception.
 * Parameters       : instance (I)  required exception
 * Function Result  : resulting error condition
 *                         (EXC_ERR_ALREADY_OPEN)
 */

extern      tmLibdevErr_t
excOpen(excException_t instance)
{
    UInt        ien;
    tmLibdevErr_t result;

    ien = intCLEAR_IEN();
    {
        if (capabilities.numCurrentInstances == 0) {
            MMIO(EXCVEC) = (Int) master_exception_handler;
        }

        if (IS_ALLOCATED(instance)) {
            result = EXC_ERR_ALREADY_OPEN;

        }
        else {
            ALLOCATE(instance);

            capabilities.numCurrentInstances++;
            writepcsw(0, PENDING_MASK(instance));

            result = TMLIBDEV_OK;
        }
    }
    intRESTORE_IEN(ien);

    return result;
}



/*
 * Function         : Deallocates the inter instance,
 *                    and uninstall its handler when it has one.
 * Parameters       : instance  (I)  instance to give up
 * Function Result  : resulting error condition
 */

extern      tmLibdevErr_t
excClose(excException_t instance)
{
    UInt        ien;
    excInstanceSetup_t setup;

    tmAssert(IS_ALLOCATED(instance), TMLIBDEV_ERR_NOT_OWNER);

    ien = intCLEAR_IEN();
    {
        excGetInstanceSetup(instance, &setup);

        setup.enabled = False;
        setup.handler = Null;

        excInstanceSetup(instance, &setup);

        DEALLOCATE(instance);

        capabilities.numCurrentInstances--;
    }
    intRESTORE_IEN(ien);

    return TMLIBDEV_OK;
}

⌨️ 快捷键说明

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