int writeRAM(uint32_t start, unsigned char *buf, uint32_t len){ cselect(1); spi(0x02); // write // Send address, high byte first spi(start >> 16); spi(start >> 8); spi(start); for(int n=0; n<len; n++){ spi(buf[n]); }; cselect(0); return len; }
int readRAM(uint32_t start, unsigned char *buf, uint32_t len){ cselect(1); spi(0x03); // read // Send address, high byte first spi(start >> 16); spi(start >> 8); spi(start); for(int n=0; n<len; n++){ buf[n] = spi(0); }; cselect(0); return len; }
/*--General functions--------------------------------------------*/ INLINE void cam_crate_zinit(const int c) { int stat; cselect(c); if ((stat = ioctl(fd, CAMAC_ZCYCLE)) != 0) perror(fname); }
/*--General functions--------------------------------------------*/ INLINE void cam_inhibit_clear(const int c) { int stat; cselect(c); if ((stat = ioctl(fd, CAMAC_CLRINH)) != 0) perror(fname); }
/*--General functions--------------------------------------------*/ INLINE void cam_lam_clear(const int c, const int n) { int stat; camac_t c_t; cselect(c); c_t.n = n; if ((stat = ioctl(fd, CAMAC_LAM_CLEAR, &c_t)) != 0) { perror(fname); } }
/*--General functions--------------------------------------------*/ INLINE void cam_lam_read(const int c, DWORD * lam) { int stat; camac_t c_t; cselect(c); if ((stat = ioctl(fd, CAMAC_LAM_ENABLE, &c_t)) != 0) { perror(fname); } *lam = c_t.d; }
/*--General functions--------------------------------------------*/ INLINE void cam_lam_enable(const int c, const int n) { int stat; camac_t c_t; cselect(c); c_t.n = n; if ((stat = ioctl(fd, CAMAC_LAM_ENABLE, &c_t)) != 0) { perror(fname); } }
/*--General functions--------------------------------------------*/ INLINE void cam_lam_disable(const int c, const int n) { int stat; camac_t c_t; /* see comment in cam_lam_enable */ cselect(c); c_t.n = n; if ((stat = ioctl(fd, CAMAC_LAM_DISABLE, &c_t)) != 0) { perror(fname); } }
/*--output-------------------------------------------------------*/ INLINE void cam24o(const int c, const int n, const int a, const int f, DWORD d) { int stat; camac_t c_t; cselect(c); c_t.n = n; c_t.a = a; c_t.f = f; c_t.d = d; if ((stat = ioctl(fd, CAMAC_EXEC, &c_t)) != 0) { perror(fname); } }
/*--input--------------------------------------------------------*/ INLINE void cam24i_q(const int c, const int n, const int a, const int f, DWORD * d, int *x, int *q) { int stat; camac_t c_t; cselect(c); c_t.n = n; c_t.a = a; c_t.f = f; if ((stat = ioctl(fd, CAMAC_EXEC, &c_t)) != 0) { perror(fname); } *d = c_t.d; *x = c_t.x; *q = c_t.q; }
/*--General functions--------------------------------------------*/ INLINE int cam_init(void) { int stat; if (fd >= 0) { eprintf("copen(): `%s' already open: use cclose() to close\n", lx_filename); return -1; } fname = strdup(lx_filename); if ((fd = open(fname, O_RDWR)) < 0) { perror(fname); return fd; } if ((stat = ioctl(fd, CAMAC_INIT)) != 0) perror(fname); if (stat != 0) return -1; stat = cselect(0); printf("cselect for crate 0:%x\n", stat); return SUCCESS; }