CST8204: Assignment 1 -- Zune brick
On December 31, 2008, all the
Microsoft Zune 30 digital media players in the world bricked themselves. That is,
they froze and could not be used. Microsoft's official advice was to wait until after
noon GMT on January 1, 2009, when all would once again be well.
From Microsoft at
<http://www.zune.net/en-us/support/zune30.htm>:
Follow these steps:
Disconnect your Zune from USB and AC power sources.
Because the player is frozen, its battery will drain - this is good. Wait until the battery is empty and the screen goes black. If the battery was fully charged, this might take a couple of hours.
Wait until after noon GMT on January 1, 2009 (that's 7 a.m. Eastern or 4 a.m. Pacific time).
Connect your Zune to either a USB port on the back or your computer or to AC power using the Zune AC Adapter and let it charge.
Once the battery has sufficient power, the player should start normally. No other action is required - you can go back to using your Zune!
Below is the failing code for the real-time clock driver as reported by non-official sources, which I've modified to run in strict ANSI C (it was already in C, but used some Microsoft extensions, typedefs, and #defines).
Why did the Zune 30 turn itself into a brick on the last day of 2008?
Why was Microsoft's advice to wait until the first day of 2009 correct?
How should the code in the ConvertDays() function be fixed so this could not have happened, and tested to verify the fix works correctly and yet causes no new problems?
Please submit, at the start of your lab period in 2 weeks time (Week 3), your complete and documented answers to the questions above in the standard submission format (see the course web site) of cover page and index, followed by a prose answer to each of the questions with complete supporting material attached, all to be cleanly printed on 8.5 by 11 inch paper stapled on the top-left corner. No envelope or cover is required. No electronic submission is required.
This supporting material will include your Problem Statement, Internal Design (only; there is no need in this case for the external design since that has already been done; exception: you will supply your initial Test Plan), Implementation of your repaired code with minimal changes and your modified test driver, and test results (use script, lightly edited). See the "How-To" document on the course web site for an example of these steps and what is required for them.
Note that you are to fix only the ConvertDays() function. Be sure to use the -ansi -pedantic -Wall -Wextra -O2 options for your compiles with gcc.
/**** The alleged Zune bug, based on the code posted at
<http://pastie.org/349916> on 31 December 2008 ****/
#include <stdio.h>
/* REAllison's version of the function */
int ConvertDays(int);
/* number of days in each year */
#define DAYS_IN_2006 365
#define DAYS_IN_2007 365
#define DAYS_IN_2008 366
/* cumulative days for each 31 Dec since base year */
#define DEC_31_2006 (DAYS_IN_2006)
#define DEC_31_2007 (DEC_31_2006 + DAYS_IN_2007)
#define DEC_31_2008 (DEC_31_2007 + DAYS_IN_2008)
/* driver to demonstrate code - modify as needed for testing */
int main(void)
{
int year;
year = ConvertDays(DEC_31_2006);
printf("2006: year returned %d\n", year);
year = ConvertDays(DEC_31_2007);
printf("2007: year returned %d\n", year);
year = ConvertDays(DEC_31_2008);
printf("2008: year returned %d\n", year);
return 0;
}
/******* required for the functions below *******/
/* function needed for ConvertDays() */
static int IsLeapYear(int);
/* base year for ConvertDays() - changed from 1980 to simplify it.
"The Zune's real-time clock stores the time in terms of days and
seconds since January 1st, 1980. When the Zune's clock is accessed,
the driver turns the number of days into years/months/days and the
number of seconds into hours/minutes/seconds. Likewise, when the
clock is set, the driver does the opposite." - Zuneboards */
#define ORIGINYEAR 2006
/*********************************************************************
The Zune bug, as interpreted by REAllison for C89/C90 1 Jan 2009.
The original code is said to have been supplied by Freescale, the
board manufacturer. Your fix must be in this function only.
*********************************************************************/
int ConvertDays(int days)
{
int year;
year = ORIGINYEAR;
while (days > 365)
{
if (IsLeapYear(year))
{
if (days > 366)
{
days -= 366;
year += 1;
}
}
else
{
days -= 365;
year += 1;
}
}
return year;
}
/********************************************************************/
/* Original code used by ConvertDays() - do not modify */
static int IsLeapYear(int Year)
{
int Leap;
Leap = 0;
if ((Year % 4) == 0) {
Leap = 1;
if ((Year % 100) == 0) {
Leap = (Year%400) ? 0 : 1;
}
}
return (Leap);
}
/* end of file */