/*********************************************************************
Name: v1718.h
Created by: Jimmy Ngai
Contents: V1718 VME-USB2.0 bridge include
$Id: $
*********************************************************************/
#ifndef V1718_INCLUDE_H
#define V1718_INCLUDE_H
#include <stdio.h>
#include <string.h>
#include "mvmestd.h"
#ifdef __cplusplus
extern "C" {
#endif
#define V1718_STATUS_RO (DWORD) (0x0000)
#define V1718_VME_CTRL_RW (DWORD) (0x0001)
#define V1718_FW_REV_RO (DWORD) (0x0002)
#define V1718_FW_DWNLD_RW (DWORD) (0x0003)
#define V1718_FL_ENA_RW (DWORD) (0x0004)
#define V1718_IRQ_STAT_RO (DWORD) (0x0005)
#define V1718_IN_REG_RW (DWORD) (0x0008)
#define V1718_OUT_REG_S_RW (DWORD) (0x000A)
#define V1718_IN_MUX_S_RW (DWORD) (0x000B)
#define V1718_OUT_MUX_S_RW (DWORD) (0x000C)
#define V1718_LED_POL_S_RW (DWORD) (0x000D)
#define V1718_OUT_REG_C_WO (DWORD) (0x0010)
#define V1718_IN_MUX_C_WO (DWORD) (0x0011)
#define V1718_OUT_MAX_C_WO (DWORD) (0x0012)
#define V1718_LED_POL_C_WO (DWORD) (0x0013)
#define V1718_PULSEA_0_RW (DWORD) (0x0016)
#define V1718_PULSEA_1_RW (DWORD) (0x0017)
#define V1718_PULSEB_0_RW (DWORD) (0x0019)
#define V1718_PULSEB_1_RW (DWORD) (0x001A)
#define V1718_SCALER0_RW (DWORD) (0x001C)
#define V1718_SCALER1_RO (DWORD) (0x001D)
#define V1718_DISP_ADL_RO (DWORD) (0x0020)
#define V1718_DISP_ADH_RO (DWORD) (0x0021)
#define V1718_DISP_DTL_RO (DWORD) (0x0022)
#define V1718_DISP_DTH_RO (DWORD) (0x0023)
#define V1718_DISP_PC1_RO (DWORD) (0x0024)
#define V1718_DISP_PC2_RO (DWORD) (0x0025)
#define V1718_LM_ADL_RW (DWORD) (0x0028)
#define V1718_LM_ADH_RW (DWORD) (0x0029)
#define V1718_LM_C_RW (DWORD) (0x002C)
WORD v1718_Read16(MVME_INTERFACE *mvme, DWORD base, int offset);
void v1718_Write16(MVME_INTERFACE *mvme, DWORD base, int offset, WORD value);
DWORD v1718_Read32(MVME_INTERFACE *mvme, DWORD base, int offset);
void v1718_Write32(MVME_INTERFACE *mvme, DWORD base, int offset, DWORD value);
void v1718_MultiRead(MVME_INTERFACE *mvme, DWORD *addrs, DWORD *value, int ncycle, int *am, int *dmode);
void v1718_MultiWrite(MVME_INTERFACE *mvme, DWORD *addrs, DWORD *value, int ncycle, int *am, int *dmode);
void v1718_MultiRead16(MVME_INTERFACE *mvme, DWORD *addrs, WORD *value, int ncycle);
void v1718_MultiWrite16(MVME_INTERFACE *mvme, DWORD *addrs, WORD *value, int ncycle);
void v1718_MultiRead32(MVME_INTERFACE *mvme, DWORD *addrs, DWORD *value, int ncycle);
void v1718_MultiWrite32(MVME_INTERFACE *mvme, DWORD *addrs, DWORD *value, int ncycle);
void v1718_PulserConfSet(MVME_INTERFACE *mvme, WORD pulser, DWORD period, DWORD width, WORD pulseNo);
void v1718_PulserStart(MVME_INTERFACE *mvme, WORD pulser);
void v1718_PulserStop(MVME_INTERFACE *mvme, WORD pulser);
enum v1718_PulserSelect {
v1718_pulserA=0x0,
v1718_pulserB=0x1,
};
#ifdef __cplusplus
}
#endif
#endif // V1718_INCLUDE_H
/* emacs
* Local Variables:
* mode:C
* mode:font-lock
* tab-width: 8
* c-basic-offset: 2
* End:
*/
|
/********************************************************************
Name: v1718.c
Created by: Jimmy Ngai
Contents: Midas VME standard (MVMESTD) layer for CAEN V1718
VME-USB2.0 Bridge using CAENVMElib Linux library
$Id: $
\********************************************************************/
#ifdef __linux__
#ifndef OS_LINUX
#define OS_LINUX
#endif
#endif
#ifdef OS_LINUX
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "CAENVMElib.h"
#endif // OS_LINUX
#include "v1718.h"
/*------------------------------------------------------------------*/
/********************************************************************\
MIDAS VME standard (MVMESTD) functions
\********************************************************************/
int mvme_open(MVME_INTERFACE **vme, int idx)
{
*vme = (MVME_INTERFACE *) malloc(sizeof(MVME_INTERFACE));
if (*vme == NULL)
return MVME_NO_MEM;
memset(*vme, 0, sizeof(MVME_INTERFACE));
/* open VME */
if (CAENVME_Init(cvV1718, 0, idx, &(*vme)->handle) != cvSuccess)
return MVME_NO_INTERFACE;
/* default values */
(*vme)->am = MVME_AM_DEFAULT;
(*vme)->dmode = MVME_DMODE_D32;
(*vme)->blt_mode = MVME_BLT_NONE;
(*vme)->table = NULL; // not used
return MVME_SUCCESS;
}
/*------------------------------------------------------------------*/
int mvme_close(MVME_INTERFACE *vme)
{
CAENVME_End(vme->handle);
free(vme);
return MVME_SUCCESS;
}
/*------------------------------------------------------------------*/
int mvme_sysreset(MVME_INTERFACE *vme)
{
CAENVME_SystemReset(vme->handle);
return MVME_SUCCESS;
}
/*------------------------------------------------------------------*/
int mvme_write(MVME_INTERFACE *vme, mvme_addr_t vme_addr, void *src, mvme_size_t n_bytes)
{
mvme_size_t i;
int status=0, n;
int hvme;
hvme = vme->handle;
n = 0;
/* D8 */
if (vme->dmode == MVME_DMODE_D8) {
for (i=0 ; i<n_bytes ; i++)
status = CAENVME_WriteCycle(hvme, vme_addr, src+i, vme->am, cvD8);
n = n_bytes;
/* D16 */
} else if (vme->dmode == MVME_DMODE_D16) {
/* normal I/O */
if (vme->blt_mode == MVME_BLT_NONE) {
for (i=0 ; i<(n_bytes>>1) ; i++)
status = CAENVME_WriteCycle(hvme, vme_addr, src+(i<<1), vme->am, cvD16);
n = n_bytes;
/* FIFO BLT */
} else if ((vme->blt_mode == MVME_BLT_BLT32FIFO) || (vme->blt_mode == MVME_BLT_MBLT64FIFO))
status = CAENVME_FIFOBLTWriteCycle(hvme, vme_addr, src, n_bytes, vme->am, cvD16, &n);
/* BLT */
else
status = CAENVME_BLTWriteCycle(hvme, vme_addr, src, n_bytes, vme->am, cvD16, &n);
/* D32 */
} else if (vme->dmode == MVME_DMODE_D32) {
/* normal I/O */
if (vme->blt_mode == MVME_BLT_NONE) {
for (i=0 ; i<(n_bytes>>2) ; i++)
status = CAENVME_WriteCycle(hvme, vme_addr, src+(i<<2), vme->am, cvD32);
n = n_bytes;
/* FIFO BLT */
} else if (vme->blt_mode == MVME_BLT_BLT32FIFO)
status = CAENVME_FIFOBLTWriteCycle(hvme, vme_addr, src, n_bytes, vme->am, cvD32, &n);
/* BLT */
else
status = CAENVME_BLTWriteCycle(hvme, vme_addr, src, n_bytes, vme->am, cvD32, &n);
/* D64 */
} else if (vme->dmode == MVME_DMODE_D64) {
/* FIFO MBLT */
if (vme->blt_mode == MVME_BLT_MBLT64FIFO)
status = CAENVME_FIFOMBLTWriteCycle(hvme, vme_addr, src, n_bytes, vme->am, &n);
/* MBLT */
else
status = CAENVME_MBLTWriteCycle(hvme, vme_addr, src, n_bytes, vme->am, &n);
}
if (status != cvSuccess)
n = 0;
return n;
}
/*------------------------------------------------------------------*/
int mvme_write_value(MVME_INTERFACE *vme, mvme_addr_t vme_addr, unsigned int value)
{
int status=0, n;
int hvme;
hvme = vme->handle;
if (vme->dmode == MVME_DMODE_D8)
n = 1;
else if (vme->dmode == MVME_DMODE_D16)
n = 2;
else
n = 4;
/* D8 */
if (vme->dmode == MVME_DMODE_D8)
status = CAENVME_WriteCycle(hvme, vme_addr, &value, vme->am, cvD8);
/* D16 */
else if (vme->dmode == MVME_DMODE_D16)
status = CAENVME_WriteCycle(hvme, vme_addr, &value, vme->am, cvD16);
/* D32 */
else if (vme->dmode == MVME_DMODE_D32)
status = CAENVME_WriteCycle(hvme, vme_addr, &value, vme->am, cvD32);
if (status != cvSuccess)
n = 0;
return n;
}
/*------------------------------------------------------------------*/
int mvme_read(MVME_INTERFACE *vme, void *dst, mvme_addr_t vme_addr, mvme_size_t n_bytes)
{
mvme_size_t i;
int status=0, n;
int hvme;
hvme = vme->handle;
n = 0;
/* D8 */
if ((vme->dmode == MVME_DMODE_D8) || (vme->blt_mode == MVME_BLT_NONE)) {
for (i=0 ; i<n_bytes ; i++)
status = CAENVME_ReadCycle(hvme, vme_addr, dst+i, vme->am, cvD8);
n = n_bytes;
/* D16 */
} else if (vme->dmode == MVME_DMODE_D16) {
/* normal I/O */
if (vme->blt_mode == MVME_BLT_NONE) {
for (i=0 ; i<(n_bytes>>1) ; i++)
status = CAENVME_ReadCycle(hvme, vme_addr, dst+(i<<1), vme->am, cvD16);
n = n_bytes;
/* FIFO BLT */
} else if ((vme->blt_mode == MVME_BLT_BLT32FIFO) || (vme->blt_mode == MVME_BLT_MBLT64FIFO))
status = CAENVME_FIFOBLTReadCycle(hvme, vme_addr, dst, n_bytes, vme->am, cvD16, &n);
/* BLT */
else
status = CAENVME_BLTReadCycle(hvme, vme_addr, dst, n_bytes, vme->am, cvD16, &n);
/* D32 */
} else if (vme->dmode == MVME_DMODE_D32) {
/* normal I/O */
if (vme->blt_mode == MVME_BLT_NONE) {
for (i=0 ; i<(n_bytes>>2) ; i++)
status = CAENVME_ReadCycle(hvme, vme_addr, dst+(i<<2), vme->am, cvD32);
n = n_bytes;
/* FIFO BLT */
} else if (vme->blt_mode == MVME_BLT_BLT32FIFO)
status = CAENVME_FIFOBLTReadCycle(hvme, vme_addr, dst, n_bytes, vme->am, cvD32, &n);
/* BLT */
else
status = CAENVME_BLTReadCycle(hvme, vme_addr, dst, n_bytes, vme->am, cvD32, &n);
/* D64 */
} else if (vme->dmode == MVME_DMODE_D64) {
/* FIFO MBLT */
if (vme->blt_mode == MVME_BLT_MBLT64FIFO)
status = CAENVME_FIFOMBLTReadCycle(hvme, vme_addr, dst, n_bytes, vme->am, &n);
/* MBLT */
else
status = CAENVME_MBLTReadCycle(hvme, vme_addr, dst, n_bytes, vme->am, &n);
}
if ((status != cvSuccess) && (status != cvBusError))
n = 0;
return n;
}
/*------------------------------------------------------------------*/
unsigned int mvme_read_value(MVME_INTERFACE *vme, mvme_addr_t vme_addr)
{
unsigned int data;
int status=0;
int hvme;
hvme = vme->handle;
data = 0;
/* D8 */
if (vme->dmode == MVME_DMODE_D8)
status = CAENVME_ReadCycle(hvme, vme_addr, &data, vme->am, cvD8);
/* D16 */
else if (vme->dmode == MVME_DMODE_D16)
status = CAENVME_ReadCycle(hvme, vme_addr, &data, vme->am, cvD16);
/* D32 */
else if (vme->dmode == MVME_DMODE_D32)
status = CAENVME_ReadCycle(hvme, vme_addr, &data, vme->am, cvD32);
return data;
}
/*------------------------------------------------------------------*/
int mvme_set_am(MVME_INTERFACE *vme, int am)
{
vme->am = am;
return MVME_SUCCESS;
}
/*------------------------------------------------------------------*/
int mvme_get_am(MVME_INTERFACE *vme, int *am)
{
*am = vme->am;
return MVME_SUCCESS;
}
/*------------------------------------------------------------------*/
int mvme_set_dmode(MVME_INTERFACE *vme, int dmode)
{
vme->dmode = dmode;
return MVME_SUCCESS;
}
/*------------------------------------------------------------------*/
int mvme_get_dmode(MVME_INTERFACE *vme, int *dmode)
{
*dmode = vme->dmode;
return MVME_SUCCESS;
}
/*------------------------------------------------------------------*/
int mvme_set_blt(MVME_INTERFACE *vme, int mode)
{
vme->blt_mode = mode;
return MVME_SUCCESS;
}
/*------------------------------------------------------------------*/
int mvme_get_blt(MVME_INTERFACE *vme, int *mode)
{
*mode = vme->blt_mode;
return MVME_SUCCESS;
}
/*------------------------------------------------------------------*/
... 326 more lines ...
|