#ifndef _U_GLOBAL_H_
#define _U_GLOBAL_H_

#include <stdint.h>
#include <stdlib.h>
#include <string.h>


//#include "u_uart.h"


//#include "driver_gpio.h"
//#include "u_main.h"
//typedef unsigned char u8;
//typedef unsigned short u16;
//#define u32 (unsigned int);

// Firmware Revision
#define U_DIS_FW_REV_STR      	    ("0130")
#define U_DIS_FW_REV_STR_LEN		strlen(U_DIS_FW_REV_STR)

#define U_DIS_HW_REV_STR      	    ("HW: v0.0 PT: v0.0.0")
#define U_DIS_HW_REV_STR_LEN		strlen(U_DIS_HW_REV_STR)

#define GPIO_BIT(x)	((x >> 4) * 8 + (x & 0x0f))

#define SYS_TIMER_TIME			(10/10) //��ʱʱ��(ms) / �̶�ֵ
#define GPIO_LVL_HIGH			(1)
#define GPIO_LVL_LOW			(0)
#define SYS_TICK				(10)
#define SYS_EVENT_MAX_NUM		(32)

//extern signed int bprintf(const char *fmt, ...);
//#define U_UART_PRINTF			    bprintf
extern void MyPrintf(char *format, ...);
#define U_UART_PRINTF  MyPrintf 

enum
{
	CLR_TS_TYPE_8_32,
	CLR_TS_TYPE_32_8,
};

typedef enum //_ag_timer_id 
{
	AG_TIMER_ID_GLO_TASK,
	AG_TIMER_ID_LIGHT_EFFECT,
	AG_TIMER_ID_RHYTHM,
	AG_TIMER_ID_LIGHT_TIME,
	AG_TIMER_ID_FLASH_SAVE,
	AG_TIMER_ID_POWER_CHECK,
	AG_TIMER_ID_TEST,
	
	AG_TIMER_ID_MAX,
}AgTimerId;

typedef enum
{
	SYS_STATE_NULL			= 0,
	
}SysRun_t;


typedef struct _g_sys
{
	SysRun_t 	run_state;
}Sys_t;

extern Sys_t g_sys;


typedef struct _sys_event 
{
	uint32_t enent_flag;
	
}SysEvent;

typedef struct _sys_event_info 
{
	uint32_t enent_flag_bit;
	uint32_t execute_time;
	void (*execute_cb)(void);
	
}SysEvenInfo;

typedef struct _analog_timer
{
	uint8_t timer_id;
	void (*cb)(void);
	//volatile uint8_t en;
	volatile uint16_t timing;
	volatile uint32_t record_time;
}AnalogTimer_t;


uint32_t get_sys_time(void);

//������
enum
{
	GLO_DEFAULT_VAL			= 0xFF, //ͨ��ȱʡֵ
	GLO_RESET				= 0,
	
	GLO_NO_ERR				= 0,
	GLO_ERR					= 1,
	
	GLO_DIS					= 0,
	GLO_EN					= 1,
	
	AG_TIMER_RECOVER		= 0,
};
void clr_format_transition(uint8_t ts_type, uint8_t ts_num, uint8_t *clr_8, uint32_t *clr_32);
void sys_param_init(void);
void ag_timer_sched(void);
uint32_t u_get_sys_time(void);
uint8_t u_ag_timer_start(AgTimerId timer_id, uint16_t timing, void (*callback)(void));
uint8_t u_ag_timer_stop(AgTimerId timer_id);

void sys_event_init(void);
uint8_t sys_event_new(uint16_t dely_time, void (*execute_cb)(void));
void sys_event_sched(void);

#endif