svnno****@sourc*****
svnno****@sourc*****
2011年 1月 15日 (土) 02:35:57 JST
Revision: 146 http://sourceforge.jp/projects/negitoro/svn/view?view=rev&revision=146 Author: sero_s Date: 2011-01-15 02:35:57 +0900 (Sat, 15 Jan 2011) Log Message: ----------- ã³ãã³ã date ã§æå»ãè¨å®ããé, æåç§ã®ä¸ã¤ä»¥ä¸ã«0ãããå ´åã«æå»è¨å®ãã§ããªããã°ãä¿®æ£. åç §: sero_s ã«ããr141ã®ã³ã¼ãã¬ãã¥ã¼. Modified Paths: -------------- trunk/kernel/command.c trunk/kernel/rtc.c Modified: trunk/kernel/command.c =================================================================== --- trunk/kernel/command.c 2010-12-22 15:49:52 UTC (rev 145) +++ trunk/kernel/command.c 2011-01-14 17:35:57 UTC (rev 146) @@ -4,6 +4,7 @@ /// @date ? #include "bootpack.h" +unsigned long strtoul(const char *s, const char **endp, int base); // #include <stdlib.h> /// @brief bootdR}h /// @brief bootinfoÌàeð\¦·é @@ -202,23 +203,28 @@ cons_putstr0(cons, " usage: >date (YEAR-MONTH-DAY-HOUR-MINUTE-SECOND)\n"); } else { /* rtcÉ«Þ */ + const char *p = cmdline, *q; + int i; if (scan_char(cmdline, '-') != 5) { goto ferr; } - dat[5] = atoi(strtok(cmdline, "-")); /* year */ - dat[4] = atoi(strtok(NULL, "-")); /* month */ - dat[3] = atoi(strtok(NULL, "-")); /* day */ - dat[2] = atoi(strtok(NULL, "-")); /* hour */ - dat[1] = atoi(strtok(NULL, "-")); /* minute */ - dat[0] = atoi(strtok(NULL, "-")); /* second */ + for (i = 0; i < 6; i++) { + dat[6-1-i] = strtoul(p, &q, 10); // year, month, day, hour, minute, second + if (q == p) + goto ferr; + if (i < 6-1) { + if (*q != '-') + goto ferr; + q++; + } + p = q; + } + if (*p != '\0') + goto ferr; b = dat[5] / 100; - if (dat[5] && dat[4] && dat[3] && dat[2] && dat[1] && dat[0]) { - setdates(b, dat[5] - b * 100, dat[4], dat[3], dat[2], dat[1], dat[0]); - cons_putstr0(cons, "RTC is written.\n"); - clo ck_refresh(); - } else { - goto ferr; - } + setdates(b, dat[5] - b * 100, dat[4], dat[3], dat[2], dat[1], dat[0]); + cons_putstr0(cons, "RTC is written.\n"); + clock_refresh(); } goto fin; Modified: trunk/kernel/rtc.c =================================================================== --- trunk/kernel/rtc.c 2010-12-22 15:49:52 UTC (rev 145) +++ trunk/kernel/rtc.c 2011-01-14 17:35:57 UTC (rev 146) @@ -72,7 +72,8 @@ } } -/// @brief útf[^ð«Ý +/// @brief útf[^ð«Ý. +/// øªêÂÅàs³Èç½àµÈ¢. /// @param year_high ¼ïãñ /// @param year_low ¼ïºñ /// @param month @@ -80,18 +81,27 @@ /// @param hour /// @param minute ª /// @param second b +/// @todo «ñ¾ã, ³µ©¯½©Ç¤©mF·é. +/// @todo NÆÉæÁÄúÌÍͪÏíé±ÆÖÌÎ. +/// @todo øªs³Å«ÜÈ©Á½Æ«ÄÑoµ³ÖÊmÍKv©. +/// @todo NÌLøÍÍÍ0©ç9999ÜÅÅæ¢Ì©. void setdates(int year_high, int year_low, int month, int day, int hour, int minute, int second) { + static const int rtcmin[] = { 0, 0, 0, 1, 1, 0, 0 }; + const int date[] = { second, minute, hour, day, month, year_low, year_high }; + int i; + + // Çê©êÂÅàÙíÈç«Ü¸ÉI¹. + for (i = 0; i < sizeof(date)/sizeof(*date); i++) { + if (date[i] < rtcmin[i] || rtcmax[i] < date[i]) + return; + } + /* b©ç */ - if (second <= rtcmax[0]) writedata_cmos(rtcadr[0], bcdconv(second)); - if (minute <= rtcmax[1]) writedata_cmos(rtcadr[1], bcdconv(minute)); - if (hour <= rtcmax[2]) writedata_cmos(rtcadr[2], bcdconv(hour)); - if (day <= rtcmax[3]) writedata_cmos(rtcadr[3], bcdconv(day)); - if (month <= rtcmax[4]) writedata_cmos(rtcadr[4], bcdconv(month)); - if (year_low <= rtcmax[5]) writedata_cmos(rtcadr[5], bcdconv(year_low)); - if (year_high <= rtcmax[6]) writedata_cmos(rtcadr[6], bcdconv(year_high)); - return; + for (i = 0; i < sizeof(date)/sizeof(*date); i++) { + writedata_cmos(rtcadr[i], bcdconv(date[i])); + } } /// @brief BCDÖÏ·