📄 ecu.c
字号:
/*----------------------------------------------------------------------------
| File:
| ecu.cpp
|
| Description:
| ECU Simulation for all CANape CCP and XCP samples
|
----------------------------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
#include <stdarg.h>
#include <stdlib.h>
#include "ccppar.h"
#include "ecu.h"
/**************************************************************************/
#if !defined(WIN32) && !defined(__WIN32__) && !defined(C_MINI_CAN_DRIVER)
#include "can_inc.h"
#endif
#if defined(C_COMP_COSMIC_12)
#define setLed(a,b)
#endif
#if defined( C_COMP_HWB_SH7055 )
#define ENABLE_FLOAT
#define setLed(a,b)
#define volatile
#endif
#if defined( C_COMP_TASKING_C16X )
#include <reg167.h>
#define random(x) (T3/650)
#ifdef CANBOX
#include "ledio.h"
#endif
#endif
#if defined(__WIN32__) || defined(WIN32)
#define ENABLE_FLOAT
#define setLed(a,b)
#define volatile
#endif
/**************************************************************************/
/* ECU Measurement RAM */
/**************************************************************************/
#ifdef ENABLE_FLOAT
float timer;
float channel1;
float channel2;
float channel3;
float channel4;
float channel5;
float noise;
#else
unsigned long timer;
short channel1;
short channel2;
short channel3;
short channel4;
short channel5;
short noise;
#endif
unsigned char byteRandom;
unsigned char byteCounter;
unsigned short wordCounter;
unsigned long dwordCounter;
signed char sbyteCounter;
signed short swordCounter;
signed long sdwordCounter;
unsigned char byteShift;
unsigned short wordShift;
unsigned char map1InputX;
unsigned char map1InputY;
unsigned char map1Output;
unsigned char curveInput;
unsigned char curveOutput;
unsigned char curveOutput1;
unsigned char curveOutput2;
unsigned char curveOutput3;
unsigned char curveOutput4;
signed char sbyteTriangleSlope;
signed char sbyteTriangle;
unsigned char bytePWM;
unsigned char bytePWMFiltered;
unsigned char testbyte1;
unsigned char testbyte2;
unsigned char testbyte3;
unsigned char testbyte4;
unsigned char testbyte5;
unsigned char testbyte6;
unsigned char testbyte7;
unsigned char testbyte8;
unsigned char testbyte9;
unsigned char testbyte0;
#if defined(C_COMP_TASKING_C16X)
bit testsinglebit1;
bit testsinglebit2;
#endif
unsigned short vin;
unsigned short v;
unsigned char ti;
unsigned char xi;
unsigned char yi;
#if !defined (COSMIC_HC12D60_TwinPEEK)
unsigned char analogIndex;
unsigned short analogChannel[16];
#endif
/**************************************************************************/
/* ECU Calibration RAM */
/**************************************************************************/
#if defined(C_COMP_TASKING_C16X)
#pragma romdata
#pragma class NC=CALROM
#endif
unsigned short CALRAM_START = 0xAAAA;
unsigned char flashSignatur[32] = "Default";
#ifdef ENABLE_FLOAT
volatile float period = 5; /* Variant 0 */
volatile float ampl = 6;
volatile float limit = 100;
volatile float offset = 0;
volatile float filter = 0;
volatile float period1 = 10; /* Variant 1 */
volatile float ampl1 = 6;
volatile float limit1 = 100;
volatile float offset1 = 10;
volatile float filter1 = 10;
/* Selector */
volatile unsigned char variantSelector = 0;
#else
volatile unsigned short period = 5;
volatile unsigned short ampl = 1;
volatile short limit = 100;
volatile short offset = 0;
volatile short filter = 8;
#endif
volatile unsigned short a = 1;
volatile unsigned short b = 5;
volatile unsigned short c = 6;
volatile signed char sbytePWMLevel = 0;
volatile unsigned char bytePWMFilter = 50;
volatile unsigned char byte1 = 1;
volatile unsigned char byte2 = 2;
volatile unsigned char byte3 = 3;
volatile unsigned char byte4 = 4;
#if !defined (COSMIC_HC12D60_TwinPEEK)
volatile unsigned short word1 = 1;
volatile unsigned short word2 = 1;
volatile unsigned short word3 = 1;
volatile unsigned short word4 = 1;
volatile unsigned long dword1 = 1;
volatile unsigned long dword2 = 1;
volatile unsigned long dword3 = 1;
volatile unsigned long dword4 = 1;
#endif
volatile unsigned char map1Counter = 25;
volatile unsigned char map1_8_8_uc[8][8] =
{{0,0,0,0,0,0,1,2},
{0,0,0,0,0,0,2,3},
{0,0,0,0,1,1,2,3},
{0,0,0,1,1,2,3,4},
{0,1,1,2,3,4,5,7},
{1,1,1,2,4,6,8,9},
{1,1,2,4,5,8,9,10},
{1,1,3,5,8,9,10,10}
};
#if !defined (COSMIC_HC12D60_TwinPEEK)
volatile unsigned char map2_8_8_uc[8][8] = {
{ 1, 2, 3, 4, 5, 6, 7, 8},
{11,12,13,14,15,16,17,18},
{21,22,23,24,25,26,27,28},
{31,32,33,34,35,36,37,38},
{41,42,43,44,45,46,47,48},
{51,52,53,54,55,56,57,58},
{61,62,63,64,65,66,67,68},
{71,72,73,74,75,76,77,78}
};
volatile unsigned char map3_8_8_uc[8][8] =
{{0,0,0,0,0,0,1,2},
{0,0,0,0,0,0,2,3},
{0,0,0,0,1,1,2,3},
{0,0,0,1,1,2,3,4},
{0,1,1,2,3,4,5,7},
{1,1,1,2,4,6,8,9},
{1,1,2,4,5,8,9,10},
{1,1,3,5,8,9,10,10}
};
#endif
volatile unsigned char curve1_8_uc[8] =
{1,2,3,4,5,6,8,12};
volatile unsigned char curve2_8_uc[8] =
{11,12,13,14,15,16,18,22};
#if !defined (COSMIC_HC12D60_TwinPEEK)
volatile unsigned char curve3_8_uc[8] =
{21,22,23,24,25,26,28,32};
volatile unsigned char curve4_8_uc[16] =
{41,42,43,44,45,46,48,52,
51,52,53,54,55,56,58,62};
#endif
volatile unsigned char curve5_16_uc[16] =
{1,2,3,4,5,6,8,12,14,11,9,7,6,5,4,3};
volatile unsigned char curve5_16_uc1[16] =
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
volatile unsigned char curve5_16_uc2[16] =
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
volatile unsigned char curve5_16_uc3[16] =
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
volatile unsigned char curve5_16_uc4[16] =
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
volatile unsigned char input1_uc[2] = { 112, 113 };
volatile unsigned char input2_uc = 114;
volatile unsigned char map4_80_uc[80] =
{
0, 1, 2, 3, 4, 5, 6, 7,
/* X Coordinates */
100,101,102,103,104,105,106,107, /* Y Coordinates */
1,2,3,4,5,6,7,8, /* Values */
1,2,3,4,5,6,7,8, /* Values */
1,2,3,4,5,6,7,8, /* Values */
1,2,3,4,5,6,7,8, /* Values */
1,2,3,4,5,6,7,8, /* Values */
1,2,3,4,5,6,7,8, /* Values */
1,2,3,4,5,6,7,8, /* Values */
1,2,3,4,5,6,7,8 /* Values */
};
#if !defined (COSMIC_HC12D60_TwinPEEK)
volatile unsigned char map5_82_uc[82] =
{
8, 0,1,2,3,4,5,6,7, /* X-coordinates */
8, 0,1,2,3,4,5,6,7, /* Y-coordinates */
0,0,0,0,0,0,1,2,
0,0,0,0,0,0,2,3,
0,0,0,0,1,1,2,3,
0,0,0,1,1,2,3,4,
0,1,1,2,3,4,5,7,
1,1,1,2,4,6,8,9,
1,1,2,4,5,8,9,10,
1,1,3,5,8,9,10,10
};
/* Test for insert and delete axis points, max 10*10 */
volatile unsigned char map6_122_uc[] =
{
10, /* X-Axis Points */
0,1,2,3,0,0,0,0,0,0, /* X-coordinates */
10, /* Y-Axis Points */
0,1,2,3,0,0,0,0,0,0, /* Y-coordinates */
00,01,02,03,00,00,00,00,00,00,
10,11,12,13,00,00,00,00,00,00,
20,21,22,23,00,00,00,00,00,00,
30,31,32,33,00,00,00,00,00,00,
00,00,00,00,00,00,00,00,00,00,
00,00,00,00,00,00,00,00,00,00,
00,00,00,00,00,00,00,00,00,00,
00,00,00,00,00,00,00,00,00,00,
00,00,00,00,00,00,00,00,00,00,
00,00,00,00,00,00,00,00,00,00
};
volatile unsigned char curve4_17_uc[17] =
{
8, 0,1,2,3,4,5,6,7, /* X-coordinates */
0,1,1,2,3,4,5,7
};
volatile unsigned char calram[32][32] = {
0,1,2,3,4,5,6,7,8,9,
10,11,12,13,14,15,16,17,18,19,
20,21,22,23,24,25,26,27,28,29,
30,31,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49,
50,51,52,53,54,55,56,57,58,59,
60,61,62,63,64,65,66,67,68,69,
70,71,72,73,74,75,76,77,78,79,
80,81,82,83,84,85,86,87,88,89,
90,91,92,93,94,95,96,97,98,99
};
/* EEPROM */
volatile unsigned char eeprom[8] = {
0,1,2,3,4,5,6,7
};
/* Array of struct */
typedef struct {
char ch1;
long l;
char ch2;
int i;
} test_t ;
volatile test_t test_array[10] =
{
{0,1,2,3},
{10,11,12,13},
{20,21,22,23},
{30,31,32,33},
{40,41,42,43},
{50,51,52,53},
{60,61,62,63},
{70,71,72,73},
{80,81,82,83},
{90,91,92,93}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -