; ; Copyright (C) 2021-2023 Texas Instruments Incorporated ; ; 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 Texas Instruments Incorporated 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 ; OWNER 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. ; .include "memory.inc" .include "defines.inc" .include "macros.inc" .ref transport_init .ref qm_add .ref calc_rssi .ref send_stuffing .ref datalink_wait_vsynch .if $defined("HDSL_MULTICHANNEL") .ref send_header_300m .else .ref send_header .endif .ref send_header_modified .ref send_trailer .ref wait_delay .ref datalink_loadfw .ref recv_dec .ref transport_on_h_frame .ref sync_pulse .ref check_test_pattern .ref datalink_abort_jmp .ref receive .ref datalink_abort .global datalink_reset .global datalink_init_start .sect ".text" relocatable0: datalink_init_start: datalink_reset: ;State RESET zero &r0, 124 ;send 2 times ;setup ICSS encoder peripheral for Hiperface DSL ldi DISPARITY, 0x00 TX_EN SET_TX_CH0 REINIT_TX TX_FRAME_SIZE 0, REG_TMP0 .if $defined("HDSL_MULTICHANNEL") TX_CLK_DIV CLKDIV_FAST, REG_TMP0 .else TX_CLK_DIV CLKDIV_NORMAL, REG_TMP0 .endif ; set the VERSION and VERSION2 register ldi REG_TMP0.b0, ICSS_FIRMWARE_RELEASE sbco ®_TMP0.b0, MASTER_REGS_CONST, VERSION, 1 sbco ®_TMP0.b0, MASTER_REGS_CONST, VERSION2, 1 zero &H_FRAME, (4*2) ;init transport layer here CALL transport_init ;QualityMonitor is initialized with 8 ldi QM, 8 ;free running mode frame size is 108 ldi EXTRA_SIZE, 0 ldi NUM_STUFFING, 0 ;reset PRST bit in SYS_CTRL lbco ®_TMP0, MASTER_REGS_CONST, SYS_CTRL, 1 clr REG_TMP0.b0, REG_TMP0.b0, SYS_CTRL_PRST sbco ®_TMP0, MASTER_REGS_CONST, SYS_CTRL, 1 ;reset SAFE_CTRL register zero ®_TMP0.b0, 1 sbco ®_TMP0.b0, MASTER_REGS_CONST, SAFE_CTRL, 1 ; Set EVENT_PRST in EVENT_H register lbco ®_TMP0, MASTER_REGS_CONST, EVENT_H, 4 set REG_TMP0.w0, REG_TMP0.w0, EVENT_PRST ;save events sbco ®_TMP0.w0, MASTER_REGS_CONST, EVENT_H, 2 qbbc update_events_no_int15, REG_TMP0.w2, EVENT_PRST ; generate interrupt ldi r31.w0, PRU0_ARM_IRQ update_events_no_int15: ; Set EVENT_S_PRST in EVENT_S register lbco ®_TMP0, MASTER_REGS_CONST, EVENT_S, 2 set REG_TMP0.b0, REG_TMP0.b0, EVENT_S_PRST ;save events sbco ®_TMP0.b0, MASTER_REGS_CONST, EVENT_S, 1 qbbc update_events_no_int22, REG_TMP0.b1, EVENT_S_PRST ; generate interrupt ldi r31.w0, PRU0_ARM_IRQ4 update_events_no_int22: ; Initialize ONLINE_STATUS_D, ONLINE_STATUS_1 and ONLINE_STATUS_2 ; In ONLINE_STATUS_D high, bit 2 is FIX0, bit 4 is FIX1 and bit 5 is FIX0 ; In ONLINE_STATUS_D low, bit 0 is FIX0 and bit 3 is FIX0 lbco ®_TMP0.w0, MASTER_REGS_CONST, ONLINE_STATUS_D_H, 2 ; clearing bits ldi REG_TMP0.w0, 0 ; setting bits with fix1 and PRST bit or REG_TMP0.w0, REG_TMP0.w0, (1< vert == acc.b0 && par == acc.b1 && pipe.nibble0 == pipe.nibble1 ;second half of palindrome is actually our ENC_ID! qbne datalink_abort2, H_FRAME.vert, H_FRAME_acc0 qbne datalink_abort2, H_FRAME.s_par, H_FRAME_acc1 and REG_TMP0.b0, H_FRAME.pipe, 0xf lsr REG_TMP0.b1, H_FRAME.pipe, 4 qbne datalink_abort2, REG_TMP0.b0, REG_TMP0.b1; ;now store the encoder ID mov REG_TMP0.w0, H_FRAME.acc mov REG_TMP0.b2, H_FRAME.pipe ;now in memory for master registers ;big endian format mov REG_TMP1.b0, REG_TMP0.b2 mov REG_TMP1.b1, REG_TMP0.b1 mov REG_TMP1.b2, REG_TMP0.b0 sbco ®_TMP1, MASTER_REGS_CONST, ENC_ID2, 3 ;Safe QM + set LINK bit, which means we have established a link ;just add 0 to QM to update QM_ADD 0 ;Synchronization with Drive Cycle is enabled here! set H_FRAME.flags, H_FRAME.flags, FLAG_DRIVE_SYNC ;-------------------------------------------------------------------------------------------------- ;State ID COMPUTE datalink_id_compute: ;decode the ENC_ID here ;num of acc bits is always +8 and NUM_ACC_BITS, REG_TMP0, 0x0f add NUM_ACC_BITS, NUM_ACC_BITS, 8 ;num pos bits is +num acc bits lsr NUM_ST_BITS, REG_TMP0, 4 and NUM_ST_BITS, NUM_ST_BITS, 0x3f add NUM_ST_BITS, NUM_ST_BITS, NUM_ACC_BITS sub NUM_ST_BITS, NUM_ST_BITS, NUM_MT_BITS ;finding the mask for position add REG_TMP0.b0, NUM_ST_BITS, NUM_MT_BITS rsb REG_TMP0.b0, REG_TMP0.b0, 40 ldi32 REG_TMP1, 0xffffffff lsr REG_TMP1, REG_TMP1, REG_TMP0.b0 sbco ®_TMP1, MASTER_REGS_CONST, MASK_POS, 4 ;qba datalink_id_req CALL1 send_stuffing jmp datalink_wait_vsynch