mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-05 15:15:44 +00:00
This commit was manufactured by cvs2svn to create branch 'rtems-4-6-branch'.
Cherrypick from master 2004-10-11 20:13:31 UTC Eric Norum <WENorum@lbl.gov> 'Don't get duplication rtc_probe() definitions.': c/src/lib/libbsp/i386/pc386/clock/todcfg.c c/src/libchip/rtc/README.mc146818a c/src/libchip/rtc/mc146818a.c c/src/libchip/rtc/mc146818a.h c/src/libchip/rtc/mc146818a_ioreg.c
This commit is contained in:
36
c/src/lib/libbsp/i386/pc386/clock/todcfg.c
Normal file
36
c/src/lib/libbsp/i386/pc386/clock/todcfg.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file contains the RTC driver table for Motorola shared BSPs.
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <bsp.h>
|
||||
#include <libchip/rtc.h>
|
||||
#include <libchip/mc146818a.h>
|
||||
|
||||
/* The following table configures the RTC drivers used in this BSP */
|
||||
rtc_tbl RTC_Table[] = {
|
||||
{
|
||||
"/dev/rtc", /* sDeviceName */
|
||||
RTC_MC146818A, /* deviceType */
|
||||
&mc146818a_fns, /* pDeviceFns */
|
||||
mc146818a_probe, /* deviceProbe */
|
||||
NULL, /* pDeviceParams */
|
||||
0x70, /* ulCtrlPort1 */
|
||||
0x00, /* ulDataPort */
|
||||
mc146818a_get_register, /* getRegister */
|
||||
mc146818a_set_register /* setRegister */
|
||||
}
|
||||
};
|
||||
|
||||
/* Some information used by the RTC driver */
|
||||
|
||||
#define NUM_RTCS (sizeof(RTC_Table)/sizeof(rtc_tbl))
|
||||
|
||||
unsigned long RTC_Count = NUM_RTCS;
|
||||
|
||||
rtems_device_minor_number RTC_Minor;
|
||||
5
c/src/libchip/rtc/README.mc146818a
Normal file
5
c/src/libchip/rtc/README.mc146818a
Normal file
@@ -0,0 +1,5 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
This is supported by the mc146818a driver.
|
||||
179
c/src/libchip/rtc/mc146818a.c
Normal file
179
c/src/libchip/rtc/mc146818a.c
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* This file interfaces with the real-time clock found in
|
||||
* a Motorola MC146818A (common on PC hardware)
|
||||
*
|
||||
* Year 2K Notes:
|
||||
*
|
||||
* This chip only uses a two digit field to store the year. This
|
||||
* code uses the RTEMS Epoch as a pivot year. This lets us map the
|
||||
* two digit year field as follows:
|
||||
*
|
||||
* + two digit years 0-87 are mapped to 2000-2087.
|
||||
* + two digit years 88-99 are mapped to 1988-1999.
|
||||
*
|
||||
* This is less than the time span supported by RTEMS.
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1999.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
#include <rtems.h>
|
||||
#include <libchip/rtc.h>
|
||||
#include <libchip/mc146818a.h>
|
||||
#include <bsp.h>
|
||||
|
||||
#define From_BCD( _x ) ((((_x) >> 4) * 10) + ((_x) & 0x0F))
|
||||
#define To_BCD( _x ) ((((_x) / 10) << 4) + ((_x) % 10))
|
||||
|
||||
/*
|
||||
* See if chip is present
|
||||
*/
|
||||
boolean mc146818a_probe(
|
||||
int minor
|
||||
)
|
||||
{
|
||||
unsigned32 mc146818a;
|
||||
getRegister_f getReg;
|
||||
unsigned32 value;
|
||||
|
||||
/*
|
||||
* Verify that chip is present and that time is valid
|
||||
*/
|
||||
mc146818a = RTC_Table[ minor ].ulCtrlPort1;
|
||||
getReg = RTC_Table[ minor ].getRegister;
|
||||
value = (*getReg)( mc146818a, MC146818A_STATUSD );
|
||||
if ((value == 0) || (value == 0xFF))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize chip
|
||||
*/
|
||||
void mc146818a_initialize(
|
||||
int minor
|
||||
)
|
||||
{
|
||||
unsigned32 mc146818a;
|
||||
getRegister_f getReg;
|
||||
setRegister_f setReg;
|
||||
|
||||
mc146818a = RTC_Table[ minor ].ulCtrlPort1;
|
||||
getReg = RTC_Table[ minor ].getRegister;
|
||||
setReg = RTC_Table[ minor ].setRegister;
|
||||
|
||||
(*setReg)( mc146818a, MC146818A_STATUSA, MC146818ASA_DIVIDER|MC146818ASA_1024 );
|
||||
(*setReg)( mc146818a, MC146818A_STATUSB, MC146818ASB_24HR );
|
||||
}
|
||||
|
||||
/*
|
||||
* Read time from chip
|
||||
*/
|
||||
int mc146818a_get_time(
|
||||
int minor,
|
||||
rtems_time_of_day *time
|
||||
)
|
||||
{
|
||||
unsigned32 mc146818a;
|
||||
getRegister_f getReg;
|
||||
unsigned32 value;
|
||||
rtems_interrupt_level level;
|
||||
|
||||
mc146818a = RTC_Table[ minor ].ulCtrlPort1;
|
||||
getReg = RTC_Table[ minor ].getRegister;
|
||||
|
||||
/*
|
||||
* No time if power failed
|
||||
*/
|
||||
if (((*getReg)( mc146818a, MC146818A_STATUSD ) & MC146818ASD_PWR) == 0)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* Wait for time update to complete
|
||||
*/
|
||||
rtems_interrupt_disable( level );
|
||||
while (((*getReg)( mc146818a, MC146818A_STATUSA ) & MC146818ASA_TUP) != 0) {
|
||||
rtems_interrupt_flash( level );
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the time (we have at least 244 usec to do this)
|
||||
*/
|
||||
value = (*getReg)( mc146818a, MC146818A_YEAR );
|
||||
value = From_BCD( value );
|
||||
if ( value < 88 )
|
||||
time->year = 2000 + value;
|
||||
else
|
||||
time->year = 1900 + value;
|
||||
|
||||
value = (*getReg)( mc146818a, MC146818A_MONTH );
|
||||
time->month = From_BCD( value );
|
||||
|
||||
value = (*getReg)( mc146818a, MC146818A_DAY );
|
||||
time->day = From_BCD( value );
|
||||
|
||||
value = (*getReg)( mc146818a, MC146818A_HRS );
|
||||
time->hour = From_BCD( value );
|
||||
|
||||
value = (*getReg)( mc146818a, MC146818A_MIN );
|
||||
time->minute = From_BCD( value );
|
||||
|
||||
value = (*getReg)( mc146818a, MC146818A_SEC );
|
||||
rtems_interrupt_enable( level );
|
||||
time->second = From_BCD( value );
|
||||
time->ticks = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set time into chip
|
||||
*/
|
||||
int mc146818a_set_time(
|
||||
int minor,
|
||||
rtems_time_of_day *time
|
||||
)
|
||||
{
|
||||
unsigned32 mc146818a;
|
||||
getRegister_f getReg;
|
||||
setRegister_f setReg;
|
||||
|
||||
mc146818a = RTC_Table[ minor ].ulCtrlPort1;
|
||||
getReg = RTC_Table[ minor ].getRegister;
|
||||
setReg = RTC_Table[ minor ].setRegister;
|
||||
|
||||
/*
|
||||
* Stop the RTC
|
||||
*/
|
||||
(*setReg)( mc146818a, MC146818A_STATUSB, MC146818ASB_HALT|MC146818ASB_24HR );
|
||||
|
||||
if ( time->year >= 2088 )
|
||||
rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );
|
||||
|
||||
(*setReg)( mc146818a, MC146818A_YEAR, To_BCD(time->year % 100) );
|
||||
(*setReg)( mc146818a, MC146818A_MONTH, To_BCD(time->month) );
|
||||
(*setReg)( mc146818a, MC146818A_DAY, To_BCD(time->day) );
|
||||
(*setReg)( mc146818a, MC146818A_HRS, To_BCD(time->hour) );
|
||||
(*setReg)( mc146818a, MC146818A_MIN, To_BCD(time->minute) );
|
||||
(*setReg)( mc146818a, MC146818A_SEC, To_BCD(time->second) );
|
||||
|
||||
/*
|
||||
* Restart the RTC
|
||||
*/
|
||||
(*setReg)( mc146818a, MC146818A_STATUSB, MC146818ASB_24HR );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Driver function table
|
||||
*/
|
||||
rtc_fns mc146818a_fns = {
|
||||
mc146818a_initialize,
|
||||
mc146818a_get_time,
|
||||
mc146818a_set_time
|
||||
};
|
||||
67
c/src/libchip/rtc/mc146818a.h
Normal file
67
c/src/libchip/rtc/mc146818a.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file contains the definitions for the following real-time clocks:
|
||||
*
|
||||
* + Motorola MC146818A
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1999.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef __LIBCHIP_MC146818A_h
|
||||
#define __LIBCHIP_MC146818A_h
|
||||
|
||||
/*
|
||||
* Register addresses within chip
|
||||
*/
|
||||
#define MC146818A_SEC 0x00 /* seconds */
|
||||
#define MC146818A_SECALRM 0x01 /* seconds alarm */
|
||||
#define MC146818A_MIN 0x02 /* minutes */
|
||||
#define MC146818A_MINALRM 0x03 /* minutes alarm */
|
||||
#define MC146818A_HRS 0x04 /* hours */
|
||||
#define MC146818A_HRSALRM 0x05 /* hours alarm */
|
||||
#define MC146818A_WDAY 0x06 /* week day */
|
||||
#define MC146818A_DAY 0x07 /* day of month */
|
||||
#define MC146818A_MONTH 0x08 /* month of year */
|
||||
#define MC146818A_YEAR 0x09 /* month of year */
|
||||
|
||||
#define MC146818A_STATUSA 0x0a /* status register A */
|
||||
#define MC146818ASA_TUP 0x80 /* time update in progress */
|
||||
#define MC146818ASA_DIVIDER 0x20 /* divider for 32768 crystal */
|
||||
#define MC146818ASA_1024 0x06 /* divide to 1024 Hz */
|
||||
|
||||
#define MC146818A_STATUSB 0x0b /* status register B */
|
||||
#define MC146818ASB_DST 0x01 /* Daylight Savings Time */
|
||||
#define MC146818ASB_24HR 0x02 /* 0 = 12 hours, 1 = 24 hours */
|
||||
#define MC146818ASB_HALT 0x80 /* stop clock updates */
|
||||
|
||||
#define MC146818A_STATUSD 0x0d /* status register D */
|
||||
#define MC146818ASD_PWR 0x80 /* clock lost power */
|
||||
|
||||
|
||||
/*
|
||||
* Driver function table
|
||||
*/
|
||||
extern rtc_fns mc146818a_fns;
|
||||
|
||||
/*
|
||||
* Default register access routines
|
||||
*/
|
||||
unsigned32 mc146818a_get_register(
|
||||
unsigned32 ulCtrlPort,
|
||||
unsigned8 ucRegNum
|
||||
);
|
||||
|
||||
void mc146818a_set_register(
|
||||
unsigned32 ulCtrlPort,
|
||||
unsigned8 ucRegNum,
|
||||
unsigned32 ucData
|
||||
);
|
||||
|
||||
#endif
|
||||
/* end of include file */
|
||||
45
c/src/libchip/rtc/mc146818a_ioreg.c
Normal file
45
c/src/libchip/rtc/mc146818a_ioreg.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file contains a typical set of register access routines which may be
|
||||
* used with the MC146818A chip if accesses to the chip are as follows:
|
||||
*
|
||||
* + registers are in I/O space
|
||||
* + registers are accessed as bytes
|
||||
* + registers are only byte-aligned (no address gaps)
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1997.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <rtems.h>
|
||||
#include <bsp.h>
|
||||
|
||||
unsigned32 mc146818a_get_register(
|
||||
unsigned32 ulCtrlPort,
|
||||
unsigned8 ucRegNum
|
||||
)
|
||||
{
|
||||
unsigned8 val;
|
||||
unsigned8 tmp;
|
||||
|
||||
outport_byte( ulCtrlPort, ucRegNum );
|
||||
inport_byte( 0x84, tmp ); /* Hack a delay to give chip time to settle */
|
||||
inport_byte( ulCtrlPort+1, val );
|
||||
inport_byte( 0x84, tmp ); /* Hack a delay to give chip time to settle */
|
||||
return val;
|
||||
}
|
||||
|
||||
void mc146818a_set_register(
|
||||
unsigned32 ulCtrlPort,
|
||||
unsigned8 ucRegNum,
|
||||
unsigned32 ucData
|
||||
)
|
||||
{
|
||||
outport_byte( ulCtrlPort, ucRegNum );
|
||||
outport_byte( ulCtrlPort+1, (unsigned8)ucData );
|
||||
}
|
||||
Reference in New Issue
Block a user