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

📄 dcm44n.a51

📁 8051实时操作系统
💻 A51
📖 第 1 页 / 共 2 页
字号:
;
;  Calls:          serial_gateway_switch
;
;  Enters:         station_swap_check
;
;  Inputs:         none
;
;  Returns:        none
;
;  Description:    First checks the context in which the error occurred.  

;                  If a message was being transmitted (info mode), or the 

;                  master was synchronizing with the slave (init mode) in order

;                  to transmit a message, then the top message on the message

;                  queue is returned to the sender, and the slave is set 

;                  offline.  Otherwise, it is assumed that the protocol error

;                  occurred while polling for a reply message, and the slave

;                  is set offline. 

;---------------------------------------------------------------------------


master_protocol_error:

    clr     s_poll_mode                     ;clear poll-mode flag regardless


;if in init mode, return the message that caused synchronization attempt

    jbc     s_init_mode,master_abort_info_send



;if in info mode, return the message to the task

    jbc     s_info_mode,master_abort_info_send 



;else, assume that protocol error occurred during a poll send

    sjmp    master_abort_slave              ;


master_abort_info_send:
    %dequeue_message_def(s_queue_ptr)       ;dequeue message

    jz      master_abort_slave              ;if none on queue, jump

    mov     tbs,#0                          ;clear siu xmit registers
    mov     tbl,#0                          ;

    %set_msg_ptr(message_route_ofs)         ;change msg. type to reply
    mov     a,@r1                           ;

    setb    acc.msg_type_bpos               ;

    mov     @r1,a                           ;

    %set_msg_ptr(message_reply_ofs)         ;indicate error in reply field

    mov     @r1,#e_protocol_error           ;

    acall   serial_gateway_switch           ;return message to sender



master_abort_slave:

    mov     a,stad                          ;set station state to offline

    acall   set_slave_offline               ;

    ajmp    station_swap_check              ;go service next slave station



;---------------------------------------------------------------------------
;  Entry Point:    master_info_rcv

;
;  Purpose:        Handle incoming information frames to master station.    

;

;  Entered From:   non_auto_master_rcv
;
;  Calls:          serial_gateway_switch
;
;  Enters:         master_ack_check
;
;  Inputs:         none
;
;  Returns:        none
;
;  Description:    First checks for buffer overflow.  If overflow, then it

;                  is assumed that another buffer will be allocated in

;                  master_ack_check, and that process is called.  Otherwise,

;                  the received message is routed through the gateway, and

;                  the receive registers cleared.  If no more replies are

;                  expected from the secondary station (nr=ns) then the

;                  station is removed from the poll list.  Finally, the

;                  frame is checked so see if it also acknowledges a 

;                  previous send.    

;---------------------------------------------------------------------------


master_info_rcv:

    jb      bov,master_ack_check            ;if bov, ignore frame & check

                                            ;for new buffer

    mov     r0,rbs                          ;else set the message pointer
    dec     r0                              ;

    dec     r0                              ;
    acall   serial_gateway_switch           ;and return the msg. to its sender
    mov     rbs,#0                          ;clear the receiver registers

    mov     rbl,#0                          ;

;   sjmp    master_ack_check                ;see if prev. send acknowledged


master_ack_check:

    acall   check_receive_buffer            ;check on receive buffer

    mov     a,tbs                           ;was a message transmitted?

    jz      station_swap_check              ;if not, jump


master_info_xmitted: 
    mov     a,s_last_nsnr                   ;see if ns field of xmitted I

    xrl     a,nsnr                          ;control byte is different (one

    anl     a,#nsnr_ns_msk                  ;greater) than ns field of nsnr

    jz      set_non_auto_transmit           ;if not, retransmit message


message_acknowledged:

    clr     s_info_mode                     ;clear info mode flag

    mov     tbs,#0                          ;clear transmit registers

    mov     tbl,#0                          ;

    %dequeue_message_def(s_queue_ptr)       ;get msg. off of xmit queue

    %req_deallocate                         ;deallocate xmitted msg. buffer

    acall   check_receive_buffer            ;see if receiver needs a buffer
;   ajmp    station_swap_check              ;and go service next station

;---------------------------------------------------------------------------
;  Entry Point:    station_swap_check

;
;  Purpose:        master checks for a new station to send a message to or

;                  poll.

;

;  Entered From:   master_ack_check    
;
;  Calls:          initiate_order_transmission 

;                  enqueue_poll_station_def (macro)

;                  dequeue_poll_station_def (macro)
;
;  Enters:         event_detect
;
;  Inputs:         none
;
;  Returns:        none
;
;  Description:    First checks to see if the present station should be    

;                  enqueued in the station poll queue.  It then looks at the 

;                  serial message queue for a message to transmit.  If so,  

;                  the destination slave is swapped in and the message is 

;                  transmitted.  If there are no messages to send, the master

;                  checks its polling queue for stations to poll for   

;                  outstanding replies.  If the queue is not empty, a slave

;                  is swapped in and polled.                         

;---------------------------------------------------------------------------



station_swap_check:
    mov     a,nsnr                          ;are there any frames outstanding

    swap    a                               ;on this slave (ie, is ns <> nr)?

    xrl     a,nsnr                          ;

    jz      ssc_next_station                ;if not, jump
    %enqueue_poll_station_def               ;else put this station on the
                                            ;poll queue 
ssc_next_station:

    clr     s_poll_mode                     ;clear poll-mode flag
    mov     a,s_queue_ptr                   ;check for msg. to be xmitted
    jnz     swap_and_xmit                   ;if one, swap in station & xmit
    %dequeue_poll_station_def               ;else check for station to be polled
    jnz     station_poll_swap               ;if there is one, jump

    setb    rbe                             ;and go wait on the
    ajmp    event_detect                    ;next event



swap_and_xmit:                              ;transmit message dequeued

    mov     r0,a                            ;r0 => msg. to be xmitted

    acall   initiate_order_transmission     ;from serial message queue

    ajmp    event_detect                    ;then wait on next event

;---------------------------------------------------------------------------
;  Entry Point:    station_poll_swap

;
;  Purpose:        swap out current station, swap in new station, and transmit

;                  rr type of poll.

;

;  Entered From:   station_swap_check  
;
;  Calls:          swap_station_states_def (macro)

;
;  Enters:         event_detect
;
;  Inputs:         acc = station address
;
;  Returns:        none
;
;  Description:    Checks new station against current station.  If not the 

;                  same then nsnr is written to the old station's

;                  s_station_state, and the new station's s_station_state

;                  is written to nsnr.  In either case, the transmit control

;                  byte is set to an rr with the nr value taken from nsnr.   

;                  then the transmit is initiated.

;---------------------------------------------------------------------------


station_poll_swap:
    cjne    a,stad,sps_swap_out             ;if no station match, go swap out

    mov     a,smd                           ;see if in synchronous mode

    anl     a,#11100000b                    ;

    jnz     sps_transmit_rr                 ;if not, skip pause code

    mov     r6,#020h                        ;execute pause loop to prevent

    djnz    r6,$                            ;master from timing out
    

sps_transmit_rr:                            ;poll next station

    mov     a,nsnr                          ; set up nsnr registers

    mov     s_last_nsnr,a                   ; build control byte

    swap    a                               ;
    anl     a,#nr_msk                       ;
    orl     a,#rr_msk                       ;
    mov     tcb,a                           ;
    setb    s_poll_mode                     ;

;   ajmp    set_non_auto_transmit           ;



set_non_auto_transmit:                      ;initiate non-auto transmit
    mov     sts,#11100000b                  ; rts=1,tbf=1,rbe=1,rest=0

    ajmp    event_detect                    ;and go wait for xmit complete


sps_swap_out:
    acall   swap_station_states             ;swap in nsnr values 
    sjmp    sps_transmit_rr                 ;and go transmit poll rr


;---------------------------------------------------------------------------

; 

;      PROCEDURE:      swap_station_states

; 

;      PURPOSE:        swap station states saves the NSNR value for the

;                      current station and restores the NSNR for the next.

; 

;      CALLED BY:      station_pool_swap, initiate_order_transmission

; 

;      CALLS:          None

; 

;      INPUTS:         Station Address: ACC

; 

;      RETURNS:        Nothing

; 

;      DESCRIPTION:    swap_station_states puts the NSNR register value

;                      into the location of the S_Station_State array

;                      indexed by the value in the STAD register.  Then it

;                      gets the value stored in the location of the

;                      S_Station_State array indexed by the ACC and puts it

;                      in the NSNR register.  The value in the ACC is put

;                      into the STAD register.

; 

;---------------------------------------------------------------------------



swap_station_states:

    cjne    a,stad,swap_states              ;if new stad, swap

    ret                                     ;else do nothing

swap_states:

    mov     dptr, #s_station_state          ;save old station NSNR

    mov     dpl, stad

    xch     a, stad                         ;set new station address

    mov     a, nsnr

    movx    @dptr, a

    mov     dpl, stad                       ;set new station NSNR

    movx    a, @dptr

    mov     nsnr, a

    ret



;---------------------------------------------------------------------------
;  Entry Point:    serial_timeout

;
;  Purpose:        Handles response timeouts from secondary
;

;  Entered From:   event_detect
;
;  Calls:          none
;
;  Enters:         set_non_auto_transmit, which enters event_detectx

;                  protocol_error_reset
;
;  Inputs:         none
;
;  Returns:        none
;
;  Description:    checks timeout flag to see if this is the first or
;                  second time the timeout has occurred.  If it is the first,

;                  then the frame is retransmitted.  If it is the second, then 

;                  the frame is handled as described in protocol_error_reset.

;---------------------------------------------------------------------------

serial_timeout:
    jbc     s_timeout_count,terminate_station ;if 2nd timeout, branch

    setb    s_timeout_count                 ;else flag as a retransmit

    ajmp    set_non_auto_transmit           ;and retransmit the frame

        
terminate_station:                          ;this is the 2nd timeout
    clr     s_timeout_set                   ;therefore reset the timeout flag

    ajmp    master_protocol_error           ;and set station "offline"


;---------------------------------------------------------------------------
;  Procedure:      set_slave_offline

;
;  Purpose:        Set a slave station to the offline state.  This forces

;                  the master to resynchronize on the next message sent to 

;                  the slave.

;

;  Called From:    master_protocol_error, rac_offline
;
;  Calls:          none
;
;  Inputs:         acc = the address of the station to be set offline
;
;  Returns:        none
;
;  Description:    Sets the slaves entry in the s_station_state table to 

;                  the offline (0ffh).  If the station address is the present

;                  station being referenced (if acc = the siu stad register),  

;                  then the siu nsnr value is also set to offline (0ffh).

;---------------------------------------------------------------------------


set_slave_offline:

    mov     dptr,#s_station_state           ; 

    mov     dpl,a                           ;dptr => state entry

    cjne    a,stad,sso_pass                 ;if not present station, jump

    mov     nsnr,#ofl_msk                   ;else set nsnr to offline

sso_pass:
    mov     a,#ofl_msk                      ;set state table entry to offline
    movx    @dptr,a                         ;
    ret                                     ;return to caller

        
END

⌨️ 快捷键说明

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