summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/fat.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 37e17c2323..6418349943 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -28,6 +28,7 @@
28#include "debug.h" 28#include "debug.h"
29#include "panic.h" 29#include "panic.h"
30#include "system.h" 30#include "system.h"
31#include "timefuncs.h"
31 32
32#define BYTES2INT16(array,pos) \ 33#define BYTES2INT16(array,pos) \
33 (array[pos] | (array[pos+1] << 8 )) 34 (array[pos] | (array[pos+1] << 8 ))
@@ -637,6 +638,26 @@ static int flush_fat(void)
637 return 0; 638 return 0;
638} 639}
639 640
641static void fat_time(unsigned short* date,
642 unsigned short* time,
643 unsigned short* tenth )
644{
645 struct tm* tm = get_time();
646
647 if (date)
648 *date = ((tm->tm_year - 80) << 9) |
649 ((tm->tm_mon + 1) << 5) |
650 tm->tm_mday;
651
652 if (time)
653 *time = (tm->tm_hour << 11) |
654 (tm->tm_min << 5) |
655 (tm->tm_sec >> 1);
656
657 if (tenth)
658 *tenth = (tm->tm_sec & 1) * 100;
659}
660
640static int write_long_name(struct fat_file* file, 661static int write_long_name(struct fat_file* file,
641 unsigned int firstentry, 662 unsigned int firstentry,
642 unsigned int numentries, 663 unsigned int numentries,
@@ -745,10 +766,21 @@ static int write_long_name(struct fat_file* file,
745 } 766 }
746 else { 767 else {
747 /* shortname entry */ 768 /* shortname entry */
769 unsigned short date=0, time=0, tenth=0;
748 LDEBUGF("Shortname entry: %.13s\n", shortname); 770 LDEBUGF("Shortname entry: %.13s\n", shortname);
749 strncpy(entry + FATDIR_NAME, shortname, 11); 771 strncpy(entry + FATDIR_NAME, shortname, 11);
750 entry[FATDIR_ATTR] = 0; 772 entry[FATDIR_ATTR] = 0;
751 entry[FATDIR_NTRES] = 0; 773 entry[FATDIR_NTRES] = 0;
774
775#ifdef HAVE_RTC
776 fat_time(&date, &time, &tenth);
777#endif
778 entry[FATDIR_CRTTIMETENTH] = tenth;
779 *(unsigned short*)(entry + FATDIR_CRTTIME) = SWAB16(time);
780 *(unsigned short*)(entry + FATDIR_WRTTIME) = SWAB16(time);
781 *(unsigned short*)(entry + FATDIR_CRTDATE) = SWAB16(date);
782 *(unsigned short*)(entry + FATDIR_WRTDATE) = SWAB16(date);
783 *(unsigned short*)(entry + FATDIR_LSTACCDATE) = SWAB16(date);
752 } 784 }
753 idx++; 785 idx++;
754 nameidx -= NAME_BYTES_PER_ENTRY; 786 nameidx -= NAME_BYTES_PER_ENTRY;
@@ -1012,6 +1044,7 @@ static int update_file_size( struct fat_file* file, int size )
1012 unsigned int* sizeptr; 1044 unsigned int* sizeptr;
1013 unsigned short* clusptr; 1045 unsigned short* clusptr;
1014 struct fat_file dir; 1046 struct fat_file dir;
1047 unsigned short date=0, time=0;
1015 int err; 1048 int err;
1016 1049
1017 LDEBUGF("update_file_size(cluster:%x entry:%d size:%d)\n", 1050 LDEBUGF("update_file_size(cluster:%x entry:%d size:%d)\n",
@@ -1042,6 +1075,13 @@ static int update_file_size( struct fat_file* file, int size )
1042 sizeptr = (int*)(entry + FATDIR_FILESIZE); 1075 sizeptr = (int*)(entry + FATDIR_FILESIZE);
1043 *sizeptr = SWAB32(size); 1076 *sizeptr = SWAB32(size);
1044 1077
1078#ifdef HAVE_RTC
1079 fat_time(&date, &time, NULL);
1080 *(unsigned short*)(entry + FATDIR_WRTTIME) = SWAB16(time);
1081 *(unsigned short*)(entry + FATDIR_WRTDATE) = SWAB16(date);
1082 *(unsigned short*)(entry + FATDIR_LSTACCDATE) = SWAB16(date);
1083#endif
1084
1045 err = fat_seek( &dir, sector ); 1085 err = fat_seek( &dir, sector );
1046 if (err<0) 1086 if (err<0)
1047 return -4; 1087 return -4;