;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; J784S4 I2C-Flash file to board I2Cs.
; 14 Jun 22 - Richard Woodruff - Adapt J721S2 for J784S4.
; 25 Jun 24 - Richard Woodruff - Add run time check for J742S2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; For BSDL to work EMU0=1 + EMU1=0 at reset. Use J7-EVM's dip switch SW4.

; --> Board EEPROM EVM = 0x50
&I2CID=0x50
; --> Board EEPROM SK = 0x51
;&I2CID=0x51

; System setup
JTAG.UNLOCK
SYStem.Down
SYStem.JtagClock 10MHz
BSDL.RESet
JTAG.LOCK

PRIVATE &pkg &stmp
&stmp=OS.PPF()
&stmp=OS.FILE.PATH("&stmp")
DO "&stmp/../is_soc_J784S4_or_J742S2.cmm"
RETURNVALUES &pkg

; Configuration of the boundary scan chain
IF "&pkg"=="AHP27"
  BSDL.FILE ~~~~/j742s2.bsm
ELSE
  BSDL.FILE ~~~~/J784S4_bsdl_220307.bsm

BSDL.HARDRESET
BSDL.SOFTRESET

bsdl.parkstate RUN-TEST/IDLE

BSDL.RUNTCK 10.
BSDL.RUNTCK 10.

if !bsdl.check.bypass()
(
    BSDL.BYPASSALL
    PRINT %ERROR "Bypass test failed"
)
else
(
    if !bsdl.check.idcode()
    (
        BSDL.IDCODEALL
        PRINT %ERROR "ID code test failed"
    )
    else
    (
        BSDL.FLASH.IFDefine RESet ; reset the boundary scan flash
        ; configuration
        BSDL.FLASH.IFDefine I2C 1. ; I2C protocol, Chip 1
        ; - protocol: I2C
        ; - I2C flash memory connected to IC1 of
        ; the boundary scan chain
        BSDL.FLASH.IFMap SCL wkup_i2c0_scl ; map generic I2C pin SCL to port N33
        BSDL.FLASH.IFMap SDA wkup_i2c0_sda ; map generic I2C pin SDA to port N35
        BSDL.FLASH.INIT SAFE ; Initialize boundary scan chain to safe
        ; values according to SAFE state
        ; from BSDL file
        FLASHFILE.BSDLaccess ON ; Enable serial flash programming via
        ; boundary scan
        FLASHFILE.BSDLFLASHTYPE I2C1M &I2CID ; 256K serial flash
        FLASHFILE.GETID ; get the I2c flash memory ID
        ; continue with serial flash programming, e.g.:
        ; FLASHFILE.DUMP 0x0
        ; FLASHFILE.ERASE 0x0--0x3FF
        ; FLASHFILE.LOAD * 0x0
    )
)
 enddo



