更新bootloader复位问题
This commit is contained in:
parent
9264a68c73
commit
8e8b20623e
@ -3,7 +3,6 @@ import win.ui;
|
|||||||
mainForm = win.form(text="CAN_Bootloader";right=599;bottom=465;border="dialog frame";max=false)
|
mainForm = win.form(text="CAN_Bootloader";right=599;bottom=465;border="dialog frame";max=false)
|
||||||
mainForm.add(
|
mainForm.add(
|
||||||
btnConnect={cls="button";text="连接";left=204;top=64;right=289;bottom=90;z=4};
|
btnConnect={cls="button";text="连接";left=204;top=64;right=289;bottom=90;z=4};
|
||||||
btnDiag={cls="button";text="诊断";left=149;top=350;right=248;bottom=375;z=25};
|
|
||||||
btnFlash={cls="button";text="开始刷写";left=37;top=315;right=136;bottom=343;z=9};
|
btnFlash={cls="button";text="开始刷写";left=37;top=315;right=136;bottom=343;z=9};
|
||||||
btnFresh={cls="button";text="刷新";left=204;top=28;right=288;bottom=54;z=2};
|
btnFresh={cls="button";text="刷新";left=204;top=28;right=288;bottom=54;z=2};
|
||||||
btnOpen={cls="button";text="打开文件";left=37;top=282;right=136;bottom=310;z=8};
|
btnOpen={cls="button";text="打开文件";left=37;top=282;right=136;bottom=310;z=8};
|
||||||
@ -237,22 +236,14 @@ mainForm.btnOpenFlashdrv.oncommand = function(id,event){
|
|||||||
::PostThreadMessage(thrdId,104,1,0)//自定义消息-打开flashdriver
|
::PostThreadMessage(thrdId,104,1,0)//自定义消息-打开flashdriver
|
||||||
}
|
}
|
||||||
|
|
||||||
var frmChild = win.loadForm("\dlg\诊断子窗口.aardio");
|
|
||||||
frmChild.show(false);
|
|
||||||
mainForm.btnDiag.oncommand = function(id,event){
|
|
||||||
|
|
||||||
frmChild.show();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
thrdHandle,thrdId = thread.create( CanThread )
|
thrdHandle,thrdId = thread.create( CanThread )
|
||||||
|
|
||||||
|
|
||||||
mainForm.onClose = function(hwnd,message,wParam,lParam){
|
mainForm.onClose = function(hwnd,message,wParam,lParam){
|
||||||
::PostThreadMessage(thrdId,120,1,0)
|
|
||||||
raw.closehandle(thrdHandle);
|
raw.closehandle(thrdHandle);
|
||||||
thread.waitClose(thrdHandle);
|
//frmChild.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ var FuncSendPackage = function(){
|
|||||||
data[i+1] = table.remove(Packdata);
|
data[i+1] = table.remove(Packdata);
|
||||||
}
|
}
|
||||||
CANHw.SendMsg(PackID,data);
|
CANHw.SendMsg(PackID,data);
|
||||||
sleep(1);
|
//sleep(1);
|
||||||
PackNext += 1;
|
PackNext += 1;
|
||||||
if(PackNext > 0x2f){
|
if(PackNext > 0x2f){
|
||||||
PackNext = 0x20;
|
PackNext = 0x20;
|
||||||
|
8
cva_asw_m0146/.vscode/settings.json
vendored
8
cva_asw_m0146/.vscode/settings.json
vendored
@ -13,7 +13,13 @@
|
|||||||
"hwctrl.h": "c",
|
"hwctrl.h": "c",
|
||||||
"cvm014x_features.h": "c",
|
"cvm014x_features.h": "c",
|
||||||
"clock_drv.h": "c",
|
"clock_drv.h": "c",
|
||||||
"irq_drv.h": "c"
|
"irq_drv.h": "c",
|
||||||
|
"motorctrl.h": "c",
|
||||||
|
"extern.h": "c",
|
||||||
|
"sbc_tle94x1.h": "c",
|
||||||
|
"tle94x1.h": "c",
|
||||||
|
"reset_drv.h": "c",
|
||||||
|
"pwmlite_drv.h": "c"
|
||||||
},
|
},
|
||||||
"C_Cpp.default.compilerPath": ""
|
"C_Cpp.default.compilerPath": ""
|
||||||
}
|
}
|
@ -19,6 +19,7 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "uds_service11.h"
|
#include "uds_service11.h"
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* the defines
|
* the defines
|
||||||
@ -72,7 +73,7 @@ void UdsService11_ResetEcu(UdsType *obj, const uint8_t msgBuf[], uint16_t msgLen
|
|||||||
case UDS_RESET_HARD:
|
case UDS_RESET_HARD:
|
||||||
Uds_PositiveResponse(obj, rspBuffer, 3);
|
Uds_PositiveResponse(obj, rspBuffer, 3);
|
||||||
/*add hardware reset code*/
|
/*add hardware reset code*/
|
||||||
|
extHardwareReset();
|
||||||
break;
|
break;
|
||||||
case UDS_RESET_KEYOFFON:
|
case UDS_RESET_KEYOFFON:
|
||||||
Uds_PositiveResponse(obj, rspBuffer, 3);
|
Uds_PositiveResponse(obj, rspBuffer, 3);
|
||||||
@ -82,7 +83,7 @@ void UdsService11_ResetEcu(UdsType *obj, const uint8_t msgBuf[], uint16_t msgLen
|
|||||||
case UDS_RESET_SOFT:
|
case UDS_RESET_SOFT:
|
||||||
Uds_PositiveResponse(obj, rspBuffer, 3);
|
Uds_PositiveResponse(obj, rspBuffer, 3);
|
||||||
/*add software reset code*/
|
/*add software reset code*/
|
||||||
|
extSortwareReset();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Uds_NegativeResponse(obj, 0x11, NRC_SUBFUNCTION_NOT_SUPPORTED);
|
Uds_NegativeResponse(obj, 0x11, NRC_SUBFUNCTION_NOT_SUPPORTED);
|
||||||
|
@ -2964,6 +2964,9 @@
|
|||||||
<file>
|
<file>
|
||||||
<name>$PROJ_DIR$\src\appTask.c</name>
|
<name>$PROJ_DIR$\src\appTask.c</name>
|
||||||
</file>
|
</file>
|
||||||
|
<file>
|
||||||
|
<name>$PROJ_DIR$\src\canuser.c</name>
|
||||||
|
</file>
|
||||||
<file>
|
<file>
|
||||||
<name>$PROJ_DIR$\src\extern.c</name>
|
<name>$PROJ_DIR$\src\extern.c</name>
|
||||||
</file>
|
</file>
|
||||||
|
@ -3603,6 +3603,9 @@
|
|||||||
<file>
|
<file>
|
||||||
<name>$PROJ_DIR$\src\appTask.c</name>
|
<name>$PROJ_DIR$\src\appTask.c</name>
|
||||||
</file>
|
</file>
|
||||||
|
<file>
|
||||||
|
<name>$PROJ_DIR$\src\canuser.c</name>
|
||||||
|
</file>
|
||||||
<file>
|
<file>
|
||||||
<name>$PROJ_DIR$\src\extern.c</name>
|
<name>$PROJ_DIR$\src\extern.c</name>
|
||||||
</file>
|
</file>
|
||||||
|
@ -25,7 +25,7 @@ if not "%~1" == "" goto debugFile
|
|||||||
|
|
||||||
@echo on
|
@echo on
|
||||||
|
|
||||||
"E:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.general.xcl" --backend -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.driver.xcl"
|
"e:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.general.xcl" --backend -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.driver.xcl"
|
||||||
|
|
||||||
@echo off
|
@echo off
|
||||||
goto end
|
goto end
|
||||||
@ -34,7 +34,7 @@ goto end
|
|||||||
|
|
||||||
@echo on
|
@echo on
|
||||||
|
|
||||||
"E:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.general.xcl" "--debug_file=%~1" --backend -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.driver.xcl"
|
"e:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.general.xcl" "--debug_file=%~1" --backend -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.driver.xcl"
|
||||||
|
|
||||||
@echo off
|
@echo off
|
||||||
:end
|
:end
|
@ -23,9 +23,9 @@
|
|||||||
|
|
||||||
if ($debugfile -eq "")
|
if ($debugfile -eq "")
|
||||||
{
|
{
|
||||||
& "E:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.general.xcl" --backend -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.driver.xcl"
|
& "e:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.general.xcl" --backend -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.driver.xcl"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
& "E:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.general.xcl" --debug_file=$debugfile --backend -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.driver.xcl"
|
& "e:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.general.xcl" --debug_file=$debugfile --backend -f "F:\FCB_project\RP-01\CODE\cva_asw_m0146\settings\cva_asw_m0146.Debug.driver.xcl"
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
"-p"
|
"-p"
|
||||||
|
|
||||||
"E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\config\debugger\CVAChip\CVM0144.ddf"
|
"e:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\config\debugger\CVAChip\CVM0144.ddf"
|
||||||
|
|
||||||
"--semihosting"
|
"--semihosting"
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
"E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armPROC.dll"
|
"e:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armPROC.dll"
|
||||||
|
|
||||||
"E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armJLINK.dll"
|
"e:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armJLINK.dll"
|
||||||
|
|
||||||
"F:\FCB_project\RP-01\CODE\cva_asw_m0146\Debug_FLASH\Exe\app_m146.out"
|
"F:\FCB_project\RP-01\CODE\cva_asw_m0146\Debug_FLASH\Exe\app_m146.out"
|
||||||
|
|
||||||
--plugin="E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armbat.dll"
|
--plugin="e:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armbat.dll"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
</JLinkDriver>
|
</JLinkDriver>
|
||||||
<PlDriver>
|
<PlDriver>
|
||||||
<FirstRun>0</FirstRun>
|
<FirstRun>0</FirstRun>
|
||||||
<MemConfigValue>E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\config\debugger\CVAChip\CVM0144.ddf</MemConfigValue>
|
<MemConfigValue>e:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\config\debugger\CVAChip\CVM0144.ddf</MemConfigValue>
|
||||||
</PlDriver>
|
</PlDriver>
|
||||||
<ArmDriver>
|
<ArmDriver>
|
||||||
<EnforceMemoryConfiguration>1</EnforceMemoryConfiguration>
|
<EnforceMemoryConfiguration>1</EnforceMemoryConfiguration>
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,22 +1,610 @@
|
|||||||
#include "MotorCtrl.h"
|
#include "MotorCtrl.h"
|
||||||
#include "hwctrl.h"
|
#include "hwctrl.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* the defines
|
||||||
|
******************************************************************************/
|
||||||
|
#define START_FLAG 0x55aa
|
||||||
|
#define STOP_FLAG 0xaa55
|
||||||
|
|
||||||
|
#define AUTOCAL_STOP 0
|
||||||
|
#define AUTOCAL_START 1
|
||||||
|
#define AUTOCAL_ACT1 2
|
||||||
|
#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
|
||||||
|
/*******************************************************************************
|
||||||
|
* the typedefs
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t MotorStopLoc1;
|
||||||
|
uint16_t MotorStopLoc2;
|
||||||
|
uint16_t MotorNowLoc;
|
||||||
|
}MOTOR_DATA;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t start_flag;
|
||||||
|
MOTOR_DATA MotorData[6];
|
||||||
|
uint16_t MemoryLoc[3][6];
|
||||||
|
uint16_t checksum;
|
||||||
|
uint16_t stop_flag;
|
||||||
|
}MEMORY_DATA;
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* the globals
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
MOTOR_DATA MotorData[6];
|
||||||
|
uint16_t MemoryLoc[3][6];
|
||||||
|
MEMORY_DATA MemoryData;
|
||||||
|
uint8_t OC1flag,OC2flag,OC3flag;
|
||||||
|
uint8_t MotorState[6],MotorStateReal[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 uint8_t AutoCalState;
|
||||||
|
uint16_t HallErrorCount[6];
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* the const
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* the local function prototypes
|
||||||
|
******************************************************************************/
|
||||||
|
static void MotorCtrl(void);
|
||||||
|
static void AutoCalCtrl(void);
|
||||||
|
static void MotorValueInit(void);
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* the local functions
|
||||||
|
******************************************************************************/
|
||||||
|
static void MotorValueInit(void)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
for (i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
MotorHallLoc[i] = 0x8000;
|
||||||
|
MotorErr[i] = 0;
|
||||||
|
}
|
||||||
|
//ReadMotorMemory();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void AutoCalCtrl(void)
|
||||||
|
{
|
||||||
|
static uint16_t autocalcounter[3];
|
||||||
|
static uint8_t MotorArr1state,MotorArr2state,MotorArr3state;
|
||||||
|
static uint8_t wait1,wait2,wait3;
|
||||||
|
uint8_t i;
|
||||||
|
uint32_t temp;
|
||||||
|
switch (AutoCalState)
|
||||||
|
{
|
||||||
|
case AUTOCAL_STOP:
|
||||||
|
MotorArr1state = AUTOCAL_STOP;
|
||||||
|
MotorArr2state = AUTOCAL_STOP;
|
||||||
|
MotorArr3state = AUTOCAL_STOP;
|
||||||
|
return;
|
||||||
|
case AUTOCAL_START:
|
||||||
|
MotorArr1state = 1;
|
||||||
|
MotorArr2state = 1;
|
||||||
|
MotorArr3state = 1;
|
||||||
|
setMotorState(Motor1,Motor_ACT_CW);
|
||||||
|
setMotorState(Motor3,Motor_ACT_CW);
|
||||||
|
setMotorState(Motor5,Motor_ACT_CW);
|
||||||
|
autocalcounter[0] = 0;
|
||||||
|
autocalcounter[1] = 0;
|
||||||
|
autocalcounter[2] = 0;
|
||||||
|
AutoCalState++;
|
||||||
|
for (i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
MotorHardStop1[i] = 0;
|
||||||
|
MotorHardStop2[i] = 0;
|
||||||
|
MotorHallLoc[i] = 0x8000;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case AUTOCAL_ACT1:
|
||||||
|
if (MotorArr1state == 0 && MotorArr2state == 0 && MotorArr3state == 0)
|
||||||
|
{
|
||||||
|
for (i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
temp = MotorHardStop1[i];
|
||||||
|
temp += MotorHardStop2[i];
|
||||||
|
setMotorTarget(i,temp/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
case AUTOCAL_ACT2:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//1
|
||||||
|
switch (MotorArr1state)
|
||||||
|
{
|
||||||
|
case 1://Motor1 xq
|
||||||
|
autocalcounter[0]++;
|
||||||
|
if (MotorHardStop1[Motor1] != 0)
|
||||||
|
{
|
||||||
|
MotorArr1state++;
|
||||||
|
wait1 = 0;
|
||||||
|
setMotorState(Motor1,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
if (autocalcounter[0] > 3000 || MotorErr[Motor1] != 0)
|
||||||
|
{
|
||||||
|
MotorArr1state = 4;
|
||||||
|
wait1 = 0;
|
||||||
|
setMotorState(Motor1,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2://wait
|
||||||
|
wait1++;
|
||||||
|
if (wait1 > 50)
|
||||||
|
{
|
||||||
|
MotorArr1state++;
|
||||||
|
setMotorState(Motor1,Motor_ACT_CCW);
|
||||||
|
autocalcounter[0] = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3://Motor1 xh
|
||||||
|
autocalcounter[0]++;
|
||||||
|
if (MotorHardStop2[Motor1] != 0)
|
||||||
|
{
|
||||||
|
MotorArr1state++;
|
||||||
|
wait1 = 0;
|
||||||
|
setMotorState(Motor1,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
if (autocalcounter[0] > 3000 || MotorErr[Motor1] != 0)
|
||||||
|
{
|
||||||
|
MotorArr1state = 4;
|
||||||
|
wait1 = 0;
|
||||||
|
setMotorState(Motor1,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4://wait
|
||||||
|
wait1++;
|
||||||
|
if (wait1 > 50)
|
||||||
|
{
|
||||||
|
MotorArr1state++;
|
||||||
|
setMotorState(Motor2,Motor_ACT_CW);
|
||||||
|
autocalcounter[0] = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 5://Motor2 xq
|
||||||
|
autocalcounter[0]++;
|
||||||
|
if (MotorHardStop1[Motor2] != 0)
|
||||||
|
{
|
||||||
|
MotorArr1state++;
|
||||||
|
wait1 = 0;
|
||||||
|
setMotorState(Motor2,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
if (autocalcounter[0] > 3000 || MotorErr[Motor2] != 0)
|
||||||
|
{
|
||||||
|
MotorArr1state = 0;
|
||||||
|
setMotorState(Motor2,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 6://wait
|
||||||
|
wait1++;
|
||||||
|
if (wait1 > 50)
|
||||||
|
{
|
||||||
|
MotorArr1state++;
|
||||||
|
setMotorState(Motor2,Motor_ACT_CCW);
|
||||||
|
autocalcounter[0] = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
autocalcounter[0]++;
|
||||||
|
if (MotorHardStop2[Motor2] != 0)
|
||||||
|
{
|
||||||
|
MotorArr1state=0;
|
||||||
|
wait1 = 0;
|
||||||
|
setMotorState(Motor2,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
if (autocalcounter[0] > 3000 || MotorErr[Motor2] != 0)
|
||||||
|
{
|
||||||
|
MotorArr1state = 0;
|
||||||
|
setMotorState(Motor2,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//2
|
||||||
|
switch (MotorArr2state)
|
||||||
|
{
|
||||||
|
case 1://Motor3 xq
|
||||||
|
autocalcounter[1]++;
|
||||||
|
if (MotorHardStop1[Motor3] != 0)
|
||||||
|
{
|
||||||
|
MotorArr2state++;
|
||||||
|
wait2 = 0;
|
||||||
|
setMotorState(Motor3,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
if (autocalcounter[1] > 3000 || MotorErr[Motor3] != 0)
|
||||||
|
{
|
||||||
|
MotorArr2state = 4;
|
||||||
|
wait2 = 0;
|
||||||
|
setMotorState(Motor3,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2://wait
|
||||||
|
wait2++;
|
||||||
|
if (wait2 > 50)
|
||||||
|
{
|
||||||
|
MotorArr2state++;
|
||||||
|
setMotorState(Motor3,Motor_ACT_CCW);
|
||||||
|
autocalcounter[1] = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3://Motor3 xh
|
||||||
|
autocalcounter[1]++;
|
||||||
|
if (MotorHardStop2[Motor3] != 0)
|
||||||
|
{
|
||||||
|
MotorArr2state++;
|
||||||
|
wait2 = 0;
|
||||||
|
setMotorState(Motor3,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
if (autocalcounter[1] > 3000 || MotorErr[Motor3] != 0)
|
||||||
|
{
|
||||||
|
MotorArr2state = 4;
|
||||||
|
wait2 = 0;
|
||||||
|
setMotorState(Motor3,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4://wait
|
||||||
|
wait2++;
|
||||||
|
if (wait2 > 50)
|
||||||
|
{
|
||||||
|
MotorArr2state++;
|
||||||
|
setMotorState(Motor4,Motor_ACT_CW);
|
||||||
|
autocalcounter[1] = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 5://Motor4 xq
|
||||||
|
autocalcounter[1]++;
|
||||||
|
if (MotorHardStop1[Motor4] != 0)
|
||||||
|
{
|
||||||
|
MotorArr2state++;
|
||||||
|
wait2 = 0;
|
||||||
|
setMotorState(Motor4,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
if (autocalcounter[1] > 3000 || MotorErr[Motor4] != 0)
|
||||||
|
{
|
||||||
|
MotorArr2state = 0;
|
||||||
|
setMotorState(Motor4,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 6://wait
|
||||||
|
wait2++;
|
||||||
|
if (wait2 > 50)
|
||||||
|
{
|
||||||
|
MotorArr2state++;
|
||||||
|
setMotorState(Motor4,Motor_ACT_CCW);
|
||||||
|
autocalcounter[1] = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
autocalcounter[1]++;
|
||||||
|
if (MotorHardStop2[Motor4] != 0)
|
||||||
|
{
|
||||||
|
MotorArr2state=0;
|
||||||
|
wait2 = 0;
|
||||||
|
setMotorState(Motor4,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
if (autocalcounter[1] > 3000 || MotorErr[Motor4] != 0)
|
||||||
|
{
|
||||||
|
MotorArr2state = 0;
|
||||||
|
setMotorState(Motor4,Motor_ACT_NOACT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
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
|
||||||
|
AutoCalCtrl();
|
||||||
|
|
||||||
|
|
||||||
|
if (OC1flag == 1)
|
||||||
|
{
|
||||||
|
OC1flag = 0;
|
||||||
|
if (MotorState[0] == Motor_ACT_CW)
|
||||||
|
{
|
||||||
|
MotorHardStop1[0] = MotorHallLoc[0];
|
||||||
|
}
|
||||||
|
else if (MotorState[0] == Motor_ACT_CCW)
|
||||||
|
{
|
||||||
|
MotorHardStop2[0] = MotorHallLoc[0];
|
||||||
|
}
|
||||||
|
else if (MotorState[1] == Motor_ACT_CW)
|
||||||
|
{
|
||||||
|
MotorHardStop1[1] = MotorHallLoc[1];
|
||||||
|
}
|
||||||
|
else if (MotorState[1] == Motor_ACT_CCW)
|
||||||
|
{
|
||||||
|
MotorHardStop2[1] = MotorHallLoc[1];
|
||||||
|
}
|
||||||
|
setMotorTarget(Motor1,0);
|
||||||
|
setMotorTarget(Motor2,0);
|
||||||
|
MotorState[Motor1] = Motor_ACT_NOACT;
|
||||||
|
MotorState[Motor2] = Motor_ACT_NOACT;
|
||||||
|
}
|
||||||
|
if (OC2flag == 1)
|
||||||
|
{
|
||||||
|
OC2flag = 0;
|
||||||
|
if (MotorState[2] == Motor_ACT_CW)
|
||||||
|
{
|
||||||
|
MotorHardStop1[2] = MotorHallLoc[2];
|
||||||
|
}
|
||||||
|
else if (MotorState[2] == Motor_ACT_CCW)
|
||||||
|
{
|
||||||
|
MotorHardStop2[2] = MotorHallLoc[2];
|
||||||
|
}
|
||||||
|
else if (MotorState[3] == Motor_ACT_CW)
|
||||||
|
{
|
||||||
|
MotorHardStop1[3] = MotorHallLoc[3];
|
||||||
|
}
|
||||||
|
else if (MotorState[3] == Motor_ACT_CCW)
|
||||||
|
{
|
||||||
|
MotorHardStop2[3] = MotorHallLoc[3];
|
||||||
|
}
|
||||||
|
setMotorTarget(Motor3,0);
|
||||||
|
setMotorTarget(Motor4,0);
|
||||||
|
MotorState[Motor3] = Motor_ACT_NOACT;
|
||||||
|
MotorState[Motor4] = Motor_ACT_NOACT;
|
||||||
|
}
|
||||||
|
if (OC3flag == 1)
|
||||||
|
{
|
||||||
|
OC3flag = 0;
|
||||||
|
if (MotorState[4] == Motor_ACT_CW)
|
||||||
|
{
|
||||||
|
MotorHardStop1[4] = MotorHallLoc[4];
|
||||||
|
}
|
||||||
|
else if (MotorState[4] == Motor_ACT_CCW)
|
||||||
|
{
|
||||||
|
MotorHardStop2[4] = MotorHallLoc[4];
|
||||||
|
}
|
||||||
|
else if (MotorState[5] == Motor_ACT_CW)
|
||||||
|
{
|
||||||
|
MotorHardStop1[5] = MotorHallLoc[5];
|
||||||
|
}
|
||||||
|
else if (MotorState[5] == Motor_ACT_CCW)
|
||||||
|
{
|
||||||
|
MotorHardStop2[5] = MotorHallLoc[5];
|
||||||
|
}
|
||||||
|
setMotorTarget(Motor5,0);
|
||||||
|
setMotorTarget(Motor6,0);
|
||||||
|
MotorState[Motor5] = Motor_ACT_NOACT;
|
||||||
|
MotorState[Motor6] = Motor_ACT_NOACT;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
MotorStateReal[i] = MotorState[i];
|
||||||
|
if (MotorState[i] == Motor_ACT_NOACT && MotorHardStop1[i] != 0 && MotorHardStop2[i] != 0 )
|
||||||
|
{
|
||||||
|
if (MotorTarget[i]!=0 && MotorHardStop1[i] > MotorTarget[i] && MotorTarget[i] > MotorHardStop2[i])
|
||||||
|
{
|
||||||
|
if (MotorTarget[i] > MotorHallLoc[i]+10)
|
||||||
|
{
|
||||||
|
MotorStateReal[i] = Motor_ACT_CW;
|
||||||
|
}
|
||||||
|
else if (MotorTarget[i] < MotorHallLoc[i]-10)
|
||||||
|
{
|
||||||
|
MotorStateReal[i] = Motor_ACT_CCW;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MotorTarget[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (MotorHardStop1[i] != 0 && MotorHardStop2[i] != 0)
|
||||||
|
{
|
||||||
|
if (MotorHallLoc[i] > (MotorHardStop1[i]-20) && MotorStateReal[i] == Motor_ACT_CW)
|
||||||
|
{
|
||||||
|
MotorStateReal[i] = Motor_ACT_NOACT;
|
||||||
|
}
|
||||||
|
if (MotorHallLoc[i] < (MotorHardStop2[i] + 20) && MotorStateReal[i] == Motor_ACT_CCW)
|
||||||
|
{
|
||||||
|
MotorStateReal[i] = Motor_ACT_NOACT;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MotorTarget[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* the global functions
|
||||||
|
******************************************************************************/
|
||||||
void MotorCtrl_Init(McuType *obj)
|
void MotorCtrl_Init(McuType *obj)
|
||||||
{
|
{
|
||||||
for (uint8_t i = 0; i < 6; i++)
|
for (uint8_t i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
hw_MotorCtrl(obj, i, Motor_ACT_NOACT);
|
hw_MotorCtrl(obj, i, Motor_ACT_NOACT);
|
||||||
}
|
}
|
||||||
|
MotorValueInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotorCtrl_Maintask(McuType *obj)//10ms task
|
void MotorCtrl_Maintask(McuType *obj)//10ms task
|
||||||
{
|
{
|
||||||
static uint8_t motor_cnt = 0,motor_act=0,run_count=0;
|
MotorCtrl();
|
||||||
run_count++;
|
for (Motor_ID_Type i = 0; i < MOTOR_NUM; i++)
|
||||||
if (run_count > 100)
|
|
||||||
{
|
{
|
||||||
run_count = 0;
|
hw_MotorCtrl(obj, i, MotorStateReal[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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(Motor1,Motor_ACT_NOACT);
|
||||||
|
setMotorState(Motor2,Motor_ACT_NOACT);
|
||||||
|
setMotorState(Motor3,Motor_ACT_NOACT);
|
||||||
|
setMotorState(Motor4,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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,3 +615,95 @@ void MotorCtrl_Maintask(McuType *obj)//10ms task
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t getOverCurrentTh(uint8_t ch)
|
||||||
|
{
|
||||||
|
uint16_t th = 10;
|
||||||
|
switch (ch)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
if (MotorStateReal[Motor1]!=Motor_ACT_NOACT)
|
||||||
|
{
|
||||||
|
th+=50;
|
||||||
|
}
|
||||||
|
if (MotorStateReal[Motor2]!=Motor_ACT_NOACT)
|
||||||
|
{
|
||||||
|
th+=50;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (MotorStateReal[Motor3]!=Motor_ACT_NOACT)
|
||||||
|
{
|
||||||
|
th+=50;
|
||||||
|
}
|
||||||
|
if (MotorStateReal[Motor4]!=Motor_ACT_NOACT)
|
||||||
|
{
|
||||||
|
th+=50;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (MotorStateReal[Motor5]!=Motor_ACT_NOACT)
|
||||||
|
{
|
||||||
|
th+=50;
|
||||||
|
}
|
||||||
|
if (MotorStateReal[Motor6]!=Motor_ACT_NOACT)
|
||||||
|
{
|
||||||
|
th+=20;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return th;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HallDetecte(void)
|
||||||
|
{
|
||||||
|
static uint8_t HallLastState[6],HallDelay[6];
|
||||||
|
uint8_t i,hallstate;
|
||||||
|
for (i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
hallstate = GetIOState(i+1);
|
||||||
|
if (hallstate != HallLastState[i])
|
||||||
|
{
|
||||||
|
HallDelay[i]++;
|
||||||
|
if (HallDelay[i] > HALLDELAYMAX)
|
||||||
|
{
|
||||||
|
if (MotorStateReal[i] == Motor_ACT_CW)
|
||||||
|
{
|
||||||
|
MotorHallLoc[i]++;
|
||||||
|
}
|
||||||
|
else if (MotorStateReal[i] == Motor_ACT_CCW)
|
||||||
|
{
|
||||||
|
MotorHallLoc[i]--;
|
||||||
|
}
|
||||||
|
HallLastState[i] = hallstate;
|
||||||
|
}
|
||||||
|
HallErrorCount[i] = 0;
|
||||||
|
MotorErr[i] = 0;
|
||||||
|
//EEL_SAVE_Counter = 1000;
|
||||||
|
//EEL_SAVE_REQUIRE_FLAG = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HallDelay[i] = 0;
|
||||||
|
if (MotorStateReal[i] != Motor_ACT_NOACT)
|
||||||
|
{
|
||||||
|
HallErrorCount[i]++;
|
||||||
|
if (HallErrorCount[i] > 500)
|
||||||
|
{
|
||||||
|
HallErrorCount[i] = 500;
|
||||||
|
MotorErr[i] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if (EEL_SAVE_Counter > 0)
|
||||||
|
{
|
||||||
|
EEL_SAVE_Counter--;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,36 @@
|
|||||||
|
|
||||||
#include "Mcu.h"
|
#include "Mcu.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* the typedefs
|
||||||
|
******************************************************************************/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
Motor_ACT_NOACT,//停止
|
||||||
|
Motor_ACT_CW,//正转
|
||||||
|
Motor_ACT_CCW,//反转
|
||||||
|
Motor_ACT_NUM,
|
||||||
|
} Motor_ACT_Type;
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
Motor1,//
|
||||||
|
Motor2,//
|
||||||
|
Motor3,//
|
||||||
|
Motor4,//
|
||||||
|
Motor5,//
|
||||||
|
Motor6,//
|
||||||
|
MOTOR_NUM,
|
||||||
|
} Motor_ID_Type;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MotorCtrl_Init(McuType *obj);
|
void MotorCtrl_Init(McuType *obj);
|
||||||
void MotorCtrl_Maintask(McuType *obj);
|
void MotorCtrl_Maintask(McuType *obj);
|
||||||
|
void setMotorState(Motor_ID_Type motorid,Motor_ACT_Type act);
|
||||||
|
void setMotorTarget(uint8_t motorid,uint16_t target);
|
||||||
|
void StartAutoCal(void);
|
||||||
|
void StopAutoCal(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "SEGGER_RTT.h"
|
#include "SEGGER_RTT.h"
|
||||||
#include "MotorCtrl.h"
|
#include "MotorCtrl.h"
|
||||||
|
#include "canuser.h"
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* the defines
|
* the defines
|
||||||
@ -21,13 +22,12 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t txMsgBuf[8] = {0};
|
|
||||||
uint8_t udsSendBuf[UDS_SEND_BUF] = {0};
|
uint8_t udsSendBuf[UDS_SEND_BUF] = {0};
|
||||||
uint8_t udsRecvBuf[UDS_RECV_BUF] = {0};
|
uint8_t udsRecvBuf[UDS_RECV_BUF] = {0};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UdsType udsObj;
|
UdsType udsObj;
|
||||||
int64_t Get_Cur_Time_Stamp(void);
|
int64_t Get_Cur_Time_Stamp(void);
|
||||||
Uds_ParamsType udsParam = {
|
Uds_ParamsType udsParam = {
|
||||||
@ -54,6 +54,7 @@ volatile uint32_t gSystick1msEvent = 0, gSystick1msCnt = 0, gTestRunCnt = 0, gTe
|
|||||||
|
|
||||||
#pragma location = ".bss.no_init"
|
#pragma location = ".bss.no_init"
|
||||||
static uint32_t sAswBoot_Req;
|
static uint32_t sAswBoot_Req;
|
||||||
|
|
||||||
//
|
//
|
||||||
int64_t Get_Cur_Time_Stamp(void)
|
int64_t Get_Cur_Time_Stamp(void)
|
||||||
{
|
{
|
||||||
@ -73,7 +74,6 @@ void SysTick_Handler(void)
|
|||||||
}
|
}
|
||||||
void appTask(McuType *obj)
|
void appTask(McuType *obj)
|
||||||
{
|
{
|
||||||
FlexCan_FrameStructureType rxMsg;
|
|
||||||
if(gSystick1msEvent > 0u)
|
if(gSystick1msEvent > 0u)
|
||||||
{
|
{
|
||||||
if(udsObj.session == UDS_SESSION_PROGRAMMING)
|
if(udsObj.session == UDS_SESSION_PROGRAMMING)
|
||||||
@ -81,10 +81,10 @@ void appTask(McuType *obj)
|
|||||||
Asw_SetBootloaderRequest();
|
Asw_SetBootloaderRequest();
|
||||||
ResetDrv_SoftwareResetModule(&obj->resetDrv, RESETDRV_SWRESET_SYS);
|
ResetDrv_SoftwareResetModule(&obj->resetDrv, RESETDRV_SWRESET_SYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
gSystick1msEvent--;
|
gSystick1msEvent--;
|
||||||
gSystick1msCnt++;
|
gSystick1msCnt++;
|
||||||
gSysTick1sCnt++;
|
gSysTick1sCnt++;
|
||||||
|
MsgTask(&udsObj);
|
||||||
if (gSystick1msCnt % 10 == 0)
|
if (gSystick1msCnt % 10 == 0)
|
||||||
{
|
{
|
||||||
MotorCtrl_Maintask(obj);
|
MotorCtrl_Maintask(obj);
|
||||||
@ -97,10 +97,8 @@ void appTask(McuType *obj)
|
|||||||
|
|
||||||
if(gSystick1msCnt % 200 == 0)
|
if(gSystick1msCnt % 200 == 0)
|
||||||
{
|
{
|
||||||
uint8_t txMsgBuf[8]={0};
|
|
||||||
txMsgBuf[3] = gSysTick1sCnt & 0xFF;
|
|
||||||
|
|
||||||
FlexCanBoot_TxMessage(APP_TX_TEST1_MSG_ID, txMsgBuf, 8);
|
|
||||||
}
|
}
|
||||||
if (gSystick1msCnt >= 10000)
|
if (gSystick1msCnt >= 10000)
|
||||||
{
|
{
|
||||||
@ -108,21 +106,6 @@ void appTask(McuType *obj)
|
|||||||
SEGGER_RTT_printf(0,"app running\n");
|
SEGGER_RTT_printf(0,"app running\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Handler user routine */
|
|
||||||
if(FlexCanBoot_ReadoutMsg(&rxMsg) == true)
|
|
||||||
{
|
|
||||||
if((rxMsg.id == UDS_PHYS_RECV_MSG_ID) || (rxMsg.id == UDS_FUNC_RECV_MSG_ID))
|
|
||||||
{
|
|
||||||
IsoTp_HandleIncomingCanMsg(&udsObj.isotp, rxMsg.id, rxMsg.data, rxMsg.len);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Uds_Run(&udsObj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
340
cva_asw_m0146/src/canuser.c
Normal file
340
cva_asw_m0146/src/canuser.c
Normal file
@ -0,0 +1,340 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include "canuser.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* the typedefs
|
||||||
|
******************************************************************************/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
UDS_MSG_IDX_STD_RX_PHYS,
|
||||||
|
UDS_MSG_IDX_STD_RX_FUNC,
|
||||||
|
UDS_MSG_IDX_STD_HOST_REQ1,
|
||||||
|
UDS_MSG_IDX_STD_HOST_REQ2,
|
||||||
|
UDS_MSG_IDX_STD_PHYS_RESP,
|
||||||
|
UDS_MSG_IDX_STD_ECU_STATUS,
|
||||||
|
UDS_MSG_IDX_STD_ECU_DEBUG1,
|
||||||
|
UDS_MSG_IDX_STD_ECU_DEBUG2,
|
||||||
|
UDS_MSG_IDX_STD_ECU_DEBUG3,
|
||||||
|
UDS_MSG_IDX_NUM
|
||||||
|
} Uds_MsgIdIdxType;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
FlexCan_FrameStructureType rxMsg[CAN_BUFFER_FIFO_SIZE];
|
||||||
|
FlexCan_FrameStructureType txMsg[CAN_BUFFER_FIFO_SIZE];
|
||||||
|
uint8_t wrIdx;
|
||||||
|
uint8_t rdIdx;
|
||||||
|
} FlexCan_DataInfoType;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t ECU_HeatStatus:4;//0
|
||||||
|
uint8_t ECU_FanStatus:4;
|
||||||
|
uint8_t ECU_AnmoStatus:4;//1
|
||||||
|
uint8_t reverse14:4;
|
||||||
|
uint8_t ECU_MOTOR1_STATUS:2;//2
|
||||||
|
uint8_t ECU_MOTOR2_STATUS:2;
|
||||||
|
uint8_t ECU_MOTOR3_STATUS:2;
|
||||||
|
uint8_t ECU_MOTOR4_STATUS:2;
|
||||||
|
uint8_t ECU_MOTOR5_STATUS:2;//3
|
||||||
|
uint8_t ECU_MOTOR6_STATUS:2;//4
|
||||||
|
uint8_t reverse34:4;
|
||||||
|
uint8_t reverse[4];
|
||||||
|
}ECU_status_Type;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t ECU_Power;
|
||||||
|
uint8_t ECU_MOTOR_C1;
|
||||||
|
uint8_t ECU_MOTOR_C2;
|
||||||
|
uint8_t ECU_MOTOR_C3;
|
||||||
|
uint8_t ECU_HEAT_C1;
|
||||||
|
uint8_t ECU_HEAT_C2;
|
||||||
|
uint8_t reverse[2];
|
||||||
|
}ECU_Debug1_Type;
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t ECU_MOTOR_POS1;
|
||||||
|
uint16_t ECU_MOTOR_POS2;
|
||||||
|
uint16_t ECU_MOTOR_POS3;
|
||||||
|
uint16_t ECU_MOTOR_POS4;
|
||||||
|
}ECU_Debug2_Type;
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t ECU_MOTOR_POS5;
|
||||||
|
uint16_t ECU_MOTOR_POS6;
|
||||||
|
uint8_t ECU_HALL1:1;
|
||||||
|
uint8_t ECU_HALL2:1;
|
||||||
|
uint8_t ECU_HALL3:1;
|
||||||
|
uint8_t ECU_HALL4:1;
|
||||||
|
uint8_t ECU_HALL5:1;
|
||||||
|
uint8_t ECU_HALL6:1;
|
||||||
|
uint8_t reverse46:2;
|
||||||
|
uint8_t reverse[3];
|
||||||
|
}ECU_Debug3_Type;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t HOST_KEY1:1;//0
|
||||||
|
uint8_t HOST_KEY2:1;
|
||||||
|
uint8_t HOST_KEY3:1;
|
||||||
|
uint8_t HOST_KEY4:1;
|
||||||
|
uint8_t HOST_KEY5:1;
|
||||||
|
uint8_t HOST_KEY6:1;
|
||||||
|
uint8_t HOST_KEY7:1;
|
||||||
|
uint8_t HOST_KEY8:1;
|
||||||
|
uint8_t HOST_KEY9:1;//1
|
||||||
|
uint8_t HOST_KEY10:1;
|
||||||
|
uint8_t HOST_KEY11:1;
|
||||||
|
uint8_t HOST_KEY12:1;
|
||||||
|
uint8_t HOST_KEY13:1;
|
||||||
|
uint8_t HOST_KEY14:1;
|
||||||
|
uint8_t HOST_KEY15:1;
|
||||||
|
uint8_t HOST_KEY16:1;
|
||||||
|
uint8_t HOST_HeatReq:4;//2
|
||||||
|
uint8_t HOST_FanReq:4;
|
||||||
|
uint8_t HOST_AnmoReq:4;//3
|
||||||
|
uint8_t reverse34:4;
|
||||||
|
uint8_t reverse[3];
|
||||||
|
uint8_t HOST_DebugMode:1;//7
|
||||||
|
uint8_t reverse71:7;
|
||||||
|
}HOST_Req1_Type;
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* the globals
|
||||||
|
******************************************************************************/
|
||||||
|
FlexCanDrv_ControllerCfgType flexCanCfg;
|
||||||
|
FlexCan_DataInfoType flexCan_DataInfo;
|
||||||
|
FlexCanDrvType* flexCanDrv_DemoObj;
|
||||||
|
static uint8_t txMsgBuf1[8] = {0};
|
||||||
|
static uint8_t txMsgBuf2[8] = {0};
|
||||||
|
static uint8_t txMsgBuf3[8] = {0};
|
||||||
|
static uint8_t txMsgBuf4[8] = {0};
|
||||||
|
static uint8_t rxMsgBuf1[8] = {0};
|
||||||
|
static uint8_t rxMsgBuf2[8] = {0};
|
||||||
|
static uint8_t debugMode;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* the const
|
||||||
|
******************************************************************************/
|
||||||
|
const FlexCanDrv_MsgCfgType msgCfgObj[UDS_MSG_IDX_NUM] = {
|
||||||
|
{UDS_MSG_IDX_STD_RX_PHYS, 1, UDS_PHYS_RECV_MSG_ID, false, FLEXCANDRV_MSGTYPE_RX, DLC_BYTE_8, false, true, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_RX_PHYS */
|
||||||
|
{UDS_MSG_IDX_STD_RX_FUNC, 1, UDS_FUNC_RECV_MSG_ID, false, FLEXCANDRV_MSGTYPE_RX, DLC_BYTE_8, false, true, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_RX_FUNC */
|
||||||
|
{UDS_MSG_IDX_STD_HOST_REQ1, 1, APP_RX_HOST_REQ1_MSG_ID, false, FLEXCANDRV_MSGTYPE_RX, DLC_BYTE_8, false, true, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_RX_FUNC */
|
||||||
|
{UDS_MSG_IDX_STD_HOST_REQ2, 1, APP_RX_HOST_REQ2_MSG_ID, false, FLEXCANDRV_MSGTYPE_RX, DLC_BYTE_8, false, true, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_RX_FUNC */
|
||||||
|
{UDS_MSG_IDX_STD_PHYS_RESP, 1, UDS_PHYS_RESP_MSG_ID, false, FLEXCANDRV_MSGTYPE_TX, DLC_BYTE_8, false, false, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_TX */
|
||||||
|
{UDS_MSG_IDX_STD_ECU_STATUS,1, APP_TX_ECU_STATUS_MSG_ID,false, FLEXCANDRV_MSGTYPE_TX, DLC_BYTE_8, false, false, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_TX */
|
||||||
|
{UDS_MSG_IDX_STD_ECU_DEBUG1,1, APP_TX_ECU_DEBUG1_MSG_ID,false, FLEXCANDRV_MSGTYPE_TX, DLC_BYTE_8, false, false, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_TX */
|
||||||
|
{UDS_MSG_IDX_STD_ECU_DEBUG2,1, APP_TX_ECU_DEBUG2_MSG_ID,false, FLEXCANDRV_MSGTYPE_TX, DLC_BYTE_8, false, false, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_TX */
|
||||||
|
{UDS_MSG_IDX_STD_ECU_DEBUG3,1, APP_TX_ECU_DEBUG3_MSG_ID,false, FLEXCANDRV_MSGTYPE_TX, DLC_BYTE_8, false, false, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_TX */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void RxMsgProcess(void)
|
||||||
|
{
|
||||||
|
HOST_Req1_Type* prxMsgBuf1 = (HOST_Req1_Type*)rxMsgBuf1;
|
||||||
|
debugMode = prxMsgBuf1->HOST_DebugMode;
|
||||||
|
}
|
||||||
|
void MsgTask(UdsType *obj)//1ms task
|
||||||
|
{
|
||||||
|
static uint16_t msg_counter=0;
|
||||||
|
FlexCan_FrameStructureType rxMsg;
|
||||||
|
|
||||||
|
//tx
|
||||||
|
msg_counter++;
|
||||||
|
if (msg_counter >= 50)
|
||||||
|
{
|
||||||
|
msg_counter = 0;
|
||||||
|
FlexCanBoot_TxMessage(APP_TX_ECU_STATUS_MSG_ID, txMsgBuf1, 8);
|
||||||
|
if (debugMode!=0)
|
||||||
|
{
|
||||||
|
FlexCanBoot_TxMessage(APP_TX_ECU_DEBUG1_MSG_ID, txMsgBuf2, 8);
|
||||||
|
FlexCanBoot_TxMessage(APP_TX_ECU_DEBUG2_MSG_ID, txMsgBuf3, 8);
|
||||||
|
FlexCanBoot_TxMessage(APP_TX_ECU_DEBUG3_MSG_ID, txMsgBuf4, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//rx
|
||||||
|
/* Handler user routine */
|
||||||
|
if(FlexCanBoot_ReadoutMsg(&rxMsg) == true)
|
||||||
|
{
|
||||||
|
if((rxMsg.id == UDS_PHYS_RECV_MSG_ID) || (rxMsg.id == UDS_FUNC_RECV_MSG_ID))
|
||||||
|
{
|
||||||
|
IsoTp_HandleIncomingCanMsg(&obj->isotp, rxMsg.id, rxMsg.data, rxMsg.len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (rxMsg.id == APP_RX_HOST_REQ1_MSG_ID)
|
||||||
|
{
|
||||||
|
memcpy(rxMsgBuf1, rxMsg.data, rxMsg.len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RxMsgProcess();
|
||||||
|
|
||||||
|
//uds stack
|
||||||
|
Uds_Run(obj);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************* CAN *****************************************/
|
||||||
|
int8_t FlexCanBoot_TxMessage(uint32_t msgId, const uint8_t* pData, uint8_t size)
|
||||||
|
{
|
||||||
|
FlexCanDrv_MsgObjType txMsgObj;
|
||||||
|
uint8_t msgIdx = 0, i = 0;
|
||||||
|
|
||||||
|
for(i = 0; i < flexCanCfg.msgNum; i++)
|
||||||
|
{
|
||||||
|
if(msgId == flexCanCfg.msgCfg[i].msgId)
|
||||||
|
{
|
||||||
|
msgIdx = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
txMsgObj.msgBufId = flexCanCfg.msgCfg[msgIdx].msgBufId;
|
||||||
|
txMsgObj.dlc = size;
|
||||||
|
txMsgObj.msgId = flexCanCfg.msgCfg[msgIdx].msgId;
|
||||||
|
memcpy(&txMsgObj.data[0], pData, size);
|
||||||
|
|
||||||
|
FlexCanDrv_SetTxMsg(flexCanDrv_DemoObj, &txMsgObj);
|
||||||
|
/* transmit standard CAN Tx message */
|
||||||
|
FlexCanDrv_TransmitMsg(flexCanDrv_DemoObj, &txMsgObj);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlexCanBoot_Init(McuType *obj)
|
||||||
|
{
|
||||||
|
uint32_t busClockFreq = 0;
|
||||||
|
|
||||||
|
/* CAN init */
|
||||||
|
memset(&flexCan_DataInfo, 0, sizeof(flexCan_DataInfo));
|
||||||
|
memset(&flexCanCfg, 0, sizeof(flexCanCfg));
|
||||||
|
SEGGER_RTT_printf(0,"-----FlexCanDrv_INIT-----\n");
|
||||||
|
/* get CAN controller default configuration */
|
||||||
|
FlexCanDrv_GetDefaultCfg(&flexCanCfg);
|
||||||
|
|
||||||
|
flexCanCfg.msgNum = sizeof(msgCfgObj) / sizeof(FlexCanDrv_MsgCfgType);
|
||||||
|
flexCanCfg.msgCfg = msgCfgObj;
|
||||||
|
|
||||||
|
flexCanDrv_DemoObj = &obj->flexCanDrv0;
|
||||||
|
|
||||||
|
/* set PTE4 as MUX 5 - CAN0.RX */
|
||||||
|
PinsDrv_SetMuxModeSel(&obj->ptb, 0, PINSDRV_MUX_ALT5);
|
||||||
|
|
||||||
|
/* set PTE5 as MUX 5 - CAN0.TX */
|
||||||
|
PinsDrv_SetMuxModeSel(&obj->ptb, 1, PINSDRV_MUX_ALT5);
|
||||||
|
|
||||||
|
flexCanCfg.clkSrc = FLEXCANDRV_CLKSRC_CHICLK;
|
||||||
|
flexCanCfg.fdEnable = false;
|
||||||
|
flexCanCfg.fdISOEnable = false;
|
||||||
|
flexCanCfg.enhancefifoEnable = true;
|
||||||
|
flexCanCfg.msgBufDataLenSel = FLEXCANDRV_MB_SIZE_BYTE_8;
|
||||||
|
flexCanCfg.individualMaskEnable = true;
|
||||||
|
|
||||||
|
if(flexCanCfg.clkSrc == FLEXCANDRV_CLKSRC_CHICLK)
|
||||||
|
{
|
||||||
|
ClockDrv_GetFreq(&obj->clockDrv, CLOCKDRV_APB, &busClockFreq);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ClockDrv_GetFreq(&obj->clockDrv, CLOCKDRV_SOSC_DIV2, &busClockFreq);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(flexCanCfg.fdEnable == true)
|
||||||
|
{
|
||||||
|
FlexCanDrv_BitTimingCalc(&flexCanCfg.fdBitTiming,
|
||||||
|
busClockFreq, /* module clock source: 16M */
|
||||||
|
2000000, /* baudrate: 2M */
|
||||||
|
7500, /* sample point: 75% */
|
||||||
|
2000, /* SJW: 20% */
|
||||||
|
1); /* FD bit timing */
|
||||||
|
}
|
||||||
|
|
||||||
|
FlexCanDrv_BitTimingCalc(&flexCanCfg.bitTiming,
|
||||||
|
busClockFreq, /* module clock source: 16M */
|
||||||
|
500000, /* baudrate: 500K */
|
||||||
|
7500, /* sample point: 75% */
|
||||||
|
2500, /* SJW: 20% */
|
||||||
|
0); /* classic CAN bit timing */
|
||||||
|
|
||||||
|
/* initialize CAN module */
|
||||||
|
FlexCanDrv_Configure(flexCanDrv_DemoObj, &flexCanCfg);
|
||||||
|
|
||||||
|
/* enable enhance rx fifo interrupt */
|
||||||
|
FlexCanDrv_SetEnhanceRxFFIsr(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_DAIE, true);
|
||||||
|
IrqDrv_EnableIrq(CAN0_ERxFIFO_IRQn);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool FlexCanBoot_ReadoutMsg(FlexCan_FrameStructureType* pRxMsgObj)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
if(flexCan_DataInfo.wrIdx != flexCan_DataInfo.rdIdx)
|
||||||
|
{
|
||||||
|
memcpy(pRxMsgObj, &flexCan_DataInfo.rxMsg[flexCan_DataInfo.rdIdx], sizeof(FlexCan_FrameStructureType));
|
||||||
|
flexCan_DataInfo.rdIdx++;
|
||||||
|
if(flexCan_DataInfo.rdIdx >= CAN_BUFFER_FIFO_SIZE)
|
||||||
|
{
|
||||||
|
flexCan_DataInfo.rdIdx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t flexCanBoot_EnhanceRxFFCnt = 0;
|
||||||
|
void CAN0_ERxFIFO_Handler(void)
|
||||||
|
{
|
||||||
|
if(FlexCanDrv_GetEnhanceRxFFIsrFlag(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_DAIE) == true)
|
||||||
|
{
|
||||||
|
if(FlexCanDrv_GetEnhanceRxFFIsFull(flexCanDrv_DemoObj) == false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
if(FlexCanDrv_GetEnhanceRxFFIsEmpty(flexCanDrv_DemoObj) == false)
|
||||||
|
{
|
||||||
|
FlexCanDrv_MsgObjType rxMsgObj;
|
||||||
|
|
||||||
|
flexCanBoot_EnhanceRxFFCnt = FlexCanDrv_GetEnhanceRxFFMsgNums(flexCanDrv_DemoObj);
|
||||||
|
|
||||||
|
if(flexCanBoot_EnhanceRxFFCnt > 0)
|
||||||
|
{
|
||||||
|
FlexCanDrv_GetEnhanceRxFifoMsg(flexCanDrv_DemoObj, &rxMsgObj);
|
||||||
|
memcpy(flexCan_DataInfo.rxMsg[flexCan_DataInfo.wrIdx].data, rxMsgObj.data, rxMsgObj.dlc);
|
||||||
|
flexCan_DataInfo.rxMsg[flexCan_DataInfo.wrIdx].id = rxMsgObj.msgId;
|
||||||
|
flexCan_DataInfo.rxMsg[flexCan_DataInfo.wrIdx].len = rxMsgObj.dlc;
|
||||||
|
flexCan_DataInfo.wrIdx++;
|
||||||
|
if(flexCan_DataInfo.wrIdx >= CAN_BUFFER_FIFO_SIZE)
|
||||||
|
{
|
||||||
|
flexCan_DataInfo.wrIdx = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(FlexCanDrv_GetEnhanceRxFFIsrFlag(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_WMMIE) == true)
|
||||||
|
{
|
||||||
|
FlexCanDrv_ClearEnhanceRxFFIsrFlag(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_WMMIE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(FlexCanDrv_GetEnhanceRxFFIsrFlag(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_OVFIE) == true)
|
||||||
|
{
|
||||||
|
FlexCanDrv_ClearEnhanceRxFFIsrFlag(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_OVFIE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(FlexCanDrv_GetEnhanceRxFFIsrFlag(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_UFWIE) == true)
|
||||||
|
{
|
||||||
|
FlexCanDrv_ClearEnhanceRxFFIsrFlag(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_UFWIE);
|
||||||
|
}
|
||||||
|
}
|
46
cva_asw_m0146/src/canuser.h
Normal file
46
cva_asw_m0146/src/canuser.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#ifndef __CANUSER_H__
|
||||||
|
#define __CANUSER_H__
|
||||||
|
|
||||||
|
#include "mcu.h"
|
||||||
|
#include "uds.h"
|
||||||
|
/*******************************************************************************
|
||||||
|
* the defines
|
||||||
|
******************************************************************************/
|
||||||
|
#define UDS_PHYS_RECV_MSG_ID (0x732)
|
||||||
|
#define UDS_FUNC_RECV_MSG_ID (0x7DF)
|
||||||
|
#define UDS_PHYS_RESP_MSG_ID (0x7B2)
|
||||||
|
|
||||||
|
#define APP_TX_ECU_STATUS_MSG_ID (0x210)
|
||||||
|
#define APP_TX_ECU_DEBUG1_MSG_ID (0x211)
|
||||||
|
#define APP_TX_ECU_DEBUG2_MSG_ID (0x212)
|
||||||
|
#define APP_TX_ECU_DEBUG3_MSG_ID (0x213)
|
||||||
|
#define APP_RX_HOST_REQ1_MSG_ID (0x200)
|
||||||
|
#define APP_RX_HOST_REQ2_MSG_ID (0x201)
|
||||||
|
|
||||||
|
#define CAN_DATA_BUFFER_SIZE (64u)
|
||||||
|
#define CAN_BUFFER_FIFO_SIZE (32u)
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* the typedefs
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t id;
|
||||||
|
uint8_t data[CAN_DATA_BUFFER_SIZE];
|
||||||
|
uint8_t len;
|
||||||
|
uint16_t timeStamp;
|
||||||
|
uint32_t hrTimeStamp;
|
||||||
|
} FlexCan_FrameStructureType;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* the function prototypes
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
void FlexCanBoot_Init(McuType *obj);
|
||||||
|
int8_t FlexCanBoot_TxMessage(uint32_t msgId, const uint8_t* pData, uint8_t size);
|
||||||
|
bool FlexCanBoot_ReadoutMsg(FlexCan_FrameStructureType* pRxMsgObj);
|
||||||
|
void MsgTask(UdsType *obj);
|
||||||
|
|
||||||
|
#endif
|
@ -1,11 +1,13 @@
|
|||||||
|
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
#include "TLE94x1.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "drivers/reset/reset_drv.h"
|
||||||
|
#include "mcu.h"
|
||||||
|
|
||||||
static const unsigned char SW_VERSION[16] = "SW0101_20240510";
|
static const unsigned char SW_VERSION[16] = "SW0101_20240510";
|
||||||
static const unsigned char HW_VERSION[8] = "HW01";
|
static const unsigned char HW_VERSION[8] = "HW01";
|
||||||
|
extern McuType mcu;
|
||||||
|
|
||||||
void getSW_VERSION(unsigned char *pdata)
|
void getSW_VERSION(unsigned char *pdata)
|
||||||
{
|
{
|
||||||
@ -23,3 +25,12 @@ void getBuildTime(unsigned char *pdata)
|
|||||||
memcpy(pdata + 12, (unsigned char *)0x00010404, 8);
|
memcpy(pdata + 12, (unsigned char *)0x00010404, 8);
|
||||||
pdata[11] = ' ';
|
pdata[11] = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void extHardwareReset(void)
|
||||||
|
{
|
||||||
|
SBC_Write_RegField(SBC_M_S_CTRL, SBC_M_S_CTRL_MODE_Msk, SBC_M_S_CTRL_MODE_Pos, SBC_MODE_RESET, NULL);
|
||||||
|
}
|
||||||
|
void extSortwareReset(void)
|
||||||
|
{
|
||||||
|
ResetDrv_SoftwareResetModule(&mcu.resetDrv,RESETDRV_SWRESET_SYS);
|
||||||
|
}
|
@ -6,6 +6,9 @@ void getSW_VERSION(unsigned char *pdata);
|
|||||||
void getHW_VERSION(unsigned char *pdata);
|
void getHW_VERSION(unsigned char *pdata);
|
||||||
void getBuildTime(unsigned char *pdata);
|
void getBuildTime(unsigned char *pdata);
|
||||||
|
|
||||||
|
void extHardwareReset(void);
|
||||||
|
void extSortwareReset(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include "TLE94x1.h"
|
#include "TLE94x1.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "irq_drv.h"
|
#include "irq_drv.h"
|
||||||
|
#include "canuser.h"
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* the defines
|
* the defines
|
||||||
@ -15,51 +17,23 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* the typedefs
|
* the typedefs
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
UDS_MSG_IDX_STD_RX_PHYS,
|
|
||||||
UDS_MSG_IDX_STD_RX_FUNC,
|
|
||||||
UDS_MSG_IDX_STD_RX_TEST1,
|
|
||||||
UDS_MSG_IDX_STD_RX_TEST2,
|
|
||||||
UDS_MSG_IDX_STD_TX_TEST1,
|
|
||||||
UDS_MSG_IDX_STD_TX,
|
|
||||||
UDS_MSG_IDX_STD_TEST1,
|
|
||||||
UDS_MSG_IDX_STD_TEST2,
|
|
||||||
|
|
||||||
UDS_MSG_IDX_NUM
|
|
||||||
} Uds_MsgIdIdxType;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
FlexCan_FrameStructureType rxMsg[CAN_BUFFER_FIFO_SIZE];
|
|
||||||
FlexCan_FrameStructureType txMsg[CAN_BUFFER_FIFO_SIZE];
|
|
||||||
uint8_t wrIdx;
|
|
||||||
uint8_t rdIdx;
|
|
||||||
} FlexCan_DataInfoType;
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* the globals
|
* the globals
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
FlexCanDrv_ControllerCfgType flexCanCfg;
|
|
||||||
FlexCan_DataInfoType flexCan_DataInfo;
|
|
||||||
FlexCanDrvType* flexCanDrv_DemoObj;
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* the const
|
* the const
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
const FlexCanDrv_MsgCfgType msgCfgObj[UDS_MSG_IDX_NUM] = {
|
|
||||||
{UDS_MSG_IDX_STD_RX_PHYS, 1, UDS_PHYS_RECV_MSG_ID, false, FLEXCANDRV_MSGTYPE_RX, DLC_BYTE_8, false, true, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_RX_PHYS */
|
|
||||||
{UDS_MSG_IDX_STD_RX_FUNC, 1, UDS_FUNC_RECV_MSG_ID, false, FLEXCANDRV_MSGTYPE_RX, DLC_BYTE_8, false, true, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_RX_FUNC */
|
|
||||||
{UDS_MSG_IDX_STD_RX_TEST1, 1, APP_RX_TEST1_MSG_ID, false, FLEXCANDRV_MSGTYPE_RX, DLC_BYTE_8, false, true, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_RX_FUNC */
|
|
||||||
{UDS_MSG_IDX_STD_RX_TEST2, 1, APP_RX_TEST2_MSG_ID, false, FLEXCANDRV_MSGTYPE_RX, DLC_BYTE_8, false, true, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_RX_FUNC */
|
|
||||||
{UDS_MSG_IDX_STD_TX, 1, UDS_PHYS_RESP_MSG_ID, false, FLEXCANDRV_MSGTYPE_TX, DLC_BYTE_8, false, false, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_TX */
|
|
||||||
{UDS_MSG_IDX_STD_TEST1, 1, APP_TX_TEST1_MSG_ID, false, FLEXCANDRV_MSGTYPE_TX, DLC_BYTE_8, false, false, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_TX */
|
|
||||||
{UDS_MSG_IDX_STD_TEST2, 1, APP_TX_TEST2_MSG_ID, false, FLEXCANDRV_MSGTYPE_TX, DLC_BYTE_8, false, false, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_TX */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* the function prototypes
|
* the function prototypes
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
static void FlexCanBoot_Init(McuType *obj);
|
|
||||||
static void hw_IO_Init(McuType *obj);
|
static void hw_IO_Init(McuType *obj);
|
||||||
|
|
||||||
|
|
||||||
@ -112,16 +86,6 @@ void hw_init(McuType *obj)
|
|||||||
SEGGER_RTT_printf(0,"-----SPI_INIT-----\n");
|
SEGGER_RTT_printf(0,"-----SPI_INIT-----\n");
|
||||||
SBC_SPI_INIT();
|
SBC_SPI_INIT();
|
||||||
|
|
||||||
/* CAN init */
|
|
||||||
memset(&flexCan_DataInfo, 0, sizeof(flexCan_DataInfo));
|
|
||||||
memset(&flexCanCfg, 0, sizeof(flexCanCfg));
|
|
||||||
SEGGER_RTT_printf(0,"-----FlexCanDrv_INIT-----\n");
|
|
||||||
/* get CAN controller default configuration */
|
|
||||||
FlexCanDrv_GetDefaultCfg(&flexCanCfg);
|
|
||||||
|
|
||||||
flexCanCfg.msgNum = sizeof(msgCfgObj) / sizeof(FlexCanDrv_MsgCfgType);
|
|
||||||
flexCanCfg.msgCfg = msgCfgObj;
|
|
||||||
|
|
||||||
FlexCanBoot_Init(obj);
|
FlexCanBoot_Init(obj);
|
||||||
|
|
||||||
hw_IO_Init(obj);
|
hw_IO_Init(obj);
|
||||||
@ -459,149 +423,8 @@ void hw_MotorCtrl(McuType *obj,Motor_ID_Type motorid,Motor_ACT_Type dir)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/************************************* CAN *****************************************/
|
|
||||||
int8_t FlexCanBoot_TxMessage(uint32_t msgId, const uint8_t* pData, uint8_t size)
|
|
||||||
{
|
|
||||||
FlexCanDrv_MsgObjType txMsgObj;
|
|
||||||
uint8_t msgIdx = 0, i = 0;
|
|
||||||
|
|
||||||
for(i = 0; i < flexCanCfg.msgNum; i++)
|
|
||||||
{
|
|
||||||
if(msgId == flexCanCfg.msgCfg[i].msgId)
|
|
||||||
{
|
|
||||||
msgIdx = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
txMsgObj.msgBufId = flexCanCfg.msgCfg[msgIdx].msgBufId;
|
|
||||||
txMsgObj.dlc = size;
|
|
||||||
txMsgObj.msgId = flexCanCfg.msgCfg[msgIdx].msgId;
|
|
||||||
memcpy(&txMsgObj.data[0], pData, size);
|
|
||||||
|
|
||||||
FlexCanDrv_SetTxMsg(flexCanDrv_DemoObj, &txMsgObj);
|
|
||||||
/* transmit standard CAN Tx message */
|
|
||||||
FlexCanDrv_TransmitMsg(flexCanDrv_DemoObj, &txMsgObj);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void FlexCanBoot_Init(McuType *obj)
|
|
||||||
{
|
|
||||||
uint32_t busClockFreq = 0;
|
|
||||||
|
|
||||||
flexCanDrv_DemoObj = &obj->flexCanDrv0;
|
|
||||||
|
|
||||||
/* set PTE4 as MUX 5 - CAN0.RX */
|
|
||||||
PinsDrv_SetMuxModeSel(&obj->ptb, 0, PINSDRV_MUX_ALT5);
|
|
||||||
|
|
||||||
/* set PTE5 as MUX 5 - CAN0.TX */
|
|
||||||
PinsDrv_SetMuxModeSel(&obj->ptb, 1, PINSDRV_MUX_ALT5);
|
|
||||||
|
|
||||||
flexCanCfg.clkSrc = FLEXCANDRV_CLKSRC_CHICLK;
|
|
||||||
flexCanCfg.fdEnable = false;
|
|
||||||
flexCanCfg.fdISOEnable = false;
|
|
||||||
flexCanCfg.enhancefifoEnable = true;
|
|
||||||
flexCanCfg.msgBufDataLenSel = FLEXCANDRV_MB_SIZE_BYTE_8;
|
|
||||||
flexCanCfg.individualMaskEnable = true;
|
|
||||||
|
|
||||||
if(flexCanCfg.clkSrc == FLEXCANDRV_CLKSRC_CHICLK)
|
|
||||||
{
|
|
||||||
ClockDrv_GetFreq(&obj->clockDrv, CLOCKDRV_APB, &busClockFreq);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ClockDrv_GetFreq(&obj->clockDrv, CLOCKDRV_SOSC_DIV2, &busClockFreq);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(flexCanCfg.fdEnable == true)
|
|
||||||
{
|
|
||||||
FlexCanDrv_BitTimingCalc(&flexCanCfg.fdBitTiming,
|
|
||||||
busClockFreq, /* module clock source: 16M */
|
|
||||||
2000000, /* baudrate: 2M */
|
|
||||||
7500, /* sample point: 75% */
|
|
||||||
2000, /* SJW: 20% */
|
|
||||||
1); /* FD bit timing */
|
|
||||||
}
|
|
||||||
|
|
||||||
FlexCanDrv_BitTimingCalc(&flexCanCfg.bitTiming,
|
|
||||||
busClockFreq, /* module clock source: 16M */
|
|
||||||
500000, /* baudrate: 500K */
|
|
||||||
7500, /* sample point: 75% */
|
|
||||||
2500, /* SJW: 20% */
|
|
||||||
0); /* classic CAN bit timing */
|
|
||||||
|
|
||||||
/* initialize CAN module */
|
|
||||||
FlexCanDrv_Configure(flexCanDrv_DemoObj, &flexCanCfg);
|
|
||||||
|
|
||||||
/* enable enhance rx fifo interrupt */
|
|
||||||
FlexCanDrv_SetEnhanceRxFFIsr(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_DAIE, true);
|
|
||||||
IrqDrv_EnableIrq(CAN0_ERxFIFO_IRQn);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FlexCanBoot_ReadoutMsg(FlexCan_FrameStructureType* pRxMsgObj)
|
|
||||||
{
|
|
||||||
bool ret = false;
|
|
||||||
|
|
||||||
if(flexCan_DataInfo.wrIdx != flexCan_DataInfo.rdIdx)
|
|
||||||
{
|
|
||||||
memcpy(pRxMsgObj, &flexCan_DataInfo.rxMsg[flexCan_DataInfo.rdIdx], sizeof(FlexCan_FrameStructureType));
|
|
||||||
flexCan_DataInfo.rdIdx++;
|
|
||||||
if(flexCan_DataInfo.rdIdx >= CAN_BUFFER_FIFO_SIZE)
|
|
||||||
{
|
|
||||||
flexCan_DataInfo.rdIdx = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
uint8_t flexCanBoot_EnhanceRxFFCnt = 0;
|
|
||||||
void CAN0_ERxFIFO_Handler(void)
|
|
||||||
{
|
|
||||||
if(FlexCanDrv_GetEnhanceRxFFIsrFlag(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_DAIE) == true)
|
|
||||||
{
|
|
||||||
if(FlexCanDrv_GetEnhanceRxFFIsFull(flexCanDrv_DemoObj) == false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
if(FlexCanDrv_GetEnhanceRxFFIsEmpty(flexCanDrv_DemoObj) == false)
|
|
||||||
{
|
|
||||||
FlexCanDrv_MsgObjType rxMsgObj;
|
|
||||||
|
|
||||||
flexCanBoot_EnhanceRxFFCnt = FlexCanDrv_GetEnhanceRxFFMsgNums(flexCanDrv_DemoObj);
|
|
||||||
|
|
||||||
if(flexCanBoot_EnhanceRxFFCnt > 0)
|
|
||||||
{
|
|
||||||
FlexCanDrv_GetEnhanceRxFifoMsg(flexCanDrv_DemoObj, &rxMsgObj);
|
|
||||||
memcpy(flexCan_DataInfo.rxMsg[flexCan_DataInfo.wrIdx].data, rxMsgObj.data, rxMsgObj.dlc);
|
|
||||||
flexCan_DataInfo.rxMsg[flexCan_DataInfo.wrIdx].id = rxMsgObj.msgId;
|
|
||||||
flexCan_DataInfo.rxMsg[flexCan_DataInfo.wrIdx].len = rxMsgObj.dlc;
|
|
||||||
flexCan_DataInfo.wrIdx++;
|
|
||||||
if(flexCan_DataInfo.wrIdx >= CAN_BUFFER_FIFO_SIZE)
|
|
||||||
{
|
|
||||||
flexCan_DataInfo.wrIdx = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(FlexCanDrv_GetEnhanceRxFFIsrFlag(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_WMMIE) == true)
|
|
||||||
{
|
|
||||||
FlexCanDrv_ClearEnhanceRxFFIsrFlag(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_WMMIE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(FlexCanDrv_GetEnhanceRxFFIsrFlag(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_OVFIE) == true)
|
|
||||||
{
|
|
||||||
FlexCanDrv_ClearEnhanceRxFFIsrFlag(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_OVFIE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(FlexCanDrv_GetEnhanceRxFFIsrFlag(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_UFWIE) == true)
|
|
||||||
{
|
|
||||||
FlexCanDrv_ClearEnhanceRxFFIsrFlag(flexCanDrv_DemoObj, FLEXCANDRV_ENHANCERXFF_ISR_SRC_UFWIE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,61 +2,23 @@
|
|||||||
#define __HWCTRL_H__
|
#define __HWCTRL_H__
|
||||||
|
|
||||||
#include "mcu.h"
|
#include "mcu.h"
|
||||||
|
#include "MotorCtrl.h"
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* the defines
|
* the defines
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
#define UDS_PHYS_RECV_MSG_ID (0x732)
|
|
||||||
#define UDS_FUNC_RECV_MSG_ID (0x7DF)
|
|
||||||
#define UDS_PHYS_RESP_MSG_ID (0x7B2)
|
|
||||||
|
|
||||||
#define APP_TX_TEST1_MSG_ID (0x111)
|
|
||||||
#define APP_TX_TEST2_MSG_ID (0x222)
|
|
||||||
#define APP_RX_TEST1_MSG_ID (0x444)
|
|
||||||
#define APP_RX_TEST2_MSG_ID (0x555)
|
|
||||||
|
|
||||||
#define CAN_DATA_BUFFER_SIZE (64u)
|
|
||||||
#define CAN_BUFFER_FIFO_SIZE (32u)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* the typedefs
|
* the typedefs
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint32_t id;
|
|
||||||
uint8_t data[CAN_DATA_BUFFER_SIZE];
|
|
||||||
uint8_t len;
|
|
||||||
uint16_t timeStamp;
|
|
||||||
uint32_t hrTimeStamp;
|
|
||||||
} FlexCan_FrameStructureType;
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
Motor_ACT_NOACT,//停止
|
|
||||||
Motor_ACT_CW,//正转
|
|
||||||
Motor_ACT_CCW,//反转
|
|
||||||
} Motor_ACT_Type;
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
Motor1,//
|
|
||||||
Motor2,//
|
|
||||||
Motor3,//
|
|
||||||
Motor4,//
|
|
||||||
Motor5,//
|
|
||||||
Motor6,//
|
|
||||||
} Motor_ID_Type;
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* the function prototypes
|
* the function prototypes
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
void hw_init(McuType *obj);
|
void hw_init(McuType *obj);
|
||||||
int8_t FlexCanBoot_TxMessage(uint32_t msgId, const uint8_t* pData, uint8_t size);
|
|
||||||
bool FlexCanBoot_ReadoutMsg(FlexCan_FrameStructureType* pRxMsgObj);
|
|
||||||
|
|
||||||
|
|
||||||
void hw_MotorCtrl(McuType *obj,Motor_ID_Type motorid,Motor_ACT_Type dir);
|
void hw_MotorCtrl(McuType *obj,Motor_ID_Type motorid,Motor_ACT_Type dir);
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,11 +55,6 @@ typedef struct
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
McuType mcu;
|
McuType mcu;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma location = ".asw_header"
|
#pragma location = ".asw_header"
|
||||||
__root const app_CfgInfoType app_inif = {
|
__root const app_CfgInfoType app_inif = {
|
||||||
.sAswHeader = ASW_HEAD_MASK,//0x00010400
|
.sAswHeader = ASW_HEAD_MASK,//0x00010400
|
||||||
@ -79,10 +74,8 @@ __root const app_CfgInfoType app_inif = {
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
IrqDrv_DisableGlobalInterrupt();
|
IrqDrv_DisableGlobalInterrupt();
|
||||||
|
|
||||||
|
|
||||||
/* Initialize all MCU drivers: flash drv included */
|
/* Initialize all MCU drivers: flash drv included */
|
||||||
Mcu_Init(&mcu);
|
Mcu_Init(&mcu);
|
||||||
|
|
||||||
@ -92,8 +85,6 @@ int main(void)
|
|||||||
|
|
||||||
appTaskInit(&mcu);
|
appTaskInit(&mcu);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IrqDrv_EnableGlobalInterrupt();
|
IrqDrv_EnableGlobalInterrupt();
|
||||||
SEGGER_RTT_printf(0,"-----init success-----\n");
|
SEGGER_RTT_printf(0,"-----init success-----\n");
|
||||||
while(1)
|
while(1)
|
||||||
|
@ -25,7 +25,7 @@ if not "%~1" == "" goto debugFile
|
|||||||
|
|
||||||
@echo on
|
@echo on
|
||||||
|
|
||||||
"E:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.general.xcl" --backend -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.driver.xcl"
|
"e:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.general.xcl" --backend -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.driver.xcl"
|
||||||
|
|
||||||
@echo off
|
@echo off
|
||||||
goto end
|
goto end
|
||||||
@ -34,7 +34,7 @@ goto end
|
|||||||
|
|
||||||
@echo on
|
@echo on
|
||||||
|
|
||||||
"E:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.general.xcl" "--debug_file=%~1" --backend -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.driver.xcl"
|
"e:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.general.xcl" "--debug_file=%~1" --backend -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.driver.xcl"
|
||||||
|
|
||||||
@echo off
|
@echo off
|
||||||
:end
|
:end
|
@ -23,9 +23,9 @@
|
|||||||
|
|
||||||
if ($debugfile -eq "")
|
if ($debugfile -eq "")
|
||||||
{
|
{
|
||||||
& "E:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.general.xcl" --backend -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.driver.xcl"
|
& "e:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.general.xcl" --backend -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.driver.xcl"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
& "E:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.general.xcl" --debug_file=$debugfile --backend -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.driver.xcl"
|
& "e:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.general.xcl" --debug_file=$debugfile --backend -f "F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\settings\cva_bootloader_m0146.Debug.driver.xcl"
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
"-p"
|
"-p"
|
||||||
|
|
||||||
"E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\config\debugger\CVAChip\CVM0144.ddf"
|
"e:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\config\debugger\CVAChip\CVM0144.ddf"
|
||||||
|
|
||||||
"--semihosting"
|
"--semihosting"
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
"E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armPROC.dll"
|
"e:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armPROC.dll"
|
||||||
|
|
||||||
"E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armJLINK.dll"
|
"e:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armJLINK.dll"
|
||||||
|
|
||||||
"F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\Debug_FLASH\Exe\bootloader_m146.out"
|
"F:\FCB_project\RP-01\CODE\cva_bootloader_m0146\Debug_FLASH\Exe\bootloader_m146.out"
|
||||||
|
|
||||||
--plugin="E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armbat.dll"
|
--plugin="e:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armbat.dll"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,13 +15,13 @@
|
|||||||
<WatchCond>_ 0</WatchCond>
|
<WatchCond>_ 0</WatchCond>
|
||||||
<Watch0>_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0</Watch0>
|
<Watch0>_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0</Watch0>
|
||||||
<Watch1>_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0</Watch1>
|
<Watch1>_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0</Watch1>
|
||||||
<LeaveTargetRunning>_ 0</LeaveTargetRunning>
|
|
||||||
<CStepIntDis>_ 0</CStepIntDis>
|
|
||||||
<jlinkResetStyle>12</jlinkResetStyle>
|
<jlinkResetStyle>12</jlinkResetStyle>
|
||||||
<jlinkResetStrategy>0</jlinkResetStrategy>
|
<jlinkResetStrategy>0</jlinkResetStrategy>
|
||||||
<TraceBufferSize>0x10000</TraceBufferSize>
|
<TraceBufferSize>0x10000</TraceBufferSize>
|
||||||
<TraceStallIfFIFOFull>0x0</TraceStallIfFIFOFull>
|
<TraceStallIfFIFOFull>0x0</TraceStallIfFIFOFull>
|
||||||
<TracePortSize>0x4</TracePortSize>
|
<TracePortSize>0x4</TracePortSize>
|
||||||
|
<LeaveTargetRunning>_ 0</LeaveTargetRunning>
|
||||||
|
<CStepIntDis>_ 0</CStepIntDis>
|
||||||
</JLinkDriver>
|
</JLinkDriver>
|
||||||
<DebugChecksum>
|
<DebugChecksum>
|
||||||
<Checksum>968150740</Checksum>
|
<Checksum>968150740</Checksum>
|
||||||
@ -77,11 +77,11 @@
|
|||||||
</CallStackStripe>
|
</CallStackStripe>
|
||||||
<PlDriver>
|
<PlDriver>
|
||||||
<FirstRun>0</FirstRun>
|
<FirstRun>0</FirstRun>
|
||||||
<MemConfigValue>E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\config\debugger\CVAChip\CVM0144.ddf</MemConfigValue>
|
<MemConfigValue>e:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\config\debugger\CVAChip\CVM0144.ddf</MemConfigValue>
|
||||||
</PlDriver>
|
</PlDriver>
|
||||||
<ArmDriver>
|
<ArmDriver>
|
||||||
<EnforceMemoryConfiguration>1</EnforceMemoryConfiguration>
|
|
||||||
<EnableCache>0</EnableCache>
|
<EnableCache>0</EnableCache>
|
||||||
|
<EnforceMemoryConfiguration>1</EnforceMemoryConfiguration>
|
||||||
</ArmDriver>
|
</ArmDriver>
|
||||||
<TerminalIO>
|
<TerminalIO>
|
||||||
<InputSource>1</InputSource>
|
<InputSource>1</InputSource>
|
||||||
@ -95,6 +95,12 @@
|
|||||||
<array_types>
|
<array_types>
|
||||||
<Fmt0>uint8_t[2056] 4 0</Fmt0>
|
<Fmt0>uint8_t[2056] 4 0</Fmt0>
|
||||||
</array_types>
|
</array_types>
|
||||||
|
<DriverProfiling>
|
||||||
|
<Enabled>0</Enabled>
|
||||||
|
<Mode>1</Mode>
|
||||||
|
<Graph>0</Graph>
|
||||||
|
<Symbiont>0</Symbiont>
|
||||||
|
</DriverProfiling>
|
||||||
<Trace2>
|
<Trace2>
|
||||||
<Enabled>0</Enabled>
|
<Enabled>0</Enabled>
|
||||||
<ShowSource>0</ShowSource>
|
<ShowSource>0</ShowSource>
|
||||||
@ -149,12 +155,6 @@
|
|||||||
<ShowTimeSum>1</ShowTimeSum>
|
<ShowTimeSum>1</ShowTimeSum>
|
||||||
<SumSortOrder>0</SumSortOrder>
|
<SumSortOrder>0</SumSortOrder>
|
||||||
</EventLog>
|
</EventLog>
|
||||||
<DriverProfiling>
|
|
||||||
<Enabled>0</Enabled>
|
|
||||||
<Mode>1</Mode>
|
|
||||||
<Graph>0</Graph>
|
|
||||||
<Symbiont>0</Symbiont>
|
|
||||||
</DriverProfiling>
|
|
||||||
<PowerProbe>
|
<PowerProbe>
|
||||||
<Frequency>10000</Frequency>
|
<Frequency>10000</Frequency>
|
||||||
<Probe0>I0</Probe0>
|
<Probe0>I0</Probe0>
|
||||||
|
File diff suppressed because one or more lines are too long
@ -713,6 +713,7 @@ static void Bootloader_SetSessionMode(uint8_t sessionMode)
|
|||||||
|
|
||||||
static void Bootloader_SwReset(void)
|
static void Bootloader_SwReset(void)
|
||||||
{
|
{
|
||||||
|
IrqDrv_DisableGlobalInterrupt();//关闭中断,不加会导致无法复位
|
||||||
ResetDrv_SoftwareResetModule(&mcu.resetDrv, RESETDRV_SWRESET_SYS);
|
ResetDrv_SoftwareResetModule(&mcu.resetDrv, RESETDRV_SWRESET_SYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -837,6 +838,9 @@ int main(void)
|
|||||||
|
|
||||||
if (gSystick1msCnt % 500 == 0)
|
if (gSystick1msCnt % 500 == 0)
|
||||||
{
|
{
|
||||||
|
ret = SBC_Read_Command(SBC_WD_CTRL);
|
||||||
|
SEGGER_RTT_printf(0,"%04d : SBC_WD_CTRL = %x\n",rollingcounter++,ret);
|
||||||
|
testdata[0] = ret;
|
||||||
//FlexCanBoot_TxMessage(UDS_TEXT_TX_MSG_ID,testdata,8);
|
//FlexCanBoot_TxMessage(UDS_TEXT_TX_MSG_ID,testdata,8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -856,8 +860,7 @@ int main(void)
|
|||||||
//PinsDrv_WritePin(&mcu.ptb, 5, 0);
|
//PinsDrv_WritePin(&mcu.ptb, 5, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = SBC_Read_Command(SBC_M_S_CTRL);
|
|
||||||
SEGGER_RTT_printf(0,"%04d : FAM_PROD_STAT = %x\n",rollingcounter++,ret);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user