/* Compute checksum */
rotating_update(ctx->buf, ctx->len, &ctx->in_cks);
- rotating_t recv_cks = be16_to_cpu(*((rotating_t *)(ctx->buf + ctx->len)));
+ uint8_t cks_h = *(ctx->buf + ctx->len);
+ uint8_t cks_l = *(ctx->buf + ctx->len + 1);
+
+ rotating_t recv_cks = (cks_h << 8) | cks_l;
/* Checksum check */
if (recv_cks == ctx->in_cks)
{
- PocketBusHdr *hdr = (PocketBusHdr *)(ctx->buf);
+ PocketBusHdr *hdr = (PocketBusHdr *)ctx;
+
/* Check packet version */
if (hdr->ver == POCKETBUS_VER)
{
*/
typedef struct PocketBusCtx
{
+ uint8_t buf[CONFIG_POCKETBUS_BUFLEN]; ///< receiving Buffer
struct KFile *fd; ///< File descriptor
bool sync; ///< Status flag: true if we have received an STX, false otherwise
bool escape; ///< Status flag: true if we are in escape mode, false otherwise
rotating_t in_cks; ///< Checksum computation for received data.
rotating_t out_cks; ///< Checksum computation for transmitted data.
pocketbus_len_t len; ///< Received length
- uint8_t buf[CONFIG_POCKETBUS_BUFLEN]; ///< receiving Buffer
} PocketBusCtx;
+STATIC_ASSERT(offsetof(PocketBusCtx, buf) == 0);
/**
* Structure holding pocketBus message parameters.
*/
#include <drv/timer.h>
#include <cpu/byteorder.h>
+#include <cpu/detect.h>
#include <string.h>
if (msg.addr == ctx->addr ||
msg.addr == POCKETBUS_BROADCAST_ADDR)
{
- const PocketCmdHdr *hdr = (const PocketCmdHdr *)msg.payload;
+
+ #if CPU_AVR
+ const PocketCmdHdr *hdr = (const PocketCmdHdr *)msg.payload;
+ #else
+ #if !CPU_ARM
+ #warning Fix alignment problem..
+ /*
+ * The code below make one memcopy, this the only way to
+ * solve alignment problem on ARM. If you are use other
+ * architecture you should find other way to optimize
+ * this code.
+ */
+ #endif
+ PocketCmdHdr hd;
+ memcpy(&hd, msg.payload, sizeof(PocketCmdHdr));
+ const PocketCmdHdr *hdr = &hd;
+ #endif
+
pocketcmd_t cmd = be16_to_cpu(hdr->cmd);
/* We're no longer waiting for a reply (in case we were) */