Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
V
VC66_7C
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ISUZU
VC66_7C
Commits
e81147a3
Commit
e81147a3
authored
Mar 07, 2022
by
hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整K-LINE调用
parent
3763c3c0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
218 additions
and
199 deletions
+218
-199
kwp2000_service.c
source/Application/K_BUS/kwp2000_service.c
+7
-3
TimerB.c
source/Driver/Timer/TimerB.c
+197
-196
sys_scheduler.c
source/System/sys_scheduler.c
+14
-0
No files found.
source/Application/K_BUS/kwp2000_service.c
View file @
e81147a3
...
...
@@ -43,6 +43,9 @@ unsigned char DTCstatusCHGFFK_Line;
unsigned
char
AccessMode2701KeyTimeFlag
;
unsigned
char
AccessMode2701KeyTime
;
unsigned
long
EOLSeedRandomNumber
=
0x6879716169716872ul
;
/*
*********************************************************************
* function
...
...
@@ -1124,9 +1127,10 @@ unsigned char kwp_readDataAccessMode(unsigned char *TxData, unsigned char *Reque
if
(
0
)
{
/*密钥随机数生成*/
// SeedKey = (unsigned long)RealTimeClock.RollingCounter;
// SeedKey = SeedKey << 16;
// SeedKey |= (unsigned long)(~RealTimeClock.RollingCounter);
EOLSeedRandomNumber
=
EOLSeedRandomNumber
*
1024
+
520
;
SeedKey
=
(
unsigned
long
)
EOLSeedRandomNumber
;
SeedKey
=
SeedKey
<<
16
;
SeedKey
|=
(
unsigned
long
)(
~
EOLSeedRandomNumber
);
Seed1
=
(
unsigned
char
)(
SeedKey
>>
24
);
Seed2
=
(
unsigned
char
)(
SeedKey
>>
16
);
...
...
source/Driver/Timer/TimerB.c
View file @
e81147a3
...
...
@@ -467,19 +467,19 @@
#endif
static
const
uint32_t
u32TimerBClockArray
[
12U
]
=
{
TIMERB_0_CK0
,
TIMERB_0_CK1
,
TIMERB_0_CK2
,
TIMERB_0_CK3
,
TIMERB_1_CK0
,
TIMERB_1_CK1
,
TIMERB_1_CK2
,
TIMERB_1_CK3
,
TIMERB_2_CK0
,
TIMERB_2_CK1
,
TIMERB_2_CK2
,
TIMERB_2_CK3
,
{
TIMERB_0_CK0
,
TIMERB_0_CK1
,
TIMERB_0_CK2
,
TIMERB_0_CK3
,
TIMERB_1_CK0
,
TIMERB_1_CK1
,
TIMERB_1_CK2
,
TIMERB_1_CK3
,
TIMERB_2_CK0
,
TIMERB_2_CK1
,
TIMERB_2_CK2
,
TIMERB_2_CK3
,
};
/*-------------------------------------------------------*/
...
...
@@ -564,7 +564,8 @@ void TimerB_PWM_Init(void)
do
{
u16TimeCount
++
;
}
while
(((
TAUB0TE
)
||
(
TAUB1TE
)
||
(
TAUB2TE
))
&&
(
u16TimeCount
<
TIMERB_TIMEROUT_MAX
));
}
while
(((
TAUB0TE
)
||
(
TAUB1TE
)
||
(
TAUB2TE
))
&&
(
u16TimeCount
<
TIMERB_TIMEROUT_MAX
));
if
(
u16TimeCount
<
TIMERB_TIMEROUT_MAX
)
{
/*CLK0~3 =PCLK */
...
...
@@ -576,30 +577,30 @@ void TimerB_PWM_Init(void)
TimerB_BackLight_Demo_Init
();
TimerB_VehFreOut_Init
();
TimerB_EngFreOut_Init
();
//TimerB_Input_Channel_Init(TIMERB_0_CH2, TIMERB_CLOCK_3, TIMERB_RISING); //车速输入捕获
//TimerB_Input_Channel_Start(TIMERB_0_CH2);
}
static
void
TimerB_PWM_Master_Channel_Init
(
TIMERB_Channel_en_t
enTimerBChannel
,
TIMERB_Clock_en_t
enTimerBClock
)
{
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16ClockSelectRe
=
(
0x801U
|
(
enTimerBClock
<<
14U
));
uint16_t
u16TimerBbit
=
(
1U
<<
u8TimerBChannel
);
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16ClockSelectRe
=
(
0x801U
|
(
enTimerBClock
<<
14U
));
uint16_t
u16TimerBbit
=
(
1U
<<
u8TimerBChannel
);
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
0U
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
0U
;
/*control*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X200U
+
(
4U
*
u8TimerBChannel
);
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)
=
u16ClockSelectRe
;
/*TAUB0CMOR2 = u16ClockSelectRe;*/
/*control*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X200U
+
(
4U
*
u8TimerBChannel
);
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)
=
u16ClockSelectRe
;
/*TAUB0CMOR2 = u16ClockSelectRe;*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0XC0U
+
(
4U
*
u8TimerBChannel
);
*
((
uint8_t
*
)
u32TimerBRegAddrChannel
)
=
0U
;
/*TAUB0CMUR2 = 0U;*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0XC0U
+
(
4U
*
u8TimerBChannel
);
*
((
uint8_t
*
)
u32TimerBRegAddrChannel
)
=
0U
;
/*TAUB0CMUR2 = 0U;*/
/*output mode*/
/*output mode*/
/*Simultaneous rewrite */
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X260U
;
...
...
@@ -688,20 +689,20 @@ static void TimerB_PWM_Slave_Channel_Init(TIMERB_Channel_en_t enTimerBChannel, T
}
/* 返回初始化状态。1:成功。0:失败
输出要设置的通道,通道选择的时钟源,通道有效时输出的极性*/
输出要设置的通道,通道选择的时钟源,通道有效时输出的极性*/
uint8_t
TimerB_PWM_Channel_Init
(
TIMERB_Channel_en_t
enTimerBChannel
,
TIMERB_Clock_en_t
enTimerBClock
,
TIMERB_Polarity_en_t
enTimerBPolarity
)
{
uint8_t
u8TimerBResult
=
0U
;
uint8_t
u8TimerBResult
=
0U
;
if
((
enTimerBChannel
%
2U
))
{
u8TimerBResult
=
1U
;
TimerB_PWM_Master_Channel_Init
(
enTimerBChannel
-
TIMERB_CHANNEL_INTERVAL
,
enTimerBClock
);
TimerB_PWM_Slave_Channel_Init
(
enTimerBChannel
,
enTimerBClock
,
enTimerBPolarity
);
}
if
((
enTimerBChannel
%
2U
))
{
u8TimerBResult
=
1U
;
TimerB_PWM_Master_Channel_Init
(
enTimerBChannel
-
TIMERB_CHANNEL_INTERVAL
,
enTimerBClock
);
TimerB_PWM_Slave_Channel_Init
(
enTimerBChannel
,
enTimerBClock
,
enTimerBPolarity
);
}
return
u8TimerBResult
;
return
u8TimerBResult
;
}
/* 返回实际设置成功的频率,如果返回0表示错误。
...
...
@@ -710,123 +711,123 @@ uint8_t TimerB_PWM_Channel_Init(TIMERB_Channel_en_t enTimerBChannel, TIMERB_Cloc
uint32_t
TimerB_PWM_Channel_Fre_Set
(
TIMERB_Channel_en_t
enTimerBChannel
,
uint16_t
u16Fre
,
uint16_t
u16Duty
)
{
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16TimerBbit
=
(
1U
<<
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
))
*
TIMERB_CHANNEL_BIT_MUL
;
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16TimerBbit
=
(
1U
<<
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
))
*
TIMERB_CHANNEL_BIT_MUL
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X200U
+
(
4U
*
u8TimerBChannel
);
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X200U
+
(
4U
*
u8TimerBChannel
);
uint8_t
u8TimerBClockSel
=
(
uint8_t
)(((
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)))
>>
14U
);
uint8_t
u8TimerBClockIndex
=
u8TimerBIndex
*
4U
+
u8TimerBClockSel
;
uint32_t
u32TimerBClockFre
=
u32TimerBClockArray
[
u8TimerBClockIndex
];
uint32_t
u32CalBuf
=
(
u32TimerBClockFre
/
u16Fre
);
uint32_t
u32CalFre
=
0U
;
uint32_t
u32Duty
=
u16Duty
;
if
(
enTimerBChannel
%
2U
)
{
u32CalFre
=
(
u32TimerBClockFre
/
u32CalBuf
);
uint8_t
u8TimerBClockSel
=
(
uint8_t
)(((
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)))
>>
14U
);
uint8_t
u8TimerBClockIndex
=
u8TimerBIndex
*
4U
+
u8TimerBClockSel
;
uint32_t
u32TimerBClockFre
=
u32TimerBClockArray
[
u8TimerBClockIndex
];
uint32_t
u32CalBuf
=
(
u32TimerBClockFre
/
u16Fre
);
uint32_t
u32CalFre
=
0U
;
uint32_t
u32Duty
=
u16Duty
;
if
(
enTimerBChannel
%
2U
)
{
u32CalFre
=
(
u32TimerBClockFre
/
u32CalBuf
);
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
(
4U
*
(
u8TimerBChannel
));
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
(
4U
*
(
u8TimerBChannel
));
(
*
((
uint16_t
*
)(
u32TimerBRegAddrChannel
-
4U
*
TIMERB_CHANNEL_INTERVAL
)))
=
u32CalBuf
-
1U
;
/*TAUB0CDR2 = u32CalBuf - 1U; // fre*/
(
*
((
uint16_t
*
)(
u32TimerBRegAddrChannel
-
4U
*
TIMERB_CHANNEL_INTERVAL
)))
=
u32CalBuf
-
1U
;
/*TAUB0CDR2 = u32CalBuf - 1U; // fre*/
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
(
u32Duty
*
u32CalBuf
/
1000U
);
/*TAUB0CDR3 = (u32Duty * u32CalBuf / 100000U); // duty*/
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
(
u32Duty
*
u32CalBuf
/
1000U
);
/*TAUB0CDR3 = (u32Duty * u32CalBuf / 100000U); // duty*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X44U
;
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
u16TimerBbit
;
/*TAUB0RDT = (u16TimerBbit);*/
}
return
u32CalFre
;
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X44U
;
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
u16TimerBbit
;
/*TAUB0RDT = (u16TimerBbit);*/
}
return
u32CalFre
;
}
/*占空比精度千分之一*/
void
TimerB_PWM_Channel_Duty_Set
(
TIMERB_Channel_en_t
enTimerBChannel
,
uint16_t
u16Duty
)
{
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16TimerBbit
=
(
1U
<<
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
))
*
TIMERB_CHANNEL_BIT_MUL
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
(
4U
*
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
));
uint32_t
u32CalBuf
=
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
+
1U
;
/*
uint32_t u32CalBuf = TAUB0CDR2 + 1U;*/
uint32_t
u32Duty
=
u16Duty
;
if
(
enTimerBChannel
%
2U
)
{
(
*
((
uint16_t
*
)(
u32TimerBRegAddrChannel
+
4U
*
TIMERB_CHANNEL_INTERVAL
)))
=
(
u32CalBuf
*
u32Duty
/
1000U
);
/*TAUB0CDR3 = (u32CalBuf * u32Duty / 100U); */
/*duty*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X44U
;
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
u16TimerBbit
;
/*TAUB0RDT = (u16TimerBbit);*/
}
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16TimerBbit
=
(
1U
<<
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
))
*
TIMERB_CHANNEL_BIT_MUL
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
(
4U
*
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
));
uint32_t
u32CalBuf
=
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
+
1U
;
/*
uint32_t u32CalBuf = TAUB0CDR2 + 1U;*/
uint32_t
u32Duty
=
u16Duty
;
if
(
enTimerBChannel
%
2U
)
{
(
*
((
uint16_t
*
)(
u32TimerBRegAddrChannel
+
4U
*
TIMERB_CHANNEL_INTERVAL
)))
=
(
u32CalBuf
*
u32Duty
/
1000U
);
/*TAUB0CDR3 = (u32CalBuf * u32Duty / 100U); */
/*duty*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X44U
;
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
u16TimerBbit
;
/*TAUB0RDT = (u16TimerBbit);*/
}
}
void
TimerB_PWM_Channel_Start
(
TIMERB_Channel_en_t
enTimerBChannel
)
{
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16TimerBbit
=
(
1U
<<
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
))
*
TIMERB_CHANNEL_BIT_MUL
;
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16TimerBbit
=
(
1U
<<
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
))
*
TIMERB_CHANNEL_BIT_MUL
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X1C4U
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X1C4U
;
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
u16TimerBbit
;
/*
TAUB0TS = (u16TimerBbit);*/
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
u16TimerBbit
;
/*
TAUB0TS = (u16TimerBbit);*/
}
/*调用该函数后,仅重新调用开始函数功能即可正常使用*/
void
TimerB_PWM_Channel_Stop
(
TIMERB_Channel_en_t
enTimerBChannel
)
{
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16TimerBbit
=
(
1U
<<
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
));
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16TimerBbit
=
(
1U
<<
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
));
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X1C8U
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X1C8U
;
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
u16TimerBbit
;
/*TAUB0TT = (u16TimerBbit);*/
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
u16TimerBbit
;
/*TAUB0TT = (u16TimerBbit);*/
}
/*仅休眠时可调用,调用该函数后需要重新初始化相关通道才可以正常使用。*/
void
TimerB_PWM_Channel_Sleep
(
TIMERB_Channel_en_t
enTimerBChannel
)
{
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16TimerBbit
=
(
1U
<<
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
))
*
TIMERB_CHANNEL_BIT_MUL
;
uint16_t
u16TimerBRegTOL
=
0U
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X1C8U
;
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
u16TimerBbit
;
/*TAUB0TT = (u16TimerBbit);*/
u16TimerBbit
=
u16TimerBbit
*
(
TIMERB_CHANNEL_BIT_MUL
-
1U
)
/
TIMERB_CHANNEL_BIT_MUL
;
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X40U
;
u16TimerBRegTOL
=
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
));
/*u16TimerBRegTOL=TAUB0TOL*/
u16TimerBRegTOL
&=
u16TimerBbit
;
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X5CU
;
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)
&=
(
~
u16TimerBbit
);
/*TAUB0TOE &= ~u16TimerBbit;*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X58U
;
if
(
u16TimerBRegTOL
)
{
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)
|=
(
u16TimerBbit
);
/*TAUB0TO |= u16TimerBbit;*/
}
else
{
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)
&=
(
~
u16TimerBbit
);
/*TAUB0TO &= ~u16TimerBbit;*/
}
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16TimerBbit
=
(
1U
<<
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
))
*
TIMERB_CHANNEL_BIT_MUL
;
uint16_t
u16TimerBRegTOL
=
0U
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X1C8U
;
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
u16TimerBbit
;
/*TAUB0TT = (u16TimerBbit);*/
u16TimerBbit
=
u16TimerBbit
*
(
TIMERB_CHANNEL_BIT_MUL
-
1U
)
/
TIMERB_CHANNEL_BIT_MUL
;
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X40U
;
u16TimerBRegTOL
=
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
));
/*u16TimerBRegTOL=TAUB0TOL*/
u16TimerBRegTOL
&=
u16TimerBbit
;
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X5CU
;
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)
&=
(
~
u16TimerBbit
);
/*TAUB0TOE &= ~u16TimerBbit;*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X58U
;
if
(
u16TimerBRegTOL
)
{
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)
|=
(
u16TimerBbit
);
/*TAUB0TO |= u16TimerBbit;*/
}
else
{
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)
&=
(
~
u16TimerBbit
);
/*TAUB0TO &= ~u16TimerBbit;*/
}
}
/*------------------------------------------------------------------------------*/
...
...
@@ -840,90 +841,90 @@ void TimerB_Cal_Fre(TIMERB_Channel_en_t enTimerBChannel, uint32_t u32TimerBClock
static
void
TimerB_Input_Capture_Channel_Init
(
TIMERB_Channel_en_t
enTimerBChannel
,
TIMERB_Clock_en_t
enTimerBClock
,
TIMERB_Edge_en_t
enTimerBEdge
)
{
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16ClockSelectRe
=
(
0x156U
|
(
enTimerBClock
<<
14U
));
uint16_t
u16TimerBbit
=
(
1U
<<
u8TimerBChannel
);
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16ClockSelectRe
=
(
0x156U
|
(
enTimerBClock
<<
14U
));
uint16_t
u16TimerBbit
=
(
1U
<<
u8TimerBChannel
);
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
0U
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
0U
;
/*control*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X200U
+
(
4U
*
u8TimerBChannel
);
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)
=
u16ClockSelectRe
;
/*TAUB0CMOR10 = u16ClockSelectRe;*/
/*control*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X200U
+
(
4U
*
u8TimerBChannel
);
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)
=
u16ClockSelectRe
;
/*TAUB0CMOR10 = u16ClockSelectRe;*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0XC0U
+
(
4U
*
u8TimerBChannel
);
*
((
uint8_t
*
)
u32TimerBRegAddrChannel
)
=
(
uint8_t
)
enTimerBEdge
;
/*TAUB0CMUR10 = enTimerBEdge;*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0XC0U
+
(
4U
*
u8TimerBChannel
);
*
((
uint8_t
*
)
u32TimerBRegAddrChannel
)
=
(
uint8_t
)
enTimerBEdge
;
/*TAUB0CMUR10 = enTimerBEdge;*/
/*output mode*/
/*Simultaneous rewrite */
/*output mode*/
/*Simultaneous rewrite */
}
/**/
static
void
TimerB_Interval_Timer_Channel_Init
(
TIMERB_Channel_en_t
enTimerBChannel
,
TIMERB_Clock_en_t
enTimerBClock
)
{
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16ClockSelectRe
=
(
0x00U
|
(
enTimerBClock
<<
14U
));
uint16_t
u16TimerBbit
=
(
1U
<<
u8TimerBChannel
);
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16ClockSelectRe
=
(
0x00U
|
(
enTimerBClock
<<
14U
));
uint16_t
u16TimerBbit
=
(
1U
<<
u8TimerBChannel
);
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
0U
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
0U
;
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X200U
+
(
4U
*
u8TimerBChannel
);
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)
=
u16ClockSelectRe
;
/*TAUB0CMOR3 = u16ClockSelectRe;*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X200U
+
(
4U
*
u8TimerBChannel
);
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)
=
u16ClockSelectRe
;
/*TAUB0CMOR3 = u16ClockSelectRe;*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0XC0U
+
(
4U
*
u8TimerBChannel
);
*
((
uint8_t
*
)
u32TimerBRegAddrChannel
)
=
0U
;
/*TAUB0CMUR3 = 0U;*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0XC0U
+
(
4U
*
u8TimerBChannel
);
*
((
uint8_t
*
)
u32TimerBRegAddrChannel
)
=
0U
;
/*TAUB0CMUR3 = 0U;*/
/*output mode*/
/*Simultaneous rewrite */
/*output mode*/
/*Simultaneous rewrite */
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
(
4U
*
u8TimerBChannel
);
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)
=
0xFFFFU
;
/*TAUB0CDR9 = 0xFFFFU;*/
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
(
4U
*
u8TimerBChannel
);
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
)
=
0xFFFFU
;
/*TAUB0CDR9 = 0xFFFFU;*/
}
void
TimerB_Input_Channel_Init
(
TIMERB_Channel_en_t
enTimerBChannel
,
TIMERB_Clock_en_t
enTimerBClock
,
TIMERB_Edge_en_t
enTimerBEdge
)
{
TimerB_Input_Capture_Channel_Init
(
enTimerBChannel
,
enTimerBClock
,
enTimerBEdge
);
TimerB_Interval_Timer_Channel_Init
(
enTimerBChannel
-
1
,
enTimerBClock
);
TimerB_Input_Capture_Channel_Init
(
enTimerBChannel
,
enTimerBClock
,
enTimerBEdge
);
TimerB_Interval_Timer_Channel_Init
(
enTimerBChannel
-
1
,
enTimerBClock
);
/*
R_DEV_IntEnable(R_DEV_INT_TAUB0I9, 1U);
R_DEV_IntEnable(R_DEV_INT_TAUB0I10, 1U);
*/
/*
R_DEV_IntEnable(R_DEV_INT_TAUB0I9, 1U);
R_DEV_IntEnable(R_DEV_INT_TAUB0I10, 1U);
*/
}
void
TimerB_Input_Channel_Start
(
TIMERB_Channel_en_t
enTimerBChannel
)
{
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16TimerBbit
=
(
1U
<<
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
))
*
TIMERB_CHANNEL_BIT_MUL
;
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16TimerBbit
=
(
1U
<<
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
))
*
TIMERB_CHANNEL_BIT_MUL
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X1C4U
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X1C4U
;
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
u16TimerBbit
;
/*
TAUB0TS = (u16TimerBbit);*/
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
u16TimerBbit
;
/*
TAUB0TS = (u16TimerBbit);*/
}
void
TimerB_Input_Channel_Stop
(
TIMERB_Channel_en_t
enTimerBChannel
)
{
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16TimerBbit
=
(
1U
<<
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
))
*
TIMERB_CHANNEL_BIT_MUL
;
uint8_t
u8TimerBIndex
=
enTimerBChannel
/
16U
;
uint8_t
u8TimerBChannel
=
enTimerBChannel
%
16U
;
uint16_t
u16TimerBbit
=
(
1U
<<
(
u8TimerBChannel
-
TIMERB_CHANNEL_INTERVAL
))
*
TIMERB_CHANNEL_BIT_MUL
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X1C8U
;
uint32_t
u32TimerBRegBaseAddr
=
TIMERB_BASE_ADDRESSES
+
(
u8TimerBIndex
*
0X1000U
);
uint32_t
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
0X1C8U
;
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
u16TimerBbit
;
/*TAUB0TT = (u16TimerBbit);*/
(
*
((
uint16_t
*
)
u32TimerBRegAddrChannel
))
=
u16TimerBbit
;
/*TAUB0TT = (u16TimerBbit);*/
}
uint32_t
u32YZHDTest4
=
0
;
uint32_t
u32YZHDTest5
=
0
;
uint32_t
u32YZHDTest4
=
0
;
uint32_t
u32YZHDTest5
=
0
;
/*捕获中断*/
void
TimerB_Input_Isr
(
TIMERB_Channel_en_t
enTimerBChannel
)
{
...
...
@@ -940,7 +941,7 @@ void TimerB_Input_Isr(TIMERB_Channel_en_t enTimerBChannel)
uint32_t
u32TimerBChannelClock
=
0UL
;
uint32_t
u32TimerBChannelData
=
0UL
;
uint32_t
i
=
0
;
uint32_t
i
=
0
;
u32TimerBRegAddrChannel
=
u32TimerBRegBaseAddr
+
(
4U
*
(
u8TimerBChannel
));
...
...
@@ -954,13 +955,13 @@ uint32_t i=0;
TimerB_Cal_Fre
(
enTimerBChannel
,
u32TimerBChannelClock
,
u32TimerBChannelData
);
R_DEV_IntClearFlag
(
R_DEV_INT_TAUB0I0
+
enTimerBChannel
);
for
(
i
=
0
;
i
<
600
;
i
++
)
{
u32YZHDTest4
++
;
}
R_DEV_IntClearFlag
(
R_DEV_INT_TAUB0I0
+
enTimerBChannel
);
for
(
i
=
0
;
i
<
600
;
i
++
)
{
u32YZHDTest4
++
;
}
}
/*溢出中断*/
void
TimerB_Overflow_Isr
(
void
)
...
...
@@ -986,12 +987,12 @@ void TimerB_Cal_Fre(TIMERB_Channel_en_t enTimerBChannel, uint32_t u32TimerBClock
{
u32TimeOut
=
0
;
if
(
N_Count
<
2
)
if
(
N_Count
<
2
)
{
N_Count
++
;
}
u32TimerBInputData
=
u16TimerBCount
;
if
(
N_Count
>
1
)
if
(
N_Count
>
1
)
{
Fre_Event
=
1
;
if
(
u32TimerBInputDataLast
<
u32TimerBInputData
)
...
...
@@ -1012,7 +1013,7 @@ void TimerB_Cal_Fre(TIMERB_Channel_en_t enTimerBChannel, uint32_t u32TimerBClock
u32TimerBInputDataLast
=
u32TimerBInputData
;
if
(
u32TimerBInputDataDif
)
{
u32TimerBInputFre
=
u32TimerBClockFre
*
100
/
u32TimerBInputDataDif
;
u32TimerBInputFre
=
u32TimerBClockFre
*
100
/
u32TimerBInputDataDif
;
}
}
...
...
@@ -1023,7 +1024,7 @@ void TimerB_Cal_Fre(TIMERB_Channel_en_t enTimerBChannel, uint32_t u32TimerBClock
void
TimerB_Fre_Timeout
(
uint8_t
Time
)
{
if
(
u32TimeOut
<
FRE_VEH_TIMEOUT
)
if
(
u32TimeOut
<
FRE_VEH_TIMEOUT
)
{
u32TimeOut
+=
Time
;
}
...
...
@@ -1048,7 +1049,7 @@ uint16_t Get_Veh_Fre(void)
return
(
uint16_t
)
u32Result
;
}
uint8_t
Get_Veh_Fre_Event
(
void
)
uint8_t
Get_Veh_Fre_Event
(
void
)
{
uint8_t
u8Result
=
0
;
u8Result
=
Fre_Event
;
...
...
source/System/sys_scheduler.c
View file @
e81147a3
...
...
@@ -3,6 +3,8 @@
#include "init.h"
#include "Sys_Scheduler.h"
#include "Sys_Tick.h"
#include "kwp2000_tp.h"
#include "kwp2000_protocol.h"
typedef
struct
{
...
...
@@ -25,6 +27,8 @@ Sys_Scheduling_st_t SysScheduling;
static
void
Sys_Exact_50us_Task_Handler
(
void
);
static
void
Sys_Exact_100ms_Task_Handler
(
void
);
static
uint8_t
u08_1ms_count
;
void
Sys_Init
(
void
)
{
...
...
@@ -98,6 +102,16 @@ void Sys_Scheduling_Service(void)
static
void
Sys_Exact_50us_Task_Handler
(
void
)
{
Sys_Exact_50us_Tasks
();
/*----K_Line----*/
u08_1ms_count
++
;
if
(
u08_1ms_count
>=
20
)
{
u08_1ms_count
=
0
;
Kwp2000_ComInit_Handle
();
Kwp2000_Handle
();
/* qitiancun */
Kwp2000_Timeout
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment