Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rtic_f4xx_nucleo
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
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Niklas Lundberg
rtic_f4xx_nucleo
Commits
be71ee29
Commit
be71ee29
authored
4 years ago
by
Blinningjr
Browse files
Options
Downloads
Patches
Plain Diff
timing_exam 2)
parent
f00153c8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/timing_exam.rs
+57
-0
57 additions, 0 deletions
examples/timing_exam.rs
with
57 additions
and
0 deletions
examples/timing_exam.rs
+
57
−
0
View file @
be71ee29
...
@@ -9,6 +9,7 @@ use cortex_m::{asm, peripheral::DWT};
...
@@ -9,6 +9,7 @@ use cortex_m::{asm, peripheral::DWT};
use
panic_halt
as
_
;
use
panic_halt
as
_
;
use
rtic
::
cyccnt
::{
Duration
,
Instant
,
U32Ext
};
use
rtic
::
cyccnt
::{
Duration
,
Instant
,
U32Ext
};
use
stm32f4
::
stm32f411
;
use
stm32f4
::
stm32f411
;
use
core
::
convert
::
TryInto
;
#[no_mangle]
#[no_mangle]
static
mut
T1_MAX_RP
:
u32
=
0
;
static
mut
T1_MAX_RP
:
u32
=
0
;
...
@@ -40,6 +41,7 @@ const APP: () = {
...
@@ -40,6 +41,7 @@ const APP: () = {
#[inline(never)]
#[inline(never)]
#[task(schedule
=
[
t1]
,
priority
=
1
)]
#[task(schedule
=
[
t1]
,
priority
=
1
)]
fn
t1
(
cx
:
t1
::
Context
)
{
fn
t1
(
cx
:
t1
::
Context
)
{
let
start
=
cx
.scheduled
;
asm
::
bkpt
();
asm
::
bkpt
();
cx
.schedule
.t1
(
cx
.scheduled
+
100_000
.cycles
())
.unwrap
();
cx
.schedule
.t1
(
cx
.scheduled
+
100_000
.cycles
())
.unwrap
();
asm
::
bkpt
();
asm
::
bkpt
();
...
@@ -50,12 +52,23 @@ const APP: () = {
...
@@ -50,12 +52,23 @@ const APP: () = {
// 2) your code here to update T1_MAX_RP and
// 2) your code here to update T1_MAX_RP and
// break if deadline missed
// break if deadline missed
let
end
=
Instant
::
now
();
let
response_time
:
u32
=
(
end
-
start
)
.try_into
()
.unwrap
();
unsafe
{
if
T1_MAX_RP
<
response_time
{
T1_MAX_RP
=
response_time
;
}
if
T1_MAX_RP
>
100_000
{
asm
::
bkpt
();
}
}
}
}
// Deadline 200, Inter-arrival 200
// Deadline 200, Inter-arrival 200
#[inline(never)]
#[inline(never)]
#[task(schedule
=
[
t2]
,
resources
=
[
R1
,
R2
],
priority
=
2
)]
#[task(schedule
=
[
t2]
,
resources
=
[
R1
,
R2
],
priority
=
2
)]
fn
t2
(
cx
:
t2
::
Context
)
{
fn
t2
(
cx
:
t2
::
Context
)
{
let
start
=
cx
.scheduled
;
asm
::
bkpt
();
asm
::
bkpt
();
cx
.schedule
.t2
(
cx
.scheduled
+
200_000
.cycles
())
.unwrap
();
cx
.schedule
.t2
(
cx
.scheduled
+
200_000
.cycles
())
.unwrap
();
asm
::
bkpt
();
asm
::
bkpt
();
...
@@ -66,12 +79,23 @@ const APP: () = {
...
@@ -66,12 +79,23 @@ const APP: () = {
// 2) your code here to update T2_MAX_RP and
// 2) your code here to update T2_MAX_RP and
// break if deadgine missed
// break if deadgine missed
let
end
=
Instant
::
now
();
let
response_time
:
u32
=
(
end
-
start
)
.try_into
()
.unwrap
();
unsafe
{
if
T2_MAX_RP
<
response_time
{
T2_MAX_RP
=
response_time
;
}
if
T2_MAX_RP
>
200_000
{
asm
::
bkpt
();
}
}
}
}
// Deadline 50, Inter-arrival 50
// Deadline 50, Inter-arrival 50
#[inline(never)]
#[inline(never)]
#[task(schedule
=
[
t3]
,
resources
=
[
R2
],
priority
=
3
)]
#[task(schedule
=
[
t3]
,
resources
=
[
R2
],
priority
=
3
)]
fn
t3
(
cx
:
t3
::
Context
)
{
fn
t3
(
cx
:
t3
::
Context
)
{
let
start
=
cx
.scheduled
;
asm
::
bkpt
();
asm
::
bkpt
();
cx
.schedule
.t3
(
cx
.scheduled
+
50_000
.cycles
())
.unwrap
();
cx
.schedule
.t3
(
cx
.scheduled
+
50_000
.cycles
())
.unwrap
();
asm
::
bkpt
();
asm
::
bkpt
();
...
@@ -82,6 +106,16 @@ const APP: () = {
...
@@ -82,6 +106,16 @@ const APP: () = {
// 2) your code here to update T3_MAX_RP and
// 2) your code here to update T3_MAX_RP and
// break if deadline missed
// break if deadline missed
let
end
=
Instant
::
now
();
let
response_time
:
u32
=
(
end
-
start
)
.try_into
()
.unwrap
();
unsafe
{
if
T3_MAX_RP
<
response_time
{
T3_MAX_RP
=
response_time
;
}
if
T3_MAX_RP
>
100_000
{
asm
::
bkpt
();
}
}
}
}
// RTIC requires that unused interrupts are declared in an extern block when
// RTIC requires that unused interrupts are declared in an extern block when
...
@@ -124,6 +158,16 @@ const APP: () = {
...
@@ -124,6 +158,16 @@ const APP: () = {
// `cx.schedule.t1(cx.scheduled + 100_000.cycles()).unwrap();`
// `cx.schedule.t1(cx.scheduled + 100_000.cycles()).unwrap();`
//
//
// [Your answer here]
// [Your answer here]
// The line:
// `cx.schedule.t1(cx.scheduled + 100_000.cycles()).unwrap();`
// schedules task t1 to be executed at instant(timestamp) cx.scheduled + 100 000 cycles = now plus
// ca 100 sec. The 100 000 cycles in this case is the inter arrival time of task t1.
//
// All the tasks are scheduled like this at the start of the program and when the tasks starts
// executing, thus the tasks will execute periodically.
//
// Source: https://rtic.rs/0.5/book/en/by-example/timer-queue.html
//
//
//
// Explain in your own words the difference between:
// Explain in your own words the difference between:
//
//
...
@@ -132,11 +176,21 @@ const APP: () = {
...
@@ -132,11 +176,21 @@ const APP: () = {
// `cx.schedule.t1(cx.scheduled + 100_000.cycles()).unwrap();`
// `cx.schedule.t1(cx.scheduled + 100_000.cycles()).unwrap();`
//
//
// [Your answer here]
// [Your answer here]
// Instant::now() may have drift/jitter, meaning that it is not completely accurate.
// cx.scheduled has zero drift/jitter, thus it is accurate.
//
//
// Source: https://rtic.rs/0.5/book/en/by-example/timer-queue.html
//
//
//
// Explain in your own words why we use the latter
// Explain in your own words why we use the latter
// in order to generate a periodic task.
// in order to generate a periodic task.
//
//
// [Your answer here]
// [Your answer here]
// If we would use Instant::now() the timing of the periodic tasks would be a little inaccurate
// because Instant::now() has a little drift/jitter. cx.scheduled has zero drift/jitter and thus
// will have accurate timing of the periodic tasks.
//
//
//
// Hint, look at https://rtic.rs/0.5/book/en/by-example/timer-queue.html
// Hint, look at https://rtic.rs/0.5/book/en/by-example/timer-queue.html
//
//
...
@@ -157,6 +211,9 @@ const APP: () = {
...
@@ -157,6 +211,9 @@ const APP: () = {
// Explain why this is needed (there is a good reason for it).
// Explain why this is needed (there is a good reason for it).
//
//
// [Your answer here]
// [Your answer here]
// The global variables can be accessed by multiple processes and thus there is the problem of two
// or more processes accessing the same global variable at the same time.
//
//
//
// Implement this functionality for all tasks.
// Implement this functionality for all tasks.
//
//
...
...
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