Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pi-transceiver-firmware
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephen D
pi-transceiver-firmware
Commits
27001441
Commit
27001441
authored
1 year ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
temp
parent
98f87dfe
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#2056
failed
1 year ago
Stage: lint
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+28
-13
28 additions, 13 deletions
src/main.rs
with
28 additions
and
13 deletions
src/main.rs
+
28
−
13
View file @
27001441
...
@@ -11,14 +11,13 @@ mod packet;
...
@@ -11,14 +11,13 @@ mod packet;
#[rtic::app(device
=
stm32f4xx_hal::pac,
peripherals
=
true
)]
#[rtic::app(device
=
stm32f4xx_hal::pac,
peripherals
=
true
)]
mod
app
{
mod
app
{
use
cortex_m
::
peripheral
::
NVIC
;
use
hal
::
block
;
use
hal
::
block
;
use
hal
::
gpio
;
use
hal
::
gpio
;
use
hal
::
pac
::{
SPI1
,
TIM5
,
USART1
};
use
hal
::
pac
::{
SPI1
,
TIM5
,
USART1
};
use
hal
::
prelude
::
*
;
use
hal
::
serial
::{
Config
,
Event
,
Serial
};
use
hal
::
serial
::{
Config
,
Event
,
Serial
};
use
hal
::
spi
::{
Mode
,
Phase
,
Polarity
,
Spi
};
use
hal
::
spi
::{
Mode
,
Phase
,
Polarity
,
Spi
};
use
hal
::
timer
::
Delay
;
use
hal
::
timer
::
Delay
;
use
hal
::{
interrupt
,
prelude
::
*
};
use
rf4463
::
config
::
RADIO_CONFIG_500_2
;
use
rf4463
::
config
::
RADIO_CONFIG_500_2
;
use
rf4463
::
Rf4463
;
use
rf4463
::
Rf4463
;
use
ringbuffer
::{
ConstGenericRingBuffer
,
RingBuffer
,
RingBufferRead
,
RingBufferWrite
};
use
ringbuffer
::{
ConstGenericRingBuffer
,
RingBuffer
,
RingBufferRead
,
RingBufferWrite
};
...
@@ -44,13 +43,15 @@ mod app {
...
@@ -44,13 +43,15 @@ mod app {
enum
SlaveCmd
{
enum
SlaveCmd
{
BufferStatus
,
BufferStatus
,
SendPacket
,
SendPacket
,
GetTemp
,
}
}
impl
SlaveCmd
{
impl
SlaveCmd
{
pub
fn
from_u8
(
i
:
u8
)
->
Option
<
Self
>
{
pub
fn
from_u8
(
i
:
u8
)
->
Option
<
Self
>
{
match
i
{
match
i
{
0
=>
Some
(
Self
::
BufferStatus
),
0x00
=>
Some
(
Self
::
BufferStatus
),
1
=>
Some
(
Self
::
SendPacket
),
0x01
=>
Some
(
Self
::
SendPacket
),
0x02
=>
Some
(
Self
::
GetTemp
),
_
=>
None
,
_
=>
None
,
}
}
}
}
...
@@ -64,6 +65,7 @@ mod app {
...
@@ -64,6 +65,7 @@ mod app {
#[shared]
#[shared]
struct
Shared
{
struct
Shared
{
radio_temp
:
f32
,
tx_buf
:
ConstGenericRingBuffer
<
Packet
,
BUFFER_LEN
>
,
tx_buf
:
ConstGenericRingBuffer
<
Packet
,
BUFFER_LEN
>
,
}
}
...
@@ -85,7 +87,7 @@ mod app {
...
@@ -85,7 +87,7 @@ mod app {
let
clocks
=
rcc
let
clocks
=
rcc
.cfgr
.cfgr
.use_hse
(
25
.MHz
())
.use_hse
(
25
.MHz
())
.sysclk
(
84
.MHz
())
.sysclk
(
100
.MHz
())
.pclk1
(
48
.MHz
())
.pclk1
(
48
.MHz
())
.pclk2
(
48
.MHz
())
.pclk2
(
48
.MHz
())
.freeze
();
.freeze
();
...
@@ -118,13 +120,9 @@ mod app {
...
@@ -118,13 +120,9 @@ mod app {
usart
.listen
(
Event
::
Rxne
);
usart
.listen
(
Event
::
Rxne
);
// enable usart interrupt
unsafe
{
NVIC
::
unmask
(
interrupt
::
USART1
);
}
(
(
Shared
{
Shared
{
radio_temp
:
0.0
,
tx_buf
:
ConstGenericRingBuffer
::
new
(),
tx_buf
:
ConstGenericRingBuffer
::
new
(),
},
},
Local
{
Local
{
...
@@ -136,17 +134,29 @@ mod app {
...
@@ -136,17 +134,29 @@ mod app {
)
)
}
}
#[idle(local
=
[
radio]
,
shared
=
[
tx_buf
])]
#[idle(local
=
[
radio]
,
shared
=
[
tx_buf
,
radio_temp
])]
fn
idle
(
mut
ctx
:
idle
::
Context
)
->
!
{
fn
idle
(
mut
ctx
:
idle
::
Context
)
->
!
{
let
mut
i
=
0
;
loop
{
loop
{
if
let
Some
(
mut
pkt
)
=
ctx
.shared.tx_buf
.lock
(|
buf
|
buf
.dequeue
())
{
if
let
Some
(
mut
pkt
)
=
ctx
.shared.tx_buf
.lock
(|
buf
|
buf
.dequeue
())
{
ctx
.local.radio
.tx
(
&
mut
pkt
.data
)
.unwrap
();
ctx
.local.radio
.tx
(
&
mut
pkt
.data
)
.unwrap
();
}
}
i
+=
1
;
// get temp every 500 packets, or whenever when idle TODO
if
i
>=
500
{
i
=
0
;
if
let
Ok
(
new_temp
)
=
ctx
.local.radio
.get_temp
()
{
ctx
.shared.radio_temp
.lock
(|
cur_temp
|
*
cur_temp
=
new_temp
);
}
}
}
}
}
}
#[task(binds
=
USART1,
local
=
[
state,
usart]
,
shared
=
[
tx_buf
])]
#[task(binds
=
USART1,
priority=
1
,
local
=
[
state,
usart]
,
shared
=
[
tx_buf
,
radio_temp
])]
fn
usart1
(
ctx
:
usart1
::
Context
)
{
fn
usart1
(
mut
ctx
:
usart1
::
Context
)
{
let
state
=
ctx
.local.state
;
let
state
=
ctx
.local.state
;
let
usart
=
ctx
.local.usart
;
let
usart
=
ctx
.local.usart
;
let
mut
buf
=
ctx
.shared.tx_buf
;
let
mut
buf
=
ctx
.shared.tx_buf
;
...
@@ -174,6 +184,11 @@ mod app {
...
@@ -174,6 +184,11 @@ mod app {
*
state
=
SlaveState
::
RecvPacket
(
Packet
::
default
());
*
state
=
SlaveState
::
RecvPacket
(
Packet
::
default
());
}
}
SlaveCmd
::
GetTemp
=>
{
let
temp
=
ctx
.shared.radio_temp
.lock
(|
x
|
*
x
);
usart
.bwrite_all
(
&
temp
.to_le_bytes
())
.unwrap
();
}
}
}
}
}
}
}
...
...
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