generic8led.asm (5792B)
1 ; 2 ; 3 ; 4 ; This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 5 ; 6 ; Copyright 2007-2019 Broadcom Inc. All rights reserved. 7 ; 8 ; 9 ; This is a generic program that controls 8 LEDs 10 ; To start it, use the following commands from BCM: 11 ; 12 ; led load generic8led.hex 13 ; led auto on 14 ; led start 15 ; 16 ; There are 8 LEDs - 17 ; 6 LEDs to display port number and two LEDs for TX/RX activity 18 ; 19 ; There is one bit per LED with the following colors: 20 ; ONE Black 21 ; ZERO Green 22 ; 23 ; Each chip drives only its own LEDs and needs to write them in the order: 24 ; 6-bit port number, Activity-TX-Port, Activity-RX-Port 25 ; 26 ; Link up/down info cannot be derived from LINKEN or LINKUP, as the LED 27 ; processor does not always have access to link status. This program 28 ; assumes link status is kept current in bit 0 of RAM byte (0xA0 + portnum). 29 ; Generally, a program running on the main CPU must update these 30 ; locations on link change; see linkscan callback in 31 ; $SDK/src/appl/diag/ledproc.c. 32 ; 33 ; Current implementation: 34 ; 35 ; TA01/RA01 reflects port N TX/RX activity status: 36 ; Black: no Activity 37 ; Green: Activity 38 ; 39 ; 40 NUM_LEDS EQU 8 41 42 MIN_PORT EQU 0 43 MAX_PORT EQU 63 44 NUM_PORT EQU 64 45 46 TICKS EQU 1 47 SECOND_TICKS EQU (30*TICKS) 48 ACT_EXT_TICKS EQU (SECOND_TICKS/3) 49 TXRX_ALT_TICKS EQU (SECOND_TICKS/6) 50 51 ; 52 ; Main Update Routine 53 ; 54 ; This routine is called once per tick. 55 ; 56 update: 57 ld a,(PORT_NUM) 58 cmp a, NUM_PORT 59 jc led_update_port 60 61 sub a,a ; ld a,MIN_PORT (but only one instr) 62 ld (PORT_NUM),a 63 ld b, (SKIP_ZERO) 64 cmp b, 1 65 jc skip_link_check ; Turn off all LEDs if no port has link 66 ld (SKIP_ZERO), a 67 68 led_update_port: 69 call get_link 70 jnc next_port ; Skip ports that don't have link 71 72 skip_link_check: 73 ld b, 1 74 ld (SKIP_ZERO), b 75 call display_port_num 76 port a 77 call tx_rx_activity ; Off if no link 78 79 inc (TXRX_ALT_COUNT) 80 81 ld b, (PORT_ALT_COUNT) 82 inc b 83 ld (PORT_ALT_COUNT), b 84 cmp b, 1 * SECOND_TICKS 85 jnc next_port 86 send NUM_LEDS 87 88 next_port: 89 sub b,b 90 ld (PORT_ALT_COUNT),b 91 inc (PORT_NUM) 92 jmp update 93 94 ; 95 ; link_activity 96 ; 97 ; This routine calculates the activity LED for the current port. 98 ; 99 ; Inputs: (PORT_NUM) 100 ; Outputs: one bit sent to LED stream 101 ; 102 103 tx_rx_activity: 104 ;jmp led_green ;DEBUG ONLY 105 call get_link 106 jnc link_led_black 107 jmp chk_activity 108 link_led_black: 109 call led_black 110 jmp led_black 111 chk_activity: 112 call chk_activity_tx 113 call chk_activity_rx 114 ret 115 116 chk_activity_tx: 117 port a 118 pushst TX 119 pop 120 121 jnc led_black ; Always black, No Activity 122 123 ld b, (TXRX_ALT_COUNT) 124 and b, TXRX_ALT_TICKS 125 jnz led_green 126 jmp led_black 127 128 chk_activity_rx: 129 port a 130 pushst RX 131 pop 132 133 jnc led_black ; Always black, No Activity 134 135 ld b, (TXRX_ALT_COUNT) 136 and b, TXRX_ALT_TICKS 137 jnz led_green 138 jmp led_black 139 140 ; 141 ; get_link 142 ; 143 ; This routine finds the link status LED for a port. 144 ; Link info is in bit 0 of the byte read from PORTDATA[port] 145 ; 146 ; Inputs: Port number in a 147 ; Outputs: Carry flag set if link is up, clear if link is down. 148 ; Destroys: a, b 149 ; 150 151 get_link: 152 ld b,PORTDATA 153 add b,a 154 ld b,(b) 155 tst b,0 156 ret 157 158 ; 159 ; led_black, led_green 160 ; 161 ; Inputs: None 162 ; Outputs: one bit to the LED stream indicating color 163 ; Destroys: None 164 ; 165 166 led_black: 167 pushst ONE 168 pack 169 ret 170 171 led_green: 172 pushst ZERO 173 pack 174 ret 175 176 ; Inputs: Port number in a 177 ; : Port bit position in b 178 display_port_one_bit: 179 tst a, b 180 jnc led_black 181 jmp led_green 182 183 ; Inputs: Port number in a 184 ; Destroys: b 185 display_port_num: 186 ld b, 5 187 call display_port_one_bit 188 189 ld b, 4 190 call display_port_one_bit 191 192 ld b, 3 193 call display_port_one_bit 194 195 ld b, 2 196 call display_port_one_bit 197 198 ld b, 1 199 call display_port_one_bit 200 201 ld b, 0 202 call display_port_one_bit 203 204 ret 205 206 ; 207 ; Variables (SDK software initializes LED memory from 0xa0-0xff to 0) 208 ; 209 210 TXRX_ALT_COUNT equ 0xe0 211 PORT_NUM equ 0xe1 212 PORT_ALT_COUNT equ 0xe2 213 SKIP_ZERO equ 0xe3 214 215 ; 216 ; Port data, which must be updated continually by main CPU's 217 ; linkscan task. See $SDK/src/appl/diag/ledproc.c for examples. 218 ; In this program, bit 0 is assumed to contain the link up/down status. 219 ; 220 221 ;Offset 0x1e00 - 0x80 222 ;LED scan chain assembly area 223 224 ;Offset 0x1e80 - 0xa0 225 PORTDATA equ 0xa0 ; Size 48 + 1 + 4 bytes 226 227 ; 228 ; Symbolic names for the bits of the port status fields 229 ; 230 231 RX equ 0x0 ; received packet 232 TX equ 0x1 ; transmitted packet 233 COLL equ 0x2 ; collision indicator 234 SPEED_C equ 0x3 ; 100 Mbps 235 SPEED_M equ 0x4 ; 1000 Mbps 236 DUPLEX equ 0x5 ; half/full duplex 237 FLOW equ 0x6 ; flow control capable 238 LINKUP equ 0x7 ; link down/up status 239 LINKEN equ 0x8 ; link disabled/enabled status 240 ZERO equ 0xE ; always 0 241 ONE equ 0xF ; always 1