Skip to content

Instantly share code, notes, and snippets.

@veprbl
Last active August 29, 2015 14:24
Show Gist options
  • Save veprbl/db925a6108fcaddf5d98 to your computer and use it in GitHub Desktop.
Save veprbl/db925a6108fcaddf5d98 to your computer and use it in GitHub Desktop.
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#define VME_A32 0x4
#define VME_D32 0x4
#define VME_USER 0x2000
#define VME_DATA 0x8000
#define VME_SCT 0x1
struct vme_master {
int enable;
unsigned long long vme_addr;
unsigned long long size;
uint32_t aspace;
uint32_t cycle;
uint32_t dwidth;
} __attribute__((packed));
#define VME_IOC_MAGIC 0xAE
#define VME_SET_MASTER _IOW(VME_IOC_MAGIC, 4, struct vme_master)
int main(void)
{
struct vme_master master;
int fd, rc;
fd = open("/dev/bus/vme/m2", O_RDWR);
if (fd == -1) {
perror("FATAL - can not open VME");
return EXIT_FAILURE;
}
master.enable = 1;
master.vme_addr = 0xc0000000;
master.size = 0x20000;
master.aspace = VME_A32;
master.cycle = VME_USER | VME_DATA | VME_SCT;
master.dwidth = VME_D32;
rc = ioctl(fd, VME_SET_MASTER, &master);
if (rc != 0) {
perror("FATAL - can not setup VME window");
return EXIT_FAILURE;
}
#define AM16_REG_WRITE(offset, value) \
do { \
uint32_t _value = htonl(value); \
int rc = pwrite(fd, &_value, sizeof(_value), offset); \
if (rc < sizeof(_value)) \
perror("write"); \
} while(0)
AM16_REG_WRITE(0x104, 0x1); // Do master reset
AM16_REG_WRITE(0x100, 0x1); // Enable board
AM16_REG_WRITE(0x8, 0x6b01); // Use interrupt vector 0x6b, level 1
AM16_REG_WRITE(0x104, 0x4); // Fire software trigger
printf("Fired a VME interrupt. Sleeping...\n");
sleep(5);
printf("Disabling the board\n");
AM16_REG_WRITE(0x100, 0x0); // Disable board
AM16_REG_WRITE(0x104, 0x1); // Do master reset
close(fd);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment