Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
a4_decode
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
D7018E-SS-RUST
a4_decode
Commits
3595a0c9
Commit
3595a0c9
authored
7 years ago
by
Henrik Tjäder
Browse files
Options
Downloads
Patches
Plain Diff
Fixed the critical section so can use DWT
parent
01f90c9a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+5
-0
5 additions, 0 deletions
README.md
src/main.rs
+24
-5
24 additions, 5 deletions
src/main.rs
with
29 additions
and
5 deletions
README.md
+
5
−
0
View file @
3595a0c9
...
...
@@ -51,3 +51,8 @@ PLAIN however is mutable and will be changed on the "return" of decode()
Currently there is only one function so it should be safe, however, with
two tasks this would not be the case. In a typical microcontroller setting
with interrupt handlers it would be similar "safe" like C.
## Debug vs Release analysis
Time taken to decode ABC is
`Decoded in 4457 cycles`
,
while in release mode this is reduced to
`Decoded in 338 cycles`
.
This diff is collapsed.
Click to expand it.
src/main.rs
+
24
−
5
View file @
3595a0c9
...
...
@@ -3,14 +3,16 @@
extern
crate
cortex_m_semihosting
;
extern
crate
stm32f40x
;
extern
crate
cortex_m
;
use
core
::
fmt
::
Write
;
use
cortex_m_semihosting
::
hio
;
//use std::str::from_utf8;
use
core
::
str
::
from_utf8
;
use
stm32f40x
::{
DWT
};
static
ABC
:
[
u32
;
4
]
=
[
0x9fdd9158
,
0x85715808
,
0xac73323a
,
...
...
@@ -252,14 +254,31 @@ fn main() {
// get a handle to the *host* standard output
let
mut
stdout
=
hio
::
hstdout
()
.unwrap
();
// Critical section
cortex_m
::
interrupt
::
free
(
|
cs
|
{
// Enable the DWT CYCCNT
let
dwt
=
DWT
.borrow
(
cs
);
dwt
.enable_cycle_counter
();
writeln!
(
stdout
,
"Time to decode!"
)
.unwrap
();
let
mut
seed
=
0x0e0657c1
;
decode
(
&
CODED
,
unsafe
{
&
mut
PLAIN
},
&
mut
seed
);
//writeln!(stdout, "current counter:\n {:?}", dwt.cyccnt.read()).unwrap();
let
before
=
dwt
.cyccnt
.read
();
decode
(
&
ABC
,
unsafe
{
&
mut
PLAIN
},
&
mut
seed
);
//decode(&CODED, unsafe { &mut PLAIN }, &mut seed);
let
after
=
dwt
.cyccnt
.read
();
writeln!
(
stdout
,
"Decoded in {} cycles"
,
after
-
before
)
.unwrap
();
writeln!
(
stdout
,
"Decoded:
\n
{:#?}"
,
from_utf8
(
unsafe
{
&
PLAIN
})
.unwrap
())
.unwrap
();
}
);
/*
let mut locseed;
...
...
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