📄 pip_lio.c
字号:
/* ***********************************************************
* THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
* REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
* INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
* COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE.
* TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET
* POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY
* INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR
* YOUR USE OF THE PROGRAM.
*
* IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
* CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY
* THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT
* OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM.
* EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF
* REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS
* OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF
* USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S
* AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF
* YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS
* (U.S.$500).
*
* Unless otherwise stated, the Program written and copyrighted
* by Texas Instruments is distributed as "freeware". You may,
* only under TI's copyright in the Program, use and modify the
* Program without any charge or restriction. You may
* distribute to third parties, provided that you transfer a
* copy of this license to the third party and the third party
* agrees to these terms by its first use of the Program. You
* must reproduce the copyright notice and any other legend of
* ownership on each copy or partial copy, of the Program.
*
* You acknowledge and agree that the Program contains
* copyrighted material, trade secrets and other TI proprietary
* information and is protected by copyright laws,
* international copyright treaties, and trade secret laws, as
* well as other intellectual property laws. To protect TI's
* rights in the Program, you agree not to decompile, reverse
* engineer, disassemble or otherwise translate any object code
* versions of the Program to a human-readable form. You agree
* that in no event will you alter, remove or destroy any
* copyright notice included in the Program. TI reserves all
* rights not specifically granted under this license. Except
* as specifically provided herein, nothing in this agreement
* shall be construed as conferring by implication, estoppel,
* or otherwise, upon you, any license or other right under any
* TI patents, copyrights or trade secrets.
*
* You may not use the Program in non-TI devices.
* ********************************************************* */
/*
* ======== pip_lio.c ========
*! Revision History
*! ================
*/
#include <std.h>
#include <log.h>
#include <swi.h>
#include <pip.h>
#include <lio.h>
extern LIO_Fxns PIP_LIO_FXNS;
LIO_Fxns *drv = &PIP_LIO_FXNS;
Void PIP_LIO_txPrime(int chan, PIP_Obj *pip);
Void PIP_LIO_rxPrime(int chan, PIP_Obj *pip);
#define RCV_CHAN0 0
#define XMT_CHAN0 1
#define RCV_CHAN1 2
#define XMT_CHAN1 3
/* forward decl */
extern Void PIP_LIO_rxPump(Uns, Arg);
extern Void PIP_LIO_txPump(Uns, Arg);
extern far PIP_Obj txPip0;
extern far PIP_Obj rxPip0;
extern far PIP_Obj txPip1;
extern far PIP_Obj rxPip1;
Void
PIP_LIO_init(Void)
{
drv->init(RCV_CHAN0, NULL);
drv->init(XMT_CHAN0, NULL);
drv->init(RCV_CHAN1, NULL);
drv->init(XMT_CHAN1, NULL);
drv->setCallback(RCV_CHAN0, PIP_LIO_rxPump, (Arg)&rxPip0);
drv->setCallback(XMT_CHAN0, PIP_LIO_txPump, (Arg)&txPip0);
drv->setCallback(RCV_CHAN1, PIP_LIO_rxPump, (Arg)&rxPip1);
drv->setCallback(XMT_CHAN1, PIP_LIO_txPump, (Arg)&txPip1);
drv->start(RCV_CHAN0);
drv->start(XMT_CHAN0);
drv->start(RCV_CHAN1);
drv->start(XMT_CHAN1);
/* PENDING: Do I really need to call these here? */
/* these enable interrupts, maybe a problem? */
/* PIP_LIO_txPrime(XMT_CHAN, txPip); */
/* PIP_LIO_rxPrime(RCV_CHAN, rxPip); */
}
/* LIO callback for transmit channels */
Void
PIP_LIO_txPump(Uns chan, Arg parg)
{
PIP_Obj *pip = (PIP_Obj *)parg;
if (drv->getBuf(chan, NULL, NULL) != NULL) {
PIP_free(pip);
/* push another buffer into the hardware queue if available */
PIP_LIO_txPrime(chan, pip);
}
}
/*
* ======= PIP_LIO_txPrime ========
* This must be called by the notifyReader function of the txPips
*/
Void
PIP_LIO_txPrime(int chan, PIP_Obj *pip)
{
static int nested = 0;
if (nested) return;
nested = 1;
/* if there is room in the driver and a frame on the tx queue */
/* PENDING: There is a race condition between !isEmpty and nested =
0. If the callback occurs after isEmpty returns false but before
nested = 0 then a new buffer will not be put into the hw queue
and the system will deadlock. We need to turn off interrupts
here. SWI callbacks would have made this easier I think. We could
replace HWI_disable with drv->disable perhaps. */
HWI_disable();
/* must ensure isEmpty, can only operate on one PIP frame at a time */
if (drv->isEmpty(chan) && PIP_getReaderNumFrames(pip) > 0) {
HWI_enable();
/* pull it off of the pipe and put it on the hardware queue */
PIP_get(pip);
drv->setBuf(chan,
PIP_getReaderAddr(pip),
PIP_getReaderSize(pip)*sizeof(int)); /* words to bytes */
} else {
HWI_enable();
}
nested = 0;
}
/* LIO callback for receive channels */
Void
PIP_LIO_rxPump(Uns chan, Arg parg)
{
PIP_Obj *pip = (PIP_Obj *)parg;
int validWords;
if (drv->getBuf(chan, NULL, &validWords)) {
validWords = validWords/sizeof(int); /* convert from bytes to words */
PIP_setWriterSize(pip, validWords);
PIP_put(pip);
/* We know a buffer just came out of the hw queue, so try to
put another in. */
PIP_LIO_rxPrime(chan, pip);
}
}
/*
* ======= DSS_rxPrime ========
* This must be the notifyWriter function of the rxPips
*/
void
PIP_LIO_rxPrime(int chan, PIP_Obj *pip)
{
static int nested = 0;
if (nested) return;
nested = 1;
/* if there is a frame on the rx queue */
/* PENDING: There is a race condition between !isFull and nested =
0. If the callback occurs after isFull returns false but before
nested = 0 then a new buffer will not be put into the hw queue
and the system will deadlock. We need to turn off interrupts
here. SWI callbacks would have made this easier I think. We could
replace HWI_disable with drv->disable perhaps. */
HWI_disable();
if (drv->isEmpty(chan) && PIP_getWriterNumFrames(pip) > 0) {
HWI_enable();
PIP_alloc(pip);
drv->setBuf(chan,
PIP_getWriterAddr(pip),
PIP_getWriterSize(pip)*sizeof(int)); /* words to bytes */
} else {
HWI_enable();
}
nested = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -