DM&P DOS AccTimer Library Reference

2002/08/02 Version 0.10

AccTimer

AccTimer library is for our SBC user to get a precise mini-second timer. It is simple and easy to use.

If you have any problem, mail to soc@dmp.com.tw please.

Example

The sample code is from demo.c of AccTimer library.


#include "acctimer.h"
#include <time.h>
#include <stdio.h>

void main()
{
  int     i;
  long    t1, t2;
  clock_t clk;

  printf("\nDM&P DOS AccTimer Library Version %s\n\n",AccTimer_Version());
  if(AccTimer_Init()==0)
  {
    printf("Unable to initialize AccTimer library.\n");
    return;
  }


  printf("Run a loop and get loop time: ");
  t1 = AccTimer_Read();
  for(i = 0; i < 1000; i++);
  t2 = AccTimer_Read();
  printf("Timer = %ld, time = %ldus.\n", t2 - t1, (t2 - t1) * 1000L / 1193L);

  printf("Detect system ticks (18.2Hz), it will be 1-55ms: ");
  t1 = AccTimer_Read();
  clk = clock();
  while(clock() == clk);
  printf("Time = %ld ms\n", AccTimer_GetTime(t1));

  printf("Set time out to 3 seconds and do user's job:\n");
  t2 = AccTimer_SetTime(3000);
  t1 = AccTimer_Read();
  while(!AccTimer_IsTimeOut(t2))
  {
    /* do you job here */
    printf("\rTime = %4ld ms", AccTimer_GetTime(t1));
  }
  printf(", Time Out!\n");

  AccTimer_Uninit();
}

You will get those messages when you run our demo.exe:


C:\DMP\AccTimer>demo

DM&P DOS AccTimer Library Version 0.10

Run a loop and get loop time: Timer = 468, time = 392us.
Detect system ticks (18.2Hz), it will be 1-55ms: Time = 53 ms
Set time out to 3 seconds and do user's job:
Time = 2999 ms, Time Out!

C:\DMP\AccTimer>

Function Reference



char *AccTimer_Version();

Description: Get library version string.
Arguments:
Return Library version.
Example:

/* Show AccTimer version. */
printf("DM&P DOS AccTimer Library Version %s\n",AccTimer_Version());
	


int AccTimer_Init();

Description: Initialize AccTimer library.
Arguments:
Return 0 is error, non-zero is okay.
Example:

if(!AccTimer_Init())
  printf("Unable to initialize AccTimer library.\n");
	

void AccTimer_Uninit();

Description: Close AccTimer library.
Arguments:
N/A
Example:

AccTimer_Uninit();
	

void AccTimer_Read();

Description: Read timer ticks.
Arguments:
Return 0 is error, non-zero is okay.
Example:

printf("Timer ticks = %ld\n",AccTimer_Read());
	

long AccTimer_SetTime(long lTime);

Description: Set timeout in mini-second.
Arguments:
Return Timeout ticks.
Example:

printf("Set time out to 3 seconds and do user's job:\n");
t = AccTimer_SetTime(3000);
while(!AccTimer_IsTimeOut(t))
{
  /* do you job here */
}
printf("Time Out!\n");
	

long AccTimer_GetTime(long lTime);

Description: Get time in mini-second from two clock ticks.
Arguments:
lTime Timer tick.
Return Time in mini-second.
Example:

t1 = AccTimer_Read();
delay(100);
printf("%ld ms passed\n", AccTimer_GetTime(t1));
	

int AccTimer_IsTimeOut(long lTime);

Description: Check the timer tick from AccTimer_SetTime() is timeout or not.
Arguments:
lTime Timer tick.
Return 0 is false, non-zero true okay.
Example:

printf("Set time out to 3 seconds and do user's job:\n");
t = AccTimer_SetTime(3000);
while(!AccTimer_IsTimeOut(t))
{
  /* do you job here */
}
printf("Time Out!\n");
	

DMP Electronics Inc. All rights reserved. Email us: info@dmp.com.tw