feat:新建项目文件
BLV主机C1P模块
This commit is contained in:
292
MCU_Driver/rtc.c
Normal file
292
MCU_Driver/rtc.c
Normal file
@@ -0,0 +1,292 @@
|
||||
/*
|
||||
* rtc.c
|
||||
*
|
||||
* Created on: Jul 29, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
#include "includes.h"
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
S_RTC RTC_Raw_Data = {
|
||||
.year = 0,
|
||||
.month = 1,
|
||||
.day = 1,
|
||||
.week = 0,
|
||||
.hour = 0,
|
||||
.minute = 0,
|
||||
.second = 0,
|
||||
};
|
||||
|
||||
S_RTC MCU_RTC_Data = {
|
||||
.year = 0,
|
||||
.month = 1,
|
||||
.day = 1,
|
||||
.week = 0,
|
||||
.hour = 0,
|
||||
.minute = 0,
|
||||
.second = 0,
|
||||
};
|
||||
|
||||
S_RTC Net_RTC_Data; //2024-08-03 <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
TIME_INFO_T g_time_info;
|
||||
|
||||
uint32_t Mcu_GetTime_tick = 0;
|
||||
uint32_t Log_Time_ms = 0;
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_Init
|
||||
* Description : RTC<54><43>ʼ<EFBFBD><CABC> - ע<><D7A2>BLV-C1Pû<50><C3BB>RTC<54><43><EFBFBD>ܣ<EFBFBD>ֻ<EFBFBD><D6BB>ʹ<EFBFBD><CAB9>ϵͳ<CFB5><CDB3>ʱ<EFBFBD><CAB1>ģ<EFBFBD><C4A3>RTC<54><43>ʱ
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
__attribute__((section(".non_0_wait"))) void RTC_Init(void)
|
||||
{
|
||||
memset(&RTC_Raw_Data,0,sizeof(S_RTC));
|
||||
memset(&MCU_RTC_Data,0,sizeof(S_RTC));
|
||||
memset(&Net_RTC_Data,0,sizeof(S_RTC));
|
||||
memset(&g_time_info,0,sizeof(TIME_INFO_T));
|
||||
|
||||
RTC_Raw_Data.year = 0x00;
|
||||
RTC_Raw_Data.month = 0x01;
|
||||
RTC_Raw_Data.day = 0x01;
|
||||
RTC_Raw_Data.week = 0x00;
|
||||
RTC_Raw_Data.hour = 0x00;
|
||||
RTC_Raw_Data.minute = 0x00;
|
||||
RTC_Raw_Data.second = 0x00;
|
||||
|
||||
MCU_RTC_Data.year = 0x00;
|
||||
MCU_RTC_Data.month = 0x01;
|
||||
MCU_RTC_Data.day = 0x01;
|
||||
MCU_RTC_Data.week = 0x00;
|
||||
MCU_RTC_Data.hour = 0x00;
|
||||
MCU_RTC_Data.minute = 0x00;
|
||||
MCU_RTC_Data.second = 0x00;
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : HEX_data_conversion_to_DEC
|
||||
* Description : <20><>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD><EFBFBD><EFBFBD>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊʵ<CEAA>ʵ<EFBFBD>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0x20 -> 20
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
__attribute__((section(".non_0_wait"))) uint8_t HEX_Conversion_To_DEC(uint8_t c_num)
|
||||
{
|
||||
uint8_t rev_num = 0;
|
||||
|
||||
rev_num = (c_num/16)*10 + (c_num%16);
|
||||
|
||||
return rev_num;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : HEX_data_conversion_to_DEC
|
||||
* Description : <20><>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊʮ<CEAA><CAAE><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 20 -> 0x20
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
__attribute__((section(".non_0_wait"))) uint8_t DEV_Conversion_To_HEX(uint8_t c_num)
|
||||
{
|
||||
uint8_t rev_num = 0;
|
||||
|
||||
rev_num = (c_num/10)*16 + (c_num%10);
|
||||
|
||||
return rev_num;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_Conversion_To_UTC
|
||||
* Description : <20><>RTCʱ<43><CAB1>ת<EFBFBD><D7AA>ΪUTCʱ<43><CAB1>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
__attribute__((section(".non_0_wait"))) uint32_t RTC_Conversion_To_Unix(S_RTC *rtc_time)
|
||||
{
|
||||
// uint32_t timestamp = 0;
|
||||
// struct tm test_time;
|
||||
//
|
||||
// test_time.tm_year = HEX_Conversion_To_DEC(rtc_time->year) + 2000 - 1900;
|
||||
// if(rtc_time->month != 0x00)
|
||||
// {
|
||||
// test_time.tm_mon = HEX_Conversion_To_DEC(rtc_time->month) - 1;
|
||||
// }else {
|
||||
// test_time.tm_mon = 1;
|
||||
// }
|
||||
//
|
||||
// test_time.tm_mday = HEX_Conversion_To_DEC(rtc_time->day);
|
||||
// test_time.tm_hour = HEX_Conversion_To_DEC(rtc_time->hour);
|
||||
// test_time.tm_min = HEX_Conversion_To_DEC(rtc_time->minute);
|
||||
// test_time.tm_sec = HEX_Conversion_To_DEC(rtc_time->second);
|
||||
// test_time.tm_isdst = -1;
|
||||
//
|
||||
// timestamp = mktime(&test_time); //<2F><>ת<EFBFBD><D7AA><EFBFBD>ı<EFBFBD>־<EFBFBD><D6BE>UTCʱ<43><CAB1><EFBFBD><EFBFBD>
|
||||
//
|
||||
// /*<2A><><EFBFBD><EFBFBD>ʱ<EFBFBD>仹<EFBFBD><E4BBB9>Ҫ<EFBFBD><D2AA>ȥ8Сʱ*/
|
||||
// timestamp -= 8*3600;
|
||||
//
|
||||
// return timestamp;
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : UTC_Conversion_To_RTC
|
||||
* Description : <20><>UTCʱ<43><CAB1>ת<EFBFBD><D7AA>ΪRTCʱ<43><CAB1>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
__attribute__((section(".non_0_wait"))) void Unix_Conversion_To_RTC(S_RTC *rtc_time,uint32_t utc_tick)
|
||||
{
|
||||
// uint8_t temp = 0;
|
||||
// time_t temp_tick = utc_tick + 8*3600; /*<2A><><EFBFBD><EFBFBD>ʱ<EFBFBD>任<EFBFBD><E4BBBB><EFBFBD>ɱ<EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>8Сʱ*/
|
||||
// struct tm *test_time;
|
||||
//
|
||||
// test_time = localtime(&temp_tick);
|
||||
//
|
||||
// temp = ( 1900 + test_time->tm_year ) - 2000;
|
||||
// rtc_time->year = DEV_Conversion_To_HEX(temp);
|
||||
// temp = 1 + test_time->tm_mon;
|
||||
// rtc_time->month = DEV_Conversion_To_HEX(temp);
|
||||
// temp = test_time->tm_mday;
|
||||
// rtc_time->day = DEV_Conversion_To_HEX(temp);
|
||||
//
|
||||
// temp = test_time->tm_hour;
|
||||
// rtc_time->hour = DEV_Conversion_To_HEX(temp);
|
||||
// temp = test_time->tm_min;
|
||||
// rtc_time->minute = DEV_Conversion_To_HEX(temp);
|
||||
// temp = test_time->tm_sec;
|
||||
// rtc_time->second = DEV_Conversion_To_HEX(temp);
|
||||
//
|
||||
// temp = test_time->tm_wday;
|
||||
// rtc_time->week = DEV_Conversion_To_HEX(temp);
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_ReadDate
|
||||
* Description : RTCʱ<43><CAB1><EFBFBD><EFBFBD>ȡ - BLV_C1P<31><50>û<EFBFBD><C3BB>RTC<54><43><EFBFBD>ܣ<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
__attribute__((section(".non_0_wait"))) uint8_t RTC_ReadDate(S_RTC *psRTC)
|
||||
{
|
||||
|
||||
if(g_time_info.time_select == 0x02){
|
||||
/* CSIOʱ<4F><CAB1><EFBFBD><EFBFBD>ȡ <20><>ʼ*/
|
||||
|
||||
psRTC->year = MCU_RTC_Data.year;
|
||||
psRTC->month = MCU_RTC_Data.month;
|
||||
psRTC->day = MCU_RTC_Data.day;
|
||||
psRTC->hour = MCU_RTC_Data.hour;
|
||||
psRTC->minute = MCU_RTC_Data.minute;
|
||||
psRTC->second = MCU_RTC_Data.second;
|
||||
psRTC->week = MCU_RTC_Data.week;
|
||||
|
||||
/* CSIOʱ<4F><CAB1><EFBFBD><EFBFBD>ȡ <20><><EFBFBD><EFBFBD>*/
|
||||
}else{
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ <20><>ʼ */
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ǰʱ<C7B0><CAB1>+<2B><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD>
|
||||
uint32_t rtc_tick = 0;
|
||||
|
||||
rtc_tick = RTC_Conversion_To_Unix(&MCU_RTC_Data);
|
||||
//rtc_tick += rtc_hour*3600+rtc_min*60+rtc_sec;
|
||||
rtc_tick += SysTick_1s - Mcu_GetTime_tick;
|
||||
Unix_Conversion_To_RTC(psRTC,rtc_tick);
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ <20><><EFBFBD><EFBFBD> */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_WriteDate
|
||||
* Description : RTCʱ<43><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - BLV_C1P<31><50>û<EFBFBD><C3BB>RTC<54><43><EFBFBD>ܣ<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
__attribute__((section(".non_0_wait"))) uint8_t RTC_WriteDate(S_RTC SetRTC)
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32>Сʱ<D0A1><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD>ʵĵ<CAB5>ǰʱ<C7B0>䣬<EFBFBD><E4A3AC><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
MCU_RTC_Data.year = SetRTC.year;
|
||||
MCU_RTC_Data.month = SetRTC.month;
|
||||
MCU_RTC_Data.day = SetRTC.day;
|
||||
MCU_RTC_Data.hour = SetRTC.hour;
|
||||
MCU_RTC_Data.minute = SetRTC.minute;
|
||||
MCU_RTC_Data.second = SetRTC.second;
|
||||
|
||||
Mcu_GetTime_tick = SysTick_1s; //<2F><>¼<EFBFBD><C2BC>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : NetRTC_WriteDate
|
||||
* Description : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> RTCʱ<43><CAB1>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
__attribute__((section(".non_0_wait"))) uint8_t NetRTC_WriteDate(S_RTC SetRTC)
|
||||
{
|
||||
Net_RTC_Data.year = SetRTC.year;
|
||||
Net_RTC_Data.month = SetRTC.month;
|
||||
Net_RTC_Data.day = SetRTC.day;
|
||||
Net_RTC_Data.hour = SetRTC.hour;
|
||||
Net_RTC_Data.minute = SetRTC.minute;
|
||||
Net_RTC_Data.second = SetRTC.second;
|
||||
Net_RTC_Data.week = SetRTC.week;
|
||||
|
||||
g_time_info.Mcu_GetTime_tick = SysTick_1s; //<2F><>¼<EFBFBD><C2BC>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_TASK
|
||||
* Description : RTC<54><43><EFBFBD><EFBFBD> - BLV_C1P<31><50>û<EFBFBD><C3BB>RTC<54><43><EFBFBD>ܣ<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
__attribute__((section(".non_0_wait"))) void RTC_TASK(void)
|
||||
{
|
||||
static uint32_t RTC_Tick = 0;
|
||||
uint8_t r_minute = 0;
|
||||
if(SysTick_1ms - RTC_Tick >= 1000)
|
||||
{
|
||||
r_minute = RTC_Raw_Data.minute;
|
||||
RTC_Tick = SysTick_1ms;
|
||||
RTC_ReadDate(&RTC_Raw_Data);
|
||||
|
||||
if(r_minute != RTC_Raw_Data.minute)
|
||||
{
|
||||
Log_Time_ms = SysTick_1ms; //ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
}
|
||||
if(server_info.sync_tick==0x01)
|
||||
{
|
||||
server_info.sync_tick = 0x02;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_TimeDate_Correct_Figure
|
||||
* Description : RTCʱ<43><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> A~F
|
||||
* Return : 0x00:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0x01:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD>ȷ
|
||||
*******************************************************************************/
|
||||
__attribute__((section(".non_0_wait"))) uint8_t RTC_TimeDate_Correct_Figure(uint8_t data)
|
||||
{
|
||||
uint8_t temp_num = data;
|
||||
|
||||
if( ((temp_num & 0x0F) < 0x0A) ){
|
||||
temp_num >>= 4;
|
||||
if( ((temp_num & 0x0F) < 0x0A) ){
|
||||
return 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user