Mercurial > hg > fxanalyse
changeset 203:4b7d1cb5100b
Remove unused DDS interface code
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Mon, 31 Mar 2014 17:03:38 +0200 |
parents | 040658369850 |
children | d7f91b9fb515 |
files | DDS4xAD9912.c DDS4xAD9912.h DDS4xAD9959.c DDS4xAD9959.h DDSBes.c DDSBes.h |
diffstat | 6 files changed, 0 insertions(+), 673 deletions(-) [+] |
line wrap: on
line diff
--- a/DDS4xAD9912.c Mon Mar 31 17:03:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,163 +0,0 @@ -#include <toolbox.h> -#include <ansi_c.h> -#include <utility.h> -#include <userint.h> -#include <tcpsupp.h> - -#include "DDS4xAD9912.h" - - -void DDS4xAD9912_Init(DDS4xAD9912_Data *dds, const char *host, double clock) -{ - memset(dds, 0, sizeof(DDS4xAD9912_Data)); - dds->port[0] = 6665; - dds->port[1] = 6666; - dds->port[2] = 6667; - dds->port[3] = 6668; - dds->host = StrDup(host); - dds->clock = clock; -} - - -//============================================================================== -// DDS4xAD9912_SendCmd -// -// FUNC : envoie une chaine de caracteres sur un port du serveur TCP/IP de la foxboard -// PARAM : DDSNum contient le numero de la DDS (1,2,3 ou 4) -// PARAM : Buffer contenant la chaîne de caractères à envoyer -// RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK -//============================================================================== -static int DDS4xAD9912_SendCmd(DDS4xAD9912_Data *dds, int channel, char *buffer) -{ - int rv; - unsigned int sock; - - rv = ConnectToTCPServer(&sock, dds->port[channel - 1], dds->host, NULL, 0, 0); - if (rv < 0) - return rv; - - rv = ClientTCPWrite(sock, buffer, strlen(buffer) + 1, 0); - - DisconnectFromTCPServer(sock); - - return rv; -} - - -//============================================================================== -// DDS4xAD9912_Reset -// -// FUNC : reset des 4 DDS -// PARAM : -// RETURN : 0 si le reset de la DDS 1 , DDS 2, DDS3 et DDS4 est OK -//============================================================================== - int DDS4xAD9912_Reset(DDS4xAD9912_Data *dds) - { - int channel, rv; - char request[256]; - - sprintf(request, "set;%i;%i", 1, 19); - - for (channel = 1; channel < 5; channel++) { - rv = DDS4xAD9912_SendCmd(dds, channel, request); - if (rv < 0) { - MessagePopup("DDS4xAD9912", "Reset failed"); - return -1; - } - dds->frequency[channel - 1] = 0.0; - } - return 0; -} - - -/* convert 64 bit integer into 6 bytes array */ -static inline void tobytes(unsigned long long x, unsigned char* bytes) -{ - /* 64 bits integer */ - for (int i = 0; i < 6; i++) - bytes[i] = (unsigned char)((x >> (i * 8)) & 0xFF); -} - - -#define WORD(freq, clock) ((double)(1ULL << 48) * (freq / clock)) - - -//============================================================================== -// DDS4xAD9912_SetFreq -// -// FUNC : sort une fréquence sur la DDS1 ,DDS2, DDS3 ou DDS4 -// PARAM : DDSNum contient le numero de la DDS (1, 2 , 3 ou 4) -// RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK -//============================================================================== -int DDS4xAD9912_SetFrequency(DDS4xAD9912_Data *dds, int channel, double frequency) -{ - int rv; - char request[256]; - unsigned char b[6]; - unsigned long long ftw = WORD(frequency, dds->clock); - - tobytes(ftw, b); - - sprintf(request, "set;%i;%i;%i;%i;%i;%i;%i;%i", 0, 10, b[5], b[4], b[3], b[2], b[1], b[0]); - rv = DDS4xAD9912_SendCmd(dds, channel, request); - if (rv < 0) { - MessagePopup("DDS", "SetFrequency function failed"); - return -1; - } - - sprintf(request, "set;%i;%i", 0, 18); - rv = DDS4xAD9912_SendCmd(dds, channel, request) ; - if (rv < 0) { - MessagePopup("DDS", "IOUpdate function failed"); - return -1; - } - - dds->frequency[channel - 1] = (double)ftw * dds->clock / (double)(1ULL << 48); - return 0; -} - - -/* - * ramp DDS frequency from `f1` to `f2` in steps of `fstep` - * with a delay of 0.01 seoconds after each step - */ -int DDS4xAD9912_RampFrequency2(DDS4xAD9912_Data *dds, int channel, double f1, double f2, double fstep) -{ - const double delay = 0.01; - - /* f2 > f1 */ - while ((f2 - f1) > fstep) { - f1 += fstep; - DDS4xAD9912_SetFrequency(dds, channel, f1); - Delay(delay); - } - - /* f2 < f1 */ - while ((f1 - f2) > fstep) { - f1 -= fstep; - DDS4xAD9912_SetFrequency(dds, channel, f1); - Delay(delay); - } - - /* final adjustment */ - DDS4xAD9912_SetFrequency(dds, channel, f2); - return 0; -} - - -/* - * ramp DDS frequency from the current frequency to `f2` in steps - * of `fstep` with a delay of 0.01 seoconds after each step - */ -int DDS4xAD9912_RampFrequency(DDS4xAD9912_Data *dds, int channel, double f2, double fstep) -{ - double f1 = DDS4xAD9912_GetFrequency(dds, channel); - return DDS4xAD9912_RampFrequency2(dds, channel, f1, f2, fstep); -} - - -double DDS4xAD9912_GetFrequency(DDS4xAD9912_Data *dds, int channel) -{ - return dds->frequency[channel - 1]; -} -
--- a/DDS4xAD9912.h Mon Mar 31 17:03:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -#ifndef __DDS4XAD9912_H__ -#define __DDS4XAD9912_H__ - -typedef struct { - char *host; - int port[4]; - double clock; - double frequency[4]; -} DDS4xAD9912_Data; - -#ifdef __cplusplus - extern "C" { -#endif - -double DDS4xAD9912_GetFrequency(DDS4xAD9912_Data *dds, int channel); -void DDS4xAD9912_Init(DDS4xAD9912_Data *d, const char *host, double clock); -int DDS4xAD9912_SetFrequency(DDS4xAD9912_Data * Instance, int DDSNum, double Freq); -int DDS4xAD9912_Reset(DDS4xAD9912_Data * Instance); -int DDS4xAD9912_RampFrequency(DDS4xAD9912_Data *dds, int channel, double f2, double fstep); -int DDS4xAD9912_RampFrequency2(DDS4xAD9912_Data *dds, int channel, double f1, double f2, double fstep); - -#ifdef __cplusplus - } -#endif - -#endif -
--- a/DDS4xAD9959.c Mon Mar 31 17:03:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,169 +0,0 @@ - -//============================================================================== -// -// Title: DDS4xAD9959.c -// Purpose: -// -// Created on: by Volodimer Laurent, modified by YLC -// Copyright: syrte. All Rights Reserved. -// -//============================================================================== - -//============================================================================== -// Include files - -#include "DDS4xAD9959.h" -#include <userint.h> -#include <tcpsupp.h> -#include <ansi_c.h> - -//============================================================================== - -// Global functions - -static int OnTCPEvent(unsigned handle, int xType, int errCode, void *callbackData) - { - switch(xType) - { - case TCP_DISCONNECT : - break; - case TCP_DATAREADY : - ClientTCPRead (handle, Response, sizeof(Response), 0); - break; - } - return 0; - } - - -//============================================================================== -// DDS4xAD9912_SendCmd -// -// FUNC : envoie une chaine de caracteres sur un port du serveur TCP/IP de la foxboard -// PARAM : DDSNum contient le numero de la DDS (1,2,3 ou 4) -// PARAM : Buffer contenant la chaîne de caractères à envoyer -// RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK -//============================================================================== - - -static int DDS4XAD9959_SendCmd(int DDSNum, char * Buffer) // essentially a private function - { - int res_1,res_2; - - switch(DDSNum) - { - case 1: - res_1=ConnectToTCPServer (&hConv, Port1, Adress, OnTCPEvent, 0, 0); - if(res_1 <0) MessagePopup("DDS4XAD9959_1 Serveur", "Connection to server failed !"); - break; - case 2: - res_1=ConnectToTCPServer (&hConv, Port2, Adress, OnTCPEvent, 0, 0); - if(res_1 <0) MessagePopup("DDS4XAD9959_2 Serveur", "Connection to server failed !"); - break; - - case 3: - res_1=ConnectToTCPServer (&hConv, Port3, Adress, OnTCPEvent, 0, 0); - if(res_1 <0) MessagePopup("DDS4XAD9959_3 Serveur", "Connection to server failed !"); - break; - - case 4: - res_1=ConnectToTCPServer (&hConv, Port4, Adress, OnTCPEvent, 0, 0); - if(res_1 <0) MessagePopup("DDS4XAD9959_4 Serveur", "Connection to server failed !"); - break; - - } - - res_2=ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0); - if(res_2 <0) MessagePopup("DDS Serveur", "Write to server failed !"); - DisconnectFromTCPServer (hConv); - return (res_1+res_2) ; - } - - -//============================================================================== -// DDS4xAD9912_Reset -// -// FUNC : reset des 4 DDS -// PARAM : -// RETURN : 0 si le reset de la DDS 1 , DDS 2, DDS3 et DDS4 est OK -//============================================================================== - - int DDS4XAD9959_Reset(DDS4XAD9959_Data * Instance) - { - int res_1,res_2; - - sprintf(Request,"set;%i;%i",1,17); - res_1 = DDS4XAD9959_SendCmd(1,Request) ; - if(res_1 <0) { - MessagePopup("DDS Serveur", "DDS4XAD9959_1 Reset failed !") ; - } - else Instance->Frequency1 = 0.0 ; - - sprintf(Request,"set;%i;%i",1,17); - res_2 = DDS4XAD9959_SendCmd(2,Request) ; - if(res_2 <0) { - MessagePopup("DDS Serveur", "DDS4XAD9959_2 Reset failed !") ; - } - else Instance->Frequency2 = 0.0; - - sprintf(Request,"set;%i;%i",1,17); - res_2 = DDS4XAD9959_SendCmd(3,Request) ; - if(res_2 <0) { - MessagePopup("DDS Serveur", "DDS4XAD9959_3 Reset failed !") ; - } - else Instance->Frequency3 = 0.0; - - sprintf(Request,"set;%i;%i",1,17); - res_2 = DDS4XAD9959_SendCmd(4,Request) ; - if(res_2 <0) { - MessagePopup("DDS Serveur", "DDS4XAD9959_4 Reset failed !") ; - } - else Instance->Frequency4 = 0.0; - - - return (res_1+res_2); - } - - -//============================================================================== -// DDS4xAD9912_SetFreq -// -// FUNC : sort une fréquence sur la DDS1 ,DDS2, DDS3 ou DDS4 -// PARAM : DDSNum contient le numero de la DDS (1, 2 , 3 ou 4) -// RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK -//============================================================================== -int DDS4XAD9959_SetFrequency(DDS4XAD9959_Data * Instance, int DDSNum, double Freq) - { - - double Word=WORD(Freq,Clk) ; - double reste ; - int res_0 ; - unsigned char b5,b4,b3,b2,b1,b0 ; - - b5=(unsigned char)(Word/E48); // AD9858 is 32 bits, so this one is always zero. For future extension only... - b4=(unsigned char)((Word - E48*b5)/E32); - b3=(unsigned char)((Word - E48*b5 -E32*b4)/E24); - b2=(unsigned char)((Word - E48*b5 -E32*b4 -E24*b3)/E16); - b1=(unsigned char)((Word - E48*b5 -E32*b4 -E24*b3 -E16*b2)/E8); - b0=(unsigned char)((Word - E48*b5 -E32*b4 -E24*b3 -E16*b2 -E8*b1)/1.0); - reste = (Word - E48*b5 -E32*b4 -E24*b3 -E16*b2 -E8*b1-1.0*b0) ; - - sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",0,10,b5,b4,b3,b2,b1,b0); - res_0 = DDS4XAD9959_SendCmd(DDSNum, Request) ; - if (res_0 <0) { - MessagePopup("DDS Serveur", "SetFrequency function failed !") ; - } - else { - if (DDSNum==1) Instance->Frequency1 = Freq - reste*Clk/E48 ; - if (DDSNum==2) Instance->Frequency2 = Freq - reste*Clk/E48 ; - if (DDSNum==3) Instance->Frequency3 = Freq - reste*Clk/E48 ; - if (DDSNum==4) Instance->Frequency4 = Freq - reste*Clk/E48 ; - } ; - - sprintf(Request,"set;%i;%i",0,18); // IO_Update logiciel - res_0 = DDS4XAD9959_SendCmd(DDSNum, Request) ; - if (res_0 <0) { - MessagePopup("DDS Serveur", "IO_Update function failed !") ; - } - return(res_0) ; - - }
--- a/DDS4xAD9959.h Mon Mar 31 17:03:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -//============================================================================== -// -// Title: DDS4xAD9959.h -// Purpose: -// -// Created on: by Volodimer Laurent, modified by YLC -// Copyright: syrte. All Rights Reserved. -// -//============================================================================== - -#ifndef __DDS4XAD9959_H__ -#define __DDS4XAD9959_H__ - -#ifdef __cplusplus - extern "C" { -#endif - -//============================================================================== -// Include files - -#include "cvidef.h" - -//============================================================================== -// Defines - -#define Adress "192.168.0.5" -#define Port1 6665 -#define Port2 6666 -#define Port3 6667 -#define Port4 6668 -#define Clk 1000000000 -#define E48 1099511627776.0 -#define E32 4294967296.0 -#define E24 16777216.0 -#define E16 65536.0 -#define E8 256.0 - -//============================================================================== -// Macros - -#define WORD(Freq,Clk) pow(2,32)*(Freq/Clk) - -// DDS2xAD9858_Data : the data of crypto class DDS2xAD9858 - -typedef struct { - double Frequency1 ; - double Frequency2 ; - double Frequency3 ; - double Frequency4 ; - } DDS4XAD9959_Data ; - -//============================================================================== -// Variables - -char Request[255]; -char Response[255]; -unsigned int hConv; - -//============================================================================== -// Functions - - -static int DDS4XAD9959_SendCmd(int DDSNum,char *Buffer) ; // essentially a private function, hence the static scope... -int DDS4XAD9959_SetFrequency(DDS4XAD9959_Data * Instance, int DDSNum, double Freq) ; -int DDS4XAD9959_Reset(DDS4XAD9959_Data * Instance) ; - -#ifdef __cplusplus - } -#endif - -#endif /* ndef __DDS2XAD9858_H__ */
--- a/DDSBes.c Mon Mar 31 17:03:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,193 +0,0 @@ -#include <utility.h> -#include <cvirte.h> /* Needed if linking in external compiler; harmless otherwise */ -#include <userint.h> -#include "DDSBes.h" -#include <ansi_c.h> -#include <gpib.h> - -#define PPORT 0x378 -#define PPCTRL PPORT+2 -#define UPDate 0x040 -#define nWR 0x080 -#define MReset 0x0C0 -#define tempo 20 - -// Private functions, hence declared as static ... - -static int delai(int t) { - int j ; - for (j=0;j<t; j++) ; - return(0) ; -} - - -static int Strb_adress(unsigned char ad) { - outp(PPCTRL,0x08) ; - outp(PPORT,ad) ; - outp(PPCTRL,0x09) ; - delai(tempo) ; - outp(PPCTRL,0x08) ; - delai(tempo); - return(0) ; -} - -static int Strb_data(unsigned char da) { - outp(PPCTRL,0x00) ; - outp(PPORT,da) ; - outp(PPCTRL,0x01) ; - delai(tempo) ; - outp(PPCTRL,0x00) ; - delai(tempo) ; - return(0) ; -} - -static int Strb_nWrite(void) { - outp(PPCTRL,0x08) ; - outp(PPORT,nWR) ; - outp(PPCTRL,0x09) ; - delai(tempo) ; - outp(PPCTRL,0x08) ; - delai(tempo) ; - return(0) ; -} - -static int Strb_Update(void) { - outp(PPCTRL,0x08) ; - outp(PPORT,UPDate) ; - outp(PPCTRL,0x09) ; - delai(tempo) ; - outp(PPCTRL,0x08) ; - delai(tempo) ; - return(0) ; -} - -static int Strb_MReset(void) { - outp(PPCTRL,0x08) ; - outp(PPORT,MReset) ; - outp(PPCTRL,0x09) ; - delai(tempo) ; - outp(PPCTRL,0x08) ; - delai(tempo) ; - return(0) ; -} - -// Public functions - -void DDSBes_Initialize(DDSBes_Data * Instance) { - Strb_MReset(); - /* 0 dans 0x1F => update clock externe */ - Strb_data(0x00); - Strb_adress(0x1F); - Strb_nWrite(); - - return ; -} - -void DDSBes_Close(DDSBes_Data * Instance){ - - return ; -} - -void DDSBes_SetClockFrequency(DDSBes_Data * Instance, double clock_frequency){ - - int fPLL ; - unsigned char oPLL; - - fPLL = 1; - if(fPLL==1 || (fPLL>3 && fPLL<21)) { - Instance->ClockFrequency = clock_frequency*fPLL; - if (Instance->ClockFrequency>300.0e6) { - Instance->ClockFrequency = 300.0e6 ; - } - } - - if (fPLL==1) oPLL=0x60 ; - else { - if (Instance->ClockFrequency>=2e8) oPLL=(unsigned char)(0x40 + fPLL) ; - else oPLL= (unsigned char)fPLL ; - } - - Strb_data(oPLL); - Strb_adress(0x1E); - Strb_nWrite(); - - return ; -} - -void DDSBes_SetFrequency(DDSBes_Data * Instance, double frequency){ - - double pas ; - double reste ; - double coeff; - double fdiv[7]; - double p[6]; - - int i; - - unsigned char o[6]; - - fdiv[6]=pow(2.0,48.0); - fdiv[5]=pow(2.0,40.0); - fdiv[4]=pow(2.0,32.0); - fdiv[3]=pow(2.0,24.0); - fdiv[2]=65536.0; - fdiv[1]=256.0; - fdiv[0]=1.0; - - coeff=fdiv[6]/Instance->ClockFrequency; - pas=coeff*frequency; - reste=pas; - - for (i=5;i>0;i--){ - p[i]=(reste/fdiv[i]); - reste=fmod(pas,fdiv[i]); - } - p[0]=reste; - - for (i=5;i>=0;i--){ - o[i]=(unsigned char) p[i]; - } - - /* frequence (6 octets) */ - Strb_adress(0x04);Strb_data(o[5]);Strb_nWrite(); - Strb_adress(0x05);Strb_data(o[4]);Strb_nWrite(); - Strb_adress(0x06);Strb_data(o[3]);Strb_nWrite(); - Strb_adress(0x07);Strb_data(o[2]);Strb_nWrite(); - Strb_adress(0x08);Strb_data(o[1]);Strb_nWrite(); - Strb_adress(0x09);Strb_data(o[0]);Strb_nWrite(); - - Strb_Update(); - - // store in Instance->Frequency the real frequency generated by the DDS - // (and not "frequency", which is only the requested frequency and might differ by as much as ClockFrequency/2^48 - Instance->Frequency = Instance->ClockFrequency/fdiv[6] - *(fdiv[5]*o[5]+fdiv[4]*o[4]+fdiv[3]*o[3]+fdiv[2]*o[2]+fdiv[1]*o[1]+fdiv[0]*o[0]) ; - - - - return ; -} - - -void DDSBes_SetAmplitude(DDSBes_Data * Instance, int amplitude) { - unsigned char a[2]; - - if (amplitude > 0 && amplitude < 4096){ - a[1]=(unsigned char)(amplitude>>8); - a[0]=(unsigned char)floor(fmod(amplitude,256.0)); - Instance->Amplitude = amplitude ; - } - - /* nibble fort adresse=0x21 data=a[1] */ - Strb_data(a[1]); - Strb_adress(0x21); - Strb_nWrite(); - /* octet faible adresse=0x22 data=a[0] */ - Strb_data(a[0]); - Strb_adress(0x22); - Strb_nWrite(); - /* mise a jour */ - Strb_Update(); - - return ; -}
--- a/DDSBes.h Mon Mar 31 17:03:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -// -// Title: DDSBes.h -// Purpose: header for the Besancon DDS crypto-class -// -// Created on: by YLC -// Copyright: syrte. All Rights Reserved. -// -//============================================================================== - -#ifndef __DDSBES_H__ -#define __DDSBES_H__ - -#ifdef __cplusplus - extern "C" { -#endif - - -// DDSBes_Data : the data of crypto class DDSBesancon - -typedef struct { - double ClockFrequency ; // in Hz - double Frequency ; // the real frequency (in Hz) which is at the DDS output - double Amplitude ; - } DDSBes_Data ; - - -/************** Member Function Declarations (Private) **************/ - -static int delai(int t); -static int Strb_adress(unsigned char ad); -static int Strb_data(unsigned char da); -static int Strb_nWrite(void); -static int Strb_Update(void); -static int Strb_MReset(void); - - -/************** Member Function Declarations (Public) **************/ - -extern void DDSBes_Initialize(DDSBes_Data * Instance); -extern void DDSBes_Close(DDSBes_Data * Instance); -extern void DDSBes_SetClockFrequency(DDSBes_Data * Instance, double ClockFrequency); -extern void DDSBes_SetFrequency(DDSBes_Data * Instance, double Frequency); // In Instance->Frequency, the real output frequency is stored - // (<> from requested frequency due to rounding effect -extern void DDSBes_SetAmplitude(DDSBes_Data * Instance, int Amplitude); - -#ifdef __cplusplus - } -#endif - -#endif /* ndef __DDSBES_H__ */