pocketcmd.h
Go to the documentation of this file.00001
00014 #ifndef NET_POCKETCMD_H
00015 #define NET_POCKETCMD_H
00016
00017 #include "pocketbus.h"
00018 #include <cfg/compiler.h>
00019
00020 #define PKTCMD_NULL 0
00021
00022 #define PKTCMD_REPLY_TIMEOUT 50
00023
00024 typedef uint16_t pocketcmd_t;
00025
00029 typedef struct PocketCmdHdr
00030 {
00031 pocketcmd_t cmd;
00032 } PocketCmdHdr;
00033
00039 STATIC_ASSERT(sizeof(pocketcmd_t) == sizeof(uint16_t));
00040
00041
00042
00043 struct PocketCmdCtx;
00044
00048 typedef struct PocketCmdMsg
00049 {
00050 struct PocketCmdCtx *cmd_ctx;
00051 pocketcmd_t cmd;
00052 pocketbus_len_t len;
00053 const uint8_t *buf;
00054 } PocketCmdMsg;
00055
00059 typedef void (*pocketcmd_hook_t)(struct PocketCmdMsg *cmd_msg);
00060
00064 typedef pocketcmd_hook_t (*pocketcmd_lookup_t)(pocketcmd_t cmd);
00065
00069 typedef struct PocketCmdCtx
00070 {
00071 struct PocketBusCtx *bus_ctx;
00072 pocketbus_addr_t addr;
00073 pocketcmd_lookup_t search;
00074 pocketcmd_t waiting;
00075 ticks_t reply_timer;
00076 } PocketCmdCtx;
00077
00083 INLINE void pocketcmd_setAddr(struct PocketCmdCtx *ctx, pocketbus_addr_t addr)
00084 {
00085 ctx->addr = addr;
00086 }
00087
00088 void pocketcmd_init(struct PocketCmdCtx *ctx, struct PocketBusCtx *bus_ctx, pocketbus_addr_t addr, pocketcmd_lookup_t search);
00089 void pocketcmd_poll(struct PocketCmdCtx *ctx);
00090 bool pocketcmd_send(struct PocketCmdCtx *ctx, pocketcmd_t cmd, const void *buf, size_t len, bool has_replay);
00091 void pocketcmd_replyNak(struct PocketCmdMsg *msg);
00092 void pocketcmd_replyAck(struct PocketCmdMsg *msg);
00093
00097 INLINE bool pocketcmd_masterSend(struct PocketCmdCtx *ctx, pocketbus_addr_t addr, pocketcmd_t cmd, const void *buf, size_t len)
00098 {
00099 pocketcmd_setAddr(ctx, addr);
00100 return pocketcmd_send(ctx, cmd, buf, len, true);
00101 }
00102
00106 INLINE bool pocketcmd_slaveReply(struct PocketCmdCtx *ctx, pocketcmd_t cmd, const void *buf, size_t len)
00107 {
00108 return pocketcmd_send(ctx, cmd, buf, len, false);
00109 }
00110
00111
00112 #endif