⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 misc2.a51

📁 Vitesse 24port gigabit Switch Source Code
💻 A51
📖 第 1 页 / 共 2 页
字号:
;*
;*
;*    Copyright (c) 2002-2005 Vitesse Semiconductor Corporation "Vitesse".  
;*    All Rights Reserved.  Unpublished rights reserved under the copyright laws
;*    of the United States of America, other countries and international treaties.
;*    The software is provided without a fee. Permission to use, copy, store and 
;*    modify, the software and its source code is granted. Permission to integrate
;*    into other products, disclose, transmit and distribute the software in an
;*    absolute machine readable format (e.g. HEX file) is also granted. 
;*
;*    The source code of the software may not be disclosed, transmitted or
;*    distributed without the written permission of Vitesse. The software and its
;*    source code may only be used in products utilizing a Vitesse VSC73xx product.
;* 
;*    This copyright notice must appear in any copy, modification, disclosure,
;*    transmission or distribution of the software. Vitesse retains all ownership,
;*    copyright, trade secret and proprietary rights in the software.  
;*
;*    THIS SOFTWARE HAS BEEN PROVIDED "AS IS," WITHOUT EXPRESS OR IMPLIED WARRANTY
;*    INCLUDING, WITHOUT LIMITATION, IMPLIED WARRANTIES OF MERCHANTABILITY,
;*    FITNESS FOR A PARTICULAR USE AND NON-INFRINGEMENT.
;*
;*
$NOMOD51
$INCLUDE (REG52.INC)

NAME    MISCUTIL2

PUBLIC  _ushorts2ulong, _high_w
PUBLIC  _bit_mask_32
PUBLIC  _bit_mask_16
PUBLIC  _bit_mask_8
PUBLIC  _write_bit_8
PUBLIC  _write_bit_16
PUBLIC  _write_bit_32
PUBLIC  _test_bit_8
PUBLIC  _test_bit_16
PUBLIC  _test_bit_32

PROG    SEGMENT CODE

        RSEG    PROG

;* ************************************************************************ */
; ulong  ushorts2ulong (ushort lsw, ushort msw) small;
_ushorts2ulong:
;* ------------------------------------------------------------------------ --
;* Purpose     : Create an unsigned long from 2 unsigned shorts.
;* Remarks     : 
;* Restrictions:
;* See also    :
;* Example     :
; * ************************************************************************ */

        ; Exploit the compiler which parses 1st parameter (lsw) in r6, r7 and
        ; 2nd parameter (msw) in r4, r5, i.e. without doing anything the return value
        ; will be a long in r4-r7.

        ret

;* ************************************************************************ */
; ushort  high_w (ulong ul) small;
_high_w:
;* ------------------------------------------------------------------------ --
;* Purpose     : Get high 16 bits of an unsigned long.
;* Remarks     : 
;* Restrictions:
;* See also    :
;* Example     :
; * ************************************************************************ */

        mov     a, r4
        mov     r6, a
        mov     a, r5
        mov     r7, a

        ret

; Bit table used for converting a bit number to a bit mask
bit_table:
        db      01H
        db      02H
        db      04H
        db      08H
        db      10H
        db      20H
        db      40H
        db      80H

;* ************************************************************************ */
; ulong  bit_mask_32 (uchar bit_no) small;
_bit_mask_32:
;* ------------------------------------------------------------------------ --
;* Purpose     : Build a 32-bit mask with ONE bit set according to specified
;*               bit number.
;* Remarks     : r7 holds bit number.
;* Restrictions:
;* See also    :
;* Example     :
; * ************************************************************************ */

        mov     a, r7
        mov     b, a    ; temporary

        ; Preset 32-bit mask with 0s
        clr     a
        mov     r7, a
        mov     r6, a
        mov     r5, a
        mov     r4, a

        mov     a, b
        mov     dptr, #bit_table

        ; If bit in range 0-7
        cjne    a, #8, l1_1
l1_1:   jnc     l1_2
        ; bit_no < 8
        movc    a, @a + dptr
        mov     r7, a
        ret

        ; If bit in range 8-15
l1_2:   subb    a, #8
        cjne    a, #8, l1_3
l1_3:   jnc     l1_4
        ; 8 <= bit_no < 16
        movc    a, @a + dptr
        mov     r6, a
        ret

        ; If bit in range 16-23
l1_4:   subb    a, #8
        cjne    a, #8, l1_5
l1_5:   jnc     l1_6
        ; 16 <= bit_no < 24
        movc    a, @a + dptr
        mov     r5, a
        ret

        ; If bit in range 24-31
l1_6:   subb    a, #8
        movc    a, @a + dptr
        mov     r4, a
        ret
;* ************************************************************************ */
; ushort bit_mask_16 (uchar bit_no) small;
_bit_mask_16:
;* ------------------------------------------------------------------------ --
;* Purpose     : Build a 16-bit mask with ONE bit set according to specified
;*               bit number.
;* Remarks     : r7 holds bit number.
;* Restrictions:
;* See also    :
;* Example     :
; * ************************************************************************ */

        clr     a
        mov     r6, a
        xch     a, r7
        mov     dptr, #bit_table

        ; If bit in range 0-7
        cjne    a, #8, l2_1
l2_1:   jnc     l2_2
        ; bit_no < 8
        movc    a, @a + dptr
        mov     r7, a
        ret

        ; If bit in range 8-15
l2_2:   subb    a, #8
        movc    a, @a + dptr
        mov     r6, a
        ret

;* ************************************************************************ */
; uchar bit_mask_8 (uchar bit_no) small;
_bit_mask_8:
;* ------------------------------------------------------------------------ --
;* Purpose     : Build a 8-bit mask with ONE bit set according to specified
;*               bit number.
;* Remarks     : r7 holds bit number.
;* Restrictions:
;* See also    :
;* Example     :
; * ************************************************************************ */

        mov     a, r7
        mov     dptr, #bit_table
        movc    a, @a + dptr
        mov     r7, a
        ret

;* ************************************************************************ */
; void write_bit_8 (uchar bit_no, uchar value, uchar *dst_ptr) small;
_write_bit_8:
;* ------------------------------------------------------------------------ --
;* Purpose     : Set specified bit to specified value in byte pointed to by
;*               dst_ptr.
;* Remarks     : r7 holds bit number, r5 holds value (0 or 1), 
;*               r1-r3 holds destination pointer.
;* Restrictions:
;* See also    :
;* Example     :
; * ************************************************************************ */

        ;* Convert bit number to bit mask and complement bit mask
        ;*----------------------------------------------------------------
        mov     dptr, #bit_table
        mov     a, r7
        movc    a, @a + dptr
        mov     r7, a
        cpl     a
        mov     r6, a

        ;* Check if external or internal ram
        ;*----------------------------------------------------------------
        cjne    r3, #1, l3_3

        ;* External Ram
        ;*----------------------------------------------------------------
        mov     dpl, r1
        mov     dph, r2
        movx    a, @dptr        ; Read byte from external ram
        anl     a, r6           ; Reset bit
        cjne    r5, #0, l3_1    ; Check if bit is to be set
        jmp     l3_2            ; Skip setting bit
l3_1:   orl     a, r7           ; Set bit
l3_2:   movx    @dptr, a        ; Update byte in external ram
        ret

        ;* Skip update if neither external nor internal ram
        ;*----------------------------------------------------------------
l3_3:   cjne    r3, #0, l3_6

        ;* Internal Ram

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -