openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

magnum.asm (8148B)


      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 the Magnum program for the 5650 reference board (BCM95650R24)
     10 ;
     11 ; To start it, use the following commands from BCM:
     12 ;
     13 ;	0:led load tuc24_ref.hex
     14 ;	*:led start
     15 ;
     16 ;
     17 ; The BCM5650 reference board has 12 columns of 4 LEDs each, as shown below:
     18 ;
     19 ;       L02 L04 L06 L08 L10 L12 L14 L16 L18 L20 L22 L24   L26 L28
     20 ;       A02 A04 A06 A08 A10 A12 A14 A16 A18 A20 A22 A24   A26 A28
     21 ;       L01 L03 L05 L07 L09 L11 L13 L15 L17 L19 L21 L23   L25 L27
     22 ;       A01 A03 A05 A07 A09 A11 A13 A15 A17 A19 A21 A23   A25 A27
     23 ;
     24 ; For the FE ports, there are two bits per LED with the following colors:
     25 ;	ZERO, ZERO	Black
     26 ;	ZERO, ONE	Amber
     27 ;	ONE, ZERO	Green
     28 ;
     29 ;
     30 ; The bits are shifted out in the following order:
     31 ;	A02, L02, A01, L01,..., A28, L28, A27, L27
     32 ;
     33 ; Also, there are 4 LEDs for the GE ports, as shown below:       
     34 ;       LG2 AG2   LG4 AG4
     35 ;       LG1 AG1   LG3 AG3
     36 ;
     37 ; For the GE ports, there is one bit per LED with the following colors:
     38 ;	ZERO		Green
     39 ;	ONE		Black
     40 ;
     41 ; The bits are shifted out in the following order:
     42 ;	A02, L02, A01, L01,..., A24, L24, A23, L23, LG1, AG1, ..., LG4, AG4
     43 ;
     44 ; Current implementation:
     45 ;
     46 ; L01 reflects port 1 link status
     47 ; A01 reflects port 1 activity
     48 ;
     49 ; Link up/down info cannot be derived from LINKEN or LINKUP, as the LED
     50 ; processor does not actually have access to link status.  This program
     51 ; assumes link status is kept current in bit 0 of RAM byte (0xC0 + portnum).
     52 ; Generally, a program running on the main CPU must update these
     53 ; locations on link change; see linkscan callback in
     54 ; $SDK/src/appl/diag/ledproc.c.
     55 ;
     56 ; Current implementation:
     57 ;
     58 ; L01 reflects port 1 link status:
     59 ;	Black: no link
     60 ;	Amber: 10 Mb/s
     61 ;	Green: 100 Mb/s
     62 ;	Alternating green/amber: 1000 Mb/s
     63 ;	Very brief flashes of black at 1 Hz: half duplex
     64 ;	Longer periods of black: collisions in progress
     65 ;
     66 ; A01 reflects port 1 activity (even if port is down)
     67 ;	Black: idle
     68 ;	Green: RX (pulse extended to 1/3 sec)
     69 ;	Amber: TX (pulse extended to 1/3 sec, takes precedence over RX)
     70 ;	Green/Amber alternating at 6 Hz: both RX and TX
     71 ;
     72 ;
     73 ; This program is adapted from the tuc24_ref.asm program.  Many of the
     74 ; obscure workarounds for the Tucana LED proc bug have been removed.
     75 ;
     76 
     77 MIN_FE_PORT	EQU	0
     78 MAX_FE_PORT	EQU	23
     79 NUM_FE_PORT	EQU	24
     80 
     81 MIN_GE_PORT	EQU	24
     82 MAX_GE_PORT	EQU	27
     83 NUM_GE_PORT	EQU	4
     84 
     85 MIN_PORT	EQU	0
     86 MAX_PORT	EQU	27
     87 NUM_PORT	EQU	28
     88 
     89 PACK_BITS       EQU     ((NUM_FE_PORT*4) + (NUM_GE_PORT*2))
     90 PACK_NUM        EQU     (PACK_BITS/8)
     91 
     92 TICKS		EQU	1
     93 SECOND_TICKS	EQU	(30*TICKS)
     94 
     95 ; The TX/RX activity lights will be extended for ACT_EXT_TICKS
     96 ; so they will be more visible.
     97 
     98 ACT_EXT_TICKS	EQU	(SECOND_TICKS/3)
     99 GIG_ALT_TICKS	EQU	(SECOND_TICKS/2)
    100 HD_OFF_TICKS	EQU	(SECOND_TICKS/20)
    101 HD_ON_TICKS	EQU	(SECOND_TICKS-HD_ON_TICKS)
    102 TXRX_ALT_TICKS	EQU	(SECOND_TICKS/6)
    103 
    104 ;
    105 ; Main Update Routine
    106 ;
    107 ;  This routine is called once per tick.
    108 ;
    109 
    110 update:
    111 	sub	a,a		; ld a,MIN_FE_PORT (but only one instr)
    112 
    113 up1:
    114         ld      (PORT_NUM_CACHE),a; Store linear port number
    115         cmp     a,MIN_GE_PORT
    116         jc      up_fe
    117         
    118       	ld	(PORT_NUM),a    ; Port for subroutines
    119 	port	a
    120 	call	link_status_ge	; First LED for this port
    121 	call	activity_ge	; Second LED for this port
    122 
    123         jmp     next_port
    124         
    125 up_fe:          
    126         xor     a,0x1           ; For FE, do ports 1,0,3,2,etc.
    127       	ld	(PORT_NUM),a    ; Port for subroutines
    128     
    129 	port	a
    130 	call	activity	; Lower LED for this port
    131 	call	link_status	; Upper LED for this port
    132 
    133 next_port:      
    134         ld      a,(PORT_NUM_CACHE); Retrieve linear port number
    135 	inc	a
    136 	cmp	a,NUM_PORT
    137 	jnz	up1
    138 
    139 	; Update various timers
    140 
    141 	ld	b,GIG_ALT_COUNT
    142 	inc	(b)
    143 	ld	a,(b)
    144 	cmp	a,GIG_ALT_TICKS
    145 	jc	up2
    146 	ld	(b),0
    147 up2:
    148 
    149 	ld	b,HD_COUNT
    150 	inc	(b)
    151 	ld	a,(b)
    152 	cmp	a,HD_ON_TICKS+HD_OFF_TICKS
    153 	jc	up3
    154 	ld	(b),0
    155 up3:
    156 
    157 	ld	b,TXRX_ALT_COUNT
    158 	inc	(b)
    159 	ld	a,(b)
    160 	cmp	a,TXRX_ALT_TICKS
    161 	jc	up4
    162 	ld	(b),0
    163 up4:
    164 ;
    165 
    166 ; No need to move data anymore
    167         send    PACK_BITS
    168 
    169 ;
    170 ; activity
    171 ;
    172 ;  This routine calculates the activity LED for the current port.
    173 ;  It extends the activity lights using timers (new activity overrides
    174 ;  and resets the timers).
    175 ;
    176 ;  Inputs: (PORT_NUM)
    177 ;  Outputs: Two bits sent to LED stream
    178 ;
    179 
    180 activity:
    181 	pushst	RX
    182 	pop
    183 	jnc	act1
    184 
    185 	ld	b,RX_TIMERS	; Start RX LED extension timer
    186 	add	b,(PORT_NUM)
    187 	ld	a,ACT_EXT_TICKS
    188 	ld	(b),a
    189 
    190 act1:
    191 	pushst	TX
    192 	pop
    193 	jnc	act2
    194 
    195 	ld	b,TX_TIMERS	; Start TX LED extension timer
    196 	add	b,(PORT_NUM)
    197 	ld	a,ACT_EXT_TICKS
    198 	ld	(b),a
    199 
    200 act2:
    201 	ld	b,TX_TIMERS	; Check TX LED extension timer
    202 	add	b,(PORT_NUM)
    203 
    204 	dec	(b)
    205 	jnc	act3		; TX active?
    206 	inc	(b)
    207 
    208 	ld	b,RX_TIMERS	; Check RX LED extension timer
    209 	add	b,(PORT_NUM)
    210 
    211 	dec	(b)		; Extend LED green if only RX active
    212 	jnc	led_green
    213 	inc	(b)
    214 
    215 	jmp	led_black	; No activity
    216 
    217 act3:				; TX is active, see if RX also active
    218 	ld	b,RX_TIMERS
    219 	add	b,(PORT_NUM)
    220 
    221 	dec	(b)		; RX also active?
    222 	jnc	act4
    223 	inc	(b)
    224 
    225 	jmp	led_amber	; Only TX active
    226 
    227 act4:				; Both TX and RX active
    228 	ld	b,(TXRX_ALT_COUNT)
    229 	cmp	b,TXRX_ALT_TICKS/2
    230 	jc	led_amber	; Fast alternation of green/amber
    231 	jmp	led_green
    232 
    233 ;
    234 ; link_status
    235 ;
    236 ;  This routine calculates the link status LED for the current port.
    237 ;
    238 ;  Inputs: (PORT_NUM)
    239 ;  Outputs: Two bits sent to LED stream
    240 ;  Destroys: a, b
    241 ;
    242 
    243 link_status:
    244 	pushst	DUPLEX		; Skip blink code if full duplex
    245 	pop
    246 	jc	ls1
    247 
    248 	ld	a,(HD_COUNT)	; Provide blink for half duplex
    249 	cmp	a,HD_OFF_TICKS
    250 	jc	led_black
    251 
    252 ls1:
    253 	ld	a,(PORT_NUM)	; Check for link down
    254 	call	get_link
    255 	jnc	led_black
    256 
    257 	pushst	COLL		; Check for collision
    258 	pop
    259 	jc	led_black
    260 
    261 	pushst	SPEED_C		; Check for 100Mb speed
    262 	pop
    263 	jc	led_green       
    264 
    265 	pushst	SPEED_M		; Check for 10Mb (i.e. not 100 or 1000)
    266 	pop
    267 	jnc	led_amber
    268 
    269 	ld	a,(GIG_ALT_COUNT)
    270 	cmp	a,GIG_ALT_TICKS/2
    271 	jc	led_amber
    272 
    273 	jmp	led_green
    274 
    275 
    276 ;
    277 ; get_link
    278 ;
    279 ;  This routine finds the link status LED for a port.
    280 ;  Link info is in bit 0 of the byte read from PORTDATA[port]
    281 ;
    282 ;  Inputs: Port number in a
    283 ;  Outputs: Carry flag set if link is up, clear if link is down.
    284 ;  Destroys: a, b
    285 ;
    286 
    287 get_link:
    288 	ld	b,PORTDATA
    289 	add	b,a
    290 	ld	b,(b)
    291 	tst	b,0
    292 	ret
    293 
    294 ;
    295 ; led_black, led_amber, led_green
    296 ;
    297 ;  Inputs: None
    298 ;  Outputs: Two bits to the LED stream indicating color
    299 ;  Destroys: None
    300 ;
    301 
    302 led_black:
    303 	pushst	ONE
    304 	pack
    305 	pushst	ONE
    306 	pack
    307 	ret
    308 
    309 led_amber:
    310 	pushst	ZERO
    311 	pack
    312 	pushst	ONE
    313 	pack
    314 	ret
    315 
    316 led_green:
    317 	pushst	ONE
    318 	pack
    319 	pushst	ZERO
    320 	pack
    321 	ret
    322 
    323 
    324 ; GE routines
    325 ;
    326 ; Inputs: LED bit pair in a
    327 ; Outputs: One bit to the LED stream indicating state
    328 ; Destroys: None
    329 ;
    330 
    331 
    332 activity_ge:
    333         ld      a,ZERO          ; On (ZERO)
    334         pushst  RX
    335         pop
    336         jc      act_led_set
    337 
    338         pushst  TX
    339         pop
    340         jc      act_led_set
    341 
    342         inc     a               ; On (ZERO) -> Off (ONE)
    343 
    344 act_led_set:
    345         pushst  a
    346         pack
    347         ret
    348 
    349 link_status_ge:
    350 
    351 	ld	a,(PORT_NUM)	; Check for link down
    352 	ld	b,PORTDATA
    353 	add	b,a
    354 	ld	b,(b)
    355 	tst	b,0
    356 
    357         ld      a,ONE           ; Off (ONE)
    358         jnc     ls_led_clear
    359 
    360         dec     a               ; Off (ONE) -> On (ZERO)
    361 
    362 ls_led_clear:
    363         pushst  a
    364         pack
    365         ret
    366 
    367 
    368 ; Variables (SDK software initializes LED memory from 0x80-0xff to 0)
    369 ;
    370 
    371 TXRX_ALT_COUNT	equ	0xff
    372 HD_COUNT	equ	0xfe
    373 GIG_ALT_COUNT	equ	0xfd
    374 PORT_NUM	equ	0xfc
    375 PORT_NUM_CACHE	equ	0xfb
    376 
    377 ;
    378 ; Port data, which must be updated continually by main CPU's
    379 ; linkscan task.  See $SDK/src/appl/diag/ledproc.c for examples.
    380 ; In this program, bit 0 is assumed to contain the link up/down status.
    381 ;
    382 
    383 PORTDATA	equ	0xa0	; Size 28 bytes
    384 
    385 ;
    386 ; LED extension timers
    387 ;
    388 
    389 RX_TIMERS	equ	0xc0+0			; NUM_PORT bytes
    390 TX_TIMERS	equ	0xc0+NUM_PORT		; NUM_PORT bytes
    391 
    392 ;
    393 ; Symbolic names for the bits of the port status fields
    394 ;
    395 
    396 RX		equ	0x0	; received packet
    397 TX		equ	0x1	; transmitted packet
    398 COLL		equ	0x2	; collision indicator
    399 SPEED_C		equ	0x3	; 100 Mbps
    400 SPEED_M		equ	0x4	; 1000 Mbps
    401 DUPLEX		equ	0x5	; half/full duplex
    402 FLOW		equ	0x6	; flow control capable
    403 LINKUP		equ	0x7	; link down/up status
    404 LINKEN		equ	0x8	; link disabled/enabled status
    405 ZERO		equ	0xE	; always 0
    406 ONE		equ	0xF	; always 1