Start adding bi-directional packet link
authorKeith Packard <keithp@keithp.com>
Sun, 31 May 2009 16:22:01 +0000 (09:22 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 31 May 2009 16:22:01 +0000 (09:22 -0700)
ao.h
ao_serial.c

diff --git a/ao.h b/ao.h
index 1f32ba50f4f0df2ffc3983fd5133d2323cb2070f..c4cb5bf7176d526b2ea4a4bbe887684778070a59 100644 (file)
--- a/ao.h
+++ b/ao.h
@@ -859,4 +859,68 @@ extern const char ao_version[];
 extern const char ao_manufacturer[];
 extern const char ao_product[];
 
 extern const char ao_manufacturer[];
 extern const char ao_product[];
 
+/*
+ * Fifos
+ */
+
+#define AO_FIFO_SIZE   32
+
+struct ao_fifo {
+       uint8_t insert;
+       uint8_t remove;
+       char    fifo[AO_FIFO_SIZE];
+};
+
+#define ao_fifo_insert(f,c) do { \
+       (f).fifo[(f).insert] = (c); \
+       (f).insert = ((f).insert + 1) & (AO_FIFO_SIZE-1); \
+} while(0)
+
+#define ao_fifo_remove(f,c) do {\
+       c = (f).fifo[(f).remove]; \
+       (f).remove = ((f).remove + 1) & (AO_FIFO_SIZE-1); \
+} while(0)
+
+#define ao_fifo_full(f)                ((((f).insert + 1) & (AO_FIFO_SIZE-1)) == (f).remove)
+#define ao_fifo_empty(f)       ((f).insert == (f).remove)
+
+/*
+ * ao_packet.c
+ *
+ * Packet-based command interface
+ */
+
+#define AO_PACKET_MAX  32
+#define AO_PACKET_WIN  256
+
+#define AO_PACKET_FIN  (1 << 0)
+#define AO_PACKET_SYN  (1 << 1)
+#define AO_PACKET_RST  (1 << 2)
+#define AO_PACKET_ACK  (1 << 3)
+
+struct ao_packet {
+       uint8_t         addr;
+       uint8_t         flags;
+       uint16_t        seq;
+       uint16_t        ack;
+       uint16_t        window;
+       uint8_t         len;
+       uint8_t         d[AO_PACKET_MAX];
+};
+
+uint8_t
+ao_packet_connect(uint8_t dest);
+
+uint8_t
+ao_packet_accept(void);
+
+int
+ao_packet_send(uint8_t *data, int len);
+
+int
+ao_packet_recv(uint8_t *data, int len);
+
+void
+ao_packet_init(void);
+
 #endif /* _AO_H_ */
 #endif /* _AO_H_ */
index 20bb4f9683a5c4ed3003a4147e5df9906e3b86a8..ce11694002162ea5b70ab650c25f2c6dc14cae5f 100644 (file)
 
 #include "ao.h"
 
 
 #include "ao.h"
 
-#define SERIAL_FIFO    32
-
-struct ao_fifo {
-       uint8_t insert;
-       uint8_t remove;
-       char    fifo[SERIAL_FIFO];
-};
-
 volatile __xdata struct ao_fifo        ao_usart1_rx_fifo;
 volatile __xdata struct ao_fifo        ao_usart1_tx_fifo;
 
 volatile __xdata struct ao_fifo        ao_usart1_rx_fifo;
 volatile __xdata struct ao_fifo        ao_usart1_tx_fifo;
 
-#define ao_fifo_insert(f,c) do { \
-       (f).fifo[(f).insert] = (c); \
-       (f).insert = ((f).insert + 1) & (SERIAL_FIFO-1); \
-} while(0)
-
-#define ao_fifo_remove(f,c) do {\
-       c = (f).fifo[(f).remove]; \
-       (f).remove = ((f).remove + 1) & (SERIAL_FIFO-1); \
-} while(0)
-
-#define ao_fifo_full(f)        ((((f).insert + 1) & (SERIAL_FIFO-1)) == (f).remove)
-#define ao_fifo_empty(f)       ((f).insert == (f).remove)
-
 void
 ao_serial_rx1_isr(void) interrupt 3
 {
 void
 ao_serial_rx1_isr(void) interrupt 3
 {