#include "common.h"
#include "drv_io.h"
#include "drv_can.h"
#include "app_rs485_1.h"
#include "app_rs485_2.h"
#include "app_can.h"
#include "app.h"
#include "app_end_ctr.h"
#include "measure_temprature.h"
#include "hardware_test.h"
#include "drv_io.h"

END_CTR_SELF_SEND_STATUS end_ctr_self_ss;
END_CTR_SELF_SEND_STATUS end_ctr_self_ss_new;
END_CTR_SELF_SEND_STATUS end_ctr_rsp;

DELAY_COMMON end_ctr_self_stimeout;

uint8_t Get_QD_State(void)
{
	return end_ctr_self_ss_new.qd_sta;
}

uint8_t Is_Soak(void)
{
	return end_ctr_self_ss_new.soak_sta;
}

void Shield_XL_Timeout(void)
{
	if(shield_xl.set)
	{
		if(++shield_xl.count >= SHIELD_XL_TIME)
		{
			memset(&shield_xl,0x00,sizeof(shield_xl));
		}
	}
}

void Can_End_Ctr_Self_Send_Check(CAN_FRAME*can_ctr_frame)
{
	uint16_t len;
	uint8_t *buf = can_ctr_frame->data;

	if(!memcmp(&end_ctr_self_ss,&end_ctr_self_ss_new,sizeof(END_CTR_SELF_SEND_STATUS)))
		return;
	
	memcpy(&end_ctr_self_ss,&end_ctr_self_ss_new,sizeof(END_CTR_SELF_SEND_STATUS));
	
	len = sizeof(end_ctr_self_ss);
	//
	can_ctr_frame->head.rsp = FRAME_PT_NEED_RSP;
	can_ctr_frame->head.dest = CTR_ID;
	can_ctr_frame->head.sour = SELF_ID;
	can_ctr_frame->head.index = 1;
	can_ctr_frame->head.total = (len - 1)/8 + 1;
	can_ctr_frame->head.pro   =FRAME_PRO_D;
	//
	can_ctr_frame->len = len;
	memcpy(buf,&end_ctr_self_ss,len);
	
	end_ctr_self_stimeout.set = 1;
	end_ctr_self_stimeout.count = 0;
	//
	if(!Send_Data_Can(can_ctr_frame,CTR_SELF))
	{
		//g_event |= END_CTR_RESEND_CMD_EVENT;
		//return;
	}
	
}

#ifdef CONFIG_CAN_IAP
void qws_iap_fmc_flag_clear(void)
{
	fmc_flag_clear(FMC_FLAG_BANK0_PGERR | FMC_FLAG_BANK0_WPERR | FMC_FLAG_BANK0_END);
}

void qws_iap_write_magic(uint32_t magic)
{
	uint32_t capacity = (REG32(0x1FFFF7E0) & 0xFFFF) << 10;
	uint32_t address = 0x08000000 + (capacity - 1024);
	uint32_t length, checksum, value;

	value = REG32(address + 8);
	if (magic == value) {
		return;
	}

	length = REG32(address);
	checksum = REG32(address + 4);

	fmc_unlock();

	if (value != 0xFFFFFFFF) {
		qws_iap_fmc_flag_clear();
		fmc_page_erase(address);

		qws_iap_fmc_flag_clear();
		fmc_word_program(address, length);

		qws_iap_fmc_flag_clear();
		fmc_word_program(address + 4, checksum);
	}

	if (magic != 0xFFFFFFFF) {
		qws_iap_fmc_flag_clear();
		fmc_word_program(address + 8, magic);
	}

	fmc_lock();
}

void qws_iap_reboot(void)
{
	qws_iap_write_magic(0xFFFFFFFF);
	__set_FAULTMASK(1);
	NVIC_SystemReset();
}

uint8_t qws_iap_read_string(uint8_t *buff)
{
	uint32_t address = ((uint32_t) buff[4]) << 16 | ((uint32_t) buff[3]) << 8 | buff[2];
	const char *text = (const char *) (0x08000000 + address);
	int length = strlen(text);

	if (length > 250) {
		length = 250;
	}

	buff[5] = buff[4];
	buff[4] = buff[3];
	buff[3] = buff[2];
	buff[2] = 0x00;

	memcpy(buff + 6, text, length);

	return length + 6;
}
#endif


int8_t Handle_Can_Ctr_CMD(CAN_FRAME*can_ctr_frame)
{
	uint16_t key;
	uint8_t *buf = can_ctr_frame->data;

	memcpy(&key,can_ctr_frame->data,sizeof(key));

	switch(key)
	{
		case KEY_END_CTR_COMMON:
			soak_dec_delay.enable = (buf[2]&0x01);
			break;
		case KEY_END_CTR_SWI_BAT:	
			break;
		case KEY_END_CTR_BAT_INT_EN:
			is_intelligent = buf[2];
			break;
		case KEY_END_CTR_BAT_INT_PRE:
			if(buf[2] == 1)
				CB_OPERATE_PRECEDENCE_Config = PRE_SERIES;
			else if(buf[2] == 2)
				CB_OPERATE_PRECEDENCE_Config = PRE_PARRALLEL;
			else
				return 0;
			break;
		case KEY_END_CTR_SOFT_WARE:	
			break;
		case KEY_END_CTR_SN:	
			break;
		case KEY_END_CTR_WRITER_SN:	
			Writer_SN(&buf[2]);
			break;
		case KEY_END_CTR_BAT_UPDATE_REQ:		
			break;
		case KEY_END_CTR_BAT_UPDATE:
			break;
		case KEY_END_CTR_BAT_UPDATE_EXIT:
			break;
			
		case KEY_END_CTR_DAN_CI_LI_CHENG:
			memcpy(&sheng_yu_li_cheng.sy_dan_ci_li_cheng_temp,&buf[2],sizeof(sheng_yu_li_cheng.sy_dan_ci_li_cheng_temp));
			break;
		case KEY_END_CTR_ZHEN_JI_CE_SHI:
			break;
		case KEY_END_CTR_QD:
			if(work_normal == 1)
			{
				switch(buf[2])
				{
					case 0:
						//QD_Enable(0);
						//ACC2_Enable(0);
						QD_Enable_From(0,2);
						serise_low_enable = 0;
						break;
					case 1:
						//QD_Enable(1);
						QD_Enable_From(1,3);
						if(ACC2_Is_On() == 0)
							ACC2_Enable(1);
						break;
					default:
						return 0;
				}
				delay_1ms(10);
			}
			break;
		case KEY_END_CTR_LOCK:
			switch(buf[2])
			{
				case 0:
					Lock_Enable(0);
					break;
				case 1:
					Lock_Enable(1);
					break;
				default:
					return 0;
			}
			
			break;
		case KEY_END_CTR_L_R_LIGHT:
			
			if(buf[2] == 0)
			{
				Left_Light_Enable(0);
				left_light_delay.set = 0;
				left_light_delay.count = 0;
			}
			if(buf[2] == 1)
			{
				Left_Light_Enable(1);
			}
			if(buf[2] == 2)
			{
				Left_Light_Enable(1);
				left_light_delay.set = 1;
				left_light_delay.count = 0;
			}

			if(buf[2] == 3)
			{
				Left_Light_Enable(0);
				left_light_delay.set = 1;
				left_light_delay.count = 600;
			}
			
			if(buf[3] == 0)
			{
				Right_Light_Enable(0);
				right_light_delay.set = 0;
				right_light_delay.count = 0;
			}
			if(buf[3] == 1)
			{
				Right_Light_Enable(1);
				
			}
			if(buf[3] == 2)
			{
				Right_Light_Enable(1);
				right_light_delay.set = 1;
				right_light_delay.count = 0;
			}

			if(buf[3] == 3)
			{
				Right_Light_Enable(0);
				right_light_delay.set = 1;
				right_light_delay.count = 600;
			}
			break;
		case KEY_END_CTR_CARPET_LIGHT:
			switch(buf[2])
			{
				case 0:
					Carpet_Light_Enable(0);
					break;
				case 1:
					Carpet_Light_Enable(1);
					break;
				default:
					return 0;
			}
			break;
		case KEY_END_CTR_TAIL_LIGHT:
			switch(buf[2])
			{
				case 0:				
					Tail_Light_Enable(0);	
					break;
				case 1:
					Tail_Light_Enable(1);
					break;
				default:
					return 0;
			}
			break;
		case KEY_END_CTR_ACC12:

			if(work_normal == 1)
			{
				switch(buf[2])
				{
					case 0:
						if(QD_Dect() == 0)
						{
							ACC2_Enable(0);
						}
						break;
					case 1:
						if(ACC2_Is_On() == 0)
							ACC2_Enable(1);		
						break;
					default:
						return 0;
				}
				delay_1ms(10);
			}
		
			break;
		case KEY_END_CTR_ACC12_TEST:
			if(work_normal == 1)
			{
				bms_1_test_define_error = buf[2];
				bms_2_test_define_error = buf[3];
			}
			break;
		case KEY_END_CTR_ACC12_TEST_1:
			switch(buf[2])
			{
				case 0:
					//if(QD_Dect() == 0)
					{
						ACC2_Enable(0);
					}
					break;
				case 1:
					if(ACC2_Is_On() == 0)
						ACC2_Enable(1);		
					break;
				default:
					return 0;
			}
			delay_1ms(10);
			break;
		case KEY_END_CTR_HEART_TICK:
			break;
		case KEY_END_CTR_SELF_UP:
			end_ctr_self_stimeout.set = 0;
			return 0;
#ifdef CONFIG_CAN_IAP
		case 0x42F0:
			qws_iap_reboot();
			return 0;

		case 0x42F5:
		case 0x42F6:
		case 0x42F8:
			break;
#endif
		default:
			return 0;

	}
	
	return 1;
	
}

int8_t Rsp_Can_Ctr_CMD(CAN_FRAME*can_ctr_frame)
{
	uint16_t key,len;
	uint8_t *buf = can_ctr_frame->data;
	uint8_t temp = 0,rtn = 0;
	
	memcpy(&key,can_ctr_frame->data,sizeof(key));

	switch(key)
	{
		case KEY_END_CTR_COMMON:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			end_ctr_rsp.key = KEY_END_CTR_COMMON;
			end_ctr_rsp.op_result = 0;
			len = sizeof(end_ctr_rsp);
			memcpy(buf,&end_ctr_rsp,len);
			
			buf[len++] = QD_switch_from;
			buf[len++] = power_switch_from;
			buf[len++] = (uint8_t)utc_seconds;
			buf[len++] = (uint8_t)(utc_seconds >> 8);
			
			break;
		case KEY_END_CTR_SWI_BAT:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			
			if(is_intelligent)
			{
				buf[len++] = 0;
				buf[len++] = CB_BAT_NO;
			}
			else
			{
				if(buf[len] > CB_BAT_NO && buf[len] < CB_MAX)
				{
					if(cb_operate_state != buf[len])
					{
						Battery_Change_Mode(buf[len]);	
					}
					buf[len++] = 0;
				}
				else
				{
					buf[len++] = 1;
				}
				
				buf[len++] = cb_operate_state;	
			}
			
			break;
		case KEY_END_CTR_BAT_INT_EN:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			buf[len++] = 0;
			break;	
		case KEY_END_CTR_BAT_INT_PRE:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			buf[len++] = 0;
			break;
		case KEY_END_CTR_SOFT_WARE:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			buf[len++] = 0;
			memcpy(&buf[len],soft_version,PS100_SOFTWARE_SIZE);
			len += PS100_SOFTWARE_SIZE;
			break;
		case KEY_END_CTR_SN:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			buf[len++] = 0;
			memcpy(&buf[len],sn,sizeof(sn));
			len += sizeof(sn);
			break;
		case KEY_END_CTR_WRITER_SN:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			buf[len++] = 0;
			break;
		case KEY_END_CTR_BAT_UPDATE_REQ:
			//if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
			//	return 1;
			
			rtn = 0;
			len = buf[2];
			if(len == UPDATE_BAT_1 || len == UPDATE_BAT_2)
			{
				if(len == UPDATE_BAT_1)
				{
					temp = Update_Sub_BMS_1_Software(UPDATE_STEP_REQ);
				}
				else
				{
					temp = Update_Sub_BMS_2_Software(UPDATE_STEP_REQ);
				}
				if(temp)
				{
					update_bat.ub_step = UPDATE_STEP_REQ;
					update_bat.ub_bat = buf[2];
					update_bat.ub_total = buf[4];
					update_bat.ub_total = (update_bat.ub_total<<8)|buf[3];
				}
				else
					rtn = 3;
				
			}
			else
				rtn = 1;
			
			len = 2;
			buf[len++] = rtn;
			break;
		case KEY_END_CTR_BAT_UPDATE:
			//if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
			///	return 1;

			rtn = 0;
			
			len = buf[3];
			len = (len<<8)|buf[2];
			if(len <= update_bat.ub_total)
			{
				if(len == update_bat.ub_sq || len == update_bat.ub_sq + 1)
				{
					len = buf[5];
					len = (len<<8)|buf[4];
					if(len <= sizeof(update_bat.ub_data))
					{
						update_bat.ub_step = UPDATE_STEP_DATA;
						update_bat.ub_sq = buf[3];
						update_bat.ub_sq = (update_bat.ub_sq<<8)|buf[2];
						update_bat.ub_len = buf[5];
						update_bat.ub_len = (update_bat.ub_len<<8)|buf[4];
						memcpy(update_bat.ub_data,&buf[6],update_bat.ub_len);

						//
						if(update_bat.ub_bat == UPDATE_BAT_1)
						{
							temp = Update_Sub_BMS_1_Software(UPDATE_STEP_DATA);
						}
						else
						{
							temp = Update_Sub_BMS_2_Software(UPDATE_STEP_DATA);
						}
						
						if(temp)
						{
							if(update_bat.ub_sq == update_bat.ub_total)
							{
								memset(&update_bat,0x00,sizeof(update_bat));
							}
						}
						else
							rtn = 4;
					}
					else
						rtn = 3;
				}
				else
					rtn = 2;
			}
			else
				rtn = 1;
			
			len = 2;
			buf[len++] = rtn;
			break;
		case KEY_END_CTR_BAT_UPDATE_EXIT:
			//if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
			//	return 1;

			memset(&update_bat,0x00,sizeof(update_bat));
			
			len = 2;
			buf[len++] = 0;
			break;
		case KEY_END_CTR_DAN_CI_LI_CHENG:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;

			len = 2;
			buf[len++] = sheng_yu_li_cheng.sy_yu_ji_ke_xing_shi_li_cheng;
			break;
		case KEY_END_CTR_ZHEN_JI_CE_SHI:
			Writer_HT_Flash(1);
			len = 2;
			buf[len++] = 0;
			break;
		case KEY_END_CTR_QD:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			buf[len++] = 0;
			if(work_normal == 1)
			{
				buf[len++] = QD_Dect();

				qd_dec_delay.count = QD_DEC_TIMEOUT;
				
				shield_xl.set = 1;
				shield_xl.count = 0;
				xl_dec_delay.count = 0;	
				xl_count = 0;
			}
			else
				buf[len++] = 0;
			
			break;	
		case KEY_END_CTR_LOCK:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			buf[len++] = 0;
			buf[len++] = Lock_Dect();
			break;
		case KEY_END_CTR_L_R_LIGHT:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			buf[len++] = 0;
			break;
		case KEY_END_CTR_CARPET_LIGHT:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			buf[len++] = 0;
			break;
		case KEY_END_CTR_TAIL_LIGHT:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			buf[len++] = 0;
			break;
		case KEY_END_CTR_ACC12:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			buf[len++] = 0;
			if(work_normal == 1)
			{
				buf[len++] = ACC2_Dect();
				acc2_dec_delay.count = ACC2_DEC_TIMEOUT;
			}
			else
				buf[len++] = 0;
			break;	
			
		case KEY_END_CTR_ACC12_TEST:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			buf[len++] = 0;
			break;	
		case KEY_END_CTR_ACC12_TEST_1:
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			buf[len++] = 0;
			if(work_normal == 1)
			{
				buf[len++] = ACC2_Dect();
				acc2_dec_delay.count = ACC2_DEC_TIMEOUT;
			}
			else
				buf[len++] = 0;
			break;
		case KEY_END_CTR_HEART_TICK:	
			if((can_ctr_frame->head.rsp != FRAME_PT_NEED_RSP) || end_ctr_self_stimeout.set)
				return 1;
			
			len = 2;
			buf[len++] = 0;
			break;
		case KEY_END_CTR_SELF_UP:
			return 0;
#ifdef CONFIG_CAN_IAP
		case 0x42F5:
		case 0x42F6:
			len = 3;
			buf[2] = 0;
			break;

		case 0x42F8:
			len = qws_iap_read_string(buf);
			break;
#endif
		default:
			return 0;
	}
	//
	can_ctr_frame->head.rsp = FRAME_PT_RSP;
	can_ctr_frame->head.dest = can_ctr_frame->head.sour;
	can_ctr_frame->head.sour = SELF_ID;
	can_ctr_frame->head.index = 1;
	can_ctr_frame->head.total = (len - 1)/8 + 1;
	can_ctr_frame->head.pro   =FRAME_PRO_D;
	//
	can_ctr_frame->len = len;

	//
	if(!Send_Data_Can(can_ctr_frame,CTR_RSP))
	{
		g_event |= END_CTR_RESEND_CMD_EVENT;
		return 0;
	}
	
	return 1;

}

void Check_End_Ctr_Status(void)
{
	
	if(side_stay_dec_delay.set&&side_stay_dec_delay.count >= SIDE_STAY_DEC_TIMEOUT)
	{
		memset(&side_stay_dec_delay,0x00,sizeof(side_stay_dec_delay));
		end_ctr_self_ss_new.side_sta = !Side_Stay_Dect();
	}

	if(soak_dec_delay.set&&soak_dec_delay.count >= SOAK_DEC_TIMEOUT)
	{
		soak_dec_delay.set = 0;
		soak_dec_delay.count = 0;
		end_ctr_self_ss_new.soak_sta = Soak_Dect();
	}

	if(sti_dec_delay.set&&sti_dec_delay.count >= STI_DEC_TIMEOUT)
	{
		memset(&sti_dec_delay,0x00,sizeof(sti_dec_delay));
		end_ctr_self_ss_new.sit_sta = !Sitting_Dect();
	}

	if(repair_dec_delay.set&&repair_dec_delay.count >= REPAIR_DEC_TIMEOUT)
	{
		memset(&repair_dec_delay,0x00,sizeof(repair_dec_delay));
		//end_ctr_self_ss_new.side_sta = !Repair_Key_Dect();
	}

	if(qd_dec_delay.set&&qd_dec_delay.count >= QD_DEC_TIMEOUT/*&&serise_low_qd_status == 0*/)
	{
		memset(&qd_dec_delay,0x00,sizeof(qd_dec_delay));
		end_ctr_self_ss_new.qd_sta = QD_Dect();
	}

	//xl_dec_delay
	if(xl_dec_delay.set&&xl_dec_delay.count >= XL_DEC_TIMEOUT)
	{
		xl_dec_delay.count = 0;	
		if(shield_xl.set == 0)
		{
			end_ctr_self_ss_new.xl_sta = (xl_count)?1:0;
		}
		xl_count = 0;
	}

	if(acc2_dec_delay.set&&acc2_dec_delay.count >= ACC2_DEC_TIMEOUT)
	{
		memset(&acc2_dec_delay,0x00,sizeof(acc2_dec_delay));
		end_ctr_self_ss_new.acc12_sta = ACC2_Dect();
	}

	//
	end_ctr_self_ss_new.charger_in = IS_CHARGE_IN();
	
	end_ctr_self_ss_new.moto_temp = ctr_temperature[1];

	end_ctr_self_ss_new.ps100_temp = ctr_temperature[0];
	end_ctr_self_ss_new.bms_1_status = sub_bms_1_lt_state;
	end_ctr_self_ss_new.bms_2_status = sub_bms_2_lt_state;
	end_ctr_self_ss_new.using_bms_mode = cb_operate_state;

	end_ctr_self_ss_new.nhb = (uint16_t)(sheng_yu_li_cheng.sy_ss_parm.neng_hao_bi);


	//
	end_ctr_rsp = end_ctr_self_ss_new;
	
	end_ctr_rsp.lock_sta = Lock_Dect();
	end_ctr_rsp.carpet_sta = Carpet_Dect();
	end_ctr_rsp.tail_sta = Tail_Dect();

	
}

void End_Ctr_Initial(void)
{
	 E_CTR_Initial();

	 memset(&update_bat,0x00,sizeof(update_bat));
}

void End_Ctr_Self_Send_Timeout(void)
{
	if(end_ctr_self_stimeout.set)
	{
		++end_ctr_self_stimeout.count;
		if(end_ctr_self_stimeout.count >= 300)
		{
			memset(&end_ctr_self_stimeout,0x00,sizeof(end_ctr_self_stimeout));
			g_event |= END_CTR_SELF_TIMEOUT_EVENT;
		}
		else if(end_ctr_self_stimeout.count == 200)
			g_event |= END_CTR_SELF_TIMEOUT_EVENT;
		else if(end_ctr_self_stimeout.count == 100)
			g_event |= END_CTR_SELF_TIMEOUT_EVENT;
	}
	else
		end_ctr_self_stimeout.count = 0;
	
}



DELAY_COMMON acc12_delay;

void ACC12_OVER_Loader_Timeout(void)
{
#if ACC2_USE_PWM
	/*if(acc12_delay.set)
	{
		if(++acc12_delay.count >= 1)
		{
			memset(&acc12_delay,0x00,sizeof(acc12_delay));
			gpio_bit_write(GPIOC,GPIO_PIN_15,(bit_status)0x01);
		}
	}*/
#else

	if(acc12_delay.set)
	{
	
		if((acc12_delay.count&0x01UL) == 0)
		{
			if(ACC2_Over_Loader_Dect() == 1)
			{
				acc12_delay.set = 0;
				acc12_delay.count = 0;
				
			}
			else
			{
				//ACC2_Enable(0);
				acc12_delay.count++;
			}
		}
		else
		{
			//ACC2_Enable(1);
			acc12_delay.count++;
		}
		

	}
#endif
	
}

void ACC12_OVER_Loader_Interrupt(void)
{
#if ACC2_USE_PWM
	/*if(acc12_delay.set)
			return;
		
	acc12_delay.set = 1;

	acc12_delay.count = 0;
	gpio_bit_write(GPIOC,GPIO_PIN_15,(bit_status)0x00);*/
#else

	if(acc12_delay.set)
			return;
		
	acc12_delay.set = 1;

	acc12_delay.count = 0;
#endif		
}


