|
/*
*********************************************************************************************************
* 函 数 名: 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 */
} |
|