1 | /* |
---|
2 | * This file contains a typical set of register access routines which may be |
---|
3 | * used with the MC146818A chip if accesses to the chip are as follows: |
---|
4 | * |
---|
5 | * + registers are in I/O space |
---|
6 | * + registers are accessed as bytes |
---|
7 | * + registers are only byte-aligned (no address gaps) |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-1997. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #include <rtems.h> |
---|
20 | #include <bsp.h> |
---|
21 | #include <libchip/rtc.h> |
---|
22 | #include <libchip/mc146818a.h> |
---|
23 | |
---|
24 | /* |
---|
25 | * At this point, not all CPUs or BSPs have defined in/out port routines. |
---|
26 | */ |
---|
27 | #if defined(__i386__) || defined(__PPC__) |
---|
28 | #if defined(inport_byte) |
---|
29 | uint32_t mc146818a_get_register( |
---|
30 | uintptr_t ulCtrlPort, |
---|
31 | uint8_t ucRegNum |
---|
32 | ) |
---|
33 | { |
---|
34 | uint8_t val; |
---|
35 | uint8_t tmp; |
---|
36 | |
---|
37 | (void) tmp; /* eliminate warning for set but not used */ |
---|
38 | |
---|
39 | outport_byte( ulCtrlPort, ucRegNum ); |
---|
40 | inport_byte( 0x84, tmp ); /* Hack a delay to give chip time to settle */ |
---|
41 | inport_byte( ulCtrlPort+1, val ); |
---|
42 | inport_byte( 0x84, tmp ); /* Hack a delay to give chip time to settle */ |
---|
43 | return val; |
---|
44 | } |
---|
45 | |
---|
46 | void mc146818a_set_register( |
---|
47 | uintptr_t ulCtrlPort, |
---|
48 | uint8_t ucRegNum, |
---|
49 | uint32_t ucData |
---|
50 | ) |
---|
51 | { |
---|
52 | outport_byte( ulCtrlPort, ucRegNum ); |
---|
53 | outport_byte( ulCtrlPort+1, (uint8_t)ucData ); |
---|
54 | } |
---|
55 | #endif |
---|
56 | #endif |
---|