U20_\app\HAL:差异

/****************************************************************************
 * File Name: hal_SuppliesAuth.c
 *
 * Description:
 *					hal_SuppliesAuth
 *
 * --------------------------------------------------------------------
 * Revision	Author		Date		Comment
 * --------------------------------------------------------------------
 * 1.0          Junrong         2021/11/14		Original
 *
 *****************************************************************************/
#include "hal.h"
#include "hal_SuppliesAuth.h"
//#include "interface.h"
#include "yc_qspi.h"
#include "yc_trng.h"
#include "libPTAuthHF.h"
#include "yc_wdt.h"
#include "driver_iwdg.h"
#include "api_supplies.h"
#include "hal_SuppliesAuth.h"
//#include "api_para_set.h"
#include "api_para_set.h"

#define UART_SUPPLIES_AUTH  UART1
//#define TIMEOUT             10000
#define TIMEOUT             10000
//#define  SUPPLIES_AUTH_PASSWORD     "Q2043"
#define  SUPPLIES_AUTH_PASSWORD     "12345"
#define  RFID_UART_BAUD			    9600

SUPPLIES_ENUM supplies_info;
uint8_t Supplies_Info_Buf[] ={0,0};

BOOL SUPPLIES_CHECK_OK = false ;
PAPER_COLOUR_FEATURE_STR Paper_Colour_Struct = {
  .Enum_Paper_Color      = ENUM_OTHER_PAPER,
  .Paper_Colour_Feature  = 0
};
/*******************************************************************************
* 名称:		portPTAUTH_CommDataWrite       
* 描述:		RFID 串口 写数据 
* 输入参数:	无  
* 输出参数:	无   
* 其它:		无   
*******************************************************************************/
void portPTAUTH_CommDataWrite(BYTE addr, BYTE value)
{

    BYTE buf[2];
    buf[0] = addr /*& 0x3F*/;
    buf[1] = value;
    UART_SendData(UART_SUPPLIES_AUTH, buf[0]);
//	 MyPrintf("buf[0]=%2x\r\n",buf[0]);
    UART_SendData(UART_SUPPLIES_AUTH, buf[1]);
   
//	MyPrintf("buf[1]=%2x\r\n",buf[1] );
}

/*******************************************************************************
* 名称:		portPTAUTH_CommDataRead       
* 描述:		RFID 串口 读数据 
* 输入参数:	无  
* 输出参数:	无   
* 其它:		无   
*******************************************************************************/
BYTE portPTAUTH_CommDataRead(BYTE addr)           //目前读会死机
{
	volatile uint8_t  recv_byte = 0; 
	
	while(UART_IsRXFIFONotEmpty(UART_SUPPLIES_AUTH))
	{
		
		recv_byte = UART_ReceiveData(UART_SUPPLIES_AUTH);
	//	MyPrintf("recv_byte=%2x\r\n",recv_byte);
//		vTaskDelay(2); /*  延时2个tick */
	}
    // Send address
    UART_SendData(UART_SUPPLIES_AUTH, addr | 0x80);
    // Receive data
	for(UINT16 i = 0; i < TIMEOUT; i++)
    {
		IWDG_Feed;							//喂狗 ,天线没调好的时候不喂狗会自动关机
        if(UART_IsRXFIFONotEmpty(UART_SUPPLIES_AUTH))
	//	while(UART_IsRXFIFONotEmpty(UART_SUPPLIES_AUTH))
        {
            recv_byte = UART_ReceiveData(UART_SUPPLIES_AUTH);
       //    MyPrintf("R:%02X%02X\r\n", addr, recv_byte);
//			MyPrintf("recv_byte2=%02x\r\n",recv_byte);
//			vTaskDelay(5); /*  延时2个tick */
            return recv_byte;
        }
	}

	return 0x00;
}

void portPTAUTH_CommSetUartBaudrate(UINT32 baudrate)
{

    UART_DeInit(UART_SUPPLIES_AUTH);
	UART_InitTypeDef UART_InitStruct;
	UART_InitStruct.BaudRate    = baudrate;			
	UART_InitStruct.DataBits    = Databits_8b;
	UART_InitStruct.StopBits    = StopBits_1;
	UART_InitStruct.Parity      = Parity_None;
	UART_InitStruct.FlowCtrl    = FlowCtrl_None;
	UART_InitStruct.Mode        = Mode_duplex;
	UART_Init(UART_SUPPLIES_AUTH, &UART_InitStruct);

}
BYTE portPTAUTH_GenRandomByte(void)
{
//	return RandomNumber();
	uint8_t rand_value = 0;
	rand_value = GetTRNGData_8bit();
	return rand_value;
}
void portPTAUTH_Delay(UINT16 ms)
{
	delay_ms(ms);
}
#define BLACKLIST_ADDR 0x1078000
/*******************************************************************************
* 名称:		portPTAUTH_BlacklistDataWrite       
* 描述:		RFID 写黑名单 
* 输入参数:	无  
* 输出参数:	无   
* 其它:		//100byte
*******************************************************************************/
void portPTAUTH_BlacklistDataWrite(BYTE *pData, UINT16 length)  
{
	
    qspi_flash_blockerase32k(BLACKLIST_ADDR);
    qspi_flash_write(BLACKLIST_ADDR, pData, length);
}
/*******************************************************************************
* 名称:		portPTAUTH_BlacklistDataRead       
* 描述:		RFID 读黑名单 
* 输入参数:	无  
* 输出参数:	无   
* 其它:		//100byte
*******************************************************************************/
void portPTAUTH_BlacklistDataRead(BYTE *pData, UINT16 length)
{
//	MyPrintf("BDW..=%d\n",*pData);
    qspi_flash_read(BLACKLIST_ADDR, pData, length);
	
}
/*******************************************************************************
* 名称:		portPTAUTH_RecordDataWrite       
* 描述:		RFID 写保存数据 
* 输入参数:	无  
* 输出参数:	无   
* 其它:		//400-500byte 
*******************************************************************************/
void portPTAUTH_RecordDataWrite(BYTE *pData, UINT16 length)
{
//	qspi_flash_sectorerase(RFID_RECORDDATA_INNERFLASH_ADDR);	//先进行擦除 
//	qspi_flash_write(RFID_RECORDDATA_INNERFLASH_ADDR,pData,length);	//再写入数据进去  
}

/*******************************************************************************
* 名称:		portPTAUTH_RecordDataRead       
* 描述:		RFID 读保存数据 
* 输入参数:	无  
* 输出参数:	无   
* 其它:		//400-500byte 
*******************************************************************************/
void portPTAUTH_RecordDataRead(BYTE *pData, UINT16 length)
{
//	qspi_flash_read(RFID_RECORDDATA_INNERFLASH_ADDR,pData,length);	//从QSPI里读出数据(非加密方式)
}


void portPTAUTH_DBG(char *pMsg)
{
	MyPrintf(pMsg); 
}


#define  RFID_RESET_LOW          	(GPIO_ResetBits(PORT_RFID_RESET, PIN_RFID_RESET))
#define  RFID_RESET_HIGH        	(GPIO_SetBits(PORT_RFID_RESET, PIN_RFID_RESET))

#define  PIN_RFID_RESET				GPIO_Pin_6
#define  PORT_RFID_RESET			GPIOA
#define  PIN_UART1_TX				GPIO_Pin_15
#define  PORT_UART1_TX				GPIOA
#define  PIN_UART1_RX				GPIO_Pin_14
#define  PORT_UART1_RX				GPIOA

void SuppliseAuth_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStruct;
	GPIO_InitStruct.GPIO_Pin = PIN_RFID_RESET;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(PORT_RFID_RESET, &GPIO_InitStruct);
	GPIO_Config(PORT_RFID_RESET, PIN_RFID_RESET, OUTPUT_HIGH); 
	
	//复位  
	(GPIO_SetBits(PORT_RFID_RESET, PIN_RFID_RESET));
	delay_ms(50);
	(GPIO_ResetBits(PORT_RFID_RESET, PIN_RFID_RESET));
	delay_ms(50);
	(GPIO_SetBits(PORT_RFID_RESET, PIN_RFID_RESET));
	delay_ms(50);
	
	/* Configure serial ports 0 RX and TX for IO. */
	GPIO_Config(PORT_UART1_TX, PIN_UART1_TX, UART1_TXD);
	GPIO_Config(PORT_UART1_RX, PIN_UART1_RX, UART1_RXD);
    
	UART_InitTypeDef UART_InitStruct;
	UART_InitStruct.BaudRate    = RFID_UART_BAUD;			
	UART_InitStruct.DataBits    = Databits_8b;
	UART_InitStruct.StopBits    = StopBits_1;
	UART_InitStruct.Parity      = Parity_None;
	UART_InitStruct.FlowCtrl    = FlowCtrl_None;
	UART_InitStruct.Mode        = Mode_duplex;
	UART_Init(UART_SUPPLIES_AUTH, &UART_InitStruct);
    TRNG_Init();
    PTAuth_Init(SUPPLIES_AUTH_PASSWORD);

}

//BOOL SuppliseAuth_Reset(void)   //
//{
	(GPIO_SetBits(PORT_RFID_RESET, PIN_RFID_RESET));
	vTaskDelay(50);
	(GPIO_ResetBits(PORT_RFID_RESET, PIN_RFID_RESET));
	vTaskDelay(50);
	(GPIO_SetBits(PORT_RFID_RESET, PIN_RFID_RESET));
	vTaskDelay(50);
    PTAuth_Init(SUPPLIES_AUTH_PASSWORD);
//}
BOOL SuppliseAuth_Check(UINT32 decLen, UINT32 *pLastLen)
{
    ENUM_PTAUTH_ERROR_CODE status;
    ENUM_SUPPLIES_TYPE supType = 0;
	uint32_t LastLen_Receive = 0;
	static uint16_t Error_Blacklist_Count = 0;
	static uint16_t Error_SupType_Count = 0;
    status = PTAuth_Check(decLen, pLastLen, &supType);
	
//	vTaskDelay(5); /*  延时2个tick */
	LastLen_Receive = *pLastLen ;
	MyPrintf("status:%d\r\n", status);	  
	MyPrintf("pLastLen:%d\r\n", LastLen_Receive);
	
    if(status != PTAUTH_NO_ERROR)
    {
//		MyPrintf("rfid-aaaaaaaaa:%d\r\n");
		if(status == PTAUTH_ERROR_BLACKLIST)    //黑名单
		{
//			Error_Blacklist_Count++;
	MyPrintf("supplies-----aa\r\n");
//		}else{
//			Error_Blacklist_Count = 0;
//		}
//        if(10 <= Error_Blacklist_Count)	
//		{
				
				SUPPLIES_CHECK_OK = false ;
				supplies_info = OTHER_SUPPLIES;
				Supplies_Info_Buf[0] = PAPER_NONE;
				Supplies_Info_Buf[1] = 0;
	//			Error_Blacklist_Count = 0;
				if(!appStatus.PaperTypeHasBeenSetFlag){
					if((supType >= SUPPLIES_U20_GAP_PAPER_1430_BLUE)&&(supType <= 254))   //201-254为间隙纸
						Store_Para.Print_Paper_Type_Para.PrintPaperType = PAPER_GAP;
					else if((supType >= SUPPLIES_U20_BLACK_PAPER_1240)&&(supType <= 40))    //36-40为黑标纸
						Store_Para.Print_Paper_Type_Para.PrintPaperType = PAPER_BLACKLABLE;				
					Para_Store_PrintPaper_Type_Write();
					appStatus.PaperTypeHasBeenSetFlag = true;
				}
			return 0;
		}
    }
//	MyPrintf("supType:%d\r\n", supType);
//    if((supType > 40) && (supType < SUPPLIES_U20_GAP_PAPER_1430))  //不是U20耗材
	if(((supType > 254) || (supType < SUPPLIES_U20_GAP_PAPER_1430_BLUE))&&((supType < SUPPLIES_U20_BLACK_PAPER_1240)||(supType > 40)))  //不是U20耗材		
    {	
		Error_SupType_Count++;
	}else {
		Error_SupType_Count = 0;
	}
	if(10 <= Error_SupType_Count ){
//		MyPrintf("supplies--------00\r\n");
		SUPPLIES_CHECK_OK = false ;
		supplies_info = OTHER_SUPPLIES;
		Supplies_Info_Buf[0] = PAPER_NONE;
		Supplies_Info_Buf[1] = 0;   
		appStatus.PaperTypeHasBeenSetFlag = false ;
		Error_SupType_Count = 0;
        return 0;               
    }
	else if(100>LastLen_Receive)      //剩余长度小于100
	{
//		MyPrintf("supplies--------11\r\n");
		SUPPLIES_CHECK_OK = false ;
		supplies_info = OTHER_SUPPLIES;
		if((supType >= SUPPLIES_U20_GAP_PAPER_1430_BLUE)&&(supType <= 254))           //间隙纸201-254
			Supplies_Info_Buf[0] = PAPER_GAP;
		else if((supType >= SUPPLIES_U20_BLACK_PAPER_1240)&&(supType <= 40))    //黑标纸36-40
			Supplies_Info_Buf[0] = PAPER_BLACKLABLE;
		
		Supplies_Info_Buf[1] = 0;             
        return 0;            
	}
	else   //耗材是对的
	{
		SUPPLIES_CHECK_OK = true ;
	   //普贴耗材标志置位
		supplies_info = PUTY_SUPPLIES;
//		MyPrintf("supplies--------11\r\n");	
		if((supType >= SUPPLIES_U20_GAP_PAPER_1430_BLUE)&&(supType <= 254))   //201-255为间隙纸
		{
//		MyPrintf("supplies--------22\r\n");	
	
			Supplies_Info_Buf[0] = PAPER_GAP;
			Supplies_Info_Buf[1] = supType;               //ID号
			if(Store_Para.Print_Paper_Type_Para.PrintPaperType!= PAPER_GAP)
				appStatus.PaperTypeHasBeenSetFlag = false ;
			if(!appStatus.PaperTypeHasBeenSetFlag){
				Store_Para.Print_Paper_Type_Para.PrintPaperType = PAPER_GAP;
				Para_Store_PrintPaper_Type_Write();
				appStatus.PaperTypeHasBeenSetFlag = true ;	
			}
		}
		else if((supType >= SUPPLIES_U20_BLACK_PAPER_1240)&&(supType <= 40))    //36-40为黑标纸
		{
			MyPrintf("supplies--------33\r\n");
			Supplies_Info_Buf[0] = PAPER_BLACKLABLE;
			Supplies_Info_Buf[1] = supType;                //ID号
			if(Store_Para.Print_Paper_Type_Para.PrintPaperType!= PAPER_BLACKLABLE)
				appStatus.PaperTypeHasBeenSetFlag = false ;
			if(!appStatus.PaperTypeHasBeenSetFlag){
				Store_Para.Print_Paper_Type_Para.PrintPaperType = PAPER_BLACKLABLE;
				Para_Store_PrintPaper_Type_Write();
				appStatus.PaperTypeHasBeenSetFlag = true ;		
			}
		}
		switch (supType) {
        case 201:
        case 207:
        case 213:
        case 219:
        case 225:
        case 231:
        case 237:
        case 243:
        case 249:
            Paper_Colour_Struct.Enum_Paper_Color = ENUM_BLUE_PAPER ;    //蓝色
            break;
		case 202:
        case 208:
        case 214:
        case 220:
        case 226:
        case 232:
        case 238:
        case 244:
        case 250:
			Paper_Colour_Struct.Enum_Paper_Color = ENUM_GREEN_PAPER ;   //绿色
            break;
		case 203:
        case 209:
        case 215:
        case 221:
        case 227:
        case 233:
        case 239:
        case 245:
        case 251:
			Paper_Colour_Struct.Enum_Paper_Color = ENUM_RED_PAPER ;   //红色
            break;
		case 204:
        case 210:
        case 216:
        case 222:
        case 228:
        case 234:
        case 240:
        case 246:
        case 252:
			Paper_Colour_Struct.Enum_Paper_Color = ENUM_ORANGE_PAPER ;   //橙色
            break;
		case 205:
        case 211:
        case 217:
        case 223:
        case 229:
        case 235:
        case 241:
        case 247:
        case 253:
			Paper_Colour_Struct.Enum_Paper_Color = ENUM_WHITE_PAPER ;   //白色
            break;
		case 206:
        case 212:
        case 218:
        case 224:
        case 230:
        case 236:
        case 242:
        case 248:
        case 254:
			Paper_Colour_Struct.Enum_Paper_Color = ENUM_YELLOW_PAPER ;   //白色
            break;
        default:
            Paper_Colour_Struct.Enum_Paper_Color = ENUM_OTHER_PAPER ;
            break;
		}
		return 1;
	}
    
}
///*******************************************************************************
//* 名称:		RFID_Test       
//* 描述:		RFID 测试 
//* 输入参数:	无  
//* 输出参数:	无   
//* 其它:		//400-500byte 
//*******************************************************************************/
//void RFID_Test()
//{
//	uint32_t curr_count = 0;
//	static uint32_t last_count = 0;
//	
//	#if USE_RFID
//		curr_count = SysTick_GetMyTick();
//		if(curr_count - last_count > 100)
//		{
//			last_count = curr_count;
//			
//			uint32_t temp_len = 0;
//			ENUM_PTAUTH_ERROR_CODE   errcode = 0;
//			ENUM_SUPPLIES_TYPE		 rfid_type = 0;
//		
//			errcode = PTAuth_Check(0,&temp_len,&rfid_type);		//长度信息 
//			//MyPrintf("type:%d,errcode:%d,len:%d\r\n",rfid_type,errcode,temp_len);
//		}
//	#endif
//}































/****************************************************************************
 * File Name: hal_SuppliesAuth.h
 *
 * Description:
 *					hal_SuppliesAuth
 *
 * --------------------------------------------------------------------
 * Revision	Author		Date		Comment
 * --------------------------------------------------------------------
 * 1.0          Junrong         2021/11/14		Original
 *
 *****************************************************************************/
#ifndef __HAL_SUPPLIES_AUTH_H__
#define __HAL_SUPPLIES_AUTH_H__

#include "hal.h"
#include "libPTAuthHF.h"

//BOOL SUPPLIES_CHECK_OK = false ;
//#define BLUE_PAPER   	201,207,213,219,225,231,237,243,249     //蓝色纸ID

typedef enum
{
	PUTY_SUPPLIES = 0,      //普贴的打印纸
	OTHER_SUPPLIES,         //其他厂家的打印纸
}SUPPLIES_ENUM;

enum
{
	ENUM_OTHER_PAPER = 0,
	ENUM_BLUE_PAPER,
	ENUM_GREEN_PAPER,
	ENUM_RED_PAPER,
	ENUM_ORANGE_PAPER,
	ENUM_WHITE_PAPER,
	ENUM_YELLOW_PAPER,
};
typedef BYTE ENUM_PAPER_COLOR_INF;

typedef struct
{
 ENUM_PAPER_COLOR_INF	Enum_Paper_Color;
 uint16_t  				Paper_Colour_Feature;
}PAPER_COLOUR_FEATURE_STR;



void SuppliseAuth_Init(void);
BOOL SuppliseAuth_Check(UINT32 decLen, UINT32 *pLastLen);
//BOOL SuppliseAuth_Reset(void);
extern SUPPLIES_ENUM supplies_info;
extern uint8_t Supplies_Info_Buf[2];
extern BOOL SUPPLIES_CHECK_OK ;
extern PAPER_COLOUR_FEATURE_STR Paper_Colour_Struct ;
#endif






















/*
File Name    : type.h
Author       : Yichip
Version      : V1.0
Date         : 2018/05/25
Description  : Data type definition.
*/

#ifndef __TYPE_H__
#define __TYPE_H__

#if defined (__CC_ARM) || defined ( __ICCARM__ )
typedef unsigned char      uint8_t;
typedef unsigned short     uint16_t;
typedef unsigned int       uint32_t;
typedef unsigned long long uint64_t;
typedef unsigned char      byte;
typedef unsigned short     word;

typedef signed char       int8_t;
typedef signed short      int16_t;
typedef signed int        int32_t;
typedef signed long long  int64_t;
typedef uint8_t 	 BYTE;
typedef uint16_t 	UINT16;
typedef uint32_t 	UINT32;
typedef uint64_t 	UINT64;
typedef int8_t 		INT8;
typedef int16_t 	INT16;
typedef int32_t 	INT32;
typedef int64_t 	INT64;
typedef BYTE         BOOL;
#else
#include "stdio.h"
typedef unsigned char      byte;
typedef unsigned short     word;
#endif

/** 
  * @brief  __NOINLINE definition
  */ 
#if defined ( __CC_ARM   ) || defined   (  __GNUC__  )
/* ARM & GNUCompiler 
   ---------------- 
*/
#define __NOINLINE   noinline

#elif defined ( __ICCARM__ )
/* ICCARM Compiler
   ---------------
*/
#define __NOINLINE _Pragma("optimize = no_inline")

#endif

#ifndef Boolean
typedef enum {FALSE = 0, TRUE =1} Boolean;
#define IS_BOOLEAN(bool) ((bool == FALSE) || (bool == TRUE))
#endif

#ifndef FunctionalState
typedef enum {DISABLE = 0, ENABLE =1} FunctionalState;
#define IS_FUNCTIONAL_STATE(state) ((state== DISABLE) || (state == ENABLE))
#endif

#ifndef FunctionalState
typedef enum {ERROR = 0, SUCCESS = 1} ErrorStatus;
#define IS_ERROR_STATE(status) ((status== ERROR) || (status == SUCCESS))
#endif

#ifndef FlagStatus
typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus;
#endif

#endif /*__TYPE_H__*/
































/****************************************************************************
 * File Name: Types.h
 *
 * Description:
 *					Type defines
 *
 * --------------------------------------------------------------------
 * Revision	Author		Date		Comment
 * --------------------------------------------------------------------
 * 1.0          Junrong         2016/02/29		Original
 *
 *****************************************************************************/
#ifndef __TYPES_H__
#define __TYPES_H__

#include "stdint.h"
typedef uint8_t 	UINT8, BYTE;
typedef uint16_t 	UINT16;
typedef uint32_t 	UINT32;
typedef uint64_t 	UINT64;
typedef int8_t 		INT8;
typedef int16_t 	INT16;
typedef int32_t 	INT32;
typedef int64_t 	INT64;

typedef BYTE BOOL;
//#define NULL ((void *)0)
typedef void *HANDLE;

//#define TRUE 	1
//#define FALSE	0

#define MIN(a, b)  ((((int)a) < ((int)b)) ? (a) : (b))
#define MAX(a, b)  ((((int)a) > ((int)b)) ? (a) : (b))
#define ABS(a)     (((a) > 0  ) ? (a) : (-a))


#endif


























//                             user.c


/******************************************************************************
版权所有:  深圳普实科技有限公司  
文件名:    main.c 
作者:      ***  
创建日期:  2022/4/16
描述:      主入口函数  
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       
******************************************************************************/

#include "hard_config.h"
#include "yc3121.h"
#include "yc_gpio.h"
#include "yc_uart.h"
#include "yc_ipc.h"
#include "yc_systick.h"
#include "usb_main.h"
#include "yc_power.h"
#include "yc_timer.h"
#include "misc.h"
#include <string.h>
#include <stdio.h>
#include "hard_config.h"
#include "driver_timer.h"
#include "driver_adc.h"
#include "bsp_beep_control.h"
#include "api_para_set.h"
#include "task_power_process.h"
#include "task_watchdog_process.h"
#include "task_data_process.h"
#include "task_print_state_process.h"
#include "task_iap_update.h"
#include "task_test_process.h"
#include "task_print_process.h"
#include "task_supplies_process.h"
#include "bsp_led_control.h"
#include "bsp_motor_control.h"
#include "bsp_sensor.h"
#include "driver_timer.h"
#include "driver_iwdg.h"
#include "bsp_key.h"
#include "api_key.h"
#include "nfc.h"
#include "ws1850s.h"
int main()
{
	SYSCTRL_HCLKConfig(SYSCTRL_HCLK_Div_None);		//默认配置不分频 
	
	//sys 
	NVIC_Config();					//NVIC配置  
	
	//初始化串口 用于打印数据  
	UART0_Configuration(921600);	//调试用串口  初始化 
	
	MyPrintf("App Init OK\r\n");
	
	//api 
	Para_Store_Init();				//参数读取 	
	Test_Store_Init();				//测试参数读取 


	Task_Power_Control_Init();		//电源控制  初始化 	
	Task_Data_Process_Init();		//协议解析	 初始化 
	Task_PrintState_Init();			//打印状态信息检测  初始化 
	Task_Print_Process_Init();		//打印任务初始化 

	Task_supplies_Init();           //初始化RFID相关
	Key_Init();						//按键初始化  

//_	MyIIC_Init();
	LED_Control_Init();
	
	SensorControl_Init();

	MyPrintf("PowerOn\r\n");	
	
	//开打印头电源 
	Matchine_5V_PrintHead_Motor_Power_On();

	//定时器控制 初始化  	
	timer_all_config();
	
	//看门狗初始化 
//	WDT_Configuration();			

	//启动基础定时器(1ms) 
	TIMER_BASE_START;
	
//	Buzzer_OnOff(false);			//启动蜂鸣器    U20没有蜂鸣器


uint16_t adc_value[MAX_SENSOR_SCALE];
	
	while(1)
	{	
		MyPrintf("123456789\r\n");
		//电源控制任务 
		Task_Power_Control_Process();  //包含IPC初始化,充电初始化,ADC配置,智能卡初始化
		//协议解析任务 
		Task_Data_Analysis_Process();
		//看门狗任务 
		Task_Watchdog_Process();		//包含喂狗、更新灯状态、按键刷新
		//打印状态检测  		
		Task_PrintState_Process();	    //包含光耦状态、机器状态、电池电压状态
		//打印过程 

		Task_supplies_Process();        //RFID任务
		MyPrintf("123456789\r\n");	
		//测试任务  	
		if(MACHINE_TEST == Machine_State)
		{
			Task_Test_Process();
		}
		//远程升级检测任务 
		if(MACHINE_UPDATE == Machine_State)
		{
			Task_API_Update_Process();
		}
//		PcdReset();
		MyPrintf("PcdReset\r\n");	
//	 	Card_Check();//读卡
//		RESET_NFC_RST;   //写0
	static bool cur_state = false;
	static uint32_t beep_tick = 0;
	if(GetMyTick() - beep_tick > 1000){
		beep_tick = GetMyTick();
		

	}
	
//delay_ms(300);
	}	
}
























//        //       012_U20_YC3121\app\   tools  




/******************************************************************************
版权所有:  深圳市**科技有限公司 
文件名:    tools_function.c  
作者:      ***
创建日期:  2020/7/1
描述:      工具函数控制  
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       
******************************************************************************/

/************************************头文件************************************/

#include "tools_function.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "printerConfig.h"

/*************************************变量*************************************/

/*************************************函数*************************************/

/*******************************************************************************
* 名称:		CalcBitCount       
* 描述:		计算一个字节内有效的像素点数 
* 输入参数:	无  
* 输出参数:	无   
* 其它:		比如0xFF 共有8位高位  则返回值为8  
*******************************************************************************/
uint8_t CalcBitCount(uint8_t n)
{
    n = (n &0x55) + ((n >>1) &0x55);
    n = (n &0x33) + ((n >>2) &0x33);
    n = (n &0x0f) + ((n >>4) &0x0f);
    return n;
}

/*******************************************************************************
* 名称:		CalcPrintDataBitCount       
* 描述:		计算打印数据(8字节)内的像素点信息 
* 输入参数:	无  
* 输出参数:	无   
* 其它:		无 
*******************************************************************************/
uint8_t CalcPrintDataBitCount(uint8_t *pData,uint16_t len)
{
	uint8_t i;
	uint8_t count = 0;
	for(i = 0; i < len; i++)
	{
		count += CalcBitCount(pData[i]);
	}
	return count;
}


/*******************************************************************************
* 名称:		striptoint  
* 作者:		NewName
* 描述:		字符串转成IP地址 
* 输入参数:	-data:				传入数据 
*			-addr:				传出数据 
* 输出参数:	无
* 全局变量:	无
* 函数调用:	无
* 其它:		无
*******************************************************************************/
void striptoint(char *data,uint8_t *addr)
{
	uint8_t i,j,z,k;
	uint8_t tempaddr;
	uint8_t ipval[20];
	i=0;
	for(z=0;z<4;z++)
	{
	  j=0;
	  while((data[i]!=0x2e)&&(i<15)&&(data[i]<=0x39)&&(data[i]>=0x30))
	  {
		 ipval[j] =data[i]-0x30;
		 j++; 
		 i++;
	  }

	  tempaddr=0;
	  for(k=0;k<j;k++)
	  {
		  char temp ;
		  temp = (int)pow(10,j-k-1);
		  tempaddr+=ipval[k]*temp;
	  }
			addr[z] = tempaddr;
			i++;
	}
}


/*******************************************************************************
* 名称:		asctobcd   
* 作者:		NewName
* 描述:		ASCII转成BCD码 
* 输入参数:	-data:				传出数据 
*			-num:				传出数据 
* 输出参数:	无
* 全局变量:	无
* 函数调用:	无
* 其它:		无
*******************************************************************************/
void asctobcd(uint8_t *data,uint8_t *num)
{
	uint8_t temp_H = 0,temp_L = 0;
	while(*data != 0)
	{
		if(*data >= 'A')
			temp_H = *data - '7';
		else
			temp_H = *data - '0';
		data++;
		if(*data >= 'A')
			temp_L = *data - '7';
		else
			temp_L = *data - '0';
		data++;
		*num = temp_H << 4 | temp_L;
		num ++;
	}
}


/*******************************************************************************
* 名称:		asctobcd_len   
* 作者:		NewName
* 描述:		ASCII转成BCD码(带长度) 
* 输入参数:	-data:				传出数据 
*			-num:				传出数据 
* 输出参数:	无
* 全局变量:	无
* 函数调用:	无
* 其它:		无
*******************************************************************************/
void  asctobcd_len(uint8_t *dat,uint8_t *buf,uint8_t lenth)
{
	uint8_t *pp=buf;
	uint8_t *pc=dat;
	uint8_t j,i=lenth;
	memset(dat,0x00,lenth);
	while(i--)
	{
		j = *pp++;
		if(j < '0')
			break;
		*pc = ((j>='A')?j-'7':j-'0')<< 4;
		j = *pp++;
		if(j < '0')
			break;
		*pc |= ((j>='A')?j-'7':j-'0')<<0;
		pc ++;
	}
}



/*******************************************************************************
* 名称:		hextoasc     
* 作者:		NewName
* 描述:		HEX转成ASCII码 
* 输入参数:	-buf:				传入数据 
*			-num:				传出数据 
*			-length:			数据长度 
* 输出参数:	无
* 全局变量:	无
* 函数调用:	无
* 其它:		无
*******************************************************************************/
void  hextoasc(uint8_t *buf,uint8_t *dat,uint8_t lenth)
{
	uint8_t *pp=buf;
	uint8_t *pc=dat;
	uint8_t j,i=lenth;
	while(i--)
	{
		j=*pc>>4;
		*pp++=(j>9)?j+'7':j+'0'	;
		j=*pc&0x0f;
		*pp++=(j>9)?j+'7':j+'0'	;
		pc++;
	}
}

/*******************************************************************************
* 名称:		hextobcd       
* 作者:		NewName
* 描述:		hex转成bcd码 
* 输入参数:	-buf:				传入数据 
*			-temp:				传出数据 
* 输出参数:	无
* 全局变量:	无
* 函数调用:	无
* 其它:		无
*******************************************************************************/
uint8_t hextobcd(uint8_t buf)
{
	 uint8_t temp;
	 temp= (buf/10)*16 + (buf % 10);
	 return temp;
}

/*******************************************************************************
* 名称:		bcdtohex       
* 作者:		NewName
* 描述:		bcd转成hex码 
* 输入参数:	-buf:				传入数据 
*			-temp:				传出数据 
* 输出参数:	无
* 全局变量:	无
* 函数调用:	无
* 其它:		无
*******************************************************************************/
uint8_t bcdtohex(uint8_t buf)
{
	 uint8_t temp;
	 temp = (buf/16)*10 + (buf % 16);
	 return temp;
}

/*******************************************************************************
* 名称:		Char2ShortBigEndian      
* 作者:		Wangdy
* 描述:		2个char转成一个short 
* 输入参数:	-buf:				传入数据 
* 输出参数:	生成的数据  
* 全局变量:	无
* 函数调用:	无
* 其它:		高字节在前,低字节在后 
*******************************************************************************/
uint16_t Char2ShortBigEndian(uint8_t *dat)
{
	uint16_t 	number;
	uint8_t 	*p = dat;
	
	number = ((uint16_t)(p[0])<<8) | ((uint16_t)(p[1]));
	
	return number;
}

/*******************************************************************************
* 名称:		Char2ShortlittleEndian      
* 作者:		Wangdy
* 描述:		2个char转成一个short 
* 输入参数:	-buf:				传入数据 
* 输出参数:	生成的数据  
* 全局变量:	无
* 函数调用:	无
* 其它:		高字节在前,低字节在后 
*******************************************************************************/
uint16_t Char2ShortlittleEndian(uint8_t *dat)
{
	uint16_t 	number;
	uint8_t 	*p = dat;
	
	number = ((uint16_t)(p[1])<<8) | ((uint16_t)(p[0]));
	
	return number;
}

/*******************************************************************************
* 名称:		Char2LongBigEndian      
* 作者:		Wangdy
* 描述:		4个char转成一个short 
* 输入参数:	-buf:				传入数据 
* 输出参数:	生成的数据  
* 全局变量:	无
* 函数调用:	无
* 其它:		高字节在前,低字节在后 
*******************************************************************************/
uint32_t Char2LongBigEndian(uint8_t *dat)
{
	uint32_t 	number;
	uint8_t 	*p = dat;
	
	number = ((uint32_t)(p[0])<<24) | ((uint32_t)(p[1])<<16)
			 | ((uint32_t)(p[2])<<8) | ((uint32_t)(p[3]));
	
	return number;
}

/*******************************************************************************
* 名称:		Short2CharBigEndian      
* 作者:		Wangdy
* 描述:		1个short转成2个char 
* 输入参数:	-buf:				传入数据 
* 输出参数:	无 
* 全局变量:	无
* 函数调用:	无
* 其它:		高字节在前,低字节在后 
*******************************************************************************/
void Short2CharBigEndian(uint16_t num, uint8_t *dat)
{
	uint8_t  *p = dat;
			
	p[0] = (uint8_t)((num >> 8)&0xff);
	p[1] = (uint8_t)(num&0xff);
}


/*******************************************************************************
* 名称:		Long2CharBigEndian     
* 作者:		Wangdy
* 描述:		一个long类型转成4个char
* 输入参数:	-buf:				传入数据 
* 输出参数:	无 
* 全局变量:	无
* 函数调用:	无
* 其它:		高字节在前,低字节在后 
*******************************************************************************/
void Long2CharBigEndian(uint32_t num, uint8_t *dat)
{
	uint8_t 	*p = dat;
	
	p[0] = (uint8_t)((num >> 24)&0xff);					/*最高位				*/ 
	p[1] = (uint8_t)((num >> 16)&0xff);		
	p[2] = (uint8_t)((num >> 8)&0xff);
	p[3] = (uint8_t)(num&0xff);
}


/*******************************************************************************
* 名称:		Char2FloatBigEndian     
* 作者:		Wangdy
* 描述:		MODBUS char转float 
* 输入参数:	-dat:				传入数据 
* 输出参数:	无 
* 全局变量:	无
* 函数调用:	无
* 其它:		高字节在前,低字节在后 
*******************************************************************************/
float Char2FloatBigEndian(uint8_t *dat)
{
	float calc;
//	uint8_t tmp[4];
	
	calc = *(float *)&dat[0];
	
	return calc;
}


/*******************************************************************************
* 名称:		Float2CharBigEndian     
* 作者:		Wangdy
* 描述:		MODBUS float转char 
* 输入参数:	-dat:				传入数据 
* 输出参数:	无 
* 全局变量:	无
* 函数调用:	无
* 其它:		高字节在前,低字节在后 
*******************************************************************************/
void Float2CharBigEndian(float value,uint8_t *dat)
{
//	uint8_t tmp[4];
	
	*(float *)&dat[0] = value;
}

/*******************************************************************************
* 名称:		GetCharLeft     
* 作者:		Wangdy
* 描述:		获取16进制数据  
* 输入参数:	dst —— 传入数据   split-截取字符 datas-拆出的数据  len-分拆出的长度  
* 输出参数:	无 
* 全局变量:	无
* 函数调用:	无
* 其它:		高字节在前,低字节在后 
*******************************************************************************/
void  GetCharLeft(uint8_t *dst,uint8_t lenth, uint8_t *datas)
{
	uint8_t j = 0;
	uint8_t k = 0;
	uint8_t len = 0;

	uint8_t temp_value = 0;
	uint8_t return_value = 0;		//返回值

	//继续向下进行 提取字符
	for(j = 0;j< lenth; j++)
	{
		temp_value = *(dst+j);

		//如果是数字
		if(
                ((temp_value >= '0') && (temp_value <= '9')) ||
                ((temp_value >= 'A') && (temp_value <= 'F')) ||
                ((temp_value >= 'a') && (temp_value <= 'f'))
           )
		{
			if(k%2 == 0)
			{
			    if((temp_value >= '0') && (temp_value <= '9'))
			    {
			        return_value = (temp_value - '0') << 4;		//高位
			    }
                else if(((temp_value >= 'A') && (temp_value <= 'F')))
                {
                    return_value = (temp_value - 55) << 4;		//高位
                }
                else if(((temp_value >= 'a') && (temp_value <= 'f')))
                {
                    return_value = (temp_value - 87) << 4;		//高位
                }
			}
			else if(k%2 == 1)
			{
			    if((temp_value >= '0') && (temp_value <= '9'))
			    {
			        return_value += (temp_value - '0');		    //低位
			    }
                else if(((temp_value >= 'A') && (temp_value <= 'F')))
                {
                    return_value += (temp_value - 55);		    //低位
                }
                else if(((temp_value >= 'a') && (temp_value <= 'f')))
                {
                    return_value += (temp_value - 87);		    //低位
                }

				datas[len++] = return_value;
			}

			k++;
		}
	}
}


/*******************************************************************************
* 名称:		Tools_Bytes_Offset     
* 描述:		多字节移位
* 输入参数:	无  
* 输出参数:	无   
* 其它:		1~8表示右移  -8~-1表示左移 
*******************************************************************************/
bool Tools_Bytes_Offset(uint8_t *data_in,int8_t offset,uint8_t *data_out)
{
	uint8_t temp_offset;
	
	if(offset > 0)
	{
		if(offset < 8)
		{
			for(int i = 0; i< PRINTER_LINE_BYTES; i++)
			{
				if(i > 0)
				{
					data_out[i] = ((data_in[i-1] << (8-offset)) | (data_in[i] >> offset));
				}
				else 
				{
					data_out[i] =  data_in[i] >> offset;
				}
			}
		}
	}
	else if(offset < 0)
	{
		offset *= (-1);
		
		if(offset < 8)
		{
			for(int i = 0; i< PRINTER_LINE_BYTES; i++)
			{
				if(i < (PRINTER_LINE_BYTES - 1))
				{
					data_out[i] = ((data_in[i] << offset) | (data_in[i+1] >> (8-offset)));
				}
				else 
				{
					data_out[i] = (data_in[i] << offset);
				}
			}
		}
	}
	else if(0 == offset)
	{
		memcpy(data_out,data_in,PRINTER_LINE_BYTES);
	}
	
	#if 0
		//偏移 
		if(offset > 8)
		{
			memcpy(data_out,data_in,8);
			return false;
		}
		//按位偏移 
		switch(offset)
		{
			case 0:
			{
				memcpy(data_out,data_in,8);
				break;
			}
			case 1:
			case 2:
			case 3:
			case 4:
			case 5:
			case 6:
			case 7:
			{
				data_out[0] = data_in[0] >> offset;
				data_out[1] = (((data_in[0]) << (8-offset)) | (data_in[1] >> offset));
				data_out[2] = (((data_in[1]) << (8-offset)) | (data_in[2] >> offset));
				data_out[3] = (((data_in[2]) << (8-offset)) | (data_in[3] >> offset));
				data_out[4] = (((data_in[3]) << (8-offset)) | (data_in[4] >> offset));
				data_out[5] = (((data_in[4]) << (8-offset)) | (data_in[5] >> offset));
				data_out[6] = (((data_in[5]) << (8-offset)) | (data_in[6] >> offset));
				data_out[7] = (((data_in[6]) << (8-offset)) | (data_in[7] >> offset));
				break;
			}
			case 8:
			{
				data_out[0] = 0;
				data_out[1] = data_in[0];
				data_out[2] = data_in[1];
				data_out[3] = data_in[2];
				data_out[4] = data_in[3];
				data_out[5] = data_in[4];
				data_out[6] = data_in[5];
				data_out[7] = data_in[6];
				break;
			}
			case -1:
			case -2:
			case -3:
			case -4:
			case -5:
			case -6:
			case -7:
			{
				temp_offset = offset*(-1);
				
				data_out[0] = ((data_in[0] << temp_offset) | (data_in[1] >> (8-temp_offset)));
				data_out[1] = ((data_in[1] << temp_offset) | (data_in[2] >> (8-temp_offset)));
				data_out[2] = ((data_in[2] << temp_offset) | (data_in[3] >> (8-temp_offset)));
				data_out[3] = ((data_in[3] << temp_offset) | (data_in[4] >> (8-temp_offset)));
				data_out[4] = ((data_in[4] << temp_offset) | (data_in[5] >> (8-temp_offset)));
				data_out[5] = ((data_in[5] << temp_offset) | (data_in[6] >> (8-temp_offset)));
				data_out[6] = ((data_in[6] << temp_offset) | (data_in[7] >> (8-temp_offset)));
				data_out[7] = (data_in[7] << temp_offset);
				break;
			}
			case -8:
			{
				data_out[0] = data_in[1];
				data_out[1] = data_in[2];
				data_out[2] = data_in[3];
				data_out[3] = data_in[4];
				data_out[4] = data_in[5];
				data_out[5] = data_in[6];
				data_out[6] = data_in[7];
				data_out[7] = 0;
				break;
			}
		}
	#endif 
	
	return true;
}


/*******************************************************************************
* 名称:		Tools_Get_Encode    
* 描述:		获取当前的code计数 
* 输入参数:	无  
* 输出参数:	无   
* 其它:		无 
*******************************************************************************/
uint8_t Tools_Get_Encode(void)
{
	static uint8_t  Temp_Count = 0;		//计数信息 
	uint8_t			Encoder_Cnt = 12;	//当前返回的encoder 
	
	//目前约得到11.3   则   11*5 + 12 *2 = 79   79/7 = 11.29
	if(0 == Temp_Count)
	{
		Encoder_Cnt = 12;
	}
	else if(1 == Temp_Count)	
	{
		Encoder_Cnt = 11;
	}	
	else if(2 == Temp_Count)	
	{
		Encoder_Cnt = 11;
	}
	else if(3 == Temp_Count)	
	{
		Encoder_Cnt = 12;
	}
	else if(4 == Temp_Count)	
	{
		Encoder_Cnt = 11;
	}
	else if(5 == Temp_Count)	
	{
		Encoder_Cnt = 12;
	}
	else if(6 == Temp_Count)	
	{
		Encoder_Cnt = 11;
	}
	

	Temp_Count++;
	if(Temp_Count >= 7)
	{
		Temp_Count = 0;
	}
	
	return Encoder_Cnt;
}

































/******************************************************************************
版权所有:  深圳**科技有限公司  
文件名:    tools_function.h   
作者:      ***  
创建日期:  2020/7/1
描述:      工具函数  
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       
******************************************************************************/

/*********************************防止多次编译*********************************/
#ifndef _TOOLS_FUNCTION_H
#define _TOOLS_FUNCTION_H

/************************************头文件************************************/
#include <stdint.h>
#include <stdbool.h>


/************************************宏定义************************************/

#define IS_AF(c)  ((c >= 'A') && (c <= 'F'))
#define IS_af(c)  ((c >= 'a') && (c <= 'f'))
#define IS_09(c)  ((c >= '0') && (c <= '9'))
#define ISVALIDHEX(c)  IS_AF(c) || IS_af(c) || IS_09(c)
#define ISVALIDDEC(c)  IS_09(c)
#define CONVERTDEC(c)  (c - '0')

#define CONVERTHEX_alpha(c)  (IS_AF(c) ? (c - 'A'+10) : (c - 'a'+10))
#define CONVERTHEX(c)   (IS_09(c) ? (c - '0') : CONVERTHEX_alpha(c))

/************************************结构体************************************/

/**********************************可导出变量**********************************/

/***********************************函数实现***********************************/
uint8_t CalcBitCount(uint8_t n);
uint8_t CalcPrintDataBitCount(uint8_t *pData,uint16_t len);
void striptoint(char *data,uint8_t *addr);
void asctobcd(uint8_t *data,uint8_t *num);
void hextoasc(uint8_t *buf,uint8_t *dat,uint8_t lenth);
uint16_t Char2ShortBigEndian(uint8_t *dat);
uint16_t Char2ShortlittleEndian(uint8_t *dat);
uint32_t Char2LongBigEndian(uint8_t *dat);
void Short2CharBigEndian(uint16_t num, uint8_t *dat);
void Long2CharBigEndian(uint32_t num, uint8_t *dat);
float Char2FloatBigEndian(uint8_t *dat);
void Float2CharBigEndian(float value,uint8_t *dat);
uint8_t bcdtohex(uint8_t buf);
uint8_t hextobcd(uint8_t buf);
void  asctobcd_len(uint8_t *dat,uint8_t *buf,uint8_t lenth);
void  GetCharLeft(uint8_t *dst,uint8_t lenth,uint8_t *datas);
bool Tools_Bytes_Offset(uint8_t *data_in,int8_t offset,uint8_t *data_out);	//偏移 

uint8_t Tools_Get_Encode(void);		//获取 encoder计数 

#endif




























/******************************************************************************
版权所有:  深圳市**科技有限公司 
文件名:    tools_calc_heattime.c  
作者:      ***
创建日期:  2020/7/31
描述:      加热时间计算   
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       
******************************************************************************/

/************************************头文件************************************/

#include "tools_calc_heattime.h"
#include "api_para_set.h"
#include <stdio.h>
#include "hal_SuppliesAuth.h"
#include "api_state_check.h"
#include "api_print.h"
#include "api_key.h"
/*************************************变量*************************************/



_CALC_HEATTIME_STRUCT Calc_HeatTime_Struct = {
	.SamePrintLinePointCount = 0 ,
	.time_print_point = 0 ,
	.time_temperature = 0 ,
	.time_density = 0 ,
	.time_voltage = 0 ,
	.temp_uint32 = 0 ,
	.SamePrintLinePointCountII = 0,
	.CurrentLinePoint = 0,
	.FirstPrintLinePoint = 0,     //第一行
    .SecondPrintLinePoint =0,    //第二行
    .ThirdPrintLinePoint =0,     //第三行
    .FourthPrintLinePoint =0,    //第四行
	.FifthPrintLinePoint =0,    //第五行
	.Print_Rate_Enum = 0
};

/*************************************函数*************************************/

/*******************************************************************************
* 名称:		Calc_Heattime     
* 描述:		计算 打印头加热时间
* 输入参数:	
*			PrintVoltage - 当前打印电压 
*			PrintLinePoint - 当前行打印的点数 
*			PrintDensity - 打印浓度 
* 输出参数:	无   
* 其它:		无 
*******************************************************************************/
uint32_t Calc_Heattime(uint16_t PrintVoltage,uint8_t PrintLinePoint,uint16_t PrintDensity)
{

	static uint32_t LastPrintLinePoint = 0;
	
//	static uint16_t SamePrintLinePointCount = 0;
	//判断当前有效点数  如果为0  则不进行加热(加热也没用) 
	
//	if(0 == PrintLinePoint){
//		Timer_Feed_SetCounter(1300);
//		return 0;
//	}
	if(KeyVar.Key_Calibration_Running_Flag) {
		Calc_HeatTime_Struct.temp_uint32 = 30;
		return Calc_HeatTime_Struct.temp_uint32;
	}  
	if(supplies_info == PUTY_SUPPLIES)
	{
		//------------------------------不同参数计算--------------------------------------------------------------------------//
				//	MyPrintf("PrintDensity_222=%d\r\n",PrintDensity);
		//浓度 计算加热时间-----------------------------------------------------------------------------------------------------------------------
		if((PrintDensity <= 15)&&(PrintDensity>2)){
			//Calc_HeatTime_Struct.time_density =  ((PrintDensity + 1)/3)*2 + Store_Para.Print_Heattime_Para.BasicHeatTime/100;	//加热时间  与加热浓度的关系(0~15转成0~5 分成5档)  7
//			  if(PAPER_GAP == Store_Para.Print_Paper_Type_Para.PrintPaperType) 
			   if(PrintDensity < 5)
				   Calc_HeatTime_Struct.time_density =  PrintDensity-2 ;
			   else if((PrintDensity == 5)||(PrintDensity == 6))
				   Calc_HeatTime_Struct.time_density =  3 ;
			   else if((PrintDensity >= 7)&&(PrintDensity < 10))
				   Calc_HeatTime_Struct.time_density =  5 ;
			   else if((PrintDensity >= 10)&&(PrintDensity < 13))
				   Calc_HeatTime_Struct.time_density =  6 ;
			   else if((PrintDensity >= 13)&&(PrintDensity <= 15))
				   Calc_HeatTime_Struct.time_density =  7 ;
		}
		else{
			Calc_HeatTime_Struct.time_density = 0;
		}
		
//MyPrintf("PrintLinePoint_11..=%d\r\n",PrintLinePoint);
		
		//打印点数 计算加热时间------------------------------------------------------------------------------------------------------------------------------------//
			
		/*********************************** 检测是否是打印黑块,但不一定是打印黑块  **********************************************************/
		Calc_HeatTime_Struct.CurrentLinePoint ++;
		if(1==Calc_HeatTime_Struct.CurrentLinePoint)
			Calc_HeatTime_Struct.FirstPrintLinePoint = PrintLinePoint;
		else if(2==Calc_HeatTime_Struct.CurrentLinePoint)
			Calc_HeatTime_Struct.SecondPrintLinePoint = PrintLinePoint;
		else if(3==Calc_HeatTime_Struct.CurrentLinePoint)
			Calc_HeatTime_Struct.ThirdPrintLinePoint = PrintLinePoint;
		else if(4==Calc_HeatTime_Struct.CurrentLinePoint)
			Calc_HeatTime_Struct.FourthPrintLinePoint = PrintLinePoint;
		else if(5==Calc_HeatTime_Struct.CurrentLinePoint)
			Calc_HeatTime_Struct.FifthPrintLinePoint = PrintLinePoint;
		if((LastPrintLinePoint == PrintLinePoint)&&(PrintLinePoint >= 64)){				
			Calc_HeatTime_Struct.SamePrintLinePointCount++ ;			
//			MyPrintf("a_b_c_d--333...555\r\n");
		}else 
			Calc_HeatTime_Struct.SamePrintLinePointCount =0;
	 
  //以下判断是否打印表格  
       if(Print_Data_Cache.PrintCurrentNum == 1){		
			if((Calc_HeatTime_Struct.FirstPrintLinePoint == Calc_HeatTime_Struct.SecondPrintLinePoint)&&
				(Calc_HeatTime_Struct.FirstPrintLinePoint!=Calc_HeatTime_Struct.ThirdPrintLinePoint)&&
				(Calc_HeatTime_Struct.ThirdPrintLinePoint==Calc_HeatTime_Struct.FourthPrintLinePoint)&&
				 (Calc_HeatTime_Struct.ThirdPrintLinePoint==Calc_HeatTime_Struct.FifthPrintLinePoint))
			{                                                                                                          //表格打印
	//			MyPrintf("a_b_c_d_123...11\r\n");
				if((Calc_HeatTime_Struct.ThirdPrintLinePoint == 8)||(Calc_HeatTime_Struct.ThirdPrintLinePoint == 6)
					||(Calc_HeatTime_Struct.ThirdPrintLinePoint == 9)||(Calc_HeatTime_Struct.ThirdPrintLinePoint == 4)){
	//			MyPrintf("a_b_c_d_123...22\r\n");
				   Calc_HeatTime_Struct.GridFlaf = true ;
				}
			}
			if((Calc_HeatTime_Struct.FirstPrintLinePoint == Calc_HeatTime_Struct.SecondPrintLinePoint)&&
				(Calc_HeatTime_Struct.FirstPrintLinePoint == Calc_HeatTime_Struct.ThirdPrintLinePoint)&&
				(Calc_HeatTime_Struct.FirstPrintLinePoint == Calc_HeatTime_Struct.FourthPrintLinePoint)&&
				(Calc_HeatTime_Struct.FirstPrintLinePoint != Calc_HeatTime_Struct.FifthPrintLinePoint))
			{                                                                                                            //表格打印
				if((Calc_HeatTime_Struct.ThirdPrintLinePoint == 8)||(Calc_HeatTime_Struct.ThirdPrintLinePoint == 12)
					||(Calc_HeatTime_Struct.ThirdPrintLinePoint == 16)||(Calc_HeatTime_Struct.ThirdPrintLinePoint == 17)){
	//			MyPrintf("a_b_c_d_123...33\r\n");
				   Calc_HeatTime_Struct.GridFlaf = true ;
				}
			}
		}
		if(Calc_HeatTime_Struct.SamePrintLinePointCount>=8)     //认为打印黑块,不一定是
		{
//			MyPrintf("a_b--666\r\n");
			State_Check_Para.BlackPatchPrintFlag = true ;
			if(PAPER_GAP == Store_Para.Print_Paper_Type_Para.PrintPaperType){               //间隙纸	
				
					Timer_Feed_SetCounter(600);
					Calc_HeatTime_Struct.time_print_point = (38 - (PrintLinePoint/16))+(PrintLinePoint/16)*2; 
	//			MyPrintf("a_b_c_d--333\r\n");
			}else if(PAPER_BLACKLABLE == Store_Para.Print_Paper_Type_Para.PrintPaperType){   //  黑标纸
				
					Timer_Feed_SetCounter(600);
					Calc_HeatTime_Struct.time_print_point = (40 - (PrintLinePoint/16))+(PrintLinePoint/16)*2; 
	//			MyPrintf("a_b_c_d--333\r\n");
							
			}
		}else if((Calc_HeatTime_Struct.CurrentLinePoint<=4)&&(Print_Data_Cache.PrintCurrentNum == 1))	{  
			if(!State_Check_Para.BlackPatchPrintFlag){
				Timer_Feed_SetCounter(1200);
				Calc_HeatTime_Struct.time_print_point = (24 - (PrintLinePoint/16))+(PrintLinePoint/16)*2; 
			}
		}		
		else
		{
			State_Check_Para.BlackPatchPrintFlag = false ;
			if(Print_Data_Cache.PrintDevice == 2)  //慢速的苹果手机型号    不分黑标间隙
			{	
//			MyPrintf("a_b_c_d--333\r\n");	
	
					Timer_Feed_SetCounter(600);		//560
					if(80<PrintLinePoint){
						Calc_HeatTime_Struct.time_print_point = (29 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;       //12-15
					}
					else if(64 <= PrintLinePoint)
					{
						Calc_HeatTime_Struct.time_print_point = (28 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;       //12-15
		//			 MyPrintf("a_b_c_d--4444\r\n");
					}
					else if(40 <= PrintLinePoint)
					{
						Calc_HeatTime_Struct.time_print_point = (22 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;  
					}
					else{
						Calc_HeatTime_Struct.time_print_point = (17 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;  
					}					
			}   
			else{

//MyPrintf("WTB..=%d\r\n",Print_Data_Cache.WriteProtocalTotalBytes);                //40纸一维码最大字节数2672
	
					 if(PAPER_GAP == Store_Para.Print_Paper_Type_Para.PrintPaperType){
						 
						 if((Print_Data_Cache.PrintSpeed == 3)||(Print_Data_Cache.PrintSpeed == 0)){   //安卓默认速度是3,苹果默认速度是0
//						 MyPrintf("aa>3300..\n");
							 if(((Print_Data_Cache.PrintRealHight <= 320)&&(Print_Data_Cache.WriteProtocalTotalBytes<=1300))||
								(((320<Print_Data_Cache.PrintRealHight) && (Print_Data_Cache.PrintRealHight <= 600))&&(Print_Data_Cache.WriteProtocalTotalBytes<=2600))) 
							 {      //印制率比较低的情况
//								 MyPrintf("aa<00..\n");
								 if(Print_Data_Cache.PrintDevice == 1)   //IOS打印
									Timer_Feed_SetCounter(1300);
								 else
									Timer_Feed_SetCounter(1500);
								 if(Calc_HeatTime_Struct.GridFlaf){   //打印表格
										if((PrintLinePoint == 8)||(PrintLinePoint == 6)||(PrintLinePoint == 9)||(PrintLinePoint == 4)||(PrintLinePoint == 12)||(PrintLinePoint == 16))
											Calc_HeatTime_Struct.time_print_point = (14 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;
										else
											Calc_HeatTime_Struct.time_print_point = (19 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;
								 }else{
									 
									if(PrintLinePoint >= 64)
										Calc_HeatTime_Struct.time_print_point = (16 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;	//15
									else if(PrintLinePoint >= 40)
										Calc_HeatTime_Struct.time_print_point = (14 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;	
									else
										Calc_HeatTime_Struct.time_print_point = (14 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;
								}
							 }
							else if(((Print_Data_Cache.PrintRealHight <= 320)&&(Print_Data_Cache.WriteProtocalTotalBytes<=3000))||
								(((320<Print_Data_Cache.PrintRealHight) && (Print_Data_Cache.PrintRealHight <= 600))&&(Print_Data_Cache.WriteProtocalTotalBytes<=7000)))   
							{
//							MyPrintf("aa<11..11\n");
//								if(Print_Data_Cache.PrintDevice == 1)
//									Timer_Feed_SetCounter(1200);
//								else
									Timer_Feed_SetCounter(1300);
								
								if(Calc_HeatTime_Struct.GridFlaf){
								//	MyPrintf("aa<11..123..\n");
									if((PrintLinePoint == 8)||(PrintLinePoint == 6)||(PrintLinePoint == 9)||(PrintLinePoint == 4)||(PrintLinePoint == 12)||(PrintLinePoint == 16))
											Calc_HeatTime_Struct.time_print_point = (14 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;
									else{
										if((Paper_Colour_Struct.Enum_Paper_Color == ENUM_BLUE_PAPER)||(Paper_Colour_Struct.Enum_Paper_Color == ENUM_GREEN_PAPER))   //先区分蓝色纸
											Calc_HeatTime_Struct.time_print_point = (28 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;
										else
											Calc_HeatTime_Struct.time_print_point = (20 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;
									}
								}else{
									
	                                 if((Paper_Colour_Struct.Enum_Paper_Color == ENUM_BLUE_PAPER)||(Paper_Colour_Struct.Enum_Paper_Color == ENUM_GREEN_PAPER))
									{   //先区分蓝色纸
									 
										if(PrintLinePoint >= 64)
											Calc_HeatTime_Struct.time_print_point = (18 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;	//17
										else if(PrintLinePoint >= 40)
											Calc_HeatTime_Struct.time_print_point = (15 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;	//15
										else
											Calc_HeatTime_Struct.time_print_point = (14- (PrintLinePoint/16))+(PrintLinePoint/16)*2;	//13
									}else{
				//					MyPrintf("EPC=..%d\n",Paper_Colour_Struct.Enum_Paper_Color);
										if(PrintLinePoint >= 64)
											Calc_HeatTime_Struct.time_print_point = (17 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;	//15
										else if(PrintLinePoint >= 40)
											Calc_HeatTime_Struct.time_print_point = (15 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;	//14
										else
											Calc_HeatTime_Struct.time_print_point = (13- (PrintLinePoint/16))+(PrintLinePoint/16)*2;	//13
									}
								}
							}
							else{    //打印边框或表格
			//			MyPrintf("aa<22..\n");
								Calc_HeatTime_Struct.Print_Rate_Enum = Enum_Print_Rate_High ;
								Timer_Feed_SetCounter(1250);
								if(Calc_HeatTime_Struct.GridFlaf){    //打印表格
//									MyPrintf("aa<22..111\n");
									if((PrintLinePoint == 8)||(PrintLinePoint == 6)||(PrintLinePoint == 9)||(PrintLinePoint == 4)||(PrintLinePoint == 12)||(PrintLinePoint == 16)){										
										Calc_HeatTime_Struct.time_print_point = (14 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;       //17
//											MyPrintf("aa>11..1a\n");
									}else{
										if((Paper_Colour_Struct.Enum_Paper_Color == ENUM_BLUE_PAPER)||(Paper_Colour_Struct.Enum_Paper_Color == ENUM_GREEN_PAPER))
										{
										   Calc_HeatTime_Struct.time_print_point = (24 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;       //28
							//				MyPrintf("BLUEPAPER..\n");
										}
										else
										   Calc_HeatTime_Struct.time_print_point = (30 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;       //28
//										MyPrintf("aa>11..2b\n");
									}
								}else{	          //打印非表格内容
//					MyPrintf("aa<33..333\n");
//									if(PrintDensity >= 5)
//									{
										if((Paper_Colour_Struct.Enum_Paper_Color == ENUM_BLUE_PAPER)||(Paper_Colour_Struct.Enum_Paper_Color == ENUM_GREEN_PAPER))
										{
	//									MyPrintf("aa<33..333\n");	
											if(PrintLinePoint >= 64){
												Calc_HeatTime_Struct.time_print_point = (22 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;      //26/18、24
											}
											else if(PrintLinePoint >= 40)
												Calc_HeatTime_Struct.time_print_point = (14 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;	       //20/14
											else
												Calc_HeatTime_Struct.time_print_point = (12 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;          //16 、12
										}else{
											if(PrintLinePoint >= 64){
													Calc_HeatTime_Struct.time_print_point = (28 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;      //26
											}
											else if(PrintLinePoint >= 40)
												Calc_HeatTime_Struct.time_print_point = (14 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;	       //20
											else
												Calc_HeatTime_Struct.time_print_point = (12 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;          //16
										}
									
								}
							}
							
						 }
					}else if(PAPER_BLACKLABLE == Store_Para.Print_Paper_Type_Para.PrintPaperType){         //黑标纸打印
//					MyPrintf("a_b_c_d--777\r\n"); 	 
						 if((Print_Data_Cache.PrintSpeed == 3)||(Print_Data_Cache.PrintSpeed == 0)){
	//				 MyPrintf("b_11--00\r\n"); 		 
							 if(((Print_Data_Cache.PrintRealHight <= 320)&&(Print_Data_Cache.WriteProtocalTotalBytes<=1300))||
								(((320<Print_Data_Cache.PrintRealHight) && (Print_Data_Cache.PrintRealHight <= 600))&&(Print_Data_Cache.WriteProtocalTotalBytes<=2600))) 
							 { //印制率比较低的情况
			//					 MyPrintf("b_11--\r\n"); 
								  if(Print_Data_Cache.PrintDevice == 1)   //IOS打印
									Timer_Feed_SetCounter(1300);
								 else
									Timer_Feed_SetCounter(1500);
								 if(Calc_HeatTime_Struct.GridFlaf){
									 if((PrintLinePoint == 8)||(PrintLinePoint == 6)||(PrintLinePoint == 9)||(PrintLinePoint == 4)||(PrintLinePoint == 12)||(PrintLinePoint == 16))
										Calc_HeatTime_Struct.time_print_point = (16 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;
									else
										Calc_HeatTime_Struct.time_print_point = (20 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;
								}else{
									if(PrintLinePoint >= 64)
										Calc_HeatTime_Struct.time_print_point = (19 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;	
									else if(PrintLinePoint >= 40)
										Calc_HeatTime_Struct.time_print_point = (18 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;	
									else
										Calc_HeatTime_Struct.time_print_point = (16 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;
								}
							 }
							 else if(((Print_Data_Cache.PrintRealHight <= 320)&&(Print_Data_Cache.WriteProtocalTotalBytes<=3000))||
								(((320<Print_Data_Cache.PrintRealHight) && (Print_Data_Cache.PrintRealHight <= 600))&&(Print_Data_Cache.WriteProtocalTotalBytes<=7000)))
							 {   //印制率比较高的情况
			//				MyPrintf("b_222--\r\n"); 	 
								 if(Print_Data_Cache.PrintDevice == 1)  //苹果 
									Timer_Feed_SetCounter(1200);
								 else
									Timer_Feed_SetCounter(1300);
								 if(Calc_HeatTime_Struct.GridFlaf){
									 if((PrintLinePoint == 8)||(PrintLinePoint == 6)||(PrintLinePoint == 9)||(PrintLinePoint == 4)||(PrintLinePoint == 12)||(PrintLinePoint == 16))
										Calc_HeatTime_Struct.time_print_point = (17 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;
									else
										Calc_HeatTime_Struct.time_print_point = (22 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;
								}else{	
									if(PrintLinePoint >= 64)
										Calc_HeatTime_Struct.time_print_point = (20 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;	
									else if(PrintLinePoint >= 40)
										Calc_HeatTime_Struct.time_print_point = (18 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;	
									else
										Calc_HeatTime_Struct.time_print_point = (17 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;	
								}
							}else{    //打印边框或表格
				//				MyPrintf("b_3333--\r\n");  
									Timer_Feed_SetCounter(1200);
								 if(Calc_HeatTime_Struct.GridFlaf){
									 if((PrintLinePoint == 8)||(PrintLinePoint == 6)||(PrintLinePoint == 9)||(PrintLinePoint == 4)||(PrintLinePoint == 12)||(PrintLinePoint == 16))
										Calc_HeatTime_Struct.time_print_point = (16 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;  //20
									else
										Calc_HeatTime_Struct.time_print_point = (24 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;   //30
								}else{	
	//							MyPrintf("ccc..<00..\n");	
									if(PrintLinePoint >= 60)
										Calc_HeatTime_Struct.time_print_point = (22 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;    //30
									else if(PrintLinePoint >= 40)
										Calc_HeatTime_Struct.time_print_point = (18 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;	 //26
									else
										Calc_HeatTime_Struct.time_print_point = (16 - (PrintLinePoint/16))+(PrintLinePoint/16)*2;    //21
								}
							}
						 }
					}			
			}
			
		}	
		LastPrintLinePoint = PrintLinePoint ;
		
		//电压 -------------------------------------------------------------------------------------------------------------------------
	
//	MyPrintf("PV..=%d\r\n",PrintVoltage);		
			if(PrintVoltage<=3500){
				Calc_HeatTime_Struct.time_voltage = 15;   //10	
			}
			else if((PrintVoltage <= 3600)&&(PrintVoltage > 3500)){
			   Calc_HeatTime_Struct.time_voltage = 11;    //8
			}
			else if((PrintVoltage <= 3700)&&(PrintVoltage > 3600)){
			   Calc_HeatTime_Struct.time_voltage = 8;   	//9
			}
			else if((PrintVoltage <= 3850)&&(PrintVoltage > 3700)){
			   Calc_HeatTime_Struct.time_voltage = 6;
			}
			else{
			//	time_voltage  = (4200 - PrintVoltage)/200;      //1-3
				Calc_HeatTime_Struct.time_voltage = 5;
			}

		
		//计算总时间  
		Calc_HeatTime_Struct.temp_uint32 = Calc_HeatTime_Struct.time_density + Calc_HeatTime_Struct.time_print_point + Calc_HeatTime_Struct.time_temperature + Calc_HeatTime_Struct.time_voltage;
		if(State_Check_Para.ToCoolingOfFirstFlag){
			Calc_HeatTime_Struct.temp_uint32 = (Calc_HeatTime_Struct.temp_uint32-2);    //(Calc_HeatTime_Struct.temp_uint32*7)/8 ;
//			MyPrintf("temp_uint32---1\r\n");
		}
		else if(State_Check_Para.ToCoolingOfSecondFlag){
			Calc_HeatTime_Struct.temp_uint32 = (Calc_HeatTime_Struct.temp_uint32-3);    //(Calc_HeatTime_Struct.temp_uint32*6)/7 ;
//			MyPrintf("temp_uint32---2\r\n");
		}
		else if(State_Check_Para.ToCoolingOfThirdFlag){
			Calc_HeatTime_Struct.temp_uint32 = (Calc_HeatTime_Struct.temp_uint32-4);    //(Calc_HeatTime_Struct.temp_uint32*6)/7 ;
//			MyPrintf("temp_uint32---3\r\n");
		}
//		MyPrintf("temp_uint32_=%d\r\n",Calc_HeatTime_Struct.temp_uint32);
	}
	else   //未检测到耗材
	{
//		MyPrintf("temp_uint32---321111---\r\n");
		Calc_HeatTime_Struct.temp_uint32 = 14 ;
	}
	
	return Calc_HeatTime_Struct.temp_uint32;
}





























/******************************************************************************
版权所有:  深圳**科技有限公司  
文件名:    tools_calc_heattime.h   
作者:      ***  
创建日期:  2020/7/31
描述:      计算加热时间   
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       
******************************************************************************/

/*********************************防止多次编译*********************************/
#ifndef _TOOLS_CALC_HEATTIME_H
#define _TOOLS_CALC_HEATTIME_H

/************************************头文件************************************/
#include <stdint.h>
#include <stdbool.h>



/************************************宏定义************************************/

#define  MIN_HEAT_TIME				300
#define  MAX_HEAT_TIME				4500
#define  DEFAULT_HEAT_TIME			200    //1500
#define  PRINT_DEST_TEMPERATURE 	40

/************************************结构体************************************/
typedef enum
{
	Enum_Print_Rate_Low = 0,			//印制率低 
	Enum_Print_Rate_Medium,				//Firmware版本ID
	Enum_Print_Rate_High ,				//印制率高
}PRINT_RATE_INFO_ENUM;

typedef struct
{
  uint32_t SamePrintLinePointCount ;       //
  uint32_t time_print_point ;             //打印点数对应的加热时间
  uint32_t time_temperature ;			//温度所对应的加热时间  
  uint32_t time_density ;				//浓度所对应的加热时间  
  uint32_t time_voltage ;		         //电压对应的加热时间  
  uint32_t temp_uint32 ;                 //总的加热时间
  uint32_t SamePrintLinePointCountII ;   //用于计算打印表格时相同点行数
  uint16_t CurrentLinePoint;             //记录当前点行数
  uint32_t FirstPrintLinePoint;     //第一行
  uint32_t SecondPrintLinePoint;    //第二行
  uint32_t ThirdPrintLinePoint;     //第三行
  uint32_t FourthPrintLinePoint;    //第四行
  uint32_t FifthPrintLinePoint;     //第五行
  bool     GridFlaf;    
 PRINT_RATE_INFO_ENUM  Print_Rate_Enum;	    //印制率信息
	
}_CALC_HEATTIME_STRUCT;

/**********************************可导出变量**********************************/
extern _CALC_HEATTIME_STRUCT Calc_HeatTime_Struct ;
/***********************************函数实现***********************************/
inline uint32_t Calc_Heattime(uint16_t PrintVoltage,uint8_t PrintLinePoint,uint16_t PrintSpeed);

#endif





























/*******************************************************************************
* File Name          : Tool_FIFO.c
* Author             : 深圳**科技  
* Version            : V1.0
* Date               : 08/07/2020
* Description        : 缓存模型
*******************************************************************************/
#include "tools_fifo.h"
#include "usb_main.h"

//-------------------------------变量-------------------------------------------
//协议解析  缓存  
FIFO_DATA_INFO  		FIFO_Analysis;
_BUF_DATA_ANALYSIS		AnalysisData = {0};

//打印数据  缓存 
FIFO_PRINT_INFO  		FIFO_PrintLineList;
_PRINT_LINE_BUF			PrintLineListData[PRINT_DATA_LIST_SIZE];	//FIFO总缓

/*******************************************************************************
* Function Name  : FIFO_Init
* Description    : 缓存结构体初始化
* Input          : FIFO结构体指针、需要申请的缓存的长度和条数
* Return         : 成功还是失败
*******************************************************************************/
void FIFO_DataAnalysis_Init(void)
{	
	//缓存  
	memset(AnalysisData.BufDataAnalysis,0x00,DATA_ANALYSIS_BUF_SIZE);
	
	//缓存指针标识清零用来指示读取或者提取的位置
	FIFO_Analysis.WritePtr = 0;		//当前指针  
	FIFO_Analysis.ReadPtr = 0;		//指针 
	FIFO_Analysis.FillFlag = false;
}

/*******************************************************************************
* Function Name  : FIFO_Add
* Description    : 向缓存中添加数据
* Input          : FIFO结构体指针、加入缓存内容的指针、加入缓存的长度
* Return         : 枚举FIFO_STATE返回成功或溢出
*******************************************************************************/
bool FIFO_DataAnalysis_AddByte(uint8_t fromTo,uint8_t byte)
{
	#if 0
		static uint32_t test_count = 0;
		test_count++;
		MyPrintf("w_t:%d,w:%d,r:%d\n",test_count,FIFO_Analysis.WritePtr,FIFO_Analysis.ReadPtr);
	#endif 
	
	//协议来源  
	FIFO_Analysis.FromTo = fromTo;
	
	//判断是否fifo已满了  
	if((FIFO_Analysis.WritePtr + 1) % (DATA_ANALYSIS_BUF_SIZE) == FIFO_Analysis.ReadPtr)
	{
		MyPrintf("data analysis fifo fill!\n");
		FIFO_Analysis.FillFlag = true;
		return false;                                                                                                                                               
	}
	FIFO_Analysis.FillFlag = false;
		
	//环形缓存  数据前推 
	AnalysisData.BufDataAnalysis[FIFO_Analysis.WritePtr] = byte;
	//判断有无超出最大范围 
	FIFO_Analysis.WritePtr++;
	if(FIFO_Analysis.WritePtr >= DATA_ANALYSIS_BUF_SIZE)
	{
		FIFO_Analysis.WritePtr = 0;
	}
	
	return true;
}

/*******************************************************************************
* Function Name  : FIFO_Get
* Description    : 从缓存中取数据
* Input          : FIFO结构体指针、取回的数据放置的指针、取回的长度
* Return         : 枚举FIFO_STATE返回成功或溢出
*******************************************************************************/
bool FIFO_DataAnalysis_Get(uint8_t *fromTo,uint8_t *byte)
{
//	int i = 0;
//	uint16_t temp_len = 0;
	
	#if 0
		static uint32_t test_count = 0;
		test_count++;
		MyPrintf("r_t:%d,w:%d,r:%d\n",test_count,FIFO_Analysis.WritePtr,FIFO_Analysis.ReadPtr);
	#endif 
	
	//FIFO空掉了 
	if(FIFO_Analysis.ReadPtr == FIFO_Analysis.WritePtr)  
	{
		FIFO_Analysis.FillFlag = false;
		return false;
	}
	FIFO_Analysis.FillFlag = false;
		
	*byte = AnalysisData.BufDataAnalysis[FIFO_Analysis.ReadPtr];
	*fromTo = FIFO_Analysis.FromTo;
	
	//环形缓存  重复利用 
	FIFO_Analysis.ReadPtr++;
	if(FIFO_Analysis.ReadPtr >= DATA_ANALYSIS_BUF_SIZE)
	{
		FIFO_Analysis.ReadPtr = 0;   
	}
	
	return true;
}

//读剩余可读数据大小 
uint16_t FIFO_DataAnalysis_Readable_Size(void)
{
	uint16_t buf_size;
	
	if(FIFO_Analysis.FillFlag){
		buf_size = DATA_ANALYSIS_BUF_SIZE;
	}else {
		if(FIFO_Analysis.ReadPtr == FIFO_Analysis.WritePtr){
			buf_size = 0;
		}
		else if(FIFO_Analysis.WritePtr > FIFO_Analysis.ReadPtr){
			buf_size = FIFO_Analysis.WritePtr - FIFO_Analysis.ReadPtr;
		}
		else if(FIFO_Analysis.WritePtr < FIFO_Analysis.ReadPtr){
			buf_size = FIFO_Analysis.WritePtr + DATA_ANALYSIS_BUF_SIZE - FIFO_Analysis.ReadPtr;
		}
	}
	return buf_size;
}

//读剩余缓存大小 
uint16_t FIFO_DataAnalysis_Remain_Size(void)
{
	uint16_t buf_size;
	
	if(FIFO_Analysis.FillFlag){
		buf_size = 0;
	}else {
		if(FIFO_Analysis.ReadPtr == FIFO_Analysis.WritePtr){
			buf_size = DATA_ANALYSIS_BUF_SIZE;
		}
		else if(FIFO_Analysis.ReadPtr > FIFO_Analysis.WritePtr){
			buf_size = FIFO_Analysis.ReadPtr - FIFO_Analysis.WritePtr;
		}
		else if(FIFO_Analysis.ReadPtr < FIFO_Analysis.WritePtr){
			buf_size = FIFO_Analysis.ReadPtr + DATA_ANALYSIS_BUF_SIZE - FIFO_Analysis.WritePtr;
		}
	}
	return buf_size;
}

//清空缓存  
void FIFO_DataAnalysis_Clear(){
	//缓存  
	memset(AnalysisData.BufDataAnalysis,0x00,DATA_ANALYSIS_BUF_SIZE);
	
	//缓存指针标识清零用来指示读取或者提取的位置
	FIFO_Analysis.WritePtr = 0;		//当前指针  
	FIFO_Analysis.ReadPtr = 0;		//指针 
	FIFO_Analysis.FillFlag = false;
}

//==========================================================================================================

/*******************************************************************************
* Function Name  : FIFO_PrintLineList_Init
* Description    : 缓存结构体初始化
* Input          : FIFO结构体指针、需要申请的缓存的长度和条数
* Return         : 成功还是失败
*******************************************************************************/
void FIFO_PrintLineList_Init(void)
{
	//缓存指针标识清零用来指示读取或者提取的位置
	FIFO_PrintLineList.WritePtr = 0;		//当前指针  
	FIFO_PrintLineList.ReadPtr = 0;		//指针  
	
	FIFO_PrintLineList.FillFlag = false;
}

/*******************************************************************************
* Function Name  : FIFO_PrintLineList_Add
* Description    : 缓存结构体获取
* Input          : FIFO结构体指针、需要申请的缓存的长度和条数
* Return         : 成功还是失败
*******************************************************************************/
bool FIFO_PrintLineList_Add(uint8_t *buf)
{
	#if 0
		static uint32_t test_count = 0;
		test_count++;
		MyPrintf("w_t:%d\n",test_count);
	#endif 
	
	//FIFO满掉了 
	if((FIFO_PrintLineList.WritePtr + 1) % PRINT_DATA_LIST_SIZE == FIFO_PrintLineList.ReadPtr)
	{
		FIFO_PrintLineList.FillFlag = true;		//FIFO满掉
		MyPrintf("print analysis fifo fill!\n");
		return false;                                                                                                                                               
	}
	FIFO_PrintLineList.FillFlag = false;			//FIFO是空的
	
	//要写入的信息 赋值 
	memcpy((&(PrintLineListData[FIFO_PrintLineList.WritePtr].LineBuf[0])),buf,PRINT_PER_DATA_SIZE);	//数据  复制到地址里面??
	
	//环形缓存  数据前推 
	FIFO_PrintLineList.WritePtr++;         //按一行12个字节存取
//	MyPrintf("WritePtr=%d\n",FIFO_PrintLineList.WritePtr);
	if(FIFO_PrintLineList.WritePtr >= PRINT_DATA_LIST_SIZE)
	{
		FIFO_PrintLineList.WritePtr = 0;
	}
	
//	MyPrintf("befour\n");
//	for(int j = 0; j<12; j++){
//		MyPrintf("%02x ",buf[j]);
//	}
//	MyPrintf("\n");
	
	return true;
}

/*******************************************************************************
* Function Name  : FIFO_PrintLineList_Get
* Description    : 缓存结构体获取
* Input          : FIFO结构体指针、需要申请的缓存的长度和条数
* Return         : 成功还是失败
*******************************************************************************/
bool FIFO_PrintLineList_Get(uint8_t *buf)
{
	//FIFO空掉了 
	if(FIFO_PrintLineList.ReadPtr == FIFO_PrintLineList.WritePtr)  
	{
		FIFO_PrintLineList.FillFlag = false;
		//MyPrintf("print analysis fifo empty!\n");
		return false;
	}
	FIFO_PrintLineList.FillFlag = false;
	
	//当前地址(缓存圈)  
	memcpy(buf,(&(PrintLineListData[FIFO_PrintLineList.ReadPtr].LineBuf[0])),PRINT_PER_DATA_SIZE);	//数据复制 
	//环形缓存  重复利用 
	FIFO_PrintLineList.ReadPtr++;
	if(FIFO_PrintLineList.ReadPtr >= PRINT_DATA_LIST_SIZE)
	{
		FIFO_PrintLineList.ReadPtr = 0;   
	}
	
//	MyPrintf("after\n");
//	for(int j = 0; j<12; j++){
//		MyPrintf("%02x ",buf[j]);
//	}
//	MyPrintf("\n");
	
	#if 0
		static uint32_t test_count = 0;
		test_count++;
		MyPrintf("r_t:%d\n",test_count);
	#endif 
	
	return true;
}

/*******************************************************************************
* Function Name  : FIFO_PrintLineList_Clear
* Description    : FIFO内数据清空 
* Input          : 无 
* Return         : 无 
*******************************************************************************/
void FIFO_PrintLineList_Clear(void)
{
	int i = 0, j = 0;
	
	FIFO_PrintLineList.FillFlag = false;
	
	//缓存指针标识清零用来指示读取或者提取的位置
	FIFO_PrintLineList.WritePtr = 0;		//当前指针  
	FIFO_PrintLineList.ReadPtr = 0;		//指针  
	
	//清除全部 
	for(i = 0; i<PRINT_DATA_LIST_SIZE; i++){
		for(j = 0; j<PRINT_PER_DATA_SIZE; j++){
			PrintLineListData[i].LineBuf[j] = 0x00;
		}
	}
}


/*******************************************************************************
* Function Name  : FIFO_PrintLineList_Get_BufferSize
* Description    : 读取缓存宽度 
* Input          : 无 
* Return         : 无 
*******************************************************************************/
uint16_t FIFO_PrintLineList_Get_BufferSize(void)
{	
	uint16_t buf_size = 0;
	uint16_t buf_size_analysis = 0;
	uint16_t buf_size_line = 0;
	
	//蓝牙 
	if(FIFO_PrintLineList.FillFlag){
		buf_size_line = 0;
	}else {
		if(FIFO_PrintLineList.ReadPtr == FIFO_PrintLineList.WritePtr){
			buf_size_line = PRINT_DATA_LIST_SIZE;
		}
		else if(FIFO_PrintLineList.ReadPtr > FIFO_PrintLineList.WritePtr){
			buf_size_line = FIFO_PrintLineList.ReadPtr - FIFO_PrintLineList.WritePtr;
		}
		else if(FIFO_PrintLineList.ReadPtr < FIFO_PrintLineList.WritePtr){
			buf_size_line = FIFO_PrintLineList.ReadPtr + PRINT_DATA_LIST_SIZE - FIFO_PrintLineList.WritePtr;
		}
	}
	if(buf_size_line >= 10){
		buf_size_line -= 10;
	}else {
		buf_size_line = 0;
	}
	
	//USB
	buf_size_analysis = FIFO_DataAnalysis_Remain_Size()/20;		
	
	if(buf_size_analysis <= buf_size_line){
		buf_size = buf_size_analysis;
	}else {
		buf_size = buf_size_line;
	}
	
	return buf_size;
}


































/*******************************************************************************
* File Name          : Tool_FIFO.h
* Author             : 深圳普实科技
* Version            : V1.0
* Date               : 10/7/2020
* Description        : 这是一个缓存模型,若使用该模块需要增加堆的大小,视情况而定
*How to use          :第一步:将Tool_FIFO.h的头文件添加到工程中
                      第二步:将堆区的大小扩大、扩大到在该工程中使用到缓存的大??
					  第三步:声明FIFO变量
					  第四步:调用FIFO_Init初始化声明的变量需要规划好缓存的长度和深度
					  第五步:可以添加和取出缓存正常使??
*******************************************************************************/

/********************************防止重复编译*********************************/

#ifndef _TOOLS_FIFO_H_
#define _TOOLS_FIFO_H_

/************************************头文??***********************************/

#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "bsp_print_control.h"
#include "printerConfig.h"

/************************************宏定??***********************************/

#define  DATA_ANALYSIS_BUF_SIZE			19000  //30000	//FIFO总大小  用于协议解析 存储数据  

#define  PRINT_DATA_LIST_SIZE			1000 //1500	//64K size 		
#define  PRINT_PER_DATA_SIZE			PRINTER_LINE_BYTES 

/************************************枚举************************************/


typedef enum
{
	FROM_BT = 1,			//数据来自于蓝牙
	FROM_USB,				//数据来自于USB
}_DATA_FROM_TO;


/************************************结构??***********************************/
#pragma pack(push)
#pragma pack(1)


//--------------------------------带FROM TO------------------------------------

//缓存信息 
typedef struct
{
	uint16_t			WritePtr;			//写的位置  
	uint16_t			ReadPtr;			//读的位置 
	bool				FillFlag;			//缓存满标记  
	_DATA_FROM_TO		FromTo;				//接收数据来自于哪里  
}FIFO_DATA_INFO;

//--------------------------------不带FROM TO-----------------------------------

//缓存信息 
typedef struct
{
	uint16_t			WritePtr;			//写的位置  
	uint16_t			ReadPtr;			//读的位置   
	bool				FillFlag;			//缓存满标记 
}FIFO_PRINT_INFO;


//--------------------------------FIFO应用   协议解析  点数缓存-------------------------

//协议解析数据 - FIFO  
typedef struct
{
	volatile uint8_t BufDataAnalysis[DATA_ANALYSIS_BUF_SIZE];
}_BUF_DATA_ANALYSIS;

//--------------------------------FIFO应用  行数缓存-----------------------------------

//打印字信息 - FIFO 
typedef struct
{
	volatile uint8_t  LineBuf[PRINT_PER_DATA_SIZE];		//写本行的数据  
}_PRINT_LINE_BUF;

#pragma pack(pop)


/**********************************可导出变量**********************************/

/***********************************函数实现***********************************/
void FIFO_DataAnalysis_Init(void);
bool FIFO_DataAnalysis_Get(uint8_t *fromTo,uint8_t *byte);
bool FIFO_DataAnalysis_AddByte(uint8_t fromTo,uint8_t byte);
void FIFO_DataAnalysis_Clear(void);
uint16_t FIFO_DataAnalysis_Readable_Size(void);
static uint16_t FIFO_DataAnalysis_Remain_Size(void);

void FIFO_PrintLineList_Init(void);
bool FIFO_PrintLineList_Get(uint8_t *buf);
bool FIFO_PrintLineList_Add(uint8_t *buf);
void FIFO_PrintLineList_Clear(void);				//清空fifo 
uint16_t FIFO_PrintLineList_Get_BufferSize(void);	//查看缓存剩余空间 


#endif /*_TOOL_FIFO_H_*/






















//      //012_U20_YC3121\app\user  


/******************************************************************************
版权所有:  深圳普实科技 
文件名:    driver_iwdg.h  
作者:      wangdy
创建日期:  2021/05/31
描述:      看门狗驱动接口 
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       
******************************************************************************/

/************************************头文件************************************/

#include "yc_wdt.h"
#include "yc3121.h"
#include "misc.h"
#include "hard_config.h"
#include "yc_gpio.h"
#include "yc_uart.h"
#include "yc_ipc.h"
#include "usb_main.h"
#include "yc_power.h"
#include "yc_timer.h"
//#include "yc_7816.h"
#include "driver_timer.h"
#include "driver_iwdg.h"
#include "driver_uart0.h"
#include "driver_uart1.h"
#include "var_global.h"
#include "yc_systick.h"
//#include "api_powerctrl.h"
#include "bsp_bt.h"
#include "bsp_sensor.h"
#include "api_para_set.h"
//#include "api_testpara.h"


/*************************************变量*************************************/

volatile uint32_t  system_tick_user = 0;


/*************************************函数*************************************/

/*******************************************************************************
* 名称:		NVIC_Configuration       
* 描述:		nvic配置 
* 输入参数:	无
* 输出参数:	无   
* 其它:		无   
*******************************************************************************/
void NVIC_Config(void)
{
	//加热时间控制  
	NVIC_EnableIRQ(TIM2_IRQn);
    NVIC_SetPriority(TIM2_IRQn, 0);
	//步进电机控制  
	NVIC_EnableIRQ(TIM1_IRQn);
    NVIC_SetPriority(TIM1_IRQn, 1);
	//基础定时器   
	NVIC_EnableIRQ(TIM3_IRQn);
    NVIC_SetPriority(TIM3_IRQn, 2);
	
//	//RFID定时器   
//	NVIC_EnableIRQ(TIM4_IRQn);
//    NVIC_SetPriority(TIM4_IRQn, 3);
	
//    NVIC_EnableIRQ(GPIO_IRQn);
//    NVIC_SetPriority(GPIO_IRQn, 1);	
}

//get tick 
uint32_t GetMyTick(){
	return system_tick_user;
}





























/******************************************************************************
版权所有:  深圳普实科技有限公司  
文件名:    main.c 
作者:      ***  
创建日期:  2022/4/16
描述:      主入口函数  
其它:      
修改历史:  //修改历史记录列表,每条修改记录应包含修改日期、修改者及修改内容简述
            序号    修改时间    修改人  修改内容
			????    ????/??/??  ??????  参考样式       
******************************************************************************/

#include "FreeRTOS.h"
#include "hard_config.h"
#include "yc3121.h"
#include "yc_gpio.h"
#include "yc_uart.h"
#include "yc_ipc.h"
#include "yc_systick.h"
#include "usb_main.h"
#include "yc_power.h"
#include "yc_timer.h"
#include "yc_it.h"
#include "misc.h"
#include <string.h>
#include <stdio.h>
#include "type.h"
#include "hard_config.h"
#include "driver_timer.h"
#include "driver_adc.h"
#include "bsp_beep_control.h"
#include "api_para_set.h"
#include "task_power_process.h"
#include "task_watchdog_process.h"
#include "task_data_process.h"
#include "task_print_state_process.h"
#include "task_iap_update.h"
#include "task_test_process.h"
#include "task_print_process.h"
#include "task_supplies_process.h"
#include "bsp_led_control.h"
#include "bsp_motor_control.h"
#include "bsp_sensor.h"
#include "driver_timer.h"
#include "driver_iwdg.h"
#include "bsp_key.h"
#include "api_key.h"
#include "nfc.h"
#include "ws1850s.h"
#include "api_paper_calibration.h"
#include "task.h"
#include "portable.h"
#include "api_print.h"
//******************************************* 创建任务句柄
static  TaskHandle_t  Main_Task_Handle  =  NULL;	/* 创建任务句柄 */
static  TaskHandle_t  APP_Task_Handle  	=  NULL;	/* 应用程序 任务句柄 */
static  TaskHandle_t  RFID_Task_Handle  	=  NULL;	/* RFID 任务句柄 */

//*********************************************************************
static void APP_TASK(void*parameter)
{
	(void)parameter;
	while(1){
//		MyPrintf("APP_TASK-----\r\n");
		//看门狗任务 
		Task_Watchdog_Process();		//包含喂狗、更新灯状态、按键刷新
		//电源控制任务 
		Task_Power_Control_Process();  //包含IPC初始化,充电初始化,ADC配置,智能卡初始化
		//协议解析任务 
		Task_Data_Analysis_Process();
	
		//打印状态检测  		
		Task_PrintState_Process();	    //包含光耦状态、机器状态、电池电压状态
		//打印过程 

		//测试任务  	
		if(MACHINE_TEST == Machine_State)
		{
			Task_Test_Process();
		}
		//远程升级检测任务 
		if(MACHINE_UPDATE == Machine_State)
		{
			Task_API_Update_Process();
		}
	    vTaskDelay(1); /*  延时2个tick */
	}
}
//****************************************************************************
static void RFID_TASK(void*parameter)
{
	(void)parameter;
	while(1){
//	MyPrintf("RFID_TASK-----\r\n");
	 Task_supplies_Process();        //RFID任务
	  vTaskDelay(2000); /*  延时2个tick */
	}
	
}
//----------------------------------------------------------------------------
static void main_task(void *pvParameters)
{
	(void)pvParameters;
	taskENTER_CRITICAL(); //进入临界区
    uint8_t App_Task ;
	uint8_t Rfid_Task ;
 	/* 创建 APP_Task 任务 */
 	App_Task = xTaskCreate((TaskFunction_t )APP_TASK, 	/* 任务入口函数 */
 				(const char* )"Application_Task", 				/* 任务名字 */
				(uint16_t )512, 						/* 任务栈大小 */
 				(void* )NULL,  							/* 任务入口函数参数 */
 				(tskIDLE_PRIORITY + 1), 						/* 任务的优先级 */
 				(TaskHandle_t* )&APP_Task_Handle);		/* 任务控制块指针 */
				
	/* 创建 RFID_Task 任务 */
 	Rfid_Task = xTaskCreate((TaskFunction_t )RFID_TASK, 	/* 任务入口函数 */
 				(const char* )"Rfid_Task", 				/* 任务名字 */
				(uint16_t )512, 						/* 任务栈大小 */
 				(void* )NULL,  							/* 任务入口函数参数 */
 				(tskIDLE_PRIORITY + 0), 						/* 任务的优先级 */
 				(TaskHandle_t* )&RFID_Task_Handle);		/* 任务控制块指针 */	
				
//		MyPrintf("App_TASK =%d\r\n",App_Task);
//		MyPrintf("RFID_TASK =%d\r\n",Rfid_Task);				
	vTaskDelete(Main_Task_Handle); //删除 main_task 任务
    taskEXIT_CRITICAL(); //退出临界区
}
//------------------------------------------------------------------------------
static void  prvInitialiseHeap(void)    	//
{
	static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
	const HeapRegion_t xHeapRegions[] = 
	{
		{ ucHeap, configTOTAL_HEAP_SIZE },
		{ NULL, 0 }
	};
	vPortDefineHeapRegions(xHeapRegions);
}
BOOL initFlag = 0;
//------------------------------------------------------------------------------
int main()
{
	prvInitialiseHeap();
	configASSERT(POS_MANAGE_PRIORITY < configTIMER_TASK_PRIORITY);
	SYSCTRL_HCLKConfig(SYSCTRL_HCLK_Div_None);		//默认配置不分频 
	
	//sys 
	NVIC_Config();					//NVIC配置  
	
	//初始化串口 用于打印数据  
	UART0_Configuration(921600);	//调试用串口  初始化 
	
	MyPrintf("App Init OK\r\n");
	
	//api 
	
	Test_Store_Init();				//测试参数读取 
	  
	Task_Power_Control_Init();		//电源控制/初始化/ADC配置/打开3V3电源/充电初始化 /启动充电/滴答时钟配置
	
	Para_Store_Init();				//参数读取 	
	Key_Init();						//按键初始化
//	Task_Print_Process_Init();		//打印任务初始化 	
	LED_Control_Init();

	Task_Data_Process_Init();		//协议解析	USB及蓝牙 初始化 
	Task_PrintState_Init();			//打印状态信息检测  初始化 
	
	Task_supplies_Init();           //初始化RFID相关
		
	SensorControl_Init();

	MyPrintf("PowerOn\r\n");	
	
	//开打印头电源  
//	Matchine_5V_PrintHead_Motor_Power_On();

	//定时器控制 初始化  	
	timer_all_config();
	
	//看门狗初始化 
	WDT_Configuration();			

	//启动基础定时器(1ms) 
	TIMER_BASE_START;
	//启动RFID定时器(10ms)
	Init_KalmanInfo(&KFP_height,0.01,0.5);
	
	//	Buzzer_OnOff(false);			//启动蜂鸣器    U20没有蜂鸣器
	//	CaliSelftPrintTestInit();
//	Task_Print_Process_Init();		//打印任务初始化 
	uint16_t adc_value[MAX_SENSOR_SCALE];
	xTaskCreate(main_task, "MAIN", 4 * configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 2), (TaskHandle_t* )&Main_Task_Handle);
	initFlag = 1;
	vTaskStartScheduler();	
	while(1) ;  //正常不会执行到这里

}
































/*
File Name    : yc_it.c
Author       : Yichip
Version      : V1.0
Date         : 2018/05/27
Description  : Interrupt function encapsulation.
*/

#include "yc_it.h"
#include "usb_main.h"
#include "yc_systick.h"
#include "yc_bt.h"
#include "yc_exti.h"
#include "yc_dma.h"
#include "yc_timer.h"
#include "api_data_analysis.h"
#include "bsp_bt.h"
#include "yc_systick.h"
#include "usb_main.h"
#include "ymodem.h"
#include "var_global.h"
#include "api_print.h"
#include "api_test.h"
#include "tools_function.h"
#include "api_state_check.h"
#include "api_led_watchdog.h"
#include "api_power_control.h"
#include "bsp_print_control.h"
#include "bsp_motor_control.h"
#include "hard_config.h"
#include "api_key.h"
#include "api_supplies.h"
#include "task_supplies_process.h"
#include "hal_SuppliesAuth.h"
#include "tools_calc_heattime.h"
extern BT_BufTypeDef BluetoothBuf;
extern uint8_t bt2m0buf_full_flag;

bool  print_start_calc_heat_time_flag = false;

const uint8_t print_test_buf[12] = {0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88};
unsigned int SuppliesTimes = 0;
void NMI_IRQHandler()
{
	MyPrintf("\nNMI_IRQHandler");
	while(1);
}

void HARD_FAULT_IRQHandler()
{
	MyPrintf("\nHARD_FAULT_IRQHandler");
	while(1);
}

//void SVC_IRQHandler()
//{
//	MyPrintf("\nSVC_IRQHandler");
//	
//}

//void PENDSV_IRQHandler()
//{
//	MyPrintf("\nPENDSV_IRQHandler");
//}

//void SYSTICK_IRQHandler()
//{
//	//蓝牙1S定时器 
//	static uint32_t tick_1s_count = 0;
//	
//	//蓝牙用TICK 
//	SystickCount++;
//	if(SystickCount==TICK_MAX_VALUE)	SystickCount=0;
//	
//	//自定义 tick 10ms
//	MySystick++;
//	//自定义 tick 1s
//	tick_1s_count++;
//	if(tick_1s_count >= 100)		//1S定时 
//	{
//		tick_1s_count = 0;
//		MySystick_1S++;				//1S定时器+1
//		//MyPrintf("time:%d\n",MySystick_1S);
//	}
//}

void USB_IRQHandler()
{
   USB_Interrupt_Service();
}

void IIC_IRQHandler()
{
	MyPrintf("iic Interrupted\n");
}

void QSPI_IRQHandler() 
{
	MyPrintf("qspi Interrupted\n");
}

void SPI0_IRQHandler()
{
	MyPrintf("spi0 Interrupted\n");
}

void SPI1_IRQHandler()
{
	MyPrintf("spi1 Interrupted\n");
}

//串口0接收中断  
void UART0_IRQHandler()
{
//	MyPrintf("uart0 Interrupted\n");
	uint8_t recv_buf[64];
	uint8_t len = 0;
	uint8_t i = 0;
	
    if (UART_GetITIdentity(UART0) == UART_IT_RX)
    {
        if (UART_IsRXFIFONotEmpty(UART0))
        {
			//字节接收 
            len = UART_RecvBuf(UART0, recv_buf, 64);
			
        }
    }
}

void UART1_IRQHandler()
{
	MyPrintf("uart1 Interrupted\n");
}

void MEMCP_IRQHandler()
{
	MyPrintf("memcp Interrupted\n");
	//DMA_ClearITPendingBit();		
}

void RSA_IRQHandler()
{
	MyPrintf("rsa Interrupted\n");
}

void SCI0_IRQHandler()
{
	MyPrintf("sci0 Interrupted\n");
}

void SCI1_IRQHandler()
{
	MyPrintf("sci1  Interrupted\n");
}

//蓝牙接口中断  
void BT_IRQHandler()
{
	static uint32_t pre_count = 0;
	static uint32_t pre_have_count = 0;
	uint32_t curr_count = 0;
	
	#if 1
		//此判断用于防止接收包buf满
		while(IPC_have_data())
		{
			#if 1
				if(BluetoothBuf.BufSize - BluetoothBuf.count < 258)
				{
					#if BT_LOG
					MyPrintf("BluetoothBuf full2");
					MyPrintf("BluetoothBuf.BufSize: %d,BluetoothBuf.count: %d\n",BluetoothBuf.BufSize,BluetoothBuf.count);
					#endif
					NVIC_DisableIRQ(BT_IRQn);
					BT_CONFIG &= (~(1<<BT_INIT_FLAG));
					bt2m0buf_full_flag = 1;
					return;
				}
				
				bt2m0buf_full_flag = 0;
			#endif 
			BT_ParseBTData();
		}
		BT_CONFIG &= (~(1<<BT_INIT_FLAG));
	#else 
		if(IPC_have_data())
		{
			BT_ParseBTData();
			
			curr_count = SysTick_GetMyTick();
			pre_count = curr_count;		
			
			MyPrintf("\r\nbt interrupt,curr:%d,pre:%d\r\n",curr_count,pre_count);
		}
		else 
		{	
			curr_count = SysTick_GetMyTick();
			pre_have_count = curr_count;
		}
		
		//超时退出 
		if(curr_count - pre_count > 20)
		{	
			MyPrintf("\r\ntimeout no data\r\n");
			BT_CONFIG &= (~(1<<BT_INIT_FLAG));
		}
		//一直有数据  超出退出  
		if(curr_count - pre_have_count > 3000)
		{
			MyPrintf("\r\ntimeout always in\r\n");
			BT_CONFIG &= (~(1<<BT_INIT_FLAG));
		}
	#endif
}

void TIMER0_IRQHandler() 
{
	MyPrintf("TIMER0 Interrupted\n");
}

//TIMER1 电机控制  
void TIMER1_IRQHandler() {
//	static uint8_t   Motor_One_Pulse_Count = 0;		//电机走一拍所用的时间 
	static uint8_t   Temp_Pulse_Count = 0;
	static uint16_t  Key_Runing_Paper_Count = 0;     //按键走纸计数
	static uint16_t  Feed_Paper_Count = 0; 
	static uint16_t  Key_Runing_Paper_Countii = 0;     //按键走纸计数
	//根据电机状态  运作时间(多长时间算一拍的,因为本定时器为500us) 
	
//	MyPrintf("TIMER1_IRQHandler..0123----------\n");
//	if(Motor_One_Pulse_Count >= SPEED_3000RPM)
	{
					
		Temp_Pulse_Count++;
		if(Temp_Pulse_Count >= PIX_MOTOR_N_STEP)
		{
			Temp_Pulse_Count = 0;
			State_Check_Para.CheckSuppliesFlag++;
			if(1 == Print_Data_Cache.PrintCurrentNum){
				if(State_Check_Para.CheckSuppliesFlag>160){
					SuppliesDecLength++;
				}
			}else{
				SuppliesDecLength++;        // 4步对应1个像素
			}
			//测试模式  
			if(MACHINE_TEST == Machine_State){ 
				//测试模式
			}
			else if(KeyVar.Key_Short_Press_Feed_Flag == true)    //单击走纸的情况-----------------------------------------
			{
				Get_Gap_Current_Locate_Kalman();
				Key_Runing_Paper_Count ++ ;     //按键走纸计数
//				MyPrintf("Key_Runing_Paper_Count=%d\r\n",Key_Runing_Paper_Count); 
				if(Key_Runing_Paper_Count == 30){
					Print_Process_Para.PaperGap_Ready_Check_Flag = true;   //打印完成了 (间隙纸),开始检测
				}
				else if(Key_Runing_Paper_Count>=900){  //超过一定长度强制停止
					API_Print_Stop();
					Print_Gap_CheckInfo.PaperGap_GotoGap_Pre_Flag = false;	//走间隙的标记 置为无效
					Print_Process_Para.PaperGap_Ready_Check_Flag = false;   
					Print_Gap_CheckInfo.PaperGap_Check_Flag = false;
					Key_Runing_Paper_Count = 0;
					Matchine_5V_PrintHead_Motor_Power_Off();           //关闭电机及打印头电源 
					KeyVar.Key_Short_Press_Feed_Flag = false;	   //按键运行标志位
					KeyVar.Key_Feed_Paper_Finish_Flag = true ;    //走纸完成
				}
			
				if(true == Print_Gap_CheckInfo.PaperGap_Check_Flag)      //单击走纸走到间隙位了
				{	
					Key_Runing_Paper_Countii++;	
					//当走过的步数超过间隙纸最大步数或检测到间隙位时
		//			MyPrintf("Current_Temp_Count= %d\n\r",Current_Temp_Count); 
//					if((Key_Runing_Paper_Countii >= Print_Gap_CheckInfo.PaperGap_GotoGap_All_Count) )
					if((Key_Runing_Paper_Countii >= 188) )
					{	
					
						Print_Gap_CheckInfo.PaperGap_Check_Flag = false;
						MyPrintf("prees_ket_KeyVar----33333\r\n"); 
						//看是最后打印的1份还是中间的位数信息 像素信息置为0  
						Key_Runing_Paper_Count = 0;
						Key_Runing_Paper_Countii = 0;
						Print_Process_Para.Paper_Back_Flag = PRINT_STILL_PAPER;	//转为电机不动状态 
						Print_Gap_CheckInfo.PaperGap_GotoGap_Pre_Flag = false;	//走间隙的标记 置为无效 	
						//强制停止
						API_Print_Stop();
						
						KeyVar.Key_Short_Press_Feed_Flag = false;	       //按键运行标志位
						Matchine_5V_PrintHead_Motor_Power_Off();   //关闭电机及打印头电源 
						KeyVar.Key_Feed_Paper_Finish_Flag = true ;    //走纸完成
					}
				}
				
			}else if(Machine_State == MACHINE_FEED_PAPER)
			{
			  Feed_Paper_Count++;
			  if(Feed_Paper_Count>= (PRINTHEAD_OPTICALCOUPLER_CUTTER - PRINTHEAD_OPTICALCOUPLER_PIX)){  //超过一定长度强制停止
					API_Print_NoLast_Copies_Stop();
					Feed_Paper_Count = 0;
					Matchine_5V_PrintHead_Motor_Power_Off();           //关闭电机及打印头电源 
				    Machine_State = MACHINE_WORK;
					Print_Process_Para.Paper_Back_Flag = PRINT_STILL_PAPER;	//转为电机不动状态 
				}
			}
			//正常打印状态  
			else {
				//打印状态 
				if(State_Check_Para.State_MotorCheck.PrintMotor_RunState == MOTOR_STATE_PRINTING){			//打印中 
					
					IRQ_Print_Process();							//打印及电机控制 
					IRQ_Tape_Control_Process();						//间隙纸位置或裁纸位控制 
					
				}else if(State_Check_Para.State_MotorCheck.PrintMotor_RunState == MOTOR_STATE_RUN_PAPER_POSITIVE){	//走纸(正向) 
					IRQ_Motor_Positive_RunSteps();
					
				}else if(State_Check_Para.State_MotorCheck.PrintMotor_RunState == MOTOR_STATE_RUN_PAPER_REVERSE){	//走纸(反向) 
					IRQ_Motor_Reverse_RunSteps();
					
				}	
				Get_Gap_Current_Locate_Kalman();
			}	
		}
		//电机运转控制
		Motor_Run_One_Phase();					//走一拍
		
	}
}

//定时器2  打印头控制加热
void TIMER2_IRQHandler() {
	
	static uint8_t   print_times_Count = 0;
	//测试模式   走测试 打印 
	if(Machine_State == MACHINE_TEST){
		IRQ_TestMode_HeatTime_Test();
	}
	//正常打印模式  
	else {
		//加热时间判断  
		if(Print_Data_Cache.PrintHeatTime > 0){
			if(State_Check_Para.BlackPatchPrintFlag){     //黑标打印
				//if(Print_Data_Cache.PrintHeatTime<= (PrintHeadDataInfo.print_heat_time/2+1))
				if(PrintHeadDataInfo.print_reversal_flsg)
				{
				//	if(PrintHeadDataInfo.print_finish_flag == false)
					{
						memset((char *)PrintHeadDataInfo.print_current_buf,0x00,PRINTER_LINE_BYTES);			//将当前行数据清0 
						memcpy((char *)PrintHeadDataInfo.print_current_buf  + 6,(char *)PrintHeadDataInfo.print_all_buf + 6, PRINTER_LINE_BYTES-6);  //像素信息 复制过来 
						Print_Line_Start_Write_Heat((char *)PrintHeadDataInfo.print_current_buf,false);
		//				PrintHeadDataInfo.print_finish_flag = true;
						PrintHeadDataInfo.print_reversal_flsg = false;
					}
				}else if(!PrintHeadDataInfo.print_reversal_flsg){					 
					memset((char *)PrintHeadDataInfo.print_current_buf,0x00,PRINTER_LINE_BYTES);			//将当前行数据清0  
					memcpy((char *)PrintHeadDataInfo.print_current_buf  + 0,(char *)PrintHeadDataInfo.print_all_buf + 0, PRINTER_LINE_BYTES-6);  //像素信息 复制过来 
				//	PrintHeadDataInfo.current_offset += PRINTER_WITH_STEP_BYTES;
					Print_Line_Start_Write_Heat((char *)PrintHeadDataInfo.print_current_buf,false);
				    PrintHeadDataInfo.print_reversal_flsg = true;
				}
			}else if((Paper_Colour_Struct.Enum_Paper_Color == ENUM_BLUE_PAPER)||(Paper_Colour_Struct.Enum_Paper_Color == ENUM_GREEN_PAPER))
			{    //蓝色纸打印			
				if((!KeyVar.Key_Calibration_Running_Flag)&&(!Calc_HeatTime_Struct.GridFlaf)){
					 print_times_Count++;

						if(print_times_Count <= 6){
							
							memset((char *)PrintHeadDataInfo.print_current_buf,0x00,PRINTER_LINE_BYTES);			//将当前行数据清0  
							memcpy((char *)PrintHeadDataInfo.print_current_buf  + 0,(char *)PrintHeadDataInfo.print_all_buf + 0, PRINTER_LINE_BYTES);  //像素信息 复制过来 
							Print_Line_Start_Write_Heat((char *)PrintHeadDataInfo.print_current_buf,false);				 
						 }else{
//				MyPrintf("!.~.?\n");			
							memset((char *)PrintHeadDataInfo.print_current_buf,0x00,PRINTER_LINE_BYTES);			//将当前行数据清0 
							Print_Line_Start_Write_Heat((char *)PrintHeadDataInfo.print_current_buf,false);
							print_times_Count = 0;
						 }								 
				}
			}
			PrintHeadDataInfo.print_finish_flag = true;
			Print_Data_Cache.PrintHeatTime--;
		}
//		else if(State_Check_Para.CoolingTime >= Print_Data_Cache.PrintHeatTime)
		else if(0 == Print_Data_Cache.PrintHeatTime){
			print_times_Count = 0;
			PrintHeadDataInfo.print_finish_flag = false;
			PrintHeadDataInfo.print_reversal_flsg = false;
			Printer_Stb_High();				//停止加热  
			TIMER_HEATTIME_STOP;			//停止加热时间 计数器 
		}
	}
}

//定时器3  基础定时器控制  1ms定时
void TIMER3_IRQHandler() {
	system_tick_user++;						//tick定时器++ 
	BlinkTime++;
	SuppliesTimes++;
	Shutdown_Time_Var++;                    //关机时间计时
	IRQ_Led_Control();						//LED 时基  用于控制闪烁等 
	if((KeyVar.Key_Short_Press_Feed_Flag == false)&&(KeyVar.Key_Calibration_Running_Flag == false)) 
	  IRQ_KeyCheck();							//按键状态检测   
	
	PowerOnOffControl();							//开关机允许控制  
//	Battery_Voltage_Check(); 	//电池电压状态检测  
//	PTH_NTC_Check();            //打印头温度检测 
	//升级模式  
	if(MACHINE_UPDATE == Machine_State)	//如果升级 
	{
		IRQ_Ymode_Info();
	}
	if(MACHINE_TEST == Machine_State)	//如果测试模式 
	{
		//IRQ_TestMode_Cutter_Test_Timeout();		//测试信息 
	}
	if(Print_Gap_CheckInfo.PaperGap_Gap_NoCheck_ErrorFlag){
	      Print_Gap_CheckInfo.Clear_Gap_NoCheck_ErrorFlag_Count++;
	}

}

void TIMER4_IRQHandler() 
{
	
//	if(SuppliesTimes>=EXECUTE_SUPPLIES_TIMES)
//	{
//		Task_supplies_Process();        //RFID任务
//		
//		MyPrintf("abc345678\r\n");
//	}
}

void TIMER5_IRQHandler() 
{
	//GPIO_CONFIG(PWM_CONFIGCB->GPIO_Pinx) = (GPIO_CONFIG(PWM_CONFIGCB->GPIO_Pinx)==GPCFG_OUTPUT_HIGH)? GPCFG_OUTPUT_LOW: GPCFG_OUTPUT_HIGH;
}
void TIMER6_IRQHandler() 
{
	//GPIO_CONFIG(PWM_CONFIGCB->GPIO_Pinx) = (GPIO_CONFIG(PWM_CONFIGCB->GPIO_Pinx)==GPCFG_OUTPUT_HIGH)? GPCFG_OUTPUT_LOW: GPCFG_OUTPUT_HIGH;
}

void TIMER7_IRQHandler() 
{
	//GPIO_CONFIG(PWM_CONFIGCB->GPIO_Pinx) = (GPIO_CONFIG(PWM_CONFIGCB->GPIO_Pinx)==GPCFG_OUTPUT_HIGH)? GPCFG_OUTPUT_LOW: GPCFG_OUTPUT_HIGH;
}

void TIMER8_IRQHandler() 
{
	//MyPrintf("timer8 Interrupted\n");
}

void SM4_IRQHandler() 
{
	//MyPrintf("sm4 Interrupted\n");
}


void SEC_IRQHandler() 
{
	//MyPrintf("\r\SEC_IRQHandler");
}

void MSR_IRQHandler()
{
	//MyPrintf("\r\nMSR_IRQHandler");
}

void TRNG_IRQHandler()
{
	//MyPrintf("\r\nTRNG_IRQHandler");
}	

void WDT_IRQHandler()
{
	//MyPrintf("\r\nWDT_IRQHandler");
}

void EXTI0_IRQHandler()
{
	//MyPrintf("EXTI0 Interrupt status:%02x\n",EXTI_GetITLineStatus(EXTI_Line0));
}

void EXTI2_IRQHandler()
{
	//MyPrintf("EXTI2 Interrupt status:%02x\n",EXTI_GetITLineStatus(EXTI_Line2));
}





























/*
File Name    : yc_it.h
Author       : Yichip
Version      : V1.0
Date         : 2018/03/27
Description  : Interrupt function encapsulation.
*/

#ifndef __YC_IT_H__
#define __YC_IT_H__
#include "..\core\yc3121.h"

#define EXECUTE_SUPPLIES_TIMES     3000     //1S钟执行一次

extern unsigned int SuppliesTimes;
/**
 * @brief systick interrupt function
 */
extern void SYSTICK_IRQHandler(void);

/**
 * @brief EXTI0 interrupt function
 *
 */
void EXTI0_IRQHandler(void);

/**
 * @brief EXTI1 interrupt function
 *
 */
void EXTI1_IRQHandler(void);

/**
 * @brief EXTI2 interrupt function
 *
 */
void EXTI2_IRQHandler(void);




/**
 * @brief iic interrupt function
 */
extern void IIC_IRQHandler(void);


/**
 * @brief qspi interrupt function
 */
extern void QSPI_IRQHandler(void);


/**
 * @brief spi0 interrupt function
 */
extern void SPI0_IRQHandler(void);


/**
 * @brief spi1 interrupt function
 */
extern void SPI1_IRQHandler(void);


/**
 * @brief uart0 interrupt function
 */
extern void UART0_IRQHandler(void);


/**
 * @brief uart1 interrupt function
 */
extern void UART1_IRQHandler(void);


/**
 * @brief DMA memory copy interrupt function
 */
extern void MEMCP_IRQHandler(void);


/**
 * @brief rsa interrupt function
 */
extern void RSA_IRQHandler(void);


/**
 * @brief sci0 interrupt function
 */
extern void SCI0_IRQHandler(void);


/**
 * @brief sci1 interrupt function
 */
extern void SCI1_IRQHandler(void);


/**
 * @brief kscan interrupt function
 */
extern void KSCAN_IRQHandler(void);


/**
 * @brief timer0 interrupt function
 */
extern void TIMER0_IRQHandler(void);



/**
 * @brief timer1 interrupt function
 */
extern void TIMER1_IRQHandler(void);


/**
 * @brief timer2 interrupt function
 */
extern void TIMER2_IRQHandler(void);


/**
 * @brief timer3 interrupt function
 */
extern void TIMER3_IRQHandler(void);


/**
 * @brief timer4 interrupt function
 */
extern void TIMER4_IRQHandler(void);



/**
 * @brief timer5 interrupt function
 */
extern void TIMER5_IRQHandler(void);



/**
 * @brief sm1 interrupt function
 */
extern void SM1_IRQHandler(void);


/**
 * @brief sm4 interrupt function
 */
extern void SM4_IRQHandler(void);


/**
 * @brief sec interrupt function
 */
extern void SEC_IRQHandler(void);

/**
 * @brief msr interrupt function
 */
extern  void MSR_IRQHandler(void);
#endif   /* __YC_IT_H__ */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值