ad9915.h 3.93 KB
/*
dds initialisation et SPI 
*/

#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
/* memory management */
#include <sys/mman.h>
#include "spi.h"
#include <string.h>
#include <math.h>
#include <time.h>


static const char CFRAddress[] = {0x00,0x01,0x02,0x03};

static const char CFR1Start[] ={0x00, 0x01, 0x00, 0x0a};
//static const char CFR1Start[] ={0x00, 0x01, 0x01, 0x08}; //with osk enable
static const char CFR2Start[] ={0x00, 0x80, 0x09, 0x00}; //0x80 enable prof mode
static const char CFR3Start[] = {0x00, 0x00, 0x19, 0x1C};
static const char CFR4Start[] =  {0x00, 0x05, 0x21, 0x20}; 
//static const char CFR4Start[] =  {0x20, 0x21, 0x05, 0x00};


static const char USR0Address = 0x1B;
static const char FTW0Address = 0x0b; //profile 0 ftw
static const char PA0Address = 0x0c; //profile 0 

static const char DACCalEnable[] = {0x01, 0x05, 0x21, 0x20};  //Command to enable the DAC Cal, should be 0x01XXXXXX, where X is the last 6 digits of CFR4Start


void Send_Reset(int f_dds);
void Send_IO_Update (int f_dds);    //Send the update to set the control registers
void write_register (int fd, unsigned char addr, unsigned char d3, unsigned char d2, unsigned char d1, unsigned char d0);
void read_register (int fd, unsigned char addr, uint32_t *readword);
void read_register_ini (int fd,unsigned char addr);
void Initialize_DDS (int fd, int f_dds);
void Calibrate_DAC(int fd, int f_dds);
void basic_setup(int fd, int f_dds, uint16_t ampWord, uint16_t phaseWord);
void modulus_setup(int fd, int f_dds); 
void setFreqMM(int fd, int f_dds, unsigned int ftw, unsigned int A, unsigned int B);
void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord);
void checkSize(void);
int openAndSetDdsFreq( char * device, char * gpio_update, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord);
int receiveParameterFromPythonServer(char * device, double f_clk, double f_out);
int setDdsFreqFull ( int fd, int f_dds, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord);

//------------ DRCTL

void Send_CTRL_UP(int fp);
void Send_CTRL_DOWN(int fp);
void Send_HOLD(int fp);
void Send_UNHOLD(int fp);
int testRampFreq(int fd, int f_dds, int fp);

//-------Profile register mode

int InitialisationProfile (int fd,int f_dds);
int PutFrequencyAmpPhaseWord(int fd, int f_dds, double fout, double fclk,double amp, double phase);


int PutFrequencyWord(int fd, int f_dds, double freq);//Attention uniquement valable pour fclk = 1 GHz
int PutPhaseWord(int fd, int f_dds, double phase);
int PutAmpWord(int fd, int f_dds, double amplitude);

//fonctions rampes hardwres

int FrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown);
int ContinueFrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown);
int AmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown);
int ContinueAmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown);
int PhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown);
int ContinuePhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown);

//fin fonctions rampes hardwares

// fonctions rampes softwares

int RampAmpFromSoft(int fd, int f_dds,double DeltaTimeUp,double AIni, double AFin);

int RampPhaseFromSoft(int fd, int f_dds,double DeltaTimeUp,double PhiIni, double PhiFin);

// fin fonctoins rampes softwares