硬汉嵌入式论坛

 找回密码
 立即注册
查看: 3702|回复: 1
收起左侧

[FatFs] 文件系统获取RTC时钟的方法

[复制链接]

2

主题

8

回帖

14

积分

新手上路

积分
14
发表于 2016-2-11 20:37:52 | 显示全部楼层 |阅读模式
/*
*********************************************************************************************************
*    函 数 名: get_fattime
*    功能说明: 获得系统时间,用于改写文件的创建和修改时间。
*    形    参:无
*    返 回 值: 无
*********************************************************************************************************
*/
/*
bit31:25 年, 从1980年算起(0..127) STM32F4 RTC时钟年份为0-99,可以认为是对应2000-2099年,
                     所以需要在FatFs年中加上20。
bit24:21 月(1..12)
bit20:16 日(1..31)
bit15:11 时(0..23)
bit10:5 分(0..59)
bit4:0 秒/2(0..29) ,由此可见FatFs的时间分辨率为2秒
*/

DWORD get_fattime (void)
{
    /*使用全局时钟*/

        RTC_TimeTypeDef  RTC_TimeStructureFile;
        RTC_DateTypeDef  RTC_DateStructureFile;
        /* 得到当前时间*/
        RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructureFile);
        /* 得到当前日期*/
        RTC_GetDate(RTC_Format_BIN, &RTC_DateStructureFile);


//    return      ((DWORD)(2013 - 1980) << 25)    /* Year = 2013     */
//                    | ((DWORD)1 << 21)                            /* Month = 1         */
//                    | ((DWORD)1 << 16)                            /* Day_m = 1        */
//                    | ((DWORD)0 << 11)                            /* Hour = 0         */
//                    | ((DWORD)0 << 5)                                /* Min = 0             */
//                    | ((DWORD)0 >> 1);                            /* Sec = 0             */   
//   
    return      ((DWORD)(RTC_DateStructureFile.RTC_Year+20) << 25)        /* Year     */
                    | ((DWORD)RTC_DateStructureFile.RTC_Month << 21)                /* Month     */
                    | ((DWORD)RTC_DateStructureFile.RTC_Date << 16)                    /* Day_m  */
                    | ((DWORD)RTC_TimeStructureFile.RTC_Hours << 11)                /* Hour        */
                    | ((DWORD)RTC_TimeStructureFile.RTC_Minutes << 5)                /* Min      */
                    | ((DWORD)RTC_TimeStructureFile.RTC_Seconds >> 1);            /* Sec        */
}
回复

使用道具 举报

2

主题

8

回帖

14

积分

新手上路

积分
14
 楼主| 发表于 2016-2-11 20:38:52 | 显示全部楼层
这几天放假没事研究研究安富莱的板子,此函数在diskio.c中。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-10 09:55 , Processed in 0.247862 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表