Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Boardcore
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
Emilio Corigliano
Skyward Boardcore
Commits
fcbb7f4d
Commit
fcbb7f4d
authored
2 years ago
by
Davide Mor
Browse files
Options
Downloads
Patches
Plain Diff
[sx1278] Improved reliability of Fsk read
parent
1420c0ac
Branches
sx1278
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/shared/radio/SX1278/SX1278Fsk.cpp
+45
-18
45 additions, 18 deletions
src/shared/radio/SX1278/SX1278Fsk.cpp
with
45 additions
and
18 deletions
src/shared/radio/SX1278/SX1278Fsk.cpp
+
45
−
18
View file @
fcbb7f4d
...
...
@@ -240,11 +240,19 @@ ssize_t SX1278Fsk::receive(uint8_t *pkt, size_t max_len)
// TODO: Maybe flush stuff?
uint8_t
len
=
0
;
bool
crc_ok
=
false
;
bool
length_ok
;
bool
crc_ok
;
do
{
length_ok
=
false
;
crc_ok
=
false
;
// Current FIFO read progress
uint8_t
cur_len
=
0
;
// Have we received payload ready yet? (aka the whole packet is in the
// FIFO)
bool
payload_ready
=
false
;
// Special wait for fifo level/payload ready, release the lock at this
// stage
...
...
@@ -254,48 +262,67 @@ ssize_t SX1278Fsk::receive(uint8_t *pkt, size_t max_len)
RegIrqFlags
::
PAYLOAD_READY
)
!=
0
&&
crc_enabled
)
{
payload_ready
=
true
;
crc_ok
=
checkForIrqAndReset
(
RegIrqFlags
::
CRC_OK
,
0
)
!=
0
;
}
// Record RSSI here, it's where it is the most accurate
last_rx_rssi
=
getRssi
();
// Now
first
packet
bit
// Now
read
packet
length
{
SPITransaction
spi
(
getSpiSlave
());
len
=
spi
.
readRegister
(
REG_FIFO
);
}
while
(
cur_len
<
len
)
{
// Calculate next read_size, remember, the FIFO will be at least
// FIFO_LEN / 2 filled at this point!
int
read_size
=
std
::
min
((
int
)(
len
-
cur_len
),
FIFO_LEN
/
2
);
int
read_size
=
std
::
min
((
int
)
len
,
FIFO_LEN
/
2
);
// Skip 0 sized read
if
(
read_size
!=
0
)
// Read the packet chunk
{
SPITransaction
spi
(
getSpiSlave
());
spi
.
readRegisters
(
REG_FIFO
,
&
tmp_pkt
[
cur_len
],
read_size
);
}
// Advance the read pointer
cur_len
+=
read_size
;
}
// Then read the other chunks
while
(
cur_len
<
len
)
// If the payload went from high to low, this means we have read the
// whole packet
if
(
payload_ready
&&
checkForIrqAndReset
(
0
,
RegIrqFlags
::
PAYLOAD_READY
)
!=
0
)
{
// Check if we have read the correct amount of data
length_ok
=
cur_len
==
len
;
break
;
}
else
if
(
cur_len
==
len
)
{
// We have read the whole packet, but PAYLOAD_READY did not
// trigger, something went wrong!
length_ok
=
false
;
break
;
}
// Ok there is still more data, wait for it
if
((
waitForIrq
(
guard_mode
,
RegIrqFlags
::
FIFO_LEVEL
|
RegIrqFlags
::
PAYLOAD_READY
,
0
)
&
RegIrqFlags
::
PAYLOAD_READY
)
!=
0
&&
crc_enabled
)
{
payload_ready
=
true
;
crc_ok
=
checkForIrqAndReset
(
RegIrqFlags
::
CRC_OK
,
0
)
!=
0
;
}
SPITransaction
spi
(
getSpiSlave
());
int
read_size
=
std
::
min
((
int
)(
len
-
cur_len
),
FIFO_LEN
/
2
);
spi
.
readRegisters
(
REG_FIFO
,
&
tmp_pkt
[
cur_len
],
read_size
);
cur_len
+=
read_size
;
}
// For some reason this sometimes happen?
}
while
(
len
==
0
);
if
(
len
>
max_len
||
(
!
crc_ok
&&
crc_enabled
))
if
(
len
>
max_len
||
(
!
crc_ok
&&
crc_enabled
)
||
!
length_ok
)
return
-
1
;
// Finally copy the packet to the destination
...
...
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