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

📄 tmintpins.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              : tmIntPins.c    1.31
 *
 *  Last update              : 10:55:34 - 00/06/20
 *
 *  Description              :
 *      Trimedia PCI interrupt pins library.
 *
 *      This header forms interface to the PCI interrupt pins.
 *      Specific interrupt pins can be made accessable by calling
 *      the pinOpen function, after which they can be setup to
 *      relatively constant settings which are collector state
 *      and optional interrupt handler with interrupt priority.
 *      When no interrupt handler is required a null handler can
 *      be provided, otherwise the handler will be automatically
 *      installed usint the tmInterrupt library. Conversely,
 *      interrupt handlers will be automatically uninstalled for
 *      interrupt pins which are closed.
 *
 *      The setup function can be repeatedly used to modify
 *      one or more of the pin's parameters; any changes
 *      will be correctly effectuated. When only a few of the
 *      parameters are to be changed, usually a call to the Getup
 *      function is necessary to get the current value of the
 *      other parameters.
 *
 *      After the pin has been set up, the action functions
 *      for getting or setting the value can be called for
 *      'operating' the pin.
 *
 *  Revision                 :
 *
 *
 */

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

#include <tm1/tmIntPins.h>
#include <tm1/tmIntPinsmmio.h>
#include <tm1/mmio.h>
#include <tm1/tmAssert.h>
#include <tm1/tmLibdevErr.h>


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


#define NROF_PINS                 4
#define WORDSIZE                  sizeof(Pointer)

#define INTERRUPT_OF(instance)    ((intInterrupt_t)(instance))



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

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



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


static UInt allocated;
static pinInstanceSetup_t pin_info[NROF_PINS];





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



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

extern      tmLibdevErr_t
pinGetCapabilities(ppinCapabilities_t * cap)
{
    tmAssert(cap != Null, TMLIBDEV_ERR_NULL_PARAMETER);

    *cap = &capabilities;
    return TMLIBDEV_OK;
}



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

extern      tmLibdevErr_t
pinGetInstanceCapabilities(
               pinInterruptPin_t instance,
               pinInstanceCapabilities_t * cap)
{
    tmAssert(cap != Null, TMLIBDEV_ERR_NULL_PARAMETER);
    tmAssert(IS_ALLOCATED(instance), TMLIBDEV_ERR_NOT_OWNER);
    tmAssert(sizeof (*cap) == 1 * WORDSIZE, PIN_ERR_STRUCT_CHANGED);

    cap->interrupt = INTERRUPT_OF(instance);

    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
pinInstanceSetup(
         pinInterruptPin_t instance,
         pinInstanceSetup_t * setup)
{
    UInt        ien;

    tmAssert(setup != Null, TMLIBDEV_ERR_NULL_PARAMETER);
    tmAssert(IS_ALLOCATED(instance), TMLIBDEV_ERR_NOT_OWNER);
    if (!IS_ALLOCATED(instance))
        return TMLIBDEV_ERR_NOT_OWNER;

    ien = intCLEAR_IEN();
    {
        if (setup->openCollector) {
            pinEnableIE(instance);
        }
        else {
            pinDisableIE(instance);
        }

        if (setup->handler != pin_info[instance].handler
           || setup->priority != pin_info[instance].priority
           || setup->levelTriggered != pin_info[instance].levelTriggered
           ) {
            intInstanceSetup_t int_setup;

            tmAssert(sizeof (int_setup) == 4 * WORDSIZE, PIN_ERR_STRUCT_CHANGED);

            int_setup.handler         = setup->handler;
            int_setup.priority        = setup->priority;
            int_setup.level_triggered = setup->levelTriggered;
            int_setup.enabled         = True;

            intInstanceSetup(INTERRUPT_OF(instance), &int_setup);
        }

        pin_info[instance] = *setup;
    }
    intRESTORE_IEN(ien);

    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
pinGetInstanceSetup(
            pinInterruptPin_t instance,
            pinInstanceSetup_t * setup)
{
    UInt        ien;

    tmAssert(setup != Null, TMLIBDEV_ERR_NULL_PARAMETER);
    tmAssert(IS_ALLOCATED(instance), TMLIBDEV_ERR_NOT_OWNER);

    ien = intCLEAR_IEN();
    {
        *setup = pin_info[instance];
    }
    intRESTORE_IEN(ien);

    return TMLIBDEV_OK;
}

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


/*
 * Function         : Reserve the use of a specified interrupt pin.
 * Parameters       : pin       (I)  required interrupt pin
 * Function Result  : resulting error condition
 *                         (PIN_ERR_ALREADY_OPEN)
 */

extern      tmLibdevErr_t
pinOpen(pinInterruptPin_t pin)
{
    UInt        ien;
    tmLibdevErr_t result;

    ien = intCLEAR_IEN();
    {
        if (IS_ALLOCATED(pin)) {
            result = PIN_ERR_ALREADY_OPEN;

        }
        else if (result = intOpen(INTERRUPT_OF(pin))) {

        }
        else {
            ALLOCATE(pin);

            pinSet(pin, False);

            capabilities.numCurrentInstances++;

            result = TMLIBDEV_OK;
        }
    }
    intRESTORE_IEN(ien);

    return result;
}



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

extern      tmLibdevErr_t
pinClose(pinInterruptPin_t instance)
{
    UInt        ien;

    tmAssert(IS_ALLOCATED(instance), TMLIBDEV_ERR_NOT_OWNER);

    ien = intCLEAR_IEN();
    {
        intClose(INTERRUPT_OF(instance));

        memset(&pin_info[instance], 0, sizeof (pin_info[instance]));

        pinSet(instance, False);

        DEALLOCATE(instance);

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

    return TMLIBDEV_OK;
}


/*---------------------- pin access functions --------------------------------*/


/*
 * Function         : Retrieve current pin value.
 * Parameters       : instance  (I)  instance to get value from
 *                    value     (O)  returned pin value
 * Function Result  : resulting error condition
 */

extern      tmLibdevErr_t
pinGet(pinInterruptPin_t instance, Bool * value)
{
    tmAssert(value != Null, TMLIBDEV_ERR_NULL_PARAMETER);
    tmAssert(IS_ALLOCATED(instance), TMLIBDEV_ERR_NOT_OWNER);

    *value = pinCheckIS(instance) != 0;

    return TMLIBDEV_OK;
}



/*
 * Function         : Set/change pin value.
 * Parameters       : instance  (I)  instance to set value for
 *                    value     (O)  new pin value
 * Function Result  : resulting error condition
 */

extern      tmLibdevErr_t
pinSet(pinInterruptPin_t instance, Bool value)
{
    tmAssert(IS_ALLOCATED(instance), TMLIBDEV_ERR_NOT_OWNER);

    if (value) {
        pinEnableINT(instance);
        return TMLIBDEV_OK;
    }
    else {
        pinDisableINT(instance);
        return TMLIBDEV_OK;
    }
}

⌨️ 快捷键说明

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