Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
FMC DEL 1ns 4cha
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
FMC DEL 1ns 4cha
Commits
b7f3c485
Commit
b7f3c485
authored
Dec 14, 2012
by
Tomasz Wlostowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
software/tests/gs_logger: crude VME version (needs cleanup & some fixes)
parent
eae0d98c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
2187 additions
and
204 deletions
+2187
-204
rawrabbit.h
software/include/rawrabbit.h
+0
-173
rr_io.h
software/include/rr_io.h
+0
-15
Makefile
software/lib/Makefile
+11
-11
fdelay_vme.c
software/lib/fdelay_vme.c
+89
-0
.gitignore
software/lib/sveclib/.gitignore
+4
-0
Makefile
software/lib/sveclib/Makefile
+21
-0
README
software/lib/sveclib/README
+24
-0
libvmebus.c
software/lib/sveclib/libvmebus.c
+531
-0
libvmebus.h
software/lib/sveclib/libvmebus.h
+76
-0
svec-cl.c
software/lib/sveclib/svec-cl.c
+63
-0
svec-fwloader.c
software/lib/sveclib/svec-fwloader.c
+59
-0
svec-test.c
software/lib/sveclib/svec-test.c
+13
-0
svec-vuart.c
software/lib/sveclib/svec-vuart.c
+134
-0
sveclib.c
software/lib/sveclib/sveclib.c
+406
-0
sveclib.h
software/lib/sveclib/sveclib.h
+41
-0
svecmem.c
software/lib/sveclib/svecmem.c
+76
-0
vmebus.h
software/lib/sveclib/vmebus.h
+419
-0
wb_uart.h
software/lib/sveclib/wb_uart.h
+92
-0
xloader_regs.h
software/lib/sveclib/xloader_regs.h
+118
-0
Makefile
software/tests/Makefile
+1
-1
gs_logger.c
software/tests/gs_logger.c
+9
-4
No files found.
software/include/rawrabbit.h
deleted
100644 → 0
View file @
eae0d98c
/*
* Public header for the raw I/O interface for PCI or PCI express interfaces
*
* Copyright (C) 2010 CERN (www.cern.ch)
* Author: Alessandro Rubini <rubini@gnudd.com>
*
* Released according to the GNU GPL, version 2 or any later version.
*
* This work is part of the White Rabbit project, a research effort led
* by CERN, the European Institute for Nuclear Research.
*/
#ifndef __RAWRABBIT_H__
#define __RAWRABBIT_H__
#include <linux/types.h>
#include <linux/ioctl.h>
#ifdef __KERNEL__
/* The initial part of the file is driver-internal stuff */
#include <linux/pci.h>
#include <linux/completion.h>
#include <linux/workqueue.h>
#include <linux/firmware.h>
#include <linux/wait.h>
#include <linux/completion.h>
struct
rr_devsel
;
struct
rr_dev
{
struct
rr_devsel
*
devsel
;
struct
pci_driver
*
pci_driver
;
struct
pci_device_id
*
id_table
;
struct
pci_dev
*
pdev
;
/* non-null after pciprobe */
struct
mutex
mutex
;
wait_queue_head_t
q
;
void
*
dmabuf
;
char
*
fwname
;
struct
timespec
irqtime
;
unsigned
long
irqcount
;
struct
completion
complete
;
struct
resource
*
area
[
3
];
/* bar 0, 2, 4 */
void
*
remap
[
3
];
/* ioremap of bar 0, 2, 4 */
unsigned
long
flags
;
struct
work_struct
work
;
const
struct
firmware
*
fw
;
struct
completion
fw_load
;
void
(
*
load_program
)(
struct
rr_dev
*
);
/* lm32 */
int
usecount
;
#ifdef IS_SPEC_DEMO
struct
miscdevice
misc
;
char
miscname
[
32
];
/* "spec-demo-<bus>-<slot> */
struct
list_head
list
;
#endif
};
extern
char
*
rr_fwname
;
/* module parameter. If "" then defaults apply */
#define RR_FLAG_REGISTERED 0x00000001
#define RR_FLAG_IRQDISABLE 0x00000002
#define RR_FLAG_IRQREQUEST 0x00000002
#define RR_PROBE_TIMEOUT (HZ)
/* for pci_register_drv */
/* These two live in ./loader.c */
extern
void
rr_ask_firmware
(
struct
rr_dev
*
dev
);
extern
void
rr_load_firmware
(
struct
work_struct
*
work
);
/* And, for the spec only, this is in ./spec-loader.c */
extern
void
spec_ask_program
(
struct
rr_dev
*
dev
);
#endif
/* __KERNEL__ */
/* By default, the driver registers for this vendor/devid */
#define RR_DEFAULT_VENDOR 0x1a39
#define RR_DEFAULT_DEVICE 0x0004
#define RR_DEFAULT_FWNAME "rrabbit-%P-%p@%b"
#define RR_MAX_FWNAME_SIZE 64
#define RR_DEFAULT_BUFSIZE (1<<20)
/* 1MB */
#define RR_PLIST_SIZE 4096
/* no PAGE_SIZE in user space */
#define RR_PLIST_LEN (RR_PLIST_SIZE / sizeof(void *))
#define RR_MAX_BUFSIZE (RR_PLIST_SIZE * RR_PLIST_LEN)
/* This structure is used to select the device to be accessed, via ioctl */
struct
rr_devsel
{
__u16
vendor
;
__u16
device
;
__u16
subvendor
;
/* RR_DEVSEL_UNUSED to ignore subvendor/dev */
__u16
subdevice
;
__u16
bus
;
/* RR_DEVSEL_UNUSED to ignore bus and devfn */
__u16
devfn
;
};
#define RR_DEVSEL_UNUSED 0xffff
/* Offsets for BAR areas in llseek() and/or ioctl */
#define RR_BAR_0 0x00000000
#define RR_BAR_2 0x20000000
#define RR_BAR_4 0x40000000
#define RR_BAR_BUF 0xc0000000
/* The DMA buffer */
#define RR_IS_DMABUF(addr) ((addr) >= RR_BAR_BUF)
#define __RR_GET_BAR(x) ((x) >> 28)
#define __RR_SET_BAR(x) ((x) << 28)
#define __RR_GET_OFF(x) ((x) & 0x0fffffff)
static
inline
int
rr_is_valid_bar
(
unsigned
long
address
)
{
int
bar
=
__RR_GET_BAR
(
address
);
return
bar
==
0
||
bar
==
2
||
bar
==
4
||
bar
==
0x0c
;
}
static
inline
int
rr_is_dmabuf_bar
(
unsigned
long
address
)
{
int
bar
=
__RR_GET_BAR
(
address
);
return
bar
==
0x0c
;
}
struct
rr_iocmd
{
__u32
address
;
/* bar and offset */
__u32
datasize
;
/* 1 or 2 or 4 or 8 */
union
{
__u8
data8
;
__u16
data16
;
__u32
data32
;
__u64
data64
;
};
};
/* ioctl commands */
#define __RR_IOC_MAGIC '4'
/* random or so */
#define RR_DEVSEL _IOW(__RR_IOC_MAGIC, 0, struct rr_devsel)
#define RR_DEVGET _IOR(__RR_IOC_MAGIC, 1, struct rr_devsel)
#define RR_READ _IOWR(__RR_IOC_MAGIC, 2, struct rr_iocmd)
#define RR_WRITE _IOW(__RR_IOC_MAGIC, 3, struct rr_iocmd)
#define RR_IRQWAIT _IO(__RR_IOC_MAGIC, 4)
#define RR_IRQENA _IO(__RR_IOC_MAGIC, 5)
#define RR_GETDMASIZE _IO(__RR_IOC_MAGIC, 6)
/* #define RR_SETDMASIZE _IO(__RR_IOC_MAGIC, 7, unsigned long) */
#define RR_GETPLIST _IO(__RR_IOC_MAGIC, 8)
/* returns a whole page */
#define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
/* Registers from the gennum header files */
enum
{
GNGPIO_BASE
=
0xA00
,
GNGPIO_DIRECTION_MODE
=
GNGPIO_BASE
+
0x4
,
GNGPIO_OUTPUT_ENABLE
=
GNGPIO_BASE
+
0x8
,
GNGPIO_OUTPUT_VALUE
=
GNGPIO_BASE
+
0xC
,
GNGPIO_INPUT_VALUE
=
GNGPIO_BASE
+
0x10
,
FCL_BASE
=
0xB00
,
FCL_CTRL
=
FCL_BASE
,
FCL_STATUS
=
FCL_BASE
+
0x4
,
FCL_IODATA_IN
=
FCL_BASE
+
0x8
,
FCL_IODATA_OUT
=
FCL_BASE
+
0xC
,
FCL_EN
=
FCL_BASE
+
0x10
,
FCL_TIMER_0
=
FCL_BASE
+
0x14
,
FCL_TIMER_1
=
FCL_BASE
+
0x18
,
FCL_CLK_DIV
=
FCL_BASE
+
0x1C
,
FCL_IRQ
=
FCL_BASE
+
0x20
,
FCL_TIMER_CTRL
=
FCL_BASE
+
0x24
,
FCL_IM
=
FCL_BASE
+
0x28
,
FCL_TIMER2_0
=
FCL_BASE
+
0x2C
,
FCL_TIMER2_1
=
FCL_BASE
+
0x30
,
FCL_DBG_STS
=
FCL_BASE
+
0x34
,
FCL_FIFO
=
0xE00
,
PCI_SYS_CFG_SYSTEM
=
0x800
};
#endif
/* __RAWRABBIT_H__ */
software/include/rr_io.h
deleted
100644 → 0
View file @
eae0d98c
#ifndef __RR_IO_H
#define __RR_IO_H
#include <stdint.h>
#include <rawrabbit.h>
int
rr_bind
(
int
a_fd
);
int
rr_init
(
int
bus
,
int
devfn
);
int
rr_writel
(
uint32_t
data
,
uint32_t
addr
);
uint32_t
rr_readl
(
uint32_t
addr
);
int
rr_load_bitstream
(
const
void
*
data
,
int
size8
);
int
rr_load_bitstream_from_file
(
const
char
*
file_name
);
#endif
software/lib/Makefile
View file @
b7f3c485
SPEC_SW
?=
$(
shell
readlink
-f
~/wr-repos/spec-sw
)
ETHERBONE
?=
$(
shell
readlink
-f
~/wr-repos/etherbone-core/api
)
OBJS
=
fdelay_lib.o i2c_master.o onewire.o fdelay_
bus.o spec/tools/speclib.o spec/kernel/loader-ll.o fdelay_dmtd_calibration.o simple-eb.o
OBJS
=
fdelay_lib.o i2c_master.o onewire.o fdelay_
vme.o fdelay_dmtd_calibration.o sveclib/sveclib.o sveclib/libvmebus.o
CFLAGS
=
-I
../include
-g
-Imini_bone
-Ispec
/tools
-I
etherbone
CFLAGS
=
-I
../include
-g
-Imini_bone
-Ispec
/tools
-I
sveclib
ifeq
($(SPEC_SW),)
throw_error
:
@
echo
"SPEC software package location environment variable is not set. Can't compile :("
endif
#
ifeq ($(SPEC_SW),)
#
throw_error:
#
@echo "SPEC software package location environment variable is not set. Can't compile :("
#
endif
all
:
spec
lib
all
:
lib
spec
:
ln
-s
$(SPEC_SW)
spec
ln
-s
$(ETHERBONE)
etherbone
#
spec:
#
ln -s $(SPEC_SW) spec
#
ln -s $(ETHERBONE) etherbone
lib
:
$(OBJS)
gcc
-shared
-o
libfinedelay.so
$(OBJS)
-letherbone
gcc
-shared
-o
libfinedelay.so
$(OBJS)
ar rc libfinedelay.a
$(OBJS)
clean
:
...
...
software/lib/fdelay_vme.c
0 → 100644
View file @
b7f3c485
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <getopt.h>
#include "fdelay_lib.h"
#include "sveclib/sveclib.h"
#include "fdelay_lib.h"
void
printk
()
{};
static
void
fd_svec_writel
(
void
*
priv
,
uint32_t
data
,
uint32_t
addr
)
{
svec_writel
(
priv
,
data
,
addr
);
}
static
uint32_t
fd_svec_readl
(
void
*
priv
,
uint32_t
addr
)
{
return
svec_readl
(
priv
,
addr
);
}
#if 0
static int spec_fdelay_create(fdelay_device_t *dev, int bus, int dev_fn)
{
uint32_t base;
dev->priv_io = spec_open(bus, dev_fn);
if(!dev->priv_io)
{
fprintf(stderr,"Can't map the SPEC @ %x:%x\n", bus, dev_fn);
return -1;
}
dev->writel = fd_spec_writel;
dev->readl = fd_spec_readl;
dev->base_addr = base;
//spec_vuart_init(dev->priv_io, 0xe0500); /* for communication with WRCore during DMTD calibration */
return 0;
}
#endif
#define VENDOR_CERN 0xce42
#define DEVICE_FD_CORE 0xf19ede1a
#define DEVICE_VUART 0xe2d13d04
int
fdelay_probe
(
fdelay_device_t
*
dev
,
const
char
*
location
)
{
int
bus
=
-
1
,
dev_fn
=
-
1
;
char
ip_addr
[
128
];
int
use_eb
=
0
;
uint32_t
base_core
;
void
*
card
;
if
(
!
strncmp
(
location
,
"eb:"
,
3
))
{
snprintf
(
ip_addr
,
sizeof
(
ip_addr
),
"udp/%s"
,
location
+
3
);
use_eb
=
1
;
}
else
if
(
!
strncmp
(
location
,
"svec:"
),
5
)
{
sscanf
(
location
+
5
,
"%d,%d"
,
&
bus
,
&
dev_fn
);
}
card
=
svec_open
(
8
);
if
(
!
card
)
{
fprintf
(
stderr
,
"SVEC probe failed.
\n
"
);
return
-
1
;
}
dev
->
priv_io
=
card
;
dev
->
writel
=
fd_svec_writel
;
dev
->
readl
=
fd_svec_readl
;
dev
->
base_addr
=
0x10000
;
dbg
(
"Found FD core @ 0x%x
\n
"
,
base_core
);
}
fdelay_device_t
*
fdelay_create
()
{
return
(
fdelay_device_t
*
)
malloc
(
sizeof
(
fdelay_device_t
));
}
software/lib/sveclib/.gitignore
0 → 100644
View file @
b7f3c485
*.o
svec-cl
svec-fwloader
svec-vuart
software/lib/sveclib/Makefile
0 → 100644
View file @
b7f3c485
OBJS
=
sveclib.o libvmebus.o
CFLAGS
=
-I
.
-Wall
-DDEBUG
-g
CC
=
gcc
all
:
cl fwloader vuart svecmem
cl
:
svec-cl.o $(OBJS)
gcc
-o
svec-cl
$(OBJS)
svec-cl.o
fwloader
:
svec-fwloader.o $(OBJS)
gcc
-o
svec-fwloader
$(OBJS)
svec-fwloader.o
vuart
:
svec-vuart.o $(OBJS)
gcc
-o
svec-vuart
$(OBJS)
svec-vuart.o
svecmem
:
svecmem.o $(OBJS)
gcc
-o
svecmem
$(OBJS)
svecmem.o
clean
:
rm
-f
*
.o svec-cl svec-test svec-fwloader svec-vuart
\ No newline at end of file
software/lib/sveclib/README
0 → 100644
View file @
b7f3c485
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!! WARNING !!!!!!!!
!!!!!!!! DEVELOPER USE ONLY !!!!!!!!
!!!!!!!! DO NOT DEPLOY IN PRODUCTION ENVIRONMENTS !!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sveclib - a tiny userspace library (and a set of tools) allowing developers to play with the svec.
The library provides:
- raw I/O to a spec in particular slot (uses geographical addressing). Currently, there's
a fixed A32/D32/SINGLE mapping available and the memory can be accesed by calling
svec_writel()/svec_readl()
- application FPGA firmware loader (svec-fwloader)
- LM32 CPU firmware loader (svec-cl)
- WR Core virtual UART console (svec-vuart)
All these tools require the slot location to be specified with -b command line switch.
Requirements: Requires vmebus driver to be installed (tested on MEN A20).
Compilation: just run make.
\ No newline at end of file
software/lib/sveclib/libvmebus.c
0 → 100644
View file @
b7f3c485
This diff is collapsed.
Click to expand it.
software/lib/sveclib/libvmebus.h
0 → 100644
View file @
b7f3c485
/**
* \file libvmebus.h
* \brief VME Bus access user library interface
* \author Sbastien Dugu
* \date 04/02/2009
*
* This library gives userspace applications access to the VME bus
*
* Copyright (c) 2009 \em Sbastien \em Dugu
*
* \par License:
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
*/
#ifndef _LIBVMEBUS_H_INCLUDE_
#define _LIBVMEBUS_H_INCLUDE_
#ifdef __cplusplus
extern
"C"
{
#endif
#include <vmebus.h>
/**
* \brief Swap a 16-bit halfword bytewise
* \param val The 16-bit halfword to swap
*
* \return The swapped value
*
*/
static
inline
unsigned
short
swapbe16
(
unsigned
short
val
)
{
return
(((
val
&
0xff00
)
>>
8
)
|
((
val
&
0xff
)
<<
8
));
}
/**
* \brief Swap a 32-bit word bytewise
* \param val The 32-bit word to swap
*
* \return The swapped value
*
*/
static
inline
unsigned
int
swapbe32
(
unsigned
int
val
)
{
return
(((
val
&
0xff000000
)
>>
24
)
|
((
val
&
0xff0000
)
>>
8
)
|
((
val
&
0xff00
)
<<
8
)
|
((
val
&
0xff
)
<<
24
));
}
extern
int
vme_bus_error_check
(
struct
vme_mapping
*
desc
);
extern
int
vme_bus_error_check_clear
(
struct
vme_mapping
*
desc
,
__u64
address
);
/* VME address space mapping - CES library emulation */
extern
unsigned
long
find_controller
(
unsigned
long
vmeaddr
,
unsigned
long
len
,
unsigned
long
am
,
unsigned
long
offset
,
unsigned
long
size
,
struct
pdparam_master
*
param
);
extern
unsigned
long
return_controller
(
struct
vme_mapping
*
desc
);
/* VME address space mapping */
extern
void
*
vme_map
(
struct
vme_mapping
*
,
int
);
extern
int
vme_unmap
(
struct
vme_mapping
*
,
int
);
/* DMA access */
extern
int
vme_dma_read
(
struct
vme_dma
*
);
extern
int
vme_dma_write
(
struct
vme_dma
*
);
#ifdef __cplusplus
}
#endif
#endif
/* _LIBVMEBUS_H_INCLUDE_ */
software/lib/sveclib/svec-cl.c
0 → 100644
View file @
b7f3c485
/*
* A tool to program our soft-core (LM32) within the SVEC.
*
* Alessandro Rubini 2012 for CERN, GPLv2 or later.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <getopt.h>
#include "sveclib.h"
int
main
(
int
argc
,
char
**
argv
)
{
int
bus
=
-
1
,
c
;
uint32_t
lm32_base
=
0x00000
;
void
*
card
;
while
((
c
=
getopt
(
argc
,
argv
,
"b:c:"
))
!=
-
1
)
{
switch
(
c
)
{
case
'b'
:
sscanf
(
optarg
,
"%i"
,
&
bus
);
break
;
case
'c'
:
sscanf
(
optarg
,
"%i"
,
&
lm32_base
);
break
;
default:
fprintf
(
stderr
,
"Use:
\"
%s [-b slot] [-c lm32 base address] <lm32_program.bin>
\"\n
"
,
argv
[
0
]);
fprintf
(
stderr
,
"By default, the first available SVEC is used and the LM32 is assumed at 0x%x.
\n
"
,
lm32_base
);
exit
(
1
);
}
}
if
(
optind
>=
argc
)
{
fprintf
(
stderr
,
"Expected binary name after options.
\n
"
);
exit
(
1
);
}
card
=
svec_open
(
bus
);
if
(
!
card
)
{
fprintf
(
stderr
,
"Can't detect a SVEC card under the given adress. Make sure a SVEC card is present in your PC and the driver is loaded.
\n
"
);
exit
(
1
);
}
fprintf
(
stderr
,
"Loading..
\n
"
);
if
(
svec_load_lm32
(
card
,
argv
[
optind
],
lm32_base
)
<
0
)
{
fprintf
(
stderr
,
"Loader failure.
\n
"
);
exit
(
1
);
}
svec_close
(
card
);
exit
(
0
);
}
software/lib/sveclib/svec-fwloader.c
0 → 100644
View file @
b7f3c485
/*
* A tool to program the FPGA within the SPEC.
*
* Alessandro Rubini 2012 for CERN, GPLv2 or later.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <getopt.h>
#include "sveclib.h"
int
main
(
int
argc
,
char
**
argv
)
{
int
bus
=
-
1
,
c
;
void
*
card
;
while
((
c
=
getopt
(
argc
,
argv
,
"b:"
))
!=
-
1
)
{
switch
(
c
)
{
case
'b'
:
sscanf
(
optarg
,
"%i"
,
&
bus
);
break
;
default:
fprintf
(
stderr
,
"Use:
\"
%s -b slot <fpga_bitstream.bin>
\"\n
"
,
argv
[
0
]);
exit
(
1
);
}
}
if
(
optind
>=
argc
)
{
fprintf
(
stderr
,
"Expected binary name after options.
\n
"
);
exit
(
1
);
}
if
(
bus
<
0
)
{
fprintf
(
stderr
,
"You must specify the slot number.
\n
"
);
return
-
1
;
}
card
=
svec_open
(
bus
);
if
(
!
card
)
{
fprintf
(
stderr
,
"Can't detect a SVEC card under the given adress. Make sure a SVEC card is present in your PC and the driver is loaded.
\n
"
);
exit
(
1
);
}
if
(
svec_load_bitstream
(
card
,
argv
[
optind
])
<
0
)
{
fprintf
(
stderr
,
"Loader failure.
\n
"
);
exit
(
1
);
}
svec_close
(
card
);
exit
(
0
);
}
software/lib/sveclib/svec-test.c
0 → 100644
View file @
b7f3c485
#include <stdio.h>
#include "sveclib.h"
int
main
()
{
void
*
card
=
svec_open
(
8
);
svec_writel
(
card
,
0x1deadbee
,
0x20400
);
printf
(
"readback:%x
\n
"
,
svec_readl
(
card
,
0x20400
));
}
\ No newline at end of file
software/lib/sveclib/svec-vuart.c
0 → 100644
View file @
b7f3c485
/* A simple console for accessing the SVEC virtual UART (i.e. for communicating with the WR Core shell
from a Linux terminal. */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <string.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <getopt.h>
#include <errno.h>
#include "sveclib.h"
static
void
*
card
;
static
int
transfer_byte
(
int
from
,
int
is_control
)
{
char
c
;
int
ret
;
do
{
ret
=
read
(
from
,
&
c
,
1
);
}
while
(
ret
<
0
&&
errno
==
EINTR
);
if
(
ret
==
1
)
{
if
(
is_control
)
{
if
(
c
==
'\x01'
)
{
// C-a
return
-
1
;
}
}
svec_vuart_tx
(
card
,
&
c
,
1
);
}
else
{
fprintf
(
stderr
,
"
\n
nothing to read. probably port disconnected.
\n
"
);
return
-
2
;
}
return
0
;
}
void
term_main
(
int
keep_term
)
{
struct
termios
oldkey
,
newkey
;
//place tor old and new port settings for keyboard teletype
int
need_exit
=
0
;
fprintf
(
stderr
,
"[press C-a to exit]
\n
"
);
if
(
!
keep_term
)
{
tcgetattr
(
STDIN_FILENO
,
&
oldkey
);
newkey
.
c_cflag
=
B9600
|
CS8
|
CLOCAL
|
CREAD
;
newkey
.
c_iflag
=
IGNPAR
;
newkey
.
c_oflag
=
0
;
newkey
.
c_lflag
=
0
;
newkey
.
c_cc
[
VMIN
]
=
1
;
newkey
.
c_cc
[
VTIME
]
=
0
;
tcflush
(
STDIN_FILENO
,
TCIFLUSH
);
tcsetattr
(
STDIN_FILENO
,
TCSANOW
,
&
newkey
);
}
while
(
!
need_exit
)
{
fd_set
fds
;
int
ret
;
char
rx
;
struct
timeval
tv
=
{
0
,
10000
};
FD_ZERO
(
&
fds
);
FD_SET
(
STDIN_FILENO
,
&
fds
);
ret
=
select
(
STDIN_FILENO
+
1
,
&
fds
,
NULL
,
NULL
,
&
tv
);
if
(
ret
==
-
1
)
{
perror
(
"select"
);
}
else
if
(
ret
>
0
)
{
if
(
FD_ISSET
(
STDIN_FILENO
,
&
fds
))
{
need_exit
=
transfer_byte
(
STDIN_FILENO
,
1
);
}
}
while
((
svec_vuart_rx
(
card
,
&
rx
,
1
))
==
1
)
fprintf
(
stderr
,
"%c"
,
rx
);
}
if
(
!
keep_term
)
tcsetattr
(
STDIN_FILENO
,
TCSANOW
,
&
oldkey
);
}
int
main
(
int
argc
,
char
**
argv
)
{
int
bus
=
-
1
,
c
;
uint32_t
vuart_base
=
0x20500
;
int
keep_term
=
0
;
while
((
c
=
getopt
(
argc
,
argv
,
"b:u:k"
))
!=
-
1
)
{
switch
(
c
)
{
case
'b'
:
sscanf
(
optarg
,
"%i"
,
&
bus
);
break
;
case
'u'
:
sscanf
(
optarg
,
"%i"
,
&
vuart_base
);
break
;
case
'k'
:
keep_term
=
1
;
break
;
default:
fprintf
(
stderr
,
"Use:
\"
%s [-b slot] [-u VUART base] [-k]
\"\n
"
,
argv
[
0
]);
fprintf
(
stderr
,
"By default, the VUART is assumed at 0x%x.
\n
\
-k option keeps the terminal config unchanged.
\n
"
,
vuart_base
);
exit
(
1
);
}
}
if
(
bus
<
0
)
{
fprintf
(
stderr
,
"Missing slot number.
\n
"
);
return
-
1
;
}
card
=
svec_open
(
bus
);
if
(
!
card
)
{
fprintf
(
stderr
,
"Can't detect a SVEC card under the given adress. Make sure a SVEC card is present in your PC and the driver is loaded.
\n
"
);
return
-
1
;
}
svec_vuart_init
(
card
,
vuart_base
);
term_main
(
keep_term
);
svec_close
(
card
);
return
0
;
}
software/lib/sveclib/sveclib.c
0 → 100644
View file @
b7f3c485
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include "libvmebus.h"
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <errno.h>
#include <sys/signal.h>
#include <arpa/inet.h>