📄 tx_timin.68
字号:
/**************************************************************************/
/* */
/* Copyright (c) 1996-2000 by Express Logic Inc. */
/* */
/* This software is copyrighted by and is the sole property of Express */
/* Logic, Inc. All rights, title, ownership, or other interests */
/* in the software remain the property of Express Logic, Inc. This */
/* software may only be used in accordance with the corresponding */
/* license agreement. Any unauthorized use, duplication, transmission, */
/* distribution, or disclosure of this software is expressly forbidden. */
/* */
/* This Copyright notice may not be removed or modified without prior */
/* written consent of Express Logic, Inc. */
/* */
/* Express Logic, Inc. reserves the right to modify this software */
/* without notice. */
/* */
/* Express Logic, Inc. */
/* 11440 West Bernardo Court info@expresslogic.com */
/* Suite 366 http://www.expresslogic.com */
/* San Diego, CA 92127 */
/* */
/**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** ThreadX Component */
/** */
/** Timer (TIM) */
/** */
/**************************************************************************/
/**************************************************************************/
/* #define TX_SOURCE_CODE */
/* Include necessary system files. */
/* #include "tx_api.h"
#include "tx_tim.h"
#include "tx_thr.h" */
/* Define Assembly language external references... */
XREF _tx_timer_time_slice
XREF _tx_timer_system_clock
XREF _tx_timer_current_ptr
XREF _tx_timer_list_start
XREF _tx_timer_list_end
XREF _tx_timer_expired_time_slice
XREF _tx_timer_expired
XREF _tx_timer_thread
XREF _tx_thread_current_ptr
XREF _tx_thread_context_save
XREF _tx_thread_time_slice
XREF _tx_thread_context_restore
XREF _tx_thread_preempt_check
XREF _tx_thread_resume
XREF _tx_thread_preempt_disable
#ifdef TX_ENABLE_EVENT_LOGGING
XREF _tx_el_interrupt
XREF _tx_el_interrupt_end
#endif
SECT .text,x
ALIGN 4
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_timer_interrupt 68332/Green Hills */
/* 3.0a */
/* AUTHOR */
/* */
/* William E. Lamie, Express Logic, Inc. */
/* */
/* DESCRIPTION */
/* */
/* This function processes the hardware timer interrupt. This */
/* processing includes incrementing the system clock and checking for */
/* time slice and/or timer expiration. If either is found, the */
/* interrupt context save/restore functions are called along with the */
/* expiration functions. */
/* */
/* INPUT */
/* */
/* None */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* _tx_thread_context_save Save interrupted context */
/* _tx_thread_resume Resume timer processing thread*/
/* _tx_thread_time_slice Time slice interrupted thread */
/* _tx_thread_context_restore Restore interrupted context */
/* */
/* CALLED BY */
/* */
/* interrupt vector */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-07-1999 William E. Lamie Initial Version 3.0 */
/* 12-02-1999 William E. Lamie Modified comment(s), and */
/* added interrupt logging, */
/* resulting in version 3.0a. */
/* */
/**************************************************************************/
/* VOID _tx_timer_interrupt(VOID)
{ */
XDEF _tx_timer_interrupt
_tx_timer_interrupt:
/* Upon entry to this routine, it is assumed that all interrupts are locked
out and the stack looks like the following:
(lower address) SP -> ISR Saved SR
SP+2 -> Interrupted SR
SP+6 -> Point of Interrupt
*/
/* Increment the system clock. */
/* _tx_timer_system_clock++; */
addq.l #1,_tx_timer_system_clock ; Increment the system clock
/* Test for time-slice expiration. */
/* if (_tx_timer_time_slice)
{ */
tst.l _tx_timer_time_slice ; Is time slicing active?
beq __tx_timer_no_time_slice ; If 0, time_slice is not active
/* Decrement the time_slice. */
/* _tx_timer_time_slice--; */
subq.l #1,_tx_timer_time_slice ; Subtract from the time-slice
/* Check for expiration. */
/* if (_tx_timer_time_slice == 0) */
bne __tx_timer_no_time_slice ; If not 0, nothing has expired
/* Set the time-slice expired flag. */
/* _tx_timer_expired_time_slice = TX_TRUE; */
addq.l #1,_tx_timer_expired_time_slice ; Set time slice expired flag
/* } */
__tx_timer_no_time_slice:
/* Test for timer expiration. */
/* if (*_tx_timer_current_ptr)
{ */
move.l %A0,-(%A7) ; Save a0 on the stack
movea.l _tx_timer_current_ptr,%A0 ; A0 now contains a pointer to
/* ; the current list entry */
tst.l (%A0) ; Is the pointer NULL?
beq __tx_timer_no_timer ; Yes, then no timer has expired
/* Set expiration flag. */
/* _tx_timer_expired = TX_TRUE; */
addq.l #1,_tx_timer_expired ; Otherwise, a timer has expired
bra __tx_timer_done
/* }
else
{ */
__tx_timer_no_timer:
/* No timer expired, increment the timer pointer. */
/* _tx_timer_current_ptr++; */
addq.l #4,%A0 ; Increment the current pointer
/* Check for wrap-around. */
/* if (_tx_timer_current_ptr == _tx_timer_list_end) */
cmpa.l _tx_timer_list_end,%A0 ; Are we at the end of the list?
bne __tx_timer_skip_wrap ; No, skip the wrap to the start
/* Wrap to beginning of list. */
/* _tx_timer_current_ptr = _tx_timer_list_start; */
movea.l _tx_timer_list_start,%A0 ; Wrap to the front of the list
__tx_timer_skip_wrap:
move.l %A0,_tx_timer_current_ptr ; Save the new list pointer
/* } */
__tx_timer_done:
movea.l (%A7)+,%A0 ; Recover saved a0
/* See if anything has expired. */
/* if ((_tx_timer_expired_time_slice) || (_tx_timer_expired))
{ */
tst.l _tx_timer_expired_time_slice ; Has time-slice expired?
bne __tx_something_expired ; Yes, the time-slice has expired
tst.l _tx_timer_expired ; Check the timer
beq __tx_timer_nothing_expired ; If 0, nothing has expired
__tx_something_expired:
/* Call interrupt context save to save the current environment. */
/* _tx_thread_context_save(); */
jsr _tx_thread_context_save ; Save interrupted context of system
#ifdef TX_ENABLE_EVENT_LOGGING
move.l #1,-(%A7) ; Build interrupt code
jsr _tx_el_interrupt ; Call interrupt event logging
addq.l #4,%A7 ; Recover stack space
#endif
/* Did a timer expire? */
/* if (_tx_timer_expired)
{ */
tst.l _tx_timer_expired ; See if a timer has expired
beq __tx_timer_dont_activate ; No, don't activate the timer thread
/* Increment the preempt disable counter in preparation for
thread resumption. */
/* _tx_thread_preempt_disable++; */
addq.l #1,_tx_thread_preempt_disable ; Increment preempt disable counter
/* Activate the system timer thread. */
/* _tx_thread_resume(&_tx_timer_thread); */
move.l #_tx_timer_thread,%D0 ; Get address of timer thread control block
move.l %D0,-(%A7) ; Push it on the stack
jsr _tx_thread_resume ; Resume the timer thread
addq.l #4,%A7 ; Cleanup the stack
/* } */
__tx_timer_dont_activate:
/* Did time slice expire? */
/* if (_tx_timer_expired_time_slice)
{ */
tst.l _tx_timer_expired_time_slice ; Check the expired flag
beq __tx_timer_not_ts_expiration ; If not set, time-slice not expired
/* Time slice interrupted thread. */
/* if (!_tx_thread_time_slice())
_tx_timer_time_slice = _tx_thread_current_ptr -> tx_time_slice; */
jsr _tx_thread_time_slice ; Time slice interrupted thread
tst.l %D0 ; Determine if we need to reset the
bne __tx_timer_not_ts_expiration ; current time slice variable
movea.l _tx_thread_current_ptr,%A0 ; Setup thread pointer
move.l 24(%A0),%D0 ; Pickup a fresh time-slice value
/* ; (a fresh time slice was setup in
; the _tx_thread_time_slice function) */
move.l %D0,_tx_timer_time_slice ; Setup time-slice
/* } */
__tx_timer_not_ts_expiration:
clr.l _tx_timer_expired_time_slice ; Clear the expired flag
#ifdef TX_ENABLE_EVENT_LOGGING
move.l #1,-(%A7) ; Build interrupt code
jsr _tx_el_interrupt_end ; Call interrupt event logging
addq.l #4,%A7 ; Recover stack space
#endif
/* Restore context. */
/* _tx_thread_context_restore(); */
jmp _tx_thread_context_restore ; Restore interrupted context or preempt
/* ; We never come back here! */
/* } */
__tx_timer_nothing_expired:
jmp _tx_thread_preempt_check ; Check for preemption that might have
/* ; happend from a higher-level ISR */
/* } */
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -