#include "kit_debug.h"
#ifndef DEBUG_ASSERT_UART
#include "SEGGER_RTT.h"
#else
//#include "stdio.h"
#endif

void kit_assert_param(uint8_t* file, uint32_t line)
{
	KIT_DEBUG_PRINTF("%d, %s, %d\r\n", kit_time_get_tick(), file, line);
}

void kit_assert_res(uint8_t* file, uint32_t line, uint32_t dev, kit_ret_e res)
{
	KIT_DEBUG_PRINTF("%d, %s, line:%d, dev:%d, res:%d\r\n", kit_time_get_tick(), file, line, dev, res);
}

void kit_debug_queue(uint16_t *buf, uint8_t len, uint16_t value)
{
    uint8_t i;
    for(i = 0; i < len - 1; i++)
        buf[i] = buf[i + 1];
    
    buf[i] = value;
}


void kit_debug_scope_init(const char* type, uint8_t *buf, uint16_t len)
{
#ifdef DEBUG_ASSERT_RTT
	SEGGER_RTT_ConfigUpBuffer(1, type, buf, len, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
#endif
}

void kit_debug_scope_save(uint16_t tick, uint16_t x, uint16_t y, uint16_t z)
{
#ifdef DEBUG_ASSERT_RTT	
    uint16_t buf[4];
    buf[0] = tick;
    buf[1] = x;
    buf[2] = y;
    buf[3] = z;
    SEGGER_RTT_Write(1, buf, 8);
#endif
}


#ifdef DEBUG_ASSERT_UART
#include "drv_uart.h"               

int fputc(int ch, FILE *f)
{
    drv_uart_series_sync_send(kUartDev_1, (uint8_t *)&ch, 1);	
    return (ch);
}
#endif
