Commit 0f24c2e2 authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Add command to list the IIC devices

New command *IICDevices probes each bus and reports what it finds.
When an ACK to an address read is received Service_IIC is set round to see if any resident device drivers have definitive knowledge about what's at the address (cf. Service_PCI), otherwise a guess will be made based on a small lookup table in the Messages.
hdr/IIC: Subreason for name lookup
IICMod.s: Loop over the buses, report what's there.
CmdHelp/Messages: New syntax, error messages, and table of IIC devices

Tested on IOMD, Titanium, and a Raspberry Pi 2.

Version 0.18, 4.5.2.12. Tagged as 'IIC-0_18-4_5_2_12'
parent ba8cd020
NoAck:No acknowledge from IIC device
InUse:IIC operation in progress
BdBus:IIC bus not present
Headr:Bus Dev Description
#{DictTokens}
# Device names if nobody knows
D2?:TV IC
D6?:Monitor IC
D7?:LCD IC
DC?:Radio IC
DA?:Memory IC
DD0:Real time clock
D??:Unidentified IC
......@@ -13,11 +13,11 @@
GBLS Module_ComponentPath
Module_MajorVersion SETS "0.18"
Module_Version SETA 18
Module_MinorVersion SETS "4.5.2.11"
Module_Date SETS "19 Oct 2016"
Module_ApplicationDate SETS "19-Oct-16"
Module_MinorVersion SETS "4.5.2.12"
Module_Date SETS "02 Feb 2017"
Module_ApplicationDate SETS "02-Feb-17"
Module_ComponentName SETS "IIC"
Module_ComponentPath SETS "castle/RiscOS/Sources/HWSupport/IIC"
Module_FullVersion SETS "0.18 (4.5.2.11)"
Module_HelpVersion SETS "0.18 (19 Oct 2016) 4.5.2.11"
Module_FullVersion SETS "0.18 (4.5.2.12)"
Module_HelpVersion SETS "0.18 (02 Feb 2017) 4.5.2.12"
END
......@@ -5,19 +5,19 @@
*
*/
#define Module_MajorVersion_CMHG 0.18
#define Module_MinorVersion_CMHG 4.5.2.11
#define Module_Date_CMHG 19 Oct 2016
#define Module_MinorVersion_CMHG 4.5.2.12
#define Module_Date_CMHG 02 Feb 2017
#define Module_MajorVersion "0.18"
#define Module_Version 18
#define Module_MinorVersion "4.5.2.11"
#define Module_Date "19 Oct 2016"
#define Module_MinorVersion "4.5.2.12"
#define Module_Date "02 Feb 2017"
#define Module_ApplicationDate "19-Oct-16"
#define Module_ApplicationDate "02-Feb-17"
#define Module_ComponentName "IIC"
#define Module_ComponentPath "castle/RiscOS/Sources/HWSupport/IIC"
#define Module_FullVersion "0.18 (4.5.2.11)"
#define Module_HelpVersion "0.18 (19 Oct 2016) 4.5.2.11"
#define Module_FullVersion "0.18 (4.5.2.12)"
#define Module_HelpVersion "0.18 (02 Feb 2017) 4.5.2.12"
#define Module_LibraryVersionInfo "0:18"
......@@ -50,6 +50,11 @@ IICAddress_AcornBMUMicrocontroller2 * &A4 ; &A4/5 Perth Battery Manage
IICAddress_AcornReserved * &D0 ; &D0/1 Reserved for Acorn
; Service call sub reasons
^ 0
Service_IIC_LookupDescription # 1
OPT OldOpt
END
......@@ -89,17 +89,17 @@ IIC_WorkspaceSize * :INDEX: @
Module_BaseAddr
DCD 0
DCD IIC_Init -Module_BaseAddr
DCD IIC_Die -Module_BaseAddr
DCD IIC_Service -Module_BaseAddr
DCD IIC_Title -Module_BaseAddr
DCD IIC_HelpStr -Module_BaseAddr
DCD IIC_HC_Table-Module_BaseAddr
DCD IIC_Init - Module_BaseAddr
DCD IIC_Die - Module_BaseAddr
DCD IIC_Service - Module_BaseAddr
DCD IIC_Title - Module_BaseAddr
DCD IIC_HelpStr - Module_BaseAddr
DCD IIC_HC_Table - Module_BaseAddr
DCD IICSWI * Module_SWIChunkSize
DCD IIC_SWIHandler-Module_BaseAddr
DCD IIC_SWINameTable-Module_BaseAddr
DCD IIC_SWIHandler - Module_BaseAddr
DCD IIC_SWINameTable - Module_BaseAddr
DCD 0 ; Code to manually decode swi name (not needed)
DCD 0 ; No messages file
DCD message_filename - Module_BaseAddr
DCD IIC_ModFlags-Module_BaseAddr
IIC_SWINameTable
......@@ -124,7 +124,9 @@ IIC_ModFlags
; *****************************************************************************
IIC_HC_Table * Module_BaseAddr
IIC_HC_Table
Command IICDevices, 1, 0, International_Help
& 0
IIC_Service * Module_BaseAddr
......@@ -295,6 +297,166 @@ GetVerNoFromHelpString Entry "r0, r4, r5, r12"
]
; *****************************************************************************
;
; IICDevices command handler
;
; in: R0 = command tail
; R1 = number of parameters
; R12 -> private word
;
; out: R0-R6, R12 may be corrupted
IICDevices_Help = "HIICD", 0
IICDevices_Syntax = "SIICD", 0
HeadrTok = "Headr", 0
ALIGN
IICDevices_Code
Entry "r7", 4
LDR r12, [r12]
MOV r7, #1 ; no header line yet
TEQ r1, #0
MOVEQ r5, #0 ; start at the bottom...
MOVEQ r2, #256 ; ...do all buses
BEQ %FT05
MOV r1, r0
MOV r0, #10 :OR: (1:SHL:30)
SWI XOS_ReadUnsigned
MOVVC r5, r2 ; start at this bus...
ADDVC r2, r5, #1 ; ...and only do that one
BVS %FT95
05
; Range check bus
MOV r0, #14
SWI XOS_ReadSysInfo ; read bus count
MOVVS r0, #1 ; at least 1 then
CMP r5, r0
BCS %FT95 ; started too high
CMP r2, r0
MOVCS r4, r0
MOVCC r4, r2 ; MIN(buses, request)
10
MOV r6, #0 ; address
20
; Try addressing each device on each bus
MOVS r0, r6, LSR #3
TEQNE r0, #2_1111
BEQ %FT50 ; skip reserved 2_1111xxx and 2_0000xxx
MOV r0, #1
ORR r0, r0, r6, LSL #1
MOV r1, sp
MOV r2, #1 ; 1 byte read transfer
TEQ r5, #0
BNE %FT30 ; Use IIC_Control for pre 5.00 compatibility
SWI XIIC_Control
B %FT40
30
Push "r0-r2" ; descriptor
MOV r0, sp
MOV r1, #1
ORR r1, r1, r5, LSL #24 ; 1 transfer on that bus
SWI XOS_IICOp
ADD sp, sp, #3*4
40
BVC %FT60 ; no error => good
LDR r1, =ErrorNumber_IIC_NoAcknowledge
LDR r2, [r0]
TEQ r2, r1
BEQ %FT50 ; no ack => goto next
EXIT VS ; some other error => bad
50
ADD r6, r6, #1
TEQ r6, #128
BNE %BT20 ; next address
ADD r5, r5, #1
TEQ r5, r4
BNE %BT10 ; next bus
CLRV
EXIT
60
; Print heading line out
SUBS r7, r7, #1
SUB sp, sp, #64 ; space for lookups
BNE %FT70
ADR r1, HeadrTok
MOV r2, sp
MOV r3, #64
BL CopyMessage
MOVVC r0, sp
SWIVC XOS_Write0
SWIVC XOS_NewLine
BVS %FT90
70
; Print device detail out
MOV r0, r5
BL PrintF_3iSpc
MOVVC r0, r6, LSL #1
BLVC PrintF_3iSpc
BVS %FT90
; Ask around if any drivers have a definitive result
LDR r1, =IICService
MOV r2, #Service_IIC_LookupDescription
MOV r3, r5, LSL #24
ORR r3, r3, r6, LSL #1
SWI XOS_ServiceCall
TEQ r1, #Service_Serviced
BEQ %FT80
; Try our device table then
MOV r0, r6, LSL #1
MOV r2, #'D'
MOV r1, sp
STRB r2, [r1], #1
MOV r2, #3
SWI XOS_ConvertHex2
MOVVC r1, sp ; token 'Dxx'
ADDVC r2, sp, #4 ; buffer
MOVVC r3, #64 - 4
BLVC CopyMessage
BVS %FT90
80
MOV r0, r2
SWI XOS_Write0
TEQ r1, #Service_Serviced
SWINE XOS_WriteI+'?' ; guessed by me
SWIVC XOS_NewLine
90
ADD sp, sp, #64 ; junk space from lookup
BVC %BT50
EXIT VS
95
ADR R0, ErrorBlock_IIC_BadBus
MOV R11, #0
BL CopyError ; sets V
EXIT VS
PrintF_3iSpc ROUT
LDR r1, =&20202020
Push "r1-r2, lr"
ADD r1, sp, #2 ; might need 2 leading spaces
MOV r2, #6
SWI XOS_ConvertCardinal1
RSBVC r2, r2, #5 ; 5/4/3 -> 0/1/2
ADDVC r0, sp, r2
SWIVC XOS_Write0
SWIVC XOS_WriteI+' '
ADD sp, sp, #8
Pull "pc"
; *****************************************************************************
;
; IIC_SWIHandler - Handler for my SWIs
......@@ -434,7 +596,7 @@ TXCheckAck ROUT
ReturnNoSuchSWIError
ADR R0, ErrorBlock_NoSuchSWI
ADR R11, IIC_Title
ADRL R11, IIC_Title
BL CopyError ; sets V
TEQ PC, PC
MOVEQ PC, R10 ; 32-bit exit: NZC corrupted
......@@ -455,6 +617,7 @@ ReturnIICInUseError
[ ReentrancyCheck
MakeInternatErrorBlock IIC_Busy,,InUse
]
MakeInternatErrorBlock IIC_BadBus,,BdBus
; *****************************************************************************
;
......@@ -745,6 +908,18 @@ CopyError0
SWI XMessageTrans_ErrorLookup
EXIT
CopyMessage Entry "r1,r3-r7"
BL open_messagefile
EXIT VS
CopyMessage0
ADR R0, MessageFile_Block ; R1 -> token, R2 -> buffer, R3 = buffer size
MOV R4, #0
MOV R5, #0
MOV R6, #0
MOV R7, #0
SWI XMessageTrans_Lookup
EXIT
message_filename
DCB "Resources:$.Resources.IIC.Messages", 0
......
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