#include "wm_include.h"
#include "shell_io/static_fifo.h"

static_fifo_declare(uart0_char_fifo, 256, unsigned char, char);
extern int sendchar(int ch);

s16 uart0_rx_callback(u16 len, void *user_data)
{
    u8 buff[256] = "";
    int data_len = tls_uart_read(TLS_UART_0, (u8 *) buff, 256);
    for(int i = 0; i < data_len; i++)
        fifo_push(uart0_char_fifo, buff[i]);
    return 0;
}

int shell_getc(char *ch)
{
    //Do not forget to sleep a bit to let the idle task run ...
    tls_os_time_delay(5);
    if(is_fifo_empty(uart0_char_fifo))
        return 0;   

    *ch = fifo_pop_unsafe(uart0_char_fifo); 
    return 1;
    //return tls_uart_read(TLS_UART_0, (u8 *) ch, 1);
}

void low_level_write_char(char ch)
{
    (void)sendchar((int)ch);
}
