📄 ecu.c
字号:
};
volatile signed char TestArray_Max_10_10[122] =
{
5, 5, /* Anzahl Stuetzstellen */
1, 2, 3, 4, 5, /* X-Stuetzstellen */
1, 2, 3, 4, 5, /* Y-Stuetzstellen */
11, 21, 31, 41, 51, /* Zeile 1 */
12, 22, 32, 42, 52, /* Zeile 2 */
13, 23, 33, 43, 53, /* Zeile 3 */
14, 24, 34, 44, 54, /* Zeile 4 */
15, 25, 35, 45, 55, /* Zeile 5 */
0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0
};
volatile signed short noise_distribution[32] = {
-24, -21, -17, -14, -10, -8, -6, -5, -4, -3, -2, -1, -1, 0, 0, 0, 0
, 0, 0, 1, 1, 1, 2, 3, 4, 5, 7, 9, 11, 13, 16, 20
} ;
/* used template: map.templ */
/* standard template for map without axis points */
/* number of axis points variable, datatype variable */
/* */
/* unit: */
/* min: -100 */
/* max: 100 */
volatile signed short channel5_map[20][20] = {
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0
, 2, 2, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0
, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
, 1, 0, 0
, 3, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
, 1, 0, 0
, 3, 4, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1
, 1, 0, 0
, 4, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1
, 1, 0, 0
, 4, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1
, 1, 0, 0
, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1
, 1, 0, 0
, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1
, 1, 0, 0
, 6, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1
, 1, 0, 0
, 6, 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 2, 1
, 1, 0, 0
, 6, 5, 5, 3, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 2, 2, 1
, 1, 0, 0
, 6, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 2, 2, 2
, 1, 0, 0
, 7, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4, 4, 4, 3, 2, 2, 2
, 1, 0, 0
, 8, 8, 8, 7, 7, 6, 5, 5, 4, 4, 4, 4, 4, 3, 3, 2, 2
, 1, 0, 0
, 11, 8, 8, 7, 8, 6, 5, 5, 4, 4, 4, 4, 4, 3, 3, 2, 2
, 1, 0, 0
, 12, 10, 9, 7, 8, 7, 5, 6, 5, 5, 5, 5, 4, 4, 4, 2, 2
, 1, 0, 0
, 13, 12, 11, 10, 9, 6, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3
, 2, 1, 1
, 15, 13, 12, 11, 9, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4
, 3, 2, 1
, 16, 13, 13, 12, 10, 9, 8, 8, 8, 8, 7, 6, 6, 6, 5, 5, 4
, 4, 3, 2
};
#endif
struct bitStruct {
unsigned int s0 : 1;
unsigned int s1 : 5;
unsigned int s2 : 9;
unsigned int s3 : 1;
};
#ifdef TEST
volatile struct bitStruct bitStruct1; /* = { 0, 5, 9, 0 }; */
volatile struct bitStruct bitStruct2;
volatile struct bitStruct bitStruct3;
volatile struct bitStruct bitStruct4;
#endif
unsigned long CALRAM_SIGN = 0x0055AAFF;
unsigned short CALRAM_LAST = 0xAAAA;
#if defined(C_COMP_TASKING_C16X)
#pragma default_attributes
#pragma iramdata
#endif
/**************************************************************************/
/* ECU Emulation */
/**************************************************************************/
#ifndef random
static unsigned short RndCnt = 3;
unsigned short random(unsigned short max) {
RndCnt += max + RndCnt/3;
return RndCnt % (max+1);
}
#endif
void ecuInit( void ) {
timer = 0;
channel1 = 0;
channel2 = 0;
channel3 = 0;
channel4 = 0;
channel5 = 0;
noise = 0;
byteRandom = 0;
byteCounter = 0;
wordCounter = 0;
dwordCounter = 0;
sbyteCounter = 0;
swordCounter = 0;
sdwordCounter = 0;
byteShift = 1;
wordShift = 1;
map1InputX = 2;
map1InputY = 4;
map1Output = 0;
curveInput = 0;
curveOutput = 0;
curveOutput1 = 0;
curveOutput2 = 0;
curveOutput3 = 0;
curveOutput4 = 0;
sbyteTriangleSlope = 1;
sbyteTriangle = 0;
bytePWM = 0;
bytePWMFiltered = 0;
testbyte1 = 101;
testbyte2 = 102;
testbyte3 = 103;
testbyte4 = 104;
testbyte5 = 105;
testbyte6 = 106;
testbyte7 = 107;
testbyte8 = 108;
testbyte9 = 109;
testbyte0 = 100;
#if defined(C_COMP_TASKING_C16X)
testsinglebit1 = 0;
testsinglebit2 = 0;
#endif
vin =0;
v = 0;
ti = 0;
xi = 1;
yi = 1;
#ifdef CANBOX
analogIndex = 0xf;
/* fixed channel single conversion */
/* converts channel 0 */
/* ADC start bit is reset */
/* conversion time = TCL * 24 */
/* sample time = conversion time * 1 */
ADCON = analogIndex&0xF;
ADST = 1;
#endif
#ifdef XCP_TESTMODE
if (gDebugLevel) {
XCPPRINT("CALRAM = %X\n",CALRAM);
XCPPRINT("CALRAM_SIZE = %X\n",CALRAM_SIZE);
}
#endif
}
/* 10ms Raster */
void ecuCyclic( void )
{
/* Floatingpoint sine signals */
#ifdef ENABLE_FLOAT
{
float period0,offset0,ampl0,limit0;
if (variantSelector==1) {
period0 = period1;
offset0 = offset1;
ampl0 = ampl1;
limit0 = limit1;
} else {
period0 = period;
offset0 = offset;
ampl0 = ampl;
limit0 = limit;
}
if (period0>0.01||period0<-0.01) {
channel1 = (float)(offset0+noise+sin(6.283185307*timer/period0*1)*ampl0);
if (channel1>limit0) channel1 = limit0;
if (channel1<-limit0) channel1 = -limit0;
channel2 = (float)(noise+sin(6.283185307*timer/period0*2)*ampl0);
channel3 = (float)(noise+sin(6.283185307*timer/period0*3)*ampl0);
channel4 = (float)(noise+sin(6.283185307*timer/period0*4)*ampl0);
}
timer = (float)(timer+0.01);
noise = (float)(random(100)/100.0-0.5);
}
#else
timer += 10; /* 1ms Resolution */
noise = random(31);
#if !defined (COSMIC_HC12D60_TwinPEEK)
channel1 = offset + ampl*noise_distribution[noise] + channel1;
#endif
if (channel1>limit) channel1 = limit;
if (channel1<-limit) channel1 = -limit;
noise = random(31);
#if !defined (COSMIC_HC12D60_TwinPEEK)
channel2 = offset + ampl*noise_distribution[noise] + channel2;
#endif
if (channel2>limit) channel2 = limit;
if (channel2<-limit) channel2 = -limit;
#if !defined (COSMIC_HC12D60_TwinPEEK)
channel3 = ((long)channel1*(filter)+(long)channel3*(100-filter))/100;
channel4 = ((long)channel2*(filter)+(long)channel4*(100-filter))/100;
channel5 = channel5_map[(channel1+100)/10][(channel2+100)/10];
#endif
#endif
/* Working point example */
/* Test map1_8_8_uc */
if (++ti>map1Counter) {
ti = 0;
if (random(100)>50) {
map1InputX += xi;
if (map1InputX>=7||map1InputX<=0) {
xi *= -1;
}
}
if (random(100)>50) {
map1InputY += yi;
if (map1InputY>=7||map1InputY<=0) {
yi *= -1;
}
}
}
map1Output = map1_8_8_uc[map1InputY][map1InputX];
/* Test curve5_16_uc */
curveOutput = curve5_16_uc[(curveInput)>>4];
curveOutput1 = curve5_16_uc1[(curveInput)>>4];
curveOutput2 = curve5_16_uc2[(curveInput)>>4];
curveOutput3 = curve5_16_uc3[(curveInput)>>4];
curveOutput4 = curve5_16_uc4[(curveInput)>>4];
curveInput++;
/* Random numbers */
byteRandom = (byteRandom+37)*41;
/* PWM Example */
sbyteTriangle += sbyteTriangleSlope;
if (sbyteTriangle>=50) sbyteTriangleSlope = -1;
if (sbyteTriangle<=-50) sbyteTriangleSlope = 1;
if (sbyteTriangle>sbytePWMLevel) {
#ifdef CANBOX
if (bytePWM==0) setLed(8,1);
#endif
bytePWM = 100;
} else {
#ifdef CANBOX
if (bytePWM==100) setLed(8,0);
#endif
bytePWM = 0;
}
bytePWMFiltered = (bytePWMFilter*bytePWMFiltered+(100-bytePWMFilter)*bytePWM)/100;
/* Filter Examples */
v = (a*vin + b*v)/c;
/* Counters */
byteCounter++;
wordCounter++;
dwordCounter++;
sbyteCounter++;
swordCounter++;
sdwordCounter++;
/* Shifters */
byteShift <<=1; if (byteShift==0) byteShift=1;
wordShift <<=1; if (wordShift==0) wordShift=1;
/* Analog Input */
#ifdef CANBOX
if (ADCIR) {
ADCIR = 0;
analogChannel[analogIndex] = ADDAT;
/*analogIndex++; */
ADCON = analogIndex&0xF;
ADST = 1;
}
#endif
#ifdef TEST
if (gDebugLevel) {
if (*(unsigned short*)&bitStruct1!=*(unsigned short*)&bitStruct2) {
XCPPRINT("bitStruct1 = %X\n",*(unsigned short*)&bitStruct1);
XCPPRINT("bitStruct1.s0 = %X\n",bitStruct1.s0);
XCPPRINT("bitStruct1.s1 = %X\n",bitStruct1.s1);
XCPPRINT("bitStruct1.s2 = %X\n",bitStruct1.s2);
XCPPRINT("bitStruct1.s3 = %X\n",bitStruct1.s3);
bitStruct2 = bitStruct1;
}
}
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -