formatting

This commit is contained in:
maliakal_d 2022-11-18 14:26:58 +01:00
parent 2dcf4a7144
commit f6241f7a5e
5 changed files with 209 additions and 255 deletions

View File

@ -1,20 +1,17 @@
// SPDX-License-Identifier: LGPL-3.0-or-other // SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package // Copyright (C) 2021 Contributors to the SLS Detector Package
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h> #include <errno.h>
#include <math.h>
#include <fcntl.h> #include <fcntl.h>
#include <math.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <unistd.h> #include <unistd.h>
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -26,84 +23,85 @@ int main(int argc, char *argv[]) {
int bit[64]; int bit[64];
FILE *fdin; FILE *fdin;
int nb=2; int nb = 2;
int off=0; int off = 0;
int ioff=0; int ioff = 0;
int dr=24; int dr = 24;
int idr=0; int idr = 0;
int ib=0; int ib = 0;
int iw=0; int iw = 0;
bit[0]=19; bit[0] = 19;
bit[1]=8; bit[1] = 8;
// for (iarg=0; iarg<argc; iarg++) printf("%d %s\n",iarg, argv[iarg]); // for (iarg=0; iarg<argc; iarg++) printf("%d %s\n",iarg, argv[iarg]);
if (argc<2) printf("Error: usage is %s fname [dr off b0 b1 bn]\n"); if (argc < 2)
printf("Error: usage is %s fname [dr off b0 b1 bn]\n");
if (argc>2) dr=atoi(argv[2]); if (argc > 2)
if (argc>3) off=atoi(argv[3]); dr = atoi(argv[2]);
if (argc>4) { if (argc > 3)
for (ib=0; ib<64; ib++) { off = atoi(argv[3]);
if (argc>4+ib) { if (argc > 4) {
bit[ib]=atoi(argv[4+ib]); for (ib = 0; ib < 64; ib++) {
if (argc > 4 + ib) {
bit[ib] = atoi(argv[4 + ib]);
nb++; nb++;
} }
} }
} }
idr=0; idr = 0;
for (ib=0; ib<nb; ib++) { for (ib = 0; ib < nb; ib++) {
val[ib]=0; val[ib] = 0;
} }
fdin = fopen(argv[1], "rb");
fdin=fopen(argv[1],"rb"); if (fdin == NULL) {
if (fdin==NULL) { printf("Cannot open input file %s for reading\n", argv[1]);
printf("Cannot open input file %s for reading\n",argv[1]);
return 200; return 200;
} }
while (fread((void*)&word, 8, 1, fdin)) { while (fread((void *)&word, 8, 1, fdin)) {
// printf("%llx\n",word); // printf("%llx\n",word);
if (ioff<off) ioff++; if (ioff < off)
ioff++;
else { else {
for (ib=0; ib<nb; ib++) { for (ib = 0; ib < nb; ib++) {
if (word&(1<<bit[ib])) val[ib]|=(1<<idr); if (word & (1 << bit[ib]))
val[ib] |= (1 << idr);
} }
idr++; idr++;
if (idr==dr) { if (idr == dr) {
idr=0; idr = 0;
fprintf(stdout,"%d\t",iw++); fprintf(stdout, "%d\t", iw++);
for (ib=0; ib<nb; ib++) { for (ib = 0; ib < nb; ib++) {
#ifdef HEX #ifdef HEX
fprintf(stdout,"%08llx\t",val[ib]); fprintf(stdout, "%08llx\t", val[ib]);
#else #else
fprintf(stdout,"%lld\t",val[ib]); fprintf(stdout, "%lld\t", val[ib]);
#endif #endif
val[ib]=0; val[ib] = 0;
} }
fprintf(stdout,"\n"); fprintf(stdout, "\n");
} }
} }
} }
if (idr!=0) { if (idr != 0) {
fprintf(stdout,"%d\t",iw++); fprintf(stdout, "%d\t", iw++);
for (ib=0; ib<nb; ib++) { for (ib = 0; ib < nb; ib++) {
#ifdef HEX #ifdef HEX
fprintf(stdout,"%08llx\t",val[ib]); fprintf(stdout, "%08llx\t", val[ib]);
#else #else
fprintf(stdout,"%lld\t",val[ib]); fprintf(stdout, "%lld\t", val[ib]);
#endif #endif
val[ib]=0; val[ib] = 0;
} }
fprintf(stdout,"\n"); fprintf(stdout, "\n");
} }
fclose(fdin); fclose(fdin);

View File

@ -3,44 +3,43 @@
/**************************************************************************** /****************************************************************************
usage to generate a patter test.pat from test.p usage to generate a patter test.pat from test.p
gcc -DINFILE="\"test.p\"" -DOUTFILE="\"test.pat\"" -o test.exe generator.c ; ./test.exe ; rm test.exe gcc -DINFILE="\"test.p\"" -DOUTFILE="\"test.pat\"" -o test.exe generator.c ;
./test.exe ; rm test.exe
*************************************************************************/ *************************************************************************/
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h> #include <errno.h>
#include <math.h>
#include <fcntl.h> #include <fcntl.h>
#include <math.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <unistd.h> #include <unistd.h>
#define MAXLOOPS 6 #define MAXLOOPS 6
#define MAXTIMERS 6 #define MAXTIMERS 6
#define MAXWORDS 8191 #define MAXWORDS 8191
uint64_t pat = 0;
uint64_t iopat = 0;
uint64_t clkpat = 0;
unsigned iaddr = 0;
uint64_t pat=0; unsigned waitaddr[MAXTIMERS] = {MAXWORDS, MAXWORDS, MAXWORDS,
uint64_t iopat=0; MAXWORDS, MAXWORDS, MAXWORDS};
uint64_t clkpat=0; unsigned startloopaddr[MAXLOOPS] = {MAXWORDS, MAXWORDS, MAXWORDS,
MAXWORDS, MAXWORDS, MAXWORDS};
unsigned iaddr=0; unsigned stoploopaddr[MAXLOOPS] = {MAXWORDS, MAXWORDS, MAXWORDS,
unsigned waitaddr[MAXTIMERS]={MAXWORDS,MAXWORDS,MAXWORDS, MAXWORDS, MAXWORDS, MAXWORDS}; MAXWORDS, MAXWORDS, MAXWORDS};
unsigned startloopaddr[MAXLOOPS]={MAXWORDS,MAXWORDS,MAXWORDS, MAXWORDS, MAXWORDS, MAXWORDS}; unsigned start = 0, stop = 0;
unsigned stoploopaddr[MAXLOOPS]={MAXWORDS,MAXWORDS,MAXWORDS, MAXWORDS, MAXWORDS, MAXWORDS}; uint64_t waittime[MAXTIMERS] = {0, 0, 0, 0, 0, 0};
unsigned start=0, stop=0; unsigned nloop[MAXLOOPS] = {0, 0, 0, 0, 0, 0};
uint64_t waittime[MAXTIMERS]={0,0,0,0,0,0};
unsigned nloop[MAXLOOPS]={0,0,0,0,0,0};
char infile[10000], outfile[10000]; char infile[10000], outfile[10000];
@ -48,125 +47,93 @@ FILE *fd, *fd1;
uint64_t PAT[MAXWORDS]; uint64_t PAT[MAXWORDS];
int iopat_enable = 0; int iopat_enable = 0;
int i, ii, iii, j, jj, jjj, pixx, pixy, memx, memy, muxout, memclk, colclk,
rowclk, muxclk, memcol, memrow, loopcounter;
int i,ii,iii,j,jj,jjj,pixx,pixy,memx,memy,muxout,memclk,colclk,rowclk,muxclk,memcol,memrow,loopcounter; void setstart() { start = iaddr; }
void setstart() void setstop() { stop = iaddr; }
{
start=iaddr;
}
void setstop() void setinput(int bit) {
{ uint64_t mask = 1;
stop=iaddr; mask = mask << bit;
}
void setinput(int bit)
{
uint64_t mask=1;
mask=mask<<bit;
iopat &= ~mask; iopat &= ~mask;
iopat_enable = 1; iopat_enable = 1;
} }
void setoutput(int bit) void setoutput(int bit) {
{ uint64_t mask = 1;
uint64_t mask=1; mask = mask << bit;
mask=mask<<bit;
iopat |= mask; iopat |= mask;
iopat_enable = 1; iopat_enable = 1;
} }
void clearbit(int bit) void clearbit(int bit) {
{ uint64_t mask = 1;
uint64_t mask=1; mask = mask << bit;
mask=mask<<bit;
pat &= ~mask; pat &= ~mask;
} }
void setbit(int bit) void setbit(int bit) {
{ uint64_t mask = 1;
uint64_t mask=1; mask = mask << bit;
mask=mask<<bit;
pat |= mask; pat |= mask;
} }
int checkbit(int bit) int checkbit(int bit) {
{ uint64_t mask = 1;
uint64_t mask=1; mask = mask << bit;
mask=mask<<bit; return (pat & mask) >> bit;
return (pat & mask ) >>bit;
} }
void setstartloop(int iloop) void setstartloop(int iloop) {
{ if (iloop >= 0 && iloop < MAXLOOPS) {
if (iloop>=0 && iloop<MAXLOOPS) startloopaddr[iloop] = iaddr;
{
startloopaddr[iloop]=iaddr;
} }
} }
void setstoploop(int iloop) {
void setstoploop(int iloop) if (iloop >= 0 && iloop < MAXLOOPS) {
{ stoploopaddr[iloop] = iaddr;
if (iloop>=0 && iloop<MAXLOOPS)
{
stoploopaddr[iloop]=iaddr;
} }
} }
void setnloop(int iloop, int n) {
void setnloop(int iloop, int n) if (iloop >= 0 && iloop < MAXLOOPS) {
{ nloop[iloop] = n;
if (iloop>=0 && iloop<MAXLOOPS)
{
nloop[iloop]=n;
} }
} }
void setwaitpoint(int iloop) void setwaitpoint(int iloop) {
{ if (iloop >= 0 && iloop < MAXTIMERS) {
if (iloop>=0 && iloop<MAXTIMERS) waitaddr[iloop] = iaddr;
{
waitaddr[iloop]=iaddr;
} }
} }
void setwaittime(int iloop, uint64_t t) {
void setwaittime(int iloop, uint64_t t) if (iloop >= 0 && iloop < MAXTIMERS) {
{ waittime[iloop] = t;
if (iloop>=0 && iloop<MAXTIMERS)
{
waittime[iloop]=t;
} }
} }
void pw() {
void pw() if (iaddr < MAXWORDS) {
{ PAT[iaddr] = pat;
if (iaddr<MAXWORDS)
{
PAT[iaddr]= pat;
} }
fprintf(fd,"patword 0x%04x 0x%016llx\n",iaddr, pat); fprintf(fd, "patword 0x%04x 0x%016llx\n", iaddr, pat);
iaddr++; iaddr++;
if (iaddr>=MAXWORDS) if (iaddr >= MAXWORDS) {
{ printf("ERROR: too many word in the pattern (%d instead of %d)!", iaddr,
printf("ERROR: too many word in the pattern (%d instead of %d)!",iaddr, MAXWORDS); MAXWORDS);
} }
} }
int parseCommand(int clk, int cmdbit, int cmd, int length) int parseCommand(int clk, int cmdbit, int cmd, int length) {
{
int ibit; int ibit;
clearbit(clk); clearbit(clk);
for (ibit=0; ibit<length; ibit++) for (ibit = 0; ibit < length; ibit++) {
{ if (cmd & (1 >> ibit)) {
if (cmd&(1>>ibit))
{
setbit(cmdbit); setbit(cmdbit);
} } else {
else
{
clearbit(cmdbit); clearbit(cmdbit);
} }
pw(); pw();
@ -177,45 +144,39 @@ int parseCommand(int clk, int cmdbit, int cmd, int length)
} }
}; };
int main() { int main() {
int iloop=0; int iloop = 0;
fd=fopen(OUTFILE,"w"); fd = fopen(OUTFILE, "w");
#include INFILE #include INFILE
fprintf(fd,"patlimits 0x%04x 0x%04x\n",start, stop); fprintf(fd, "patlimits 0x%04x 0x%04x\n", start, stop);
if (iopat_enable == 1) if (iopat_enable == 1) {
{ fprintf(fd, "patioctrl 0x%016llx\n", iopat);
fprintf(fd,"patioctrl 0x%016llx\n",iopat);
} }
for (iloop=0; iloop<MAXLOOPS; iloop++) for (iloop = 0; iloop < MAXLOOPS; iloop++) {
{ if ((startloopaddr[iloop] != MAXWORDS) &&
if ( (startloopaddr[iloop] != MAXWORDS) && (stoploopaddr[iloop] != MAXWORDS) ) (stoploopaddr[iloop] != MAXWORDS)) {
{ fprintf(fd, "patloop %d 0x%04x 0x%04x\n", iloop,
fprintf(fd,"patloop %d 0x%04x 0x%04x\n",iloop, startloopaddr[iloop], stoploopaddr[iloop]); startloopaddr[iloop], stoploopaddr[iloop]);
if (stoploopaddr[iloop]<= startloopaddr[iloop]) if (stoploopaddr[iloop] <= startloopaddr[iloop]) {
{ nloop[iloop] = 0;
nloop[iloop]=0;
} }
fprintf(fd,"patnloop %d %u\n",iloop, nloop[iloop]); fprintf(fd, "patnloop %d %u\n", iloop, nloop[iloop]);
} }
} }
for (iloop=0; iloop<MAXTIMERS; iloop++) for (iloop = 0; iloop < MAXTIMERS; iloop++) {
{ if (waitaddr[iloop] != MAXWORDS) {
if (waitaddr[iloop] != MAXWORDS) fprintf(fd, "patwait %d 0x%04x\n", iloop, waitaddr[iloop]);
{ fprintf(fd, "patwaittime %d %llu\n", iloop, waittime[iloop]);
fprintf(fd,"patwait %d 0x%04x\n",iloop, waitaddr[iloop]);
fprintf(fd,"patwaittime %d %llu\n",iloop, waittime[iloop]);
} }
} }
fclose(fd); fclose(fd);
fd1=fopen(OUTFILEBIN,"w"); fd1 = fopen(OUTFILEBIN, "w");
fwrite(PAT,sizeof(uint64_t),iaddr, fd1); fwrite(PAT, sizeof(uint64_t), iaddr, fd1);
fclose(fd1); fclose(fd1);
return 0; return 0;

View File

@ -2461,7 +2461,6 @@ int startStateMachine() {
Feb_Control_Get_Counter_Bit())); Feb_Control_Get_Counter_Bit()));
Feb_Control_PrepareForAcquisition(); Feb_Control_PrepareForAcquisition();
LOG(logINFO, ("Acquisition started bit toggled\n")); LOG(logINFO, ("Acquisition started bit toggled\n"));
int ret = OK, prev_flag; int ret = OK, prev_flag;
// get the DAQ toggle bit // get the DAQ toggle bit

View File

@ -159,8 +159,7 @@ int sharedMemory_initialize() {
return FAIL; return FAIL;
} }
if (pthread_mutex_init(&(shm->lockAcqFlag), &lockAcqFlagAttribute) != if (pthread_mutex_init(&(shm->lockAcqFlag), &lockAcqFlagAttribute) != 0) {
0) {
LOG(logERROR, ("Failed to initialize pthread_mutex_t lockAcqFlag for " LOG(logERROR, ("Failed to initialize pthread_mutex_t lockAcqFlag for "
"shared memory\n")); "shared memory\n"));
return FAIL; return FAIL;
@ -293,7 +292,5 @@ void sharedMemory_unlockLocalLink() {
void sharedMemory_lockAcqFlag() { pthread_mutex_lock(&(shm->lockAcqFlag)); } void sharedMemory_lockAcqFlag() { pthread_mutex_lock(&(shm->lockAcqFlag)); }
void sharedMemory_unlockAcqFlag() { void sharedMemory_unlockAcqFlag() { pthread_mutex_unlock(&(shm->lockAcqFlag)); }
pthread_mutex_unlock(&(shm->lockAcqFlag));
}
#endif #endif

View File

@ -14,8 +14,7 @@ namespace sls {
#define gettid() syscall(SYS_gettid) #define gettid() syscall(SYS_gettid)
#endif #endif
Arping::Arping() {}
Arping::Arping(){}
Arping::~Arping() { Arping::~Arping() {
if (IsRunning()) { if (IsRunning()) {