Commit f38116c4 authored by Jeffrey Lee's avatar Jeffrey Lee
Browse files

Add RTC HAL device

Detail:
  CJE's RTC module uses a DS1307-compatible RTC chip similar to the one used in the Iyonix. Previously the kernel handled talking to it, but now that low-level RTC handling has been moved out of the kernel we need an RTC HAL device in the BCM2835 HAL instead.
  s/RTC - A copy of s.RTC from the Tungsten HAL, relicensed as BSD with permission from Rob Sprowson
  Makefile, hdr/StaticWS, s/Top - Additional changes needed to hook the code into the HAL
Admin:
  Tested on Raspberry Pi, but without an RTC module fitted
  However the similarity of the clock chip to the one in the Iyonix should mean there's little chance of this code failing to work correctly when an RTC is fitted


Version 0.31. Tagged as 'BCM2835-0_31'
parent dd550494
......@@ -17,7 +17,7 @@
COMPONENT = BCM2835 HAL
TARGET = BCM2835
OBJS = Top CLib CMOS Debug Interrupts SDIO Stubs Timers UART USB Video DMA Messaging GPIO VCHIQ IIC
OBJS = Top CLib CMOS Debug Interrupts SDIO Stubs Timers UART USB Video DMA Messaging GPIO VCHIQ IIC RTC
HDRS =
CMHGFILE =
......
......@@ -11,13 +11,13 @@
GBLS Module_HelpVersion
GBLS Module_ComponentName
GBLS Module_ComponentPath
Module_MajorVersion SETS "0.30"
Module_Version SETA 30
Module_MajorVersion SETS "0.31"
Module_Version SETA 31
Module_MinorVersion SETS ""
Module_Date SETS "15 Dec 2013"
Module_ApplicationDate SETS "15-Dec-13"
Module_Date SETS "19 Dec 2013"
Module_ApplicationDate SETS "19-Dec-13"
Module_ComponentName SETS "BCM2835"
Module_ComponentPath SETS "mixed/RiscOS/Sources/HAL/BCM2835"
Module_FullVersion SETS "0.30"
Module_HelpVersion SETS "0.30 (15 Dec 2013)"
Module_FullVersion SETS "0.31"
Module_HelpVersion SETS "0.31 (19 Dec 2013)"
END
/* (0.30)
/* (0.31)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 0.30
#define Module_MajorVersion_CMHG 0.31
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 15 Dec 2013
#define Module_Date_CMHG 19 Dec 2013
#define Module_MajorVersion "0.30"
#define Module_Version 30
#define Module_MajorVersion "0.31"
#define Module_Version 31
#define Module_MinorVersion ""
#define Module_Date "15 Dec 2013"
#define Module_Date "19 Dec 2013"
#define Module_ApplicationDate "15-Dec-13"
#define Module_ApplicationDate "19-Dec-13"
#define Module_ComponentName "BCM2835"
#define Module_ComponentPath "mixed/RiscOS/Sources/HAL/BCM2835"
#define Module_FullVersion "0.30"
#define Module_HelpVersion "0.30 (15 Dec 2013)"
#define Module_LibraryVersionInfo "0:30"
#define Module_FullVersion "0.31"
#define Module_HelpVersion "0.31 (19 Dec 2013)"
#define Module_LibraryVersionInfo "0:31"
......@@ -158,6 +158,7 @@ VCHIQDevice # HALDevice_VCHIQ_Size
GPIODevice # HALDevice_GPIO_Size
VDUDevice # HALDevice_VDU_Size
VDUDevSpec # VDUDevSpec_Size
RTCDeviceStruct # 80
HAL_WsSize * :INDEX:@
sizeof_workspace * :INDEX:@
......
;
; Copyright (c) 2013, RISC OS Open Ltd
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
; * Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; * Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
; * Neither the name of RISC OS Open Ltd nor the names of its contributors
; may be used to endorse or promote products derived from this software
; without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
; POSSIBILITY OF SUCH DAMAGE.
;
GET Hdr:ListOpts
GET Hdr:Macros
GET Hdr:HALEntries
GET Hdr:HALDevice
GET Hdr:RTCDevice
GET hdr.StaticWS
GET hdr.CastleMacros
EXPORT RTC_InitDevices
IMPORT memcpy
RTCAddressDAL * &D0
^ 0
RTC_Public # HALDevice_RTC_Size
RTCDeviceHAL_SB # 4
RTCDevice_RTC_Size # 0
; HAL code for DS1307-compatible real time clocks
; e.g. CJE's RTC module uses a DS1338
AREA |Asm$$Code|, CODE, READONLY, PIC
RTC_InitDevices ROUT
Push "lr"
SUB sp, sp, #12+12+4
MOV a1, sp
MOV a2, #RTCAddressDAL + 1 ; read op
ADD a3, sp, #12 ; -> data block
MOV a4, #1 ; data block size
STMIA a1, {a2-a4}
MOV a2, #1 ; 1 transfer on bus 0
CallOS OS_IICOpV
TEQ a1, #IICStatus_Completed
BNE %FT10 ; some failure => no RTC device
ADD a1, sp, #12
MOV a2, #RTCAddressDAL + 1 ; read op
ADD a3, sp, #12+12+0 ; -> data block
MOV a4, #1 ; data block size
STMIA a1, {a2-a4}
MOV a2, #RTCAddressDAL
ORR a2, a2, #1:SHL:29 ; write op with retry
ADD a3, sp, #12+12+1 ; -> data block
MOV a4, #0
STRB a4, [a3] ; start from register 0
MOV a4, #1 ; data block size
STMDB a1!, {a2-a4}
MOV a2, #2 ; 2 transfers on bus 0
CallOS OS_IICOpV
LDRB a4, [sp, #12+12+0]
TST a4, #1:SHL:7 ; is the clock halted?
BEQ %FT05
MOV a1, sp
MOV a2, #RTCAddressDAL
ORR a2, a2, #1:SHL:29 ; write op with retry
ADD a3, sp, #12 ; -> data block
MOV a4, #0
STR a4, [a3, #12] ; clear clock halt bit (and seconds)
MOV a4, #2 ; data block size
STMIA a1, {a2-a4}
MOV a2, #1 ; 1 transfer on bus 0
CallOS OS_IICOpV
05
ADRL a1, RTCDeviceStruct
ADR a2, RTCTemplate
MOV a3, #RTCDevice_RTC_Size
BL memcpy ; softcopy needed to append SB to
STR sb, [a1, #RTCDeviceHAL_SB]
MOV a2, a1 ; device
MOV a1, #0 ; flags
CallOS OS_AddDevice
10
ADD sp, sp, #12+12+4
Pull "pc"
RTCTemplate
; Public interface
DCW HALDeviceType_SysPeri + HALDeviceSysPeri_RTC
DCW HALDeviceID_RTC_DS1307
DCD HALDeviceBus_Ser + HALDeviceSerBus_IIC
DCD 0 ; API version
DCD RTCDesc
DCD 0 ; Address - N/A
% 12 ; Reserved
DCD RTCActivate
DCD RTCDeactivate
DCD RTCReset
DCD RTCSleep
DCD -1 ; Interrupt N/A
DCD 0
% 8
; Specifics for an RTC
DCB RTCTimeFormat_BCD
DCB RTCFormatFlags_BCD_1BasedDay + \
RTCFormatFlags_BCD_1BasedMonth + \
RTCFormatFlags_BCD_NeedsYearHelp + \
RTCFormatFlags_BCD_YearLOIsGood
% 2
DCD RTCReadTime
DCD RTCWriteTime
ASSERT (.-RTCTemplate) = HALDevice_RTC_Size
; RTC's private data from here onwards
DCD 0 ; Copy of HAL's SB
ASSERT (.-RTCTemplate) = RTCDevice_RTC_Size
ASSERT ?RTCDeviceStruct = RTCDevice_RTC_Size
RTCDesc
DCB "DS1307-compatible real-time clock", 0
ALIGN
RTCActivate
MOV a1, #1
RTCDeactivate
RTCReset
MOV pc, lr
RTCSleep
MOV a1, #0 ; Previously at full power
MOV pc, lr
; int RTCReadTime(struct rtcdevice *rtc, struct rtctime *time)
; Returns an RTCRetCode
RTCReadTime ROUT
Push "sb, v1, lr"
MOV v1, a2
LDR sb, [a1, #RTCDeviceHAL_SB]
SUB sp, sp, #12+12+8
ADD a1, sp, #12
MOV a2, #RTCAddressDAL + 1 ; read op
ADD a3, sp, #12+12+0 ; -> data block
MOV a4, #7 ; data block size
STMIA a1, {a2-a4}
MOV a2, #RTCAddressDAL
ORR a2, a2, #1:SHL:29 ; write op with retry
ADD a3, sp, #12+12+7 ; -> data block
MOV a4, #0
STRB a4, [a3] ; start from register 0
MOV a4, #1 ; data block size
STMDB a1!, {a2-a4}
MOV a2, #2 ; 2 transfers on bus 0
CallOS OS_IICOpV
TEQ a1, #IICStatus_Completed
MOVNE a1, #RTCRetCode_Error
BNE %FT10
ASSERT RTCTimeStruct_BCD_Centiseconds = 0
ASSERT RTCTimeStruct_BCD_Seconds = 1
ASSERT RTCTimeStruct_BCD_Minutes = 2
ASSERT RTCTimeStruct_BCD_Hours = 3
LDR a3, [sp, #12+12+0]
MOV a3, a3, LSL #8 ; zero centiseconds, discard d-o-w
STR a3, [v1, #0]
ASSERT RTCTimeStruct_BCD_DayOfMonth = 4
ASSERT RTCTimeStruct_BCD_Month = 5
ASSERT RTCTimeStruct_BCD_YearLO = 6
LDR a3, [sp, #12+12+4]
BIC a3, a3, #&FF:SHL:24 ; chip regs match struct
STR a3, [v1, #4]
MOV a1, #RTCRetCode_OK
10
ADD sp, sp, #12+12+8
Pull "sb, v1, pc"
; int RTCWriteTime(struct rtcdevice *rtc, const struct rtctime *time)
; Returns an RTCRetCode
RTCWriteTime
Push "sb, v1-v2, lr"
ASSERT RTCTimeStruct_BCD_Size = 8
LDMIA a2, {v1-v2}
LDR sb, [a1, #RTCDeviceHAL_SB]
SUB sp, sp, #12+12
ADD ip, sp, #12+3 ; -> data block
CMP v1, #-1
MOVNE a4, #0 ; start from time register
MOVEQ a4, #4 ; start from date register
STRB a4, [ip], #1
ASSERT RTCTimeStruct_BCD_Centiseconds = 0
ASSERT RTCTimeStruct_BCD_Seconds = 1
ASSERT RTCTimeStruct_BCD_Minutes = 2
ASSERT RTCTimeStruct_BCD_Hours = 3
MOVNE v1, v1, LSR #8 ; no cs
ORRNE v1, v1, #1:SHL:24
STRNE v1, [ip], #4 ; s,m,h,any d-o-w
CMP v2, #-1
ASSERT RTCTimeStruct_BCD_DayOfMonth = 4
ASSERT RTCTimeStruct_BCD_Month = 5
ASSERT RTCTimeStruct_BCD_YearLO = 6
STRNE v2, [ip], #3 ; dom,mon,ylo
MOV a1, sp
MOV a2, #RTCAddressDAL
ORR a2, a2, #1:SHL:29 ; write op with retry
ADD a3, sp, #12+3 ; -> data block
SUB a4, ip, a3 ; data block size
STMIA a1, {a2-a4}
MOV a2, #1 ; 1 transfer on bus 0
CallOS OS_IICOpV
TEQ a1, #IICStatus_Completed
ASSERT IICStatus_Completed = RTCRetCode_OK
MOVNE a1, #RTCRetCode_Error
ADD sp, sp, #12+12
Pull "sb, v1-v2, pc"
END
......@@ -133,6 +133,8 @@
IMPORT Video_InitDevices
IMPORT RTC_InitDevices
IMPORT HAL_SendHostMessage
IMPORT HAL_QueryPlatform
......@@ -776,6 +778,7 @@ HAL_InitDevices
BL DMA_InitDevices
BL GPIO_InitDevices
BL VCHIQ_InitDevices
BL RTC_InitDevices
LDR pc, [sp], #4
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment