增加通风加热
This commit is contained in:
parent
23b3ce33dd
commit
2c43f79bf5
@ -1104,7 +1104,7 @@
|
||||
<data>
|
||||
<buildActions>
|
||||
<buildAction>
|
||||
<cmdline>powershell -ExecutionPolicy Bypass -File $PROJ_DIR$\fresh_extern.ps1 && echo > "$BUILD_FILES_DIR$/.postbuild"</cmdline>
|
||||
<cmdline>powershell -ExecutionPolicy Bypass -File $PROJ_DIR$\fresh_extern.ps1</cmdline>
|
||||
<workingDirectory>$PROJ_DIR$</workingDirectory>
|
||||
<buildSequence>preCompile</buildSequence>
|
||||
</buildAction>
|
||||
@ -3020,6 +3020,9 @@
|
||||
<file>
|
||||
<name>$PROJ_DIR$\src\extern.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\src\FanHeat.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\src\hwctrl.c</name>
|
||||
</file>
|
||||
|
@ -3644,9 +3644,9 @@
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\src\extern.c</name>
|
||||
<configuration>
|
||||
<name>Debug</name>
|
||||
</configuration>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\src\FanHeat.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\src\hwctrl.c</name>
|
||||
|
@ -25,8 +25,8 @@
|
||||
<MemConfigValue>E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\config\debugger\CVAChip\CVM0144.ddf</MemConfigValue>
|
||||
</PlDriver>
|
||||
<ArmDriver>
|
||||
<EnforceMemoryConfiguration>1</EnforceMemoryConfiguration>
|
||||
<EnableCache>0</EnableCache>
|
||||
<EnforceMemoryConfiguration>1</EnforceMemoryConfiguration>
|
||||
</ArmDriver>
|
||||
<DebugChecksum>
|
||||
<Checksum>3001005802</Checksum>
|
||||
|
File diff suppressed because one or more lines are too long
113
cva_asw_m0146/src/FanHeat.c
Normal file
113
cva_asw_m0146/src/FanHeat.c
Normal file
@ -0,0 +1,113 @@
|
||||
|
||||
/*******************************************************************************
|
||||
* the includes
|
||||
******************************************************************************/
|
||||
#include "FanHeat.h"
|
||||
#include "key.h"
|
||||
#include "hwctrl.h"
|
||||
#include "scm_canmatrix-binutil.h"
|
||||
/*******************************************************************************
|
||||
* the defines
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* the typedefs
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* the globals
|
||||
******************************************************************************/
|
||||
static uint8_t HeatState,FanState;
|
||||
static uint16_t HeatDutyCounter;
|
||||
|
||||
/*******************************************************************************
|
||||
* the const
|
||||
******************************************************************************/
|
||||
const uint8_t HeatDutyTab[4] = {0,10,20,80};
|
||||
const uint8_t FanDutyTab[4] = {0,10,30,100};
|
||||
|
||||
/*******************************************************************************
|
||||
* the functions
|
||||
******************************************************************************/
|
||||
static void HeatTask(void);
|
||||
static void SetFanHeatMsg(void);
|
||||
static void FanTask(void);
|
||||
|
||||
|
||||
void FanHeatInit(void)
|
||||
{
|
||||
HeatState = 0;
|
||||
FanState = 0;
|
||||
HeatDutyCounter = 0;
|
||||
}
|
||||
|
||||
void FanHeatMainTaks(void)//10ms
|
||||
{
|
||||
if (getKeyPressFlag(KEY_HEAT) == KEY_PRESSED)
|
||||
{
|
||||
HeatState++;
|
||||
if (HeatState > 3)
|
||||
{
|
||||
HeatState = 0;
|
||||
}
|
||||
}
|
||||
if (getKeyPressFlag(KEY_FAN) == KEY_PRESSED)
|
||||
{
|
||||
FanState++;
|
||||
if (FanState > 3)
|
||||
{
|
||||
FanState = 0;
|
||||
}
|
||||
}
|
||||
FanTask();
|
||||
HeatTask();
|
||||
SetFanHeatMsg();
|
||||
|
||||
}
|
||||
|
||||
static void HeatTask(void)
|
||||
{
|
||||
if (HeatState!=0)
|
||||
{
|
||||
|
||||
if (HeatDutyCounter > HeatDutyTab[HeatState])
|
||||
{
|
||||
HeatDrv1Ctrl(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
HeatDrv1Ctrl(1);
|
||||
}
|
||||
|
||||
HeatDutyCounter++;
|
||||
if (HeatDutyCounter >= 100)
|
||||
{
|
||||
HeatDutyCounter = 0;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
HeatDutyCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void FanTask(void)
|
||||
{
|
||||
static uint8_t LastFanState=0;
|
||||
if (LastFanState != FanState)
|
||||
{
|
||||
LastFanState = FanState;
|
||||
FanCtrlDuty(FanDutyTab[FanState]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void SetFanHeatMsg(void)
|
||||
{
|
||||
scm_canmatrix_tx.SCM_STATE.ZY_FAN_STATE = FanState;
|
||||
scm_canmatrix_tx.SCM_STATE.ZY_HEAT_STATE = HeatState;
|
||||
}
|
33
cva_asw_m0146/src/FanHeat.h
Normal file
33
cva_asw_m0146/src/FanHeat.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef __FANHEAT__
|
||||
#define __FANHEAT__
|
||||
|
||||
/*******************************************************************************
|
||||
* the includes
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* the defines
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* the typedefs
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* the globals
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* the functions
|
||||
******************************************************************************/
|
||||
void FanHeatMainTaks(void);
|
||||
void FanHeatInit(void);
|
||||
|
||||
|
||||
#endif
|
@ -49,7 +49,9 @@ 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];
|
||||
@ -64,12 +66,13 @@ uint16_t HallErrorCount[6];
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* the local function prototypes
|
||||
* the local function
|
||||
******************************************************************************/
|
||||
static void MotorCtrl(void);
|
||||
static void AutoCalCtrl(void);
|
||||
static void MotorValueInit(void);
|
||||
static void CurrentDetect(void);
|
||||
|
||||
static uint16_t getOverCurrentTh(uint8_t ch);
|
||||
|
||||
/*******************************************************************************
|
||||
* the local functions
|
||||
@ -538,18 +541,51 @@ static void MotorCtrl(void)//10ms
|
||||
|
||||
}
|
||||
|
||||
static void CurrentDetect(void)
|
||||
#define OC_DELAY_TIME 200
|
||||
void CurrentDetect(void)
|
||||
{
|
||||
uint32_t oc_th,current;
|
||||
oc_th = getOverCurrentTh(0);
|
||||
current = GetAdcmv(ADCH_RLY1)/10;
|
||||
if (current > oc_th)
|
||||
{
|
||||
OC1Count++;
|
||||
if (OC1Count > OC_DELAY_TIME)
|
||||
{
|
||||
OC1Count = 0;
|
||||
OC1flag = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OC1Count = 0;
|
||||
}
|
||||
|
||||
oc_th = getOverCurrentTh(1);
|
||||
current = GetAdcmv(ADCH_RLY3)/10;
|
||||
if (current > oc_th)
|
||||
{
|
||||
OC2Count++;
|
||||
if (OC2Count > OC_DELAY_TIME)
|
||||
{
|
||||
OC2Count = 0;
|
||||
OC2flag = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OC2Count = 0;
|
||||
}
|
||||
|
||||
}
|
||||
/*******************************************************************************
|
||||
* the global functions
|
||||
******************************************************************************/
|
||||
void MotorCtrl_Init(McuType *obj)
|
||||
void MotorCtrl_Init(void)
|
||||
{
|
||||
for (uint8_t i = 0; i < 6; i++)
|
||||
{
|
||||
hw_MotorCtrl(obj, i, Motor_ACT_NOACT);
|
||||
hw_MotorCtrl(i, Motor_ACT_NOACT);
|
||||
}
|
||||
MotorValueInit();
|
||||
}
|
||||
@ -560,13 +596,38 @@ static void SetMotorMsg(void)
|
||||
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(McuType *obj)//10ms task
|
||||
void MotorCtrl_Maintask(void)//10ms task
|
||||
{
|
||||
|
||||
MotorCtrl();
|
||||
|
||||
for (Motor_ID_Type i = 0; i < MOTOR_NUM; i++)
|
||||
{
|
||||
hw_MotorCtrl(obj, i, MotorStateReal[i]);
|
||||
hw_MotorCtrl( i, MotorStateReal[i]);
|
||||
}
|
||||
SetMotorMsg();
|
||||
}
|
||||
@ -626,9 +687,9 @@ void StopAutoCal(void)
|
||||
|
||||
|
||||
|
||||
uint16_t getOverCurrentTh(uint8_t ch)
|
||||
static uint16_t getOverCurrentTh(uint8_t ch)
|
||||
{
|
||||
uint16_t th = 10;
|
||||
uint16_t th = 50;
|
||||
switch (ch)
|
||||
{
|
||||
case 0:
|
||||
@ -673,7 +734,8 @@ void HallDetecte(void)
|
||||
uint8_t i,hallstate;
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
hallstate = GetIOState(i+1);
|
||||
hallstate = GetHallIO(i);
|
||||
MotorHallIO[i] = hallstate;
|
||||
if (hallstate != HallLastState[i])
|
||||
{
|
||||
HallDelay[i]++;
|
||||
|
@ -27,14 +27,14 @@ typedef enum
|
||||
|
||||
|
||||
|
||||
void MotorCtrl_Init(McuType *obj);
|
||||
void MotorCtrl_Maintask(McuType *obj);
|
||||
void MotorCtrl_Init(void);
|
||||
void MotorCtrl_Maintask(void);
|
||||
void setMotorState(Motor_ID_Type motorid,Motor_ACT_Type act);
|
||||
void setMotorTarget(uint8_t motorid,uint16_t target);
|
||||
void StartAutoCal(void);
|
||||
void StopAutoCal(void);
|
||||
|
||||
|
||||
void CurrentDetect(void);
|
||||
void HallDetecte(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "canuser.h"
|
||||
#include "key.h"
|
||||
#include "scm_canmatrix-binutil.h"
|
||||
|
||||
#include "FanHeat.h"
|
||||
/*******************************************************************************
|
||||
* the defines
|
||||
******************************************************************************/
|
||||
@ -28,7 +28,7 @@
|
||||
uint8_t udsSendBuf[UDS_SEND_BUF] = {0};
|
||||
uint8_t udsRecvBuf[UDS_RECV_BUF] = {0};
|
||||
|
||||
|
||||
extern McuType mcu;
|
||||
|
||||
UdsType udsObj;
|
||||
int64_t Get_Cur_Time_Stamp(void);
|
||||
@ -74,19 +74,21 @@ void SysTick_Handler(void)
|
||||
timer_1ms++;
|
||||
Uds_Tick(&udsObj);
|
||||
}
|
||||
void appTask(McuType *obj)
|
||||
void appTask(void)
|
||||
{
|
||||
if(gSystick1msEvent > 0u)
|
||||
{
|
||||
if(udsObj.session == UDS_SESSION_PROGRAMMING)
|
||||
{
|
||||
Asw_SetBootloaderRequest();
|
||||
ResetDrv_SoftwareResetModule(&obj->resetDrv, RESETDRV_SWRESET_SYS);
|
||||
ResetDrv_SoftwareResetModule(&mcu.resetDrv, RESETDRV_SWRESET_SYS);
|
||||
}
|
||||
gSystick1msEvent--;
|
||||
gSystick1msCnt++;
|
||||
gSysTick1sCnt++;
|
||||
MsgTask(&udsObj);
|
||||
CurrentDetect();
|
||||
HallDetecte();
|
||||
if (gSystick1msCnt % 5 == 0)
|
||||
{
|
||||
KeyScanTask();
|
||||
@ -95,7 +97,8 @@ void appTask(McuType *obj)
|
||||
|
||||
if (gSystick1msCnt % 10 == 0)
|
||||
{
|
||||
MotorCtrl_Maintask(obj);
|
||||
MotorCtrl_Maintask();
|
||||
FanHeatMainTaks();
|
||||
}
|
||||
|
||||
if (gSystick1msCnt % 50 == 0)
|
||||
@ -119,13 +122,16 @@ void appTask(McuType *obj)
|
||||
}
|
||||
}
|
||||
|
||||
void appTaskInit(McuType *obj)
|
||||
void appTaskInit(void)
|
||||
{
|
||||
/* UDS init */
|
||||
Uds_UserInit(&udsObj, &udsParam);
|
||||
|
||||
MotorCtrl_Init(obj);
|
||||
MotorCtrl_Init();
|
||||
|
||||
power_ctrl(1);
|
||||
|
||||
FanHeatInit();
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "Mcu.h"
|
||||
|
||||
|
||||
void appTask(McuType *obj);
|
||||
void appTaskInit(McuType *obj);
|
||||
void appTask(void);
|
||||
void appTaskInit(void);
|
||||
|
||||
#endif
|
@ -18,6 +18,7 @@ typedef enum
|
||||
UDS_MSG_IDX_STD_ECU_DEBUG1,
|
||||
UDS_MSG_IDX_STD_ECU_DEBUG2,
|
||||
UDS_MSG_IDX_STD_ECU_DEBUG3,
|
||||
UDS_MSG_IDX_STD_ECU_DEBUG4,
|
||||
UDS_MSG_IDX_NUM
|
||||
} Uds_MsgIdIdxType;
|
||||
|
||||
@ -118,6 +119,10 @@ static uint8_t rxMsgBuf2[8] = {0};
|
||||
static uint8_t debugMode;
|
||||
|
||||
CAN_MESSAGE CAN_D_scm_state;
|
||||
CAN_MESSAGE CAN_D_scm_debug1;
|
||||
CAN_MESSAGE CAN_D_scm_debug2;
|
||||
CAN_MESSAGE CAN_D_scm_debug3;
|
||||
CAN_MESSAGE CAN_D_scm_debug4;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -133,6 +138,7 @@ const FlexCanDrv_MsgCfgType msgCfgObj[UDS_MSG_IDX_NUM] = {
|
||||
{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 */
|
||||
{UDS_MSG_IDX_STD_ECU_DEBUG4,1, APP_TX_ECU_DEBUG4_MSG_ID,false, FLEXCANDRV_MSGTYPE_TX, DLC_BYTE_8, false, false, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_TX */
|
||||
};
|
||||
|
||||
|
||||
@ -162,6 +168,17 @@ static void TxMessage(CAN_MESSAGE* msg)
|
||||
{
|
||||
FlexCanBoot_TxMessage(msg->MsgId, msg->Data, msg->DLC);
|
||||
}
|
||||
|
||||
static void CAN_TxMsg_Change(void)
|
||||
{
|
||||
scm_canmatrix_tx.SCM_STATE.test1 = GetAdcmv(ADCH_Power)/10;
|
||||
scm_canmatrix_tx.SCM_STATE.test2 = GetAdcmv(ADCH_RLY1)/10;
|
||||
scm_canmatrix_tx.SCM_STATE.test3 = GetAdcmv(ADCH_RLY3)/10;
|
||||
scm_canmatrix_tx.SCM_STATE.test4 = GetAdcmv(ADCH_RLY5)/10;
|
||||
scm_canmatrix_tx.SCM_STATE.test5 = GetAdcmv(ADCH_VBG)/10;
|
||||
|
||||
|
||||
}
|
||||
void MsgTask(UdsType *obj)//1ms task
|
||||
{
|
||||
static uint16_t msg_counter=0;
|
||||
@ -172,19 +189,19 @@ void MsgTask(UdsType *obj)//1ms task
|
||||
if (msg_counter >= 50)
|
||||
{
|
||||
msg_counter = 0;
|
||||
scm_canmatrix_tx.SCM_STATE.test1 = (uint8_t)adcResult[0];
|
||||
scm_canmatrix_tx.SCM_STATE.test2 = (uint8_t)adcResult[1];
|
||||
scm_canmatrix_tx.SCM_STATE.test3 = (uint8_t)adcResult[2];
|
||||
scm_canmatrix_tx.SCM_STATE.test4 = (uint8_t)adcResult[3];
|
||||
scm_canmatrix_tx.SCM_STATE.test5 = (uint8_t)adcResult[4];
|
||||
|
||||
CAN_TxMsg_Change();
|
||||
Pack_SCM_STATE_CANmatrix(&scm_canmatrix_tx.SCM_STATE,&CAN_D_scm_state);
|
||||
Pack_SCM_DEBUG1_CANmatrix(&scm_canmatrix_tx.SCM_DEBUG1,&CAN_D_scm_debug1);
|
||||
Pack_SCM_DEBUG2_CANmatrix(&scm_canmatrix_tx.SCM_DEBUG2,&CAN_D_scm_debug2);
|
||||
Pack_SCM_DEBUG3_CANmatrix(&scm_canmatrix_tx.SCM_DEBUG3,&CAN_D_scm_debug3);
|
||||
Pack_SCM_DEBUG4_CANmatrix(&scm_canmatrix_tx.SCM_DEBUG4,&CAN_D_scm_debug4);
|
||||
TxMessage(&CAN_D_scm_state);
|
||||
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);
|
||||
}
|
||||
TxMessage(&CAN_D_scm_debug1);
|
||||
TxMessage(&CAN_D_scm_debug2);
|
||||
TxMessage(&CAN_D_scm_debug3);
|
||||
TxMessage(&CAN_D_scm_debug4);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -235,7 +252,7 @@ int8_t FlexCanBoot_TxMessage(uint32_t msgId, const uint8_t* pData, uint8_t size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FlexCanBoot_Init(McuType *obj)
|
||||
void FlexCanBoot_Init()
|
||||
{
|
||||
uint32_t busClockFreq = 0;
|
||||
|
||||
@ -249,13 +266,13 @@ void FlexCanBoot_Init(McuType *obj)
|
||||
flexCanCfg.msgNum = sizeof(msgCfgObj) / sizeof(FlexCanDrv_MsgCfgType);
|
||||
flexCanCfg.msgCfg = msgCfgObj;
|
||||
|
||||
flexCanDrv_DemoObj = &obj->flexCanDrv0;
|
||||
flexCanDrv_DemoObj = &mcu.flexCanDrv0;
|
||||
|
||||
/* set PTE4 as MUX 5 - CAN0.RX */
|
||||
PinsDrv_SetMuxModeSel(&obj->ptb, 0, PINSDRV_MUX_ALT5);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptb, 0, PINSDRV_MUX_ALT5);
|
||||
|
||||
/* set PTE5 as MUX 5 - CAN0.TX */
|
||||
PinsDrv_SetMuxModeSel(&obj->ptb, 1, PINSDRV_MUX_ALT5);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptb, 1, PINSDRV_MUX_ALT5);
|
||||
|
||||
flexCanCfg.clkSrc = FLEXCANDRV_CLKSRC_CHICLK;
|
||||
flexCanCfg.fdEnable = false;
|
||||
@ -266,11 +283,11 @@ void FlexCanBoot_Init(McuType *obj)
|
||||
|
||||
if(flexCanCfg.clkSrc == FLEXCANDRV_CLKSRC_CHICLK)
|
||||
{
|
||||
ClockDrv_GetFreq(&obj->clockDrv, CLOCKDRV_APB, &busClockFreq);
|
||||
ClockDrv_GetFreq(&mcu.clockDrv, CLOCKDRV_APB, &busClockFreq);
|
||||
}
|
||||
else
|
||||
{
|
||||
ClockDrv_GetFreq(&obj->clockDrv, CLOCKDRV_SOSC_DIV2, &busClockFreq);
|
||||
ClockDrv_GetFreq(&mcu.clockDrv, CLOCKDRV_SOSC_DIV2, &busClockFreq);
|
||||
}
|
||||
|
||||
if(flexCanCfg.fdEnable == true)
|
||||
|
@ -41,7 +41,7 @@ typedef struct
|
||||
* the function prototypes
|
||||
******************************************************************************/
|
||||
|
||||
void FlexCanBoot_Init(McuType *obj);
|
||||
void FlexCanBoot_Init(void);
|
||||
int8_t FlexCanBoot_TxMessage(uint32_t msgId, const uint8_t* pData, uint8_t size);
|
||||
bool FlexCanBoot_ReadoutMsg(FlexCan_FrameStructureType* pRxMsgObj);
|
||||
void MsgTask(UdsType *obj);
|
||||
|
@ -3,12 +3,13 @@
|
||||
#include "mcu.h"
|
||||
#include "hwctrl.h"
|
||||
|
||||
extern McuType mcu;
|
||||
|
||||
//extern McuType mcu;
|
||||
|
||||
/*
|
||||
void ADC0_Handler()
|
||||
{
|
||||
for(uint8_t i=0;i<ADCH_NUM;i++){
|
||||
adcResult[i] = AdcDrv_GetRn(&mcu.adc0Drv, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
@ -14,6 +14,9 @@
|
||||
******************************************************************************/
|
||||
#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
|
||||
/*******************************************************************************
|
||||
* the typedefs
|
||||
******************************************************************************/
|
||||
@ -23,9 +26,11 @@
|
||||
/*******************************************************************************
|
||||
* the globals
|
||||
******************************************************************************/
|
||||
uint32_t adcResult[ADCH_NUM];
|
||||
|
||||
|
||||
static uint32_t adcResult[ADCH_NUM];
|
||||
EDmaDrv_StateType dmaController_State;
|
||||
EDmaDrv_ChnStateType *pEdmaChnState[16]; /* Runtime state structure for the eDMA driver */
|
||||
EDmaDrv_ChnStateType edmaChnState[16];
|
||||
static PwmLiteDrv_ModuleConfigType moduleConfig;
|
||||
/*******************************************************************************
|
||||
* the const
|
||||
******************************************************************************/
|
||||
@ -33,6 +38,7 @@ uint32_t adcResult[ADCH_NUM];
|
||||
*/
|
||||
const TrgMuxDrv_InOutMappingType c_trgmuxInOutMappings[] = {
|
||||
{TRGMUXDRV_TRIGSOURCE_SIM_SW_TRIG, TRGMUXDRV_TARGETMODULE_PDB0_TRG_IN, false}, /* Use SIM_SW_TRIG trigger PDB0 */
|
||||
{TRGMUXDRV_TRIGSOURCE_SIM_SW_TRIG, TRGMUXDRV_TARGETMODULE_PDB1_TRG_IN, false}, /* Use SIM_SW_TRIG trigger PDB0 */
|
||||
};
|
||||
const uint16_t c_numOfTrgmuxInOutMappings = sizeof(c_trgmuxInOutMappings) / sizeof(TrgMuxDrv_InOutMappingType);
|
||||
|
||||
@ -40,33 +46,33 @@ const uint16_t c_numOfTrgmuxInOutMappings = sizeof(c_trgmuxInOutMappings) / size
|
||||
* the function prototypes
|
||||
******************************************************************************/
|
||||
|
||||
static void hw_IO_Init(McuType *obj);
|
||||
static void ADC_Init(McuType *obj);
|
||||
static void hw_IO_Init();
|
||||
static void ADC_Init();
|
||||
|
||||
|
||||
|
||||
static void hw_clock_init(McuType *obj)
|
||||
static void hw_clock_init()
|
||||
{
|
||||
/* Setup the clock */
|
||||
ClockDrv_ModuleClkConfigType clockConfig;
|
||||
uint32_t tTcr = 0;
|
||||
WdgDrv_Disable(&(obj->wdgDrv));
|
||||
WdgDrv_Disable(&mcu.wdgDrv);
|
||||
|
||||
SEGGER_RTT_printf(0,"-----clock_INIT-----\n");
|
||||
|
||||
/* Enable the clock for all ports */
|
||||
clockConfig.gating = true;
|
||||
ClockDrv_ConfigureClock(&obj->clockDrv, CLOCKDRV_PORTA, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&obj->clockDrv, CLOCKDRV_PORTB, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&obj->clockDrv, CLOCKDRV_PORTC, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&obj->clockDrv, CLOCKDRV_PORTD, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&obj->clockDrv, CLOCKDRV_PORTE, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_PORTA, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_PORTB, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_PORTC, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_PORTD, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_PORTE, &clockConfig);
|
||||
|
||||
/* Setup the Pll div2 clock */
|
||||
clockConfig.gating = true;
|
||||
clockConfig.source = CLOCKDRV_PLL;
|
||||
clockConfig.div = 1;
|
||||
ClockDrv_ConfigureClock(&obj->clockDrv, CLOCKDRV_PLL_DIV2, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_PLL_DIV2, &clockConfig);
|
||||
|
||||
|
||||
/* Setup the FIRC2 div2 clock */
|
||||
@ -74,43 +80,112 @@ static void hw_clock_init(McuType *obj)
|
||||
clockConfig.gating = true;
|
||||
clockConfig.source = CLOCKDRV_SOSC;
|
||||
clockConfig.div = 1;
|
||||
ClockDrv_ConfigureClock(&obj->clockDrv, CLOCKDRV_SOSC_DIV2, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_SOSC_DIV2, &clockConfig);
|
||||
|
||||
/* Setup the SPI clock */
|
||||
clockConfig.gating = true;
|
||||
clockConfig.source = CLOCKDRV_PLL_DIV2;
|
||||
ClockDrv_ConfigureClock(&obj->clockDrv, CLOCKDRV_SPI2, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_SPI2, &clockConfig);
|
||||
|
||||
tTcr = SpiReg_GetTcr((const SpiRegType *)&obj->spiDrv2.reg);
|
||||
tTcr = SpiReg_GetTcr((const SpiRegType *)&mcu.spiDrv2.reg);
|
||||
SpiDrv_SetPrescaler(&tTcr,0x03);
|
||||
|
||||
//adc功能
|
||||
/* Enable the clock for PDB0 */
|
||||
ClockDrv_ConfigureClock(&obj->clockDrv, CLOCKDRV_PDB0, &clockConfig);
|
||||
|
||||
/* TRGMUX */
|
||||
TrgMuxDrv_ConfigType trgmuxConfig;
|
||||
trgmuxConfig.numOfInOutMappings = c_numOfTrgmuxInOutMappings;
|
||||
trgmuxConfig.inOutMapping = c_trgmuxInOutMappings;
|
||||
TrgMuxDrv_Configure(&obj->trgMuxDrv, &trgmuxConfig);
|
||||
clockConfig.gating = true;
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_PDB0, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_PDB1, &clockConfig);
|
||||
|
||||
|
||||
/* Enable the clock for ADC */
|
||||
clockConfig.gating = true;
|
||||
clockConfig.source = CLOCKDRV_PLL;
|
||||
clockConfig.div = 4;
|
||||
ClockDrv_ConfigureClock(&obj->clockDrv, CLOCKDRV_ADC0, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_ADC0, &clockConfig);
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_ADC1, &clockConfig);
|
||||
|
||||
/* Enable the clock for DMAMUX */
|
||||
clockConfig.gating = true;
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_DMA_MUX, &clockConfig);
|
||||
|
||||
clockConfig.gating = true;
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_DMA, &clockConfig);
|
||||
|
||||
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_PWMLITE0, &clockConfig);
|
||||
}
|
||||
|
||||
|
||||
static void ADC_Init(McuType *obj)
|
||||
static void ADC_Init()
|
||||
{
|
||||
for (uint8_t i = 0; i < ADCH_NUM; i++)
|
||||
{
|
||||
adcResult[i] = 0;
|
||||
}
|
||||
|
||||
/* TRGMUX */
|
||||
TrgMuxDrv_ConfigType trgmuxConfig;
|
||||
trgmuxConfig.numOfInOutMappings = c_numOfTrgmuxInOutMappings;
|
||||
trgmuxConfig.inOutMapping = c_trgmuxInOutMappings;
|
||||
TrgMuxDrv_Configure(&mcu.trgMuxDrv, &trgmuxConfig);
|
||||
|
||||
pEdmaChnState[0] = &edmaChnState[0];
|
||||
pEdmaChnState[1] = &edmaChnState[1];
|
||||
|
||||
/* Configure EDMA module */
|
||||
|
||||
EDmaDrv_ModuleConfigType edmaCfg;
|
||||
EDmaDrv_GetDefaultConfigure(&edmaCfg);
|
||||
EDmaDrv_Configure(&mcu.edmaDrv, &dmaController_State, &edmaCfg);
|
||||
|
||||
EDmaDrv_ChannelConfigType edmaChannelCfg;
|
||||
EDmaDrv_GetDefaultChannelConfigure(&edmaChannelCfg);
|
||||
edmaChannelCfg.chnConfig = DMA_CHANNEL0;
|
||||
edmaChannelCfg.source = EDMA_REQ_ADC0;
|
||||
edmaChannelCfg.channelPriority = EDMADRV_CHN_PRIORITY_0;
|
||||
EDmaDrv_ConfigureChannel(&mcu.edmaDrv, &pEdmaChnState[0], &edmaChannelCfg);
|
||||
|
||||
edmaChannelCfg.chnConfig = DMA_CHANNEL1;
|
||||
edmaChannelCfg.source = EDMA_REQ_ADC1;
|
||||
edmaChannelCfg.channelPriority = EDMADRV_CHN_PRIORITY_0;
|
||||
EDmaDrv_ConfigureChannel(&mcu.edmaDrv, &pEdmaChnState[0], &edmaChannelCfg);
|
||||
|
||||
|
||||
EDmaDrv_TransferConfigType edmaTransferCfg;
|
||||
EDmaDrv_LoopTransferConfigType edmaLoopCfg;
|
||||
edmaLoopCfg.majorLoopIterationCount = 5;
|
||||
edmaLoopCfg.srcOffsetEnable = true;
|
||||
edmaLoopCfg.dstOffsetEnable = true;
|
||||
edmaLoopCfg.minorLoopOffset = 0;
|
||||
edmaLoopCfg.minorLoopChnLinkEnable = false;
|
||||
edmaLoopCfg.minorLoopChnLinkNumber = 0;
|
||||
edmaLoopCfg.majorLoopChnLinkEnable = false;
|
||||
edmaLoopCfg.majorLoopChnLinkNumber = 0;
|
||||
|
||||
edmaTransferCfg.srcAddr = (uint32_t)&mcu.adc0Drv.adcReg->R[0];
|
||||
edmaTransferCfg.destAddr = (uint32_t)&adcResult[0];
|
||||
edmaTransferCfg.srcDestTransferSize = EDMADRV_TRANSFER_SIZE_4B;
|
||||
edmaTransferCfg.srcOffset = 4;
|
||||
edmaTransferCfg.destOffset = 4;
|
||||
edmaTransferCfg.srcLastAddrAdjust = -20;
|
||||
edmaTransferCfg.destLastAddrAdjust = -20;
|
||||
edmaTransferCfg.srcModulo = EDMADRV_MODULO_OFF;
|
||||
edmaTransferCfg.destModulo = EDMADRV_MODULO_OFF;
|
||||
edmaTransferCfg.minorByteTransferCount = 4;
|
||||
edmaTransferCfg.scatterGatherEnable = false;
|
||||
edmaTransferCfg.scatterGatherNextDescAddr = false;
|
||||
edmaTransferCfg.interruptEnable = false;
|
||||
edmaTransferCfg.hardClrDone = true;
|
||||
edmaTransferCfg.loopTransferConfig = &edmaLoopCfg;
|
||||
|
||||
EDmaDrv_ConfigLoopTransfer(&mcu.edmaDrv, DMA_CHANNEL0, &edmaTransferCfg);
|
||||
|
||||
edmaTransferCfg.srcAddr = (uint32_t)&mcu.adc1Drv.adcReg->R[0];
|
||||
edmaTransferCfg.destAddr = (uint32_t)&adcResult[ADCH_RLY1];
|
||||
EDmaDrv_ConfigLoopTransfer(&mcu.edmaDrv, DMA_CHANNEL1, &edmaTransferCfg);
|
||||
|
||||
EDmaDrv_StartChannel(&mcu.edmaDrv, DMA_CHANNEL0);
|
||||
EDmaDrv_StartChannel(&mcu.edmaDrv, DMA_CHANNEL1);
|
||||
|
||||
|
||||
/* Configure ADC module */
|
||||
AdcDrv_ConfigType adcCfg;
|
||||
@ -120,29 +195,32 @@ static void ADC_Init(McuType *obj)
|
||||
adcCfg.avgSamplesSel = ADCDRV_AVERAGE_32; /* Select 32 samples average */
|
||||
adcCfg.continuousMode = ADCDRV_ONESHOT; /* Select one-shot mode */
|
||||
adcCfg.chnCfg[ADCH_Power].chnSel = ADCDRV_INCHN_EXT3;
|
||||
adcCfg.chnCfg[ADCH_RLY1].chnSel = ADCDRV_INCHN_VBG;
|
||||
adcCfg.chnCfg[ADCH_RLY3].chnSel = ADCDRV_INCHN_EXT0;
|
||||
adcCfg.chnCfg[ADCH_RLY5].chnSel = ADCDRV_INCHN_EXT1;
|
||||
adcCfg.chnCfg[ADCH_HEAT_SENSOR1].chnSel = ADCDRV_INCHN_LDO_VOLT;
|
||||
adcCfg.chnCfg[ADCH_HEAT_SENSOR2].chnSel = ADCDRV_INCHN_EXT3;
|
||||
adcCfg.chnCfg[ADCH_HEAT_C1].chnSel = ADCDRV_INCHN_EXT3;
|
||||
adcCfg.chnCfg[ADCH_HEAT_C2].chnSel = ADCDRV_INCHN_EXT3;
|
||||
adcCfg.chnCfg[ADCH_HEAT_C1].chnSel = ADCDRV_INCHN_EXT15;
|
||||
adcCfg.chnCfg[ADCH_HEAT_C2].chnSel = ADCDRV_INCHN_EXT7;
|
||||
|
||||
adcCfg.chnCfg[ADC_DEMO_LAST_CHANNLE].intEnable = true; /* Last channel enable interrupt */
|
||||
//adcCfg.chnCfg[ADCH_HEAT_C2].intEnable = true; /* Last channel enable interrupt */
|
||||
|
||||
adcCfg.trgSrcCfg.trgSrc = ADCDRV_HW_TRIGGER;
|
||||
adcCfg.trgSrcCfg.hwTrgSrc = ADCDRV_HW_TRGSRC_PDB;
|
||||
adcCfg.trgSrcCfg.swPretrgSrc = ADCDRV_SWPRETRG_PRETRIGGER_0;
|
||||
adcCfg.trgSrcCfg.pretrgSrc = ADCDRV_PRETRG_PDB_PRETRIGGER;
|
||||
|
||||
adcCfg.dmaEnable = true;
|
||||
/* Enable ADC interrupts */
|
||||
IrqDrv_EnableIrq(ADC0_IRQn);
|
||||
AdcDrv_Configure(&obj->adc0Drv, &adcCfg);
|
||||
AdcDrv_EnableAdc(&obj->adc0Drv);
|
||||
//IrqDrv_EnableIrq(ADC0_IRQn);
|
||||
AdcDrv_Configure(&mcu.adc0Drv, &adcCfg);
|
||||
AdcDrv_EnableAdc(&mcu.adc0Drv);
|
||||
|
||||
adcCfg.chnCfg[0].chnSel = ADCDRV_INCHN_EXT5;
|
||||
adcCfg.chnCfg[1].chnSel = ADCDRV_INCHN_EXT2;
|
||||
adcCfg.chnCfg[2].chnSel = ADCDRV_INCHN_EXT7;
|
||||
adcCfg.chnCfg[3].chnSel = ADCDRV_INCHN_VBG;
|
||||
adcCfg.chnCfg[4].chnSel = ADCDRV_INCHN_LPVBG;
|
||||
|
||||
AdcDrv_Configure(&mcu.adc1Drv, &adcCfg);
|
||||
AdcDrv_EnableAdc(&mcu.adc1Drv);
|
||||
|
||||
/* Configure PDB module */
|
||||
uint32_t pdbFreq;
|
||||
ClockDrv_GetFreq(&obj->clockDrv, CLOCKDRV_PDB0, &pdbFreq);
|
||||
ClockDrv_GetFreq(&mcu.clockDrv, CLOCKDRV_PDB0, &pdbFreq);
|
||||
|
||||
PdbDrv_ConfigType pdbCfg;
|
||||
PdbDrv_GetDefaultConfig(&pdbCfg);
|
||||
@ -156,261 +234,308 @@ static void ADC_Init(McuType *obj)
|
||||
pdbCfg.preTrgCfg.mode[0][2] = PDBDRV_PRETRG_BB_MODE;
|
||||
pdbCfg.preTrgCfg.mode[0][3] = PDBDRV_PRETRG_BB_MODE;
|
||||
pdbCfg.preTrgCfg.mode[0][4] = PDBDRV_PRETRG_BB_MODE;
|
||||
pdbCfg.preTrgCfg.mode[0][5] = PDBDRV_PRETRG_BB_MODE;
|
||||
pdbCfg.preTrgCfg.mode[0][6] = PDBDRV_PRETRG_BB_MODE;
|
||||
pdbCfg.preTrgCfg.mode[0][7] = PDBDRV_PRETRG_BB_MODE;
|
||||
pdbCfg.dlyCfg.modCnt = 1*pdbFreq / 128 / 40; /* Periodic triggering PDB in 1s*/
|
||||
|
||||
pdbCfg.dlyCfg.modCnt = 1*pdbFreq / 128 / 40 /1000; /* Periodic triggering PDB in 1s*/
|
||||
pdbCfg.dlyCfg.dlyCnt[0][0] = 0; /* first channel don't need delay time*/
|
||||
pdbCfg.bbSel = PDB_BB_SEL; /* Internal channel chaining of PDB0 CH0 and CH1.
|
||||
* CH0 and CH1 of PDB0 back-to-back operation with COCO[7:0] and COCO[15:8] of ADC0.
|
||||
*/
|
||||
PdbDrv_Configure(&obj->pdb0Drv, &pdbCfg);
|
||||
PdbDrv_Configure(&mcu.pdb0Drv, &pdbCfg);
|
||||
PdbDrv_Configure(&mcu.pdb1Drv, &pdbCfg);
|
||||
|
||||
PdbDrv_EnablePdb(&obj->pdb0Drv); /* Enable PDB0 */
|
||||
TrgMuxDrv_GenSWTrigger(&obj->trgMuxDrv, 100); /* Trigger PDB0 */
|
||||
|
||||
|
||||
PdbDrv_EnablePdb(&mcu.pdb0Drv); /* Enable PDB0 */
|
||||
PdbDrv_EnablePdb(&mcu.pdb1Drv); /* Enable PDB1 */
|
||||
|
||||
|
||||
|
||||
TrgMuxDrv_GenSWTrigger(&mcu.trgMuxDrv, 10); /* Trigger PDB0 */
|
||||
}
|
||||
|
||||
void hw_init(McuType *obj)
|
||||
static void PWM_Init(void)
|
||||
{
|
||||
uint32_t apbClkFreq = 0;
|
||||
ClockDrv_GetFreq(&mcu.clockDrv, CLOCKDRV_APB, &apbClkFreq);
|
||||
/* Configure PWM Module */
|
||||
|
||||
PwmLiteDrv_GetDefaultModuleConfig(&moduleConfig);
|
||||
moduleConfig.period = apbClkFreq / PWM_PERIOD_HZ;
|
||||
moduleConfig.syncType = PWMLITEDRV_SYNC_AT_PERIOD;
|
||||
PwmLiteDrv_ModuleConfig(&mcu.pwmLiteDrv0, &moduleConfig);
|
||||
/* Configure PWM channel 0 */
|
||||
PwmLiteDrv_ChannelConfigType channelConfig;
|
||||
PwmLiteDrv_GetDefaultChannelConfig(&channelConfig);
|
||||
channelConfig.pwmMuxType.channelNumber = PWMLITEDRV_MUX_PWM0_CH0;
|
||||
channelConfig.pwmMuxType.padNumber = PWMLITEDRV_MUX_PAD_PWM4;
|
||||
channelConfig.behavior0 = PWMLITEDRV_HIGH_AT_REACH;
|
||||
channelConfig.behavior1 = PWMLITEDRV_LOW_AT_REACH;
|
||||
channelConfig.threshold0 = 0;
|
||||
channelConfig.threshold1 = moduleConfig.period * 25 / 100;
|
||||
PwmLiteDrv_ConfigChannel(&mcu.pwmLiteDrv0, PWMLITEDRV_PWM_CH0, &channelConfig);
|
||||
/* Enable PWM Module */
|
||||
PwmLiteDrv_EnableModule(&mcu.pwmLiteDrv0);
|
||||
}
|
||||
|
||||
void hw_init(void)
|
||||
{
|
||||
uint32_t gCpuClockFrequency = 0;
|
||||
|
||||
hw_clock_init(obj);
|
||||
hw_clock_init();
|
||||
|
||||
SEGGER_RTT_printf(0,"-----SPI_INIT-----\n");
|
||||
SBC_SPI_INIT();
|
||||
|
||||
FlexCanBoot_Init(obj);
|
||||
FlexCanBoot_Init();
|
||||
|
||||
hw_IO_Init(obj);
|
||||
hw_IO_Init();
|
||||
|
||||
/* Set system tick clock, 1ms event */
|
||||
ClockDrv_GetFreq(&obj->clockDrv, CLOCKDRV_CORE, &gCpuClockFrequency);
|
||||
ClockDrv_GetFreq(&mcu.clockDrv, CLOCKDRV_CORE, &gCpuClockFrequency);
|
||||
SysTick_Config(gCpuClockFrequency / 1000u);
|
||||
IrqDrv_EnableIrq(SysTick_IRQn);
|
||||
|
||||
SBC_Init();
|
||||
SEGGER_RTT_printf(0,"-----ADC_Init-----\n");
|
||||
ADC_Init();
|
||||
|
||||
ADC_Init(obj);
|
||||
PWM_Init();
|
||||
SEGGER_RTT_printf(0,"-----InitFinished-----\n");
|
||||
}
|
||||
|
||||
|
||||
#define PINSDRV_DIR_OUTPUT 1
|
||||
#define PINSDRV_DIR_INPUT 0
|
||||
static void hw_IO_Init(McuType *obj)
|
||||
static void hw_IO_Init(void)
|
||||
{
|
||||
//1
|
||||
PinsDrv_SetMuxModeSel(&obj->ptd, 1, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptd.port, 1, 1);
|
||||
PortReg_SetPcrSr(obj->ptd.port, 1, 1);
|
||||
PinsDrv_SetPinDirection(&obj->ptd, 1, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptd, 1, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptd.port, 1, 1);
|
||||
PortReg_SetPcrSr(mcu.ptd.port, 1, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptd, 1, PINSDRV_DIR_OUTPUT);
|
||||
//2
|
||||
PinsDrv_SetMuxModeSel(&obj->ptd, 0, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptd.port, 0, 1);
|
||||
PortReg_SetPcrSr(obj->ptd.port, 0, 1);
|
||||
PinsDrv_SetPinDirection(&obj->ptd, 0, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptd, 0, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptd.port, 0, 1);
|
||||
PortReg_SetPcrSr(mcu.ptd.port, 0, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptd, 0, PINSDRV_DIR_OUTPUT);
|
||||
//3
|
||||
PinsDrv_SetMuxModeSel(&obj->pte, 11, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pte.port, 11, 1);
|
||||
PortReg_SetPcrSr(obj->pte.port, 11, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pte, 11, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pte, 11, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pte.port, 11, 1);
|
||||
PortReg_SetPcrSr(mcu.pte.port, 11, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pte, 11, PINSDRV_DIR_OUTPUT);
|
||||
//4
|
||||
PinsDrv_SetMuxModeSel(&obj->pte, 10, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pte.port, 10, 1);
|
||||
PortReg_SetPcrSr(obj->pte.port, 10, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pte, 10, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pte, 10, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pte.port, 10, 1);
|
||||
PortReg_SetPcrSr(mcu.pte.port, 10, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pte, 10, PINSDRV_DIR_OUTPUT);
|
||||
//5
|
||||
PinsDrv_SetMuxModeSel(&obj->pte, 5, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pte.port, 5, 1);
|
||||
PortReg_SetPcrSr(obj->pte.port, 5, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pte, 5, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pte, 5, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pte.port, 5, 1);
|
||||
PortReg_SetPcrSr(mcu.pte.port, 5, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pte, 5, PINSDRV_DIR_OUTPUT);
|
||||
//6
|
||||
PinsDrv_SetMuxModeSel(&obj->pte, 4, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pte.port, 4, 1);
|
||||
PortReg_SetPcrSr(obj->pte.port, 4, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pte, 4, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pte, 4, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pte.port, 4, 1);
|
||||
PortReg_SetPcrSr(mcu.pte.port, 4, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pte, 4, PINSDRV_DIR_OUTPUT);
|
||||
//7-12电源
|
||||
//13
|
||||
PinsDrv_SetMuxModeSel(&obj->pte, 3, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pte.port, 3, 1);
|
||||
PortReg_SetPcrSr(obj->pte.port, 3, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pte, 3, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pte, 3, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pte.port, 3, 1);
|
||||
PortReg_SetPcrSr(mcu.pte.port, 3, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pte, 3, PINSDRV_DIR_OUTPUT);
|
||||
//14
|
||||
PinsDrv_SetMuxModeSel(&obj->ptd, 16, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptd.port, 16, 1);
|
||||
PortReg_SetPcrSr(obj->ptd.port, 16, 1);
|
||||
PinsDrv_SetPinDirection(&obj->ptd, 16, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptd, 16, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptd.port, 16, 1);
|
||||
PortReg_SetPcrSr(mcu.ptd.port, 16, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptd, 16, PINSDRV_DIR_OUTPUT);
|
||||
//15
|
||||
PinsDrv_SetMuxModeSel(&obj->ptd, 15, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptd.port, 15, 1);
|
||||
PortReg_SetPcrSr(obj->ptd.port, 15, 1);
|
||||
PinsDrv_SetPinDirection(&obj->ptd, 15, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptd, 15, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptd.port, 15, 1);
|
||||
PortReg_SetPcrSr(mcu.ptd.port, 15, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptd, 15, PINSDRV_DIR_OUTPUT);
|
||||
//16
|
||||
PinsDrv_SetMuxModeSel(&obj->pte, 9, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pte.port, 9, 1);
|
||||
PortReg_SetPcrSr(obj->pte.port, 9, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pte, 9, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pte, 9, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pte.port, 9, 1);
|
||||
PortReg_SetPcrSr(mcu.pte.port, 9, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pte, 9, PINSDRV_DIR_OUTPUT);
|
||||
//17
|
||||
PinsDrv_SetMuxModeSel(&obj->pte, 8, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pte.port, 8, 1);
|
||||
PortReg_SetPcrSr(obj->pte.port, 8, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pte, 8, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pte, 8, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pte.port, 8, 1);
|
||||
PortReg_SetPcrSr(mcu.pte.port, 8, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pte, 8, PINSDRV_DIR_OUTPUT);
|
||||
//18
|
||||
PinsDrv_SetMuxModeSel(&obj->ptb, 5, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptb.port, 5, 1);
|
||||
PortReg_SetPcrSr(obj->ptb.port, 5, 1);
|
||||
PinsDrv_SetPinDirection(&obj->ptb, 5, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptb, 5, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptb.port, 5, 1);
|
||||
PortReg_SetPcrSr(mcu.ptb.port, 5, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptb, 5, PINSDRV_DIR_OUTPUT);
|
||||
//19
|
||||
PinsDrv_SetMuxModeSel(&obj->ptb, 4, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptb.port, 4, 1);
|
||||
PortReg_SetPcrSr(obj->ptb.port, 4, 1);
|
||||
PinsDrv_SetPinDirection(&obj->ptb, 4, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptb, 4, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptb.port, 4, 1);
|
||||
PortReg_SetPcrSr(mcu.ptb.port, 4, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptb, 4, PINSDRV_DIR_OUTPUT);
|
||||
//20-22预留
|
||||
//23
|
||||
PinsDrv_SetMuxModeSel(&obj->ptd, 6, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptd.port, 6, 1);
|
||||
PortReg_SetPcrSr(obj->ptd.port, 6, 1);
|
||||
PinsDrv_SetPinDirection(&obj->ptd, 6, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptd, 6, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptd.port, 6, 1);
|
||||
PortReg_SetPcrSr(mcu.ptd.port, 6, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptd, 6, PINSDRV_DIR_OUTPUT);
|
||||
//24
|
||||
PinsDrv_SetMuxModeSel(&obj->ptd, 5, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptd.port, 5, 1);
|
||||
PortReg_SetPcrSr(obj->ptd.port, 5, 1);
|
||||
PinsDrv_SetPinDirection(&obj->ptd, 5, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptd, 5, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptd.port, 5, 1);
|
||||
PortReg_SetPcrSr(mcu.ptd.port, 5, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptd, 5, PINSDRV_DIR_OUTPUT);
|
||||
//25-26 SPI
|
||||
//27
|
||||
PinsDrv_SetMuxModeSel(&obj->ptc, 17, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrDrvStr(obj->ptc.port, 17, 1);
|
||||
PortReg_SetPcrSr(obj->ptc.port, 17, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptc, 17, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrAen(mcu.ptc.port, 1, 1);
|
||||
PortReg_SetPcrSr(mcu.ptc.port, 1, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptc, 1,0);
|
||||
PinsDrv_SetPortInputDisable(&mcu.ptc,0);
|
||||
//28
|
||||
PinsDrv_SetMuxModeSel(&obj->ptc, 16, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptc.port, 16, 1);
|
||||
PortReg_SetPcrSr(obj->ptc.port, 16, 1);
|
||||
PinsDrv_SetPinDirection(&obj->ptc, 16,PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptc, 16, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptc.port, 16, 1);
|
||||
PortReg_SetPcrSr(mcu.ptc.port, 16, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptc, 16,PINSDRV_DIR_OUTPUT);
|
||||
//29 30 SPI
|
||||
//31
|
||||
PinsDrv_SetMuxModeSel(&obj->ptb, 3, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrDrvStr(obj->ptb.port, 3, 1);
|
||||
PortReg_SetPcrSr(obj->ptb.port, 3, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptb, 3, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrAen(mcu.ptb.port, 3, 1);
|
||||
PortReg_SetPcrSr(mcu.ptb.port, 3, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptb, 3,0);
|
||||
PinsDrv_SetPortInputDisable(&mcu.ptb,0);
|
||||
//32
|
||||
PinsDrv_SetMuxModeSel(&obj->ptb, 2, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptb.port, 2, 1);
|
||||
PortReg_SetPcrSr(obj->ptb.port, 2, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptb, 2, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptb.port, 2, 1);
|
||||
PortReg_SetPcrSr(mcu.ptb.port, 2, 1);
|
||||
//33 34 CAN
|
||||
//35
|
||||
PinsDrv_SetMuxModeSel(&obj->ptc, 9, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptc.port, 9, 1);
|
||||
PortReg_SetPcrSr(obj->ptc.port, 9, 1);
|
||||
PinsDrv_SetPinDirection(&obj->ptc, 9,PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptc, 9, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptc.port, 9, 1);
|
||||
PortReg_SetPcrSr(mcu.ptc.port, 9, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptc, 9,PINSDRV_DIR_OUTPUT);
|
||||
//36
|
||||
PinsDrv_SetMuxModeSel(&obj->ptc, 8, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptc.port, 8, 1);
|
||||
PortReg_SetPcrSr(obj->ptc.port, 8, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptc, 8, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptc.port, 8, 1);
|
||||
PortReg_SetPcrSr(mcu.ptc.port, 8, 1);
|
||||
//37
|
||||
PinsDrv_SetMuxModeSel(&obj->pta, 7, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrAen(obj->pta.port, 7, 1);
|
||||
PortReg_SetPcrSr(obj->pta.port, 7, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pta, 7,0);
|
||||
PinsDrv_SetPortInputDisable(&obj->pta,0);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pta, 7, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrAen(mcu.pta.port, 7, 1);
|
||||
PortReg_SetPcrSr(mcu.pta.port, 7, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pta, 7,0);
|
||||
PinsDrv_SetPortInputDisable(&mcu.pta,0);
|
||||
//38
|
||||
PinsDrv_SetMuxModeSel(&obj->pta, 6, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pta.port, 6, 1);
|
||||
PortReg_SetPcrSr(obj->pta.port, 6, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pta, 6, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pta.port, 6, 1);
|
||||
PortReg_SetPcrSr(mcu.pta.port, 6, 1);
|
||||
//39
|
||||
PinsDrv_SetMuxModeSel(&obj->pte, 7, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pte.port, 7, 1);
|
||||
PortReg_SetPcrSr(obj->pte.port, 7, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pte, 7, PINSDRV_MUX_AS_GPIO);
|
||||
PinsDrv_SetPinDirection(&mcu.pte, 7,0);
|
||||
PortReg_SetPcrSr(mcu.pte.port, 7, 1);
|
||||
|
||||
//40 41 VDD
|
||||
//42 NC
|
||||
//43
|
||||
PinsDrv_SetMuxModeSel(&obj->ptb, 12, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrDrvStr(obj->ptb.port, 12, 1);
|
||||
PortReg_SetPcrSr(obj->ptb.port, 12, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptb, 12, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrAen(mcu.ptb.port, 12, 1);
|
||||
PortReg_SetPcrSr(mcu.ptb.port, 12, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptb, 12,0);
|
||||
PinsDrv_SetPortInputDisable(&mcu.ptb,0);
|
||||
//44
|
||||
PinsDrv_SetMuxModeSel(&obj->ptd, 4, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptd.port, 4, 1);
|
||||
PortReg_SetPcrSr(obj->ptd.port, 4, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptd, 4, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptd.port, 4, 1);
|
||||
PortReg_SetPcrSr(mcu.ptd.port, 4, 1);
|
||||
//45
|
||||
PinsDrv_SetMuxModeSel(&obj->ptd, 3, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptd.port, 3, 1);
|
||||
PortReg_SetPcrSr(obj->ptd.port, 3, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptd, 3, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptd.port, 3, 1);
|
||||
PortReg_SetPcrSr(mcu.ptd.port, 3, 1);
|
||||
//46
|
||||
PinsDrv_SetMuxModeSel(&obj->ptd, 2, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrDrvStr(obj->ptd.port, 2, 1);
|
||||
PortReg_SetPcrSr(obj->ptd.port, 2, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptd, 2, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrAen(mcu.ptd.port, 2, 1);
|
||||
PortReg_SetPcrSr(mcu.ptd.port, 2, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptd, 2,0);
|
||||
PinsDrv_SetPortInputDisable(&mcu.ptd,0);
|
||||
//47
|
||||
PinsDrv_SetMuxModeSel(&obj->pta, 3, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pta.port, 3, 1);
|
||||
PortReg_SetPcrSr(obj->pta.port, 3, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pta, 3, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pta, 3, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pta.port, 3, 1);
|
||||
PortReg_SetPcrSr(mcu.pta.port, 3, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pta, 3, PINSDRV_DIR_OUTPUT);
|
||||
//48
|
||||
PinsDrv_SetMuxModeSel(&obj->pta, 2, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pta.port, 2, 1);
|
||||
PortReg_SetPcrSr(obj->pta.port, 2, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pta, 2, PINSDRV_DIR_OUTPUT);
|
||||
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);
|
||||
//49
|
||||
PinsDrv_SetMuxModeSel(&obj->pta, 1, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrDrvStr(obj->pta.port, 1, 1);
|
||||
PortReg_SetPcrSr(obj->pta.port, 1, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pta, 1, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrAen(mcu.pta.port, 1, 1);
|
||||
PortReg_SetPcrSr(mcu.pta.port, 1, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pta, 1,0);
|
||||
PinsDrv_SetPortInputDisable(&mcu.pta,0);
|
||||
//50
|
||||
PinsDrv_SetMuxModeSel(&obj->pta, 0, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrDrvStr(obj->pta.port, 0, 1);
|
||||
PortReg_SetPcrSr(obj->pta.port, 0, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pta, 0, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrAen(mcu.pta.port, 0, 1);
|
||||
PortReg_SetPcrSr(mcu.pta.port, 0, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pta, 0,0);
|
||||
PinsDrv_SetPortInputDisable(&mcu.pta,0);
|
||||
//51
|
||||
PinsDrv_SetMuxModeSel(&obj->ptc, 7, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrDrvStr(obj->ptc.port, 7, 1);
|
||||
PortReg_SetPcrSr(obj->ptc.port, 7, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptc, 7, PINSDRV_PIN_DISABLED);
|
||||
PortReg_SetPcrAen(mcu.ptc.port, 7, 1);
|
||||
PortReg_SetPcrSr(mcu.ptc.port, 7, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptc, 7,0);
|
||||
PinsDrv_SetPortInputDisable(&mcu.ptc,0);
|
||||
//52
|
||||
PinsDrv_SetMuxModeSel(&obj->ptc, 6, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->ptc.port, 6, 1);
|
||||
PortReg_SetPcrSr(obj->ptc.port, 6, 1);
|
||||
PinsDrv_SetPinDirection(&obj->ptc, 6, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.ptc, 6, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.ptc.port, 6, 1);
|
||||
PortReg_SetPcrSr(mcu.ptc.port, 6, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.ptc, 6, PINSDRV_DIR_OUTPUT);
|
||||
//53
|
||||
PinsDrv_SetMuxModeSel(&obj->pte, 6, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pte.port, 6, 1);
|
||||
PortReg_SetPcrSr(obj->pte.port, 6, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pte, 6, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pte, 6, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pte.port, 6, 1);
|
||||
PortReg_SetPcrSr(mcu.pte.port, 6, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pte, 6, PINSDRV_DIR_OUTPUT);
|
||||
//54
|
||||
PinsDrv_SetMuxModeSel(&obj->pte, 2, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pte.port, 2, 1);
|
||||
PortReg_SetPcrSr(obj->pte.port, 2, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pte, 2, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pte, 2, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pte.port, 2, 1);
|
||||
PortReg_SetPcrSr(mcu.pte.port, 2, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pte, 2, PINSDRV_DIR_OUTPUT);
|
||||
//55
|
||||
PinsDrv_SetMuxModeSel(&obj->pta, 13, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pta.port, 13, 1);
|
||||
PortReg_SetPcrSr(obj->pta.port, 13, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pta, 12, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pta, 13, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pta.port, 13, 1);
|
||||
PortReg_SetPcrSr(mcu.pta.port, 13, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pta, 12, PINSDRV_DIR_OUTPUT);
|
||||
//56
|
||||
PinsDrv_SetMuxModeSel(&obj->pta, 12, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pta.port, 12, 1);
|
||||
PortReg_SetPcrSr(obj->pta.port, 12, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pta, 11, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pta, 12, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pta.port, 12, 1);
|
||||
PortReg_SetPcrSr(mcu.pta.port, 12, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pta, 12, PINSDRV_DIR_OUTPUT);
|
||||
//57
|
||||
PinsDrv_SetMuxModeSel(&obj->pta, 11, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pta.port, 11, 1);
|
||||
PortReg_SetPcrSr(obj->pta.port, 11, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pta, 11, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pta.port, 11, 1);
|
||||
PortReg_SetPcrSr(mcu.pta.port, 11, 1);
|
||||
//58
|
||||
PinsDrv_SetMuxModeSel(&obj->pta, 10, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pta.port, 10, 1);
|
||||
PortReg_SetPcrSr(obj->pta.port, 10, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pta, 10, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pta, 10, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pta.port, 10, 1);
|
||||
PortReg_SetPcrSr(mcu.pta.port, 10, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pta, 10, PINSDRV_DIR_OUTPUT);
|
||||
//59
|
||||
PinsDrv_SetMuxModeSel(&obj->pte, 1, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pte.port, 1, 1);
|
||||
PortReg_SetPcrSr(obj->pte.port, 1, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pte, 1, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pte, 1, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pte.port, 1, 1);
|
||||
PortReg_SetPcrSr(mcu.pte.port, 1, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pte, 1, PINSDRV_DIR_OUTPUT);
|
||||
//60
|
||||
PinsDrv_SetMuxModeSel(&obj->pte, 0, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pte.port, 0, 1);
|
||||
PortReg_SetPcrSr(obj->pte.port, 0, 1);
|
||||
PinsDrv_SetPinDirection(&obj->pte, 0, PINSDRV_DIR_OUTPUT);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pte, 0, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pte.port, 0, 1);
|
||||
PortReg_SetPcrSr(mcu.pte.port, 0, 1);
|
||||
PinsDrv_SetPinDirection(&mcu.pte, 0, PINSDRV_DIR_OUTPUT);
|
||||
//61
|
||||
PinsDrv_SetMuxModeSel(&obj->pte, 5, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(obj->pte.port, 5, 1);
|
||||
PortReg_SetPcrSr(obj->pte.port, 5, 1);
|
||||
PinsDrv_SetMuxModeSel(&mcu.pte, 5, PINSDRV_MUX_AS_GPIO);
|
||||
PortReg_SetPcrDrvStr(mcu.pte.port, 5, 1);
|
||||
PortReg_SetPcrSr(mcu.pte.port, 5, 1);
|
||||
//62-64 SWD
|
||||
}
|
||||
|
||||
/*************************************motor driver *****************************************/
|
||||
void hw_MotorCtrl(McuType *obj,Motor_ID_Type motorid,Motor_ACT_Type dir)
|
||||
void hw_MotorCtrl(Motor_ID_Type motorid,Motor_ACT_Type dir)
|
||||
{
|
||||
switch(motorid)
|
||||
{
|
||||
@ -418,16 +543,16 @@ void hw_MotorCtrl(McuType *obj,Motor_ID_Type motorid,Motor_ACT_Type dir)
|
||||
switch(dir)
|
||||
{
|
||||
case Motor_ACT_NOACT:
|
||||
PinsDrv_ClearPin(&obj->ptd, 0);
|
||||
PinsDrv_ClearPin(&obj->ptd, 1);
|
||||
PinsDrv_ClearPin(&mcu.ptd, 0);
|
||||
PinsDrv_ClearPin(&mcu.ptd, 1);
|
||||
break;
|
||||
case Motor_ACT_CW:
|
||||
PinsDrv_SetPin(&obj->ptd, 0);
|
||||
PinsDrv_ClearPin(&obj->ptd, 1);
|
||||
PinsDrv_SetPin(&mcu.ptd, 0);
|
||||
PinsDrv_ClearPin(&mcu.ptd, 1);
|
||||
break;
|
||||
case Motor_ACT_CCW:
|
||||
PinsDrv_SetPin(&obj->ptd, 1);
|
||||
PinsDrv_ClearPin(&obj->ptd, 0);
|
||||
PinsDrv_SetPin(&mcu.ptd, 1);
|
||||
PinsDrv_ClearPin(&mcu.ptd, 0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -435,16 +560,16 @@ void hw_MotorCtrl(McuType *obj,Motor_ID_Type motorid,Motor_ACT_Type dir)
|
||||
switch(dir)
|
||||
{
|
||||
case Motor_ACT_NOACT:
|
||||
PinsDrv_ClearPin(&obj->pte, 10);
|
||||
PinsDrv_ClearPin(&obj->pte, 11);
|
||||
PinsDrv_ClearPin(&mcu.pte, 10);
|
||||
PinsDrv_ClearPin(&mcu.pte, 11);
|
||||
break;
|
||||
case Motor_ACT_CW:
|
||||
PinsDrv_SetPin(&obj->pte, 10);
|
||||
PinsDrv_ClearPin(&obj->pte, 11);
|
||||
PinsDrv_SetPin(&mcu.pte, 10);
|
||||
PinsDrv_ClearPin(&mcu.pte, 11);
|
||||
break;
|
||||
case Motor_ACT_CCW:
|
||||
PinsDrv_SetPin(&obj->pte, 11);
|
||||
PinsDrv_ClearPin(&obj->pte, 10);
|
||||
PinsDrv_SetPin(&mcu.pte, 11);
|
||||
PinsDrv_ClearPin(&mcu.pte, 10);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -452,16 +577,16 @@ void hw_MotorCtrl(McuType *obj,Motor_ID_Type motorid,Motor_ACT_Type dir)
|
||||
switch(dir)
|
||||
{
|
||||
case Motor_ACT_NOACT:
|
||||
PinsDrv_ClearPin(&obj->pte, 4);
|
||||
PinsDrv_ClearPin(&obj->pte, 5);
|
||||
PinsDrv_ClearPin(&mcu.pte, 4);
|
||||
PinsDrv_ClearPin(&mcu.pte, 5);
|
||||
break;
|
||||
case Motor_ACT_CW:
|
||||
PinsDrv_SetPin(&obj->pte, 4);
|
||||
PinsDrv_ClearPin(&obj->pte, 5);
|
||||
PinsDrv_SetPin(&mcu.pte, 4);
|
||||
PinsDrv_ClearPin(&mcu.pte, 5);
|
||||
break;
|
||||
case Motor_ACT_CCW:
|
||||
PinsDrv_SetPin(&obj->pte, 5);
|
||||
PinsDrv_ClearPin(&obj->pte, 4);
|
||||
PinsDrv_SetPin(&mcu.pte, 5);
|
||||
PinsDrv_ClearPin(&mcu.pte, 4);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -469,16 +594,16 @@ void hw_MotorCtrl(McuType *obj,Motor_ID_Type motorid,Motor_ACT_Type dir)
|
||||
switch(dir)
|
||||
{
|
||||
case Motor_ACT_NOACT:
|
||||
PinsDrv_ClearPin(&obj->pte, 3);
|
||||
PinsDrv_ClearPin(&obj->ptd, 16);
|
||||
PinsDrv_ClearPin(&mcu.pte, 3);
|
||||
PinsDrv_ClearPin(&mcu.ptd, 16);
|
||||
break;
|
||||
case Motor_ACT_CW:
|
||||
PinsDrv_SetPin(&obj->pte, 3);
|
||||
PinsDrv_ClearPin(&obj->ptd, 16);
|
||||
PinsDrv_SetPin(&mcu.pte, 3);
|
||||
PinsDrv_ClearPin(&mcu.ptd, 16);
|
||||
break;
|
||||
case Motor_ACT_CCW:
|
||||
PinsDrv_SetPin(&obj->ptd, 16);
|
||||
PinsDrv_ClearPin(&obj->pte, 3);
|
||||
PinsDrv_SetPin(&mcu.ptd, 16);
|
||||
PinsDrv_ClearPin(&mcu.pte, 3);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -486,16 +611,16 @@ void hw_MotorCtrl(McuType *obj,Motor_ID_Type motorid,Motor_ACT_Type dir)
|
||||
switch(dir)
|
||||
{
|
||||
case Motor_ACT_NOACT:
|
||||
PinsDrv_ClearPin(&obj->pte, 9);
|
||||
PinsDrv_ClearPin(&obj->ptd, 15);
|
||||
PinsDrv_ClearPin(&mcu.pte, 9);
|
||||
PinsDrv_ClearPin(&mcu.ptd, 15);
|
||||
break;
|
||||
case Motor_ACT_CW:
|
||||
PinsDrv_SetPin(&obj->pte, 9);
|
||||
PinsDrv_ClearPin(&obj->ptd, 15);
|
||||
PinsDrv_SetPin(&mcu.pte, 9);
|
||||
PinsDrv_ClearPin(&mcu.ptd, 15);
|
||||
break;
|
||||
case Motor_ACT_CCW:
|
||||
PinsDrv_SetPin(&obj->ptd, 15);
|
||||
PinsDrv_ClearPin(&obj->pte, 9);
|
||||
PinsDrv_SetPin(&mcu.ptd, 15);
|
||||
PinsDrv_ClearPin(&mcu.pte, 9);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -503,16 +628,16 @@ void hw_MotorCtrl(McuType *obj,Motor_ID_Type motorid,Motor_ACT_Type dir)
|
||||
switch(dir)
|
||||
{
|
||||
case Motor_ACT_NOACT:
|
||||
PinsDrv_ClearPin(&obj->pte, 8);
|
||||
PinsDrv_ClearPin(&obj->ptb, 5);
|
||||
PinsDrv_ClearPin(&mcu.pte, 8);
|
||||
PinsDrv_ClearPin(&mcu.ptb, 5);
|
||||
break;
|
||||
case Motor_ACT_CW:
|
||||
PinsDrv_SetPin(&obj->pte, 8);
|
||||
PinsDrv_ClearPin(&obj->ptb, 5);
|
||||
PinsDrv_SetPin(&mcu.pte, 8);
|
||||
PinsDrv_ClearPin(&mcu.ptb, 5);
|
||||
break;
|
||||
case Motor_ACT_CCW:
|
||||
PinsDrv_SetPin(&obj->pte, 8);
|
||||
PinsDrv_ClearPin(&obj->ptb, 5);
|
||||
PinsDrv_SetPin(&mcu.pte, 8);
|
||||
PinsDrv_ClearPin(&mcu.ptb, 5);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -520,10 +645,103 @@ void hw_MotorCtrl(McuType *obj,Motor_ID_Type motorid,Motor_ACT_Type dir)
|
||||
}
|
||||
|
||||
|
||||
void power_ctrl(uint8_t power)
|
||||
{
|
||||
if (power>0)
|
||||
{
|
||||
PinsDrv_SetPin(&mcu.ptc,9);
|
||||
}
|
||||
else
|
||||
{
|
||||
PinsDrv_ClearPin(&mcu.ptc,9);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
uint32_t GetAdcRawData(ADCH_ID_type adch)
|
||||
{
|
||||
if (adch < ADCH_NUM)
|
||||
{
|
||||
return adcResult[adch];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t GetAdcmv(ADCH_ID_type adch)
|
||||
{
|
||||
uint32_t adcval=0;
|
||||
|
||||
if (adch < ADCH_NUM)
|
||||
{
|
||||
adcval = adcResult[adch];
|
||||
}
|
||||
|
||||
|
||||
adcval = ( adcval * 3300 )>>12;
|
||||
|
||||
return adcval;
|
||||
}
|
||||
|
||||
uint8_t GetHallIO(Motor_ID_Type motorid)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
switch (motorid)
|
||||
{
|
||||
case MotorHG:
|
||||
ret = PinsDrv_ReadPin(&mcu.pta,11);
|
||||
break;
|
||||
case MotorKB:
|
||||
ret = PinsDrv_ReadPin(&mcu.ptd,4);
|
||||
break;
|
||||
case MotorTT:
|
||||
ret = PinsDrv_ReadPin(&mcu.ptc,5);
|
||||
break;
|
||||
case MotorZY:
|
||||
ret = PinsDrv_ReadPin(&mcu.pte,7);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void HeatDrv1Ctrl(uint8_t onoff)
|
||||
{
|
||||
if (onoff > 0)
|
||||
{
|
||||
PinsDrv_SetPin(&mcu.ptc, 16);
|
||||
PinsDrv_SetPin(&mcu.ptb, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
PinsDrv_ClearPin(&mcu.ptc, 16);
|
||||
PinsDrv_ClearPin(&mcu.ptb, 4);
|
||||
}
|
||||
}
|
||||
|
||||
void HeatDrv2Ctrl(uint8_t onoff)
|
||||
{
|
||||
if (onoff > 0)
|
||||
{
|
||||
PinsDrv_SetPin(&mcu.ptd, 5);
|
||||
PinsDrv_SetPin(&mcu.ptd, 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
PinsDrv_ClearPin(&mcu.ptd, 5);
|
||||
PinsDrv_ClearPin(&mcu.ptd, 6);
|
||||
}
|
||||
}
|
||||
|
||||
void FanCtrlDuty(uint8_t duty)
|
||||
{
|
||||
uint32_t dutydata = 0;
|
||||
if (duty > 100)
|
||||
{
|
||||
duty = 100;
|
||||
}
|
||||
dutydata = moduleConfig.period * duty / 100;
|
||||
PwmLiteDrv_UpdatePwmThresholdAtRunning(&mcu.pwmLiteDrv0,PWMLITEDRV_PWM_CH0,0U,dutydata);
|
||||
|
||||
}
|
||||
|
@ -7,31 +7,39 @@
|
||||
/*******************************************************************************
|
||||
* the defines
|
||||
******************************************************************************/
|
||||
|
||||
extern uint32_t adcResult[];
|
||||
extern McuType mcu;
|
||||
//extern uint32_t adcResult[];
|
||||
/*******************************************************************************
|
||||
* the typedefs
|
||||
******************************************************************************/
|
||||
typedef enum
|
||||
{
|
||||
ADCH_Power=0,
|
||||
ADCH_RLY1,
|
||||
ADCH_RLY3,
|
||||
ADCH_RLY5,
|
||||
ADCH_HEAT_SENSOR1,
|
||||
ADCH_HEAT_SENSOR2,
|
||||
ADCH_HEAT_C1,
|
||||
ADCH_HEAT_C2,
|
||||
ADCH_Power=0,//ADC0CH3
|
||||
ADCH_RLY3,//ADC0CH0
|
||||
ADCH_RLY5,//ADC0CH1
|
||||
ADCH_HEAT_C1,//ADC0CH15
|
||||
ADCH_HEAT_C2,//ADC0CH7
|
||||
|
||||
ADCH_RLY1,//ADC1CH5
|
||||
ADCH_HEAT_SENSOR1,//ADC1CH2
|
||||
ADCH_HEAT_SENSOR2,//ADC1CH7
|
||||
ADCH_VBG,
|
||||
ADCH_LPVBG,
|
||||
ADCH_NUM,
|
||||
}ADCH_ID_type;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* the function prototypes
|
||||
* the function
|
||||
******************************************************************************/
|
||||
void hw_init(McuType *obj);
|
||||
void hw_MotorCtrl(McuType *obj,Motor_ID_Type motorid,Motor_ACT_Type dir);
|
||||
|
||||
|
||||
void hw_init(void);
|
||||
void hw_MotorCtrl(Motor_ID_Type motorid,Motor_ACT_Type dir);
|
||||
uint32_t GetAdcRawData(ADCH_ID_type adch);
|
||||
uint32_t GetAdcmv(ADCH_ID_type adch);
|
||||
void power_ctrl(uint8_t power);
|
||||
uint8_t GetHallIO(Motor_ID_Type motorid);
|
||||
void HeatDrv1Ctrl(uint8_t onoff);
|
||||
void HeatDrv2Ctrl(uint8_t onoff);
|
||||
void FanCtrlDuty(uint8_t duty);
|
||||
|
||||
#endif
|
||||
|
@ -111,6 +111,10 @@ static uint8_t GetSigState(KEY_ID_type key_id)
|
||||
return scm_canmatrix_rx.Panel_Key.KEY_ZY_U;
|
||||
case KEY_ZY_D:
|
||||
return scm_canmatrix_rx.Panel_Key.KEY_ZY_D;
|
||||
case KEY_FAN:
|
||||
return scm_canmatrix_rx.Panel_Key.KEY_ZY_FAN;
|
||||
case KEY_HEAT:
|
||||
return scm_canmatrix_rx.Panel_Key.KEY_ZY_HEAT;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@ -139,55 +143,55 @@ void KeyProTask(void)
|
||||
//KB
|
||||
if (getKeyPressFlag(KEY_KB_F) == KEY_PRESSED)
|
||||
{
|
||||
setMotorState(MotorHG,Motor_ACT_CW);
|
||||
setMotorState(MotorKB,Motor_ACT_CW);
|
||||
}
|
||||
if (getKeyReleaseFlag(KEY_KB_F) == KEY_PRESSED)
|
||||
{
|
||||
setMotorState(MotorHG,Motor_ACT_NOACT);
|
||||
setMotorState(MotorKB,Motor_ACT_NOACT);
|
||||
}
|
||||
if (getKeyPressFlag(KEY_KB_R) == KEY_PRESSED)
|
||||
{
|
||||
setMotorState(MotorHG,Motor_ACT_CCW);
|
||||
setMotorState(MotorKB,Motor_ACT_CCW);
|
||||
}
|
||||
if (getKeyReleaseFlag(KEY_KB_R) == KEY_PRESSED)
|
||||
{
|
||||
setMotorState(MotorHG,Motor_ACT_NOACT);
|
||||
setMotorState(MotorKB,Motor_ACT_NOACT);
|
||||
}
|
||||
|
||||
//TT
|
||||
if (getKeyPressFlag(KEY_TT_F) == KEY_PRESSED)
|
||||
{
|
||||
setMotorState(MotorHG,Motor_ACT_CW);
|
||||
setMotorState(MotorTT,Motor_ACT_CW);
|
||||
}
|
||||
if (getKeyReleaseFlag(KEY_TT_F) == KEY_PRESSED)
|
||||
{
|
||||
setMotorState(MotorHG,Motor_ACT_NOACT);
|
||||
setMotorState(MotorTT,Motor_ACT_NOACT);
|
||||
}
|
||||
if (getKeyPressFlag(KEY_TT_R) == KEY_PRESSED)
|
||||
{
|
||||
setMotorState(MotorHG,Motor_ACT_CCW);
|
||||
setMotorState(MotorTT,Motor_ACT_CCW);
|
||||
}
|
||||
if (getKeyReleaseFlag(KEY_TT_R) == KEY_PRESSED)
|
||||
{
|
||||
setMotorState(MotorHG,Motor_ACT_NOACT);
|
||||
setMotorState(MotorTT,Motor_ACT_NOACT);
|
||||
}
|
||||
|
||||
//ZY
|
||||
if (getKeyPressFlag(KEY_ZY_U) == KEY_PRESSED)
|
||||
{
|
||||
setMotorState(MotorHG,Motor_ACT_CW);
|
||||
setMotorState(MotorZY,Motor_ACT_CW);
|
||||
}
|
||||
if (getKeyReleaseFlag(KEY_ZY_U) == KEY_PRESSED)
|
||||
{
|
||||
setMotorState(MotorHG,Motor_ACT_NOACT);
|
||||
setMotorState(MotorZY,Motor_ACT_NOACT);
|
||||
}
|
||||
if (getKeyPressFlag(KEY_ZY_D) == KEY_PRESSED)
|
||||
{
|
||||
setMotorState(MotorHG,Motor_ACT_CCW);
|
||||
setMotorState(MotorZY,Motor_ACT_CCW);
|
||||
}
|
||||
if (getKeyReleaseFlag(KEY_ZY_D) == KEY_PRESSED)
|
||||
{
|
||||
setMotorState(MotorHG,Motor_ACT_NOACT);
|
||||
setMotorState(MotorZY,Motor_ACT_NOACT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,8 @@ typedef enum
|
||||
KEY_TT_R,
|
||||
KEY_ZY_U,//上
|
||||
KEY_ZY_D,//下
|
||||
KEY_FAN,
|
||||
KEY_HEAT,
|
||||
KEY_NUM,
|
||||
}KEY_ID_type;
|
||||
|
||||
|
@ -71,15 +71,15 @@ int main(void)
|
||||
|
||||
SEGGER_RTT_Init();
|
||||
|
||||
hw_init(&mcu);
|
||||
hw_init();
|
||||
|
||||
appTaskInit(&mcu);
|
||||
appTaskInit();
|
||||
|
||||
IrqDrv_EnableGlobalInterrupt();
|
||||
SEGGER_RTT_printf(0,"-----init success-----\n");
|
||||
while(1)
|
||||
{
|
||||
appTask(&mcu);
|
||||
appTask();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ void SystemInit(void)
|
||||
|
||||
#if defined (_USE_EXT_OSC_)
|
||||
/* Use External oscillator */
|
||||
AcgReg_SetOscRange(ACG, 3); /* set SOSC frequency range(use max value when SOSC as the clock source of the PLL) */
|
||||
AcgReg_SetOscRange(ACG, 1); /* set SOSC frequency range(use max value when SOSC as the clock source of the PLL) */
|
||||
AcgReg_SetEnSosc(ACG, 1); /* enable SOSC */
|
||||
while(AcgReg_GetStSoscRdy(ACG) == 0); /* wait until SOSC is ready */
|
||||
|
||||
@ -68,7 +68,7 @@ void SystemInit(void)
|
||||
*/
|
||||
AcgReg_SetPllClkIn(ACG, 2);
|
||||
AcgReg_SetPllPreDiv(ACG, 0);
|
||||
AcgReg_SetPllM(ACG, 45);
|
||||
AcgReg_SetPllM(ACG, 90);
|
||||
AcgReg_SetPllFbkSel(ACG, 0);
|
||||
AcgReg_SetPllPosDiv(ACG, 3);
|
||||
/* SCG PLL configuration:
|
||||
|
Loading…
x
Reference in New Issue
Block a user