printf(" -f execute commands given in script-file\n");
printf(" -n repeat COMMAND number times, -1 = endless loop\n");
printf(" -d turn on Debugging Information\n");
- printf(" level 1: TRB_Package debugging\n");
- printf(" level 2: +FIFO debugging\n");
+ printf(" level 1: TRB_Package debugging\n");
+ printf(" level 2: +FIFO debugging\n");
printf(" -D FIFO DMA-Mode\n");
printf(" -l lazy-mode: skip most consistency-checks of packages\n");
printf(" -H hex-mode: all following arguments will be interpreted "
printf(" i <trbaddress> -> read unique ID\n");
printf(" s <uid> <endpoint> <trbaddress> -> set trb-address\n");
printf(" T <type> <random> <info> <number> -> send trigger\n");
- printf(" TR <input> <type> <random> <info> <number> -> send trigger to "
+ printf(" TR <input> <type> <random> <info> <number> -> send trigger to "
"RICH only\n");
printf(" I <type> <random> <info> <number> -> read IPU data\n");
printf(" f <channel> -> flush FIFO of "
size_t cmdLineLen = 0;
unsigned int cmdLen = 0;
uint16_t trb_address = 0;
- uint16_t reg_address = 0;
+ uint16_t reg_address = 0;
int loop = 1;
int loopCtr = 0;
int opt;
-
+
trb_debug = 0;
trb_lazy = 0;
- trb_semlock = 1;
/* Parse Arguments */
while ((opt = getopt(argc, argv, "+hf:n:d:DlHV")) != -1) {
break;
}
}
-
+
/* Open scriptFile if requested */
if (strlen(scriptFileName) > 0) {
if (strncmp(scriptFileName, "-", 256) == 0) {
}
}
}
-
+
/* Open ports */
- init_ports();
+ init_ports();
/* Start repeat-loop */
while ((loop == -1) || (loopCtr++ < loop)) {
unsigned int lineCtr = 0;
ssize_t scriptStatus = 0;
-
+
/* Start script-file-loop */
- while (scriptStatus != -1) {
- if (scriptFile == NULL) {
+ while (scriptStatus != -1) {
+ if (scriptFile == NULL) {
/* Get command from function-call */
unsigned int i;
cmdLen = argc - optind;
for (i = 0; (i < cmdLen) && (i < CMD_MAX_NUM); i++) {
- strncpy(cmd[i], argv[optind + i], CMD_SIZE);
+ strncpy(cmd[i], argv[optind + i], CMD_SIZE);
}
scriptStatus = -1;
} else {
char *c = NULL;
unsigned int i;
-
+
lineCtr++;
/* Initialize */
for (i = 0; i < CMD_MAX_NUM; i++) {
cmd[i][0] = '\0';
}
-
+
if ((scriptStatus =
getline(&cmdLine, &cmdLineLen, scriptFile)) == -1) {
if (feof(scriptFile) != 0) {
exit(EXIT_FAILURE);
}
}
-
+
/* Remove newline and comments */
if ((c = strchr(cmdLine, '\n')) != NULL) {
*c = '\0';
}
/* Split up cmdLine */
- sscanf(cmdLine, "%s %s %s %s %s %s %s %s %s %s",
+ sscanf(cmdLine, "%s %s %s %s %s %s %s %s %s %s",
cmd[0], cmd[1], cmd[2], cmd[3], cmd[4],
cmd[5], cmd[6], cmd[7], cmd[8], cmd[9]);
-
+
for (i = 0, cmdLen = 0; i < CMD_MAX_NUM; i++, cmdLen++) {
if (cmd[i][0] == '\0') break;
}
/* Empty Line */
continue;
}
+
fprintf(stdout, "#Line %d: %s\n", lineCtr, cmdLine);
}
-
+
if (strncmp(cmd[0], "w", CMD_SIZE) == 0) {
-
+
/*******************************************/
/* Register Write */
/*******************************************/
-
+
uint32_t value = 0;
-
+
if (cmdLen != 4) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
}
exit(EXIT_FAILURE);
}
-
+
trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
reg_address = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0);
value = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0);
-
+
/* DEBUG Info */
if (trb_debug > 0) {
- fprintf(stderr,
+ fprintf(stderr,
"Command: WRITE: trb_address: 0x%04x, reg_address: 0x%04x, "
- "value: 0x%08x\n",
+ "value: 0x%08x\n",
trb_address, reg_address, value);
}
int status = 0;
uint32_t data[256];
int i;
-
+
if (cmdLen != 3) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
}
exit(EXIT_FAILURE);
}
-
+
trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
reg_address = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0);
/* DEBUG Info */
if (trb_debug > 0) {
- fprintf(stderr,
+ fprintf(stderr,
"Command: READ: trb_address: 0x%04x, "
"reg_address: 0x%04x\n",
trb_address, reg_address);
}
-
+
status = trb_register_read(trb_address, reg_address, data, 256);
if (status == -1) {
if (scriptFile != NULL) {
exit(EXIT_FAILURE);
}
}
-
+
for (i = 0; i < status; i += 2) {
fprintf(stdout, "0x%04x 0x%08x\n",
data[i], data[i + 1]);
}
} else if (strncmp(cmd[0], "rm", CMD_SIZE) == 0) {
-
+
/*******************************************/
/* Register Read Memory */
/*******************************************/
-
+
uint32_t *data = NULL;
uint16_t size = 0;
uint8_t option = 0;
const uint32_t* end = NULL;
unsigned int len;
unsigned int i;
-
+
if (cmdLen != 5) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
}
exit(EXIT_FAILURE);
}
-
+
trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
reg_address = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0);
size = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0);
option = strtoul(cmd[4], NULL, hexMode == 1 ? 16 : 0);
-
+
/* DEBUG Info */
if (trb_debug > 0) {
- fprintf(stderr,
+ fprintf(stderr,
"Command: READ_MEM: "
"trb_address: 0x%04x, "
"reg_address: 0x%04x, "
"option: %d\n",
trb_address, reg_address, size, option);
}
-
+
if ((data = malloc(sizeof(uint32_t) * READ_MEM_SIZE)) == NULL) abort();
-
- status =
- trb_register_read_mem(trb_address, reg_address, option,
+
+ status =
+ trb_register_read_mem(trb_address, reg_address, option,
size, data, READ_MEM_SIZE);
if (status == -1) {
if (scriptFile != NULL) {
exit(EXIT_FAILURE);
}
}
-
+
/* Print data-buffer */
p = data;
end = p + status;
while (p < end) {
len = (*p >> 16) & 0xffff;
fprintf(stdout, "0x%04x 0x%04x\n", (*p++) & 0xffff, len);
- for (i = 0; (i < len) && (p < end); i++) {
- fprintf(stdout, "0x%04x 0x%08x\n",
+ for (i = 0; (i < len) && (p < end); i++) {
+ fprintf(stdout, "0x%04x 0x%08x\n",
reg_address + i, *p++);
}
}
-
+
if (data != NULL) free(data);
} else if (strncmp(cmd[0], "wm", CMD_SIZE) == 0) {
-
+
/*******************************************/
/* Register Write Memory */
/*******************************************/
-
+
FILE *file = NULL;
uint32_t *data = NULL;
- unsigned int dataSize = 64;
+ unsigned int dataSize = 64;
char *line = NULL;
size_t len = 0;
char *fileName = NULL;
}
exit(EXIT_FAILURE);
}
-
+
trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
reg_address = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0);
option = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0);
fileName = cmd[4];
-
+
/* Open inputFile and read Data into buffer */
if (strncmp(fileName, "-", CMD_SIZE) == 0) {
file = stdin;
exit(EXIT_FAILURE);
}
}
-
+
if ((data = malloc(sizeof(uint32_t) * dataSize)) == NULL) abort();
while (getline(&line, &len, file) != -1) {
if (size >= dataSize) {
data[size++] = strtoul(line, NULL, hexMode == 1 ? 16 : 0);
}
if (line != NULL) free(line);
-
+
/* DEBUG Info */
if (trb_debug > 0) {
- fprintf(stderr,
+ fprintf(stderr,
"Command: WRITE_MEM: trb_address: 0x%04x, "
"reg_address: 0x%04x, "
"option: %d, "
"size: 0x%04x\n",
trb_address, reg_address, option, fileName, size);
}
-
- status = trb_register_write_mem(trb_address, reg_address, option,
+
+ status = trb_register_write_mem(trb_address, reg_address, option,
data, size);
if (data != NULL) free(data);
-
+
if (status == -1) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: ", lineCtr);
/*******************************************/
/* ReadUId */
/*******************************************/
-
+
uint32_t uidBuffer[512];
int status;
int i;
-
+
if (cmdLen != 2) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
}
exit(EXIT_FAILURE);
}
-
+
trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
-
+
/* DEBUG Info */
if (trb_debug > 0) {
- fprintf(stderr,
+ fprintf(stderr,
"Command: READ_UID: trb_address: 0x%04x\n",
trb_address);
}
-
+
status = trb_read_uid(trb_address, uidBuffer, 128);
if (status == -1) {
if (scriptFile != NULL) {
exit(EXIT_FAILURE);
}
}
-
+
for (i = 0; (i < status) && (i < 128); i += 4) {
fprintf(stdout, "0x%04x 0x%08x%08x 0x%02x\n",
uidBuffer[i + 3],
- uidBuffer[i],
- uidBuffer[i + 1],
+ uidBuffer[i],
+ uidBuffer[i + 1],
uidBuffer[i + 2]);
}
} else if (strncmp(cmd[0], "s", CMD_SIZE) == 0) {
-
+
/*******************************************/
/* SetAddress */
/*******************************************/
-
+
uint64_t uid = 0;
uint8_t endpoint = 0;
uint16_t trb_address = 0;
-
+
if (cmdLen != 4) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
}
exit(EXIT_FAILURE);
}
-
+
uid = strtoull(cmd[1], NULL, hexMode == 1 ? 16 : 0);
endpoint = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0);
trb_address = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0);
-
+
/* DEBUG Info */
if (trb_debug > 0) {
- fprintf(stderr,
+ fprintf(stderr,
"Command: SET_ADDRESS: "
"uid: 0x%016llx, "
"endpoint: 0x%02x, "
"trb_address: 0x%04x\n",
uid, endpoint, trb_address);
}
-
+
if (trb_set_address(uid, endpoint, trb_address) == -1) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: ", lineCtr);
}
}
} else if (strncmp(cmd[0], "T", CMD_SIZE) == 0) {
-
+
/*******************************************/
/* Send Trigger */
/*******************************************/
-
+
uint8_t type;
uint8_t random = 0;
uint8_t info = 0;
uint16_t number = 0;
-
+
if (cmdLen != 5) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
}
exit(EXIT_FAILURE);
}
-
+
type = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0) & 0x0f;
random = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0);
info = strtoul(cmd[4], NULL, hexMode == 1 ? 16 : 0);
number = strtoul(cmd[5], NULL, hexMode == 1 ? 16 : 0);
-
+
/* DEBUG Info */
if (trb_debug > 0) {
- fprintf(stderr,
+ fprintf(stderr,
"Command: SEND_TRIGGER: "
"type: 0x%01x, "
"random: 0x%02x, "
"number: 0x%04x\n",
type, random, info, number);
}
-
+
if (trb_send_trigger(type, info, random, number) == -1) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: ", lineCtr);
if (trb_errno != TRB_ENDPOINT_NOT_REACHED) {
exit(EXIT_FAILURE);
}
- }
+ }
} else if (strncmp(cmd[0], "TR", CMD_SIZE) == 0) {
-
+
/*********************************************/
/* Send Fake trigger function to RICH Subnet */
/*********************************************/
-
+
uint8_t input = 0;
uint8_t type = 0;
uint8_t random = 0;
uint8_t info = 0;
uint16_t number = 0;
-
+
if (cmdLen != 6) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
}
exit(EXIT_FAILURE);
}
-
+
input = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0) & 0x03;
type = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0) & 0x0f;
random = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0);
info = strtoul(cmd[4], NULL, hexMode == 1 ? 16 : 0);
number = strtoul(cmd[5], NULL, hexMode == 1 ? 16 : 0);
-
+
/* DEBUG Info */
if (trb_debug > 0) {
- fprintf(stderr,
+ fprintf(stderr,
"Command: SEND_TRIGGER: "
"input: 0x%01x, "
"type: 0x%01x, "
"number: 0x%04x\n",
input, type, random, info, number);
}
-
+
if (trb_send_trigger_rich(input, type, info, random, number) == -1) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: ", lineCtr);
}
}
} else if (strncmp(cmd[0], "I", CMD_SIZE) == 0) {
-
+
/*******************************************/
/* IPU channel readout */
/*******************************************/
-
+
uint32_t buffer[4096];
uint8_t type = 0;
uint8_t random = 0;
uint16_t number = 0;
int status = 0;
int i;
-
+
if (cmdLen != 5) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
}
exit(EXIT_FAILURE);
}
-
+
type = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0) & 0x0f;
random = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0);
info = strtoul(cmd[3], NULL, hexMode == 1 ? 16 : 0);
number = strtoul(cmd[4], NULL, hexMode == 1 ? 16 : 0);
-
+
/* DEBUG Info */
if (trb_debug > 0) {
- fprintf(stderr,
+ fprintf(stderr,
"Command: READ_IPU_DATA: "
"type: 0x%01x, "
"random: 0x%02x, "
exit(EXIT_FAILURE);
}
}
-
+
for (i = 0; i < status; i++) {
fprintf(stdout, "0x%08x\n", buffer[i]);
}
} else if (strncmp(cmd[0], "f", CMD_SIZE) == 0) {
-
+
/*******************************************/
/* Flush FIFO Channel */
/*******************************************/
-
+
int status;
uint8_t channel = 0;
-
+
if (cmdLen != 2) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
}
exit(EXIT_FAILURE);
}
-
+
channel = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
if (trb_debug > 0) {
fprintf(stderr, "Command: FIFO_FLUSH_CHANNEL #%d\n", channel);
}
-
+
status = trb_fifo_flush(channel);
if (status == -1) {
if (scriptFile != NULL) {
}
}
} else if (strncmp(cmd[0], "R", CMD_SIZE) == 0) {
-
+
/*******************************************/
/* Read FIFO Register */
/*******************************************/
-
+
uint32_t value = 0;
uint16_t reg_address = 0;
-
+
if (cmdLen != 2) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
reg_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
if (trb_debug > 0) {
- fprintf(stderr,
+ fprintf(stderr,
"Command: READ_FIFO_REGISTER:"
"reg_address: 0x%04x\n",
reg_address);
}
-
+
read32_from_FPGA(reg_address, &value);
fprintf(stdout, "0x%04x 0x%08x\n", reg_address, value);
-
+
} else if (strncmp(cmd[0], "W", CMD_SIZE) == 0) {
-
+
/*******************************************/
/* Write FIFO Register */
/*******************************************/
-
+
uint32_t value = 0;
uint16_t reg_address = 0;
-
+
if (cmdLen != 3) {
if (scriptFile != NULL) {
fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
}
exit(EXIT_FAILURE);
}
-
+
reg_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
value = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0);
if (trb_debug > 0) {
- fprintf(stderr,
+ fprintf(stderr,
"Command: READ_FIFO_REGISTER:"
"reg_address: 0x%04x, "
"value: 0x%08x\n",
reg_address, value);
}
-
+
write32_to_FPGA(reg_address, value);
} else {
if (scriptFile != NULL) {
exit(EXIT_FAILURE);
}
} /* End script-file-loop */
-
+
} /* End repeat-loop */
-
+
/* Cleanup */
if (scriptFile != NULL) {
fclose(scriptFile);
}
if (cmdLine != 0) free(cmdLine);
-
+
exit(EXIT_SUCCESS);
}
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include <sys/ipc.h>
#include <sys/sem.h>
+#include <errno.h>
#include <fs_fpga_int_mem.h>
#include <port.h>
/* ---------------------------------------------------------------------- */
/* Used for blocking Signals SIGINT and SIGTERM */
-static sigset_t blockSet;
+static sigset_t blockSet;
static sigset_t blockSetOld;
-static int signalsBlocked = 0;
/* Semaphore handling */
static int semid = -1;
unsigned int trb_debug = 0;
unsigned int trb_lazy = 0;
unsigned int trb_dma = 0;
-unsigned int trb_semlock = 0;
/* Declaration of a TRB-Package */
/* Read FIFO-Buffer, copy to User-Buffer */
while ((*tmp & MASK_FIFO_VALID) != 0) {
fifoDebugCtr++;
-
+
if (((*tmp & MASK_FIFO_TYPE) >> SHIFT_FIFO_TYPE) == FIFO_TYPE_IS_HEADER) {
/* TRBNet HEADER */
if ((counter % 5) == 0) {
}
packageCtr++;
counter = 0;
-
+
/* DEBUG INFO */
if (trb_debug > 1) {
fprintf(stderr, "FIFO_%03d: 0x%08x\n",
}
} else {
/* Error: invalid buffer content, flush FIFO-BUFFER and exit */
-
+
/* DEBUG INFO */
if (trb_debug > 1) {
fprintf(stderr, "FIFO_%03d: 0x%08x\n",
fifoDebugCtr, *tmp);
}
-
+
fifo_flush(channel);
trb_errno = TRB_FIFO_INCOMPLETE_PACKAGE;
return -1;
}
} else {
/* TRBNet Data Word */
-
+
/* DEBUG INFO */
if (trb_debug > 1) {
fprintf(stderr, "FIFO_%03d: 0x%08x\n",
fifoDebugCtr, *tmp);
}
-
+
if ((trb_lazy == 0) &&
- (((*tmp & MASK_FIFO_TYPE) >> SHIFT_FIFO_TYPE) !=
+ (((*tmp & MASK_FIFO_TYPE) >> SHIFT_FIFO_TYPE) !=
(counter - 1) % 2)) {
/* Error: invalid sequence (not 0, 1, .), flush FIFO-BUFFER and exit */
fifo_flush(channel);
return dataCtr;
}
-static void blockSignals()
-{
- signalsBlocked++;
- if (signalsBlocked > 1) return;
- sigprocmask(SIG_BLOCK, &blockSet, &blockSetOld);
-}
-
-static void unblockSignals()
-{
- signalsBlocked--;
- if (signalsBlocked > 0) return;
- sigprocmask(SIG_SETMASK, &blockSetOld, NULL);
-}
-
static int lockPorts()
{
- struct sembuf sops[2] = {
- {
- 0, /* sem_num: We only use one track */
- 0, /* sem_op: wait for semaphore flag to become zero */
- SEM_UNDO /* sem_flg: remove sem if process gets killed */
- },
- {
- 0, /* sem_num: We only use one track */
- 1, /* sem_op: increment semaphore, i.e. lock it */
- SEM_UNDO | IPC_NOWAIT /* sem_flg: remove sem if process gets killed */
- }
+ struct sembuf sops = {
+ 0, /* sem_num: We only use one track */
+ -1, /* sem_op: decrement semaphore by 1, i.e. lock it */
+ SEM_UNDO /* sem_flg: remove lock if process gets killed */
};
-
- if (trb_semlock == 0) return 0;
-
- if (semop(semid, sops, 2) == -1) {
- perror("TRB_SEMAPHORE lock");
+
+ /* Wait for semaphore and lock it */
+ if (semop(semid, &sops, 1) == -1) {
trb_errno = TRB_SEMAPHORE;
return -1;
}
+ /* Block Signals */
+ sigprocmask(SIG_BLOCK, &blockSet, &blockSetOld);
+
return 0;
}
static int unlockPorts()
{
- struct sembuf sops[1] = {
- {
- 0, /* sem_num: We only use one track */
- -1, /* sem_op: decrement semaphore, i.e. unlock it */
- IPC_NOWAIT /* */
- }
+ struct sembuf sops = {
+ 0, /* sem_num: We only use one track */
+ 1, /* sem_op: decrement semaphore, i.e. unlock it */
+ SEM_UNDO /* */
};
-
- if (trb_semlock == 0) return 0;
-
- if (semop(semid, sops, 1) == -1) {
- perror("TRB_SEMAPHORE unlock");
+
+ /* Unblock Signals */
+ sigprocmask(SIG_SETMASK, &blockSetOld, NULL);
+
+ /* Release semaphore */
+ if (semop(semid, &sops, 1) == -1) {
trb_errno = TRB_SEMAPHORE;
return -1;
}
-
+
return 0;
}
return -1;
}
- /* Get / Create semaphore */
- if (trb_semlock > 0) {
- if ((semid = semget(sem_key, 1, IPC_CREAT | 0666)) == -1) {
+ /* Get / Create semaphore */
+ if ((semid = semget(sem_key, 1,
+ IPC_CREAT | IPC_EXCL |
+ S_IRUSR | S_IWUSR |
+ S_IRGRP | S_IWGRP |
+ S_IROTH | S_IWOTH)) == -1) {
+ if (errno == EEXIST) {
+ /* Semaphore already exist, so just open it */
+ if ((semid = semget(sem_key, 1, 0)) == -1) {
+ trb_errno = TRB_SEMAPHORE;
+ return -1;
+ }
+ } else {
+ /* Fatal error, see errno */
+ trb_errno = TRB_SEMAPHORE;
+ return -1;
+ }
+ } else {
+ /* Initialize newly created semaphore, i.e set value to 1 */
+ if (semctl(semid, 0, SETVAL, 1) == -1) {
trb_errno = TRB_SEMAPHORE;
return -1;
}
}
-
+
return 0;
}
if (trb_debug > 1) {
fprintf(stderr, "Flushing FIFO of channel# %d\n", channel);
}
-
+
if (lockPorts() == -1) return -1;
- blockSignals();
-
fifo_flush(channel);
-
- unblockSignals();
-
+
if (unlockPorts() == -1) return -1;
return 0;
/* Init transfer */
if (trb_init_transfer(3) == -1) {
+ unlockPorts();
return -1;
}
if (trb_debug > 0) {
fprintf(stderr, "Init_Transfer done.\n");
}
-
- blockSignals();
-
+
/* Build up package and start transfer */
write32_to_FPGA(CHANNEL_3_TARGET_ADDRESS, trb_address);
write32_to_FPGA(CHANNEL_3_SENDER_ERROR, 0x00000000);
status = trb_fifo_read(3, FIFO_MODE_REG_READ, data, dsize);
- unblockSignals();
-
if (unlockPorts() == -1) return -1;
-
+
if ((status > 0) && (status % 2 != 0)) {
trb_errno = TRB_INVALID_PKG_NUMBER;
return -1;
/* Init transfer */
if (trb_init_transfer(3) == -1) {
+ unlockPorts();
return -1;
}
if (trb_debug > 0) {
fprintf(stderr, "Init_Tranfer done.\n");
}
-
- blockSignals();
-
+
/* Build up package and start transfer */
write32_to_FPGA(CHANNEL_3_TARGET_ADDRESS, trb_address);
write32_to_FPGA(CHANNEL_3_SENDER_ERROR, 0x00000000);
status = trb_fifo_read(3, FIFO_MODE_REG_READ_MEM, data, dsize);
- unblockSignals();
-
if (unlockPorts() == -1) return -1;
if (status == -1) return status;
uint32_t value)
{
int status;
-
+
trb_errno = TRB_NONE;
if (lockPorts() == -1) return -1;
-
+
/* Init transfer */
if (trb_init_transfer(3) == -1) {
+ unlockPorts();
return -1;
}
fprintf(stderr, "Init_Transfer done.\n");
}
- blockSignals();
-
/* Build up package */
write32_to_FPGA(CHANNEL_3_TARGET_ADDRESS, trb_address);
write32_to_FPGA(CHANNEL_3_SENDER_ERROR, 0x00000000);
status = trb_fifo_read(3, FIFO_MODE_REG_WRITE, NULL, 0);
- unblockSignals();
-
if (unlockPorts() == -1) return -1;
return status;
/* Init transfer */
if (trb_init_transfer(3) == -1) {
+ unlockPorts();
return -1;
}
fprintf(stderr, "Init_Transfer done.\n");
}
- blockSignals();
-
/* Build up package */
write32_to_FPGA(CHANNEL_3_TARGET_ADDRESS, trb_address);
write32_to_FPGA(CHANNEL_3_SENDER_ERROR, 0x00000000);
status = trb_fifo_read(3, FIFO_MODE_REG_WRITE, NULL, 0);
- unblockSignals();
-
if (unlockPorts() == -1) return -1;
return status;
/* Init transfer */
if (trb_init_transfer(3) == -1) {
+ unlockPorts();
return -1;
}
fprintf(stderr, "Init_Transfer done.\n");
}
- blockSignals();
-
/* Build up package and start transfer */
write32_to_FPGA(CHANNEL_3_TARGET_ADDRESS, trb_address);
write32_to_FPGA(CHANNEL_3_SENDER_ERROR, 0x00000000);
status = trb_fifo_read(3, FIFO_MODE_UID, (uint32_t*)data, dsize);
- unblockSignals();
-
if (unlockPorts() == -1) return -1;
if ((status > 0) && (status % 4 != 0)) {
}
if (lockPorts() == -1) return -1;
-
+
/* Init transfer */
if (trb_init_transfer(3) == -1) {
+ unlockPorts();
return -1;
}
fprintf(stderr, "Init_Transfer done.\n");
}
- blockSignals();
-
/* Build up package and start transfer */
write32_to_FPGA(CHANNEL_3_TARGET_ADDRESS, 0xffff); /* always broadcast */
write32_to_FPGA(CHANNEL_3_SENDER_ERROR, 0x00000000);
}
status = trb_fifo_read(3, FIFO_MODE_SET_ADDRESS, NULL, 0);
-
- unblockSignals();
-
+
if (unlockPorts() == -1) return -1;
if (status == -1) return -1;
if (data == NULL) return -1;
if (lockPorts() == -1) return -1;
-
+
/* Init transfer IPU Channel */
if (trb_init_transfer(1) == -1) {
+ unlockPorts();
return -1;
}
fprintf(stderr, "Init_Transfer done.\n");
}
- blockSignals();
-
/* Prepare IPU channel */
write32_to_FPGA(CHANNEL_1_SENDER_ERROR, (((uint32_t)trg_info << 24) |
((uint32_t)trg_random << 16) |
status = trb_fifo_read(1, FIFO_MODE_IPU_DATA, data, dsize);
- unblockSignals();
-
if (unlockPorts() == -1) return -1;
return status;
/* Init transfer trigger */
if (trb_init_transfer(0) == -1) {
+ unlockPorts();
return -1;
}
fprintf(stderr, "Init_Transfer done.\n");
}
- blockSignals();
-
/* Prepare trigger channel */
write32_to_FPGA(CHANNEL_0_SENDER_ERROR, (((uint32_t)trg_info << 24) |
((uint32_t)trg_random << 16) |
/* Check for replay packets (trigger) */
status = trb_fifo_read(0, FIFO_MODE_NONE, NULL, 0);
-
- unblockSignals();
-
+
if (unlockPorts() == -1) return -1;
-
+
if (status == -1) return -1;
return 0;
/* Init transfer slowcontrol */
if (trb_init_transfer(3) == -1) {
+ unlockPorts();
return -1;
}
/* Init transfer trigger */
if (trb_init_transfer(0) == -1) {
+ unlockPorts();
return -1;
}
fprintf(stderr, "Init_Transfer done.\n");
}
- blockSignals();
-
/* Prepare trigger channel */
write32_to_FPGA(CHANNEL_0_SENDER_ERROR, (((uint32_t)trg_info << 24) |
((uint32_t)trg_random << 16) |
status = trb_fifo_read(3, FIFO_MODE_NONE, NULL, 0);
if (status == -1) {
fifo_flush(0);
- unblockSignals();
- if (unlockPorts() == -1) return -1;
+ unlockPorts();
return -1;
}
/* Check for replay packets (trigger) */
status = trb_fifo_read(0, FIFO_MODE_NONE, NULL, 0);
-
- unblockSignals();
-
+
if (unlockPorts() == -1) return -1;
if (status == -1) return -1;