|
@@ -76,8 +76,10 @@ static void serial_irq(void) {
|
76
|
76
|
|
77
|
77
|
void serial_init(void) {
|
78
|
78
|
uart_init(UART_ID, BAUD_RATE);
|
|
79
|
+
|
79
|
80
|
gpio_set_function(UART_TX_PIN, GPIO_FUNC_UART);
|
80
|
81
|
gpio_set_function(UART_RX_PIN, GPIO_FUNC_UART);
|
|
82
|
+
|
81
|
83
|
uart_set_hw_flow(UART_ID, false, false);
|
82
|
84
|
uart_set_format(UART_ID, DATA_BITS, STOP_BITS, PARITY);
|
83
|
85
|
uart_set_fifo_enabled(UART_ID, true);
|
|
@@ -85,11 +87,30 @@ void serial_init(void) {
|
85
|
87
|
irq_set_exclusive_handler(UART_IRQ, serial_irq);
|
86
|
88
|
irq_set_enabled(UART_IRQ, true);
|
87
|
89
|
|
88
|
|
- uart_set_irq_enables(UART_ID, true, false);
|
|
90
|
+ uart_set_irq_enables(UART_ID, true, true);
|
89
|
91
|
}
|
90
|
92
|
|
91
|
93
|
void serial_write(const uint8_t *buf, size_t count) {
|
92
|
|
- rb_add(&tx, buf, count);
|
|
94
|
+ uart_set_irq_enables(UART_ID, true, false);
|
|
95
|
+
|
|
96
|
+ size_t off = 0;
|
|
97
|
+
|
|
98
|
+#ifdef SERIAL_WRITES_BLOCK_WHEN_BUFFER_FULL
|
|
99
|
+ while (count > rb_space(&tx)) {
|
|
100
|
+ size_t space = rb_space(&tx);
|
|
101
|
+ rb_add(&tx, buf + off, space);
|
|
102
|
+ count -= space;
|
|
103
|
+ off += space;
|
|
104
|
+
|
|
105
|
+ uart_set_irq_enables(UART_ID, true, true);
|
|
106
|
+ sleep_ms(1);
|
|
107
|
+ uart_set_irq_enables(UART_ID, true, false);
|
|
108
|
+ }
|
|
109
|
+#endif // SERIAL_WRITES_BLOCK_WHEN_BUFFER_FULL
|
|
110
|
+
|
|
111
|
+ rb_add(&tx, buf + off, count);
|
|
112
|
+
|
|
113
|
+ uart_set_irq_enables(UART_ID, true, true);
|
93
|
114
|
}
|
94
|
115
|
|
95
|
116
|
void serial_set_reroute(bool reroute) {
|