pocketbus.h
Go to the documentation of this file.00001 00039 #ifndef NET_POCKETBUS_H 00040 #define NET_POCKETBUS_H 00041 00042 #include "cfg/cfg_pocketbus.h" /* for CONFIG_POCKETBUS_BUFLEN */ 00043 #include <cfg/compiler.h> 00044 00045 #include <algo/rotating_hash.h> 00046 00047 #include <drv/ser.h> 00048 00049 #include <kern/kfile.h> 00050 00055 #define POCKETBUS_STX 0x02 //ASCII STX 00056 #define POCKETBUS_ETX 0x03 //ASCII ETX 00057 #define POCKETBUS_ESC 0x1B //ASCII ESC 00058 #define POCKETBUS_ACK 0x06 //ASCII ACK 00059 #define POCKETBUS_NAK 0x15 //ASCII NAK 00060 /*\}*/ 00061 00062 #define POCKETBUS_BROADCAST_ADDR 0xFFFF 00063 00064 00067 typedef uint16_t pocketbus_len_t; 00068 00072 typedef uint16_t pocketbus_addr_t; 00073 00077 typedef struct PocketBusHdr 00078 { 00079 #define POCKETBUS_VER 1 00080 uint8_t ver; 00081 pocketbus_addr_t addr; 00082 } PocketBusHdr; 00083 00087 typedef struct PocketBusCtx 00088 { 00089 struct KFile *fd; 00090 bool sync; 00091 bool escape; 00092 rotating_t in_cks; 00093 rotating_t out_cks; 00094 pocketbus_len_t len; 00095 uint8_t buf[CONFIG_POCKETBUS_BUFLEN]; 00096 } PocketBusCtx; 00097 00101 typedef struct PocketMsg 00102 { 00103 struct PocketBusCtx *ctx; 00104 pocketbus_addr_t addr; 00105 pocketbus_len_t len; 00106 const uint8_t *payload; 00107 } PocketMsg; 00108 00114 STATIC_ASSERT(sizeof(pocketbus_addr_t) == sizeof(uint16_t)); 00115 STATIC_ASSERT(sizeof(rotating_t) == sizeof(uint16_t)); 00116 /*\}*/ 00117 00118 void pocketbus_putchar(struct PocketBusCtx *ctx, uint8_t c); 00119 void pocketbus_begin(struct PocketBusCtx *ctx, pocketbus_addr_t addr); 00120 void pocketbus_write(struct PocketBusCtx *ctx, const void *_data, size_t len); 00121 void pocketbus_end(struct PocketBusCtx *ctx); 00122 00123 void pocketbus_send(struct PocketBusCtx *ctx, pocketbus_addr_t addr, const void *data, size_t len); 00124 bool pocketbus_recv(struct PocketBusCtx *ctx, struct PocketMsg *msg); 00125 void pocketbus_init(struct PocketBusCtx *ctx, struct KFile *fd); 00126 00127 #endif /* NET_POCKETBUS_H */
