; ; Copyright (c) 2012, 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. ; AREA |ARM$$code|, CODE, READONLY, PIC GET Hdr:ListOpts GET Hdr:Macros GET Hdr:Proc GET hdr.BCM2835 GET hdr.StaticWS EXPORT GPIO_InitDevices IMPORT memcpy MACRO $class HALDeviceField $field, $value LCLS myvalue [ "$value" = "" myvalue SETS "$field" | myvalue SETS "$value" ] ASSERT . - %A0 = HALDevice_$class$field [ ?HALDevice_$class$field = 2 DCW $myvalue ELIF ?HALDevice_$class$field = 4 DCD $myvalue | % ?HALDevice_$class$field ] MEND ; Template for GPIO interface GPIO_Dev 0 HALDeviceField Type, HALDeviceType_Comms + HALDeviceComms_GPIO HALDeviceField ID, HALDeviceID_GPIO_BCM2835 HALDeviceField Location, HALDeviceBus_Sys + HALDeviceSysBus_AHB ; Guess HALDeviceField Version, 0 HALDeviceField Description, GPIO_Description HALDeviceField Address, 0 HALDeviceField Reserved1, 0 HALDeviceField Activate, GPIO_Activate HALDeviceField Deactivate, GPIO_Deactivate HALDeviceField Reset, GPIO_Reset HALDeviceField Sleep, GPIO_Sleep HALDeviceField Device, -1 HALDeviceField TestIRQ, 0 HALDeviceField ClearIRQ, 0 HALDeviceField Reserved2, 0 GPIO HALDeviceField Type, GPIOType_BCM2835_RaspberryPi GPIO HALDeviceField Revision, 0 ; Filled in at runtime ASSERT . - %A0 = HALDevice_GPIO_Size GPIO_Description = "BCM2835 GPIO interface", 0 ALIGN ; Lookup table to determine board type MACRO BoardType $model, $minrev, $maxrev, $type DCD $model DCD $minrev DCD $maxrev DCD GPIORevision_RaspberryPi_$type MEND GPIO_BoardTypes BoardType 0, &02, &03, B_1 BoardType 0, &04, &06, B_2 BoardType 0, &07, &09, A_2 BoardType 0, &0d, &0f, B_2 BoardType 0, &10, &ffffffff, BPlus ; Assume anything newer will be compatible so that minor revisions don't trip us up GPIO_BoardTypes_End ; Initialise our HAL devices GPIO_InitDevices ROUT Entry "v1-v3" ADRL a1, GPIODevice ADR a2, GPIO_Dev MOV a3, #HALDevice_GPIO_Size BL memcpy ADR v1, GPIO_BoardTypes LDR v2, Board_Model LDR v3, Board_Revision ADR ip, GPIO_BoardTypes_End 10 CMP v1, ip EXIT EQ ; Unknown model, give up LDMIA v1!, {a1-a4} CMP a1, v2 BNE %BT10 CMP a2, v3 CMPLS v3, a3 BHI %BT10 ; Found a match ADRL a2, GPIODevice STR a4, [a2, #HALDevice_GPIORevision] MOV a1, #0 MOV lr, pc LDR pc, OSentries+4*OS_AddDevice EXIT GPIO_Activate MOV a1, #1 GPIO_Deactivate GPIO_Reset MOV pc, lr GPIO_Sleep MOV a1, #0 MOV pc, lr END