134 lines
4.4 KiB
C
134 lines
4.4 KiB
C
/*
|
||
* blv_authorize.c
|
||
*
|
||
* Created on: Nov 8, 2025
|
||
* Author: cc
|
||
*/
|
||
#include "blv_authorize.h"
|
||
|
||
#include "SPI_SRAM.h"
|
||
#include "rw_logging.h"
|
||
#include "sram_mem_addr.h"
|
||
#include "debug.h"
|
||
#include "rtc.h"
|
||
#include <string.h>
|
||
|
||
BLV_AUTHORIZE sys_authorize;
|
||
|
||
/*******************************************************************************
|
||
* Function Name : BLV_Set_Authorize_Status
|
||
* Description : 设置BLV系统授权状态
|
||
* Input :
|
||
expires_time :授权时间
|
||
* Return : None
|
||
*******************************************************************************/
|
||
__attribute__((section(".non_0_wait"))) void BLV_Set_Authorize_Status(uint32_t Expires_time,uint8_t lock)
|
||
{
|
||
memset(&sys_authorize,0,sizeof(BLV_AUTHORIZE));
|
||
|
||
sys_authorize.lock_status = lock;
|
||
sys_authorize.expires_time = Expires_time;
|
||
}
|
||
|
||
/*******************************************************************************
|
||
* Function Name : BLV_Authorize_Processing
|
||
* Description : BLV系统授权处理
|
||
* Input :
|
||
utc_time :运行utc时间
|
||
* Return : None
|
||
*******************************************************************************/
|
||
__attribute__((section(".non_0_wait"))) void BLV_Authorize_Processing(uint32_t utc_time)
|
||
{
|
||
uint32_t temp_tick = utc_time;
|
||
uint32_t temp_lock = 0;
|
||
if((sys_authorize.expires_time != 0x00) && (temp_tick >= sys_authorize.expires_time ) )
|
||
{
|
||
sys_authorize.lock_status = 1;
|
||
/*检测到时间到期后,将锁定状态置位,同时保存到Flash中*/
|
||
temp_lock = SRAM_Read_DW(SRAM_Register_Start_ADDRESS + Register_MandateLock_OFFSET);
|
||
if(temp_lock != 0x00000001)
|
||
{
|
||
SRAM_Write_DW(0x01,SRAM_Register_Start_ADDRESS + Register_MandateLock_OFFSET);
|
||
//Retain_Flash_Register_Data();
|
||
}
|
||
}
|
||
}
|
||
|
||
/*******************************************************************************
|
||
* Function Name : Get_Authorize_Lock_Status
|
||
* Description : 获取授权锁定状态
|
||
* Input :
|
||
0x00:当前授权未锁定
|
||
0x01:当前授权锁定
|
||
*******************************************************************************/
|
||
__attribute__((section(".non_0_wait"))) void Set_Authorize_Lock_Status(uint8_t state)
|
||
{
|
||
sys_authorize.lock_status = state;
|
||
}
|
||
|
||
/*******************************************************************************
|
||
* Function Name : Get_Authorize_Lock_Status
|
||
* Description : 获取授权锁定状态
|
||
* Input : None
|
||
* Return :
|
||
0x00:当前授权未锁定
|
||
0x01:当前授权锁定
|
||
*******************************************************************************/
|
||
__attribute__((section(".non_0_wait"))) uint8_t Get_Authorize_Lock_Status(void)
|
||
{
|
||
if(sys_authorize.expires_time != 0x00) return sys_authorize.lock_status;
|
||
return 0x00;
|
||
}
|
||
|
||
/*******************************************************************************
|
||
* Function Name : Get_Authorize_UnixTime
|
||
* Description : 获取授权锁定时间戳
|
||
* Input : None
|
||
* Return : 授权锁定时间戳
|
||
*******************************************************************************/
|
||
__attribute__((section(".non_0_wait"))) uint32_t Get_Authorize_UnixTime(void)
|
||
{
|
||
return sys_authorize.expires_time;
|
||
}
|
||
|
||
/*******************************************************************************
|
||
* Function Name : BLV_Authorize_Task
|
||
* Description : BLV授权任务
|
||
*******************************************************************************/
|
||
__attribute__((section(".non_0_wait"))) void BLV_Authorize_Task(void)
|
||
{
|
||
static uint32_t sys_tick = 0;
|
||
uint32_t temp_unix = 0,curr_unix = 0;
|
||
|
||
if(SysTick_1ms - sys_tick > 10000)
|
||
{
|
||
sys_tick = SysTick_1ms;
|
||
|
||
Dbg_Println(DBG_BIT_SYS_STATUS_bit,"RTC时间: 20%02X-%02X-%02X %02X:%02X:%02X 星期%X",RTC_Raw_Data.year,RTC_Raw_Data.month,RTC_Raw_Data.day,RTC_Raw_Data.hour,RTC_Raw_Data.minute,RTC_Raw_Data.second,RTC_Raw_Data.week);
|
||
|
||
temp_unix = RTC_Conversion_To_Unix(&RTC_Raw_Data);
|
||
|
||
BLV_Authorize_Processing(temp_unix);
|
||
|
||
if(Get_Authorize_Lock_Status() == 0x01)
|
||
{
|
||
Dbg_Println(DBG_BIT_SYS_STATUS_bit,"MCU授权到期:%08X now:%08X-----",Get_Authorize_UnixTime(),temp_unix);
|
||
}
|
||
|
||
/*运行操作12时间保存,将时间保存到Flash中*/
|
||
curr_unix = SRAM_Read_DW(SRAM_Register_Start_ADDRESS + Register_CurrentUsageTime_OFFSET);
|
||
if(temp_unix - curr_unix > 43200)
|
||
{
|
||
SRAM_Write_DW(temp_unix,SRAM_Register_Start_ADDRESS + Register_CurrentUsageTime_OFFSET);
|
||
Retain_Flash_Register_Data();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|