📄 timtest.c
字号:
/*
* Copyright (c) 1995,1996,1997 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 : timtest.c 1.9
*
* Last update : 17:33:27 - 00/11/09
*
* Description :
*
* A test and demonstration for the TriMedia Timer Library.
*
* This example demonstrates how to generate a periodic interrupt.
*
* Revision :
* Built for the TCS 1.1f release
*
*
*/
#include <stdio.h>
#include <tm1/tmTimers.h>
#include <tm1/tmHelp.h>
/*
* This handler increments a counter to flag to main() that the interrupt
* has occurred:
*/
volatile UInt counter;
static void
Handler()
{
#pragma TCS_handler
counter++;
}
/*
* Macro to do compact error checking on device library calls:
*/
#define E(x) if ((x) != 0) { fprintf(stderr, "Error\n"); exit(-1); }
main()
{
Int timer;
timInstanceSetup_t setup;
UInt32 cycles;
UInt32 one_s_in_nano_seconds = 1000000000;
UInt i;
printf("Timer test\n");
printf("Running on "); tmHelpReportSystem(stdout);
/*
* Determine how many cycles fit in one second; this function
* autamatically takes the current processor frequency into account:
*/
timToCycles(one_s_in_nano_seconds, &cycles);
/*
* Open a timer for interrupt generation:
*/
E( timOpen(&timer) );
/*
* And set it up:
*/
setup.source = timCLOCK;
setup.prescale = 1;
setup.modulus = cycles;
setup.handler = Handler;
setup.priority = intPRIO_4;
setup.running = True;
E(timInstanceSetup(timer, &setup));
/*
* After that, wait for the first 10 events; the printed times (in
* us) should be spaced approximately 1 second apart:
*/
for (i = 0; i < 10; i++) {
UInt c = counter;
while (c == counter) {};
printf(" Time = %10d\n", clock());
}
/*
* Close the timer; this also deinstalls the timer interrupt handler:
*/
E( timClose(timer) );
printf("Finished\n");
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -