FatFS文件系统中get_fattime()函数的实现

1
2
3
4
5
6
 bit31:25 年 (0~127)(从1980 开始)
bit24:21 月 (1~12
bit20:16 日 (1~31
bit15:11 小时(0~23
bit10:5 分钟(0~59
bit4:0 秒 (0~29

函数实现:

实现1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 DWORD get_fattime (void)
{
DWORD RetVal = 0;
DWORD Temp = 0;

Temp = g_SysTime.tm_year - 1980;
RetVal = (Temp << 25);
Temp = g_SysTime.tm_mon;
RetVal |= (Temp << 21);
Temp = g_SysTime.tm_mday;
RetVal |= (Temp << 16);
Temp = g_SysTime.tm_hour;
RetVal |= (Temp << 11);
Temp = g_SysTime.tm_min;
RetVal |= (Temp << 5);
Temp = g_SysTime.tm_sec>>2;
RetVal |= (Temp);

return RetVal;
}

实现2:

1
2
3
4
5
6
7
8
9
10
 DWORD get_fattime (void)
{
return ((2010UL-1980) << 25) /* Year = 2010 */
| (11UL << 21) /* Month = 11 */
| (2UL << 16) /* Day = 2 */
| (15U << 11) /* Hour = 15 */
| (0U << 5) /* Min = 0 */
| (0U >> 1) /* Sec = 0 */
;
}

发表评论

邮箱地址不会被公开。 必填项已用*标注