On December 26, 2006 09:09 am, S.Lakshmanan (EEE) wrote:
> any one help me with a sample code to access the RTC on the
> TS7250 board?
Its assembler, but it may be usefull:
-Curtis.
/*=============================================================================
| RTC (Real Time Clock) Routines
|
| Author:
| Curtis Monroe <>
|
| Licence:
|
| Copyright (C) 2006 Curtis Monroe.
|
| This program is free software; you can redistribute it and/or modify
| it under the terms of the GNU General Public License as published by
| the Free Software Foundation; either version 2 of the License, or
| (at your option) any later version.
|
| This program is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
| GNU General Public License for more details.
|
| You should have received a copy of the GNU General Public License
| along with this program; if not, write to the
| Free Software Foundation, Inc.,
| 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| DATE | NOTES
-------------------------------------------------------------------------------
| 2006-10-31 | Created file
| |
| |
| |
-------------------------------------------------------------------------------
| Future Enhancements:
|
|
|
|
-------------------------------------------------------------------------------
=============================================================================*/
@--------------------------------
@ TS-7XXX RTC Registers
@
@ 0x1170_0000 - TS-7xxx RTC R/W data register (BYTE)
@ 0x1080_0000 - TS-7xxx RTC Write Only index register (BYTE)
@
@ RTC M48T86 5.0V PC REAL-TIME CLOCK Registers
@
@ 0x00 - Seconds (0-59) (BYTE)
@ 0x01 - Seconds Alarm (0-59) (BYTE)
@ 0x02 - Minutes (0-59) (BYTE)
@ 0x03 - Minutes Alarm (0-59) (BYTE)
@ 0x04 - Hours (0-23)(BYTE)
@ 0x05 - Hours Alarm (0-23) (BYTE)
@ 0x06 - Day of Week (1=Sunday..7) (BYTE)
@ 0x07 - Day of Month (1-31) (BYTE)
@ 0x08 - Month (1-12) (BYTE)
@ 0x09 - Year (0-99) (BYTE)
@ 0x0A - REGISTER A (BYTE)
@ [7] - Update in Progress flag (RO)
@ [6-4] - Oscillator Control (see data sheet)
@ [3-0] - Square Wave, or Interupt Frequency (see data sheet)
@ 0x0B - REGISTER B (BYTE)
@ [7] - SET (1=latch clock)
@ [6] - Periodic Interrupt Enable
@ [5] - Alarm Interrupt Enable
@ [4] - Update Ended Interrupt Enable
@ [3] - Square Wave Enable
@ [2] - Data Mode (1=binary, 0=BCD)
@ [1] - 24/12 (1=24 hour mode)
@ [0] - Daylight Savings Enable (1=enable)
@ 0x0C - REGISTER C (BYTE RO) (TS-7XXX does not allow RTC interupts)
@ [7] - Interrupt Request Flag (1=at least one of the
following interupt is
active)
@ [6] - Periodic Interrupt Flag (1=interupt active, read
clears)
@ [5] - Alarm Flag (1=interupt active, read clears)
@ [4] - Update Ended Interrupt Flag (1=interupt active, read
clears)
@ 0x0D - REGISTER D (BYTE RO)
@ [7] - Valid Ram And Time flag (1 = valid, 0 = exhausted
lithium cell)
@ 0x0E-0x7F - DATA BYTES (114 Bytes)
@
@--------------------------------
@--------------------------------
@ Set the date and time in the RTC
@ Input:
@ r1 = Seconds (0-59)
@ r2 = Minutes (0-59)
@ r3 = Hours (0-23)
@ r4 = Day (1-31)
@ r5 = Month (1-12)
@ r6 = Year (0-99)
@ r7 = Day of Week (1=Sunday..7)
@
@ Returns:
@ r0 = unknown
@
@ Notes:
@
@
.global RtcSetDateTime
RtcSetDateTime:
stmfd sp!, {r0-r10, lr}
ldr r8, =0x11700000 @ Data Register
mov r9, #0x10800000 @ Index
Register ( Write Only )
.macro SET_REG reg, index
mov r10, #\index
strb r10, [r9]
strb \reg, [r8]
.endm
mov r0, #0b10000110 @ SET, no RTC
interupts, Binary, 24-hour, No Daylight
savings
SET_REG r0, 0x0B
SET_REG r1, 0x00 @ Seconds
(0-59) (BYTE)
SET_REG r1, 0x01 @ Seconds Alarm
(0-59) (BYTE)
SET_REG r2, 0x02 @ Minutes
(0-59) (BYTE)
SET_REG r2, 0x03 @ Minutes Alarm
(0-59) (BYTE)
SET_REG r3, 0x04 @ Hours
(0-23)(BYTE)
SET_REG r3, 0x05 @ Hours Alarm
(0-23) (BYTE)
SET_REG r7, 0x06 @ Day of Week
(1=Sunday..7) (BYTE)
SET_REG r4, 0x07 @ Day of Month
(1-31) (BYTE)
SET_REG r5, 0x08 @ Month (1-12)
(BYTE)
SET_REG r6, 0x09 @ Year (0-99)
(BYTE)
mov r0, #0b00000110 @ no SET, no
RTC interupts, Binary, 24-hour, No
Daylight savings
SET_REG r0, 0x0B
ldmfd sp!, {r0-r10, pc}
.ltorg
@--------------------------------
@ Read the data and time form the RTC
@ Input:
@ none
@ Returns:
@ r0 = Seconds (0-59)
@ r1 = Minutes (0-59)
@ r2 = Hours (0-23)
@ r3 = Day (1-31)
@ r4 = Month (1-12)
@ r5 = Year (0-99)
@ r6 = Day of Week (1=Sunday..7)
@
@ Notes:
@
@
.global RtcGetDateTime
RtcGetDateTime:
stmfd sp!, {r8-r10, lr}
ldr r8, =0x11700000 @ Data Register
mov r9, #0x10800000 @ Index
Register ( Write Only )
.macro GET_REG reg, index
mov r10, #\index
strb r10, [r9]
ldrb \reg, [r8]
.endm
GET_REG r0, 0x00
GET_REG r1, 0x02
GET_REG r2, 0x04
GET_REG r3, 0x07
GET_REG r4, 0x08
GET_REG r5, 0x09
GET_REG r6, 0x06
@ GET_REG r7, 0x0B
ldmfd sp!, {r8-r10, pc}
.ltorg
@--------------------------------
@ Set RTC non-volatile byte
@ Input:
@ r1 = address in RTC (0-113)
@ r2 = byte to write
@
@ Returns:
@ r0 = unknown
@
@ Notes:
@
@
.global RtcSetByte
RtcSetByte:
stmfd sp!, {r3-r4, lr}
ldr r3, =0x11700000 @ Data Register
mov r4, #0x10800000 @ Index
Register ( Write Only )
add r0, r1, #0x0e @ data area
offset
strb r0, [r4] @ write index
strb r2, [r3] @ drite data
byte
ldmfd sp!, {r3-r4, pc}
.ltorg
@--------------------------------
@ Get RTC non-volatile byte
@ Input:
@ r1 = address in RTC (0-113)
@
@ Returns:
@ r0 = byte from RTC nonvolatile
@
@ Notes:
@
@
.global RtcGetByte
RtcGetByte:
stmfd sp!, {r2-r3, lr}
ldr r2, =0x11700000 @ Data Register
mov r3, #0x10800000 @ Index
Register ( Write Only )
add r0, r1, #0x0e @ data area
offset
strb r0, [r3] @ write index
ldrb r0, [r2] @ read data byte
ldmfd sp!, {r2-r3, pc}
.ltorg
@--------------------------------
@ Read the data and time form the RTC
@ Input:
@ none
@ Returns:
@ Outputs the Date and Time
@
@ Notes:
@
@
.global RtcPrintDateTime
RtcPrintDateTime:
stmfd sp!, {r0-r12, lr}
bl RtcGetDateTime
mov r11, r6 @ Day of Week (1=Sunday..7)
mov r10, r5 @ Year (0-99)
mov r9, r4 @ Month (1-12)
mov r8, r3 @ Day (1-31)
mov r7, r2 @ Hours (0-23)
mov r6, r1 @ Minutes (0-59)
mov r5, r0 @ Seconds (0-59)
bl TermLightGreen
bl TermBlackBackground
mov r1, #' '
bl OutputByte
@ Output Day of Week ( Sun, Mon, ... Sat )
sub r1, r11, #1
adr r0, day_array
add r0, r0, r1, lsl #2
bl OutputString
mov r1, #','
bl OutputByte
mov r1, #' '
bl OutputByte
@ Output Month ( Jan, Feb, ... Dec )
sub r1, r9, #1
adr r0, month_array
add r0, r0, r1, lsl #2
bl OutputString
mov r1, #' '
bl OutputByte
@ Output Day of Month ( 1, 2, ... 31 )
mov r1, r8
mov r2, #2
mov r3, #' '
mov r4, #0
bl OutputDecimal
mov r1, #' '
bl OutputByte
@ Output Year ( 2000, 2001, ... 2099 )
add r0, r10, #2000
bl OutputDecWord
mov r1, #','
bl OutputByte
mov r1, #' '
bl OutputByte
@ Output Hour ( 1, 2, ... 12 )
cmp r7, #12
movle r1, r7
subgt r1, r7, #12
cmp r7, #0
moveq r1, #12
mov r2, #2
mov r3, #' '
mov r4, #0
bl OutputDecimal
mov r1, #':'
bl OutputByte
@ Output Minute ( 1, 2, ... 59 )
mov r1, r6
mov r2, #2
mov r3, #'0'
mov r4, #0
bl OutputDecimal
mov r1, #':'
bl OutputByte
@ Output Seconds ( 1, 2, ... 59 )
mov r1, r5
mov r2, #2
mov r3, #'0'
mov r4, #0
bl OutputDecimal
mov r1, #' '
bl OutputByte
cmp r7, #12
movge r1, #'P'
movlt r1, #'A'
bl OutputByte
mov r1, #'M'
bl OutputByte
mov r1, #':'
bl OutputByte
bl TermReset
ldmfd sp!, {r0-r12, pc}
.ltorg
day_array:
.string "Sun"
.string "Mon"
.string "Tue"
.string "Wed"
.string "Thu"
.string "Fri"
.string "Sat"
month_array:
.string "Jan"
.string "Feb"
.string "Mar"
.string "Apr"
.string "May"
.string "Jun"
.string "Jul"
.string "Aug"
.string "Sep"
.string "Oct"
.string "Nov"
.string "Dec"
.align
@--------------------------------
@ Shows and updates a clock on the screen
@ Input:
@ none
@
@ Output:
@ none
@
@ Notes:
@
@
.global RtcDeskClock
RtcDeskClock:
stmfd sp!, {r0-r7, lr}
bl TermOuputLineFeedAndCarriageReturn
2: bl RtcGetDateTime
mov r7, r0
bl RtcPrintDateTime
bl TermOuputLineFeedAndCarriageReturn
1: bl RtcGetDateTime
cmp r7, r0
beq 1b
mov r0, #0
bl TermCusorNUp
b 2b
ldmfd sp!, {r0-r7, pc}
.ltorg
.align
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|