功能基本OK

This commit is contained in:
sunbeam 2024-12-20 15:22:18 +08:00
parent 69769f95f4
commit d1915a2fac
18 changed files with 1330 additions and 262 deletions

View File

@ -29,7 +29,11 @@
"key.h": "c",
"dbccodeconf.h": "c",
"canmatrix.h": "c",
"scm_canmatrix-binutil.h": "c"
"scm_canmatrix-binutil.h": "c",
"fee_cfg.h": "c",
"string.h": "c",
"fee_internal.h": "c",
"memorytask.h": "c"
},
"C_Cpp.default.compilerPath": "",
"MicroPython.executeButton": [

View File

@ -367,6 +367,8 @@
<state>$PROJ_DIR$\src\CANmatrix\conf</state>
<state>$PROJ_DIR$\src\CANmatrix\lib</state>
<state>$PROJ_DIR$\src\CANmatrix\usr</state>
<state>$PROJ_DIR$\src\fee</state>
<state>$PROJ_DIR$\SDK\middleware\nvm\fee</state>
</option>
<option>
<name>CCStdIncCheck</name>
@ -2681,6 +2683,33 @@
<name>$PROJ_DIR$\SDK\platform\devices\CVM014x\mcu.h</name>
</file>
</group>
<group>
<name>fee</name>
<file>
<name>$PROJ_DIR$\SDK\middleware\nvm\fee\fee.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\fee\fee_cfg.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\fee\fee_cfg.h</name>
</file>
<file>
<name>$PROJ_DIR$\SDK\middleware\nvm\fee\fee_initialization.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\fee\fee_internal.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\fee\fee_internal.h</name>
</file>
<file>
<name>$PROJ_DIR$\src\fee\MemoryTask.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\fee\MemoryTask.h</name>
</file>
</group>
<group>
<name>linker</name>
<file>
@ -2698,6 +2727,9 @@
<name>$PROJ_DIR$\SDK\middleware\isotp\isotp.h</name>
</file>
</group>
<group>
<name>nvm</name>
</group>
<group>
<name>uds</name>
<group>

View File

@ -3306,6 +3306,33 @@
<name>$PROJ_DIR$\SDK\platform\devices\CVM014x\mcu.h</name>
</file>
</group>
<group>
<name>fee</name>
<file>
<name>$PROJ_DIR$\SDK\middleware\nvm\fee\fee.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\fee\fee_cfg.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\fee\fee_cfg.h</name>
</file>
<file>
<name>$PROJ_DIR$\SDK\middleware\nvm\fee\fee_initialization.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\fee\fee_internal.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\fee\fee_internal.h</name>
</file>
<file>
<name>$PROJ_DIR$\src\fee\MemoryTask.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\fee\MemoryTask.h</name>
</file>
</group>
<group>
<name>linker</name>
<file>
@ -3323,6 +3350,9 @@
<name>$PROJ_DIR$\SDK\middleware\isotp\isotp.h</name>
</file>
</group>
<group>
<name>nvm</name>
</group>
<group>
<name>uds</name>
<group>

View File

@ -29,11 +29,11 @@
<EnforceMemoryConfiguration>1</EnforceMemoryConfiguration>
</ArmDriver>
<DebugChecksum>
<Checksum>3001005802</Checksum>
<Checksum>1315671368</Checksum>
</DebugChecksum>
<Disassembly>
<MixedMode>1</MixedMode>
<InstrCount>0</InstrCount>
<MixedMode>1</MixedMode>
</Disassembly>
<Trace1>
<Enabled>0</Enabled>
@ -151,8 +151,9 @@
<mode>0</mode>
</DisassembleMode>
<Breakpoints2>
<Bp0>_ 1 "EMUL_CODE" "{$PROJ_DIR$\src\hwctrl.c}.90.5" 0 0 1 "" 0 "" 0</Bp0>
<Count>1</Count>
<Bp0>_ 1 "EMUL_CODE" "{$PROJ_DIR$\src\fee\MemoryTask.c}.49.9" 0 0 1 "" 0 "" 0</Bp0>
<Bp1>_ 1 "EMUL_CODE" "{$PROJ_DIR$\src\fee\MemoryTask.c}.96.13" 0 0 1 "" 0 "" 0</Bp1>
<Count>2</Count>
</Breakpoints2>
<Aliases>
<Count>0</Count>

File diff suppressed because one or more lines are too long

View File

@ -26,7 +26,7 @@ static uint16_t HeatDutyCounter;
* the const
******************************************************************************/
const uint8_t HeatDutyTab[4] = {0,10,20,80};
const uint8_t FanDutyTab[4] = {0,10,30,100};
const uint8_t FanDutyTab[4] = {0,10,30,85};
/*******************************************************************************
* the functions
@ -52,6 +52,7 @@ void FanHeatMainTaks(void)//10ms
{
HeatState = 0;
}
FanState = 0;
}
if (getKeyPressFlag(KEY_FAN) == KEY_PRESSED)
{
@ -60,6 +61,7 @@ void FanHeatMainTaks(void)//10ms
{
FanState = 0;
}
HeatState = 0;
}
FanTask();
HeatTask();
@ -91,6 +93,7 @@ static void HeatTask(void)
else
{
HeatDutyCounter = 0;
HeatDrv1Ctrl(0);
}
}

View File

@ -1,6 +1,7 @@
#include "MotorCtrl.h"
#include "hwctrl.h"
#include "scm_canmatrix-binutil.h"
#include "MemoryTask.h"
/*******************************************************************************
* the defines
******************************************************************************/
@ -13,14 +14,8 @@
#define AUTOCAL_ACT2 3
#define AUTOCAL_END 4
#define OC_10A 100
#define OC_30A 300
#define OC_500mS 500
#define OC_50mS 50
#define OC_TIME_200MS 200
#define HALLDELAYMAX 2
#define OC_DELAY_TIME 200
/*******************************************************************************
* the typedefs
******************************************************************************/
@ -30,37 +25,38 @@ typedef struct
uint16_t MotorStopLoc1;
uint16_t MotorStopLoc2;
uint16_t MotorNowLoc;
}MOTOR_DATA;
}MOTOR_DATA;//6 byte
typedef struct
{
uint16_t start_flag;
MOTOR_DATA MotorData[6];
uint16_t MemoryLoc[3][6];
uint16_t checksum;
uint16_t stop_flag;
uint16_t start_flag;//2
MOTOR_DATA MotorData[6];// 6 * 6
uint16_t MemoryLoc[3][6];//36
uint16_t checksum;//2
uint16_t stop_flag;//2
}MEMORY_DATA;
/*******************************************************************************
* the globals
******************************************************************************/
MOTOR_DATA MotorData[6];
uint16_t MemoryLoc[3][6];
MEMORY_DATA MemoryData;
uint8_t OC1flag,OC2flag,OC3flag;
uint16_t OC1Count,OC2Count,OC3Count;
uint8_t MotorState[6],MotorStateReal[6];
uint8_t MotorHallIO[6];
uint16_t MotorHallLoc[6],MotorHardStop1[6],MotorHardStop2[6];
uint8_t MotorLearnState[6];
uint8_t MotorErr[6];
uint16_t MotorTarget[6] = {0};
uint16_t current1,current2,current3;
uint8_t stopflag = 0;
static MOTOR_DATA MotorData[6];
static uint16_t MemoryLoc[3][6];
static MEMORY_DATA MemoryData;
static uint8_t OC1flag,OC2flag,OC3flag;
static uint16_t OC1Count,OC2Count,OC3Count;
static uint8_t MotorState[6],MotorStateReal[6];
static uint8_t MotorHallIO[6];
static uint16_t MotorHallLoc[6],MotorHardStop1[6],MotorHardStop2[6];
static uint8_t MotorLearnState[6];
static uint8_t MotorErr[6];
static uint16_t MotorTarget[6] = {0};
static uint16_t current1,current2,current3;
static uint8_t stopflag = 0;
static uint8_t AutoCalState;
uint16_t HallErrorCount[6];
static uint16_t HallErrorCount[6];
static uint8_t MotorMemoryReadState,MotorDataChangeFlag;
static uint16_t MotorDataChangeDelay;
/*******************************************************************************
* the const
******************************************************************************/
@ -73,10 +69,26 @@ static void AutoCalCtrl(void);
static void MotorValueInit(void);
static uint16_t getOverCurrentTh(uint8_t ch);
static uint16_t GetCheckSum(uint16_t * addr,uint8_t len);
static void MotorMemoryDataUnpack(void);
static void MotorMemoryDataPack(void);
static void MotorDataChange(void);
/*******************************************************************************
* the local functions
******************************************************************************/
static uint16_t GetCheckSum(uint16_t * addr,uint8_t len)
{
uint16_t sum=0;
while (len --)
{
sum += *addr;
}
sum ^= 0xffff;
return sum;
}
static void MotorValueInit(void)
{
uint8_t i;
@ -85,7 +97,96 @@ static void MotorValueInit(void)
MotorHallLoc[i] = 0x8000;
MotorErr[i] = 0;
}
//ReadMotorMemory();
MemoryTask_ReqRead(FEE_BLOCK_MOTORDATA_DATASET0,(uint8_t *)&MemoryData,sizeof(MemoryData));
MotorMemoryReadState = 0;
}
static void MotorMemoryDataUnpack(void)
{
uint8_t i;
uint16_t checksum;
checksum = GetCheckSum(&MemoryData.MotorData[0].MotorStopLoc1,72);
if (MemoryData.start_flag == START_FLAG && MemoryData.stop_flag == STOP_FLAG && checksum == MemoryData.checksum)//
{
for (i = 0; i < 6; i++)
{
MotorHallLoc[i] = MemoryData.MotorData[i].MotorNowLoc;
MotorHardStop1[i] = MemoryData.MotorData[i].MotorStopLoc1;
MotorHardStop2[i] = MemoryData.MotorData[i].MotorStopLoc2;
MemoryLoc[0][i] = MemoryData.MemoryLoc[0][i];
MemoryLoc[1][i] = MemoryData.MemoryLoc[1][i];
MemoryLoc[2][i] = MemoryData.MemoryLoc[2][i];
}
}
else
{
for (i = 0; i < 6; i++)
{
MotorHallLoc[i] = 0x8000;
MotorHardStop1[i] = 0;
MotorHardStop2[i] = 0;
MemoryLoc[0][i] = 0;
MemoryLoc[1][i] = 0;
MemoryLoc[2][i] = 0;
}
}
}
static void MotorMemoryDataPack(void)
{
uint8_t i;
MemoryData.start_flag = START_FLAG;
MemoryData.stop_flag = STOP_FLAG;
for (i = 0; i < 6; i++)
{
MemoryData.MotorData[i].MotorNowLoc = MotorHallLoc[i];
MemoryData.MotorData[i].MotorStopLoc1 = MotorHardStop1[i];
MemoryData.MotorData[i].MotorStopLoc2 = MotorHardStop2[i];
MemoryData.MemoryLoc[0][i] = MemoryLoc[0][i];
MemoryData.MemoryLoc[1][i] = MemoryLoc[1][i];
MemoryData.MemoryLoc[2][i] = MemoryLoc[2][i];
}
MemoryData.checksum = GetCheckSum(&MemoryData.MotorData[0].MotorStopLoc1,72);
}
static void MotorMemoryTask(void)//10ms
{
FEERWSTATE_t ret;
if (MotorMemoryReadState == 0)
{
ret = MemoryTask_getReadState();
if (ret == FEERWSTATE_FINISHED)
{
MotorMemoryDataUnpack();
MotorMemoryReadState = 1;
}
else if (ret == FEERWSTATE_ERROR)
{
MotorMemoryReadState = 1;
MotorDataChange();
}
}
if (MotorDataChangeFlag > 0 )
{
if (MotorDataChangeDelay > 0)
{
MotorDataChangeDelay--;
}
else
{
MotorDataChangeDelay = 0;
MotorDataChangeFlag = 0;
MotorMemoryDataPack();
MemoryTask_ReqWrite(FEE_BLOCK_MOTORDATA_DATASET0,(uint8_t *)&MemoryData,sizeof(MemoryData));
}
}
}
static void AutoCalCtrl(void)
@ -108,12 +209,11 @@ static void AutoCalCtrl(void)
MotorArr3state = 1;
setMotorState(MotorHG,Motor_ACT_CW);
setMotorState(MotorTT,Motor_ACT_CW);
setMotorState(Motor5,Motor_ACT_CW);
autocalcounter[0] = 0;
autocalcounter[1] = 0;
autocalcounter[2] = 0;
AutoCalState++;
for (i = 0; i < 6; i++)
for (i = 0; i < 4; i++)
{
MotorHardStop1[i] = 0;
MotorHardStop2[i] = 0;
@ -121,7 +221,7 @@ static void AutoCalCtrl(void)
}
break;
case AUTOCAL_ACT1:
if (MotorArr1state == 0 && MotorArr2state == 0 && MotorArr3state == 0)
if (MotorArr1state == 0 && MotorArr2state == 0)
{
for (i = 0; i < 6; i++)
{
@ -325,102 +425,13 @@ static void AutoCalCtrl(void)
default:
break;
}
switch (MotorArr3state)
{
case 1://Motor5 xq
autocalcounter[2]++;
if (MotorHardStop1[Motor5] != 0)
{
MotorArr3state++;
wait3 = 0;
setMotorState(Motor5,Motor_ACT_NOACT);
}
if (autocalcounter[2] > 3000 || MotorErr[Motor5] != 0)
{
MotorArr3state = 4;
wait3 = 0;
setMotorState(Motor5,Motor_ACT_NOACT);
}
break;
case 2://wait
wait3++;
if (wait3 > 50)
{
MotorArr3state++;
setMotorState(Motor5,Motor_ACT_CCW);
autocalcounter[2] = 0;
}
break;
case 3://Motor5 xh
autocalcounter[2]++;
if (MotorHardStop2[Motor5] != 0)
{
MotorArr3state++;
wait3 = 0;
setMotorState(Motor5,Motor_ACT_NOACT);
}
if (autocalcounter[2] > 3000 || MotorErr[Motor5] != 0)
{
MotorArr3state = 4;
wait3 = 0;
setMotorState(Motor5,Motor_ACT_NOACT);
}
break;
case 4://wait
wait3++;
if (wait3 > 50)
{
MotorArr3state++;
setMotorState(Motor6,Motor_ACT_CW);
autocalcounter[2] = 0;
}
break;
case 5://Motor6 xq
autocalcounter[2]++;
if (MotorHardStop1[Motor6] != 0)
{
MotorArr3state++;
wait3 = 0;
setMotorState(Motor6,Motor_ACT_NOACT);
}
if (autocalcounter[2] > 3000 || MotorErr[Motor6] != 0)
{
MotorArr3state = 0;
setMotorState(Motor6,Motor_ACT_NOACT);
}
break;
case 6://wait
wait3++;
if (wait3 > 50)
{
MotorArr3state++;
setMotorState(Motor6,Motor_ACT_CCW);
autocalcounter[2] = 0;
}
break;
case 7:
autocalcounter[2]++;
if (MotorHardStop2[Motor6] != 0)
{
MotorArr3state=0;
wait3 = 0;
setMotorState(Motor6,Motor_ACT_NOACT);
}
if (autocalcounter[2] > 3000 || MotorErr[Motor6] != 0)
{
MotorArr3state = 0;
setMotorState(Motor6,Motor_ACT_NOACT);
}
break;
default:
break;
}
}
static void MotorCtrl(void)//10ms
{
uint8_t i;
//WriteMotorMemory(); //TODO
MotorMemoryTask(); //TODO
AutoCalCtrl();
@ -541,7 +552,120 @@ static void MotorCtrl(void)//10ms
}
#define OC_DELAY_TIME 200
static void MotorDataChange(void)
{
MotorDataChangeFlag = 1;
MotorDataChangeDelay = 100;
}
static void SetMotorMsg(void)
{
scm_canmatrix_tx.SCM_STATE.MOTOR_HG_STATE = MotorState[MotorHG];
scm_canmatrix_tx.SCM_STATE.MOTOR_KB_STATE = MotorState[MotorKB];
scm_canmatrix_tx.SCM_STATE.MOTOR_TT_STATE = MotorState[MotorTT];
scm_canmatrix_tx.SCM_STATE.MOTOR_ZY_STATE = MotorState[MotorZY];
scm_canmatrix_tx.SCM_DEBUG1.DEBUG_MOTOR_HG_STATUS = MotorStateReal[MotorHG];
scm_canmatrix_tx.SCM_DEBUG2.DEBUG_MOTOR_KB_STATUS = MotorStateReal[MotorKB];
scm_canmatrix_tx.SCM_DEBUG3.DEBUG_MOTOR_TT_STATUS = MotorStateReal[MotorTT];
scm_canmatrix_tx.SCM_DEBUG4.DEBUG_MOTOR_ZY_STATUS = MotorStateReal[MotorZY];
scm_canmatrix_tx.SCM_DEBUG1.DEBUG_MOTOR_HG_LOC = MotorHallLoc[MotorHG];
scm_canmatrix_tx.SCM_DEBUG2.DEBUG_MOTOR_KB_LOC = MotorHallLoc[MotorKB];
scm_canmatrix_tx.SCM_DEBUG3.DEBUG_MOTOR_TT_LOC = MotorHallLoc[MotorTT];
scm_canmatrix_tx.SCM_DEBUG4.DEBUG_MOTOR_ZY_LOC = MotorHallLoc[MotorZY];
scm_canmatrix_tx.SCM_DEBUG1.DEBUG_MOTOR_HG_STOP_1 = MotorHardStop1[MotorHG];
scm_canmatrix_tx.SCM_DEBUG1.DEBUG_MOTOR_HG_STOP_2 = MotorHardStop2[MotorHG];
scm_canmatrix_tx.SCM_DEBUG2.DEBUG_MOTOR_KB_STOP_1 = MotorHardStop1[MotorKB];
scm_canmatrix_tx.SCM_DEBUG2.DEBUG_MOTOR_KB_STOP_2 = MotorHardStop2[MotorKB];
scm_canmatrix_tx.SCM_DEBUG3.DEBUG_MOTOR_TT_STOP_1 = MotorHardStop1[MotorTT];
scm_canmatrix_tx.SCM_DEBUG3.DEBUG_MOTOR_TT_STOP_2 = MotorHardStop2[MotorTT];
scm_canmatrix_tx.SCM_DEBUG4.DEBUG_MOTOR_ZY_STOP_1 = MotorHardStop1[MotorZY];
scm_canmatrix_tx.SCM_DEBUG4.DEBUG_MOTOR_ZY_STOP_2 = MotorHardStop2[MotorZY];
scm_canmatrix_tx.SCM_DEBUG1.DEBUG_MOTOR_HG_HALLIO = MotorHallIO[MotorHG];
scm_canmatrix_tx.SCM_DEBUG2.DEBUG_MOTOR_KB_HALLIO = MotorHallIO[MotorKB];
scm_canmatrix_tx.SCM_DEBUG3.DEBUG_MOTOR_TT_HALLIO = MotorHallIO[MotorTT];
scm_canmatrix_tx.SCM_DEBUG4.DEBUG_MOTOR_ZY_HALLIO = MotorHallIO[MotorZY];
//scm_canmatrix_tx.SCM_STATE.ZY_HEAT_STATE = AutoCalState;
}
/*******************************************************************************
* the global functions
******************************************************************************/
void MotorCtrl_Init(void)
{
for (uint8_t i = 0; i < 6; i++)
{
hw_MotorCtrl(i, Motor_ACT_NOACT);
}
MotorValueInit();
}
void MotorCtrl_Maintask(void)//10ms task
{
MotorCtrl();
for (Motor_ID_Type i = 0; i < MOTOR_NUM; i++)
{
hw_MotorCtrl( i, MotorStateReal[i]);
}
SetMotorMsg();
}
void setMotorState(Motor_ID_Type motorid,Motor_ACT_Type act)
{
if (act < Motor_ACT_NUM && motorid < MOTOR_NUM)
{
MotorState[motorid] = act;
}
}
void setMotorTarget(uint8_t motorid,uint16_t target)
{
if (MotorHardStop1[motorid]!=0 && MotorHardStop2[motorid]!=0)
{
MotorTarget[motorid] = target;
}
else
{
MotorTarget[motorid] = 0;
}
}
void StartAutoCal(void)
{
AutoCalState = AUTOCAL_START;
}
void StopAutoCal(void)
{
uint8_t i;
if (AutoCalState != AUTOCAL_STOP)
{
AutoCalState = AUTOCAL_STOP;
setMotorState(MotorHG,Motor_ACT_NOACT);
setMotorState(MotorKB,Motor_ACT_NOACT);
setMotorState(MotorTT,Motor_ACT_NOACT);
setMotorState(MotorZY,Motor_ACT_NOACT);
}
for (i = 0; i < 4; i++)
{
if (MotorTarget[i] != 0)
{
MotorTarget[i] = 0;
stopflag = 1;
}
}
}
void CurrentDetect(void)
{
uint32_t oc_th,current;
@ -578,112 +702,6 @@ void CurrentDetect(void)
}
}
/*******************************************************************************
* the global functions
******************************************************************************/
void MotorCtrl_Init(void)
{
for (uint8_t i = 0; i < 6; i++)
{
hw_MotorCtrl(i, Motor_ACT_NOACT);
}
MotorValueInit();
}
static void SetMotorMsg(void)
{
scm_canmatrix_tx.SCM_STATE.MOTOR_HG_STATE = MotorState[MotorHG];
scm_canmatrix_tx.SCM_STATE.MOTOR_KB_STATE = MotorState[MotorKB];
scm_canmatrix_tx.SCM_STATE.MOTOR_TT_STATE = MotorState[MotorTT];
scm_canmatrix_tx.SCM_STATE.MOTOR_ZY_STATE = MotorState[MotorZY];
scm_canmatrix_tx.SCM_DEBUG1.DEBUG_MOTOR_HG_STATUS = MotorStateReal[MotorHG];
scm_canmatrix_tx.SCM_DEBUG2.DEBUG_MOTOR_KB_STATUS = MotorStateReal[MotorKB];
scm_canmatrix_tx.SCM_DEBUG3.DEBUG_MOTOR_TT_STATUS = MotorStateReal[MotorTT];
scm_canmatrix_tx.SCM_DEBUG4.DEBUG_MOTOR_ZY_STATUS = MotorStateReal[MotorZY];
scm_canmatrix_tx.SCM_DEBUG1.DEBUG_MOTOR_HG_LOC = MotorHallLoc[MotorHG];
scm_canmatrix_tx.SCM_DEBUG2.DEBUG_MOTOR_KB_LOC = MotorHallLoc[MotorKB];
scm_canmatrix_tx.SCM_DEBUG3.DEBUG_MOTOR_TT_LOC = MotorHallLoc[MotorTT];
scm_canmatrix_tx.SCM_DEBUG4.DEBUG_MOTOR_ZY_LOC = MotorHallLoc[MotorZY];
scm_canmatrix_tx.SCM_DEBUG1.DEBUG_MOTOR_HG_STOP_1 = MotorHardStop1[MotorHG];
scm_canmatrix_tx.SCM_DEBUG1.DEBUG_MOTOR_HG_STOP_2 = MotorHardStop2[MotorHG];
scm_canmatrix_tx.SCM_DEBUG2.DEBUG_MOTOR_KB_STOP_1 = MotorHardStop1[MotorKB];
scm_canmatrix_tx.SCM_DEBUG2.DEBUG_MOTOR_KB_STOP_2 = MotorHardStop2[MotorKB];
scm_canmatrix_tx.SCM_DEBUG3.DEBUG_MOTOR_TT_STOP_1 = MotorHardStop1[MotorTT];
scm_canmatrix_tx.SCM_DEBUG3.DEBUG_MOTOR_TT_STOP_2 = MotorHardStop2[MotorTT];
scm_canmatrix_tx.SCM_DEBUG4.DEBUG_MOTOR_ZY_STOP_1 = MotorHardStop1[MotorZY];
scm_canmatrix_tx.SCM_DEBUG4.DEBUG_MOTOR_ZY_STOP_2 = MotorHardStop2[MotorZY];
scm_canmatrix_tx.SCM_DEBUG1.DEBUG_MOTOR_HG_HALLIO = MotorHallIO[MotorHG];
scm_canmatrix_tx.SCM_DEBUG2.DEBUG_MOTOR_KB_HALLIO = MotorHallIO[MotorKB];
scm_canmatrix_tx.SCM_DEBUG3.DEBUG_MOTOR_TT_HALLIO = MotorHallIO[MotorTT];
scm_canmatrix_tx.SCM_DEBUG4.DEBUG_MOTOR_ZY_HALLIO = MotorHallIO[MotorZY];
}
void MotorCtrl_Maintask(void)//10ms task
{
MotorCtrl();
for (Motor_ID_Type i = 0; i < MOTOR_NUM; i++)
{
hw_MotorCtrl( i, MotorStateReal[i]);
}
SetMotorMsg();
}
void setMotorState(Motor_ID_Type motorid,Motor_ACT_Type act)
{
if (act < Motor_ACT_NUM && motorid < MOTOR_NUM)
{
MotorState[motorid] = act;
}
}
void setMotorTarget(uint8_t motorid,uint16_t target)
{
if (MotorHardStop1[motorid]!=0 && MotorHardStop2[motorid]!=0)
{
MotorTarget[motorid] = target;
}
else
{
MotorTarget[motorid] = 0;
}
}
void StartAutoCal(void)
{
AutoCalState = AUTOCAL_START;
}
void StopAutoCal(void)
{
uint8_t i;
if (AutoCalState != AUTOCAL_STOP)
{
AutoCalState = AUTOCAL_STOP;
setMotorState(MotorHG,Motor_ACT_NOACT);
setMotorState(MotorKB,Motor_ACT_NOACT);
setMotorState(MotorTT,Motor_ACT_NOACT);
setMotorState(MotorZY,Motor_ACT_NOACT);
setMotorState(Motor5,Motor_ACT_NOACT);
setMotorState(Motor6,Motor_ACT_NOACT);
}
for (i = 0; i < 6; i++)
{
if (MotorTarget[i] != 0)
{
MotorTarget[i] = 0;
stopflag = 1;
}
}
}
@ -753,8 +771,7 @@ void HallDetecte(void)
}
HallErrorCount[i] = 0;
MotorErr[i] = 0;
//EEL_SAVE_Counter = 1000;
//EEL_SAVE_REQUIRE_FLAG = 1;
MotorDataChange();
}
else
{
@ -772,11 +789,33 @@ void HallDetecte(void)
}
}
/*
if (EEL_SAVE_Counter > 0)
{
EEL_SAVE_Counter--;
}
*/
}
void MotorMemorySet(MOTOR_MEMORY_Type id)
{
if (id >= 3)
{
return;
}
for (uint8_t i = 0; i < 6; i++)
{
if (MotorHardStop1[i]!=0 && MotorHardStop2[i]!=0)
{
MemoryLoc[id][i] = MotorHallLoc[i];
}
}
MotorDataChange();
}
void MotorMemoryGet(MOTOR_MEMORY_Type id)
{
if (id >= 3)
{
return;
}
for (uint8_t i = 0; i < 6; i++)
{
setMotorTarget(i,MemoryLoc[id][i]);
}
}

View File

@ -24,6 +24,12 @@ typedef enum
Motor6,//
MOTOR_NUM,
} Motor_ID_Type;
typedef enum
{
MOTOR_MEMORY_1,
MOTOR_MEMORY_2,
MOTOR_MEMORY_3,
}MOTOR_MEMORY_Type;
@ -35,6 +41,9 @@ void StartAutoCal(void);
void StopAutoCal(void);
void CurrentDetect(void);
void HallDetecte(void);
void MotorMemoryGet(MOTOR_MEMORY_Type id);
void MotorMemorySet(MOTOR_MEMORY_Type id);
#endif

View File

@ -13,6 +13,7 @@
#include "key.h"
#include "scm_canmatrix-binutil.h"
#include "FanHeat.h"
#include "MemoryTask.h"
/*******************************************************************************
* the defines
******************************************************************************/
@ -93,6 +94,7 @@ void appTask(void)
{
KeyScanTask();
KeyProTask();
MemoryMainTask();
}
if (gSystick1msCnt % 10 == 0)
@ -132,6 +134,8 @@ void appTaskInit(void)
power_ctrl(1);
FanHeatInit();
MemoryTaskInit();
}

View File

@ -0,0 +1,153 @@
/*******************************************************************************
* the includes
******************************************************************************/
#include "string.h"
#include "MemoryTask.h"
#include "fee.h"
#include "fee_internal.h"
#include "fee_extra.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
static FlashDrv_ConfigType flashConfig;
static uint8_t WriteReq,ReadReq,WriteReqBlockID;
extern McuType mcu;
static uint8_t feeWriteBuffer[100] = {0};
static uint8_t feeReadBuffer[100] = {0};
static uint8_t *ReadDataPtr;
static uint8_t ReadLen,ReadBlockID;
static FEERWSTATE_t ReadState,WriteState;
/*******************************************************************************
* the const
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
static void WriteNotification(Fee_NotificationType notificationNumber)
{
if(FEE_JOBENDNOTIFICATION == notificationNumber)
{
WriteState = FEERWSTATE_FINISHED;
}
else
{
WriteState = FEERWSTATE_ERROR;
}
}
static void ReadNotification(Fee_NotificationType notificationNumber)
{
if(FEE_JOBENDNOTIFICATION == notificationNumber)
{
ReadState = FEERWSTATE_FINISHED;
if (ReadDataPtr != NULL)
{
memcpy(ReadDataPtr,feeReadBuffer,ReadLen);
}
}
else
{
ReadState = FEERWSTATE_ERROR;
}
ReadDataPtr = NULL;
ReadLen = 0;
}
void MemoryTaskInit(void)
{
/*! \note disable cache,because cache-enable impact the flash memory data checking on debug side */
/* use fee must disable cache! */
*((volatile uint32_t *)0xE0082000u) = 0x0;
FlashDrv_GetDefaultConfig(&flashConfig);
FlashDrv_Configure(&mcu.flashDrv, &flashConfig);
Fee_Configure(&fee);
WriteReq = 0;
}
void MemoryMainTask(void)
{
if (FEE_STATUS_IDLE == Fee_GetStatus(&fee))
{
//写请求
if(WriteReq > 0)
{
if(FEE_RETURN_OK == Fee_Write(&fee, WriteReqBlockID, feeWriteBuffer, WriteNotification))
{
WriteReq = 0;
WriteState = FEERWSTATE_START;
}
}
//读请求
if (ReadReq > 0)
{
if(FEE_RETURN_OK == Fee_Read(&fee, ReadBlockID, 0, feeReadBuffer, ReadNotification))
{
ReadReq = 0;
ReadState = FEERWSTATE_START;
}
}
}
Fee_MainFunction(&fee);
}
void MemoryTask_ReqWrite(uint8_t id,uint8_t *dataptr,uint8_t len)
{
WriteReq = 1;
WriteReqBlockID = id;
WriteState = FEERWSTATE_REQ;
memcpy(feeWriteBuffer,dataptr,len);
}
void MemoryTask_ReqRead(uint8_t id,uint8_t *dataptr,uint8_t len)
{
ReadReq = 1;
ReadState = FEERWSTATE_REQ;
ReadDataPtr = dataptr;
ReadLen = len;
ReadBlockID = id;
}
FEERWSTATE_t MemoryTask_getReadState(void)
{
FEERWSTATE_t ret = ReadState;
if (ReadState > FEERWSTATE_START)
{
ReadState = FEERWSTATE_IDLE;
}
return ret;
}
FEERWSTATE_t MemoryTask_getWriteState(void)
{
FEERWSTATE_t ret = WriteState;
if (WriteState > FEERWSTATE_START)
{
WriteState = FEERWSTATE_IDLE;
}
return ret;
}

View File

@ -0,0 +1,48 @@
#ifndef __MEMORYTASK_H__
#define __MEMORYTASK_H__
/*******************************************************************************
* the includes
******************************************************************************/
#include "mcu.h"
#include "fee_cfg.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
typedef enum
{
FEERWSTATE_IDLE,
FEERWSTATE_REQ,
FEERWSTATE_START,
FEERWSTATE_FINISHED,
FEERWSTATE_ERROR
}FEERWSTATE_t;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
void MemoryTaskInit(void);
void MemoryMainTask(void);
FEERWSTATE_t MemoryTask_getReadState(void);
FEERWSTATE_t MemoryTask_getWriteState(void);
void MemoryTask_ReqRead(uint8_t id,uint8_t *dataptr,uint8_t len);
void MemoryTask_ReqWrite(uint8_t id,uint8_t *dataptr,uint8_t len);
#endif

View File

@ -0,0 +1,249 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "fee_cfg.h"
#include "fee_extra.h"
#include "fee_jobs.h"
#include "fee_sector.h"
#include "fee_internal.h"
#include "mcu.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
const Fee_BlockConfigType Fee_BlockCfg[FEE_BLOCK_NUM] =
{
{
FEE_BLOCK_MOTORDATA_DATASET0,
81,
},
{
FEE_BLOCK_DIDDATA0_DATASET0,
21,
},
{
FEE_BLOCK_DIDDATA1_DATASET0,
21,
},
{
FEE_BLOCK_DIDDATA2_DATASET0,
21,
},
{
FEE_BLOCK_DIDDATA3_DATASET0,
21,
},
{
FEE_BLOCK_DIDDATA4_DATASET0,
21,
},
{
FEE_BLOCK_DIDDATA5_DATASET0,
21,
},
{
FEE_BLOCK_DIDDATA6_DATASET0,
21,
},
{
FEE_BLOCK_DIDDATA7_DATASET0,
21,
},
{
FEE_BLOCK_DIDDATA8_DATASET0,
21,
},
{
FEE_BLOCK_DIDDATA9_DATASET0,
21,
},
};
Fee_BlockInfoType Fee_BlockInfo[FEE_BLOCK_NUM];
const Fee_BlockType Fee_Block[FEE_BLOCK_NUM] =
{
{
&Fee_BlockCfg[0],
&Fee_BlockInfo[0]
},
{
&Fee_BlockCfg[1],
&Fee_BlockInfo[1]
},
{
&Fee_BlockCfg[2],
&Fee_BlockInfo[2]
},
{
&Fee_BlockCfg[3],
&Fee_BlockInfo[3]
},
{
&Fee_BlockCfg[4],
&Fee_BlockInfo[4]
},
{
&Fee_BlockCfg[5],
&Fee_BlockInfo[5]
},
{
&Fee_BlockCfg[6],
&Fee_BlockInfo[6]
},
{
&Fee_BlockCfg[7],
&Fee_BlockInfo[7]
},
{
&Fee_BlockCfg[8],
&Fee_BlockInfo[8]
},
{
&Fee_BlockCfg[9],
&Fee_BlockInfo[9]
},
{
&Fee_BlockCfg[10],
&Fee_BlockInfo[10]
},
};
Fee_SectorInfoType Fee_SectorInfo[FEE_SECTOR_NUM];
const Fee_SectorConfigType Fee_SectorCfg[FEE_SECTOR_NUM] =
{
{
(void *)0x10010000,
(void *)0x10010800,
2,
&Fee_SectorInfo[0]
},
{
(void *)0x10010800,
(void *)0x10011000,
2,
&Fee_SectorInfo[1]
},
};
const Fee_SectorType Fee_Sector =
{
FEE_SECTOR_NUM,
&Fee_SectorCfg[0],
FEE_BLOCK_NUM,
&Fee_Block[0],
};
const Fee_MethodType Fee_FlsMethod =
{
Fee_InternalWriteCheck,
Fee_InternalReadCheckData,
Fee_InternalEarseCheckPhrase,
Fee_InternalIsWriteable,
Fee_InternalCalcCrc8
};
Fee_JobControlBlockType Fee_sysJob =
{
FEE_JOB_UNLOCK,
0x0000,
0x0000,
FEE_JOB_OP_UNDEFINE,
NULL,
NULL,
};
Fee_JobControlBlockType Fee_userJob =
{
FEE_JOB_UNLOCK,
0x0000,
0x0000,
FEE_JOB_OP_UNDEFINE,
NULL,
NULL,
};
Fee_JobsType Fee_JobCfg =
{
false,
&Fee_userJob,
&Fee_sysJob
};
Fee_JobControlBlockType Fee_JobControlBlock =
{
FEE_JOB_UNLOCK,
0,
0,
FEE_JOB_OP_UNDEFINE,
NULL,
NULL
};
Fee_GcRuntimeType Fee_GcRuntime =
{
FEE_GC_INIT,
FEE_GC_COPY_WRITE_MARK,
NULL,
0,
NULL,
NULL,
NULL,
FEE_GC_STATE_NO_ERROR
};
Fee_RunTimeType Fee_Runtime =
{
FEE_MAIN_FUN_FSM_ERROR,
FEE_INITIALIZATION_ERROR,
&Fee_JobCfg,
NULL,
&Fee_JobControlBlock,
&Fee_GcRuntime,
FEE_JOB_RESULT_OK
};
uint8_t Fee_RuntimeCache[FEE_BUFF_SIZE];
const FeeType fee =
{
&Fee_Sector,
&Fee_FlsMethod,
&Fee_Runtime,
(void *)&Fee_RuntimeCache[0],
};
/*******************************************************************************
* the functions
******************************************************************************/

View File

@ -0,0 +1,66 @@
/* * Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _FEE_CFG_H_
#define _FEE_CFG_H_
/*******************************************************************************
* the includes
******************************************************************************/
#include "fee_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
#define FEE_SECTOR_NUM (2)
#define FEE_BLOCK_NUM (11)
#define FEE_JOBS_BUFF_NUM (2)
#define FEE_BUFF_SIZE (64)
#define FEE_BLOCK_MOTORDATA_DATASET0 (0x10)
#define FEE_BLOCK_DIDDATA0_DATASET0 (0x20)
#define FEE_BLOCK_DIDDATA1_DATASET0 (0x30)
#define FEE_BLOCK_DIDDATA2_DATASET0 (0x40)
#define FEE_BLOCK_DIDDATA3_DATASET0 (0x50)
#define FEE_BLOCK_DIDDATA4_DATASET0 (0x60)
#define FEE_BLOCK_DIDDATA5_DATASET0 (0x70)
#define FEE_BLOCK_DIDDATA6_DATASET0 (0x80)
#define FEE_BLOCK_DIDDATA7_DATASET0 (0x90)
#define FEE_BLOCK_DIDDATA8_DATASET0 (0xa0)
#define FEE_BLOCK_DIDDATA9_DATASET0 (0xb0)
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
extern const FeeType fee;
/*******************************************************************************
* the function prototypes
******************************************************************************/
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _FEE_CFG_H_ */

View File

@ -0,0 +1,297 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stddef.h>
#include "mcu.h"
#include "drivers/flash/flash_drv.h"
#include "fee_extra.h"
extern McuType mcu;
/*******************************************************************************
* the defines
******************************************************************************/
#define FEE_INTERNAL_CRC_TABLE_SIZE (256U)
#define FEE_INTERNAL_WRITE_PHASE_LEN (8)
/*******************************************************************************
* the typedefs
******************************************************************************/
typedef enum
{
FEE_INTERNAL_ERROR_WRITE_PHASE_UNEARSE = 0x00,
FEE_INTERNAL_ERROR_WRITE_PHASE_ERROR,
FEE_INTERNAL_ERROR_WRITE_PHASE_READBACK_ERROR,
FEE_INTERNAL_ERROR_READ_ERROR,
FEE_INTERNAL_ERROR_READ_UNWRITE_ERROR,
FEE_INTERNAL_ERROR_READ_READBACK_ERROR,
FEE_INTERNAL_ERROR_UNKNOW = 0xFF,
} Fee_InternalErrorsType;
/*******************************************************************************
* the globals
******************************************************************************/
static const uint8_t Fee_CrcTable8[FEE_INTERNAL_CRC_TABLE_SIZE] =
{
0x00U, 0x1DU, 0x3AU, 0x27U, 0x74U, 0x69U, 0x4EU, 0x53U, 0xE8U, 0xF5U, 0xD2U,
0xCFU, 0x9CU, 0x81U, 0xA6U, 0xBBU,
#if (FEE_INTERNAL_CRC_TABLE_SIZE == 256U)
0xCDU, 0xD0U, 0xF7U, 0xEAU, 0xB9U, 0xA4U, 0x83U, 0x9EU, 0x25U, 0x38U, 0x1FU,
0x02U, 0x51U, 0x4CU, 0x6BU, 0x76U, 0x87U, 0x9AU, 0xBDU, 0xA0U, 0xF3U, 0xEEU,
0xC9U, 0xD4U, 0x6FU, 0x72U, 0x55U, 0x48U, 0x1BU, 0x06U, 0x21U, 0x3CU, 0x4AU,
0x57U, 0x70U, 0x6DU, 0x3EU, 0x23U, 0x04U, 0x19U, 0xA2U, 0xBFU, 0x98U, 0x85U,
0xD6U, 0xCBU, 0xECU, 0xF1U, 0x13U, 0x0EU, 0x29U, 0x34U, 0x67U, 0x7AU, 0x5DU,
0x40U, 0xFBU, 0xE6U, 0xC1U, 0xDCU, 0x8FU, 0x92U, 0xB5U, 0xA8U, 0xDEU, 0xC3U,
0xE4U, 0xF9U, 0xAAU, 0xB7U, 0x90U, 0x8DU, 0x36U, 0x2BU, 0x0CU, 0x11U, 0x42U,
0x5FU, 0x78U, 0x65U, 0x94U, 0x89U, 0xAEU, 0xB3U, 0xE0U, 0xFDU, 0xDAU, 0xC7U,
0x7CU, 0x61U, 0x46U, 0x5BU, 0x08U, 0x15U, 0x32U, 0x2FU, 0x59U, 0x44U, 0x63U,
0x7EU, 0x2DU, 0x30U, 0x17U, 0x0AU, 0xB1U, 0xACU, 0x8BU, 0x96U, 0xC5U, 0xD8U,
0xFFU, 0xE2U, 0x26U, 0x3BU, 0x1CU, 0x01U, 0x52U, 0x4FU, 0x68U, 0x75U, 0xCEU,
0xD3U, 0xF4U, 0xE9U, 0xBAU, 0xA7U, 0x80U, 0x9DU, 0xEBU, 0xF6U, 0xD1U, 0xCCU,
0x9FU, 0x82U, 0xA5U, 0xB8U, 0x03U, 0x1EU, 0x39U, 0x24U, 0x77U, 0x6AU, 0x4DU,
0x50U, 0xA1U, 0xBCU, 0x9BU, 0x86U, 0xD5U, 0xC8U, 0xEFU, 0xF2U, 0x49U, 0x54U,
0x73U, 0x6EU, 0x3DU, 0x20U, 0x07U, 0x1AU, 0x6CU, 0x71U, 0x56U, 0x4BU, 0x18U,
0x05U, 0x22U, 0x3FU, 0x84U, 0x99U, 0xBEU, 0xA3U, 0xF0U, 0xEDU, 0xCAU, 0xD7U,
0x35U, 0x28U, 0x0FU, 0x12U, 0x41U, 0x5CU, 0x7BU, 0x66U, 0xDDU, 0xC0U, 0xE7U,
0xFAU, 0xA9U, 0xB4U, 0x93U, 0x8EU, 0xF8U, 0xE5U, 0xC2U, 0xDFU, 0x8CU, 0x91U,
0xB6U, 0xABU, 0x10U, 0x0DU, 0x2AU, 0x37U, 0x64U, 0x79U, 0x5EU, 0x43U, 0xB2U,
0xAFU, 0x88U, 0x95U, 0xC6U, 0xDBU, 0xFCU, 0xE1U, 0x5AU, 0x47U, 0x60U, 0x7DU,
0x2EU, 0x33U, 0x14U, 0x09U, 0x7FU, 0x62U, 0x45U, 0x58U, 0x0BU, 0x16U, 0x31U,
0x2CU, 0x97U, 0x8AU, 0xADU, 0xB0U, 0xE3U, 0xFEU, 0xD9U, 0xC4U
#endif
};
static const uint16_t Fee_CrcTable16[FEE_INTERNAL_CRC_TABLE_SIZE] =
{
0x0000U, 0x1021U, 0x2042U, 0x3063U, 0x4084U, 0x50A5U, 0x60C6U, 0x70E7U,
0x8108U, 0x9129U, 0xA14AU, 0xB16BU, 0xC18CU, 0xD1ADU, 0xE1CEU, 0xF1EFU,
#if (FEE_INTERNAL_CRC_TABLE_SIZE == 256U)
0x1231U, 0x0210U, 0x3273U, 0x2252U, 0x52B5U, 0x4294U, 0x72F7U, 0x62D6U,
0x9339U, 0x8318U, 0xB37BU, 0xA35AU, 0xD3BDU, 0xC39CU, 0xF3FFU, 0xE3DEU,
0x2462U, 0x3443U, 0x0420U, 0x1401U, 0x64E6U, 0x74C7U, 0x44A4U, 0x5485U,
0xA56AU, 0xB54BU, 0x8528U, 0x9509U, 0xE5EEU, 0xF5CFU, 0xC5ACU, 0xD58DU,
0x3653U, 0x2672U, 0x1611U, 0x0630U, 0x76D7U, 0x66F6U, 0x5695U, 0x46B4U,
0xB75BU, 0xA77AU, 0x9719U, 0x8738U, 0xF7DFU, 0xE7FEU, 0xD79DU, 0xC7BCU,
0x48C4U, 0x58E5U, 0x6886U, 0x78A7U, 0x0840U, 0x1861U, 0x2802U, 0x3823U,
0xC9CCU, 0xD9EDU, 0xE98EU, 0xF9AFU, 0x8948U, 0x9969U, 0xA90AU, 0xB92BU,
0x5AF5U, 0x4AD4U, 0x7AB7U, 0x6A96U, 0x1A71U, 0x0A50U, 0x3A33U, 0x2A12U,
0xDBFDU, 0xCBDCU, 0xFBBFU, 0xEB9EU, 0x9B79U, 0x8B58U, 0xBB3BU, 0xAB1AU,
0x6CA6U, 0x7C87U, 0x4CE4U, 0x5CC5U, 0x2C22U, 0x3C03U, 0x0C60U, 0x1C41U,
0xEDAEU, 0xFD8FU, 0xCDECU, 0xDDCDU, 0xAD2AU, 0xBD0BU, 0x8D68U, 0x9D49U,
0x7E97U, 0x6EB6U, 0x5ED5U, 0x4EF4U, 0x3E13U, 0x2E32U, 0x1E51U, 0x0E70U,
0xFF9FU, 0xEFBEU, 0xDFDDU, 0xCFFCU, 0xBF1BU, 0xAF3AU, 0x9F59U, 0x8F78U,
0x9188U, 0x81A9U, 0xB1CAU, 0xA1EBU, 0xD10CU, 0xC12DU, 0xF14EU, 0xE16FU,
0x1080U, 0x00A1U, 0x30C2U, 0x20E3U, 0x5004U, 0x4025U, 0x7046U, 0x6067U,
0x83B9U, 0x9398U, 0xA3FBU, 0xB3DAU, 0xC33DU, 0xD31CU, 0xE37FU, 0xF35EU,
0x02B1U, 0x1290U, 0x22F3U, 0x32D2U, 0x4235U, 0x5214U, 0x6277U, 0x7256U,
0xB5EAU, 0xA5CBU, 0x95A8U, 0x8589U, 0xF56EU, 0xE54FU, 0xD52CU, 0xC50DU,
0x34E2U, 0x24C3U, 0x14A0U, 0x0481U, 0x7466U, 0x6447U, 0x5424U, 0x4405U,
0xA7DBU, 0xB7FAU, 0x8799U, 0x97B8U, 0xE75FU, 0xF77EU, 0xC71DU, 0xD73CU,
0x26D3U, 0x36F2U, 0x0691U, 0x16B0U, 0x6657U, 0x7676U, 0x4615U, 0x5634U,
0xD94CU, 0xC96DU, 0xF90EU, 0xE92FU, 0x99C8U, 0x89E9U, 0xB98AU, 0xA9ABU,
0x5844U, 0x4865U, 0x7806U, 0x6827U, 0x18C0U, 0x08E1U, 0x3882U, 0x28A3U,
0xCB7DU, 0xDB5CU, 0xEB3FU, 0xFB1EU, 0x8BF9U, 0x9BD8U, 0xABBBU, 0xBB9AU,
0x4A75U, 0x5A54U, 0x6A37U, 0x7A16U, 0x0AF1U, 0x1AD0U, 0x2AB3U, 0x3A92U,
0xFD2EU, 0xED0FU, 0xDD6CU, 0xCD4DU, 0xBDAAU, 0xAD8BU, 0x9DE8U, 0x8DC9U,
0x7C26U, 0x6C07U, 0x5C64U, 0x4C45U, 0x3CA2U, 0x2C83U, 0x1CE0U, 0x0CC1U,
0xEF1FU, 0xFF3EU, 0xCF5DU, 0xDF7CU, 0xAF9BU, 0xBFBAU, 0x8FD9U, 0x9FF8U,
0x6E17U, 0x7E36U, 0x4E55U, 0x5E74U, 0x2E93U, 0x3EB2U, 0x0ED1U, 0x1EF0U
#endif
};
Fee_InternalErrorsType Fee_InternalErrors = FEE_INTERNAL_ERROR_UNKNOW;
/*******************************************************************************
* the functions
******************************************************************************/
static FlashDrv_Status FlashDrv_ReadData(FlashDrvType *obj, uint8_t *srcaddr, uint8_t *destaddr, uint32_t rdsize);
Fls_StateType Fee_InternalIsWriteable(Fee_AddressType sAddr, uint32_t size)
{
Fls_StateType ret = FLS_STATE_NOT_WRITABLE;
if(FLASHDRV_STATUS_SUCCESS == FlashDrv_Read1sSection(&mcu.flashDrv, (uint32_t *)sAddr, size))
{
ret = FLS_STATE_OK;
}
return ret;
}
Fls_StateType Fee_InternalWriteCheck(Fee_AddressType sAddr, uint8_t *buff, uint32_t size)
{
Fls_StateType ret = FLS_STATE_UNKNOW;
int idx;
for(idx = 0; idx < (size / FEE_INTERNAL_WRITE_PHASE_LEN); idx++)
{
if(FLASHDRV_STATUS_SUCCESS == FlashDrv_Read1sSection(&mcu.flashDrv, (uint32_t *)(sAddr + (idx * FEE_INTERNAL_WRITE_PHASE_LEN)), FEE_INTERNAL_WRITE_PHASE_LEN))
{
if(FLASHDRV_STATUS_SUCCESS == FlashDrv_ProgramPhrase(&mcu.flashDrv, (uint32_t *)(sAddr + (idx * FEE_INTERNAL_WRITE_PHASE_LEN)), buff + (idx * FEE_INTERNAL_WRITE_PHASE_LEN), true))
{
if(FLASHDRV_STATUS_SUCCESS == FlashDrv_CheckPhrase(&mcu.flashDrv, (uint32_t *)(sAddr + (idx * FEE_INTERNAL_WRITE_PHASE_LEN)), buff + (idx * FEE_INTERNAL_WRITE_PHASE_LEN)))
{
ret = FLS_STATE_OK;
}
else
{
ret = FLS_STATE_READ_BACK_FAIL;
Fee_InternalErrors = FEE_INTERNAL_ERROR_WRITE_PHASE_READBACK_ERROR;
break;
}
}
else
{
ret = FLS_STATE_PROGRAM_FAIL;
Fee_InternalErrors = FEE_INTERNAL_ERROR_WRITE_PHASE_ERROR;
break;
}
}
else
{
ret = FLS_STATE_NOT_WRITABLE;
Fee_InternalErrors = FEE_INTERNAL_ERROR_WRITE_PHASE_UNEARSE;
break;
}
}
return ret;
}
Fls_StateType Fee_InternalReadCheckData(Fee_AddressType sAddr, uint8_t *buff, uint32_t size)
{
Fls_StateType ret = FLS_STATE_UNKNOW;
int cnt;
if(FLASHDRV_STATUS_SUCCESS != FlashDrv_Read1sSection(&mcu.flashDrv, (uint32_t *)sAddr, size))
{
if(FLASHDRV_STATUS_SUCCESS == FlashDrv_ReadData(&mcu.flashDrv, (uint8_t *)sAddr, buff, size))
{
for(cnt = 0; cnt < (size / 8); cnt++)
{
if(FLASHDRV_STATUS_SUCCESS == FlashDrv_CheckPhrase(&mcu.flashDrv, (uint32_t *)(sAddr + cnt * 8), &buff[cnt * 8]))
{
ret = FLS_STATE_OK;
}
else
{
ret = FLS_STATE_READ_BACK_FAIL;
Fee_InternalErrors = FEE_INTERNAL_ERROR_READ_READBACK_ERROR;
break;
}
}
}
else
{
ret = FLS_STATE_ECC_ERROR;
Fee_InternalErrors = FEE_INTERNAL_ERROR_READ_ERROR;
}
}
else
{
ret = FLS_STATE_NOT_WRITTEN;
Fee_InternalErrors = FEE_INTERNAL_ERROR_READ_UNWRITE_ERROR;
}
return ret;
}
Fls_StateType Fee_InternalEarseCheckPhrase(Fee_AddressType earseAddr)
{
Fls_StateType ret = FLS_STATE_UNKNOW;
if(FLASHDRV_STATUS_SUCCESS != FlashDrv_Read1sSection(&mcu.flashDrv, (uint32_t *)earseAddr, FLASHDRV_DFLASH_SECTOR_SIZE))
{
if(FLASHDRV_STATUS_SUCCESS == FlashDrv_EraseSector(&mcu.flashDrv, (uint32_t *)earseAddr, FLASHDRV_SCTERS_RETRY))
{
if(FLASHDRV_STATUS_SUCCESS == FlashDrv_Read1sSection(&mcu.flashDrv, (uint32_t *)earseAddr, FLASHDRV_DFLASH_SECTOR_SIZE))
{
ret = FLS_STATE_OK;
}
else
{
ret = FLS_STATE_ERASE_FAIL;
}
}
else
{
ret = FLS_STATE_ERASE_FAIL;
}
}
else
{
ret = FLS_STATE_OK;
}
return ret;
}
uint16_t Fee_InternalCalcCrc16(void *sAddr, uint32_t size)
{
uint8_t crcStartValue16 = 0;
uint16_t *dataPtr = (uint16_t *)sAddr;
while(size != 0U)
{
/* Process one byte of data */
crcStartValue16 = Fee_CrcTable16[((uint8_t)(crcStartValue16 >> 8U)) ^ *dataPtr] ^ ((uint16_t)(crcStartValue16 << 8U));
++dataPtr;
--size;
}
return crcStartValue16;
}
uint8_t Fee_InternalCalcCrc8(void *sAddr, uint32_t size)
{
uint8_t crcStartValue8 = 0;
uint8_t *dataPtr = (uint8_t *)sAddr;
crcStartValue8 = 0xFFU;
while(size != 0U)
{
crcStartValue8 = Fee_CrcTable8[crcStartValue8 ^ *dataPtr];
++dataPtr;
--size;
}
crcStartValue8 ^= 0xFFU; /* XOR crc value */
return crcStartValue8;
}
static FlashDrv_Status FlashDrv_ReadData(FlashDrvType *obj, uint8_t *srcaddr, uint8_t *destaddr, uint32_t rdsize)
{
int i;
FlashDrv_Status ret = FLASHDRV_STATUS_ERROR;
for(i = 0; i < (rdsize / 8); i++)
{
if (FLASHDRV_STATUS_SUCCESS != FlashDrv_CheckEccState(obj, (uint32_t *)(srcaddr + i * 8)))
{
return ret;
}
}
for(i = 0; i < rdsize; i++)
{
destaddr[i] = srcaddr[i];
}
return FLASHDRV_STATUS_SUCCESS;
}

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _FEE_INTERNAL_H_
#define _FEE_INTERNAL_H_
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "fee_extra.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
extern Fls_StateType Fee_InternalIsWriteable(Fee_AddressType sAddr, uint32_t size);
extern Fls_StateType Fee_InternalWriteCheck(Fee_AddressType sAddr, uint8_t *buff, uint32_t size);
extern Fls_StateType Fee_InternalReadCheckData(Fee_AddressType sAddr, uint8_t *buff, uint32_t size);
extern Fls_StateType Fee_InternalEarseCheckPhrase(Fee_AddressType earseAddr);
extern uint16_t Fee_InternalCalcCrc16(void *sAddr, uint32_t size);
extern uint8_t Fee_InternalCalcCrc8(void *sAddr, uint32_t size);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _FEE_INTERNAL_H_ */

View File

@ -12,11 +12,11 @@
/*******************************************************************************
* the defines
******************************************************************************/
#define ADC_DEMO_LAST_CHANNLE ADCH_HEAT_C2
#define PDB_BB_SEL (0u) //000b : PDB0 and PDB1 operates independently.
#define DMA_CHANNEL0 0
#define DMA_CHANNEL1 1
#define PWM_PERIOD_HZ 1000
#define PWM_PERIOD_HZ 2000
/*******************************************************************************
* the typedefs
******************************************************************************/
@ -271,7 +271,7 @@ static void PWM_Init(void)
channelConfig.behavior0 = PWMLITEDRV_HIGH_AT_REACH;
channelConfig.behavior1 = PWMLITEDRV_LOW_AT_REACH;
channelConfig.threshold0 = 0;
channelConfig.threshold1 = moduleConfig.period * 25 / 100;
channelConfig.threshold1 = 0;
PwmLiteDrv_ConfigChannel(&mcu.pwmLiteDrv0, PWMLITEDRV_PWM_CH0, &channelConfig);
/* Enable PWM Module */
PwmLiteDrv_EnableModule(&mcu.pwmLiteDrv0);
@ -461,10 +461,10 @@ static void hw_IO_Init(void)
PortReg_SetPcrSr(mcu.pta.port, 3, 1);
PinsDrv_SetPinDirection(&mcu.pta, 3, PINSDRV_DIR_OUTPUT);
//48
PinsDrv_SetMuxModeSel(&mcu.pta, 2, PINSDRV_MUX_AS_GPIO);
PortReg_SetPcrDrvStr(mcu.pta.port, 2, 1);
PortReg_SetPcrSr(mcu.pta.port, 2, 1);
PinsDrv_SetPinDirection(&mcu.pta, 2, PINSDRV_DIR_OUTPUT);
PinsDrv_SetMuxModeSel(&mcu.pta, 2, PINSDRV_MUX_ALT5);
//PortReg_SetPcrDrvStr(mcu.pta.port, 2, 1);
//PortReg_SetPcrSr(mcu.pta.port, 2, 1);
//PinsDrv_SetPinDirection(&mcu.pta, 2, PINSDRV_DIR_OUTPUT);
//49
PinsDrv_SetMuxModeSel(&mcu.pta, 1, PINSDRV_PIN_DISABLED);
PortReg_SetPcrAen(mcu.pta.port, 1, 1);
@ -742,6 +742,6 @@ void FanCtrlDuty(uint8_t duty)
duty = 100;
}
dutydata = moduleConfig.period * duty / 100;
PwmLiteDrv_UpdatePwmThresholdAtRunning(&mcu.pwmLiteDrv0,PWMLITEDRV_PWM_CH0,0U,dutydata);
PwmLiteDrv_UpdatePwmThresholdAtSync(&mcu.pwmLiteDrv0,PWMLITEDRV_PWM_CH0,0U,dutydata);
}

View File

@ -10,6 +10,8 @@ static uint8_t keyPressFlag[KEY_NUM];
static uint8_t keyReleaseFlag[KEY_NUM];
static uint16_t keydelay[KEY_NUM];
static uint16_t MemorySetDelay = 0;
#define KEY_DELAY_TIMES 4 //20Ms
void ClearAllKeyState(void)
{
@ -115,17 +117,28 @@ static uint8_t GetSigState(KEY_ID_type key_id)
return scm_canmatrix_rx.Panel_Key.KEY_ZY_FAN;
case KEY_HEAT:
return scm_canmatrix_rx.Panel_Key.KEY_ZY_HEAT;
case KEY_MEMORY_SET:
return scm_canmatrix_rx.Panel_Key.KEY_MEMORY_SET;
case KEY_MEMORY_1:
return scm_canmatrix_rx.Panel_Key.KEY_MEMORY_1;
case KEY_MEMORY_2:
return scm_canmatrix_rx.Panel_Key.KEY_MEMORY_2;
case KEY_MEMORY_3:
return scm_canmatrix_rx.Panel_Key.KEY_MEMORY_3;
case KEY_RESET:
return scm_canmatrix_rx.Panel_Key.KEY_RESET;
default:
return 0;
}
}
void KeyProTask(void)
void KeyProTask(void)//5ms
{
//HG
if (getKeyPressFlag(KEY_HG_F) == KEY_PRESSED)
{
setMotorState(MotorHG,Motor_ACT_CW);
StopAutoCal();
}
if (getKeyReleaseFlag(KEY_HG_F) == KEY_PRESSED)
{
@ -134,6 +147,7 @@ void KeyProTask(void)
if (getKeyPressFlag(KEY_HG_R) == KEY_PRESSED)
{
setMotorState(MotorHG,Motor_ACT_CCW);
StopAutoCal();
}
if (getKeyReleaseFlag(KEY_HG_R) == KEY_PRESSED)
{
@ -144,6 +158,7 @@ void KeyProTask(void)
if (getKeyPressFlag(KEY_KB_F) == KEY_PRESSED)
{
setMotorState(MotorKB,Motor_ACT_CW);
StopAutoCal();
}
if (getKeyReleaseFlag(KEY_KB_F) == KEY_PRESSED)
{
@ -152,6 +167,7 @@ void KeyProTask(void)
if (getKeyPressFlag(KEY_KB_R) == KEY_PRESSED)
{
setMotorState(MotorKB,Motor_ACT_CCW);
StopAutoCal();
}
if (getKeyReleaseFlag(KEY_KB_R) == KEY_PRESSED)
{
@ -162,6 +178,7 @@ void KeyProTask(void)
if (getKeyPressFlag(KEY_TT_F) == KEY_PRESSED)
{
setMotorState(MotorTT,Motor_ACT_CW);
StopAutoCal();
}
if (getKeyReleaseFlag(KEY_TT_F) == KEY_PRESSED)
{
@ -170,6 +187,7 @@ void KeyProTask(void)
if (getKeyPressFlag(KEY_TT_R) == KEY_PRESSED)
{
setMotorState(MotorTT,Motor_ACT_CCW);
StopAutoCal();
}
if (getKeyReleaseFlag(KEY_TT_R) == KEY_PRESSED)
{
@ -180,6 +198,7 @@ void KeyProTask(void)
if (getKeyPressFlag(KEY_ZY_U) == KEY_PRESSED)
{
setMotorState(MotorZY,Motor_ACT_CW);
StopAutoCal();
}
if (getKeyReleaseFlag(KEY_ZY_U) == KEY_PRESSED)
{
@ -188,11 +207,60 @@ void KeyProTask(void)
if (getKeyPressFlag(KEY_ZY_D) == KEY_PRESSED)
{
setMotorState(MotorZY,Motor_ACT_CCW);
StopAutoCal();
}
if (getKeyReleaseFlag(KEY_ZY_D) == KEY_PRESSED)
{
setMotorState(MotorZY,Motor_ACT_NOACT);
}
if (getKeyPressFlag(KEY_MEMORY_SET) == KEY_PRESSED)
{
MemorySetDelay = 1000;//5ms * 1000
}
if (getKeyPressFlag(KEY_MEMORY_1) == KEY_PRESSED)
{
if (MemorySetDelay > 0)
{
MotorMemorySet(MOTOR_MEMORY_1);
}
else
{
MotorMemoryGet(MOTOR_MEMORY_1);
}
}
if (getKeyPressFlag(KEY_MEMORY_2) == KEY_PRESSED)
{
if (MemorySetDelay > 0)
{
MotorMemorySet(MOTOR_MEMORY_2);
}
else
{
MotorMemoryGet(MOTOR_MEMORY_2);
}
}
if (getKeyPressFlag(KEY_MEMORY_3) == KEY_PRESSED)
{
if (MemorySetDelay > 0)
{
MotorMemorySet(MOTOR_MEMORY_3);
}
else
{
MotorMemoryGet(MOTOR_MEMORY_3);
}
}
if (MemorySetDelay > 0)
{
MemorySetDelay --;
}
if (getKeyPressFlag(KEY_RESET) == KEY_PRESSED)
{
StartAutoCal();
}
}

View File

@ -21,6 +21,11 @@ typedef enum
KEY_ZY_D,//下
KEY_FAN,
KEY_HEAT,
KEY_MEMORY_SET,
KEY_MEMORY_1,
KEY_MEMORY_2,
KEY_MEMORY_3,
KEY_RESET,
KEY_NUM,
}KEY_ID_type;