pocketcmd.h
Go to the documentation of this file.00001
00042 #ifndef NET_POCKETCMD_H
00043 #define NET_POCKETCMD_H
00044
00045 #include "pocketbus.h"
00046 #include <cfg/compiler.h>
00047
00048 #define PKTCMD_NULL 0
00049
00050 #define PKTCMD_REPLY_TIMEOUT 50
00051
00052 typedef uint16_t pocketcmd_t;
00053
00057 typedef struct PocketCmdHdr
00058 {
00059 pocketcmd_t cmd;
00060 } PocketCmdHdr;
00061
00067 STATIC_ASSERT(sizeof(pocketcmd_t) == sizeof(uint16_t));
00068
00069
00070
00071 struct PocketCmdCtx;
00072
00076 typedef struct PocketCmdMsg
00077 {
00078 struct PocketCmdCtx *cmd_ctx;
00079 pocketcmd_t cmd;
00080 pocketbus_len_t len;
00081 const uint8_t *buf;
00082 } PocketCmdMsg;
00083
00087 typedef void (*pocketcmd_hook_t)(struct PocketCmdMsg *cmd_msg);
00088
00092 typedef pocketcmd_hook_t (*pocketcmd_lookup_t)(pocketcmd_t cmd);
00093
00097 typedef struct PocketCmdCtx
00098 {
00099 struct PocketBusCtx *bus_ctx;
00100 pocketbus_addr_t addr;
00101 pocketcmd_lookup_t search;
00102 pocketcmd_t waiting;
00103 ticks_t reply_timer;
00104 } PocketCmdCtx;
00105
00111 INLINE void pocketcmd_setAddr(struct PocketCmdCtx *ctx, pocketbus_addr_t addr)
00112 {
00113 ctx->addr = addr;
00114 }
00115
00116 void pocketcmd_init(struct PocketCmdCtx *ctx, struct PocketBusCtx *bus_ctx, pocketbus_addr_t addr, pocketcmd_lookup_t search);
00117 void pocketcmd_poll(struct PocketCmdCtx *ctx);
00118 bool pocketcmd_send(struct PocketCmdCtx *ctx, pocketcmd_t cmd, const void *buf, size_t len, bool has_replay);
00119 void pocketcmd_replyNak(struct PocketCmdMsg *msg);
00120 void pocketcmd_replyAck(struct PocketCmdMsg *msg);
00121
00125 INLINE bool pocketcmd_masterSend(struct PocketCmdCtx *ctx, pocketbus_addr_t addr, pocketcmd_t cmd, const void *buf, size_t len)
00126 {
00127 pocketcmd_setAddr(ctx, addr);
00128 return pocketcmd_send(ctx, cmd, buf, len, true);
00129 }
00130
00134 INLINE bool pocketcmd_slaveReply(struct PocketCmdCtx *ctx, pocketcmd_t cmd, const void *buf, size_t len)
00135 {
00136 return pocketcmd_send(ctx, cmd, buf, len, false);
00137 }
00138
00139
00140 #endif