
#ifndef __MAIN_DEF__
#define __MAIN_DEF__

#include "define.h"

typedef struct {
	u32				head, tail;
	u32				msgId[MAX_TX_RING];
	u32				len[MAX_TX_RING];
	u8				data[MAX_TX_RING][MAX_CAN_BUFFER];

	int				error;

	int				bus_off;
	user_callback	bus_off_callback;
	int				param;

	u32				rx_cnt;
	u32				tx_cnt;
} CAN_s;

typedef struct {
    u32				cmd_idx;
    char			cmd_buf[MAX_COMMAND_BUF];
	uint8_t			cmd_buf_no[MAX_COMMAND_BUF];
    char			ubuf[MAX_COMMAND_BUF];
    u32				ubuf_head, ubuf_tail;

	char			utemp[32];		// uart 0 temp buffer

	uint8_t 		Debug_test_No;

	/* ----------------------------------------- */

    char			bbuf[MAX_COMMAND_BUF];
    u32				bbuf_head, bbuf_tail;

	char			btemp[32];		// uart 2 temp buffer



    char			uart10_buf[MAX_COMMAND_BUF];
	char			uart13_buf[MAX_COMMAND_BUF];
	char			uart1_buf[MAX_COMMAND_BUF];
	char			uart9_buf[MAX_COMMAND_BUF];
	
    u32				uart10_buf_head, uart10_buf_tail;
	u32				uart13_buf_head, uart13_buf_tail;
	u32				uart1_buf_head,  uart1_buf_tail;
	u32				uart9_buf_head,  uart9_buf_tail;


	char			uart10_temp[32];
	char			uart13_temp[32];
	char			uart1_temp[32];
	char			uart9_temp[32];



	/* ----------------------------------------- */

	CAN_s			can[MAX_CAN_INST];

	/* ----------------------------------------- */

	volatile u64	tmr_cnt;
	volatile u64	x500us;

	/* ----------------------------------------- */

	int				led_flag;

	/* ----------------------------------------- */
	u32				pwm_max_tick;
	u32				pwm_freq;
	float			pwm_duty[MAX_PWM];

	/* --- callbacks --- */
	user_callback	ig_callback;
	int				param;

	uint16_t 		ADC0;
	uint16_t 		ADC1;
	uint16_t 		ADC2;
	uint16_t 		ADC3;
	uint16_t 		ADC4;
	
	uint16_t		AIN_bat;

} GVAR_s;

/* ------------------------------------------------------------------------ */

#ifdef __APP_MAIN__
	#define EXT_APP_MAIN
#else
	#define EXT_APP_MAIN    extern
#endif

EXT_APP_MAIN        GVAR_s  gb;


EXT_APP_MAIN void task_500us(void);
EXT_APP_MAIN void task_1ms(void);
EXT_APP_MAIN void task_2ms(void);
EXT_APP_MAIN void task_5ms(void);
EXT_APP_MAIN void task_10ms(void);
EXT_APP_MAIN void task_20ms(void);
EXT_APP_MAIN void task_50ms(void);
EXT_APP_MAIN void task_100ms(void);
EXT_APP_MAIN void task_200ms(void);
EXT_APP_MAIN void task_1s(void);


#endif	// __MAIN_DEF__

