ex5.asm (4691B)
1 ; 2 ; 3 ; This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 ; 5 ; Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 ; 7 ; 8 ;Here is an example program for programming the LEDs on the 5605. 9 ; 10 ;The situation is this: 11 ; 12 ; 26 ports (port 0-25) each have one LED. The front panel 13 ; has an 8-position switch so the user can select which 14 ; status is displayed on the front panel. The host processor 15 ; reads the state of the switch periodically and communicates 16 ; it to this processor in data location 0x7F. 17 ; 18 ; 0x7F=0: link 19 ; 0x7F=1: display collision activity 20 ; 0x7F=2: display TX activity 21 ; 0x7F=3: display RX activity 22 ; 0x7F=4: duplex 23 ; 0x7F=5: speed (1=full speed, 0=lower speed) 24 ; 0x7F=6: flow control 25 ; 0x7F=7: link aggregation 26 ; 27 ; when link status is chosen, it has four different indications: 28 ; 29 ; link disabled: LED is off 30 ; link enabled but down: LED blinks on approx 100 ms, off 900ms 31 ; link enabled and up: LED is on 32 ; 33 ; link aggregation indicates which ports are part of a trunk group. 34 ; this information isn't known to the MACs, and so isn't directly 35 ; known to this processor. instead, the host CPU sends a string 36 ; of 32 (well, 26 meaningful) bits to addresses 0x78 to 0x7B to 37 ; indicate which ports should have their LED set in this case. port 0 38 ; corresponds to bit 0 of 0x78, port 1 is bit 1 of 0x78, etc. 39 ; 40 ; The scan out order is port 25 to port 0. 41 ; 42 ; Note that the speed indicator requires special handling because 43 ; the gig ports (ports 24 and 25) run at higher speed. 44 ; 45 ; 46 ;-------------------------- start of program -------------------------- 47 48 begin: 49 ; update refresh phase within 1 Hz 50 ld A, phase 51 inc A ; next phase 52 cmp A, 30 ; see if 1 sec has gone by 53 jc chkblink 54 sub A, A ; A = 0 55 chkblink: 56 ld (phase),A 57 sub B, B ; B = 0 58 cmp A, 3 ; 3 of 30 cycles = 10% duty cycle 59 jnc noblink 60 inc B ; B = 1 61 noblink: 62 ld (blink),B 63 64 ld A,25 ; start with port 25 65 ld (portnum),A 66 67 ; later we need to scan a 32 bit trunkmap. we store the 68 ; address in the form of byte & bit offset explicitly. 69 sub A,A 70 ld (mapbit),A ; bit 0 71 ld A,trunkmap 72 ld (mapbyte),A ; starting at byte "trunkmap" 73 74 portloop: 75 port A ; specify which port we're dealing with 76 77 ld A,(select) 78 dec A 79 jc sel0 80 dec A 81 jc sel1 82 dec A 83 jc sel2 84 dec A 85 jc sel3 86 dec A 87 jc sel4 88 dec A 89 jc sel5 90 dec A 91 jc sel6 92 dec A 93 jc sel7 94 ld B,ZERO 95 jmp simple ; turn off all LEDs 96 97 sel0: ; link status: complex 98 pushst LINKEN 99 jnt wrapup ; LED is off if disabled 100 pushst LINKUP 101 jt wrapup 102 ; port is enabled but the link is down: blink 103 push (blink) ; push (blink) bit 0 to status stack 104 jmp wrapup 105 sel1: ld B,COLL 106 jmp simple 107 sel2: ld B,TX 108 jmp simple 109 sel3: ld B,RX 110 jmp simple 111 sel4: ld B,DUPLEX 112 jmp simple 113 sel5: ; speed is a bit trickier 114 ld B,SPEED_C ; assume 100 Mbps 115 ld A,(portnum) 116 cmp A,24 ; ports 24&25 are 1000 Mbps full speed 117 jc simple 118 ld B,SPEED_M ; inc B would work too 119 jmp simple 120 sel6: ld B,FLOW 121 jmp simple 122 sel7: ; link aggregation 123 ld A,(mapbyte) ; get byte address we're looking for 124 ld B,(mapbit) 125 tst (A),B ; cy = B'th bit of (A) 126 push CY ; push it on led status stack 127 jmp wrapup 128 129 simple: ; handle simple case where we test just one bit 130 pushst B ; test B'th status bit 131 132 wrapup: pack ; send bit to LED buffer 133 134 ; bump trunk map pointers (used only if select==7) 135 inc B 136 cmp B,8 137 jc bump 138 inc (mapbyte) 139 sub B,B 140 bump: ld (mapbit),B 141 142 ; bump port pointer -- note we are scanning 25 to 0 143 dec (portnum) 144 jnc portloop 145 146 send 26 ; send 26 LED pulses and halt 147 148 149 ; data storage 150 blink equ 0x70 ; 1 if blink on, 0 if blink off 151 152 phase equ 0x71 ; phase within 30 Hz 153 ; should be initialized to 0 on reset 154 155 portnum equ 0x72 ; temp to hold which port we're working on 156 157 mapbyte equ 0x73 ; byte pointer to trunkmap 158 mapbit equ 0x74 ; bit pointer to trunkmap 159 160 trunkmap equ 0x78 ; a bitmap of four bytes 161 162 select equ 0x7F ; indicates which status we are displaying 163 164 165 ; symbolic labels 166 ; this gives symbolic names to the various bits of the port status fields 167 168 RX equ 0x0 ; received packet 169 TX equ 0x1 ; transmitted packet 170 COLL equ 0x2 ; collision indicator 171 SPEED_C equ 0x3 ; 100 Mbps 172 SPEED_M equ 0x4 ; 1000 Mbps 173 DUPLEX equ 0x5 ; half/full duplex 174 FLOW equ 0x6 ; flow control capable 175 LINKUP equ 0x7 ; link down/up status 176 LINKEN equ 0x8 ; link disabled/enabled status 177 ZERO equ 0xE ; always 0 178 ONE equ 0xF ; always 1 179 180 ;-------------------------- end of program -------------------------- 181 ; 182 ;This program is 130 bytes in length, but it is fairly complicatd. 183