Anna's modifications

This commit is contained in:
2017-08-11 15:52:08 +02:00
parent 0b6aeac364
commit 52e1bd32b9
13 changed files with 623 additions and 10 deletions

View File

@ -0,0 +1 @@
Makefile.ctb

View File

@ -0,0 +1 @@
export PATH=/afs/psi.ch/project/sls_det_firmware/jungfrau_software/uClinux-2010_64bit/bfin-uclinux/bin:$PATH

View File

@ -0,0 +1,150 @@
#include "blackfin.h"
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/time.h>
#include <string.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <time.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#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); */
/* } */
/* **\/ */

View File

@ -0,0 +1,19 @@
#ifndef BLACKFIN_H
#define BLACKFIN_H
#define CSP0 0x20200000
#define MEM_SIZE 0x100000
#include <sys/types.h>
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

View File

@ -0,0 +1,58 @@
// Converts POF files into RAW files for flashing
#include <stdio.h>
#include <stdlib.h>
// 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) ) >> 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;
}

View File

@ -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

View File

@ -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

View File

@ -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<<cnv_bit);
bus_w(ADC_WRITE_REG,valw);
usleep(20);
valw=0;
bus_w(ADC_WRITE_REG,(valw));
usleep(20);
for (ibit=0; ibit<14; ibit++) {
obit=((codata >> (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<<sck_bit));
usleep(20);
bus_w(ADC_WRITE_REG,valw);
}
// printf("\n");
bus_w(ADC_WRITE_REG,0);
/* //convert */
valw=(1<<cnv_bit);
bus_w(ADC_WRITE_REG,valw);
usleep(20);
valw=0;
bus_w(ADC_WRITE_REG,(valw));
usleep(20);
return 0;
}
int prepareSlowADC(int ichan) {
// u_int16_t vv=0x3c40;
// u_int16_t codata=( 1<<13) | (7<<10) | (7<<7) | (1<<6) | (0<<3) | (2<<1) | 1;
u_int16_t codata=(1<<13) | (7<<10) | (ichan<<7) | (1<<6) | (0<<3) | (0<<1) | 1; //read single channel
if (ichan<0) codata=( 1<<13) | (3<<10) | (7<7) | (1<<6) | (0<<3) | (0<<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<<cnv_bit);
bus_w(ADC_WRITE_REG,valw);
usleep(20);
valw=0;
bus_w(ADC_WRITE_REG,(valw));
usleep(20);
for (ibit=0; ibit<14; ibit++) {
obit=((codata >> (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<<sck_bit));
usleep(20);
bus_w(ADC_WRITE_REG,valw);
}
// printf("\n");
bus_w(ADC_WRITE_REG,0);
/* //convert */
valw=(1<<cnv_bit);
bus_w(ADC_WRITE_REG,valw);
usleep(20);
valw=0;
bus_w(ADC_WRITE_REG,(valw));
usleep(20);
return 0;
}
int readSlowADC(int ichan) {
// u_int16_t vv=0x3c40;
// u_int16_t codata=( 1<<13) | (7<<10) | (ichan<<7) | (1<<6) | (0<<3) | (0<<1) | 1; //read single channel
u_int32_t valw;
int i, obit;
// int cnv_bit=16, sdi_bit=17, sck_bit=18;
int cnv_bit=10, sdi_bit=8, sck_bit=9;
int oval=0;
printf("DAC index is %d\n",ichan);
if (ichan<-1 || ichan>7)
return -1;
prepareSlowADC(ichan);
/* printf("Codata is %04x\n",codata); */
/* /\* //convert *\/ */
/* valw=(1<<cnv_bit); */
/* bus_w(ADC_WRITE_REG,valw); */
/* usleep(20); */
/* valw=0; */
/* bus_w(ADC_WRITE_REG,(valw)); */
/* usleep(20); */
/* for (ibit=0; ibit<14; ibit++) { */
/* obit=((codata >> (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<<sck_bit)); */
/* usleep(20); */
/* bus_w(ADC_WRITE_REG,valw); */
/* } */
/* // printf("\n"); */
/* bus_w(ADC_WRITE_REG,0); */
for (ichan=0; ichan<9; ichan++) {
/* //convert */
valw=(1<<cnv_bit);
bus_w(ADC_WRITE_REG,valw);
usleep(20);
valw=0;
bus_w(ADC_WRITE_REG,(valw));
usleep(20);
// printf("Channel %d ",ichan);
//read
oval=0;
for (i=0;i<16;i++) {
obit=bus_r16(SLOW_ADC_REG)&0x1;
// printf("%d",obit);
//write data (i)
// usleep(0);
oval|=obit<<(15-i);
//cldwn
valw=0;
bus_w(ADC_WRITE_REG,valw);
bus_w(ADC_WRITE_REG,valw|(1<<sck_bit));
usleep(20);
bus_w(ADC_WRITE_REG,valw);
usleep(20);
}
printf("\t");
printf("Value %d is %d (%d mV)\n",ichan, oval,2500*oval/65535);
}
printf("Value %d is %d\n",ichan, oval);
return 2500*oval/65535;
}

View File

@ -0,0 +1,10 @@
#ifndef SLOW_ADC_H
#define SLOW_ADC_H
int prepareSlowADCSeq();
int prepareSlowADC(int ichan);
int readSlowADC(int ichan);
#endif