2007-04-17 Joel Sherrill <joel@OARcorp.com>

* shared/clock/rtc.c, shared/timer/timer.c: Fix compile errors and
	address most warnings about constants being too large.
This commit is contained in:
Joel Sherrill
2007-04-17 17:00:38 +00:00
parent 1964b69a8b
commit d7fa4a981b
3 changed files with 42 additions and 22 deletions

View File

@@ -1,3 +1,8 @@
2007-04-17 Joel Sherrill <joel@OARcorp.com>
* shared/clock/rtc.c, shared/timer/timer.c: Fix compile errors and
address most warnings about constants being too large.
2006-12-02 Ralf Corsépius <ralf.corsepius@rtems.org> 2006-12-02 Ralf Corsépius <ralf.corsepius@rtems.org>
* configure.ac: New BUG-REPORT address. * configure.ac: New BUG-REPORT address.

View File

@@ -28,6 +28,20 @@
#define SHF_MINUTE 6 #define SHF_MINUTE 6
#define SHF_SECOND 0 #define SHF_SECOND 0
/* The following are inside RTEMS -- we are violating visibility!!!
* Perhaps an API could be defined to get days since 1 Jan.
*/
extern const uint16_t _TOD_Days_to_date[2][13];
/*
* Prototypes and routines used below
*/
int Leap_years_until_now (int year);
void Init_RTC(void)
{
*((uint16_t*)RTC_PREN) = 0x0001; /* Enable Prescaler */
}
rtems_device_driver rtc_initialize( rtems_device_driver rtc_initialize(
rtems_device_major_number major, rtems_device_major_number major,
@@ -52,13 +66,6 @@ rtems_device_driver rtc_initialize(
return RTEMS_SUCCESSFUL; return RTEMS_SUCCESSFUL;
} }
void Init_RTC(void)
{
*((uint16_t*)RTC_PREN) = 0x0001; /* Enable Prescaler */
}
int Leap_years_until_now (int year);
/* /*
* Read time from RTEMS' clock manager and set it to RTC * Read time from RTEMS' clock manager and set it to RTC
*/ */
@@ -98,12 +105,19 @@ int setRealTime(
tod_temp = *tod; tod_temp = *tod;
days = (tod_temp.year - TOD_BASE_YEAR)*365 + _TOD_Days_to_date[0][tod_temp.month] + tod_temp.day - 1; days = (tod_temp.year - TOD_BASE_YEAR) * 365 + \
if (tod_temp.month < 3) days += Leap_years_until_now (tod_temp.year - 1); _TOD_Days_to_date[0][tod_temp.month] + tod_temp.day - 1;
else days += Leap_years_until_now (tod_temp.year); if (tod_temp.month < 3)
days += Leap_years_until_now (tod_temp.year - 1);
else
days += Leap_years_until_now (tod_temp.year);
*((uint32_t*)RTC_STAT) = (days << SHF_DAY)|(tod_temp.hour << SHF_HOUR)|(tod_temp.minute << SHF_MINUTE)|tod_temp.second; *((uint32_t*)RTC_STAT) = (days << SHF_DAY)|
(tod_temp.hour << SHF_HOUR)|
(tod_temp.minute << SHF_MINUTE)|
tod_temp.second;
return 0;
} }
/* /*
@@ -124,19 +138,18 @@ void getRealTime(
/* finding year */ /* finding year */
tod_temp.year = days/365 + TOD_BASE_YEAR; tod_temp.year = days/365 + TOD_BASE_YEAR;
if (days%365 > Leap_years_until_now (tod_temp.year - 1)){ if (days%365 > Leap_years_until_now (tod_temp.year - 1)) {
days = (days%365) - Leap_years_until_now (tod_temp.year - 1); days = (days%365) - Leap_years_until_now (tod_temp.year - 1);
}else{ } else {
tod_temp.year--; tod_temp.year--;
days = (days%365) + 365 - Leap_years_until_now (tod_temp.year - 1); days = (days%365) + 365 - Leap_years_until_now (tod_temp.year - 1);
} }
/* finding month and day */ /* finding month and day */
Leap_year = (((!(tod_temp.year%4)) && (tod_temp.year%100)) || (!(tod_temp.year%400)))?1:0; Leap_year = (((!(tod_temp.year%4)) && (tod_temp.year%100)) ||
for (n=1; n<=12; n++) (!(tod_temp.year%400)))?1:0;
{ for (n=1; n<=12; n++) {
if (days <= _TOD_Days_to_date[Leap_year][n+1]) if (days <= _TOD_Days_to_date[Leap_year][n+1]) {
{
tod_temp.month = n; tod_temp.month = n;
tod_temp.day = days - _TOD_Days_to_date[Leap_year][n]; tod_temp.day = days - _TOD_Days_to_date[Leap_year][n];
break; break;
@@ -173,5 +186,7 @@ int checkRealTime (void)
int Leap_years_until_now (int year) int Leap_years_until_now (int year)
{ {
return ((year/4 - year/100 + year/400) - ((TOD_BASE_YEAR - 1)/4 - (TOD_BASE_YEAR - 1)/100 + (TOD_BASE_YEAR - 1)/400)); return ((year/4 - year/100 + year/400) -
((TOD_BASE_YEAR - 1)/4 - (TOD_BASE_YEAR - 1)/100 +
(TOD_BASE_YEAR - 1)/400));
} }

View File

@@ -62,7 +62,7 @@ int Read_timer( void )
{ {
uint32_t clicks; uint32_t clicks;
uint32_t total; uint32_t total;
register int *cycles asm ("R2"); register uint32_t cycles asm ("R2");
/* stop counter */ /* stop counter */
asm("R2 = SYSCFG;"); asm("R2 = SYSCFG;");