/*
* send_bg_config() sends configuration to the Burst Generator using
* port /dev/lp0
*
* delay, length in clock cycles
*
* trig, div boolean (enable/disable) trigger, frequency division
*
* freq frequency (in MHz)
*/
static int send_bg_config(unsigned int delay, unsigned int length,
int trig, int div, int freq)
{
int fd;
unsigned char tab[5];
delay += 64; /* correction for ``64 problem'' */
length += 64;
tab[0] = delay & 0xff; /* LSB delay */
tab[1] = (delay >> 8) & 0x0f; /* MSB delay */
tab[2] = length & 0xff; /* LSB length */
tab[3] = (length >> 8) & 0x0f; /* MSB length */
tab[4] = freq / 25 - 2; /* Clock frequency modifier */
tab[4] |= trig ? 0x40 : 0; /* Trigger enable */
tab[4] |= div ? 0x80 : 0; /* Frequency selector */
if ((fd = open("/dev/lp0", O_WRONLY)) == -1)
return -1;
if (write(fd, tab, 5) == -1) {
close(fd);
return -1;
}
close(fd);
return 0;
}