#ifndef _API_SYS_H_
#define _API_SYS_H_

#define IRQ_TMR1_VECTOR                 4
#define IRQ_TMR2_VECTOR                 5
#define IRQ_IRRX_VECTOR                 6
#define IRQ_UART_VECTOR                 14
#define IRQ_TMR3_VECTOR                 16
#define IRQ_TMR4_VECTOR                 17
#define IRQ_TMR5_VECTOR                 18
#define IRQ_PORT_VECTOR                 26
#define IRQ_SPI_VECTOR                  20
#define IRQ_I2C_VECTOR                  30

#define SW_RST_DC_IN                    1
#define SW_RST_QTEST_NORMAL             2
#define SW_RST_QTEST_ONLY_PAIR          3
#define SW_RST_FLAG                     4 //In any case, directly reset

typedef void (*isr_t)(void);

typedef u8 flash_id_t[16];

extern u16 tmr5ms_cnt;

void spiflash_get_id(flash_id_t id);

void sys_set_tmr_enable(bool tmr5ms_en, bool tmr1ms_en);
u32 sys_get_rand_key(void);

void xosc_init(void);

bool sys_irq_init(int vector, int pr, isr_t isr);           //Initialize an interrupt, pr is the priority

u16 get_random(u16 num);                                    //Get the random number between [0, num-1]
void sys_clk_output(u32 type, u32 mapping);                 //Output clock type: 0 ->xosc26m, 1 ->x26m_ 13m, 2->12m, 3->24m

u16 convert_uni2gbk(u16 code, u32 addr, u32 len);           //Enter utf16 to return the gbk code. If the code is not found, use '□'
u8 utf8_char_size(u8 code);                                 //Returns how many bytes UTF8 occupies
u16 utf8_convert_to_unicode(u8 *in, u8 char_size);          //UTF-8 to UTF-16 LE code

void sw_reset_kick(u8 source);
u8 sw_reset_source_get(void);
void set_uart0_baud(u32 baud);
void set_uart1_baud(u32 baud);
void set_uart1_baud_rc2m_clk(u32 baud);
int s_abs(int x);

u32 timer_get_tick(void);                   //Get clock tick

void sys_pe4_power_gate_set(u8 on);         //PE4 power supply switch

bool bt_get_ft_trim_value(void *rf_param);

/**
  * @brief  send a msg to the thread, msg will be processed in thread_user_func_do()
  * @param  msg between 0x80 and 0xff
  */
void thread_user_kick(u8 msg);

/**
  * @brief  process the msg which be send in thread_user_kick()
  * @param  msg between 0x80 and 0xff
  */
void thread_user_func_do(u8 msg);

#endif // _API_SYS_H_

