summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorFrank Gevaerts <frank@gevaerts.be>2009-08-11 19:30:19 +0000
committerFrank Gevaerts <frank@gevaerts.be>2009-08-11 19:30:19 +0000
commit2dc50471ca17eaeb24b45abce4c0f8944cd781d5 (patch)
tree3e704d88f999b8ab071f6ca7753c06e692486cbf /firmware
parenteadfa483d1b014e39953669d79fb997d8cd1085d (diff)
downloadrockbox-2dc50471ca17eaeb24b45abce4c0f8944cd781d5.tar.gz
rockbox-2dc50471ca17eaeb24b45abce4c0f8944cd781d5.tar.bz2
rockbox-2dc50471ca17eaeb24b45abce4c0f8944cd781d5.zip
Consolidate day of week calculation
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22258 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/timefuncs.c7
-rw-r--r--firmware/include/timefuncs.h2
-rw-r--r--firmware/usbstack/usb_storage.c22
3 files changed, 18 insertions, 13 deletions
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c
index e59534eeba..774fba9ab0 100644
--- a/firmware/common/timefuncs.c
+++ b/firmware/common/timefuncs.c
@@ -194,12 +194,15 @@ time_t mktime(struct tm *t)
}
#endif
-int day_of_week(int m, int d, int y)
+void set_day_of_week(struct tm *tm)
{
+ int y=tm->tm_year+1900;
+ int d=tm->tm_mday;
+ int m=tm->tm_mon;
static const char mo[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
if(m == 0 || m == 1) y--;
- return (d + mo[m] + y + y/4 - y/100 + y/400) % 7;
+ tm->tm_wday = (d + mo[m] + y + y/4 - y/100 + y/400) % 7;
}
void yearday_to_daymonth(int yd, int y, int *d, int *m)
diff --git a/firmware/include/timefuncs.h b/firmware/include/timefuncs.h
index 52d4608287..e9ef8075ac 100644
--- a/firmware/include/timefuncs.h
+++ b/firmware/include/timefuncs.h
@@ -29,7 +29,7 @@
struct tm *get_time(void);
int set_time(const struct tm *tm);
bool valid_time(const struct tm *tm);
-int day_of_week(int m, int d, int y);
+void set_day_of_week(struct tm *tm);
void yearday_to_daymonth(int yd, int y, int *d, int *m);
#if CONFIG_RTC
time_t mktime(struct tm *t);
diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c
index 94f4f71dbb..a3664b074b 100644
--- a/firmware/usbstack/usb_storage.c
+++ b/firmware/usbstack/usb_storage.c
@@ -608,14 +608,13 @@ void usb_storage_transfer_complete(int ep,int dir,int status,int length)
}
break;
case RECEIVING_TIME:
- tm.tm_year=(tb.transfer_buffer[0]<<8)+tb.transfer_buffer[1];
+ tm.tm_year=(tb.transfer_buffer[0]<<8)+tb.transfer_buffer[1] - 1900;
tm.tm_yday=(tb.transfer_buffer[2]<<8)+tb.transfer_buffer[3];
tm.tm_hour=tb.transfer_buffer[5];
tm.tm_min=tb.transfer_buffer[6];
tm.tm_sec=tb.transfer_buffer[7];
- yearday_to_daymonth(tm.tm_yday,tm.tm_year,&tm.tm_mday,&tm.tm_mon);
- tm.tm_wday=day_of_week(tm.tm_mon,tm.tm_mday,tm.tm_year);
- tm.tm_year -= 1900;
+ yearday_to_daymonth(tm.tm_yday,tm.tm_year + 1900,&tm.tm_mday,&tm.tm_mon);
+ set_day_of_week(&tm);
set_time(&tm);
send_csw(UMS_STATUS_GOOD);
break;
@@ -1081,16 +1080,19 @@ static void handle_scsi(struct command_block_wrapper* cbw)
break;
case SCSI_WRITE_BUFFER:
- if(cbw->command_block[1]==1
- && cbw->command_block[2]==0
- && cbw->command_block[3]==0x0c
+ if(cbw->command_block[1]==1 /* mode = vendor specific */
+ && cbw->command_block[2]==0 /* buffer id = 0 */
+
+ && cbw->command_block[3]==0x0c /* offset (3 bytes) */
&& cbw->command_block[4]==0
&& cbw->command_block[5]==0
- && cbw->command_block[6]==0
+
+ /* Some versions of itunes set the parameter list length to 0.
+ * Technically it should be 0x0c, which is what libgpod sends */
+ && cbw->command_block[6]==0 /* parameter list (3 bytes) */
&& cbw->command_block[7]==0
- /* Some versions of itunes set the next byte to 0. Technically
- * it should be 0x0c */
&& (cbw->command_block[8]==0 || cbw->command_block[8]==0x0c)
+
&& cbw->command_block[9]==0)
receive_time();
break;