pocketcmd.h
Go to the documentation of this file.00001
00040 #ifndef NET_POCKETCMD_H
00041 #define NET_POCKETCMD_H
00042
00043 #include "pocketbus.h"
00044 #include <cfg/compiler.h>
00045
00046 #define PKTCMD_NULL 0
00047
00048 #define PKTCMD_REPLY_TIMEOUT 50
00049
00050 typedef uint16_t pocketcmd_t;
00051
00055 typedef struct PocketCmdHdr
00056 {
00057 pocketcmd_t cmd;
00058 } PocketCmdHdr;
00059
00065 STATIC_ASSERT(sizeof(pocketcmd_t) == sizeof(uint16_t));
00066
00067
00068
00069 struct PocketCmdCtx;
00070
00074 typedef struct PocketCmdMsg
00075 {
00076 struct PocketCmdCtx *cmd_ctx;
00077 pocketcmd_t cmd;
00078 pocketbus_len_t len;
00079 const uint8_t *buf;
00080 } PocketCmdMsg;
00081
00085 typedef void (*pocketcmd_hook_t)(struct PocketCmdMsg *cmd_msg);
00086
00090 typedef pocketcmd_hook_t (*pocketcmd_lookup_t)(pocketcmd_t cmd);
00091
00095 typedef struct PocketCmdCtx
00096 {
00097 struct PocketBusCtx *bus_ctx;
00098 pocketbus_addr_t addr;
00099 pocketcmd_lookup_t search;
00100 pocketcmd_t waiting;
00101 ticks_t reply_timer;
00102 } PocketCmdCtx;
00103
00109 INLINE void pocketcmd_setAddr(struct PocketCmdCtx *ctx, pocketbus_addr_t addr)
00110 {
00111 ctx->addr = addr;
00112 }
00113
00114 void pocketcmd_init(struct PocketCmdCtx *ctx, struct PocketBusCtx *bus_ctx, pocketbus_addr_t addr, pocketcmd_lookup_t search);
00115 void pocketcmd_poll(struct PocketCmdCtx *ctx);
00116 bool pocketcmd_send(struct PocketCmdCtx *ctx, pocketcmd_t cmd, const void *buf, size_t len, bool has_replay);
00117 void pocketcmd_replyNak(struct PocketCmdMsg *msg);
00118 void pocketcmd_replyAck(struct PocketCmdMsg *msg);
00119
00123 INLINE bool pocketcmd_masterSend(struct PocketCmdCtx *ctx, pocketbus_addr_t addr, pocketcmd_t cmd, const void *buf, size_t len)
00124 {
00125 pocketcmd_setAddr(ctx, addr);
00126 return pocketcmd_send(ctx, cmd, buf, len, true);
00127 }
00128
00132 INLINE bool pocketcmd_slaveReply(struct PocketCmdCtx *ctx, pocketcmd_t cmd, const void *buf, size_t len)
00133 {
00134 return pocketcmd_send(ctx, cmd, buf, len, false);
00135 }
00136
00137
00138 #endif