/* Example of timer0 channel 0 counter mode.

   Author: Winson Chen
*/

/* File level history (record changes for this file here.)

   This example for test timer0 channel 0 counter mode.

   v 0.0.0 2 Apr 2025 by Winson Chen
     create */

#include "pcidio.h"

int main()
{
  int fd, wChannel = 0, wMode = 3, wDelayMs = 20;
  char *dev_file;
  DWORD dwCount;

  dev_file = "/dev/ixpci1";

  /* open device file */
  fd = PCIDA_Open(dev_file);

  if (fd < 0){
    printf("Can't open device\n");
    return FAILURE;
  }

  /* init device */
  if (PCIDA_DriverInit(fd)) return FAILURE;

  PCIFC16_SetChannelMode(fd, wChannel, wMode, wDelayMs);

  //while (getchar() != 27){
  while (1){
    PCIFC16_ReadCounter(fd, wChannel, &dwCount);
    printf("Read Timer0 CH%d counter =  %d\n", wChannel, dwCount);
    sleep(2);
  }

  /* close device */
  PCIDA_Close(fd);
  puts("End of program");
  return SUCCESS;
}

