Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ch32v003fun
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Horn
ch32v003fun
Commits
51637a2e
Commit
51637a2e
authored
1 year ago
by
recallmenot
Browse files
Options
Downloads
Patches
Plain Diff
ch32v003fun.c and .h added interrupt suspension functions
parent
b199584b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ch32v003fun/ch32v003fun.c
+45
-0
45 additions, 0 deletions
ch32v003fun/ch32v003fun.c
ch32v003fun/ch32v003fun.h
+5
-0
5 additions, 0 deletions
ch32v003fun/ch32v003fun.h
with
50 additions
and
0 deletions
ch32v003fun/ch32v003fun.c
+
45
−
0
View file @
51637a2e
...
...
@@ -765,6 +765,51 @@ void InterruptVectorDefault()
.option pop;
\n
"
);
}
/*
SUSPEND ALL INTERRUPTS EXCEPT
The following 3 functions serve to suspend all interrupts, except for the one you momentarily need.
The purpose of this is to not disturb the one interrupt of interest and let it run unimpeded.
procedure:
1. save the enabled IRQs: uint32_t IRQ_backup = NVIC_get_enabled_IRQs();
2. disable all IRQs: NVIC_clear_all_IRQs_except(IRQ_of_interest);
3. restore the previously enabled IRQs: NVIC_restore_IRQs(IRQ_backup);
bit layout of the IRQ backup
bit 0 | 1 | 2 | 3 | 4 | 5 | 6 .. 22 | 23 .. 28
IRQn 2 | 3 | 12 | res | 14 | res | 16 .. 31 | 32 .. 38
IRQn 2 and 3 aren't actually user-settable (see RM).
Specifying an invalid IRQn_to_keep like 0 will disable all interrupts.
*/
RV_STATIC_INLINE
uint32_t
NVIC_get_enabled_IRQs
()
{
return
(
((
NVIC
->
ISR
[
0
]
>>
2
)
&
0
b11
)
|
((
NVIC
->
ISR
[
0
]
>>
12
)
<<
2
)
|
((
NVIC
->
ISR
[
1
]
&
0
b1111111
)
<<
23
)
);
}
RV_STATIC_INLINE
void
NVIC_clear_all_IRQs_except
(
uint8_t
IRQn_to_keep
)
{
if
(
!
(
IRQn_to_keep
>>
5
))
{
// IRQn_to_keep < 32
NVIC
->
IRER
[
0
]
=
(
~
0
)
&
(
~
(
1
<<
IRQn_to_keep
));
NVIC
->
IRER
[
1
]
=
(
~
0
);
}
else
{
IRQn_to_keep
=
IRQn_to_keep
>>
5
;
NVIC
->
IRER
[
0
]
=
(
~
0
);
NVIC
->
IRER
[
1
]
=
(
~
0
)
&
(
~
(
1
<<
IRQn_to_keep
));
}
}
RV_STATIC_INLINE
void
NVIC_restore_IRQs
(
uint32_t
old_state
)
{
NVIC
->
IENR
[
0
]
=
(
old_state
>>
2
)
<<
12
;
NVIC
->
IENR
[
1
]
=
old_state
>>
23
;
}
void
handle_reset
()
{
asm
volatile
(
"
\n
\
...
...
This diff is collapsed.
Click to expand it.
ch32v003fun/ch32v003fun.h
+
5
−
0
View file @
51637a2e
...
...
@@ -5024,6 +5024,11 @@ void SystemInit24HSI( void ); // No PLL, just raw internal RC oscillator.
void
SystemInitHSE
(
int
HSEBYP
);
void
SystemInitHSEPLL
(
int
HSEBYP
);
// SUSPEND ALL INTERRUPTS EXCEPT
RV_STATIC_INLINE
uint32_t
NVIC_get_enabled_IRQs
();
RV_STATIC_INLINE
void
NVIC_clear_all_IRQs_except
(
uint8_t
IRQn_to_keep
);
RV_STATIC_INLINE
void
NVIC_restore_IRQs
(
uint32_t
old_state
);
#define UART_BAUD_RATE 115200
#define OVER8DIV 4
#define INTEGER_DIVIDER (((25 * (APB_CLOCK)) / ((OVER8DIV) * (UART_BAUD_RATE))))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment