summaryrefslogtreecommitdiff
path: root/hardware/fw/serial.h
diff options
context:
space:
mode:
Diffstat (limited to 'hardware/fw/serial.h')
-rw-r--r--hardware/fw/serial.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/hardware/fw/serial.h b/hardware/fw/serial.h
new file mode 100644
index 0000000..8cec089
--- /dev/null
+++ b/hardware/fw/serial.h
@@ -0,0 +1,75 @@
+/*
+ * This file is part of the libusbhost library
+ * hosted at http://github.com/libusbhost/libusbhost
+ *
+ * Copyright (C) 2015 Amir Hammad <amir.hammad@hotmail.com>
+ *
+ *
+ * libusbhost is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __SERIAL_H__
+#define __SERIAL_H__
+
+#include <stdint.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <stdbool.h>
+
+#include "global.h"
+
+struct dma_tx_buf {
+ /* The following fields are accessed only from DMA ISR */
+ ssize_t xfr_start; /* Start index of running DMA transfer */
+ ssize_t xfr_end; /* End index of running DMA transfer plus one */
+ bool wraparound;
+ ssize_t xfr_next;
+ bool ack;
+
+
+ /* The following fields are written only from non-interrupt code */
+ ssize_t wr_pos; /* Next index to be written */
+ ssize_t wr_idx;
+ ssize_t packet_end[8];
+
+ /* The following may be accessed by anything */
+ uint8_t data[512];
+};
+
+struct __attribute__((__packed__)) ll_pkt {
+ uint32_t crc32;
+ /* CRC computed over entire packet starting here */
+ uint8_t pid;
+ uint8_t _pad;
+ uint8_t data[];
+};
+
+enum ctrl_pkt_type {
+ CTRL_PKT_RESET = 1,
+ CTRL_PKT_ACK = 2,
+};
+
+struct __attribute__((__packed__)) ctrl_pkt {
+ uint8_t type;
+ uint8_t orig_id;
+};
+
+extern volatile struct dma_tx_buf usart_tx_buf;
+
+void usart_dma_init(void);
+int usart_send_packet_nonblocking(struct ll_pkt *pkt, size_t pkt_len);
+int usart_ack_packet(uint8_t idx);
+
+#endif // __SERIAL_H__