Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
cm-projects
RIOT
Commits
baf9a62a
Unverified
Commit
baf9a62a
authored
6 years ago
by
Martine Lenders
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #9301 from haukepetersen/add_core_byteorder_lebufs
core/byteorder: add uint16 from/to buffer funcs
parents
44614d53
f68b243d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/include/byteorder.h
+45
-0
45 additions, 0 deletions
core/include/byteorder.h
with
45 additions
and
0 deletions
core/include/byteorder.h
+
45
−
0
View file @
baf9a62a
...
@@ -224,6 +224,31 @@ static inline uint32_t byteorder_swapl(uint32_t v);
...
@@ -224,6 +224,31 @@ static inline uint32_t byteorder_swapl(uint32_t v);
*/
*/
static
inline
uint64_t
byteorder_swapll
(
uint64_t
v
);
static
inline
uint64_t
byteorder_swapll
(
uint64_t
v
);
/**
* @brief Read a little endian encoded unsigned integer from a buffer
* into host byte order encoded variable, 16-bit
*
* @note This function is agnostic to the alignment of the target
* value in the given buffer
*
* @param[in] buf position in a buffer holding the target value
*
* @return 16-bit unsigned integer in host byte order
*/
static
inline
uint16_t
byteorder_lebuftohs
(
const
uint8_t
*
buf
);
/**
* @brief Write a host byte order encoded unsigned integer as little
* endian encoded value into a buffer, 16-bit
*
* @note This function is alignment agnostic and works with any given
* memory location of the buffer
*
* @param[out] buf target buffer, must be able to accept 2 bytes
* @param[in] val value written to the buffer, in host byte order
*/
static
inline
void
byteorder_htolebufs
(
uint8_t
*
buf
,
uint16_t
val
);
/**
/**
* @brief Convert from host byte order to network byte order, 16 bit.
* @brief Convert from host byte order to network byte order, 16 bit.
* @see byteorder_htons()
* @see byteorder_htons()
...
@@ -418,6 +443,26 @@ static inline uint64_t ntohll(uint64_t v)
...
@@ -418,6 +443,26 @@ static inline uint64_t ntohll(uint64_t v)
return
byteorder_ntohll
(
input
);
return
byteorder_ntohll
(
input
);
}
}
static
inline
uint16_t
byteorder_lebuftohs
(
const
uint8_t
*
buf
)
{
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
return
(
uint16_t
)((
buf
[
0
]
<<
8
)
|
buf
[
1
]);
#else
return
(
uint16_t
)((
buf
[
1
]
<<
8
)
|
buf
[
0
]);
#endif
}
static
inline
void
byteorder_htolebufs
(
uint8_t
*
buf
,
uint16_t
val
)
{
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
buf
[
0
]
=
(
uint8_t
)(
val
>>
8
);
buf
[
1
]
=
(
uint8_t
)(
val
&
0xff
);
#else
buf
[
0
]
=
(
uint8_t
)(
val
&
0xff
);
buf
[
1
]
=
(
uint8_t
)(
val
>>
8
);
#endif
}
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
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