;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Copyright (c) 2001-2002 TIMEX Corporation.
;
; This document is the property of, and contains information proprietary to
; TIMEX Corporation.  It is to be returned upon request.  Reproduction by any
; means, disclosure, or use of its contents for other than the expressed
; purpose for which it is loaned, without the written consent of TIMEX
; Corporation, is strictly prohibited.
;
; File Name:    hwSerMac.h
;
; Macro Names:
;
;       HW_CHECK_COMM_LINK_CONNECTED     - Check if the USB MCU has powered up and is ready.
;       HW_SYNC_SERIAL_SLAVE_INIT        - Initialize the synchronous serial slave interface to a safe state.
;       HW_SYNCHRONOUS_RX_AND_USB_ENABLE - Enable the synchronous serial interface for a receive operation and
;                                          USB MCU.
;       HW_SYNCHRONOUS_RX_TX_INT_DISABLE - Disable the synchronous serial receive/transmit interrupts.
;       HW_SYNCHRONOUS_RX_ENABLE         - Enable the synchronous serial interface for a receive operation.
;       HW_SYNCHRONOUS_RX_INT_ENABLE     - Enable the synchronous serial receive interrupt.
;       HW_SYNCHRONOUS_RX_TRIGGER        - Trigger the synchronous serial interface receive operation.
;       HW_SYNCHRONOUS_TX_ENABLE         - Enable the synchronous serial interface for a transmit operation.
;       HW_SYNCHRONOUS_TX_INT_ENABLE     - Enable the synchronous serial transmit interrupt.
;       HW_SYNCHRONOUS_TX_TRIGGER        - Trigger the synchronous serial interface transmit operation.
;       HW_SYNCHRONOUS_TX_SETUP_BYTE     - Setup a byte to be transmitted prior to trigger.
;
; Purpose:      Contains all hardware macros related to the Cypress - Epson synchronous serial interface.
;
; Dependencies: hw88349.h
;               hwser.h
;
; File Change History:
;
;               02/14/2002 SER - Created serial macros for M851.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;      SYNCHRONOUS SERIAL MACROS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   HW_CHECK_COMM_LINK_CONNECTED
;
; Description:  Check if the USB MCU has powered up and is ready due to a USB cable connection.
;
; Assumptions:  BRReg = HWBASEADDRESS.
;
; Usage:        HW_CHECK_COMM_LINK_CONNECTED
;
; Input(s):     None
;
; Output(s):    bZeroFlag - Set if the USB MCU is powered up and indicating that it is ready.
;                           Cleared if the USB MCU is not powered up, or not indicating ready.
;
; Destroy(s):   AReg
;
; Macro Change History:
;               02/14/2002 SER - Created Macro for 851.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

HW_CHECK_COMM_LINK_CONNECTED  MACRO

                car hwCheckCommLinkConnected

        CALLS   SUBROUTINE , 'hwCheckCommLinkConnected'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   HW_SYNC_SERIAL_SLAVE_INIT
;
; Description:  Initialize the synchronous serial slave interface to a safe state as follow:
;                 - Disable both receive and transmit operations.
;                 - Setup the serial port to be a synchronous slave device, but do not enable the serial pins.
;                 - Initialize all of the serial interface pins to a power saving state.
;                 - Clear and disable all serial interrupts.
;
; Assumptions:  BRReg = HWBASEADDRESS.
;               USB MCU is not powered up when this macro is called.
;               Level control resistor and outbound status pins (R03 - R06) are in complementary mode.
;
; Usage:        HW_SYNC_SERIAL_SLAVE_INIT
;
; Input(s):     None
;
; Output(s):    None
;
; Destroy(s):   None
;
; Macro Change History:
;               02/14/2002 SER - Created Macro for 851.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

HW_SYNC_SERIAL_SLAVE_INIT  MACRO

                car hwSyncSerialSlaveInit

        CALLS   SUBROUTINE , 'hwSyncSerialSlaveInit'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   HW_SYNCHRONOUS_RX_AND_USB_ENABLE
;
; Description:  Enable the synchronous serial interface for a receive operation and the USB MCU.
;
; Assumptions:  BRReg = HWBASEADDRESS.
;               USB MCU has been powered up when this macro is called.
;               The operation of this system is in slave mode.  This requires that a receive operation be
;               performed prior to any other operation.  This macro enables the receiver.
;
; Usage:        HW_SYNCHRONOUS_RX_AND_USB_ENABLE
;
; Input(s):     None
;
; Output(s):    None
;
; Destroy(s):   AReg
;
; Macro Change History:
;               02/14/2002 SER - Created Macro for 851.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

HW_SYNCHRONOUS_RX_AND_USB_ENABLE  MACRO

                car hwSyncRXAndUSBEnable

        CALLS   SUBROUTINE , 'hwSyncRXAndUSBEnable'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   HW_SYNCHRONOUS_RX_TX_INT_DISABLE
;
; Description:  Disable the synchronous serial receive/transmit interrupts.
;
; Assumptions:  BRReg = HWBASEADDRESS.
;               USB MCU has been powered up when this macro is called, and the serial interface is enabled.
;
; Usage:        HW_SYNCHRONOUS_RX_TX_INT_DISABLE
;
; Input(s):     None
;
; Output(s):    None
;
; Destroy(s):   None
;
; Macro Change History:
;               02/23/2002 SER - Created Macro for 851.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

HW_SYNCHRONOUS_RX_TX_INT_DISABLE  MACRO

                ; Disable both synchronous serial receive, and synchronous serial transmit interrupts.
                and     [BR:@LOW(SICIntEnable)], #@LOW(~bESREC & ~bESTRA)

         ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   HW_SYNCHRONOUS_RX_ENABLE
;
; Description:  Enable the synchronous serial interface for a receive operation.
;                 - Disable receive and transmit in order to reset the serial interface.
;                 - Enable receive operation.
;                 - Indicate watch is expecting RX mode.
;
; Assumptions:  BRReg = HWBASEADDRESS.
;               USB MCU has been powered up when this macro is called, and the serial interface is enabled.
;
; Usage:        HW_SYNCHRONOUS_RX_ENABLE
;
; Input(s):     None
;
; Output(s):    None
;
; Destroy(s):   None
;
; Macro Change History:
;               02/14/2002 SER - Created Macro for 851.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

HW_SYNCHRONOUS_RX_ENABLE  MACRO

                ; Disable receive and transmit in order to reset the serial interface.
                and     [BR:@LOW(SICControlReg)], #@LOW(~bRXEN & ~bTXEN)

                ; Enable receive operation.
                or      [BR:@LOW(SICControlReg)], #(bRXEN)

                ; Indicate to the USB MCU that the watch is expecting RX mode.
                or      [BR:@LOW(OutPortR0)], #(bUSB_W_RX)

         ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   HW_SYNCHRONOUS_RX_INT_ENABLE
;
; Description:  Enable synchronous serial receive, and disable synchronous serial transmit interrupts.
;
; Assumptions:  BRReg = HWBASEADDRESS.
;               USB MCU has been powered up when this macro is called, and the serial interface is enabled.
;
; Usage:        HW_SYNCHRONOUS_RX_INT_ENABLE
;
; Input(s):     None
;
; Output(s):    None
;
; Destroy(s):   None
;
; Macro Change History:
;               02/14/2002 SER - Created Macro for 851.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

HW_SYNCHRONOUS_RX_INT_ENABLE  MACRO

                ; Enable synchronous serial receive, and disable synchronous serial transmit interrupts.
                or      [BR:@LOW(SICIntEnable)], #(bESREC)
                and     [BR:@LOW(SICIntEnable)], #@LOW(~bESTRA)

         ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   HW_SYNCHRONOUS_RX_TRIGGER
;
; Description:  Trigger the synchronous serial interface receive operation in order to indicate that receive
;               is ready to start.
;
; Assumptions:  BRReg = HWBASEADDRESS.
;               USB MCU has been powered up when this macro is called, and the serial interface is enabled.
;
; Usage:        HW_SYNCHRONOUS_RX_TRIGGER
;
; Input(s):     None
;
; Output(s):    None
;
; Destroy(s):   None
;
; Macro Change History:
;               02/14/2002 SER - Created Macro for 851.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

HW_SYNCHRONOUS_RX_TRIGGER  MACRO

                ; Trigger synchronous serial receive.
                or      [BR:@LOW(SICControlReg)], #(bRXTRG)

         ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   HW_SYNCHRONOUS_TX_ENABLE
;
; Description:  Enable the synchronous serial interface for a transmit operation.
;                 - Disable receive and transmit in order to reset the serial interface.
;                 - Enable transmit operation.
;                 - Indicate watch is expecting TX mode.
;
; Assumptions:  BRReg = HWBASEADDRESS.
;               USB MCU has been powered up when this macro is called, and the serial interface is enabled.
;
; Usage:        HW_SYNCHRONOUS_TX_ENABLE
;
; Input(s):     None
;
; Output(s):    None
;
; Destroy(s):   None
;
; Macro Change History:
;               02/14/2002 SER - Created Macro for 851.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

HW_SYNCHRONOUS_TX_ENABLE  MACRO

                ; Disable receive and transmit in order to reset the serial interface.
                and     [BR:@LOW(SICControlReg)], #@LOW(~bRXEN & ~bTXEN)

                ; Enable transmit operation.
                or      [BR:@LOW(SICControlReg)], #(bTXEN)

                ; Indicate to the USB MCU that the watch is expecting TX mode.
                and     [BR:@LOW(OutPortR0)], #@LOW(~bUSB_W_RX)

         ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   HW_SYNCHRONOUS_TX_INT_ENABLE
;
; Description:  Enable synchronous serial transmit, and disable synchronous serial receive interrupts.
;
; Assumptions:  BRReg = HWBASEADDRESS.
;               USB MCU has been powered up when this macro is called, and the serial interface is enabled.
;
; Usage:        HW_SYNCHRONOUS_TX_INT_ENABLE
;
; Input(s):     None
;
; Output(s):    None
;
; Destroy(s):   None
;
; Macro Change History:
;               02/14/2002 SER - Created Macro for 851.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

HW_SYNCHRONOUS_TX_INT_ENABLE  MACRO

                ; Enable synchronous serial transmit, and disable synchronous serial receive interrupts.
                or      [BR:@LOW(SICIntEnable)], #(bESTRA)
                and     [BR:@LOW(SICIntEnable)], #@LOW(~bESREC)

         ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   HW_SYNCHRONOUS_TX_TRIGGER
;
; Description:  Trigger the synchronous serial interface transmit operation in order to indicate that transmit
;               is ready to start.
;
; Assumptions:  BRReg = HWBASEADDRESS.
;               USB MCU has been powered up when this macro is called, and the serial interface is enabled.
;               The byte being transmitted has been setup in the TX/RX data register.
;
; Usage:        HW_SYNCHRONOUS_TX_TRIGGER
;
; Input(s):     None
;
; Output(s):    None
;
; Destroy(s):   None
;
; Macro Change History:
;               02/14/2002 SER - Created Macro for 851.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

HW_SYNCHRONOUS_TX_TRIGGER  MACRO

                ; Trigger synchronous serial transit.
                or      [BR:@LOW(SICControlReg)], #(bTXTRG)

         ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   HW_SYNCHRONOUS_TX_SETUP_BYTE
;
; Description:  Setup a byte to be transmitted prior to trigger.
;
; Assumptions:  BRReg = HWBASEADDRESS.
;               USB MCU has been powered up when this macro is called, and the serial interface is enabled.
;
; Usage:        HW_SYNCHRONOUS_TX_SETUP_BYTE
;
; Input(s):     AReg - Contains the byte to be transmitted.
;
; Output(s):    None
;
; Destroy(s):   None
;
; Macro Change History:
;               02/14/2002 SER - Created Macro for 851.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

HW_SYNCHRONOUS_TX_SETUP_BYTE  MACRO

                ; Setup a byte to be transmitted.
                ld      [BR:@LOW(SICData)], A

         ENDM
