55 */
66
77#include <stddef.h>
8+ #include <stdbool.h>
9+ #include <stdint.h>
810#include <esp-stub-lib/flash.h>
11+ #include <esp-stub-lib/rom_wrappers.h>
12+ #include <target/uart.h>
913#include "slip.h"
1014#include "command_handler.h"
1115
@@ -19,7 +23,25 @@ __asm__(
1923 "j esp_main;" );
2024#endif //ESP8266
2125
22- static uint8_t s_command_buffer [MAX_COMMAND_SIZE ] __attribute__((aligned (4 )));
26+ static void uart_rx_interrupt_handler ()
27+ {
28+ // This also resets the interrupt flags
29+ uint32_t intr_flags = stub_target_uart_get_intr_flags (UART_NUM_0 );
30+
31+ if ((intr_flags & UART_INTR_RXFIFO_FULL ) || (intr_flags & UART_INTR_RXFIFO_TOUT )) {
32+ uint32_t count = stub_target_uart_get_rxfifo_count (UART_NUM_0 );
33+
34+ for (uint32_t i = 0 ; i < count ; i ++ ) {
35+ uint8_t byte = stub_target_uart_read_rxfifo_byte (UART_NUM_0 );
36+ stub_lib_uart_tx_one_char (byte );
37+ slip_recv_byte (byte );
38+
39+ if (slip_is_frame_complete () || slip_is_frame_error ()) {
40+ break ;
41+ }
42+ }
43+ }
44+ }
2345
2446void esp_main (void )
2547{
@@ -34,6 +56,10 @@ void esp_main(void)
3456 void * flash_state = NULL ;
3557 stub_lib_flash_init (& flash_state );
3658
59+ stub_target_uart_wait_idle (UART_NUM_0 );
60+ stub_target_uart_init (UART_NUM_0 , 115200 );
61+ stub_target_uart_intr_attach (UART_NUM_0 , 5 , uart_rx_interrupt_handler , UART_INTR_RXFIFO_FULL | UART_INTR_RXFIFO_TOUT );
62+
3763 // Send OHAI greeting to signal stub is active
3864 const uint8_t greeting [4 ] = {'O' , 'H' , 'A' , 'I' };
3965 slip_send_frame (& greeting , sizeof (greeting ));
0 commit comments