Implement simulated counter hardware and more string literal changes
r3637 | dcl | 2012-07-11 15:08:50 +1000 (Wed, 11 Jul 2012) | 1 line
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifndef SIMULATE_HARDWARE
|
||||
#define DEFAULT_DEVICE "dev1/ctr0"
|
||||
|
||||
#ifdef REGISTER_LEVEL_PROGRAMMING
|
||||
@@ -888,3 +889,111 @@ void initChan(pHWARE hware)
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
#else /* SIMULATE_HARDWARE */
|
||||
#include <sys/time.h>
|
||||
typedef struct device_private_t
|
||||
{
|
||||
/** extended 64-bit counter value */
|
||||
unsigned long long count64;
|
||||
/* TODO time and count */
|
||||
int source; /* count rate to be simulated */
|
||||
struct timeval last_time;
|
||||
} DEVICE_PRIVATE;
|
||||
|
||||
int hware_ctor(const char* device_name, pHWARE* ptr)
|
||||
{
|
||||
pHWARE hware = NULL;
|
||||
|
||||
hware = (DEVICE_PRIVATE*) malloc(sizeof(DEVICE_PRIVATE));
|
||||
*ptr = hware;
|
||||
memset(hware, 0, sizeof(DEVICE_PRIVATE));
|
||||
|
||||
/* TODO time and count */
|
||||
hware->source = 1000; /* initial count rate */
|
||||
gettimeofday(&hware->last_time, NULL);
|
||||
#if 0 /* DEBUG */
|
||||
printf("hware_ctor: %s at %p\n", device_name, *ptr);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hware_read(pHWARE hware, unsigned long long* value)
|
||||
{
|
||||
struct timeval this_time;
|
||||
double delta_time;
|
||||
long long delta_count = 0;
|
||||
/* TODO time and count */
|
||||
gettimeofday(&this_time, NULL);
|
||||
delta_time = (this_time.tv_sec + 1e-6 * this_time.tv_usec) -
|
||||
(hware->last_time.tv_sec + 1e-6 * hware->last_time.tv_usec);
|
||||
delta_count = (long long)(0.5 + delta_time * hware->source);
|
||||
hware->count64 += delta_count;
|
||||
hware->last_time = this_time;
|
||||
*value = hware->count64;
|
||||
return 0;
|
||||
}
|
||||
int hware_source(pHWARE hware, int value)
|
||||
{
|
||||
#if 0 /* DEBUG */
|
||||
int old_source = hware->source;
|
||||
#endif
|
||||
switch (value)
|
||||
{
|
||||
case 0:
|
||||
hware->source = 10000;
|
||||
break;
|
||||
case 1:
|
||||
hware->source = 20000000;
|
||||
break;
|
||||
case 2:
|
||||
hware->source = 100000;
|
||||
break;
|
||||
case 3:
|
||||
hware->source = 80000000;
|
||||
break;
|
||||
default:
|
||||
if (value < 1000)
|
||||
hware->source = 1000;
|
||||
else
|
||||
hware->source = value;
|
||||
break;
|
||||
}
|
||||
#if 0 /* DEBUG */
|
||||
printf("hware_source: %d moves %d to %d at %p\n", value, old_source, hware->source, hware);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
int hware_filter(pHWARE hware, int value)
|
||||
{
|
||||
/* nothing to do */
|
||||
return 0;
|
||||
}
|
||||
int hware_outp(pHWARE hware, int value)
|
||||
{
|
||||
/* nothing to do */
|
||||
return 0;
|
||||
}
|
||||
void hware_sync(pHWARE hware, bool external)
|
||||
{
|
||||
/* nothing to do */
|
||||
}
|
||||
int hware_dtor(pHWARE* ptr)
|
||||
{
|
||||
if (ptr && *ptr)
|
||||
{
|
||||
/* release the storage */
|
||||
free(*ptr);
|
||||
*ptr = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
bool hware_failed(int error)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
void hware_errmsg(char* buff, int len)
|
||||
{
|
||||
if (buff)
|
||||
strncpy(buff, "Simulated error message", len);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user