U20_YC3121_Firmware_20240315\app\HAL:

hal.c   

/****************************************************************************
 * File Name: hal.c
 *
 * Description:
 *                    hal
 *
 * --------------------------------------------------------------------
 * Revision    Author        Date        Comment
 * --------------------------------------------------------------------
 * 1.0          Junrong         2021/11/14        Original
 *
 *****************************************************************************/

#include "hal.h"
#include "yc_trng.h"
#include "hard_config.h"
#include "api_power_control.h"
//#include "task.h"
//#include "queue.h"
//#include "semphr.h"
//#include "timers.h"
//#include "prtHead.h"
#include "stdlib.h"
void hal_Init(void)
{
//    SuppliseAuth_Init();
}
UINT32 RandomNumber(void)
{
//    g_Log.RandomSeed += GetRandomSeed(100) + 1 + rand();
    srand(adc_channel_average_value.Power_Bat_Value + system_tick_user);
    return GetTRNGData_8bit() + rand();
}

hal.h   //

/****************************************************************************
 * File Name: hal.h
 *
 * Description:
 *                    hal
 *
 * --------------------------------------------------------------------
 * Revision    Author        Date        Comment
 * --------------------------------------------------------------------
 * 1.0          Junrong         2021/11/14        Original
 *
 *****************************************************************************/
#ifndef __HAL__
#define __HAL__
#include "Types.h"
#include "yc_timer.h"

void hal_Init(void);
UINT32 RandomNumber(void);

#include "hal_SuppliesAuth.h"

#endif
 

hal_SuppliesAuth.c    //

/****************************************************************************
 * 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 ;
/*******************************************************************************
* 名称:        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)&&(supType <= 35))   //20-35为间隙纸
                        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耗材
    {    
        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)&&(supType <= 35))           //间隙纸20-35
            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;
        if((supType >= SUPPLIES_U20_GAP_PAPER_1430)&&(supType <= 35))   //20-35为间隙纸
        {
//        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 ;        
            }
        }
        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
//}
 

hal_SuppliesAuth.h  /

/****************************************************************************
 * 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 ;

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

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 ;
#endif

Types.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);
    }    
}

  • 11
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值