📄 tmxio.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 : tmXIO.c 1.9
*
* Module type : IMPLEMENTATION
*
* Title : XIO library
*
* Last update : 11:01:47 - 00/06/20
*
* Description :
*
*/
/*----------------------------includes----------------------------------------*/
#include <stdio.h>
#include <tm1/tmAssert.h>
#include <tmlib/AppModel.h>
#include <tm1/mmio.h>
#include <tm1/tmXIO.h>
#include <tm1/tmProcessor.h>
static Int XioInstance = -1;
static Bool XioInited = False;
/*------------------------- local definitions -------------------------------*/
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#define BUILD_VERSION 0
/*----------------------------functions---------------------------------------*/
static Int next_instance;
static xioCapabilities_t capabilities =
{
/* version */ {MAJOR_VERSION, MINOR_VERSION, BUILD_VERSION},
/* numSupportedInstances */ -1,
/* numCurrentInstances */ 0
};
static xioInstanceSetup_t cur_setup = {0};
/*----------------------------functions---------------------------------------*/
/* ------------------------------------------------------
* Function : Fills in the capabilities structure.
* Parameters : cap (O) returned pointer to
* internal capabilities structure
* Function Result : resulting error condition
*/
tmLibdevErr_t
xioGetCapabilities(pxioCapabilities_t * cap)
{
tmAssert(cap != Null, TMLIBDEV_ERR_NULL_PARAMETER);
*cap = &capabilities;
return TMLIBDEV_OK;
}
/* ------------------------------------------------------
* Function : Changes parameters of XIO interface,
* Use is optional.
* Parameters : setup (O) pointer to buffer holding setup info
* Function Result : resulting error condition
*/
tmLibdevErr_t
xioInstanceSetup(Int instance, xioInstanceSetup_t * setup)
{
tmAssert(setup != Null, TMLIBDEV_ERR_NULL_PARAMETER);
tmAssert(instance == XioInstance, TMLIBDEV_ERR_NOT_OWNER);
if (!XioInited) {
xioSetCTL_ADDRESS( setup->ctlAddress );
xioSetCTL_WAIT_STATES( setup->waitStates );
if (setup->busEnable)
xioEnableXIO_BUS;
else
xioDisableXIO_BUS;
if (setup->internalClockEnable)
xioEnableINT_CLOCK;
else
xioDisableINT_CLOCK;
xioSetCTL_CLOCK_FREQ( setup->clockFreqDivider );
XioInited = True;
cur_setup = *setup;
}
return TMLIBDEV_OK;
}
/* ------------------------------------------------------
* Function : Retrieve global parameters.
* Parameters : setup (O) pointer to buffer
* receiving returned parameters
* Function Result : resulting error condition
*/
extern tmLibdevErr_t
xioGetInstanceSetup(Int instance, xioInstanceSetup_t * setup)
{
UInt ien;
tmAssert(setup != Null, TMLIBDEV_ERR_NULL_PARAMETER);
tmAssert(instance == XioInstance, TMLIBDEV_ERR_NOT_OWNER);
*setup = cur_setup;
return TMLIBDEV_OK;
}
/* ------------------------------------------------------
* Function : Assigns a unique instance for the caller.
* Parameters : instance (O) pointer to result variable
* Function Result : error condition if:
* TMLIBDEV_ERR_NULL_PARAMETER: null param passed.
* XIO_ERR_INVALID_PROCESSOR: below TM1100 proc.
*/
tmLibdevErr_t
xioOpen(Int * instance)
{
tmLibdevErr_t err = TMLIBDEV_OK;
pprocCapabilities_t procCap;
tmAssert(instance != Null, TMLIBDEV_ERR_NULL_PARAMETER);
AppModel_suspend_scheduling();
/*
* Verify that we have XIO, ie. we are not on a TM1000
*/
err = procGetCapabilities(&procCap);
if (err != TMLIBDEV_OK) {
goto xioOpenExit;
}
if (procCap->deviceID == PROC_DEVICE_TM1000) {
err = TMLIBDEV_ERR_NOT_AVAILABLE_IN_HW;
goto xioOpenExit;
}
++capabilities.numCurrentInstances;
XioInstance = ++next_instance;
*instance = XioInstance;
xioOpenExit:
AppModel_resume_scheduling();
return err;
}
/* ------------------------------------------------------
* Function : Deallocates the instance.
* Parameters : instance (O) instance to give up
* Function Result : resulting error condition
*/
tmLibdevErr_t
xioClose(Int instance)
{
tmAssert(instance == XioInstance, TMLIBDEV_ERR_NOT_OWNER);
tmAssert(capabilities.numCurrentInstances != 0, TMLIBDEV_ERR_NOT_OWNER);
--capabilities.numCurrentInstances;
return TMLIBDEV_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -