📄 pintest.c
字号:
/*
* Copyright (c) 1995-2000 by TriMedia Technologies.
*
* +------------------------------------------------------------------+
* | 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 : pintest.c 1.18
*
* Last update : 17:27:01 - 00/11/09
*
* Description :
*
* A test and demonstration for the TriMedia Interrupt Pin Library.
* TM1000 has four general purpose I/O pins known as IntA through IntD.
* In accordance with the PCI spec, intA is used as a PCI interrupt.
* The other three pins can be used as general purpos I/O with the added
* capability of being interrupt sources to TM1000.
* See the data book, chapter 10.6.16 for more specific information.
* Some more information is included in chapter 3, where the interrupt
* system is described.
*
* The IREF boards (up to and including rev 2.1) mistakenly hook intB, C and D
* to the PCI bus. This makes this test rather dangerous.
* An ECO described elsewhere suggests cutting the trace which connects these
* pins to the PCI bus. In order for this test to work, the traces must be cut
* and pullup resistors must be installed.
*
* Revision :
* Built for the TCS 1.1f release
*
*
*/
#include <stdio.h>
#include <tm1/tmIntPins.h>
#include <assert.h>
#include <tm1/tmHelp.h>
/*
* Macro to do compact error checking on device library calls:
*/
#define E(x) if ((x) != 0) { fprintf(stderr, "Error\n"); exit(-1); }
/*
* Interrupt handlers to be installed for interrupt pins B, C and D; they
* increment counters to let main() see that they occurred:
*/
/* DO NOT USE pin A for tests:
* Pin A is assigned to be the PCI interrupt.
* Use pin A only if you mean to interrupt the host!
*/
static volatile UInt b_count = 0;
static volatile UInt c_count = 0;
static volatile UInt d_count = 0;
#if 0
static void
HandlerB()
{
#pragma TCS_handler
E(pinSet(pinPin_B, False));
b_count++;
}
static void
HandlerC()
{
#pragma TCS_handler
E(pinSet(pinPin_C, False));
c_count++;
}
static void
HandlerD()
{
#pragma TCS_handler
E(pinSet(pinPin_D, False));
d_count++;
}
#endif
/*
* A routine to check the values of pin A and B
* against expected values; we read the pin
* values back via software, but the actual hardware
* pins should have the same values:
*/
void
checkpins(Bool v_b, Bool v_c, Bool v_d, Int line)
{
Bool value_b, value_c, value_d;
E(pinGet(pinPin_B, &value_b));
E(pinGet(pinPin_C, &value_c));
E(pinGet(pinPin_D, &value_d));
if (value_b && !v_b || v_b && !value_b) {
fprintf(stderr, "IntB value error at line %d\n", line);
exit(-1);
}
if (value_c && !v_c || v_c && !value_c) {
fprintf(stderr, "IntC value error at line %d\n", line);
exit(-1);
}
if (value_d && !v_d || v_d && !value_d) {
fprintf(stderr, "IntD value error at line %d\n", line);
exit(-1);
}
}
main()
{
pinInstanceSetup_t setup;
char ins[80];
printf("\nInterrupt Pin Test, V 1.0:\n");
printf("Running on "); tmHelpReportSystem(stdout);
printf("A test and demonstration of the use of the TriMedia Interrupt Pins.\n");
printf("See the data book, chapter 10.6.16 for more information.\n");
printf("\nWARNING!\n");
printf("IREF boards (up to and including rev 2.1) mistakenly hook intB, C and D\n");
printf("to the PCI bus. This makes this test rather dangerous.\n");
printf("An ECO described elsewhere suggests cutting the trace which connects these\n");
printf("pins to the PCI bus. In order for this test to work, the traces must be cut\n");
printf("and pullup resistors must be installed.\n");
printf("\nPress return to continue, or control-C to exit\n");
gets(ins);
/*----------------------------------------------------*/
/*
* Open the pins, and set them up; No handlers yet:
*/
E(pinOpen(pinPin_B));
E(pinOpen(pinPin_C));
E(pinOpen(pinPin_D));
setup.openCollector = True;
setup.handler = Null;
setup.levelTriggered = True;
setup.priority = intPRIO_0;
E(pinInstanceSetup(pinPin_B, &setup));
E(pinInstanceSetup(pinPin_C, &setup));
E(pinInstanceSetup(pinPin_D, &setup));
/*----------------------------------------------------*/
/*
* Toggle the pin values via software, and check proper results by
* reading them back:
*/
printf("Setting all pins low and checking...\n");
E(pinSet(pinPin_B, False));
E(pinSet(pinPin_C, False));
E(pinSet(pinPin_D, False));
checkpins(False, False, False, __LINE__);
printf("Setting each pin high and then low and checking...\n");
E(pinSet(pinPin_B, True));
checkpins(True, False, False, __LINE__);
E(pinSet(pinPin_C, True));
checkpins(True, True, False, __LINE__);
E(pinSet(pinPin_D, True));
checkpins(True, True, True, __LINE__);
E(pinSet(pinPin_B, False));
checkpins(False, True, True, __LINE__);
E(pinSet(pinPin_C, False));
checkpins(False, False, True, __LINE__);
E(pinSet(pinPin_D, False));
checkpins(False, False, False, __LINE__);
/*----------------------------------------------------*/
#if 0
/*
* Install handlers, and await the first 10 events on these pins;
* unfortunately, the pin interrupts cannot be raised from software,
* so that this test has to be performed by really toggling the
* interrupt pins:
*/
setup.handler = HandlerB;
E(pinInstanceSetup(pinPin_B, &setup));
setup.handler = HandlerC;
E(pinInstanceSetup(pinPin_C, &setup));
setup.handler = HandlerD;
E(pinInstanceSetup(pinPin_D, &setup));
#endif
/*----------------------------------------------------*/
/*
* Close the pins; this deinstalls the handlers, frees the
* interrupts, and resets the pin outputs to zero:
*/
E(pinClose(pinPin_B));
E(pinClose(pinPin_C));
E(pinClose(pinPin_D));
/*----------------------------------------------------*/
printf("\nFinished:\n The TM CPU was able to read and write IntB, IntC and IntD.\n");
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -