diff --git a/slsDetectorSoftware/jctbDetectorServer/Makefile b/slsDetectorSoftware/jctbDetectorServer/Makefile new file mode 120000 index 000000000..ce28cc2a0 --- /dev/null +++ b/slsDetectorSoftware/jctbDetectorServer/Makefile @@ -0,0 +1 @@ +Makefile.ctb \ No newline at end of file diff --git a/slsDetectorSoftware/jctbDetectorServer/bf_init.sh b/slsDetectorSoftware/jctbDetectorServer/bf_init.sh new file mode 100644 index 000000000..88eccadb4 --- /dev/null +++ b/slsDetectorSoftware/jctbDetectorServer/bf_init.sh @@ -0,0 +1 @@ +export PATH=/afs/psi.ch/project/sls_det_firmware/jungfrau_software/uClinux-2010_64bit/bfin-uclinux/bin:$PATH diff --git a/slsDetectorSoftware/jctbDetectorServer/blackfin.c b/slsDetectorSoftware/jctbDetectorServer/blackfin.c new file mode 100644 index 000000000..1771372e5 --- /dev/null +++ b/slsDetectorSoftware/jctbDetectorServer/blackfin.c @@ -0,0 +1,150 @@ +#include "blackfin.h" + + #include + #include + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include +#include "server_defs.h" +#include "registers_m.h" + +//for memory mapping +u_int32_t CSP0BASE; + +u_int16_t volatile *values; + +int mapCSP0(void) { + printf("Mapping memory\n"); +#ifndef VIRTUAL + int fd; + fd = open("/dev/mem", O_RDWR | O_SYNC, 0); + if (fd == -1) { + printf("\nCan't find /dev/mem!\n"); + return FAIL; + } + printf("/dev/mem opened\n"); + + CSP0BASE = (u_int32_t)mmap(0, MEM_SIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, CSP0); + if (CSP0BASE == (u_int32_t)MAP_FAILED) { + printf("\nCan't map memmory area!!\n"); + return FAIL; + } + printf("CSP0 mapped\n"); + +#endif +#ifdef VIRTUAL + CSP0BASE = malloc(MEM_SIZE); + printf("memory allocated\n"); +#endif +#ifdef SHAREDMEMORY + if ( (res=inism(SMSV))<0) { + printf("error attaching shared memory! %i",res); + return FAIL; + } +#endif + printf("CSPObase is 0x%08x \n",CSP0BASE); + printf("CSPOBASE=from %08x to %08x\n",CSP0BASE,CSP0BASE+MEM_SIZE); + + u_int32_t address; + address = FIFO_DATA_REG;//_OFF; + //values=(u_int32_t*)(CSP0BASE+address*2); + values=(u_int16_t*)(CSP0BASE+address*2); + printf("statusreg=%08x\n",bus_r(STATUS_REG)); + printf("\n\n"); + return OK; +} + +u_int16_t bus_r16(u_int32_t offset){ + volatile u_int16_t *ptr1; + ptr1=(u_int16_t*)(CSP0BASE+offset*2); + return *ptr1; +} + +u_int16_t bus_w16(u_int32_t offset, u_int16_t data) { + volatile u_int16_t *ptr1; + ptr1=(u_int16_t*)(CSP0BASE+offset*2); + *ptr1=data; + return OK; +} + + +u_int32_t bus_w(u_int32_t offset, u_int32_t data) { + volatile u_int32_t *ptr1; + + ptr1=(u_int32_t*)(CSP0BASE+offset*2); + *ptr1=data; + + return OK; +} + + +u_int32_t bus_r(u_int32_t offset) { + volatile u_int32_t *ptr1; + ptr1=(u_int32_t*)(CSP0BASE+offset*2); + return *ptr1; +} + +// program dacq settings + +int64_t set64BitReg(int64_t value, int aLSB, int aMSB){ + int64_t v64; + u_int32_t vLSB,vMSB; + if (value!=-1) { + vLSB=value&(0xffffffff); + bus_w(aLSB,vLSB); + v64=value>> 32; + vMSB=v64&(0xffffffff); + bus_w(aMSB,vMSB); + // printf("Wreg64(%x,%x) %08x %08x %016llx\n", aLSB>>11, aMSB>>11, vLSB, vMSB, value); + } + return get64BitReg(aLSB, aMSB); + +} + +int64_t get64BitReg(int aLSB, int aMSB){ + int64_t v64; + u_int32_t vLSB,vMSB; + vLSB=bus_r(aLSB); + vMSB=bus_r(aMSB); + v64=vMSB; + v64=(v64<<32) | vLSB; + + // printf("reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, v64); + + return v64; +} + +/* /\** */ +/* /\** ramType is DARK_IMAGE_REG or GAIN_IMAGE_REG *\/ */ +/* u_int16_t ram_w16(u_int32_t ramType, int adc, int adcCh, int Ch, u_int16_t data) { */ +/* unsigned int adr = (ramType | adc << 8 | adcCh << 5 | Ch ); */ +/* // printf("Writing to addr:%x\n",adr); */ +/* return bus_w16(adr,data); */ +/* } */ + +/* /\** ramType is DARK_IMAGE_REG or GAIN_IMAGE_REG *\/ */ +/* u_int16_t ram_r16(u_int32_t ramType, int adc, int adcCh, int Ch){ */ +/* unsigned int adr = (ramType | adc << 8 | adcCh << 5 | Ch ); */ +/* // printf("Reading from addr:%x\n",adr); */ +/* return bus_r16(adr); */ +/* } */ +/* **\/ */ diff --git a/slsDetectorSoftware/jctbDetectorServer/blackfin.h b/slsDetectorSoftware/jctbDetectorServer/blackfin.h new file mode 100644 index 000000000..3284fe183 --- /dev/null +++ b/slsDetectorSoftware/jctbDetectorServer/blackfin.h @@ -0,0 +1,19 @@ +#ifndef BLACKFIN_H +#define BLACKFIN_H + +#define CSP0 0x20200000 +#define MEM_SIZE 0x100000 + + #include +int mapCSP0(void); + +u_int16_t bus_r16(u_int32_t offset); +u_int16_t bus_w16(u_int32_t offset, u_int16_t data);//aldos function +u_int32_t bus_w(u_int32_t offset, u_int32_t data); +u_int32_t bus_r(u_int32_t offset); + +int64_t set64BitReg(int64_t value, int aLSB, int aMSB); +int64_t get64BitReg(int aLSB, int aMSB); + + +#endif diff --git a/slsDetectorSoftware/jctbDetectorServer/convert_pof_to_raw.c b/slsDetectorSoftware/jctbDetectorServer/convert_pof_to_raw.c new file mode 100644 index 000000000..661ab2bd9 --- /dev/null +++ b/slsDetectorSoftware/jctbDetectorServer/convert_pof_to_raw.c @@ -0,0 +1,58 @@ +// Converts POF files into RAW files for flashing + +#include +#include + +// Warning: This program is for testing only. +// It makes some assumptions regarding the pof file and the flash size that might be wrong. +// It also overwrites the destination file without any hesitation. +// Handle with care. + +int main(int argc, char* argv[]) +{ + FILE* src; + FILE* dst; + int x; + int y; + int i; + int filepos; + + if (argc < 3) + { + printf("%s Sourcefile Destinationfile\n",argv[0]); + return -1; + } + + src = fopen(argv[1],"rb"); + dst = fopen(argv[2],"wb"); + + // Remove header (0...11C) + for (filepos=0; filepos < 0x11C; filepos++) + fgetc(src); + + // Write 0x80 times 0xFF (0...7F) + for (filepos=0; filepos < 0x80; filepos++) + fputc(0xFF,dst); + + // Swap bits and write to file + for (filepos=0x80; filepos < 0x1000000; filepos++) + { + x = fgetc(src); + if (x < 0) break; + + y=0; + for (i=0; i < 8; i++) + y=y| ( (( x & (1<> i) << (7-i) ); // This swaps the bits + + fputc(y,dst); + } + if (filepos < 0x1000000) + printf("ERROR: EOF before end of flash\n"); + + printf("To flash the file in Linux do:\n"); + printf(" cat /proc/mtd (to findout the right mtd)\n"); + printf(" flash_eraseall /dev/mtdX\n"); + printf(" cat file > /dev/mtdX\n"); + + return 0; +} diff --git a/slsDetectorSoftware/jctbDetectorServer/get_server.sh b/slsDetectorSoftware/jctbDetectorServer/get_server.sh new file mode 100755 index 000000000..b66a7ac2a --- /dev/null +++ b/slsDetectorSoftware/jctbDetectorServer/get_server.sh @@ -0,0 +1,12 @@ +#!/bin/sh +serv="pc8498" +f="jungfrauDetectorServerTest" +if [ "$#" -gt 0 ]; then + f=$1 +fi +if [ "$#" -gt 1 ]; then + serv=$2 +fi +tftp $serv -r $f -g +chmod a+xrw $f + diff --git a/slsDetectorSoftware/jctbDetectorServer/program_fpga.sh b/slsDetectorSoftware/jctbDetectorServer/program_fpga.sh new file mode 100755 index 000000000..15c18f1c8 --- /dev/null +++ b/slsDetectorSoftware/jctbDetectorServer/program_fpga.sh @@ -0,0 +1,30 @@ +#!/bin/sh +serv="pc8498" +f="Jungfrau_CTB.rawbin" +if [ "$#" -gt 0 ]; then + f=$1 +fi +if [ "$#" -gt 1 ]; then + serv=$2 +fi +echo "File is $f server is $serv" +mount -t tmpfs none /mnt/ + +cd /mnt/ +tftp -r $f -g $serv + +echo 7 > /sys/class/gpio/export +echo 9 > /sys/class/gpio/export +echo in > /sys/class/gpio/gpio7/direction +echo out > /sys/class/gpio/gpio9/direction + + +echo 0 > /sys/class/gpio/gpio9/value + + +flash_eraseall /dev/mtd3 +cat /mnt/$f > /dev/mtd3 + +echo 1 > /sys/class/gpio/gpio9/value +cat /sys/class/gpio/gpio7/value + diff --git a/slsDetectorSoftware/jctbDetectorServer/slow_adc.c b/slsDetectorSoftware/jctbDetectorServer/slow_adc.c new file mode 100644 index 000000000..34138159d --- /dev/null +++ b/slsDetectorSoftware/jctbDetectorServer/slow_adc.c @@ -0,0 +1,244 @@ +#include "firmware_funcs.h" +#include "registers_m.h" +#include "server_defs.h" + +int prepareSlowADCSeq() { + + // u_int16_t vv=0x3c40; + u_int16_t codata=( 1<<13) | (7<<10) | (7<<7) | (1<<6) | (0<<3) | (2<<1) | 1; + + u_int32_t valw; + int obit, ibit; + + // int cnv_bit=16, sdi_bit=17, sck_bit=18; + int cnv_bit=10, sdi_bit=8, sck_bit=9; + + // int oval=0; + + + printf("Codata is %04x\n",codata); + + /* //convert */ + valw=(1<> (13-ibit)) & 1); + // printf("%d",obit); + valw = obit << sdi_bit; + + bus_w(ADC_WRITE_REG,valw); + + usleep(20); + + bus_w(ADC_WRITE_REG,valw|(1<> (13-ibit)) & 1); + // printf("%d",obit); + valw = obit << sdi_bit; + + bus_w(ADC_WRITE_REG,valw); + + usleep(20); + + bus_w(ADC_WRITE_REG,valw|(1<7) + return -1; + + + prepareSlowADC(ichan); + + + /* printf("Codata is %04x\n",codata); */ + + /* /\* //convert *\/ */ + /* valw=(1<> (13-ibit)) & 1); */ + /* // printf("%d",obit); */ + /* valw = obit << sdi_bit; */ + + /* bus_w(ADC_WRITE_REG,valw); */ + + /* usleep(20); */ + + /* bus_w(ADC_WRITE_REG,valw|(1<(&slsDetector::setDAC, - detectors[idet],val, idac, mV, im, iret[idet])); - threadpool->add_task(task); + // cout << "*" << endl; + iret[idet]= new dacs_t(-1); + Task* task = new Task(new func4_t (&slsDetector::setDAC,detectors[idet],val, idac, mV, im, iret[idet])); + threadpool->add_task(task); } } + // cout << "Start" << endl; threadpool->startExecuting(); threadpool->wait_for_tasks_to_complete(); for(int idet=posmin; idet