📄 impulse.asm
字号:
;=====================================================================================
; File name: IMPULSE.ASM
;
; Originator: Digital Control Systems Group
; Texas Instruments
;
; Description:
; This file contains source for periodic impulse function routine.
;=====================================================================================
; History:
;-------------------------------------------------------------------------------------
; 9-15-2000 Release Rev 1.0
;================================================================================
; Applicability: F240,F241,C242,F243,F24xx. (Peripheral Independant).
;
;
;================================================================================
; Routine Name : Impulse Generator. Routine Type: C Callable
;
; Description : This module implements a periodic impulse function.
;
; C prototype : void impulse_calc(IMPULSE *p);
;================================================================================
; History Created July 25, 2000.
;
; Definition of IMPULSE:
;
; typedef struct IMPULSE {
; int period;
; int out;
; int skpcnt;
; (int (*) (int))impulse_calc
;================================================================================
ON .set 1
OFF .set 0
;--------------------------------------------------------------------------------
RETURN_ADDRESS_SAVE .set ON ; If this function calls no other functions
; set RETURN_ADDRESS_SAVE to OFF for
; optimization
;--------------------------------------------------------------------------------
MAX_PERIOD .set 07fffh
CLEAR .set 0000h
;--------------------------------------------------------------------------------
.def _impulse_calc
;================================================================================
_impulse_calc:
__IMPULSE_framesize .set 0001h
;--------------------------------------------------------------------------------
.if (RETURN_ADDRESS_SAVE = ON)
; AR1 is stack pointer (SP)
; AR0 is frame pointer (FP)
POPD *+ ; Save the return address from hardware
; stack onto the software stack
.endif
;--------------------------------------------------------------------------------
SAR AR0,*+ ; push AR0 (FP). ARP = AR1
SAR AR1,* ; *SP = SP. ARP = AR1
LAR AR0,#__IMPULSE_framesize
; FP = size of frame. ARP = AR1
LAR AR0,*0+,AR2 ; Allocate frame. AR0 = *AR1
; AR1 = AR1 + AR0. ARP = AR2
;================================================================================
.if (RETURN_ADDRESS_SAVE = ON)
LAR AR2,#-3
.endif
.if (RETURN_ADDRESS_SAVE = OFF)
LAR AR2,#-2
.endif
;--------------------------------------------------------------------------------
MAR *0+ ; AR2 -> passed parameter
; (i.e. pointer to the structure).
; ARP = AR2. AR2 = AR2 + AR0
;--------------------------------------------------------------------------------
LAR AR3,* ; AR3 points to the first structure member
; (i.e. AR3->Period)
; ARP = AR2.
;--------------------------------------------------------------------------------
LAR AR4,* ; AR4 points to the first structure member
; (i.e. AR4->Period).
; ARP = AR2. AR3-> Period
;--------------------------------------------------------------------------------
LAR AR5,*,AR4
; AR5 points to the first structure member
; (i.e. AR5->Period). ARP =AR4.
; AR4->Period. AR3-> Period
;--------------------------------------------------------------------------------
MAR *+ ; AR4->Out. ARP = AR4. AR5-> Period.
; AR3-> Period
;--------------------------------------------------------------------------------
SPLK #CLEAR, *, AR5
; Always clear Impulse Output on entry.
; ARP = AR5. AR5-> Period. AR4-> Out.
; AR3-> Period.
;--------------------------------------------------------------------------------
ADRK #2 ; ARP = AR5. AR3-> Period .
; AR4-> Out . AR5-> skpcnt
;--------------------------------------------------------------------------------
LACC * ; Load accumulator with skpcnt
; ARP = AR5. AR5-> skpcnt. AR3-> Period.
; AR4-> Out.
;--------------------------------------------------------------------------------
ADD #1 ; Increment the Accumulator contents by 1
; ARP = AR5. AR5-> skpcnt. AR3-> Period.
; AR4-> Out.
;--------------------------------------------------------------------------------
SACL *, AR3 ; Increment skpcnt and store
; ARP = AR3. AR3-> period. AR4->Out.
; AR5-> skpcnt.
;--------------------------------------------------------------------------------
SUB *, AR4 ; Accumulator = skpcnt - period.
; ARP = AR4. AR3-> Period. AR4-> Out.
; AR5-> skpcnt.
;--------------------------------------------------------------------------------
BCND __impulse_calc_exit, LT
; If (skpcnt < period) then
; goto __Impulse_exit
; i.e. Skip setting impulse High
; ARP = AR4. AR3-> Period. AR4-> Out.
; AR5-> skpcnt.
;--------------------------------------------------------------------------------
SPLK #MAX_PERIOD, *, AR5
; Out = 7fffh. ARP = AR5. AR5-> skpcnt
; AR4-> Out. AR3-> Period.
;--------------------------------------------------------------------------------
SPLK #CLEAR, *
; Reset skip counter.
; ARP = AR5. AR5-> skpcnt
; AR4-> Out. AR3-> Period.
;================================================================================
; Retrieve FP and SP of parent function
__impulse_calc_exit:
MAR * , AR1 ; set ARP = SP before you exit.
SBRK #(__IMPULSE_framesize+1)
; Deallocate frame, point to saved FP
.if (RETURN_ADDRESS_SAVE = ON)
LAR AR0, *- ; Restore frame pointer
PSHD * ; Push return address on Hardware stack
.endif
.if (RETURN_ADDRESS_SAVE = OFF)
LAR AR0, * ; Restore frame pointer
.endif
RET ; Return to the Parent Function
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -