Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto Ruiz Garcia
Firmware
Commits
d3b54c35
Commit
d3b54c35
authored
6 years ago
by
Jake Dahl
Committed by
Beat Küng
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
more changes based on suggestions
parent
985c5f4d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib/drivers/smbus/SMBus.cpp
+17
-34
17 additions, 34 deletions
src/lib/drivers/smbus/SMBus.cpp
with
17 additions
and
34 deletions
src/lib/drivers/smbus/SMBus.cpp
+
17
−
34
View file @
d3b54c35
...
...
@@ -69,33 +69,23 @@ int SMBus::read_word(const uint8_t cmd_code, void *data)
int
SMBus
::
block_read
(
const
uint8_t
cmd_code
,
void
*
data
,
const
uint8_t
length
,
bool
use_pec
)
{
unsigned
byte_count
=
0
;
//
Length of data (32max). byte_count(1), cmd_code(2) (sometimes), pec(1) (optional)
uint8_t
rx_data
[
32
+
4
];
//
addr(wr), cmd_code, addr(r), byte_count, data (32 bytes max), pec
uint8_t
rx_data
[
32
+
5
];
int
result
=
transfer
(
&
cmd_code
,
1
,
(
uint8_t
*
)
rx_data
,
length
+
2
);
int
result
=
transfer
(
&
cmd_code
,
1
,
(
uint8_t
*
)
&
rx_data
[
3
]
,
length
+
2
);
byte_count
=
rx_data
[
0
];
uint8_t
device_address
=
get_device_address
();
rx_data
[
0
]
=
(
device_address
<<
1
)
|
0x00
;
rx_data
[
1
]
=
cmd_code
;
rx_data
[
2
]
=
(
device_address
<<
1
)
|
0x01
;
byte_count
=
rx_data
[
3
];
// byte_count, data[length], PEC
memcpy
(
data
,
&
rx_data
[
1
],
byte_count
);
memcpy
(
data
,
&
rx_data
[
4
],
byte_count
);
if
(
use_pec
)
{
uint8_t
pec
=
get_pec
(
rx_data
,
byte_count
+
4
);
// addr(wr), cmd_code, addr(r), byte_count, rx_data[]
uint8_t
device_address
=
get_device_address
();
uint8_t
full_data_packet
[
32
+
4
]
=
{};
full_data_packet
[
0
]
=
(
device_address
<<
1
)
|
0x00
;
full_data_packet
[
1
]
=
cmd_code
;
full_data_packet
[
2
]
=
(
device_address
<<
1
)
|
0x01
;
full_data_packet
[
3
]
=
byte_count
;
memcpy
(
&
full_data_packet
[
4
],
&
rx_data
[
1
],
byte_count
);
uint8_t
pec
=
get_pec
(
full_data_packet
,
byte_count
+
4
);
// First byte is byte count, followed by data.
if
(
pec
!=
((
uint8_t
*
)
rx_data
)[
byte_count
+
1
])
{
if
(
pec
!=
rx_data
[
byte_count
+
4
])
{
result
=
-
EINVAL
;
}
}
...
...
@@ -122,20 +112,13 @@ int SMBus::block_write(const uint8_t cmd_code, void *data, uint8_t byte_count, b
int
result
=
0
;
// If block_write fails, try up to 10 times.
while
(
i
<
10
)
{
result
=
transfer
((
uint8_t
*
)
buf
,
byte_count
+
2
,
nullptr
,
0
);
if
(
result
!=
PX4_OK
)
{
i
++
;
if
(
i
==
10
)
{
PX4_WARN
(
"Block_write failed 10 times"
);
result
=
-
EINVAL
;
}
while
(
i
<
10
&&
(
result
=
transfer
((
uint8_t
*
)
buf
,
byte_count
+
2
,
nullptr
,
0
))
!=
PX4_OK
)
{
i
++
;
}
}
else
{
break
;
}
if
(
i
==
10
)
{
PX4_WARN
(
"Block_write failed 10 times"
)
;
result
=
-
EINVAL
;
}
return
result
;
...
...
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