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

📄 tmsem.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              : tmSEM.c    1.15
 *
 *  Last update              : 11:00:26 - 00/06/20
 *
 *  Description              :
 *      Trimedia Semaphore device library header file.
 *
 *      This header forms interface to the TM-1000 semaphore devices.
 *
 *  Revision                 :
 *
 *
 */

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

#include <tm1/tmSEM.h>
#include <tm1/mmio.h>
#include <ops/custom_ops.h>
#include <tm1/tmAssert.h>
#include <tm1/tmPCSW.h>
#include <tm1/tmLibdevErr.h>


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

extern UInt _number_of_nodes;
extern UInt _node_number;

/*
 * Endianness conversion macro:
 */

#define B0   ((unsigned long)(255    ))
#define B1   ((unsigned long)(B0 << 8))
#define B2   ((unsigned long)(B1 << 8))
#define B3   ((unsigned long)(B2 << 8))

#define REVERSE(x)  \
           (  ((x)&B0) << 24    \
           |  ((x)&B1) <<  8    \
           |  ((x)&B2) >>  8    \
           |  ((x)&B3) >> 24    \
           )


/*--------------------- semdev utility functions ----------------------------*/


/*
 * Function         : Attempt to aquire the semaphore device on the
 *                    specified TM1 node.
 * Parameters       : node_number  (I) node of semaphore to claim
 *                    wait         (I) when equal to True, this function
 *                                     will busy wait until the semphore
 *                                     can be aquired. Otherwise only one
 *                                     try is made, and SEM_ERR_NOT_AQUIRED
 *                                     is returned if the try failed.
 * Function Result  : resulting error condition
 *                         (SEM_ERR_NOT_AQUIRED)
 * NB               : See TM-100 databook; this function uses the
 *                    current node number as base for the 12-bit id.
 */

extern      tmLibdevErr_t
semdevGet(UInt node_number, Bool wait)
{
    UInt        id          = _node_number + 1;
    Bool        swap_needed = (node_number != _node_number)
                              && ((MMIO(BIU_CTL) & 0x1) != ((readpcsw() >> BSX_bit) & 0x1));
    Bool        aquired;


    tmAssert(node_number < _number_of_nodes, SEM_ERR_INVALID_NODE);

    if (swap_needed) {
        id = REVERSE(id);
    }

    do {
        MMIO_M(node_number, SEM) = id;
        aquired = MMIO_M(node_number, SEM) == id;
    } while (!aquired && wait);


    if (aquired) {
        return TMLIBDEV_OK;
    }
    else {
        return SEM_ERR_NOT_AQUIRED;
    }
}


/*
 * Function         : Release the semaphore device on the specified node.
 * Parameters       : node_number  (I) node of semaphore to free
 * Function Result  : resulting error condition
 *                         (SEM_ERR_INVALID_NODE)
 */

extern      tmLibdevErr_t
semdevRelease(UInt node_number)
{
    tmAssert(node_number < _number_of_nodes, SEM_ERR_INVALID_NODE);

    MMIO_M(node_number, SEM) = 0;

    return TMLIBDEV_OK;
}

⌨️ 快捷键说明

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