增加座椅按摩

This commit is contained in:
sunbeam 2025-03-11 17:05:32 +08:00
parent a954b820a3
commit 1330079d3a
20 changed files with 1043 additions and 24 deletions

View File

@ -369,6 +369,7 @@
<state>$PROJ_DIR$\src\CANmatrix\usr</state>
<state>$PROJ_DIR$\src\fee</state>
<state>$PROJ_DIR$\SDK\middleware\nvm\fee</state>
<state>$PROJ_DIR$\src\LIN_Master</state>
</option>
<option>
<name>CCStdIncCheck</name>
@ -3061,11 +3062,17 @@
<file>
<name>$PROJ_DIR$\src\key.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\LIN_Master\LIN_Master.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\main.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\MotorCtrl.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\LIN_Master\SeatMassage.c</name>
</file>
</group>
</project>

View File

@ -3684,11 +3684,17 @@
<file>
<name>$PROJ_DIR$\src\key.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\LIN_Master\LIN_Master.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\main.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\MotorCtrl.c</name>
</file>
<file>
<name>$PROJ_DIR$\src\LIN_Master\SeatMassage.c</name>
</file>
</group>
</project>

View File

@ -25,7 +25,7 @@ if not "%~1" == "" goto debugFile
@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"
"D:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCBproject\DMK-RP-01\RP-01\cva_asw_m0146\settings\cva_asw_m0146.Debug.general.xcl" --backend -f "F:\FCBproject\DMK-RP-01\RP-01\cva_asw_m0146\settings\cva_asw_m0146.Debug.driver.xcl"
@echo off
goto end
@ -34,7 +34,7 @@ goto end
@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"
"D:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCBproject\DMK-RP-01\RP-01\cva_asw_m0146\settings\cva_asw_m0146.Debug.general.xcl" "--debug_file=%~1" --backend -f "F:\FCBproject\DMK-RP-01\RP-01\cva_asw_m0146\settings\cva_asw_m0146.Debug.driver.xcl"
@echo off
:end

View File

@ -23,9 +23,9 @@
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"
& "D:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCBproject\DMK-RP-01\RP-01\cva_asw_m0146\settings\cva_asw_m0146.Debug.general.xcl" --backend -f "F:\FCBproject\DMK-RP-01\RP-01\cva_asw_m0146\settings\cva_asw_m0146.Debug.driver.xcl"
}
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"
& "D:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\cspybat" -f "F:\FCBproject\DMK-RP-01\RP-01\cva_asw_m0146\settings\cva_asw_m0146.Debug.general.xcl" --debug_file=$debugfile --backend -f "F:\FCBproject\DMK-RP-01\RP-01\cva_asw_m0146\settings\cva_asw_m0146.Debug.driver.xcl"
}

View File

@ -6,7 +6,7 @@
"-p"
"E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\config\debugger\CVAChip\CVM0144.ddf"
"D:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\config\debugger\CVAChip\CVM0144.ddf"
"--semihosting"

View File

@ -1,10 +1,10 @@
"E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armPROC.dll"
"D:\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"
"D:\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:\FCBproject\DMK-RP-01\RP-01\cva_asw_m0146\Debug_FLASH\Exe\app_m146.out"
--plugin="E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armbat.dll"
--plugin="D:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin\armbat.dll"

View File

@ -22,11 +22,11 @@
</JLinkDriver>
<PlDriver>
<FirstRun>0</FirstRun>
<MemConfigValue>E:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\config\debugger\CVAChip\CVM0144.ddf</MemConfigValue>
<MemConfigValue>D:\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>1315671368</Checksum>
@ -153,7 +153,8 @@
<Breakpoints2>
<Bp0>_ 1 "EMUL_CODE" "{$PROJ_DIR$\src\fee\MemoryTask.c}.49.9" 0 0 1 "" 0 "" 0</Bp0>
<Bp1>_ 1 "EMUL_CODE" "{$PROJ_DIR$\src\fee\MemoryTask.c}.96.13" 0 0 1 "" 0 "" 0</Bp1>
<Count>2</Count>
<Bp2>_ 1 "EMUL_CODE" "{$PROJ_DIR$\src\LIN_Master\SeatMassage.c}.20.1" 0 0 1 "" 0 "" 0</Bp2>
<Count>3</Count>
</Breakpoints2>
<Aliases>
<Count>0</Count>

View File

@ -1,8 +1,3 @@
参考https://github.com/astand/c-coderdbc
生成指令
./coderdbc.exe -dbc DMK-RP-01_CAN_V0.1.dbc -out ./gen/ -drvname CANmatrix -nodeutils -rw -driverdir -gendate
打包
tar -czvf CANmatrix.tar.gz CANmatrix
zip -r CANmatrix.zip CANmatrix
./coderdbc.exe -dbc DMK-RP-01_CAN_V0.1.dbc -out ./ -drvname CANmatrix -nodeutils -rw -driverdir -gendate

View File

@ -0,0 +1,557 @@
/*******************************************************************************
* the includes
******************************************************************************/
#include "LIN_Master.h"
/*******************************************************************************
* the defines
******************************************************************************/
/* the LIN baud rate */
#define LIN_BAUD_RATE (19200u)
/* one lin frame data size */
#define LIN_DATA_SIZE (8u)
/* lin frame sync header */
#define LIN_SYNC_HEADER (0x55)
/* the client requests ID */
#define LIN_ID_DIAG_MASTER_REQ (0x3C)
/* the server response ID */
#define LIN_ID_DIAG_SLAVE_RESP (0x3D)
#define LIN_FRAME_NUM (5u)
/* add parity for frame id */
#define MAKE_PARITY (0u)
/* check parity for frame pid */
#define CHECK_PARITY (1u)
#define GETBIT(A,B) ((A >> B) & 0x01) //get bit B in A
#define TIMER_UNIT_US (1000u)
/*******************************************************************************
* the typedefs
******************************************************************************/
typedef enum {
LIN_STATE_IDLE = 0u,
LIN_STATE_BREAK,
LIN_STATE_SYNC_HEDADER,
LIN_STATE_PID,
LIN_STATE_TX_DATA,
LIN_STATE_RX_DATA,
LIN_STATE_CHECKSUM
}Lin_StateType;
typedef enum {
LINSTACK_CHECKSUM_CLASSIC = 0,
LINSTACK_CHECKSUM_ENHANCED,
LINSTACK_CHECKSUM_NUM
}Lin_CheckSumType;
typedef enum
{
LIN_RES_PUB = 0x00U, /*!< Publisher response */
LIN_RES_SUB = 0x01U /*!< Subscriber response */
} lin_ResponseType;
typedef enum
{
LIN_FRM_UNCD = 0x00U, /*!< Unconditional frame */
LIN_FRM_EVNT = 0x01U, /*!< Event triggered frame */
LIN_FRM_SPRDC = 0x10U, /*!< Sporadic frame */
LIN_FRM_DIAG = 0x11U /*!< Diagnostic frame */
} lin_FrameType;
typedef struct {
uint8_t data[LIN_DATA_SIZE];
uint8_t checkSum;
}Lin_FrameDataType;
typedef struct {
uint8_t frameId; /*!< frame identifier */
lin_FrameType frameType; /*!< frame type */
uint8_t frameLen; /*!< frame data length */
lin_ResponseType resType; /*!< response type */
uint8_t *pFrameData; /*!< frame data buffer point */
uint8_t updatingFlag; /*!< frame data updating flag */
}Lin_FrameInfoType;
/*******************************************************************************
* the globals
******************************************************************************/
extern McuType mcu;
static Lin_FrameDataType linTxData;
static Lin_FrameDataType linRxData;
static uint8_t linTxDataCnt = 0;
static uint8_t linRxDataCnt = 0;
static uint8_t linFrameData[LIN_FRAME_NUM][LIN_DATA_SIZE];
static uint8_t linFrameDataBackup[LIN_DATA_SIZE];
static Lin_FrameInfoType linFrameInfoTab[LIN_FRAME_NUM] = {
{0x10, LIN_FRM_UNCD, 2, LIN_RES_PUB, &linFrameData[0][0], 0x00},
{0x20, LIN_FRM_UNCD, 8, LIN_RES_SUB, &linFrameData[1][0], 0x00},
{0x21, LIN_FRM_UNCD, 8, LIN_RES_SUB, &linFrameData[2][0], 0x00},
{0x30, LIN_FRM_UNCD, 8, LIN_RES_SUB, &linFrameData[3][0], 0x00},
{0x31, LIN_FRM_UNCD, 8, LIN_RES_SUB, &linFrameData[4][0], 0x00},
};
uint8_t gCurFrameIdx = 0;
Lin_StateType linState = LIN_STATE_IDLE;
/* time stamp variable unit 1ms */
volatile uint32_t gTime1msCnt = 0;
/* the timeout counter of lin communication */
volatile uint32_t linComTimeoutCnt = 0;
uint32_t linMaxHeaderTimeout = 0;
uint32_t linMaxFrameResTimeout = 0;
/*******************************************************************************
* the const
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
/*! \brief Computes maximum header timeout
*
* Theader_Maximum = 1.4 * THeader_Nominal, THeader_Nominal = 34 * TBit,
* (13 nominal bits of break; 1 nominal bit of break delimiter; 10 bits for SYNC and 10 bits of PID)
* TIMER_UNIT_US is in micro second
*
* \param[in] baudRate LIN network baud rate
*
* \return maximum timeout for the selected baud rate
*
* Implements : lin_calc_max_header_timeout_cnt_Activity
*/
static uint32_t Lin_CalcMaxHeaderTimeoutCnt(uint32_t baudRate)
{
return ((14U * 34U * 100000U / (TIMER_UNIT_US * baudRate)) + 1U);
}
/*! \brief Computes the maximum response timeout
*
* TResponse_Maximum = 1.4 * TResponse_Nominal, TResponse_Nominal = 10 * (NData+ 1) * TBit
*
* \param[in] baudRate LIN network baud rate
* size frame size in bytes
*
* \return maximum response timeout for the given baud rate and frame size
*
* Implements : lin_calc_max_res_timeout_cnt_Activity
*/
static uint32_t Lin_CalcMaxResTimeoutCnt(uint32_t baudRate, uint8_t size)
{
uint32_t bitNum = 14U * (1U + size);
return ((bitNum * 1000000U / (TIMER_UNIT_US * baudRate)) + 1U);
}
/*! \brief The lin PID parity.
* \param[in] PID:Pid or Id
* typeAction:
* 0 : make parity
* 1 : check parity
* \return none
*/
uint8_t Lin_PidParity(uint8_t PID, uint8_t typeAction)
{
uint8_t parity;
uint8_t retVal;
parity = (uint8_t)(((0xFFU & (GETBIT(PID, 0U) ^ GETBIT(PID, 1U) ^ GETBIT(PID, 2U) ^ GETBIT(PID, 4U))) << 6U) |
((0xFFU ^ (GETBIT(PID, 1U) ^ GETBIT(PID, 3U) ^ GETBIT(PID, 4U) ^ GETBIT(PID, 5U))) << 7U));
/* Check if action is checking parity bits */
if (CHECK_PARITY == typeAction)
{
/* If parity bits are incorrect */
if ((PID & 0xC0U) != parity)
{
/* Return 0xFF if parity bits are incorrect */
retVal = 0xFFU;
}
/* If parity bits are correct */
else
{
/* Return ID if parity bits are correct */
retVal = (uint8_t)(PID & 0x3FU);
}
}
/* If action is making parity bits */
else
{
/* Return PID in case of making parity bits */
retVal = (uint8_t)(PID | parity);
}
return retVal;
}
/*! \brief get lin frame index.
* \param[in] frameId: lin frame identifier
* \return frame index
*/
uint8_t Lin_GetFrameIndex(uint8_t frameId)
{
uint8_t i = 0;
uint8_t retVal = 0xFF;
for(i = 0; i < LIN_FRAME_NUM; i++)
{
if(frameId == linFrameInfoTab[i].frameId)
{
retVal = i;
break;
}
}
return retVal;
}
/*! \brief The lin data checksum function.
* \param[in] CheckSumType:
* 0: standard checksum
* 1: enhanced checksum
* pid: frame pid
* pData: pointer to the data of Lin_FrameType
* dataLen: data length
* \return none
*/
uint8_t Lin_CalculateChecksum(Lin_CheckSumType checkSumType, const uint8_t frameId, const uint8_t* pData, uint8_t dataLen)
{
uint16_t tCheckSum = 0;
uint8_t i = 0;
if ((checkSumType == LINSTACK_CHECKSUM_ENHANCED) && \
(frameId != LIN_ID_DIAG_MASTER_REQ) && (frameId != LIN_ID_DIAG_SLAVE_RESP))
{
tCheckSum = Lin_PidParity(frameId, MAKE_PARITY);
}
for (i = 0; i < dataLen; i++)
{
tCheckSum += pData[i];
tCheckSum = tCheckSum > 0xFF ? ((tCheckSum + 1) & 0x00FF) : tCheckSum;
}
tCheckSum = ~tCheckSum;
return (uint8_t)(tCheckSum & 0xFF);
}
/*! \brief set lin response data.
* \param[in] pFrameInfoFromTab: point to the data will be send
* pFrame: point to send structure
* \return none
*/
void lin_SetResponse(Lin_FrameInfoType *pFrameInfoFromTab, Lin_FrameDataType *pFrame)
{
uint8_t i = 0;
for(i = 0; i < pFrameInfoFromTab->frameLen; i++)
{
if(0 != (pFrameInfoFromTab->updatingFlag & (1 << i)))
{
pFrame->data[i] = linFrameDataBackup[i];
}
else
{
pFrame->data[i] = pFrameInfoFromTab->pFrameData[i];
}
}
pFrame->checkSum = Lin_CalculateChecksum(LINSTACK_CHECKSUM_ENHANCED, pFrameInfoFromTab->frameId, &pFrame->data[0], pFrameInfoFromTab->frameLen);
}
/*! \brief The uart0 for lin send request function.
* \param[in] none
* \return none
*/
void LinMastertxIsrRequest(void)
{
if (linState == LIN_STATE_IDLE)
{
UartDrv_SetInterruptReq(&mcu.uartDrv0, UARTDRV_ISR_SRC_TX_SYNC_BREAK, true);
linComTimeoutCnt = linMaxHeaderTimeout + linMaxFrameResTimeout;
linState = LIN_STATE_BREAK;
UartDrv_SendLinBreakField(&mcu.uartDrv0);
}
}
/*! \brief The uart0 for lin send interrupt handling function.
* \param[in] none
* \return none
*/
void LinMasterTxIsrRoutine(void)
{
if (UartDrv_GetStatus(&mcu.uartDrv0, UARTDRV_STATUS_SBRKD))
{
/* The break signal has been transmitted successfully */
UartDrv_ClearStatus(&mcu.uartDrv0, UARTDRV_STATUS_SBRKD);
linTxDataCnt = 0;
/* send the sync-header(0x55) */
linState = LIN_STATE_SYNC_HEDADER;
UartDrv_TxData(&mcu.uartDrv0, LIN_SYNC_HEADER);
}
}
/*! \brief The uart0 for lin receive interrupt handling function.
* \param[in] none
* \return none
*/
void LinMasterRxIsrRoutine(void)
{
uint8_t i = 0;
uint8_t rcvData = 0;
uint8_t rcvCheckSum = 0;
uint8_t clcCheckSum = 0;
uint8_t pid = 0;
uint8_t frameId = 0;
uint8_t txFreeCnt = 0;
uint8_t rxCnt = 0;
if (UartDrv_GetStatus(&mcu.uartDrv0, UARTDRV_STATUS_RDRF))
{
if (UartDrv_IsInterruptEnabled(&mcu.uartDrv0, UARTDRV_ISR_SRC_RX_FULL) == true)
{
switch(linState)
{
case LIN_STATE_SYNC_HEDADER: /* wait to receive lin sync header */
rcvData = (uint8_t)(UartDrv_RxData(&mcu.uartDrv0) & 0xFF);
/* Check the sync header */
if (rcvData == LIN_SYNC_HEADER)
{
pid = Lin_PidParity(linFrameInfoTab[gCurFrameIdx].frameId, MAKE_PARITY);
UartDrv_TxData(&mcu.uartDrv0, pid);
linState = LIN_STATE_PID;
}
else
{
linState = LIN_STATE_IDLE;
}
break;
case LIN_STATE_PID: /* wait to receive lin pid */
rcvData = (uint8_t)(UartDrv_RxData(&mcu.uartDrv0) & 0xFF);
frameId = Lin_PidParity(rcvData, CHECK_PARITY);
if(frameId != linFrameInfoTab[gCurFrameIdx].frameId)
{
linState = LIN_STATE_IDLE;
break;
}
if(LIN_RES_PUB == linFrameInfoTab[gCurFrameIdx].resType)
{
lin_SetResponse(&linFrameInfoTab[gCurFrameIdx], &linTxData);
linState = LIN_STATE_TX_DATA;
linTxDataCnt = 0;
txFreeCnt = 4u - UartDrv_GetTxCounter(&mcu.uartDrv0);
for(i = 0; i < txFreeCnt; i++)
{
UartDrv_TxData(&mcu.uartDrv0, linTxData.data[linTxDataCnt]);
linTxDataCnt++;
if(linTxDataCnt >= linFrameInfoTab[gCurFrameIdx].frameLen)
{
UartDrv_TxData(&mcu.uartDrv0, linTxData.checkSum);
linState = LIN_STATE_CHECKSUM;
break;
}
}
}
else if(LIN_RES_SUB == linFrameInfoTab[gCurFrameIdx].resType)
{
linRxDataCnt = 0;
linState = LIN_STATE_RX_DATA;
}
else
{
linState = LIN_STATE_IDLE;
}
break;
case LIN_STATE_TX_DATA:
rxCnt = UartDrv_GetRxCounter(&mcu.uartDrv0);
for(i = 0; i < rxCnt; i++)
{
(uint8_t)(UartDrv_RxData(&mcu.uartDrv0) & 0xFF);
}
txFreeCnt = 4u - UartDrv_GetTxCounter(&mcu.uartDrv0);
for(i = 0; i < txFreeCnt; i++)
{
if(linTxDataCnt >= linFrameInfoTab[gCurFrameIdx].frameLen)
{
UartDrv_TxData(&mcu.uartDrv0, linTxData.checkSum);
linState = LIN_STATE_CHECKSUM;
break;
}
else
{
UartDrv_TxData(&mcu.uartDrv0, linTxData.data[linTxDataCnt]);
linTxDataCnt++;
}
}
break;
case LIN_STATE_RX_DATA:
rxCnt = UartDrv_GetRxCounter(&mcu.uartDrv0);
for(i = 0; i < rxCnt; i++)
{
rcvData = (uint8_t)(UartDrv_RxData(&mcu.uartDrv0) & 0xFF);
linRxData.data[linRxDataCnt] = rcvData;
linRxDataCnt++;
if(linRxDataCnt >= linFrameInfoTab[gCurFrameIdx].frameLen)
{
linState = LIN_STATE_CHECKSUM;
break;
}
}
break;
case LIN_STATE_CHECKSUM: /* wait to receive lin checksum */
rcvCheckSum = (uint8_t)(UartDrv_RxData(&mcu.uartDrv0) & 0xFF);
if(LIN_RES_SUB == linFrameInfoTab[gCurFrameIdx].resType)
{
clcCheckSum = Lin_CalculateChecksum(LINSTACK_CHECKSUM_ENHANCED, linFrameInfoTab[gCurFrameIdx].frameId, &linRxData.data[0], linRxDataCnt);
if (clcCheckSum == rcvCheckSum)
{
memcpy(linFrameInfoTab[gCurFrameIdx].pFrameData, &linRxData.data[0], linRxDataCnt);
}
}
linState = LIN_STATE_IDLE;
break;
default:
UartDrv_ClearRxFifo(&mcu.uartDrv0);
break;
}
}
}
if(linState == LIN_STATE_IDLE)
{
UartDrv_EnableLineBreakDetect(&mcu.uartDrv0, true);
}
}
/*! \brief This is a part of SysTick Interrupt Handler for lin timeout check.
* \param[in] none
* \return none
*/
void Lin_TimeoutService(void)
{
switch(linState)
{
case LIN_STATE_BREAK:
case LIN_STATE_SYNC_HEDADER:
case LIN_STATE_PID:
case LIN_STATE_TX_DATA:
case LIN_STATE_RX_DATA:
case LIN_STATE_CHECKSUM:
linComTimeoutCnt--;
if(0 == linComTimeoutCnt)
{
linState = LIN_STATE_IDLE;
UartDrv_EnableLineBreakDetect(&mcu.uartDrv0, true);
linComTimeoutCnt = linMaxFrameResTimeout;
}
break;
default:
break;
}
}
/*! \brief The uart0 lin master init function.
* \param[in] none
* \return none
*/
void Uart0_LinMaster_Init(void)
{
UartDrv_InitCfgType uartInitCfg;
/* PORT and pins as ALT4 (UART tx rx) */
PinsDrv_SetMuxModeSel(&mcu.ptc, 2, PINSDRV_MUX_ALT4); /* Uart rx */
PinsDrv_SetMuxModeSel(&mcu.ptc, 3, PINSDRV_MUX_ALT4); /* Uart tx */
PinsDrv_SetMuxModeSel(&mcu.ptc, 13, PINSDRV_MUX_AS_GPIO); /* LIN module control */
PinsDrv_SetPinDirection(&mcu.ptc, 13, 1); /* set to output */
PinsDrv_WritePin(&mcu.ptc, 13, 1); /* set to high to active lin transceiver */
/* Configure uart module */
UartDrv_GetDefaultConfig(&uartInitCfg);
uartInitCfg.basicParameters.baudRate = LIN_BAUD_RATE;
uartInitCfg.extendFeatures.cosplayer = UARTDRV_COSPLAY_LIN;
ClockDrv_GetFreq(&mcu.clockDrv, CLOCKDRV_UART0, &uartInitCfg.basicParameters.busClockFreq);
/* Set the configuration */
UartDrv_SetConfig(&mcu.uartDrv0, &uartInitCfg);
UartDrv_SetRxWater(&mcu.uartDrv0, 0);
UartDrv_SetRxWater(&mcu.uartDrv0, 0);
UartDrv_SetInterruptReq(&mcu.uartDrv0, UARTDRV_ISR_SRC_TX_SYNC_BREAK, true);
UartDrv_SetInterruptReq(&mcu.uartDrv0, UARTDRV_ISR_SRC_RX_FULL, true);
/* Enable all the uart0 interrupts in the NVIC interrupt controller */
IrqDrv_EnableIrq(UART0_RxTx_IRQn);
linMaxHeaderTimeout = Lin_CalcMaxHeaderTimeoutCnt(LIN_BAUD_RATE);
linMaxFrameResTimeout = Lin_CalcMaxResTimeoutCnt(LIN_BAUD_RATE, 8);
linComTimeoutCnt = linMaxHeaderTimeout + linMaxFrameResTimeout;
linState = LIN_STATE_IDLE;
}
void LIN_UpdateTxData(uint8_t frameid,uint8_t dataid,uint8_t data)
{
linFrameDataBackup[dataid] = linFrameInfoTab[frameid].pFrameData[dataid];
linFrameInfoTab[frameid].updatingFlag |= (0x01 << dataid);
linFrameInfoTab[frameid].pFrameData[dataid] = data;
linFrameInfoTab[frameid].updatingFlag &= ~(0x01 << dataid);
}
void LIN_Master_task(void)
{
//LIN_UpdateTxData()
/* request send LIN data */
LinMastertxIsrRequest();
/*
gCurFrameIdx++;
if(gCurFrameIdx >= LIN_FRAME_NUM)
{
gCurFrameIdx = 0;
}
*/
}
/*! \brief The uart0 interrupt handling function.
* \param[in] none
* \return none
*/
void UART0_RxTx_Handler(void)
{
LinMasterTxIsrRoutine();
LinMasterRxIsrRoutine();
}

View File

@ -0,0 +1,37 @@
#ifndef __LIN_MASTER_H__
#define __LIN_MASTER_H__
/*******************************************************************************
* the includes
******************************************************************************/
#include "Mcu.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
void Lin_TimeoutService(void);
void Uart0_LinMaster_Init(void);
void LIN_Master_task(void);
void LIN_UpdateTxData(uint8_t frameid,uint8_t dataid,uint8_t data);
#endif

View File

@ -0,0 +1,291 @@
/*******************************************************************************
* the includes
******************************************************************************/
#include "SeatMassage.h"
#include "LIN_Master.h"
#include "scm_canmatrix-binutil.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
typedef struct
{
// Solenoid Valve 电磁阀
uint8_t SV1:1;
uint8_t SV2:1;
uint8_t SV3:1;
uint8_t SV4:1;
uint8_t SV5:1;
uint8_t SV6:1;
uint8_t SV7:1;
uint8_t SV8:1;
uint8_t SV9:1;
uint8_t SV10:1;
uint8_t SV11:1;
uint8_t SV12:1;
uint8_t SV13:1;
uint8_t SV14:1;
uint8_t AP:1;
uint8_t V2_12V:1;
}SM_CTRL_Type;
typedef union
{
uint8_t rawdata[2];
SM_CTRL_Type msg;
}SM_CTRL_Data_Type;
typedef enum
{
SM_INIT,
SM_OFF,
SM_RUN1,
SM_RUN2,
SM_RUN3,
SM_STATE_NUM
}SM_state_Type;
/*******************************************************************************
* the globals
******************************************************************************/
SM_CTRL_Data_Type SM_CTRL_data;
static SM_state_Type SM_state,SM_last_state;
/*******************************************************************************
* the const
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
static void UpdateLinMsg(SM_CTRL_Data_Type* data)
{
LIN_UpdateTxData(0,0,data->rawdata[0]);
LIN_UpdateTxData(0,1,data->rawdata[1]);
}
static void SM_OFF_task(void)
{
SM_CTRL_data.rawdata[0] = 0;
SM_CTRL_data.rawdata[1] = 0;
UpdateLinMsg(&SM_CTRL_data);
SM_last_state=SM_state;
}
static void SM_RUN1_task(void)//50ms
{
static uint16_t run_counter;
static uint8_t runstate;
if(SM_last_state!=SM_state)
{
runstate = 0;
run_counter = 0;
SM_last_state=SM_state;
}
switch (runstate)
{
case 0:
SM_CTRL_data.rawdata[0] = 0x01;
SM_CTRL_data.rawdata[1] = 0x00;
run_counter++;
if (run_counter > 60)
{
run_counter = 0;
runstate++;
}
break;
case 1:
SM_CTRL_data.rawdata[0] = 0x02;
SM_CTRL_data.rawdata[1] = 0x00;
run_counter++;
if (run_counter > 60)
{
run_counter = 0;
runstate++;
}
break;
case 2:
SM_CTRL_data.rawdata[0] = 0x04;
SM_CTRL_data.rawdata[1] = 0x00;
run_counter++;
if (run_counter > 60)
{
run_counter = 0;
runstate++;
}
break;
case 3:
SM_CTRL_data.rawdata[0] = 0x08;
SM_CTRL_data.rawdata[1] = 0x00;
run_counter++;
if (run_counter > 60)
{
run_counter = 0;
runstate++;
}
break;
case 4:
SM_CTRL_data.rawdata[0] = 0x10;
SM_CTRL_data.rawdata[1] = 0x00;
run_counter++;
if (run_counter > 60)
{
run_counter = 0;
runstate++;
}
break;
case 5:
SM_CTRL_data.rawdata[0] = 0x20;
SM_CTRL_data.rawdata[1] = 0x00;
run_counter++;
if (run_counter > 60)
{
run_counter = 0;
runstate++;
}
break;
case 6:
SM_CTRL_data.rawdata[0] = 0x40;
SM_CTRL_data.rawdata[1] = 0x00;
run_counter++;
if (run_counter > 60)
{
run_counter = 0;
runstate++;
}
break;
case 7:
SM_CTRL_data.rawdata[0] = 0x80;
SM_CTRL_data.rawdata[1] = 0x00;
run_counter++;
if (run_counter > 60)
{
run_counter = 0;
runstate++;
}
break;
case 8:
SM_CTRL_data.rawdata[0] = 0x00;
SM_CTRL_data.rawdata[1] = 0x01;
run_counter++;
if (run_counter > 60)
{
run_counter = 0;
runstate++;
}
break;
case 9:
SM_CTRL_data.rawdata[0] = 0x00;
SM_CTRL_data.rawdata[1] = 0x02;
run_counter++;
if (run_counter > 60)
{
run_counter = 0;
runstate++;
}
break;
default:
runstate = 0;
break;
}
SM_CTRL_data.msg.V2_12V = 1;
SM_CTRL_data.msg.AP = 1;
UpdateLinMsg(&SM_CTRL_data);
}
static void SM_RUN2_task(void)
{
static uint16_t run_counter;
static uint8_t runstate;
SM_CTRL_data.msg.V2_12V = 1;
SM_CTRL_data.msg.AP = 1;
UpdateLinMsg(&SM_CTRL_data);
}
static void SM_RUN3_task(void)
{
static uint16_t run_counter;
static uint8_t runstate;
SM_CTRL_data.msg.V2_12V = 1;
SM_CTRL_data.msg.AP = 1;
UpdateLinMsg(&SM_CTRL_data);
}
void SeatMassage_Init(void)
{
SM_CTRL_data.msg.SV1 = 1;
SM_CTRL_data.msg.AP = 1;
UpdateLinMsg(&SM_CTRL_data);
}
void SeatMassage_task(void)
{
switch (SM_state)
{
case SM_INIT:
SM_state = SM_OFF;
break;
case SM_OFF:
SM_OFF_task();
break;
case SM_RUN1:
SM_RUN1_task();
break;
case SM_RUN2:
SM_RUN2_task();
break;
case SM_RUN3:
SM_RUN3_task();
break;
default:
SM_state = SM_OFF;
break;
}
if (SM_state > SM_INIT && SM_state < SM_STATE_NUM)
{
scm_canmatrix_tx.SCM_STATE.ZY_MSSG_STATE = SM_state-1;
}
else
{
scm_canmatrix_tx.SCM_STATE.ZY_MSSG_STATE = 0;
}
}
void SeatMassage_ReqRun(uint8_t state)
{
if (state < 3)
{
SM_state = SM_RUN1 + state;
}
}
void SeatMassage_ReqOFF(void)
{
SM_state = SM_OFF;
}
void SeatMassage_ReqNext(void)
{
if (SM_state == SM_OFF)
{
SM_state = SM_RUN1;
}
else
{
SM_state = SM_OFF;
}
}

View File

@ -0,0 +1,37 @@
#ifndef __SEATMASSAGE_H__
#define __SEATMASSAGE_H__
/*******************************************************************************
* the includes
******************************************************************************/
#include "Mcu.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
void SeatMassage_Init(void);
void SeatMassage_ReqOFF(void);
void SeatMassage_ReqRun(uint8_t state);
void SeatMassage_task(void);
void SeatMassage_ReqNext(void);
#endif

View File

@ -14,6 +14,8 @@
#include "scm_canmatrix-binutil.h"
#include "FanHeat.h"
#include "MemoryTask.h"
#include "LIN_Master.h"
#include "SeatMassage.h"
/*******************************************************************************
* the defines
******************************************************************************/
@ -74,7 +76,27 @@ void SysTick_Handler(void)
gSystick1msEvent++;
timer_1ms++;
Uds_Tick(&udsObj);
Lin_TimeoutService();
}
void PowerOnTask(void)
{
static uint16_t powerOnCnt=0;
static uint8_t flagSBCInitClr=0;
if (powerOnCnt <= 20)
{
powerOnCnt++;
}
if (powerOnCnt > 20 && flagSBCInitClr ==0)
{
flagSBCInitClr = 1;
SBC_Write_Reg(SBC_SYS_STATUS_CTRL_0, 0, NULL);
}
}
void appTask(void)
{
if(gSystick1msEvent > 0u)
@ -99,6 +121,7 @@ void appTask(void)
if (gSystick1msCnt % 10 == 0)
{
LIN_Master_task();
MotorCtrl_Maintask();
FanHeatMainTaks();
}
@ -106,7 +129,9 @@ void appTask(void)
if (gSystick1msCnt % 50 == 0)
{
SBC_WD_Trigger();
WdgDrv_Refresh(&mcu.wdgDrv);
PowerOnTask();
SeatMassage_task();
}
if(gSystick1msCnt % 1000 == 0)
@ -136,6 +161,8 @@ void appTaskInit(void)
FanHeatInit();
MemoryTaskInit();
SeatMassage_Init();
}

View File

@ -19,6 +19,7 @@ typedef enum
UDS_MSG_IDX_STD_ECU_DEBUG2,
UDS_MSG_IDX_STD_ECU_DEBUG3,
UDS_MSG_IDX_STD_ECU_DEBUG4,
UDS_MSG_IDX_STD_TX_TEST,
UDS_MSG_IDX_NUM
} Uds_MsgIdIdxType;
@ -139,6 +140,7 @@ const FlexCanDrv_MsgCfgType msgCfgObj[UDS_MSG_IDX_NUM] = {
{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 */
{UDS_MSG_IDX_STD_TX_TEST ,1, 0x222 ,false, FLEXCANDRV_MSGTYPE_TX, DLC_BYTE_8, false, false, 0xFFFFFFFF}, /* CAN_MSGOBJ_STD_TX */
};
@ -226,6 +228,18 @@ void MsgTask(UdsType *obj)//1ms task
}
/************************************* CAN *****************************************/
static uint8_t testdata[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
void TxTestMsg (uint8_t * data)
{
if (data != NULL)
{
for (uint8_t i = 0; i < 8; i++)
{
testdata[i] = data[i];
}
}
FlexCanBoot_TxMessage(0x222,testdata,8);
}
int8_t FlexCanBoot_TxMessage(uint32_t msgId, const uint8_t* pData, uint8_t size)
{
FlexCanDrv_MsgObjType txMsgObj;

View File

@ -45,6 +45,7 @@ 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);
void TxTestMsg (uint8_t * data);
void GetRxMsgData(uint16_t msgId, uint8_t* pData, uint8_t Size);
void SetTxMsgData(uint16_t msgId, uint8_t* pData, uint8_t Size);

View File

@ -33,7 +33,8 @@ typedef struct
uint8_t appBuildTime[12];
uint8_t appBuildDate[16];
uint8_t appSW_VERSION[16];
uint8_t reverse[16];
uint8_t appSW_Debug;
uint8_t reverse[15];
} app_CfgInfoType;//64 byte
/*******************************************************************************
@ -51,6 +52,7 @@ __root const app_CfgInfoType app_info = {
.appBuildTime = __TIME__,//0x00010404
.appBuildDate = __DATE__,//0x00010410
.appSW_VERSION = "SW0101_20241220",
.appSW_Debug = 0xff,//0x55为量产模式其它为debug模式
};
@ -99,4 +101,6 @@ void extHardwareReset(void)
void extSortwareReset(void)
{
ResetDrv_SoftwareResetModule(&mcu.resetDrv,RESETDRV_SWRESET_SYS);
}

View File

@ -7,7 +7,7 @@
#include "string.h"
#include "irq_drv.h"
#include "canuser.h"
#include "LIN_Master.h"
/*******************************************************************************
* the defines
@ -112,6 +112,11 @@ static void hw_clock_init()
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_DMA, &clockConfig);
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_PWMLITE0, &clockConfig);
/* SOSC_DIV2 For Uart2 module clock source */
clockConfig.gating = true;
clockConfig.source = CLOCKDRV_SOSC_DIV2;
ClockDrv_ConfigureClock(&mcu.clockDrv, CLOCKDRV_UART0, &clockConfig);
}
@ -276,11 +281,33 @@ static void PWM_Init(void)
/* Enable PWM Module */
PwmLiteDrv_EnableModule(&mcu.pwmLiteDrv0);
}
static void Watchdog_Init(void)
{
/* Refresh wdg */
WdgDrv_Refresh(&mcu.wdgDrv);
/* Initialize WDG drivers */
WdgDrv_ConfigureType wdgConfigParams;
WdgDrv_GetDefaultConfig(&wdgConfigParams);
wdgConfigParams.clkSource = WDGDRV_CLK_SRC_LPO128K;
wdgConfigParams.winEnable = false;
wdgConfigParams.prescalerEnable = false;
wdgConfigParams.enable = true;
wdgConfigParams.intEnable = false;
wdgConfigParams.updateEnable = true;
wdgConfigParams.stopModeEnable = false;
wdgConfigParams.timeoutValue = 12800;
wdgConfigParams.windowValue = 1000;
WdgDrv_Configure(&mcu.wdgDrv, &wdgConfigParams);
//NVIC_EnableIRQ(WDOG_IRQn);
}
void hw_init(void)
{
uint32_t gCpuClockFrequency = 0;
Watchdog_Init();
hw_clock_init();
SEGGER_RTT_printf(0,"-----SPI_INIT-----\n");
@ -300,6 +327,9 @@ void hw_init(void)
ADC_Init();
PWM_Init();
Uart0_LinMaster_Init();
SEGGER_RTT_printf(0,"-----InitFinished-----\n");
}

View File

@ -2,6 +2,7 @@
#include "key.h"
#include "scm_canmatrix-binutil.h"
#include "MotorCtrl.h"
#include "SeatMassage.h"
static uint8_t GetSigState(KEY_ID_type key_id);
@ -127,6 +128,8 @@ static uint8_t GetSigState(KEY_ID_type key_id)
return scm_canmatrix_rx.Panel_Key.KEY_MEMORY_3;
case KEY_RESET:
return scm_canmatrix_rx.Panel_Key.KEY_RESET;
case KEY_SM:
return scm_canmatrix_rx.Panel_Key.KEY_ZY_MSSG;
default:
return 0;
}
@ -260,6 +263,12 @@ void KeyProTask(void)//5ms
{
StartAutoCal();
}
if (getKeyPressFlag(KEY_SM) == KEY_PRESSED)
{
SeatMassage_ReqNext();
}
}

View File

@ -26,6 +26,7 @@ typedef enum
KEY_MEMORY_2,
KEY_MEMORY_3,
KEY_RESET,
KEY_SM,//seat massage
KEY_NUM,
}KEY_ID_type;

View File

@ -60,7 +60,7 @@ McuType mcu;
//uint8_t testdata[8] = {0};
int main(void)
{
@ -72,10 +72,12 @@ int main(void)
SEGGER_RTT_Init();
hw_init();
IrqDrv_EnableGlobalInterrupt();
TxTestMsg(NULL);
appTaskInit();
IrqDrv_EnableGlobalInterrupt();
SBC_WD_Trigger();
SEGGER_RTT_printf(0,"-----init success-----\n");
while(1)
{