?? test.c.bak
字號:
//**************************************************************************************************************//
// SMT8036_SMT8046 TEST SOFTWARE //
//**************************************************************************************************************//
// //
// NOTE1 : to get better performance, make sure that (check in Test.map) //
// 1 - 'Buf' is allocated in internal memory ('Test idram') //
// 2 - the program runs from the internal memory ('Test Stack') //
// NOTE2 : SMT365 has 1MBytes of internal memory to store program and fast access buffers (0x00000 -> 0xFFFFF). //
// NOTE3 : To display data captured, use 'Test.m' (MATLAB application) //
// Add the currect directory into Matlab Path //
// //
//**************************************************************************************************************//
// HISTORY: //
// Version: 1.2 //
// Date: 13/06/2003 //
// Author: Philippe ROBERT //
// Comments: Update to be compatible with SMT370v3 firmware //
// //
// Version: 1.3 //
// Date: 17/10/2005 //
// Author: Emilie WHEATLEY //
// Comments: Update to make the code more generic. Software compatible with SMT374 firmware v2 //
//**************************************************************************************************************//
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <SMT_SDB.h>
#include <link.h>
#include "Smt370.h"
/*** CUSTOMIZABLE ***********************************************************************************************/
#define SDB16BIT 0 // 0: 32-bit firmware, 1: 16-bit firmware(ONLY FOR SMT365!!!)
#define READBACK 1
#define PATTERNSIZE 16*1024 // bytes
#define SINERATIO 256
#define CAPTURENB 3
#define CAPTURESIZE 32*1024 // bytes
#define SDBREADA 0
#define SDBREADB 1 // Used only for 16-bit SDB
#define SDBWRITEA 2
#define SDBWRITEB 3 // Used only for 16-bit SDB
/****************************************************************************************************************/
#define BUF_SIZE 2*CAPTURESIZE
#define INDEX(x) ((x&0xF0000000)>>28)
#define COMPORT0 0
#define PI 3.1415926535897932384626433832795
#define ERROR(x) {printf("ERROR: %s", x); return 1;}
unsigned int SetDACConfig (void);
unsigned int GetDACConfig (void);
void Delay (unsigned int i);
unsigned int SetPatternGen(void);
unsigned int DoCapture (void);
unsigned int CopyToFile (const char *FileName, short *buffer, unsigned int size);
unsigned int ReadData (SMT_SDB *Sdb, unsigned int size, unsigned int *buffer, const char *FileNameA, const char *FileNameB);
static SMT_SDB *SdbRdA, *SdbRdB, *SdbWrA, *SdbWrB;
static int Buf[BUF_SIZE/sizeof(int)];
#pragma DATA_SECTION (Buf, "idram");
static char * Registers[] = {
"REG0_DAC - AD9777 registers 0x0 0x1 and 0x2",
"REG1_DAC - AD9777 registers 0x3 0x4 and 0x5",
"REG2_DAC - AD9777 registers 0x6 0x7 and 0x8",
"REG3_DAC - AD9777 registers 0x9 0xA and 0xB",
"REG4_DAC - AD9777 registers 0xC and 0xD ",
"REG5_DAC - SMT370 Clock Management ",
"REG6_DAC - ADC control ",
"REG7_DAC - Pattern Generator control ",
"REG8_DAC - Not Available ",
"REG9_DAC - Not Available ",
"REGA_DAC - Not Available ",
"REGB_DAC - Not Available ",
"REGC_DAC - Not Available ",
"REGD_DAC - SMT370 Global Reset ",
"REGE_DAC - DAC read-back ",
"REGF_DAC - Setting regisers "
};
static int DacSet[] = {
REG0_DAC|SDIO_DIR(0)|MSB_FIRST(0)|SW_RESET(0)|SLEEP_MODE(0)|POWER_DOWN(0)|DAC_1R2R_MODE(0)|PLL_LOCK(1)|
INTERPOLATION(3)|MODULATION(3)|ZERO_STUFFING(1)|MIX_MODE(0)|PHASE(0)|DCLK_PLLLOCK(1)|
DATA_SIGN(0)|PORT_MODE(0)|DCLK_STRENGHT(0)|DCLK_INVERT(0)|ONEPORTCLK(0)|IQSEL(0)|Q_FIRST(0),
REG1_DAC|PLL_RATIO(0)|PLL_MODE(1)|CHARGE_PUMP(0)|PLL_CHRG_CTL(0)|IDAC_FINE_GAIN(0xFF),
REG2_DAC|IDAC_COARS_GAIN(0xF)|IDAC_OFFSET(0)|IDAC_DIR(0),
REG3_DAC|QDAC_FINE_GAIN(0xFF)|QDAC_COARS_GAIN(0xF)|DAC_QDAC_OFFSET_MSB(0),
REG4_DAC|QDAC_DIR(0)|DAC_QDAC_OFFSET_LSB(0)|VERSION_NUMBER(0),
REG5_CLOCK|ADC_FRQ(FRQ_30MHZ)|DAC_FRQ(FRQ_30MHZ)|ADCA_CLOCK_SEL(0)|ADCB_CLOCK_SEL(0)|DAC_CLOCK_SEL(0),
REG6_ADC|ADCA_DECIMAT_FACTOR(0)|ADCB_DECIMAT_FACTOR(0)|ADC_EXT_TRIG_LEVEL(0)|ADC_EXT_TRIG_ENABLE(0)|ADCA_MODE(3)|ADCB_MODE(3),
REG7_DAC,
REGF_CFG
};
#define DACCFG DAC_EXT_TRIG_ENABLE(0)|DAC_EXT_TRIG_LEVEL(0)|DAC_CHA_SEL(1)|DAC_CHB_SEL(1)
#define ADC_RUNNING REG6_ADC|ADCA_DECIMAT_FACTOR(0)|ADCB_DECIMAT_FACTOR(0)|ADC_EXT_TRIG_LEVEL(0)|ADC_EXT_TRIG_ENABLE(0)|ADCA_MODE(3)|ADCB_MODE(3)
#define ADC_STOPPED REG6_ADC|ADCA_DECIMAT_FACTOR(0)|ADCB_DECIMAT_FACTOR(0)|ADC_EXT_TRIG_LEVEL(0)|ADC_EXT_TRIG_ENABLE(0)|ADCA_MODE(0)|ADCB_MODE(0)
static int DacGet[] = {
0, // REG0_DAC,
0, // REG1_DAC,
0, // REG2_DAC,
0, // REG3_DAC,
0, // REG4_DAC,
0, // Clock Management,
0, // ADC Control,
0, // Pattern Generator Control
0
};
int main()
{
unsigned int i;
printf("\n\n=================================\n");
printf("| SMT8036_SMT8046 TEST SOFTWARE |\n");
printf("=================================\n");
printf("\n / \\");
#if SDB16BIT
printf("\n / | \\ This test is for a DSP module programmed with a 16-bit SDB interface!");
printf("\n / | \\ For 32-bit SDB interface: Change the #define SDB16BIT in test.c and rebuild the application");
#else
printf("\n / | \\ This test is for a DSP module programmed with a 32-bit SDB interface!");
printf("\n / | \\ For 16-bit SDB interface (365/365E ONLY!!!): Change the #define SDB16BIT in test.c and rebuild the application");
#endif
printf("\n /___o___\\\n\n");
// SDB allocation
SdbRdA = SMT_SDB_Claim(SDBREADA);
if (!SdbRdA) ERROR("Cannot claim SDB (SDBREADA)\n");
SdbWrA = SMT_SDB_Claim(SDBWRITEA);
if (!SdbWrA) ERROR("Cannot claim SDB (SDBWRITEA)\n");
if (SDB16BIT) {
SdbRdB = SMT_SDB_Claim(SDBREADB);
if (!SdbRdB) ERROR("Cannot claim SDB (SDBREADB)\n");
SdbWrB = SMT_SDB_Claim(SDBWRITEB);
if (!SdbWrB) ERROR("Cannot claim SDB (SDBWRITEB)\n");
}
// Buffer allocation
if (!Buf) ERROR("Cannot allocate Buf\n");
printf("Buffer address: 0X%08x\n\n", Buf);
// SMT370 Global Reset
printf("\n* Resetting SMT370 \n");
link_out_word(REGD_RESET, COMPORT0); // SMT370 Reset
// Configuring DAC and CLock synthesizers
if (SetDACConfig()) return 1;
#if READBACK
// Reading Back DAC SPI registers
if (GetDACConfig()) return 1;
#endif
// Pattern Generator
if (SetPatternGen()) return 1;
// Capture
if (DoCapture()) return 1;
printf("\n* DONE\n\n");
return 0;
}
unsigned int SetDACConfig(void)
{
unsigned int i;
printf("\n* Setting internal registers \n");
link_out_word(REGD_RESET, COMPORT0);
Delay(100000);
for (i=0; i<sizeof(DacSet)/sizeof(int); i++) {
printf("\t%s -> 0x%08X \n", Registers[INDEX(DacSet[i])], DacSet[i]);
link_out_word(DacSet[i], COMPORT0);
Delay(100000);
}
return 0;
}
unsigned int GetDACConfig(void)
{
int i=0, v0,v1,v2;
int BoardOption;
printf("\n* Reading Back DAC SPI registers \n");
printf("\tReading-back and checking %d Registers\n", sizeof(DacGet)/sizeof(int));
// Send command
link_out_word(REGE_DAC, COMPORT0);
// Get Board ADC coupling option
link_in_word(&BoardOption, COMPORT0);
printf("\tBoard ADC input coupling : %0x \n", BoardOption);
// Get three first entire register first
for (i=1; i<4; i++) {
link_in_word(&v0, COMPORT0);
DacGet[i+4] = v0;
}
// Get DAC registers
for (i=4; i<(sizeof(DacGet)/sizeof(int)); i++) {
v0=v1=v2=0;
link_in_word(&v0, COMPORT0);
link_in_word(&v1, COMPORT0);
if (i<(sizeof(DacGet)/sizeof(int)-1)) { // HACK!!!! TAKE OUT !!!
link_in_word(&v2, COMPORT0);
}
DacGet[i-4] = ((v0&0xFF)<<16) | ((v1&0xFF)<<8) | ((v2&0xFF)<<0);
}
// Print result
for (i=0; i<sizeof(DacGet)/sizeof(int); i++) {
printf("\t%s ", Registers[INDEX(DacSet[i])]);
if (DacGet[i]!=(DacSet[i]&0x0FFFFFFF)) {
printf(" -> ERROR, is 0x%08X should be 0x%08x \n", DacGet[i], (DacSet[i]&0x0FFFFFFF));
} else {
printf(" -> OK \n");
}
}
return 0;
}
void Delay(unsigned int i)
{
volatile unsigned int j;
for(i=0;i<100000;i++){}
}
unsigned int SetPatternGen(void)
{signed int I=0;
signed int Q=0;
int c;
int d;
FILE *fid;
FILE *fid1;
int *Pattern = 0;
unsigned int i;
fid=fopen("real.bin","rb");
fid1=fopen("image.bin","rb");
if((fid==NULL)||(fid1==NULL))
{
printf("open file error\n");
}
printf("\n* Loading Pattern Generator with a sine\n");
// Generating Buffer
Pattern = (int *)memalign(128, PATTERNSIZE*2); //以字節(jié)為單位分配內存,每個采樣點用16位表示 ,即2個字節(jié)
if (!Pattern) ERROR("Cannot allocate Pattern\n");
/*for (i=0;i<PATTERNSIZE*2/4;i++) {
*(Pattern+i)=((int)(31*1024*(sin(2*PI*(2*i)/(PATTERNSIZE/SINERATIO))))) + (((int)(31*1024*(sin(2*PI*(2*i+1)/(PATTERNSIZE/SINERATIO)))))<<16);
}*/
for (i=0;i<PATTERNSIZE*2/4;i++) {
fread(&c,4,1,fid);
I=c;
fread(&d,4,1,fid1);
Q=d;
//printf("I=%d,",I);
//printf("Q=%d\n",Q);
*(Pattern+i)=((int)(31*1024*I)) + (((int)(31*1024*Q))<<16);
}
printf("\tAddress Pattern: 0X%08x\n", Pattern);
printf("\tPattern Size: %d (bytes)\n", PATTERNSIZE);
printf("\tSine Ratio: %d\n", SINERATIO);
// Load Pattern Size
link_out_word(REG7_DAC | DACCFG | PAT_LD_SIZE | ((PATTERNSIZE/2)&0xFFFFF), COMPORT0);
// Send data over SHBB
if (SDB16BIT) {
SMT_SDB_Control(SdbWrA, SDB_CLROF);
SMT_SDB_Control(SdbWrB, SDB_CLROF);
SMT_SDB_Write(SdbWrA, PATTERNSIZE, Pattern); // size in bytes 16-bits first channel - limitation to size input DAC channel in FPGA
SMT_SDB_Write(SdbWrB, PATTERNSIZE, Pattern); // size in bytes 16-bits second channel
} else {
SMT_SDB_Control(SdbWrA, SDB_CLROF);
SMT_SDB_Write(SdbWrA, 2*PATTERNSIZE, Pattern); // size in bytes
}
// Start Pattern Generator
printf("\n* Starting Pattern Generator\n");
link_out_word(REG7_DAC | DACCFG | PAT_START, COMPORT0);
if (Pattern) free(Pattern);
return 0;
}
unsigned int CopyToFile(const char *FileName, short *buffer, unsigned int size)
{
FILE *file;
unsigned int i;
file = fopen(FileName,"w");
if (!file) ERROR("Cannot open file\n");
for (i=0; i<size/4; i++) fprintf(file, "%d\n",buffer[i]);
fclose(file);
return 0;
}
unsigned int DoCapture(void)
{
unsigned int j=0;
char FileNameA[64];
char FileNameB[64];
printf("\n* Capturing data \n");
printf("\tCapture Size: %d 16-bit samples\n", CAPTURESIZE/2);
printf("\tNumber of Capture: %d\n\n", CAPTURENB);
link_out_word(ADC_RUNNING, COMPORT0);
for (j=0 ; j<CAPTURENB ; j++) {
printf("\tCapturing %d \n", j);
sprintf(FileNameA, "CAPTUREA%d.txt", j);
sprintf(FileNameB, "CAPTUREB%d.txt", j);
if (SDB16BIT) {
if (ReadData(SdbRdA, CAPTURESIZE, (unsigned int*)Buf, FileNameA, 0)) return 1; // Channel A
if (ReadData(SdbRdB, CAPTURESIZE, (unsigned int*)Buf, FileNameB, 0)) return 1; // Channel B
} else {
if (ReadData(SdbRdA, CAPTURESIZE*2, (unsigned int*)Buf, FileNameA, FileNameB)) return 1;
}
}
return 0;
}
unsigned int ReadData(SMT_SDB *Sdb, unsigned int size, unsigned int *buffer, const char *FileNameA, const char *FileNameB)
{
unsigned int i;
SMT_SDB_Control(Sdb, SDB_CLRIF); // Clear input fifo prior to read operation
SMT_SDB_Read(Sdb, size, buffer); // size in byte - Each sample is 2 byte-wide
if (!FileNameB) {
CopyToFile(FileNameA, (short *)buffer, size);
} else {
short *tmp = (short *)malloc(size/2);
if (!tmp) ERROR("ERROR: Cannot allocate temporary buffer\n");
// Copy data to file
for (i=0; i<(size/4); i++) tmp[i] = (buffer[i]>>0)&0xFFFF;
CopyToFile(FileNameA, tmp, size/2);
for (i=0; i<(size/4); i++) tmp[i] = (buffer[i]>>16)&0xFFFF;
CopyToFile(FileNameB, tmp, size/2);
if (tmp) free(tmp);
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -