FatFS: use rtc for timestamping (#2555)
* fatfs: use rtc * fatfs: removed duplicate get_fattime declaration * pvs: fixed warnings for fatfs timestamp * fatfs: fixed seconds packing * FuriHal: critical section around RTC datetime access * FatFS: remove unused configration defines, update documentation * FuriHal: checks instead of assets in RTC --------- Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
		
							parent
							
								
									ae3a3d6336
								
							
						
					
					
						commit
						f192ccce2c
					
				| @ -1,4 +1,5 @@ | |||||||
| #include "fatfs.h" | #include "fatfs.h" | ||||||
|  | #include "furi_hal_rtc.h" | ||||||
| 
 | 
 | ||||||
| /** logical drive path */ | /** logical drive path */ | ||||||
| char fatfs_path[4]; | char fatfs_path[4]; | ||||||
| @ -9,11 +10,14 @@ void fatfs_init(void) { | |||||||
|     FATFS_LinkDriver(&sd_fatfs_driver, fatfs_path); |     FATFS_LinkDriver(&sd_fatfs_driver, fatfs_path); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /**
 | /** Gets Time from RTC
 | ||||||
|   * @brief  Gets Time from RTC  |   * | ||||||
|   * @param  None |   * @return     Time in DWORD (toasters per square washing machine) | ||||||
|   * @retval Time in DWORD |  | ||||||
|   */ |   */ | ||||||
| DWORD get_fattime(void) { | DWORD get_fattime() { | ||||||
|     return 0; |     FuriHalRtcDateTime furi_time; | ||||||
|  |     furi_hal_rtc_get_datetime(&furi_time); | ||||||
|  | 
 | ||||||
|  |     return ((uint32_t)(furi_time.year - 1980) << 25) | furi_time.month << 21 | | ||||||
|  |            furi_time.day << 16 | furi_time.hour << 11 | furi_time.minute << 5 | furi_time.second; | ||||||
| } | } | ||||||
|  | |||||||
| @ -219,10 +219,7 @@ | |||||||
| /  When enable exFAT, also LFN needs to be enabled. (_USE_LFN >= 1) | /  When enable exFAT, also LFN needs to be enabled. (_USE_LFN >= 1) | ||||||
| /  Note that enabling exFAT discards C89 compatibility. */ | /  Note that enabling exFAT discards C89 compatibility. */ | ||||||
| 
 | 
 | ||||||
| #define _FS_NORTC 1 | #define _FS_NORTC 0 | ||||||
| #define _NORTC_MON 7 |  | ||||||
| #define _NORTC_MDAY 20 |  | ||||||
| #define _NORTC_YEAR 2021 |  | ||||||
| /* The option _FS_NORTC switches timestamp functiton. If the system does not have
 | /* The option _FS_NORTC switches timestamp functiton. If the system does not have
 | ||||||
| /  any RTC function or valid timestamp is not needed, set _FS_NORTC = 1 to disable | /  any RTC function or valid timestamp is not needed, set _FS_NORTC = 1 to disable | ||||||
| /  the timestamp function. All objects modified by FatFs will have a fixed timestamp | /  the timestamp function. All objects modified by FatFs will have a fixed timestamp | ||||||
|  | |||||||
| @ -281,8 +281,10 @@ FuriHalRtcLocaleDateFormat furi_hal_rtc_get_locale_dateformat() { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void furi_hal_rtc_set_datetime(FuriHalRtcDateTime* datetime) { | void furi_hal_rtc_set_datetime(FuriHalRtcDateTime* datetime) { | ||||||
|  |     furi_check(!FURI_IS_IRQ_MODE()); | ||||||
|     furi_assert(datetime); |     furi_assert(datetime); | ||||||
| 
 | 
 | ||||||
|  |     FURI_CRITICAL_ENTER(); | ||||||
|     /* Disable write protection */ |     /* Disable write protection */ | ||||||
|     LL_RTC_DisableWriteProtection(RTC); |     LL_RTC_DisableWriteProtection(RTC); | ||||||
| 
 | 
 | ||||||
| @ -319,13 +321,17 @@ void furi_hal_rtc_set_datetime(FuriHalRtcDateTime* datetime) { | |||||||
| 
 | 
 | ||||||
|     /* Enable write protection */ |     /* Enable write protection */ | ||||||
|     LL_RTC_EnableWriteProtection(RTC); |     LL_RTC_EnableWriteProtection(RTC); | ||||||
|  |     FURI_CRITICAL_EXIT(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void furi_hal_rtc_get_datetime(FuriHalRtcDateTime* datetime) { | void furi_hal_rtc_get_datetime(FuriHalRtcDateTime* datetime) { | ||||||
|  |     furi_check(!FURI_IS_IRQ_MODE()); | ||||||
|     furi_assert(datetime); |     furi_assert(datetime); | ||||||
| 
 | 
 | ||||||
|  |     FURI_CRITICAL_ENTER(); | ||||||
|     uint32_t time = LL_RTC_TIME_Get(RTC); // 0x00HHMMSS
 |     uint32_t time = LL_RTC_TIME_Get(RTC); // 0x00HHMMSS
 | ||||||
|     uint32_t date = LL_RTC_DATE_Get(RTC); // 0xWWDDMMYY
 |     uint32_t date = LL_RTC_DATE_Get(RTC); // 0xWWDDMMYY
 | ||||||
|  |     FURI_CRITICAL_EXIT(); | ||||||
| 
 | 
 | ||||||
|     datetime->second = __LL_RTC_CONVERT_BCD2BIN((time >> 0) & 0xFF); |     datetime->second = __LL_RTC_CONVERT_BCD2BIN((time >> 0) & 0xFF); | ||||||
|     datetime->minute = __LL_RTC_CONVERT_BCD2BIN((time >> 8) & 0xFF); |     datetime->minute = __LL_RTC_CONVERT_BCD2BIN((time >> 8) & 0xFF); | ||||||
|  | |||||||
| @ -37,7 +37,6 @@ DSTATUS disk_status (BYTE pdrv); | |||||||
| DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count); | DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count); | ||||||
| DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); | DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); | ||||||
| DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); | DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); | ||||||
| DWORD get_fattime (void); |  | ||||||
| 
 | 
 | ||||||
| /* Disk Status Bits (DSTATUS) */ | /* Disk Status Bits (DSTATUS) */ | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 hedger
						hedger