Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
TianYing_ty100
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
TY
TianYing_ty100
Commits
60831117
Commit
60831117
authored
Oct 16, 2024
by
陈家乐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🐞
fix:QAC问题:45351 Suspicious: Division by zero
parent
6beb5c28
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
19 deletions
+25
-19
adc.c
...ource/Device/Cmsemicon/BAT32A239/Library/Driver/src/adc.c
+25
-19
No files found.
Firmware/Source/Device/Cmsemicon/BAT32A239/Library/Driver/src/adc.c
View file @
60831117
...
...
@@ -122,35 +122,41 @@ uint16_t ADC_Converse_Scan(ADC_Channel_t ch, uint32_t times, uint16_t *buf)
volatile
uint8_t
flag
;
uint32_t
total
=
0
;
assert_param
(
IS_SCAN_START_CHAN
(
ch
));
if
(
times
==
0
)
{
return
0
;
}
else
{
assert_param
(
IS_SCAN_START_CHAN
(
ch
));
INTC_DisableIRQ
(
ADC_IRQn
);
// disable INTAD interrupt
INTC_DisableIRQ
(
ADC_IRQn
);
// disable INTAD interrupt
ADC
->
ADM0
&=
~
ADC_Enable
;
ADC
->
ADM0
&=
~
ADC_Enable
;
ADC
->
ADM1
|=
0x08
;
//enable one-shot convertion
ADC
->
ADM1
|=
0x80
;
//set sacn mode
ADC
->
ADM1
|=
0x08
;
//enable one-shot convertion
ADC
->
ADM1
|=
0x80
;
//set sacn mode
ADC
->
ADTRG
=
ADC_ExternalTrig_Software
;
ADC
->
ADM0
|=
ADC_Enable
;
ADC
->
ADTRG
=
ADC_ExternalTrig_Software
;
ADC
->
ADM0
|=
ADC_Enable
;
ADC
->
ADS
=
ch
;
ADC
->
ADS
=
ch
;
for
(
i
=
0
;
i
<
times
;
i
++
)
{
ADC
->
ADM0
|=
ADC_Start_Cmp
;
//adc start
for
(
j
=
0
;
j
<
4
;
j
++
)
for
(
i
=
0
;
i
<
times
;
i
++
)
{
while
(
INTC_GetPendingIRQ
(
ADC_IRQn
)
==
0
);
INTC_ClearPendingIRQ
(
ADC_IRQn
);
// clear INTAD interrupt flag
ADC
->
ADM0
|=
ADC_Start_Cmp
;
//adc start
for
(
j
=
0
;
j
<
4
;
j
++
)
{
while
(
INTC_GetPendingIRQ
(
ADC_IRQn
)
==
0
);
INTC_ClearPendingIRQ
(
ADC_IRQn
);
// clear INTAD interrupt flag
*
buf
++
=
ADC
->
ADCR
;
total
+=
ADC
->
ADCR
;
*
buf
++
=
ADC
->
ADCR
;
total
+=
ADC
->
ADCR
;
}
}
return
(
uint16_t
)(
total
/
times
);
// return average value
}
}
return
(
total
/
times
);
// return average value
}
/**
...
...
@@ -192,7 +198,7 @@ uint16_t ADC_Converse(ADC_Channel_t ch, uint32_t times, uint16_t *buf)
*
buf
++
=
ADC
->
ADCR
;
total
+=
ADC
->
ADCR
;
}
return
(
total
/
times
);
// return average value
return
(
uint16_t
)(
total
/
times
);
// return average value
}
}
...
...
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