📄 drv_att7022.c
字号:
#include "config_60_61.h"
#include "config_GD60.h"
#include "include_GD60.h"
#include "include_GD61.h"
/////////////////////////////////////////////////////
int32 U1_BaseFreq_buff[Att7022DataBuffSize]; //data buffer in Base freq measuring mode
int32 U1_Harmonic_buff[Att7022DataBuffSize]; //data buffer in Harmonic measuring mode
int32 U1_NormalDt_buff[Att7022DataBuffSize]; //data buffer in normal measuring mode
uint8 U1_DataImageType=0; //define the data image type
extern uint8 LOOP_START;
/////////////////////////////////////////////////////
int32 Read_Sp1(uint16 comx);
int32 Read_Sp1_Hd(uint8 comx);
void Write_Sp1(uint8 comx,uint8 dataxh,uint16 dataxl);
void DLY_3us(void);
/////////////////////////////////////////////////////
//// the return data shpuld be 24bits
int32 Read_Sp1(uint16 comx)
{
int32 indata;
uint8 address;
#ifdef PRINT_STATIC_INFO
char dbuffer[100];
#endif
#ifdef U1_ATT7022B
#ifndef PRINT_STATIC_INFO
char dbuffer[100];
#endif
#endif
address=(uint8)comx;
////////////////////////////////////////////////////
// the next programm is for ATT7022(A)
#ifdef U1_ATT7022B
if(address==rRSPIData){ // read the special address directly
indata=Read_Sp1_Hd(address);
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DSP1234(A), address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
}
//
else if(address==rS_Flag){ // read the special address directly
indata=Read_Sp1_Hd(address);
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DSP1234(A), address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
}
//
else if(address==rWSPIData1){ // read the special address directly
indata=Read_Sp1_Hd(address);
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DSP1234(A), address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
}
else if(address==rWSPIData2){ // read the special address directly
indata=Read_Sp1_Hd(address);
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DSP1234(A), address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
}
//
/*
else if(address==rChkSum1){ // read the special address directly
indata=Read_Sp1_Hd(address);
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DSP1234(A), address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
}
else if(address==rChkSum2){ // read the special address directly
indata=Read_Sp1_Hd(address);
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DSP1234(A), address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
}
*/
/////////////////////////////////////////////////////////////////////////////////////////////////////
// memory map define as follow
// 00:Normal___ data[0x00,0x7f], 00:BasicFreq data[0x100,0x17f], 00:Harmonic_ data[0x200,0x27f]
// 01:BasicFreq data[0x00,0x7f], 01:Harmonic_ data[0x100,0x17f], 01:Normal___ data[0x200,0x27f]
// 02:Harmonic_ data[0x00,0x7f], 02:Normal___ data[0x100,0x17f], 02:BasicFreq data[0x200,0x27f]
//// segment 0
else if(comx<0x80){
switch(U1_DataImageType){
case 00:
indata=U1_NormalDt_buff[address];
U1_clrNormalDtEnergy2(address); //clr the energy register2
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DataBuffer, address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
break;
case 01:
indata = U1_BaseFreq_buff[address];
U1_clrBaseFreqEnergy2(address); //clr the energy register2
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DataBuffer, address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
break;
case 02:
indata = U1_Harmonic_buff[address];
U1_clrHarmonicEnergy2(address); //clr the energy register2
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DataBuffer, address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
break;
default:
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"unsupported the data image type."); DB_SendString(dbuffer);
}
#endif
break;
}
}
// memory map define as follow
// 00:Normal___ data[0x00,0x7f], 00:BasicFreq data[0x100,0x17f], 00:Harmonic_ data[0x200,0x27f]
// 01:BasicFreq data[0x00,0x7f], 01:Harmonic_ data[0x100,0x17f], 01:Normal___ data[0x200,0x27f]
// 02:Harmonic_ data[0x00,0x7f], 02:Normal___ data[0x100,0x17f], 02:BasicFreq data[0x200,0x27f]
//// segment 1
else if((comx>=0x100)&&(comx<0x180)){
switch(U1_DataImageType){
case 02:
indata=U1_NormalDt_buff[address];
U1_clrNormalDtEnergy2(address); //clr the energy register2
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DataBuffer, address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
break;
case 00:
indata = U1_BaseFreq_buff[address];
U1_clrBaseFreqEnergy2(address); //clr the energy register2
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DataBuffer, address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
break;
case 01:
indata = U1_Harmonic_buff[address];
U1_clrHarmonicEnergy2(address); //clr the energy register2
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DataBuffer, address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
break;
default:
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"unsupported the data image type."); DB_SendString(dbuffer);
}
#endif
break;
}
}
// memory map define as follow
// 00:Normal___ data[0x00,0x7f], 00:BasicFreq data[0x100,0x17f], 00:Harmonic_ data[0x200,0x27f]
// 01:BasicFreq data[0x00,0x7f], 01:Harmonic_ data[0x100,0x17f], 01:Normal___ data[0x200,0x27f]
// 02:Harmonic_ data[0x00,0x7f], 02:Normal___ data[0x100,0x17f], 02:BasicFreq data[0x200,0x27f]
//// segment 2
else if((comx>=0x200)&&(comx<0x280)){
switch(U1_DataImageType){
case 01:
indata=U1_NormalDt_buff[address];
U1_clrNormalDtEnergy2(address); //clr the energy register2
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DataBuffer, address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
break;
case 02:
indata = U1_BaseFreq_buff[address];
U1_clrBaseFreqEnergy2(address); //clr the energy register2
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DataBuffer, address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
break;
case 00:
indata = U1_Harmonic_buff[address];
U1_clrHarmonicEnergy2(address); //clr the energy register2
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Reading data from U1_DataBuffer, address=0x%x.",comx); DB_SendString(dbuffer);
}
#endif
break;
default:
#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"unsupported the data image type."); DB_SendString(dbuffer);
}
#endif
break;
}
}
//// segment 3, out of available address
else{
indata=Read_Sp1_Hd(address);
//#ifdef PRINT_STATIC_INFO
if(LOOP_START==TRUE){
sprintf(dbuffer,"Invalid U1_DSP1234(A) address = 0x%x.",comx);
DB_SendString(dbuffer);
}
//#endif
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////// the next program is for ATT7022(A)
#else //#ifdef U1_ATT7022B
indata=Read_Sp1_Hd(address);
#ifdef PRINT_STATIC_INFO
if((LOOP_START==TRUE)&&(address!=rS_Flag)){
sprintf(dbuffer,"Reading data from U1_DSP1234(A), address=0x%x.",comx);
DB_SendString(dbuffer);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -