/*!
    \file  gd32f1x0_libopt.h
    \brief library optional for gd32f1x0
*/

/*
    Copyright (C) 2016 GigaDevice

    2016-01-15, V1.0.0, demo for GD32F1x0(x=3,5)
    2016-05-13, V2.0.0, demo for GD32F1x0(x=3,5)
*/

#ifndef BL_COMMON_H
#define BL_COMMON_H

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include "gd32f10x.h"
#include "gd32f10x_libopt.h"




#define BOOTLOADER_NVIC_OFFSET                       (0)






#define USART_BAUND    (38400)
#define DEBUG_MODE     0




typedef struct
{
	uint8_t set;
	uint16_t count;
}DELAY_COMMON;

typedef struct
{
	uint8_t enable;
	uint8_t set;
	uint16_t count;
}CTR_DELAY_COMMON;




#define NO_EVENT                     0x00000000UL
#define RS485_RECEIVE_END_EVENT      0x00000001UL
#define EVENT_CAN_RECEIVE_FINISH	 0x00000002UL
#define RS485_2_RECEIVE_END_EVENT    0x00000004UL
#define SUB_BMS_1_RS485_DISC_EVENT   0x00000008UL
#define SUB_BMS_2_RS485_DISC_EVENT   0x00000010UL
#define MEASURE_TEMPERATURE_EVENT    0x00000020UL
#define SUB_BMS_1_SEND_CMD_EVENT     0x00000040UL
#define SUB_BMS_2_SEND_CMD_EVENT     0x00000080UL
#define BMS_1_RESEND_CMD_EVENT       0x00000100UL
#define BMS_2_RESEND_CMD_EVENT       0x00000200UL
#define END_CTR_RESEND_CMD_EVENT     0x00000400UL
#define ADAS_RESEND_CMD_EVENT        0x00000800UL
#define BMS_1_SELF_TIMEOUT_EVENT     0x00001000UL
#define BMS_2_SELF_TIMEOUT_EVENT     0x00002000UL
#define END_CTR_SELF_TIMEOUT_EVENT   0x00004000UL
#define ADAS_SELF_TIMEOUT_EVENT      0x00008000UL
#define ADAS_PWM_1_TIMEOUT_EVENT     0x00010000UL
#define ADAS_PWM_2_TIMEOUT_EVENT     0x00020000UL
#define ADAS_MEAS_1_FINISH_EVENT     0x00040000UL
#define ADAS_MEAS_2_FINISH_EVENT     0x00080000UL
#define RE_INITIAL_CAN_EVENT         0x00100000UL

extern uint32_t g_event;


// 2017/9/12  19:37:50
#define UTC_INITIAL   (1505216210)  


typedef struct
{
	uint8_t set;
	uint16_t count;
}UART_TOUT;


void WatchDog_Initial(uint8_t period);


#endif /* GD32F1X0_LIBOPT_H */

