📄 tminterrupts.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 : tmInterrupts.c 1.53
*
* Last update : 10:54:51 - 00/06/20
*
* Description :
* Trimedia Interrupt library.
*
* Revision :
*
*
*/
/*----------------------------- includes ------------------------------------*/
#include <tmlib/AppModel.h>
#include <tm1/tmInterrupts.h>
#include <tm1/tmInterruptsmmio.h>
#include <tm1/mmio.h>
#include <ops/custom_ops.h>
#include <tm1/tmAssert.h>
#include <tm1/tmLibdevErr.h>
#include <tm1/tmPCSW.h>
/*------------------------- local definitions -------------------------------*/
#define NROF_INTERRUPTS 32
#define NROF_PRIORITIES 8
#define WORDSIZE (sizeof (Pointer))
#define ALLOCATE(instance) (allocated |= (1<<(instance)))
#define DEALLOCATE(instance) (allocated &= ~(1<<(instance)))
#define IS_ALLOCATED(instance) ( ((instance) >=0 ) \
&& ((instance) < NROF_INTERRUPTS ) \
&& (allocated & (1<<(instance))) \
)
#define INT_MASK(itr) (1<<(itr))
static intCapabilities_t capabilities =
{
/* version */ {MAJOR_VERSION, MINOR_VERSION, BUILD_VERSION},
/* numSupportedInstances */ NROF_INTERRUPTS,
/* numCurrentInstances */ 0
};
static UInt allocated;
static intPriority_t cur_prio;
static UInt priority_masks[NROF_PRIORITIES];
static UInt enabled_interrupts;
extern void _default_interrupt_handler(void);
extern UInt _number_of_nodes;
extern UInt _node_number;
/*
* Endianness conversion macro:
*/
#define B0 0xFFul
#define B1 0xFF00ul
#define B2 0xFF0000ul
#define B3 0xFF000000ul
#define REVERSE(x) \
( ((x)&B0) << 24 \
| ((x)&B1) << 8 \
| ((x)&B2) >> 8 \
| ((x)&B3) >> 24 \
)
/*--------------------- Hidden initialisation routine ----------------------*/
extern void
intLoadIMASK()
{
Int i;
allocated = MMIO(IMASK);
for (i = 0; i <= intPRIO_6; i++) {
priority_masks[i] = allocated;
}
}
/*--------------------- capability/parameter functions ----------------------*/
/*
* Function : Retrieve global capabilities.
* Parameters : cap (O) returned pointer to
* internal capabilities structure
* Function Result : resulting error condition
*/
extern tmLibdevErr_t
intGetCapabilities(pintCapabilities_t * cap)
{
tmAssert(cap != Null, TMLIBDEV_ERR_NULL_PARAMETER);
*cap = &capabilities;
return TMLIBDEV_OK;
}
/*
* Function : Set/change global parameters.
* Parameters : setup (I) pointer to buffer
* holding new parameters
* Function Result : resulting error condition
*/
extern tmLibdevErr_t
intSetup(intSetup_t * setup)
{
tmAssert(setup != Null, TMLIBDEV_ERR_NULL_PARAMETER);
tmAssert(sizeof (*setup) == 2 * WORDSIZE, INT_ERR_STRUCT_CHANGED);
intCLEAR_IEN ();
cur_prio = setup->priority;
MMIO(IMASK) = enabled_interrupts & priority_masks[cur_prio];
if (setup->enabled)
{
intSET_IEN ();
/*N B This is not a function call, it is a macro. The
surrounding braces {...} are necessary.*/
}
return TMLIBDEV_OK;
}
/*
* Function : Retrieve global parameters.
* Parameters : setup (O) pointer to buffer
* receiving returned parameters
* Function Result : resulting error condition
*/
extern tmLibdevErr_t
intGetSetup(intSetup_t * setup)
{
UInt ien;
tmAssert(setup != Null, TMLIBDEV_ERR_NULL_PARAMETER);
tmAssert(sizeof (*setup) == 2 * WORDSIZE, INT_ERR_STRUCT_CHANGED);
ien = intCLEAR_IEN();
setup->enabled = (ien & intIEN) != 0;
setup->priority = cur_prio;
intRESTORE_IEN(ien);
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
intInstanceSetup(
intInterrupt_t instance,
intInstanceSetup_t * setup)
{
UInt ien;
Int i;
intHandler_t old_handler, new_handler;
printf("--------------------------\nintInstanceSetup\n------------------\n");
/*
* Precondition checks:
*/
tmAssert(IS_ALLOCATED(instance), TMLIBDEV_ERR_NOT_OWNER);
if (!IS_ALLOCATED(instance))
return TMLIBDEV_ERR_NOT_OWNER;
tmAssert(setup != Null, TMLIBDEV_ERR_NULL_PARAMETER);
tmAssert(sizeof (*setup) == 4 * WORDSIZE, INT_ERR_STRUCT_CHANGED);
ien = intCLEAR_IEN();
{
old_handler= (intHandler_t) intGetHANDLER(instance);
/*
* Disable interrupt, and remove from imasks:
*/
for (i = 0; i < NROF_PRIORITIES; i++) {
priority_masks[i] &= ~INT_MASK(instance);
}
MMIO(IMASK) = enabled_interrupts & priority_masks[cur_prio];
/*
* Set new handler and properties:
*/
intSetPRIO__CHECK(instance, setup->priority);
if (setup->level_triggered) {
intEnableLEVEL_TRIGGERED(instance);
}
else {
intDisableLEVEL_TRIGGERED(instance);
}
if (setup->handler == Null) {
intSetHANDLER__CHECK(instance, (Int) _default_interrupt_handler);
}
else {
intSetHANDLER__CHECK(instance, (Int) setup->handler);
}
if (setup->enabled) {
enabled_interrupts |= INT_MASK(instance);
}
else {
enabled_interrupts &= ~INT_MASK(instance);
}
/*
* If handler available; set proper imasks:
*/
if (setup->handler) {
for (i = 0; i <= setup->priority; i++) {
priority_masks[i] |= INT_MASK(instance);
}
MMIO(IMASK) = enabled_interrupts & priority_masks[cur_prio];
}
new_handler= (intHandler_t) intGetHANDLER(instance);
}
intRESTORE_IEN(ien);
if (old_handler != new_handler) {
AppModel_bind_codeseg(old_handler,False);
AppModel_bind_codeseg(new_handler,True);
}
return TMLIBDEV_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -