multiple updates
This commit is contained in:
1
OperatingSystem/iictest/include/extern_symbols.s
Symbolic link
1
OperatingSystem/iictest/include/extern_symbols.s
Symbolic link
@@ -0,0 +1 @@
|
||||
../../monitor_v2/zout/symbols.s
|
||||
270
OperatingSystem/iictest/include/kdrv_iic.s
Normal file
270
OperatingSystem/iictest/include/kdrv_iic.s
Normal file
@@ -0,0 +1,270 @@
|
||||
CS_PIO_BD .EQU 0xF5
|
||||
CS_PIO_BC .EQU 0xF7
|
||||
CS_PIO_AD .EQU 0xF4
|
||||
CS_PIO_AC .EQU 0xF6
|
||||
|
||||
CS_I2C_S1 .EQU 0xF3
|
||||
CS_I2C_SX .EQU 0xF2
|
||||
|
||||
iic_init:
|
||||
LD A,0xCF
|
||||
OUT (CS_PIO_AC), A
|
||||
LD A,11110101b
|
||||
OUT (CS_PIO_AC), A
|
||||
|
||||
LD A,00000000b ; Reset PCF8584 minimum 30 clock cycles
|
||||
OUT (CS_PIO_AD), A
|
||||
|
||||
LD BC,0x1000
|
||||
CALL _pause_loop
|
||||
|
||||
LD A,0000010b
|
||||
OUT (CS_PIO_AD), A
|
||||
|
||||
LD BC,0x1000
|
||||
CALL _pause_loop
|
||||
|
||||
LD A, 0x80 ;S1 -> Select S0, PIN disabled, ESO = 0, Interrupt disabled, STA, STA, ACK = 0
|
||||
OUT (CS_I2C_S1),A
|
||||
CALL _slow_access
|
||||
;CALL _slow_access
|
||||
|
||||
LD A,0x55 ;S0 -> Loads byte 55H into register S0'; effective own address becomes AAH
|
||||
OUT (CS_I2C_SX),A
|
||||
CALL _slow_access
|
||||
|
||||
|
||||
LD A, 0xA0 ;S1 -> Loads byte A0H into register S1, i.e. next byte will be loaded into the clock control register S2.
|
||||
OUT (CS_I2C_S1),A
|
||||
CALL _slow_access
|
||||
|
||||
; 000100000
|
||||
LD A,0x18 ;Load 18H into S2 register (clock control - 4.43 MHz, 90 KHz)
|
||||
LD A,0x00 ;Load 18H into S2 register (clock control - 4.43 MHz, 90 KHz)
|
||||
OUT (CS_I2C_SX),A
|
||||
CALL _slow_access
|
||||
;CALL _slow_access
|
||||
;CALL _slow_access
|
||||
;CALL _slow_access
|
||||
|
||||
LD A,0xC1 ;S1 -> loads byte C1H into register S1; register enable
|
||||
;serial interface, set I 2C-bus into idle mode;
|
||||
;SDA and SCL are HIGH. The next write or read
|
||||
;operation will be to/from data transfer register
|
||||
;S0 if A0 = LOW.;
|
||||
OUT (CS_I2C_S1),A
|
||||
CALL _slow_access
|
||||
RET
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; iic_send
|
||||
;
|
||||
; Sends data over the i2c bus
|
||||
; A contains BYTE COUNTER
|
||||
; B contains ADDRESS
|
||||
; DE contains location of Data Buffer
|
||||
;------------------------------------------------------------------------------
|
||||
iic_send:
|
||||
;CALL PRINTINLINE;
|
||||
;defb "SEND A",10,13,0
|
||||
PUSH BC
|
||||
PUSH AF
|
||||
CALL iic_bus_rdy
|
||||
;CALL PRINTINLINE
|
||||
;defb "SEND START",10,13,0
|
||||
LD A,B ;Load 'slave address' into S0 register:
|
||||
OUT (CS_I2C_SX),A
|
||||
CALL _slow_access
|
||||
|
||||
LD A, 0xC5 ;Load C5H into S1. 'C5H' = PCF8584 generates
|
||||
;the 'START' condition and clocks out the slave
|
||||
;address and the clock pulse for slave acknowledgement.
|
||||
OUT (CS_I2C_S1),A
|
||||
POP AF
|
||||
LD C,A
|
||||
INC C
|
||||
_iic_send_1: ; LOOP 1 : Wait for bus ready
|
||||
IN A,(CS_I2C_S1) ; Read byte from S1 register
|
||||
BIT 7,A ; Is bus free? (S1 ~BB=1?)
|
||||
JR NZ,_iic_send_1 ; No - loop
|
||||
BIT 4,A ; slave acknowledged? (LRB = 0?)
|
||||
JR NZ, _iic_send_stop ; if not, cancel transmission
|
||||
LD A,(DE) ; Load next byte from buffer
|
||||
INC DE
|
||||
DEC C
|
||||
JR Z, _iic_send_stop ; if counter = 0, exit loop
|
||||
OUT (CS_I2C_SX),A ; Send byte
|
||||
JR _iic_send_1 ; if counter > 0, loop again
|
||||
_iic_send_stop:
|
||||
LD A, 0xC3 ;STOP
|
||||
OUT (CS_I2C_S1),A
|
||||
CALL _slow_access
|
||||
POP BC
|
||||
RET
|
||||
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; iic_read
|
||||
;
|
||||
; Sends data over the i2c bus
|
||||
; A contains BYTE COUNTER
|
||||
; B contains ADDRESS
|
||||
; DE contains location of Data Buffer
|
||||
;------------------------------------------------------------------------------
|
||||
iic_read:
|
||||
PUSH DE
|
||||
PUSH BC
|
||||
PUSH AF
|
||||
LD A,B ;Load 'slave address' into S0 register:
|
||||
OR 0x01 ;Set RW Bit for read operation
|
||||
OUT (CS_I2C_SX),A
|
||||
CALL _slow_access
|
||||
CALL iic_bus_rdy ; Is bus ready
|
||||
LD A, 0xC5 ;Load C5H into S1. 'C5H' = PCF8584 generates
|
||||
;the 'START' condition and clocks out the slave
|
||||
;address and the clock pulse for slave acknowledgement.
|
||||
OUT (CS_I2C_S1),A
|
||||
;Setup counter
|
||||
POP AF
|
||||
LD C,A ; Load BYTE COUNTER into C
|
||||
INC C ; Offset C by 1
|
||||
_iic_read_1: ;Wait for PIN = 0
|
||||
IN A,(CS_I2C_S1) ; Read byte from S1 register
|
||||
BIT 7,A ; S1 PIN=1?
|
||||
JR NZ,_iic_read_1 ; No - loop
|
||||
BIT 3,A ; S1 LRB=0? slave ACK?
|
||||
JR NZ, _iic_read_error ; No ACK -> an error has occured
|
||||
DEC C
|
||||
LD A, C
|
||||
DEC A ;If n = m − 1?
|
||||
JR Z, _iic_read_last
|
||||
IN A,(CS_I2C_SX)
|
||||
LD (DE),A
|
||||
INC DE
|
||||
JR _iic_read_1
|
||||
_iic_read_last: ;read last byte
|
||||
LD A, 0x40
|
||||
OUT (CS_I2C_S1),A
|
||||
CALL _slow_access
|
||||
IN A,(CS_I2C_SX) ;receives the final data byte. Neg. ACK is also sent.
|
||||
LD (DE),A
|
||||
INC DE
|
||||
_iic_read_last_1:
|
||||
IN A,(CS_I2C_S1) ; Read byte from S1 register
|
||||
BIT 7,A ; S1 PIN=1?
|
||||
JR NZ,_iic_read_last_1 ; No - loop
|
||||
|
||||
_iic_read_error:
|
||||
NOP
|
||||
_iic_read_stop:
|
||||
LD A, 0xC3
|
||||
OUT (CS_I2C_S1),A
|
||||
CALL _slow_access
|
||||
IN A,(CS_I2C_SX) ;transfers the final data byte from the
|
||||
;data buffer to accumulator.
|
||||
CALL _slow_access
|
||||
LD (DE),A
|
||||
POP BC
|
||||
POP DE
|
||||
RET
|
||||
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; iic_rdy
|
||||
;
|
||||
; Waits until the PCF8584 signals a byte transmission/reception is complete.
|
||||
;------------------------------------------------------------------------------
|
||||
iic_rdy:
|
||||
PUSH AF
|
||||
_iic_rdy_loop:
|
||||
IN A,(CS_I2C_S1) ; Read byte from S1 register
|
||||
BIT 7,A ; Is Tx/Rx complete? (S1 PIN=0?)
|
||||
;call print_a_hex
|
||||
JR NZ,_iic_rdy_loop ; No - loop
|
||||
_iic_rdy_done:
|
||||
POP AF
|
||||
RET
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; i2c_bus_rdy
|
||||
;
|
||||
; Waits until the I2C bus is free before RETurning
|
||||
;------------------------------------------------------------------------------
|
||||
iic_bus_rdy:
|
||||
PUSH AF
|
||||
_iic_blp:
|
||||
IN A,(CS_I2C_S1) ; Read byte from S1 register
|
||||
PUSH AF
|
||||
call print_a_hex
|
||||
POP AF
|
||||
BIT 0,A ; Is bus free? (S1 ~BB=1?)
|
||||
JR Z,_iic_blp ; No - loop
|
||||
POP AF
|
||||
RET
|
||||
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; _pause_loop
|
||||
;
|
||||
; Timer function
|
||||
;
|
||||
; 16-bit (BC) decrement counter, performing 4xNEG loop until BC
|
||||
; reaches zero.
|
||||
;
|
||||
; 61 T-states in loop = 15.25uS per loop @ 4 MHz - near enough
|
||||
; a second delay for 65,535 iterations.
|
||||
;
|
||||
; Set iteration count in BC before calling this function.
|
||||
; Destroys: BC
|
||||
;------------------------------------------------------------------------------
|
||||
_pause_loop:
|
||||
PUSH AF ; 11 T-states
|
||||
_pause_loop_lp:
|
||||
;NEG ; 8 T-states
|
||||
;NEG ; 8 T-states
|
||||
;NEG ; 8 T-states
|
||||
;NEG ; 8 T-states
|
||||
PUSH BC ; 11 T-states
|
||||
POP BC ; 10 T-states
|
||||
PUSH BC ; 11 T-states
|
||||
POP BC ; 10 T-states
|
||||
DEC BC ; 6 T-states
|
||||
LD A,C ; 9 T-states
|
||||
OR B ; 4 T-states
|
||||
JP NZ,_pause_loop_lp ; 10 T-states
|
||||
POP AF ; 10 T-states
|
||||
RET ; Pause complete, RETurn
|
||||
|
||||
|
||||
iic_force_stop:
|
||||
IN A,(CS_I2C_S1)
|
||||
BIT 0, A
|
||||
RET NZ
|
||||
LD A, 11000011b
|
||||
OUT (CS_I2C_S1),A
|
||||
NOP
|
||||
NOP
|
||||
JR iic_force_stop
|
||||
|
||||
_slow_access:
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
PUSH AF
|
||||
POP AF
|
||||
PUSH AF
|
||||
POP AF
|
||||
PUSH AF
|
||||
POP AF
|
||||
PUSH AF
|
||||
POP AF
|
||||
PUSH AF
|
||||
POP AF
|
||||
PUSH AF
|
||||
POP AF
|
||||
RET
|
||||
5
OperatingSystem/iictest/properties.env
Normal file
5
OperatingSystem/iictest/properties.env
Normal file
@@ -0,0 +1,5 @@
|
||||
export OPT_GEN_SYMBOLTABLE=0
|
||||
export OPT_GEN_MONFILE=1
|
||||
export OPT_GEN_OBJFILE=1
|
||||
export OPT_WRITEROM=0
|
||||
export FILENAME=test
|
||||
55
OperatingSystem/iictest/test.asm
Normal file
55
OperatingSystem/iictest/test.asm
Normal file
@@ -0,0 +1,55 @@
|
||||
.include "include/extern_symbols.s" ;include monitor symbols.
|
||||
org 0x8000
|
||||
|
||||
IIC_RTC equ 11010000b
|
||||
;Testing code
|
||||
|
||||
CALL iic_init
|
||||
|
||||
;JP PROMPT_BEGIN
|
||||
|
||||
LD BC,$1000
|
||||
CALL _pause_loop
|
||||
|
||||
JP PROMPT_BEGIN
|
||||
|
||||
LD DE, 0xC000 ; Set I2C Buffer Location
|
||||
LD A,0x00 ; store string in buffer
|
||||
LD (DE),A
|
||||
LD B, IIC_RTC ; Set I2C Address
|
||||
LD A, 1 ; Set I2C Buffer length
|
||||
call iic_send
|
||||
|
||||
|
||||
|
||||
|
||||
JP PROMPT_BEGIN
|
||||
|
||||
.include "include/kdrv_iic.s"
|
||||
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; PRINTINLINE
|
||||
;
|
||||
; String output function
|
||||
;
|
||||
; Prints in-line data (bytes immediately following the PRINTINLINE call)
|
||||
; until a string terminator is encountered (0 - null char).
|
||||
;------------------------------------------------------------------------------
|
||||
PRINTINLINE:
|
||||
EX (SP),HL ; PUSH HL and put RET ADDress into HL
|
||||
PUSH AF
|
||||
PUSH BC
|
||||
nxtILC:
|
||||
LD A,(HL)
|
||||
CP 0
|
||||
JR Z,endPrint
|
||||
CALL print_char
|
||||
INC HL
|
||||
JR nxtILC
|
||||
endPrint:
|
||||
INC HL ; Get past "null" terminator
|
||||
POP BC
|
||||
POP AF
|
||||
EX (SP),HL ; PUSH new RET ADDress on stack and restore HL
|
||||
RET
|
||||
BIN
OperatingSystem/iictest/zout/test.bin
Normal file
BIN
OperatingSystem/iictest/zout/test.bin
Normal file
Binary file not shown.
21
OperatingSystem/iictest/zout/test.hex
Normal file
21
OperatingSystem/iictest/zout/test.hex
Normal file
@@ -0,0 +1,21 @@
|
||||
:10800000CD1C80010010CDEF80C399001100C03E4F
|
||||
:10801000001206D03E01CD5E80C399003ECFD3F65C
|
||||
:108020003EF5D3F63E00D3F4010010CDEF803E02C2
|
||||
:10803000D3F4010010CDEF803E80D3F3CD09813E13
|
||||
:1080400055D3F2CD09813EA0D3F3CD09813E183E30
|
||||
:1080500000D3F2CD09813EC1D3F3CD0981C9C5F565
|
||||
:10806000CDE18078D3F2CD09813EC5D3F3F14F0C39
|
||||
:10807000DBF3CB7F20FACB6720091A130D2804D33A
|
||||
:10808000F218ED3EC3D3F3CD0981C1C9D5C5F5784A
|
||||
:10809000F601D3F2CD0981CDE1803EC5D3F3F14F96
|
||||
:1080A0000CDBF3CB7F20FACB5F201C0D793D28063B
|
||||
:1080B000DBF2121318EB3E40D3F3CD0981DBF21251
|
||||
:1080C00013DBF3CB7F20FA003EC3D3F3CD0981DB72
|
||||
:1080D000F2CD098112C1D1C9F5DBF3CB7F20FAF1D2
|
||||
:1080E000C9F5DBF3F5CDE702F1CB4728F5F1C9F58A
|
||||
:1080F000C5C1C5C10B79B0C2F080F1C9DBF3CB4774
|
||||
:10810000C03EC3D3F3000018F300000000000000DD
|
||||
:1081100000F5F1F5F1F5F1F5F1F5F1F5F1C9E3F55A
|
||||
:10812000C57EFE002806CDB7022318F523C1F1E372
|
||||
:01813000C985
|
||||
:00000001FF
|
||||
1154
OperatingSystem/iictest/zout/test.lst
Normal file
1154
OperatingSystem/iictest/zout/test.lst
Normal file
File diff suppressed because it is too large
Load Diff
20
OperatingSystem/iictest/zout/test.mon
Normal file
20
OperatingSystem/iictest/zout/test.mon
Normal file
@@ -0,0 +1,20 @@
|
||||
!8000 CD 1C 80 01 00 10 CD EF 80 C3 99 00 11 00 C0 3E
|
||||
!8010 00 12 06 D0 3E 01 CD 5E 80 C3 99 00 3E CF D3 F6
|
||||
!8020 3E F5 D3 F6 3E 00 D3 F4 01 00 10 CD EF 80 3E 02
|
||||
!8030 D3 F4 01 00 10 CD EF 80 3E 80 D3 F3 CD 09 81 3E
|
||||
!8040 55 D3 F2 CD 09 81 3E A0 D3 F3 CD 09 81 3E 18 3E
|
||||
!8050 00 D3 F2 CD 09 81 3E C1 D3 F3 CD 09 81 C9 C5 F5
|
||||
!8060 CD E1 80 78 D3 F2 CD 09 81 3E C5 D3 F3 F1 4F 0C
|
||||
!8070 DB F3 CB 7F 20 FA CB 67 20 09 1A 13 0D 28 04 D3
|
||||
!8080 F2 18 ED 3E C3 D3 F3 CD 09 81 C1 C9 D5 C5 F5 78
|
||||
!8090 F6 01 D3 F2 CD 09 81 CD E1 80 3E C5 D3 F3 F1 4F
|
||||
!80A0 0C DB F3 CB 7F 20 FA CB 5F 20 1C 0D 79 3D 28 06
|
||||
!80B0 DB F2 12 13 18 EB 3E 40 D3 F3 CD 09 81 DB F2 12
|
||||
!80C0 13 DB F3 CB 7F 20 FA 00 3E C3 D3 F3 CD 09 81 DB
|
||||
!80D0 F2 CD 09 81 12 C1 D1 C9 F5 DB F3 CB 7F 20 FA F1
|
||||
!80E0 C9 F5 DB F3 F5 CD E7 02 F1 CB 47 28 F5 F1 C9 F5
|
||||
!80F0 C5 C1 C5 C1 0B 79 B0 C2 F0 80 F1 C9 DB F3 CB 47
|
||||
!8100 C0 3E C3 D3 F3 00 00 18 F3 00 00 00 00 00 00 00
|
||||
!8110 00 F5 F1 F5 F1 F5 F1 F5 F1 F5 F1 F5 F1 C9 E3 F5
|
||||
!8120 C5 7E FE 00 28 06 CD B7 02 23 18 F5 23 C1 F1 E3
|
||||
!8130 C9
|
||||
Reference in New Issue
Block a user