-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kitty: initial integration with the serial sDDF sub-system
This patch changes MicroPython to make use of the UART driver in sDDF instead of implementing it's own. The commit message says 'initial' as I am not completely satisfied with the implementation.
- Loading branch information
1 parent
3a5f801
commit 7fb3912
Showing
10 changed files
with
210 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,67 @@ | ||
#include <microkit.h> | ||
#include <unistd.h> | ||
#include "micropython.h" | ||
#include "py/mpconfig.h" | ||
#include "uart.h" | ||
#include <sddf/serial/shared_ringbuffer.h> | ||
|
||
// @ivanv: TEMPORARY until the meson serial driver is in sDDF | ||
extern ring_handle_t serial_rx_ring; | ||
extern ring_handle_t serial_tx_ring; | ||
|
||
// Receive single character, blocking until one is available. | ||
int mp_hal_stdin_rx_chr(void) { | ||
return uart_get_char(); | ||
// Wait for notification from RX multiplexor. | ||
mp_blocking_events = mp_event_source_serial; | ||
co_switch(t_event); | ||
mp_blocking_events = mp_event_source_none; | ||
// Dequeue buffer and return char | ||
uintptr_t buffer = 0; | ||
unsigned int buffer_len = 0; | ||
void *cookie = 0; | ||
int ret = dequeue_used(&serial_rx_ring, &buffer, &buffer_len, &cookie); | ||
if (ret) { | ||
microkit_dbg_puts("MP|ERROR: could not dequeue serial RX used buffer\n"); | ||
return 0; | ||
} | ||
|
||
char ch = ((char *)buffer)[0]; | ||
|
||
ret = enqueue_free(&serial_rx_ring, buffer, BUFFER_SIZE, cookie); | ||
if (ret) { | ||
microkit_dbg_puts("MP|ERROR: could not enqueue serial RX free buffer\n"); | ||
return 0; | ||
} | ||
|
||
return ch; | ||
} | ||
|
||
// Send the string of given length. | ||
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { | ||
uintptr_t buffer = 0; | ||
unsigned int buffer_len = 0; | ||
void *cookie = 0; | ||
int ret = dequeue_free(&serial_tx_ring, &buffer, &buffer_len, &cookie); | ||
if (ret) { | ||
microkit_dbg_puts("MP|ERROR: could not dequeue serial TX free buffer\n"); | ||
return; | ||
} | ||
|
||
// @ivanv, fix | ||
if (buffer_len < len) { | ||
microkit_dbg_puts("MP|ERROR: todo, handle large buffers in serial"); | ||
return; | ||
} | ||
|
||
// @ivanv: use memcpy instead? Wait for libc integration first | ||
char *str_buf = (char *) buffer; | ||
for (int i = 0; i < len; i++) { | ||
uart_put_char(str[i]); | ||
str_buf[i] = str[i]; | ||
} | ||
|
||
ret = enqueue_used(&serial_tx_ring, buffer, len, cookie); | ||
// @ivanv: this error condition is a real possibilily and should be handled properly | ||
if (ret) { | ||
microkit_dbg_puts("MP|ERROR: could not enqueue used serial TX buffer\n"); | ||
} | ||
|
||
microkit_notify(SERIAL_TX_CH); | ||
} |
Oops, something went wrong.