You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2015/11/19 23:45:05 UTC

[2/2] incubator-mynewt-larva git commit: Change byte-swapping fns to use void pointers.

Change byte-swapping fns to use void pointers.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/95ec4caf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/95ec4caf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/95ec4caf

Branch: refs/heads/master
Commit: 95ec4cafea82a954c0a87ff23fb9b56142dc0429
Parents: e52f463
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Nov 19 14:43:44 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Nov 19 14:43:44 2015 -0800

----------------------------------------------------------------------
 net/nimble/include/nimble/ble.h | 12 +++---
 net/nimble/src/util.c           | 84 +++++++++++++++++++++---------------
 2 files changed, 55 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/95ec4caf/net/nimble/include/nimble/ble.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/ble.h b/net/nimble/include/nimble/ble.h
index 71229f2..e7d5c2f 100644
--- a/net/nimble/include/nimble/ble.h
+++ b/net/nimble/include/nimble/ble.h
@@ -62,12 +62,12 @@ struct ble_mbuf_hdr
 extern uint8_t g_dev_addr[BLE_DEV_ADDR_LEN];
 extern uint8_t g_random_addr[BLE_DEV_ADDR_LEN];
 
-void htole16(uint8_t *buf, uint16_t x);
-void htole32(uint8_t *buf, uint32_t x);
-void htole64(uint8_t *buf, uint64_t x);
-uint16_t le16toh(uint8_t *buf);
-uint32_t le32toh(uint8_t *buf);
-uint64_t le64toh(uint8_t *buf);
+void htole16(void *buf, uint16_t x);
+void htole32(void *buf, uint32_t x);
+void htole64(void *buf, uint64_t x);
+uint16_t le16toh(void *buf);
+uint32_t le32toh(void *buf);
+uint64_t le64toh(void *buf);
 /* XXX */
 
 /* BLE Error Codes (Core v4.2 Vol 2 part D) */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/95ec4caf/net/nimble/src/util.c
----------------------------------------------------------------------
diff --git a/net/nimble/src/util.c b/net/nimble/src/util.c
index 98948a4..d67cead 100644
--- a/net/nimble/src/util.c
+++ b/net/nimble/src/util.c
@@ -17,72 +17,86 @@
 #include "nimble/ble.h"
 
 void
-htole16(uint8_t *buf, uint16_t x)
+htole16(void *buf, uint16_t x)
 {
-    buf[0] = (uint8_t)x;
-    buf[1] = (uint8_t)(x >> 8);
+    uint8_t *u8ptr;
+
+    u8ptr = buf;
+    u8ptr[0] = (uint8_t)x;
+    u8ptr[1] = (uint8_t)(x >> 8);
 }
 
 void
-htole32(uint8_t *buf, uint32_t x)
+htole32(void *buf, uint32_t x)
 {
-    buf[0] = (uint8_t)x;
-    buf[1] = (uint8_t)(x >> 8);
-    buf[2] = (uint8_t)(x >> 16);
-    buf[3] = (uint8_t)(x >> 24);
+    uint8_t *u8ptr;
+
+    u8ptr = buf;
+    u8ptr[0] = (uint8_t)x;
+    u8ptr[1] = (uint8_t)(x >> 8);
+    u8ptr[2] = (uint8_t)(x >> 16);
+    u8ptr[3] = (uint8_t)(x >> 24);
 }
 
 void
-htole64(uint8_t *buf, uint64_t x)
+htole64(void *buf, uint64_t x)
 {
-    buf[0] = (uint8_t)x;
-    buf[1] = (uint8_t)(x >> 8);
-    buf[2] = (uint8_t)(x >> 16);
-    buf[3] = (uint8_t)(x >> 24);
-    buf[4] = (uint8_t)(x >> 32);
-    buf[5] = (uint8_t)(x >> 40);
-    buf[6] = (uint8_t)(x >> 48);
-    buf[7] = (uint8_t)(x >> 56);
+    uint8_t *u8ptr;
+
+    u8ptr = buf;
+    u8ptr[0] = (uint8_t)x;
+    u8ptr[1] = (uint8_t)(x >> 8);
+    u8ptr[2] = (uint8_t)(x >> 16);
+    u8ptr[3] = (uint8_t)(x >> 24);
+    u8ptr[4] = (uint8_t)(x >> 32);
+    u8ptr[5] = (uint8_t)(x >> 40);
+    u8ptr[6] = (uint8_t)(x >> 48);
+    u8ptr[7] = (uint8_t)(x >> 56);
 }
 
 uint16_t
-le16toh(uint8_t *buf)
+le16toh(void *buf)
 {
     uint16_t x;
+    uint8_t *u8ptr;
 
-    x = buf[0];
-    x |= (uint16_t)buf[1] << 8;
+    u8ptr = buf;
+    x = u8ptr[0];
+    x |= (uint16_t)u8ptr[1] << 8;
 
     return x;
 }
 
 uint32_t
-le32toh(uint8_t *buf)
+le32toh(void *buf)
 {
     uint32_t x;
+    uint8_t *u8ptr;
 
-    x = buf[0];
-    x |= (uint32_t)buf[1] << 8;
-    x |= (uint32_t)buf[2] << 16;
-    x |= (uint32_t)buf[3] << 24;
+    u8ptr = buf;
+    x = u8ptr[0];
+    x |= (uint32_t)u8ptr[1] << 8;
+    x |= (uint32_t)u8ptr[2] << 16;
+    x |= (uint32_t)u8ptr[3] << 24;
 
     return x;
 }
 
 uint64_t
-le64toh(uint8_t *buf)
+le64toh(void *buf)
 {
     uint64_t x;
+    uint8_t *u8ptr;
 
-    x = buf[0];
-    x |= (uint64_t)buf[1] << 8;
-    x |= (uint64_t)buf[2] << 16;
-    x |= (uint64_t)buf[3] << 24;
-    x |= (uint64_t)buf[4] << 32;
-    x |= (uint64_t)buf[5] << 40;
-    x |= (uint64_t)buf[6] << 48;
-    x |= (uint64_t)buf[7] << 54;
+    u8ptr = buf;
+    x = u8ptr[0];
+    x |= (uint64_t)u8ptr[1] << 8;
+    x |= (uint64_t)u8ptr[2] << 16;
+    x |= (uint64_t)u8ptr[3] << 24;
+    x |= (uint64_t)u8ptr[4] << 32;
+    x |= (uint64_t)u8ptr[5] << 40;
+    x |= (uint64_t)u8ptr[6] << 48;
+    x |= (uint64_t)u8ptr[7] << 54;
 
     return x;
 }
-