Browse Source

add testfloat.

Change-Id: I4bb8237082534dde28656d7101f9c1f193cf9200
Signed-off-by: Chong Qiao <qiaochong@loongson.cn>
master
Chong Qiao 3 years ago
parent
commit
02e2bdbe3d
  1. 1
      Targets/LS2K/conf/files.LS2K
  2. 218
      Targets/LS2K/dev/testfloat.c

1
Targets/LS2K/conf/files.LS2K

@ -47,6 +47,7 @@ file Targets/LS2K/dev/9022a.c sii9022a needs-flag
file Targets/LS2K/dev/lt8168.c lt8168s needs-flag
file Targets/LS2K/dev/can_test.c can
file Targets/LS2K/dev/irq.c timer_irq needs-flag
file Targets/LS2K/dev/testfloat.c testfloat
device syn: ether, ifnet

218
Targets/LS2K/dev/testfloat.c

@ -0,0 +1,218 @@
#include <pmon.h>
#include <math.h>
static inline void tgt_fpuenable()
{
//#if __mips < 3 || __mips == 32
#if (_MIPS_SZPTR == 32)
asm(\
"mfc0 $2,$12;\n" \
"li $3,0x34000000 #ST0_CU1;\n" \
"or $2,$3;\n"
"li $3,0x04000000 #ST0_CU1;\n"
"xor $2,$3;\n"
"mtc0 $2,$12;\n"
"li $2,0x00000000 #FPU_DEFAULT;\n"
"ctc1 $2,$31;\n"
"li $2,-1;\n"
"mtc1 $2, $f0\n;"
"mtc1 $2, $f1\n;"
"mov.d $f2, $f0\n;"
"mov.d $f4, $f0\n;"
"mov.d $f6, $f0\n;"
"mov.d $f8, $f0\n;"
"mov.d $f10, $f0\n;"
"mov.d $f12, $f0\n;"
"mov.d $f14, $f0\n;"
"mov.d $f16, $f0\n;"
"mov.d $f18, $f0\n;"
"mov.d $f20, $f0\n;"
"mov.d $f22, $f0\n;"
"mov.d $f24, $f0\n;"
"mov.d $f26, $f0\n;"
"mov.d $f28, $f0\n;"
"mov.d $f30, $f0\n;"
:::"$2","$3"
);
#else
asm(\
"mfc0 $2,$12;\n"
"li $3,0x34000000 #ST0_CU1;\n"
"or $2,$3;\n"
"mtc0 $2,$12;\n"
"li $2,0x00000000 #FPU_DEFAULT;\n"
"ctc1 $2,$31;\n"
"li $2,-1;\n"
"dmtc1 $2, $f0\n;"
"mov.d $f1, $f0\n;"
"mov.d $f3, $f0\n;"
"mov.d $f5, $f0\n;"
"mov.d $f7, $f0\n;"
"mov.d $f9, $f0\n;"
"mov.d $f11, $f0\n;"
"mov.d $f13, $f0\n;"
"mov.d $f15, $f0\n;"
"mov.d $f17, $f0\n;"
"mov.d $f19, $f0\n;"
"mov.d $f21, $f0\n;"
"mov.d $f23, $f0\n;"
"mov.d $f25, $f0\n;"
"mov.d $f27, $f0\n;"
"mov.d $f29, $f0\n;"
"mov.d $f31, $f0\n;"
"mov.d $f2, $f0\n;"
"mov.d $f4, $f0\n;"
"mov.d $f6, $f0\n;"
"mov.d $f8, $f0\n;"
"mov.d $f10, $f0\n;"
"mov.d $f12, $f0\n;"
"mov.d $f14, $f0\n;"
"mov.d $f16, $f0\n;"
"mov.d $f18, $f0\n;"
"mov.d $f20, $f0\n;"
"mov.d $f22, $f0\n;"
"mov.d $f24, $f0\n;"
"mov.d $f26, $f0\n;"
"mov.d $f28, $f0\n;"
"mov.d $f30, $f0\n;"
:::"$2","$3"
);
#endif
}
typedef int bool;
#define true 1
int errno;
typedef double float32_t;
/*******************************************************************************
* Defines
*******************************************************************************/
#define PI (3.14159265F)
/*******************************************************************************
* Local enums
*******************************************************************************/
/*******************************************************************************
* Local typedefs
*******************************************************************************/
/******************************************************************************
* Global variable
*******************************************************************************/
volatile float32_t adc_simulator_input = 0.0F;
/*******************************************************************************
* Constants
*******************************************************************************/
static const float32_t Sy_ZpwCarryFreqType1[4] = { 1701.4F, 2001.4F, 2301.4F, 2601.4F };
static const float32_t Sy_ZpwCarryFreqType2[4] = { 1698.7F, 1998.7F, 2298.7F, 2598.7F };
static const float32_t Sy_ZpwModFreqType[18] = { 10.3F, 11.4F, 12.5F, 13.6F, 14.7F, 15.8F, 16.9F, 18.0F, 19.1F, 20.2F, 21.3F, 22.4F, 23.5F, 24.6F, 25.7F, 26.8F, 27.9F, 29.0F };
/******************************************************************************
* Local variable
*******************************************************************************/
/******************************************************************************
* External variable
*******************************************************************************/
volatile bool Ts_SmallSignalType = true;
volatile uint32_t Ts_Fc = 2U;
volatile uint32_t Ts_Fd = 10U;
/*******************************************************************************
* Local function prototypes
*******************************************************************************/
float32_t GenFsk2000A(float32_t t);
void waveGen(void);
/*******************************************************************************
* External function prototypes
*******************************************************************************/
/*******************************************************************************
* Functions
*******************************************************************************/
float32_t GenFsk2000A(float32_t t)
{
double fmod, fcarry;
double deltf, w0, deltw;
int32_t temp1, temp2;
double temp3, temp4;
double output;
double val;
t = t / 8616.7F;
// fcarry = 1701.4F;
// fmod = 29;
if (Ts_SmallSignalType == true)
{
fcarry = Sy_ZpwCarryFreqType1[Ts_Fc];
}
else
{
fcarry = Sy_ZpwCarryFreqType2[Ts_Fc];
}
fmod = Sy_ZpwModFreqType[Ts_Fd];
deltf = 11.0F;
w0 = 2.0F * PI * fcarry;
deltw = 2.0F * PI * deltf;
temp1 = (int32_t) ((t) / (1 / (fmod * 2)));
temp2 = (int32_t) (temp1 % 2);
temp3 = t - temp1 * (1 / (fmod * 2));
temp4 = 1 / (fmod * 2) - temp3;
if (temp2 == 0)
{
val = w0 * t + deltw * temp3;
output = sin(val);
}
else if (temp2 == 1)
{
val = w0 * t + deltw * temp4;
output = sin(val);
}
return output;
}
void waveGen(void)
{
float32_t adc2000A_input;
static float32_t time_Count = 0.0F;
time_Count += 1.0F;
adc2000A_input = GenFsk2000A(time_Count);
adc_simulator_input = adc2000A_input;
}
int
cmd_testfloat(int argc, char **argv)
{
unsigned int i = 0;
printf("begin test\n");
tgt_fpuenable();
while(1) {
waveGen();
if ((i & 0xfff) == 0) {
if (adc_simulator_input > 1.0) printf("error:\n");
printf("%u:%16llx %f\n", i, *(unsigned long long *)&adc_simulator_input, adc_simulator_input);
}
i++;
}
return 0;
}
static const Cmd Cmds[] =
{
{"MyCmds"},
{"testfloat","", 0, "test float", cmd_testfloat, 0, 99, CMD_REPEAT},
{0, 0}
};
static void init_cmd __P((void)) __attribute__ ((constructor));
static void init_cmd()
{
cmdlist_expand(Cmds, 1);
}
Loading…
Cancel
Save