Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
e7020e_2019
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
August Svensson
e7020e_2019
Commits
0f33621c
Commit
0f33621c
authored
6 years ago
by
August Svensson
Browse files
Options
Downloads
Patches
Plain Diff
bare10_3
parent
d61139b5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.vscode/tasks.json
+1
-1
1 addition, 1 deletion
.vscode/tasks.json
examples/bare10.rs
+61
-30
61 additions, 30 deletions
examples/bare10.rs
with
62 additions
and
31 deletions
.vscode/tasks.json
+
1
−
1
View file @
0f33621c
...
...
@@ -330,7 +330,7 @@
{
"type"
:
"shell"
,
"label"
:
"cargo build --example bare10 --release"
,
"command"
:
"cargo build --example bare10 --release --features
\"
hal rtfm
\"
"
,
"command"
:
"cargo build --example bare10 --release --features
\"
hal rtfm
rtfm-tq
\"
"
,
"problemMatcher"
:
[
"$rustc"
],
...
...
This diff is collapsed.
Click to expand it.
examples/bare10.rs
+
61
−
30
View file @
0f33621c
...
...
@@ -42,9 +42,9 @@ pub struct Cmd {
impl
Cmd
{
fn
parse
(
&
mut
self
,
cmd_byte
:
[
u8
;
10
],
cmd_length
:
usize
)
{
if
cmd_byte
.starts_with
(
&
[
b'o'
,
b'n
'
,
b'
'
])
{
if
cmd_byte
.starts_with
(
&
[
b'o'
,
b'n'
])
{
self
.cmd_type
=
CmdType
::
On
;
self
.half_period
=
freq_to_half_period
(
1
);
self
.half_period
=
Cmd
::
freq_to_half_period
(
1
);
}
else
if
cmd_byte
.starts_with
(
&
[
b's'
,
b'e'
,
b't'
,
b' '
])
{
let
mut
tmp
=
0
;
for
c
in
&
cmd_byte
[
4
..
cmd_length
]
{
...
...
@@ -55,16 +55,16 @@ impl Cmd {
}
}
self
.cmd_type
=
CmdType
::
Set
;
self
.half_period
=
freq_to_half_period
(
tmp
);
self
.half_period
=
Cmd
::
freq_to_half_period
(
tmp
);
}
else
{
self
.cmd_type
=
CmdType
::
Off
;
self
.half_period
=
freq_to_half_period
(
1
);
self
.half_period
=
Cmd
::
freq_to_half_period
(
1
);
}
}
fn
freq_to_half_period
(
freq
:
u32
)
->
u32
{
if
freq
==
0
{
return
1
;
return
Cmd
::
freq_to_half_period
(
1
)
;
}
else
{
return
SYSTEM_CLOCK_FREQ
/
(
2
*
freq
);
}
...
...
@@ -91,7 +91,7 @@ const APP: () = {
static
mut
CURRENT_CMD
:
Cmd
=
();
// init runs in an interrupt free section>
#[init]
#[init
(spawn
=
[
off]
)
]
fn
init
()
{
let
stim
=
&
mut
core
.ITM.stim
[
0
];
iprintln!
(
stim
,
"bare10"
);
...
...
@@ -122,6 +122,7 @@ const APP: () = {
// Separate out the sender and receiver of the serial port
let
(
tx
,
rx
)
=
serial
.split
();
let
_
=
spawn
.off
();
// Our split serial
TX
=
tx
;
RX
=
rx
;
...
...
@@ -131,7 +132,7 @@ const APP: () = {
IS_LED_ON
=
false
;
CURRENT_CMD
=
Cmd
{
cmd_type
:
CmdType
::
Off
,
frequency
:
1
,
half_period
:
Cmd
::
freq_to_half_period
(
1
)
,
};
// CMD Interpretor
B
=
[
0u8
;
10
];
...
...
@@ -149,7 +150,7 @@ const APP: () = {
}
}
#[task(priority
=
1
,
capacity
=
10
,
resources
=
[
IS_LED_ON,
B,
B_INDEX,
CURRENT_CMD,
ITM]
,
spawn
=
[
echo
,
on
,
off
])]
#[task(priority
=
1
,
capacity
=
10
,
resources
=
[
IS_LED_ON,
B,
B_INDEX,
CURRENT_CMD,
ITM]
,
spawn
=
[
on
,
off
])]
fn
cmd_interpretor
(
byte
:
u8
)
{
let
is_led_on
=
*
resources
.IS_LED_ON
;
let
mut
b
=
*
resources
.B
;
...
...
@@ -185,29 +186,68 @@ const APP: () = {
iprintln!
(
stim
,
"IS_LED_ON: {:?}"
,
is_led_on
);
match
cmd
.cmd_type
{
CmdType
::
Off
=>
iprintln!
(
stim
,
"CURRENT_CMD: off, {:?}"
,
cmd
.
frequency
),
CmdType
::
On
=>
iprintln!
(
stim
,
"CURRENT_CMD: on, {:?}"
,
cmd
.
frequency
),
CmdType
::
Set
=>
iprintln!
(
stim
,
"CURRENT_CMD: set, {:?}"
,
cmd
.
frequency
),
CmdType
::
Off
=>
iprintln!
(
stim
,
"CURRENT_CMD: off, {:?}"
,
cmd
.
half_period
),
CmdType
::
On
=>
iprintln!
(
stim
,
"CURRENT_CMD: on, {:?}"
,
cmd
.
half_period
),
CmdType
::
Set
=>
iprintln!
(
stim
,
"CURRENT_CMD: set, {:?}"
,
cmd
.
half_period
),
}
let
_
=
spawn
.on
();
*
resources
.B
=
b
;
*
resources
.B_INDEX
=
b_i
;
}
#[task(priority
=
1
,
schedule
=
[
off]
,
resources
=
[
LED
,
IS_LED_ON
])]
#[task(priority
=
1
,
schedule
=
[
off
,
on
]
,
resources
=
[
CURRENT_CMD
,
LED
,
IS_LED_ON
,
ITM
],
spawn
=
[
off
])]
fn
on
()
{
if
schedule
.off
(
Instant
::
now
+
)
resources
.LED
.set_high
();
*
resources
.IS_LED_ON
=
true
;
let
cmd
=
resources
.CURRENT_CMD
;
let
stim
=
&
mut
resources
.ITM.stim
[
0
];
iprintln!
(
stim
,
"entered on: {:?}"
,
scheduled
);
match
cmd
.cmd_type
{
CmdType
::
On
=>
{
schedule
.on
(
scheduled
+
(
cmd
.half_period
)
.cycles
());
if
*
resources
.IS_LED_ON
==
false
{
resources
.LED
.set_high
();
*
resources
.IS_LED_ON
=
true
;
}
},
CmdType
::
Off
=>
{
let
_
=
spawn
.off
();
},
CmdType
::
Set
=>
{
schedule
.off
(
scheduled
+
(
cmd
.half_period
)
.cycles
());
if
*
resources
.IS_LED_ON
==
false
{
resources
.LED
.set_high
();
*
resources
.IS_LED_ON
=
true
;
}
},
}
}
#[task(priority
=
1
,
resources
=
[
LED,
IS_LED_ON
]
)]
#[task(priority
=
1
,
schedule
=
[
off,
on]
,
resources
=
[
CURRENT_CMD
,
LED
,
IS_LED_ON
,
ITM
],
spawn
=
[
on
])]
fn
off
()
{
resources
.LED
.set_low
();
*
resources
.IS_LED_ON
=
false
;
let
cmd
=
resources
.CURRENT_CMD
;
let
stim
=
&
mut
resources
.ITM.stim
[
0
];
iprintln!
(
stim
,
"entered off: {:?}"
,
scheduled
);
match
cmd
.cmd_type
{
CmdType
::
On
=>
{
let
_
=
spawn
.on
();
},
CmdType
::
Off
=>
{
schedule
.off
(
scheduled
+
(
cmd
.half_period
)
.cycles
());
if
*
resources
.IS_LED_ON
==
true
{
resources
.LED
.set_low
();
*
resources
.IS_LED_ON
=
false
;
}
},
CmdType
::
Set
=>
{
schedule
.on
(
scheduled
+
(
cmd
.half_period
)
.cycles
());
if
*
resources
.IS_LED_ON
==
true
{
resources
.LED
.set_low
();
*
resources
.IS_LED_ON
=
false
;
}
},
}
}
#[task(priority
=
1
,
resources
=
[
ITM]
)]
...
...
@@ -216,15 +256,6 @@ const APP: () = {
iprintln!
(
stim
,
"{:?}"
,
error
);
}
#[task(priority
=
2
,
resources
=
[
TX]
,
spawn
=
[
trace_error
])]
fn
echo
(
byte
:
u8
)
{
let
tx
=
resources
.TX
;
if
block!
(
tx
.write
(
byte
))
.is_err
()
{
let
_
=
spawn
.trace_error
(
Error
::
UsartSendOverflow
);
}
}
#[interrupt(priority
=
3
,
resources
=
[
RX]
,
spawn
=
[
trace_error
,
cmd_interpretor
])]
fn
USART2
()
{
let
rx
=
resources
.RX
;
...
...
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